@linxin666/dsh-client-ui-task-board-ssh 0.0.0-stage → 0.4.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/LICENSE +202 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +85 -2
  4. package/README.zh.md +86 -0
  5. package/cordis.patch.yml +15 -0
  6. package/icon.svg +5 -0
  7. package/lib/client.js +4429 -0
  8. package/lib/index.js +6100 -0
  9. package/lib/types/client/PluginSettingsCard.d.ts +255 -0
  10. package/lib/types/client/RangeBubble.d.ts +46 -0
  11. package/lib/types/client/SegmentGroup.d.ts +28 -0
  12. package/lib/types/client/index.d.ts +100 -0
  13. package/lib/types/client/locales.d.ts +125 -0
  14. package/lib/types/client/seat-props.d.ts +53 -0
  15. package/lib/types/client/settings-entry-form.d.ts +49 -0
  16. package/lib/types/client/settings-form.d.ts +237 -0
  17. package/lib/types/client/ssh/card-decoration.d.ts +23 -0
  18. package/lib/types/client/ssh/compose-section.d.ts +7 -0
  19. package/lib/types/client/ssh/detail-section.d.ts +7 -0
  20. package/lib/types/client/ssh/extension.d.ts +54 -0
  21. package/lib/types/client/ssh/log-buffer.d.ts +128 -0
  22. package/lib/types/client/ssh/log-view.d.ts +37 -0
  23. package/lib/types/client/ssh/model.d.ts +130 -0
  24. package/lib/types/client/ssh/settings-section.d.ts +134 -0
  25. package/lib/types/client/ssh/summary.d.ts +160 -0
  26. package/lib/types/client/ssh/target-form.d.ts +60 -0
  27. package/lib/types/core/action.d.ts +89 -0
  28. package/lib/types/core/adapters/claude.d.ts +15 -0
  29. package/lib/types/core/adapters/codex.d.ts +15 -0
  30. package/lib/types/core/adapters/custom.d.ts +29 -0
  31. package/lib/types/core/adapters/dsh.d.ts +21 -0
  32. package/lib/types/core/adapters/index.d.ts +25 -0
  33. package/lib/types/core/adapters/types.d.ts +76 -0
  34. package/lib/types/core/contract.d.ts +445 -0
  35. package/lib/types/core/launcher-script.d.ts +13 -0
  36. package/lib/types/core/launcher.d.ts +153 -0
  37. package/lib/types/core/ledger.d.ts +123 -0
  38. package/lib/types/core/shell.d.ts +61 -0
  39. package/lib/types/core/target.d.ts +143 -0
  40. package/lib/types/core/task-record.d.ts +63 -0
  41. package/lib/types/core/workspace.d.ts +74 -0
  42. package/lib/types/host/board.d.ts +71 -0
  43. package/lib/types/host/engine.d.ts +418 -0
  44. package/lib/types/host/extension.d.ts +59 -0
  45. package/lib/types/host/logs.d.ts +135 -0
  46. package/lib/types/host/payload.d.ts +75 -0
  47. package/lib/types/host/prompt.d.ts +44 -0
  48. package/lib/types/host/queue.d.ts +53 -0
  49. package/lib/types/host/remote.d.ts +120 -0
  50. package/lib/types/host/settings.d.ts +149 -0
  51. package/lib/types/host/timers.d.ts +20 -0
  52. package/lib/types/host/tools.d.ts +15 -0
  53. package/lib/types/host/workspace/errors.d.ts +29 -0
  54. package/lib/types/host/workspace/git.d.ts +108 -0
  55. package/lib/types/host/workspace/in-place.d.ts +36 -0
  56. package/lib/types/host/workspace/index.d.ts +28 -0
  57. package/lib/types/host/workspace/layout.d.ts +62 -0
  58. package/lib/types/host/workspace/local-git.d.ts +72 -0
  59. package/lib/types/host/workspace/remote-git.d.ts +111 -0
  60. package/lib/types/host/workspace/remote.d.ts +85 -0
  61. package/lib/types/host/workspace/types.d.ts +28 -0
  62. package/lib/types/host/workspace-seam.d.ts +100 -0
  63. package/lib/types/index.d.ts +97 -0
  64. package/lib/types/mount-once.d.ts +55 -0
  65. package/locale/en.json +6 -0
  66. package/locale/zh.json +6 -0
  67. package/package.json +89 -3
  68. package/src/client/PluginSettingsCard.tsx +838 -0
  69. package/src/client/RangeBubble.tsx +164 -0
  70. package/src/client/SegmentGroup.tsx +93 -0
  71. package/src/client/css-modules.d.ts +5 -0
  72. package/src/client/index.ts +195 -0
  73. package/src/client/locales.ts +257 -0
  74. package/src/client/seat-props.ts +58 -0
  75. package/src/client/settings-card.module.css +821 -0
  76. package/src/client/settings-entry-form.ts +141 -0
  77. package/src/client/settings-form.ts +529 -0
  78. package/src/client/ssh/card-decoration.tsx +55 -0
  79. package/src/client/ssh/compose-section.tsx +147 -0
  80. package/src/client/ssh/detail-section.tsx +345 -0
  81. package/src/client/ssh/extension.ts +271 -0
  82. package/src/client/ssh/log-buffer.ts +224 -0
  83. package/src/client/ssh/log-view.tsx +149 -0
  84. package/src/client/ssh/model.ts +299 -0
  85. package/src/client/ssh/settings-section.tsx +401 -0
  86. package/src/client/ssh/summary.ts +388 -0
  87. package/src/client/ssh/target-form.tsx +380 -0
  88. package/src/client/ssh.module.css +617 -0
  89. package/src/core/action.ts +270 -0
  90. package/src/core/adapters/claude.ts +64 -0
  91. package/src/core/adapters/codex.ts +83 -0
  92. package/src/core/adapters/custom.ts +88 -0
  93. package/src/core/adapters/dsh.ts +87 -0
  94. package/src/core/adapters/index.ts +74 -0
  95. package/src/core/adapters/types.ts +95 -0
  96. package/src/core/contract.ts +510 -0
  97. package/src/core/launcher-script.ts +313 -0
  98. package/src/core/launcher.ts +283 -0
  99. package/src/core/ledger.ts +372 -0
  100. package/src/core/shell.ts +77 -0
  101. package/src/core/target.ts +413 -0
  102. package/src/core/task-record.ts +65 -0
  103. package/src/core/workspace.ts +78 -0
  104. package/src/host/board.ts +103 -0
  105. package/src/host/engine.ts +1602 -0
  106. package/src/host/extension.ts +304 -0
  107. package/src/host/logs.ts +297 -0
  108. package/src/host/payload.ts +134 -0
  109. package/src/host/prompt.ts +89 -0
  110. package/src/host/queue.ts +73 -0
  111. package/src/host/remote.ts +328 -0
  112. package/src/host/settings.ts +294 -0
  113. package/src/host/timers.ts +33 -0
  114. package/src/host/tools.ts +259 -0
  115. package/src/host/workspace/errors.ts +43 -0
  116. package/src/host/workspace/git.ts +305 -0
  117. package/src/host/workspace/in-place.ts +58 -0
  118. package/src/host/workspace/index.ts +37 -0
  119. package/src/host/workspace/layout.ts +122 -0
  120. package/src/host/workspace/local-git.ts +164 -0
  121. package/src/host/workspace/remote-git.ts +244 -0
  122. package/src/host/workspace/remote.ts +181 -0
  123. package/src/host/workspace/types.ts +34 -0
  124. package/src/host/workspace-seam.ts +132 -0
  125. package/src/index.ts +243 -0
  126. package/src/mount-once.ts +142 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The card-decoration seat: one chip that says where the card runs and how the
3
+ * run stands.
4
+ *
5
+ * It is a pure function of the card's ledger payload — no request, no timer, no
6
+ * subscription — because the board renders it on every card of every column on
7
+ * every mirror frame, and a provider's badge may not become the board's cost.
8
+ * An untargeted card renders nothing at all, so the chip always means "this card
9
+ * is pinned somewhere".
10
+ *
11
+ * @module dsh-task-board-ssh/client/ssh/card-decoration
12
+ */
13
+ import type { SshCardDecorationProps } from '../seat-props.ts'
14
+ import { sshCardView, type SshCardPhase } from './model.ts'
15
+ import { useHostHalfStatus } from './summary.ts'
16
+ import { t, type TaskBoardSshKey } from '../locales.ts'
17
+ import css from '../ssh.module.css'
18
+
19
+ /** Short plugin name the semantic attributes carry. */
20
+ const PLUGIN_ATTR = 'task-board-ssh'
21
+
22
+ /** Copy key naming one phase; the detail section's pill reads the same table. */
23
+ export function phaseKey(phase: SshCardPhase): TaskBoardSshKey {
24
+ return `run.${phase}`
25
+ }
26
+
27
+ /**
28
+ * Render the card badge.
29
+ * @param props - the card being decorated.
30
+ * @returns the chip, or nothing when the card pins no target.
31
+ */
32
+ export function SshCardDecoration({ task }: SshCardDecorationProps) {
33
+ const view = sshCardView(task)
34
+ const hostHalf = useHostHalfStatus()
35
+ const target = view.target
36
+ if (target === undefined) return null
37
+ // Nothing is mounted to keep this chip true, so the card claims nothing.
38
+ if (hostHalf === 'unmounted') return null
39
+ const isProxy = target.mode === 'proxy'
40
+ const state = isProxy ? t('detail.mode.proxy') : t(phaseKey(view.phase))
41
+ return (
42
+ <span
43
+ className={css.badge}
44
+ data-dsh-plugin={PLUGIN_ATTR}
45
+ data-dsh-part="badge"
46
+ data-run={isProxy ? 'idle' : view.phase}
47
+ title={t('card.badgeTitle', { host: target.host, state })}
48
+ >
49
+ <span className={css.badgeDot} aria-hidden="true" />
50
+ <span className={css.badgeHost}>{target.host}</span>
51
+ <span className={css.badgeSeparator} aria-hidden="true">{' · '}</span>
52
+ <span className={css.badgeState}>{state}</span>
53
+ </span>
54
+ )
55
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The create dialog's own rows: pin this new card to a remote target before it
3
+ * exists, instead of creating it untargeted and opening its detail seat.
4
+ *
5
+ * The seat renders nothing at all unless the provider can actually run the card:
6
+ * the extension's own switch is followed by the seat registration itself (the
7
+ * board drops every seat this provider owns when the switch goes off), and the
8
+ * host half is proved mounted by a published summary having arrived. A
9
+ * deployment that ships `dsh-ssh` disabled therefore contributes no rows here —
10
+ * the same judgement the detail seat makes when it says which plugin to enable,
11
+ * minus the sentence: creating a card has nothing to do with SSH, and a dialog
12
+ * about a card is no place to explain a missing host half.
13
+ *
14
+ * The default is no target at all: an unchecked switch that expands into the
15
+ * same field set the detail seat renders, starts from the provider's published
16
+ * defaults, and reports the draft this card will carry on every change. Invalid
17
+ * input is never reported — the board would otherwise store a target this build
18
+ * cannot read back — and its refusal lands under the field that carries it.
19
+ *
20
+ * @module dsh-task-board-ssh/client/ssh/compose-section
21
+ */
22
+ import { useEffect, useId, useMemo, useState } from 'react'
23
+ import { SSH_EXTENSION_ID } from '../../core/action.ts'
24
+ import { composeDraftPayload, parseSshLedgerPayload } from '../../core/ledger.ts'
25
+ import type { SshTarget } from '../../core/target.ts'
26
+ import { t } from '../locales.ts'
27
+ import type { SshComposeSectionProps } from '../seat-props.ts'
28
+ import { draftOf, targetSummaryParts, validateDraft, type SshDraftField, type SshTargetDraft } from './model.ts'
29
+ import { useHostHalfStatus, usePublishedSummary } from './summary.ts'
30
+ import { refusalText, SshTargetFields } from './target-form.tsx'
31
+ import css from '../ssh.module.css'
32
+
33
+ /** Short plugin name the semantic attributes carry. */
34
+ const PLUGIN_ATTR = 'task-board-ssh'
35
+
36
+ /** Extract a pinned SSH target from a duplicated card's integrations container. */
37
+ function initialTargetFrom(integrations: Readonly<Record<string, unknown>> | undefined): SshTarget | undefined {
38
+ const raw = integrations?.[SSH_EXTENSION_ID]
39
+ if (raw === undefined) return undefined
40
+ const parsed = parseSshLedgerPayload(raw)
41
+ return parsed.ok ? parsed.value.target : undefined
42
+ }
43
+
44
+ /**
45
+ * Render the SSH provider's new-card seat.
46
+ * @param props - the board's draft channel, optional duplicate source and submit counter.
47
+ * @returns the picker while the host half is mounted, nothing otherwise.
48
+ */
49
+ export function SshComposeSection({ contribute, initialIntegrations, submitAttempt = 0 }: SshComposeSectionProps) {
50
+ const summary = usePublishedSummary()
51
+ const hostHalf = useHostHalfStatus()
52
+ const [initialTarget] = useState<SshTarget | undefined>(() => initialTargetFrom(initialIntegrations))
53
+ const [chosen, setChosen] = useState(() => initialTarget !== undefined)
54
+ // Only the reader's own edits live here: until the first one the draft is
55
+ // derived from the duplicated target or whatever the provider publishes, so
56
+ // a summary that arrives with defaults after the first render still prefills.
57
+ const [edited, setEdited] = useState<SshTargetDraft | undefined>(() => (
58
+ initialTarget === undefined ? undefined : draftOf(initialTarget)
59
+ ))
60
+ const [touched, setTouched] = useState<ReadonlySet<SshDraftField>>(() => new Set())
61
+ const defaults = summary?.defaults
62
+ const draft = useMemo(() => edited ?? draftOf(initialTarget, defaults), [edited, initialTarget, defaults])
63
+ const validation = useMemo(() => validateDraft(draft), [draft])
64
+ const fieldsId = `${useId()}-fields`
65
+ const mounted = hostHalf === 'mounted' && summary !== undefined
66
+ const live = chosen && mounted
67
+
68
+ const visibleErrors = useMemo(() => {
69
+ if (submitAttempt > 0) return validation.errors
70
+ const filtered: typeof validation.errors = {}
71
+ for (const [field, issue] of Object.entries(validation.errors) as Array<[SshDraftField, (typeof validation.errors)[SshDraftField]]>) {
72
+ if (issue !== undefined && touched.has(field)) filtered[field] = issue
73
+ }
74
+ return filtered
75
+ }, [validation.errors, touched, submitAttempt])
76
+
77
+ // Report both the payload (when complete) and the summary/blocking error so
78
+ // collapsing "Run Mode" keeps a clear preview and an incomplete target stops
79
+ // "Create and Run" from silently falling back to local execution.
80
+ useEffect(() => {
81
+ if (!live) {
82
+ contribute(SSH_EXTENSION_ID, undefined)
83
+ return
84
+ }
85
+ if (validation.target === undefined) {
86
+ const firstEntry = (Object.entries(validation.errors) as Array<[SshDraftField, (typeof validation.errors)[SshDraftField]]>)
87
+ .find(([, issue]) => issue !== undefined)
88
+ const blocker = firstEntry !== undefined && firstEntry[1] !== undefined
89
+ ? refusalText(firstEntry[0], firstEntry[1])
90
+ : t('detail.error.host')
91
+ contribute(SSH_EXTENSION_ID, undefined, { summary: t('compose.remote'), error: blocker })
92
+ return
93
+ }
94
+ const payload = composeDraftPayload(validation.target, Date.now())
95
+ if (payload === undefined) {
96
+ contribute(SSH_EXTENSION_ID, undefined, { summary: t('compose.remote'), error: t('detail.rejected') })
97
+ return
98
+ }
99
+ const parts = targetSummaryParts(validation.target)
100
+ const label = validation.target.mode === 'proxy'
101
+ ? `${parts.host} · ${t('detail.mode.proxy')}`
102
+ : `${parts.host} · ${t(`detail.agent.${parts.agent}`)}`
103
+ contribute(SSH_EXTENSION_ID, { ...payload }, { summary: label })
104
+ }, [live, validation, contribute])
105
+
106
+ if (!mounted) return null
107
+
108
+ return (
109
+ <div className={css.compose} data-dsh-plugin={PLUGIN_ATTR} data-dsh-part="compose">
110
+ <label className={css.composeToggle}>
111
+ <input
112
+ type="checkbox"
113
+ checked={chosen}
114
+ aria-controls={live ? fieldsId : undefined}
115
+ onChange={event => { setChosen(event.target.checked) }}
116
+ />
117
+ <span>{t('compose.remote')}</span>
118
+ </label>
119
+ {live && (
120
+ <div className={css.composeFields} id={fieldsId}>
121
+ <SshTargetFields
122
+ draft={draft}
123
+ errors={visibleErrors}
124
+ hosts={summary?.hosts ?? []}
125
+ modeHint={t(draft.mode === 'direct' ? 'detail.modeHintDirect' : 'detail.modeHintProxy')}
126
+ onTouch={field => {
127
+ setTouched(current => {
128
+ if (current.has(field)) return current
129
+ const next = new Set(current)
130
+ next.add(field)
131
+ return next
132
+ })
133
+ }}
134
+ onChange={patch => {
135
+ setEdited({ ...draft, ...patch })
136
+ setTouched(current => {
137
+ const next = new Set(current)
138
+ for (const key of Object.keys(patch)) next.add(key as SshDraftField)
139
+ return next
140
+ })
141
+ }}
142
+ />
143
+ </div>
144
+ )}
145
+ </div>
146
+ )
147
+ }
@@ -0,0 +1,345 @@
1
+ /**
2
+ * The task-detail seat: what this card runs on, where it is, and what it said.
3
+ *
4
+ * The section is built out of three facts the card already holds and one
5
+ * channel it reads: the ledger payload carries the pinned target and the run
6
+ * records, the published summary carries the host list and the log increments,
7
+ * and every write leaves through the board's `dispatch` — the section owns no
8
+ * HTTP surface and no board internal.
9
+ *
10
+ * An untargeted card shows the form and nothing else: there is no run state to
11
+ * report and no log to read, so showing either would be decoration.
12
+ *
13
+ * @module dsh-task-board-ssh/client/ssh/detail-section
14
+ */
15
+ import { useEffect, useRef, useState } from 'react'
16
+ import { SSH_EXTENSION_ID } from '../../core/action.ts'
17
+ import type { TaskBoardExtensionActionRequest } from '../../core/contract.ts'
18
+ import type { SshAgentKind, SshTarget } from '../../core/target.ts'
19
+ import { t, type TaskBoardSshKey } from '../locales.ts'
20
+ import type { SshDetailSectionProps } from '../seat-props.ts'
21
+ import { SshLogBuffer } from './log-buffer.ts'
22
+ import { SshLogView } from './log-view.tsx'
23
+ import { draftOf, isSshRunActive, sshCardView, targetSummaryParts } from './model.ts'
24
+ import { getLastBoardError, useHostHalfStatus, usePublishedSummary } from './summary.ts'
25
+ import { SshTargetForm } from './target-form.tsx'
26
+ import css from '../ssh.module.css'
27
+
28
+ /** Short plugin name the semantic attributes carry. */
29
+ const PLUGIN_ATTR = 'task-board-ssh'
30
+
31
+ /** Upper bound for auto-paging settled remote logs into the detail viewer, in bytes. */
32
+ const AUTO_PAGE_MAX_BYTES = 512 * 1024
33
+
34
+ /** Copy key naming one run phase; the pill and the badge read the same table. */
35
+ function phaseKey(phase: ReturnType<typeof sshCardView>['phase']): TaskBoardSshKey {
36
+ return `run.${phase}`
37
+ }
38
+
39
+ /** Display name of one agent CLI. */
40
+ function agentLabel(kind: SshAgentKind): string {
41
+ return t(`detail.agent.${kind}`)
42
+ }
43
+
44
+ /** One sentence from whatever was thrown, for the section's error line. */
45
+ function messageOf(error: unknown): string {
46
+ return error instanceof Error ? error.message : String(error)
47
+ }
48
+
49
+ /**
50
+ * Render the SSH provider's task-detail section.
51
+ * @param props - the card and the board's action channel.
52
+ * @returns the section in the shape the card's payload asks for.
53
+ */
54
+ export function SshDetailSection({ task, dispatch }: SshDetailSectionProps) {
55
+ const view = sshCardView(task)
56
+ const summary = usePublishedSummary()
57
+ const hostHalf = useHostHalfStatus()
58
+ const [editing, setEditing] = useState(false)
59
+ const [saving, setSaving] = useState(false)
60
+ const [cancelling, setCancelling] = useState(false)
61
+ const [sending, setSending] = useState(false)
62
+ const [queuedLocal, setQueuedLocal] = useState(false)
63
+ const [text, setText] = useState('')
64
+ const [error, setError] = useState<string | undefined>()
65
+ const buffer = useRef<SshLogBuffer | undefined>(undefined)
66
+ if (buffer.current === undefined) buffer.current = new SshLogBuffer()
67
+ const [version, setVersion] = useState(0)
68
+ const awaitingReplay = useRef(false)
69
+ const lastRequestedOffset = useRef(0)
70
+
71
+ const targeted = view.target !== undefined
72
+ const isProxy = view.target?.mode === 'proxy'
73
+ const archived = task.archivedAt !== undefined
74
+ const active = !isProxy && isSshRunActive(view.phase)
75
+ const pending = summary?.logs?.[task.id]
76
+
77
+ // Reset per-card ephemeral state whenever the reused TaskDetail panel
78
+ // switches to another card, preventing cross-card form/draft/error bleed.
79
+ useEffect(() => {
80
+ setEditing(false)
81
+ setSaving(false)
82
+ setCancelling(false)
83
+ setSending(false)
84
+ setQueuedLocal(false)
85
+ setText('')
86
+ setError(undefined)
87
+ }, [task.id])
88
+
89
+ // Close target edit form automatically if a run becomes active or archived.
90
+ useEffect(() => {
91
+ if (active || archived) setEditing(false)
92
+ }, [active, archived])
93
+
94
+ // One write path for every control: the board's action channel, with a
95
+ // refusal (a thrown channel error or a refused commit) surfacing as a line
96
+ // the reader can act on instead of a silent no-op.
97
+ const send = async (request: TaskBoardExtensionActionRequest): Promise<boolean> => {
98
+ setError(undefined)
99
+ try {
100
+ const accepted = await dispatch(request)
101
+ if (!accepted) {
102
+ const hostReason = getLastBoardError()
103
+ setError(hostReason !== undefined && hostReason !== '' ? t('detail.actionFailed', { error: hostReason }) : t('detail.rejected'))
104
+ }
105
+ return accepted
106
+ } catch (cause) {
107
+ setError(t('detail.actionFailed', { error: messageOf(cause) }))
108
+ return false
109
+ }
110
+ }
111
+
112
+ // Opening the panel replays the run's log from its first byte: the buffer is
113
+ // this panel's, and the provider re-reads the remote file from zero on this
114
+ // request. A different run (or a different card) starts a different log.
115
+ useEffect(() => {
116
+ const current = buffer.current
117
+ if (current === undefined) return
118
+ current.reset(view.runId)
119
+ lastRequestedOffset.current = 0
120
+ awaitingReplay.current = targeted && !isProxy && view.runId !== undefined
121
+ setVersion(previous => previous + 1)
122
+ if (!targeted || isProxy) return
123
+ void dispatch({
124
+ extensionId: SSH_EXTENSION_ID,
125
+ action: 'refresh',
126
+ taskId: task.id,
127
+ ...(view.runId === undefined ? {} : { payload: { runId: view.runId } }),
128
+ }).catch(() => {})
129
+ }, [task.id, view.runId, targeted, isProxy])
130
+
131
+ // The provider publishes log increments; ignore stale pre-replay frames with
132
+ // a non-zero offset until the byte-0 replay lands, and auto-page remaining
133
+ // windows of settled >8 KiB logs via `refresh({ runId, offset })`.
134
+ useEffect(() => {
135
+ const current = buffer.current
136
+ if (current === undefined || pending === undefined || isProxy) return
137
+ if (view.runId !== undefined && pending.runId !== view.runId) return
138
+ if (awaitingReplay.current) {
139
+ if (pending.baseOffset > 0) return
140
+ awaitingReplay.current = false
141
+ }
142
+ if (current.append(pending)) setVersion(previous => previous + 1)
143
+ if (
144
+ pending.hasMore === true
145
+ && !active
146
+ && view.runId !== undefined
147
+ && pending.endOffset > lastRequestedOffset.current
148
+ && pending.endOffset < AUTO_PAGE_MAX_BYTES
149
+ ) {
150
+ lastRequestedOffset.current = pending.endOffset
151
+ void dispatch({
152
+ extensionId: SSH_EXTENSION_ID,
153
+ action: 'refresh',
154
+ taskId: task.id,
155
+ payload: { runId: view.runId, offset: pending.endOffset },
156
+ }).catch(() => {})
157
+ }
158
+ }, [pending, isProxy, active, task.id, view.runId, dispatch])
159
+
160
+ // Clear local optimistic queued chip when the run is no longer active or the
161
+ // ledger itself now owns the pending state.
162
+ useEffect(() => {
163
+ if (!active || view.pending !== undefined) setQueuedLocal(false)
164
+ }, [active, view.pending])
165
+
166
+ const hasQueuedFollowUp = view.pending !== undefined || (queuedLocal && active)
167
+
168
+ const saveTarget = async (target: SshTarget): Promise<void> => {
169
+ setSaving(true)
170
+ const accepted = await send({
171
+ extensionId: SSH_EXTENSION_ID,
172
+ action: 'set-target',
173
+ taskId: task.id,
174
+ payload: { target: target as unknown as Record<string, unknown> },
175
+ })
176
+ setSaving(false)
177
+ if (accepted) setEditing(false)
178
+ }
179
+
180
+ const cancelRun = async (): Promise<void> => {
181
+ setCancelling(true)
182
+ await send({ extensionId: SSH_EXTENSION_ID, action: 'cancel', taskId: task.id })
183
+ setCancelling(false)
184
+ }
185
+
186
+ const submitFollowUp = async (): Promise<void> => {
187
+ if (text.trim() === '') return
188
+ setSending(true)
189
+ const accepted = await send({
190
+ extensionId: SSH_EXTENSION_ID,
191
+ action: 'follow-up',
192
+ taskId: task.id,
193
+ payload: { text },
194
+ })
195
+ setSending(false)
196
+ if (!accepted) return
197
+ setText('')
198
+ if (active) setQueuedLocal(true)
199
+ }
200
+
201
+ // A deployment that ships dsh-ssh disabled never mounts this provider's host
202
+ // half, so no summary can ever arrive and every control below would write into
203
+ // a surface nothing serves. The section says what to enable instead.
204
+ if (hostHalf === 'unmounted') {
205
+ return (
206
+ <section className={css.section} data-dsh-plugin={PLUGIN_ATTR} data-dsh-part="unmounted">
207
+ <p className={css.meta}>{t('detail.hostHalfMissing')}</p>
208
+ </section>
209
+ )
210
+ }
211
+
212
+ if (!targeted) {
213
+ if (archived) return null
214
+ return (
215
+ <section className={css.section} data-dsh-plugin={PLUGIN_ATTR} data-dsh-part="target">
216
+ <h4 className={css.sectionTitle}>{t('detail.setTarget')}</h4>
217
+ <SshTargetForm
218
+ key={task.id}
219
+ initial={draftOf(undefined, summary?.defaults)}
220
+ hosts={summary?.hosts ?? []}
221
+ saving={saving}
222
+ submitLabel={saving ? t('detail.saving') : t('detail.save')}
223
+ onSubmit={target => { void saveTarget(target) }}
224
+ />
225
+ {error !== undefined && <p className={css.formError} role="alert">{error}</p>}
226
+ </section>
227
+ )
228
+ }
229
+
230
+ const target = view.target as SshTarget
231
+ const parts = targetSummaryParts(target)
232
+ const lastRun = view.lastRun
233
+ const canEditTarget = !active && !archived
234
+ // Only offer follow-ups on direct cards that are active or have already run
235
+ // (sending a follow-up on a never-run idle card would overwrite the card's
236
+ // initial prompt on first launch).
237
+ const canFollowUp = !isProxy && !archived && (active || lastRun !== undefined)
238
+ // What the run left behind in the workspace it came back from; the provider
239
+ // publishes a count only when there was something to report.
240
+ const untracked = summary?.runs?.find(run => run.taskId === task.id)?.untrackedFiles ?? 0
241
+ return (
242
+ <section className={css.section} data-dsh-plugin={PLUGIN_ATTR} data-dsh-part="run">
243
+ <div className={css.head}>
244
+ <h4 className={css.sectionTitle}>{t('detail.target')}</h4>
245
+ {!isProxy && (
246
+ <span className={css.statePill} data-run={view.phase}>{t(phaseKey(view.phase))}</span>
247
+ )}
248
+ {canEditTarget && (
249
+ <button type="button" className={css.linkButton} onClick={() => setEditing(current => !current)}>
250
+ {t(editing ? 'detail.cancelEdit' : 'detail.editTarget')}
251
+ </button>
252
+ )}
253
+ </div>
254
+ {!editing && (
255
+ <p className={css.targetLine} title={parts.workspace}>
256
+ {t('detail.targetSummary', {
257
+ host: parts.host,
258
+ agent: isProxy ? t('detail.mode.proxy') : agentLabel(parts.agent),
259
+ workspace: parts.workspace,
260
+ })}
261
+ </p>
262
+ )}
263
+ {!editing && isProxy && <p className={css.meta}>{t('detail.modeHintProxy')}</p>}
264
+
265
+ {editing && canEditTarget && (
266
+ <SshTargetForm
267
+ key={`${task.id}:edit`}
268
+ initial={draftOf(target, summary?.defaults)}
269
+ hosts={summary?.hosts ?? []}
270
+ unknownHost={(summary?.hosts ?? []).some(host => host.alias === target.host) ? undefined : target.host}
271
+ saving={saving}
272
+ submitLabel={saving ? t('detail.saving') : t('detail.save')}
273
+ onCancel={() => setEditing(false)}
274
+ onSubmit={next => { void saveTarget(next) }}
275
+ />
276
+ )}
277
+
278
+ {!isProxy && !active && lastRun?.error !== undefined && <p className={css.formError}>{lastRun.error}</p>}
279
+ {!isProxy && lastRun?.branch !== undefined && <p className={css.meta}>{t('detail.branch', { branch: lastRun.branch })}</p>}
280
+ {!isProxy && untracked > 0 && <p className={css.meta}>{t('detail.untrackedFiles', { count: String(untracked) })}</p>}
281
+ {!isProxy && !active && lastRun?.summary !== undefined && lastRun.summary !== '' && (
282
+ <p className={css.summary} title={lastRun.summary}>{lastRun.summary}</p>
283
+ )}
284
+
285
+ {!isProxy && (
286
+ <SshLogView
287
+ buffer={buffer.current as SshLogBuffer}
288
+ version={version}
289
+ live={view.phase === 'running'}
290
+ resetKey={`${task.id}:${view.runId ?? ''}`}
291
+ labels={{
292
+ empty: t('detail.logEmpty'),
293
+ truncated: t('detail.logTruncated'),
294
+ latest: t('detail.logLatest'),
295
+ name: t('detail.log'),
296
+ }}
297
+ />
298
+ )}
299
+
300
+ {(canFollowUp || (!isProxy && active && !archived)) && (
301
+ <div className={css.actions}>
302
+ {canFollowUp && (
303
+ <textarea
304
+ className={css.followUp}
305
+ aria-label={t('detail.followUp')}
306
+ placeholder={t('detail.followUpPlaceholder')}
307
+ rows={2}
308
+ value={text}
309
+ disabled={sending}
310
+ onChange={event => setText(event.target.value)}
311
+ onKeyDown={event => {
312
+ if (event.key === 'Enter' && !event.shiftKey) {
313
+ event.preventDefault()
314
+ void submitFollowUp()
315
+ }
316
+ }}
317
+ />
318
+ )}
319
+ <div className={css.actionRow}>
320
+ {hasQueuedFollowUp && <span className={css.queuedChip}>{t('detail.followUpQueued')}</span>}
321
+ {active && !archived && (
322
+ <button type="button" className={css.ghostButton} onClick={() => { void cancelRun() }} disabled={cancelling}>
323
+ {t(cancelling ? 'detail.cancelling' : 'detail.cancel')}
324
+ </button>
325
+ )}
326
+ {canFollowUp && (
327
+ <button
328
+ type="button"
329
+ className={css.primaryButton}
330
+ onClick={() => { void submitFollowUp() }}
331
+ disabled={sending || text.trim() === ''}
332
+ >
333
+ {t('detail.followUpSend')}
334
+ </button>
335
+ )}
336
+ </div>
337
+ {error !== undefined && <p className={css.formError} role="alert">{error}</p>}
338
+ </div>
339
+ )}
340
+ {!canFollowUp && !(active && !archived) && error !== undefined && (
341
+ <p className={css.formError} role="alert">{error}</p>
342
+ )}
343
+ </section>
344
+ )
345
+ }