File size: 22,192 Bytes
bdbd3b2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 | import type {
On,
PaneOpenArgs,
ResultOf,
SessionMessage,
Timer,
} from 'claude-code'
import Ask from './ask'
import Backend from './backend'
import { COMMAND_SPEC } from './command-spec'
import { drawnFilesOf } from './drawn-files-of'
import { entryKindsOf } from './entry-kinds-of'
import type Git from './git'
import type { Host } from './host'
import { isOnPaneSurface } from './is-on-pane-surface'
import Limits from './limits'
import { mapLimited } from './map-limited'
import { messageOf } from './message-of'
import { mtimeOf } from './mtime-of'
import Names from './names'
import PaneState from './pane-state'
import PaneToggle from './pane-toggle'
import Record from './record'
import Tools from './tools'
import Views from './views'
/**
* Registers the diff pane: `/diff` once the built-in stands down, the
* pane's drawing and refresh, its opening on Claude's first edit, the ask.
*
* Git runs when the built-in's would: `session.start` binds the host and
* registers `/diff`; `/diff` or the first edit with room pins the backend
* where the session started, until `/clear`; an open pane alone fetches.
*
* @param on the engine's registrar
*/
export function register(on: On) {
let host: Host | null = null
let backend: Backend.Backend | null = null
let probing: Promise<boolean> | null = null
let sessionStartMs = 0
let isPaneOpen = false
let dialogRows: number | null = null
let hasAutoOpened = false
let columns: number | null = null
let shownSessionId: string | null = null
let armed: Ask.ArmedAsk | null = null
let carrying: Ask.ArmedAsk | null = null
let isRefreshing = false
let isRefreshQueued = false
let generation = 0
let bodyStamp: string | null = null
let bodyBase: string | null = null
const bodyLoads = new Map<string, Promise<Git.FileHunks | null>>()
const polled = { toplevel: '', headKey: '' }
const pin = { cwd: '', isEmpty: false, epoch: 0 }
let model: PaneState.PaneModel = PaneState.INITIAL_MODEL
const timers = new Map<'refresh' | 'redraw' | 'poll', Timer>()
const loggedBaseKinds = new Set<'ok' | 'sad'>()
const currentOf = (engine: Host): Host => host ?? engine
const backendHostOf = (engine: Host): Backend.BackendHost => ({
run: (argv, init) =>
currentOf(engine).run(
argv,
pin.cwd === '' ? init : { cwd: pin.cwd, ...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',
props: {
outcome: { value: base.kind, of: Record.BASE_OUTCOMES },
},
}
if (!loggedBaseKinds.has(outcome.kind)) {
loggedBaseKinds.add(outcome.kind)
Record.recorderOf(currentOf(engine)).mark(
Record.FEATURES.baseResolve,
outcome,
)
}
},
})
function pinBackend(engine: Host): Promise<boolean> {
if (backend || pin.isEmpty) {
return Promise.resolve(true)
}
probing ??= probeBackend(engine).finally(() => {
probing = null
})
return probing
}
async function probeBackend(engine: Host): Promise<boolean> {
const asked = { isAnswered: true }
const probeHost = backendHostOf(engine)
const { epoch } = pin
const probed = await Backend.backendOf(
{
...probeHost,
run: (argv, init) =>
probeHost.run(argv, init).catch((error: unknown) => {
asked.isAnswered &&=
argv[0] !== 'git' || !/\baborted\b/.test(messageOf(error))
throw error
}),
},
Backend.INSTALLED_BACKEND_PROBES,
)
if (epoch !== pin.epoch) {
return false
}
backend ??= probed
pin.isEmpty = backend === null && asked.isAnswered
if (!probed || backend !== probed) {
return asked.isAnswered || backend !== null
}
const stored = PaneState.baseModeOf(
await engine
.storeGet(Names.baseStoreKeyOf(probed.repository.toplevel))
.catch(() => undefined),
)
const mode = stored && probed.baseModes.includes(stored) ? stored : null
model = {
...model,
words: probed.words,
baseModes: probed.baseModes,
...(mode && { requestedMode: mode }),
}
return true
}
function unpin() {
backend = null
pin.isEmpty = false
pin.epoch += 1
polled.toplevel = ''
polled.headKey = ''
timers.get('poll')?.cancel()
timers.delete('poll')
}
function dialogPane(): PaneOpenArgs {
return {
id: Names.PANE_ID,
title: Names.PANE_TITLE,
holdToasts: true,
closeOnEscape: true,
rows: Views.dialogRowsOf(model),
}
}
function fitDialog(engine: Host) {
const rows = Views.dialogRowsOf(model)
const isStale =
isPaneOpen && model.isFullscreen === false && rows !== dialogRows
if (isStale) {
dialogRows = rows
void engine.openPane(dialogPane()).catch(() => undefined)
}
}
function redraw(engine: Host) {
fitDialog(engine)
if (timers.has('redraw')) {
return
}
timers.set(
'redraw',
engine.after(Limits.REDRAW_COALESCE_MS, () => {
timers.delete('redraw')
engine.invalidate()
}),
)
}
async function loadBodies(engine: Host): Promise<boolean> {
const { data } = model
const pinned = backend
if (!data || !pinned) {
bodyStamp = null
bodyBase = null
bodyLoads.clear()
model = { ...model, bodies: PaneState.NO_BODIES }
return false
}
const stamp = bodyStampOf(data)
const isNewBase = data.baseRef !== bodyBase
if (stamp !== bodyStamp) {
bodyStamp = stamp
bodyLoads.clear()
}
if (isNewBase) {
bodyBase = data.baseRef
model = { ...model, bodies: PaneState.NO_BODIES }
redraw(engine)
}
return fetchBodies(engine, pinned, data)
}
const bodyStampOf = (data: Git.DiffData) => `${generation}|${data.baseRef}`
async function fetchBodies(
engine: Host,
pinned: Backend.Backend,
data: Git.DiffData,
): Promise<boolean> {
const stamp = bodyStampOf(data)
function loadOf(file: Git.FileStat): Promise<Git.FileHunks | null> {
const load = pinned.fetchFileHunks(data, file)
bodyLoads.set(file.path, load)
return load.then(body => {
if (bodyStamp === stamp) {
model = {
...model,
bodies: new Map(model.bodies).set(file.path, body),
}
redraw(engine)
}
return body
})
}
return (
await mapLimited(
drawnFilesOf(model).filter(file => !bodyLoads.has(file.path)),
Limits.BODY_FETCH_CONCURRENCY,
loadOf,
)
).includes(null)
}
function startPoll(engine: Host, pinned: Backend.Backend) {
const readHeadKey = () => pinned.headKeyOf().catch(() => '')
if (polled.toplevel === pinned.repository.toplevel) {
return
}
timers.get('poll')?.cancel()
polled.toplevel = pinned.repository.toplevel
polled.headKey = ''
timers.set(
'poll',
engine.every(Limits.HEAD_POLL_MS, () => {
if (!isPaneOpen) {
return
}
void readHeadKey().then(key => {
const hasMoved = polled.headKey !== '' && key !== polled.headKey
polled.headKey = key
if (hasMoved) {
scheduleRefresh(engine)
}
})
}),
)
}
async function refresh(engine: Host): Promise<void> {
if (isRefreshing) {
isRefreshQueued = true
return
}
isRefreshing = true
const record = Record.recorderOf(engine)
const pinned = backend
const fetched = (): Promise<Git.FetchOutcome> =>
pinned
? pinned.fetchDiff(model.requestedMode)
: Promise.resolve({ kind: 'no-repository' })
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) {
case 'no-repository':
break
case 'unavailable':
record.mark(Record.FEATURES.read, {
kind: 'sad',
reason: 'git_diff_failed',
})
break
case 'data':
generation += 1
if (pinned) {
startPoll(engine, pinned)
}
break
}
const hasHunksFailed = await loadBodies(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 = false
redraw(engine)
if (isRefreshQueued) {
isRefreshQueued = false
scheduleRefresh(engine)
}
}
}
function scheduleRefresh(engine: Host): void {
timers.get('refresh')?.cancel()
timers.set(
'refresh',
engine.after(Limits.REFRESH_DEBOUNCE_MS, () => {
timers.delete('refresh')
void refresh(engine)
}),
)
}
async function openPane(
engine: Host,
trigger: (typeof Record.SHOWN_TRIGGERS)[number],
): Promise<void> {
const isDialog = model.isFullscreen === false
model = {
...model,
selectedPath: null,
dialogView: 'list',
place: { ...model.place, top: 0, listStart: 0 },
}
dialogRows = isDialog ? Views.dialogRowsOf(model) : null
await engine.openPane(
isDialog
? { ...dialogPane(), focus: true }
: { id: Names.PANE_ID, title: Names.PANE_TITLE, holdToasts: true },
)
isPaneOpen = true
const sessionId = await engine.sessionId().catch(() => null)
if (sessionId !== null && sessionId !== shownSessionId) {
shownSessionId = sessionId
Record.recorderOf(engine).shown(trigger, Record.widthBucketOf(columns))
}
void refresh(engine)
}
async function closePane(engine: Host): Promise<void> {
await engine.closePane({ id: Names.PANE_ID })
isPaneOpen = false
}
function markTabSwitch(engine: Host, tab: (typeof Record.TABS)[number]) {
Record.recorderOf(engine).mark(Record.FEATURES.tabSwitch, {
kind: 'ok',
props: { tab: { value: tab, of: Record.TABS } },
})
}
async function openOnFirstEdit(engine: Host): Promise<void> {
const isTaken = () => isPaneOpen || hasAutoOpened
if (isTaken()) {
return
}
const preference = await engine.storeGet(Names.STORE_OPEN_KEY)
const isKeptOpen = preference === true
const floor = isKeptOpen
? Limits.OPEN_MIN_COLUMNS
: Limits.AUTO_OPEN_MIN_COLUMNS
const hasRoom =
preference !== false &&
model.isFullscreen === true &&
columns !== null &&
columns >= floor
if (!hasRoom || isTaken()) {
return
}
await pinBackend(engine)
if (!backend || isTaken()) {
return
}
hasAutoOpened = true
await openPane(engine, 'auto_open')
}
function disarm(engine: Host) {
armed = null
model = { ...model, armedPath: null }
engine.status(undefined)
}
const actionsOf = (engine: Host): Views.PaneActions => ({
selectFile: path => {
const isDocked = model.placement === 'dock'
model = {
...model,
selectedPath: path,
dialogView: isDocked ? model.dialogView : 'detail',
place: isDocked ? Views.placeAtFile(model, path) : model.place,
}
redraw(engine)
},
scrollList: delta => {
model = { ...model, place: Views.listScrolledBy(model, delta) }
redraw(engine)
},
toggleNoise: () => {
model = { ...model, isNoiseShown: !model.isNoiseShown }
void loadBodies(engine)
redraw(engine)
},
togglePreSession: () => {
model = { ...model, isPreSessionShown: !model.isPreSessionShown }
void loadBodies(engine)
redraw(engine)
},
cycleBase: () => {
const { baseModes, requestedMode } = model
const mode =
baseModes[(baseModes.indexOf(requestedMode) + 1) % baseModes.length] ??
requestedMode
if (mode === requestedMode) {
return
}
model = { ...model, requestedMode: mode }
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) {
void engine
.storeSet(Names.baseStoreKeyOf(toplevel), mode)
.catch(() => undefined)
}
void refresh(engine)
redraw(engine)
},
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, dialogView: 'list' }
redraw(engine)
},
toggleAsk: path => {
if (armed?.path === path) {
disarm(engine)
redraw(engine)
return
}
arm(engine, path)
},
})
function arm(engine: Host, path: string) {
armed = Ask.armedAskOf(
path,
PaneState.pickedTurnOf(model)?.files.find(file => file.path === path)
?.hunks ??
model.bodies.get(path)?.hunks ??
[],
)
model = { ...model, armedPath: path }
engine.status(
`${Views.sanitizeName(path)} rides your next prompt (press ` +
`asked ✓ to drop it)`,
)
redraw(engine)
}
async function bind(engine: Host, cwd: string): Promise<void> {
sessionStartMs = await engine.now()
pin.cwd = cwd
try {
await engine.registerCommand(COMMAND_SPEC)
host = engine
} catch (error) {
const reason = messageOf(error)
if (!Names.BUILTIN_HOLDS_PATTERN.test(reason)) {
engine.uiLog(Names.registerFailedTextOf(Views.sanitizeName(reason)))
}
}
}
on('session.start', async ($, e, next) => {
await bind(
{
now: () => $.clock.now(),
after: (ms, fn) => $.clock.after(ms, fn),
every: (ms, fn) => $.clock.every(ms, fn),
run: (argv, init) => $.process.run(argv, init),
stat: path => $.fs.stat(path),
listDir: path => $.fs.list(path),
readFile: path => $.fs.read(path),
storeGet: key => $.store.get(key),
storeSet: (key, value) => $.store.set(key, value),
messages: () => $.session.messages(),
invalidate: () => $.ui.invalidate('ui.render'),
status: text => $.ui.status(text),
uiLog: text => $.ui.log(text),
openPane: pane => $.ui.open(pane),
closePane: pane => $.ui.close(pane),
registerCommand: spec => $.command.register(spec),
sessionId: () => $.session.id(),
mark: entry => $.telemetry.mark(entry),
log: entry => $.telemetry.log(entry),
},
e.cwd,
)
return next(e)
})
on('ui.render', { component: 'PromptHint' }, ($, e, next) => {
if (isOnPaneSurface(e)) {
columns = e.viewport?.columns ?? columns
model = {
...model,
isFullscreen: e.viewport?.isFullscreen ?? model.isFullscreen,
}
}
return next(e)
})
on('ui.render', { component: 'Pane' }, async ($, e, next) => {
if (e.requestId !== Names.PANE_ID || !host || !isOnPaneSurface(e)) {
return next(e)
}
const { Box, Text, Button, Select, Code } = await $.ui.resolve(e)
columns = e.viewport?.columns ?? columns
model = {
...model,
placement: e.props.placement,
place: {
...model.place,
columns: Math.max(
1,
e.props.bodyColumns - Limits.PANE_RIGHT_PAD_COLUMNS,
),
rows: e.props.scroll.bodyRows,
},
}
return Views.paneView(
{
ui: { Box, Text, Button, Select, Code },
actions: actionsOf(host),
columns: e.props.bodyColumns,
rows: e.props.scroll.bodyRows,
},
model,
{ placement: e.props.placement, terminalColumns: columns },
)
})
on('command.run', { command: Names.COMMAND_NAME }, async ($, e, next) => {
if (!host) {
return next(e)
}
const isAnswered = (await pinBackend(host)) || (await pinBackend(host))
if (!backend) {
return {
text: isAnswered
? Names.NOT_IN_REPOSITORY_TEXT
: Names.GIT_UNANSWERED_TEXT,
}
}
const { isFullscreen } = e.presentation
columns = e.presentation.columns
model = { ...model, isFullscreen }
const toggle = PaneToggle.paneToggleOf({
isOpen: isPaneOpen,
columns: isFullscreen ? columns : null,
})
if (toggle === 'too-narrow') {
return { text: Names.RESIZE_TERMINAL_TEXT }
}
const isOpening = toggle === 'open'
await (isOpening ? openPane(host, 'manual') : closePane(host))
if (!isFullscreen) {
return isOpening ? {} : { text: Names.DIALOG_DISMISSED_TEXT }
}
markTabSwitch(host, isOpening ? 'diff' : 'convo')
await host.storeSet(Names.STORE_OPEN_KEY, isOpening).catch(() => undefined)
return {
text: isOpening ? Names.PANEL_SHOWN_TEXT : Names.PANEL_HIDDEN_TEXT,
}
})
on('ui.close', { id: Names.PANE_ID }, async ($, e, next) => {
const isBack =
e.origin.kind === 'person' &&
model.placement === 'inline' &&
model.dialogView === 'detail'
if (isBack && host) {
model = { ...model, dialogView: 'list' }
redraw(host)
dialogRows = Views.dialogRowsOf(model)
void host
.openPane({ ...dialogPane(), focus: true })
.catch(() => undefined)
return { deny: 'back to the file list' }
}
const result = await next(e)
const isClosed = result.deny === undefined
const isPersons = isClosed && e.origin.kind === 'person'
if (isClosed) {
isPaneOpen = false
}
const isDialog = model.isFullscreen === false
if (isPersons && host && isDialog) {
host.uiLog(Names.DIALOG_DISMISSED_TEXT)
}
if (isPersons && host && !isDialog) {
markTabSwitch(host, 'convo')
await host.storeSet(Names.STORE_OPEN_KEY, false).catch(() => undefined)
}
return result
})
on('ui.focus', { plugin: Names.PLUGIN_NAME }, ($, e, next) => {
const isListed =
model.placement === 'inline' && model.dialogView === 'list' && host
const focus = isListed ? Views.dialogFocusOf(model, e.element) : null
if (focus === 'stay') {
return {}
}
if (!focus || !host) {
return next(e)
}
model = { ...model, selectedPath: focus.selectedPath }
fitDialog(host)
host.invalidate()
return next({ ...e, element: focus.landing })
})
on('ui.scroll', { requestId: Names.PANE_ID }, ($, e, next) => {
const isOwnBody = e.origin.kind === 'person' && model.placement === 'dock'
if (!isOwnBody || !host) {
return next(e)
}
const isOverList = Views.isWheelOverList(model, e)
model = {
...model,
place: isOverList
? Views.listScrolledBy(model, e.by)
: Views.bodyScrolledBy(model, e),
}
host.invalidate()
return {}
})
on('command.run', { command: ['clear', 'resume'] }, async ($, e, next) => {
const result = await next(e)
if (host) {
if (isPaneOpen) {
await closePane(host).catch(() => undefined)
}
unpin()
hasAutoOpened = false
bodyStamp = null
bodyBase = null
bodyLoads.clear()
disarm(host)
model = PaneState.afterNewSession(model)
}
return result
})
function afterTool(
engine: Host,
tool: string,
result: ResultOf['tool.call'] | undefined,
) {
const isEdit = Tools.EDITING_TOOLS.some(name => name === tool)
const hasEdited =
isEdit &&
result !== undefined &&
result.deny === undefined &&
result.isError !== true
const isStale =
isPaneOpen &&
(isEdit ? hasEdited : result === undefined || result.deny === undefined)
if (isStale) {
scheduleRefresh(engine)
}
if (hasEdited) {
void openOnFirstEdit(engine).catch(() => undefined)
}
}
on(
'tool.call',
{ tool: [...Tools.EDITING_TOOLS, ...Tools.SHELL_TOOLS] },
async ($, e, next) => {
let result: ResultOf['tool.call'] | undefined
try {
result = await next(e)
return result
} finally {
if (host) {
afterTool(host, e.tool, result)
}
}
},
)
on('prompt.submit', async ($, e, next) => {
const asked = armed
if (!host || !asked || carrying === asked) {
return next(e)
}
const context = e.context ?? []
const text = Ask.fittedAskTextOf(
asked.text,
Limits.PROMPT_CONTEXT_MAX_CHARS -
context.reduce((sum, entry) => sum + entry.length, 0),
)
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)
}
carrying = asked
try {
const result = await next({ ...e, context: [...context, text] })
if (result.drop === undefined) {
Record.recorderOf(host).asked()
if (armed === asked) {
disarm(host)
redraw(host)
}
}
return result
} finally {
carrying = null
}
})
}
|