@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,299 @@
1
+ /**
2
+ * What a card's SSH payload means, derived as pure functions.
3
+ *
4
+ * Every predicate the card badge and the detail section consult lives here, and
5
+ * none of them reads a clock, issues a request, or allocates more than the
6
+ * record it was handed: the badge renders on every card of every column on
7
+ * every mirror frame, so "cheap" is a property the tests pin rather than an
8
+ * intention. The reader is deliberately lenient — one unreadable field costs
9
+ * that field, never the card's whole account — because the payload arrives from
10
+ * a host half that may be a version ahead of this browser bundle.
11
+ *
12
+ * @module dsh-task-board-ssh/client/ssh/model
13
+ */
14
+ import { SSH_INTEGRATION_KEY } from '../../core/ledger.ts'
15
+ import { parseSshRunRecord, parseSshTarget } from '../../core/target.ts'
16
+ import type {
17
+ SshAgentKind,
18
+ SshExecutionMode,
19
+ SshRunPhase,
20
+ SshRunRecord,
21
+ SshTarget,
22
+ SshValidationIssue,
23
+ SshWorkspaceKind,
24
+ } from '../../core/target.ts'
25
+ import type { TaskRecord } from '../../core/task-record.ts'
26
+
27
+ /** The phase a card shows when it has no run at all. */
28
+ export type SshCardPhase = 'idle' | SshRunPhase
29
+
30
+ /** Everything the seats derive from one card. */
31
+ export interface SshCardView {
32
+ /** The target the card pins, absent when it pins none. */
33
+ target?: SshTarget
34
+ /** The run currently in flight, when there is one. */
35
+ activeRun?: SshRunRecord
36
+ /** The newest finished run, when the card has run before. */
37
+ lastRun?: SshRunRecord
38
+ /** Phase the card presents: the active run's, else the newest run's, else idle. */
39
+ phase: SshCardPhase
40
+ /** Run the phase belongs to, absent while the card has never run. */
41
+ runId?: string
42
+ /** Queued follow-up / rework instruction waiting on the ledger, when any. */
43
+ pending?: 'follow-up' | 'rework'
44
+ }
45
+
46
+ /** Versions of the stored payload this reader understands. */
47
+ const READABLE_PAYLOAD_VERSIONS = new Set([1])
48
+
49
+ /** Whether a value is a plain object (not an array, not null). */
50
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
51
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
52
+ }
53
+
54
+ /** One card with nothing pinned. */
55
+ const NO_VIEW: SshCardView = { phase: 'idle' }
56
+
57
+ /**
58
+ * Read a card's SSH payload leniently.
59
+ *
60
+ * The container is accepted at a version this reader knows; a payload stamped
61
+ * with a version it does not know is refused whole, exactly as the ledger's own
62
+ * parser refuses it, because guessing at a future shape is worse than showing
63
+ * an untargeted card. Inside a readable container each record is parsed on its
64
+ * own, so one corrupt run never hides the target or the other runs.
65
+ * @param task - card to read.
66
+ * @returns the parsed pieces, or undefined when the card carries no readable payload.
67
+ */
68
+ export function readSshLedger(task: TaskRecord): { target?: SshTarget, activeRun?: SshRunRecord, history: SshRunRecord[], pending?: 'follow-up' | 'rework' } | undefined {
69
+ const raw = task.integrations?.[SSH_INTEGRATION_KEY]
70
+ if (!isPlainObject(raw)) return undefined
71
+ if (typeof raw.version === 'number' && !READABLE_PAYLOAD_VERSIONS.has(raw.version)) return undefined
72
+ const target = parseSshTarget(raw.target)
73
+ const activeRun = parseSshRunRecord(raw.activeRun)
74
+ const history: SshRunRecord[] = []
75
+ if (Array.isArray(raw.history)) {
76
+ for (const entry of raw.history) {
77
+ const parsed = parseSshRunRecord(entry)
78
+ if (parsed.ok) history.push(parsed.value)
79
+ }
80
+ }
81
+ const pendingKind = isPlainObject(raw.pending) && (raw.pending.kind === 'follow-up' || raw.pending.kind === 'rework')
82
+ ? raw.pending.kind
83
+ : undefined
84
+ return {
85
+ ...(target.ok ? { target: target.value } : {}),
86
+ ...(activeRun.ok ? { activeRun: activeRun.value } : {}),
87
+ ...(pendingKind === undefined ? {} : { pending: pendingKind }),
88
+ history,
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Derive everything the card badge and the detail section show.
94
+ *
95
+ * Pure and allocation-light by contract: at most one record copy from the
96
+ * lenient reader, no request, no clock.
97
+ * @param task - card to derive.
98
+ * @returns the view; {@link NO_VIEW} when the card pins nothing.
99
+ */
100
+ export function sshCardView(task: TaskRecord): SshCardView {
101
+ const ledger = readSshLedger(task)
102
+ if (ledger === undefined) return NO_VIEW
103
+ const lastRun = ledger.history.length > 0 ? ledger.history[ledger.history.length - 1] : undefined
104
+ const from = ledger.activeRun ?? lastRun
105
+ const view: SshCardView = { phase: from?.phase ?? 'idle' }
106
+ if (ledger.target !== undefined) view.target = ledger.target
107
+ if (ledger.activeRun !== undefined) view.activeRun = ledger.activeRun
108
+ if (lastRun !== undefined) view.lastRun = lastRun
109
+ if (from !== undefined) view.runId = from.runId
110
+ if (ledger.pending !== undefined) view.pending = ledger.pending
111
+ return view
112
+ }
113
+
114
+ /**
115
+ * Whether a card pins a target at all.
116
+ * @param task - card to test.
117
+ * @returns true when the card's payload carries a readable target.
118
+ */
119
+ export function isSshTargeted(task: TaskRecord): boolean {
120
+ return sshCardView(task).target !== undefined
121
+ }
122
+
123
+ /**
124
+ * Whether a phase means a run is under way.
125
+ * @param phase - phase to test.
126
+ * @returns true for queued and running.
127
+ */
128
+ export function isSshRunActive(phase: SshCardPhase): boolean {
129
+ return phase === 'queued' || phase === 'running'
130
+ }
131
+
132
+ /** Every field the target form edits, in tab order. */
133
+ export type SshDraftField =
134
+ | 'mode'
135
+ | 'host'
136
+ | 'agent'
137
+ | 'agentCommand'
138
+ | 'agentResumeCommand'
139
+ | 'workspaceKind'
140
+ | 'workspacePath'
141
+ | 'gitSource'
142
+ | 'repositoryUrl'
143
+ | 'baseBranch'
144
+ | 'workspaceId'
145
+
146
+ /** The target form's whole state, as strings: a form holds text, not a target. */
147
+ export interface SshTargetDraft {
148
+ mode: SshExecutionMode
149
+ host: string
150
+ agent: SshAgentKind
151
+ agentCommand: string
152
+ agentResumeCommand: string
153
+ workspaceKind: SshWorkspaceKind
154
+ gitSource: 'url' | 'workspace'
155
+ workspacePath: string
156
+ repositoryUrl: string
157
+ baseBranch: string
158
+ workspaceId: string
159
+ }
160
+
161
+ /** What a save attempt produced: a target, or the field that refused it. */
162
+ export interface SshDraftValidation {
163
+ /** The parsed target, present only when nothing was refused. */
164
+ target?: SshTarget
165
+ /** First refusal per field, keyed by the field the form highlights. */
166
+ errors: Partial<Record<SshDraftField, SshValidationIssue>>
167
+ /** Every refusal, in the parser's order. */
168
+ issues: readonly SshValidationIssue[]
169
+ }
170
+
171
+ /**
172
+ * Map one parser path onto the form field that carries it.
173
+ * @param path - dotted path the core parser reported.
174
+ * @returns the field, or undefined for a path the form cannot address.
175
+ */
176
+ function fieldOfIssue(path: string): SshDraftField | undefined {
177
+ if (path === 'mode') return 'mode'
178
+ if (path === 'host') return 'host'
179
+ if (path === 'agent' || path === 'agent.kind') return 'agent'
180
+ if (path === 'agent.command') return 'agentCommand'
181
+ if (path === 'agent.resumeCommand') return 'agentResumeCommand'
182
+ if (path === 'workspace' || path === 'workspace.kind') return 'workspaceKind'
183
+ if (path === 'workspace.path') return 'workspacePath'
184
+ if (path === 'workspace.source' || path === 'workspace.source.kind') return 'gitSource'
185
+ if (path === 'workspace.source.url') return 'repositoryUrl'
186
+ if (path === 'workspace.source.base') return 'baseBranch'
187
+ if (path === 'workspace.source.workspaceId') return 'workspaceId'
188
+ return undefined
189
+ }
190
+
191
+ /**
192
+ * Build the wire shape a draft describes, leaving out the fields the chosen
193
+ * mode and workspace kind do not use.
194
+ *
195
+ * Leaving them out is what makes the parser's verdict match what the form
196
+ * showed: a hidden field can neither pass nor fail.
197
+ * @param draft - the form's state.
198
+ * @returns a candidate target for {@link parseSshTarget}.
199
+ */
200
+ export function draftToTarget(draft: SshTargetDraft): Record<string, unknown> {
201
+ // Proxy mode runs in a local DSH session and does not execute a remote agent
202
+ // CLI or upload local workspace bundles; normalize hidden fields so they can
203
+ // never block validation or store misleading config.
204
+ const agent: Record<string, unknown> = draft.mode === 'proxy' ? { kind: 'dsh' } : { kind: draft.agent }
205
+ if (draft.mode !== 'proxy' && draft.agent === 'custom') {
206
+ agent.command = draft.agentCommand
207
+ if (draft.agentResumeCommand.trim() !== '') agent.resumeCommand = draft.agentResumeCommand
208
+ }
209
+ let workspace: Record<string, unknown>
210
+ if (draft.workspaceKind === 'in-place') {
211
+ workspace = { kind: 'in-place', path: draft.workspacePath }
212
+ } else if (draft.mode === 'proxy' || draft.gitSource === 'url') {
213
+ const source: Record<string, unknown> = { kind: 'url', url: draft.repositoryUrl }
214
+ if (draft.baseBranch.trim() !== '') source.base = draft.baseBranch
215
+ workspace = { kind: 'git', source }
216
+ } else {
217
+ workspace = { kind: 'git', source: { kind: 'workspace', workspaceId: draft.workspaceId } }
218
+ }
219
+ return { mode: draft.mode, host: draft.host, agent, workspace }
220
+ }
221
+
222
+ /**
223
+ * Validate a draft through the frozen parser, addressing refusals per field.
224
+ * @param draft - the form's state.
225
+ * @param parse - target parser; defaults to the frozen core parser.
226
+ * @returns the target, or the refusals keyed by field.
227
+ */
228
+ export function validateDraft(
229
+ draft: SshTargetDraft,
230
+ parse: (value: unknown) => { ok: true, value: SshTarget } | { ok: false, errors: readonly SshValidationIssue[] } = parseSshTarget,
231
+ ): SshDraftValidation {
232
+ const parsed = parse(draftToTarget(draft))
233
+ if (parsed.ok) return { target: parsed.value, errors: {}, issues: [] }
234
+ const errors: Partial<Record<SshDraftField, SshValidationIssue>> = {}
235
+ for (const issue of parsed.errors) {
236
+ const field = fieldOfIssue(issue.path)
237
+ if (field !== undefined && errors[field] === undefined) errors[field] = issue
238
+ }
239
+ return { errors, issues: parsed.errors }
240
+ }
241
+
242
+ /**
243
+ * Read a card's form state out of its target, filling the rest from defaults.
244
+ * @param target - the pinned target, when the card has one.
245
+ * @param defaults - the published defaults, when the provider publishes any.
246
+ * @returns the draft the form opens with.
247
+ */
248
+ export function draftOf(target: SshTarget | undefined, defaults?: { host?: string, mode?: SshExecutionMode, agent?: SshAgentKind, workspace?: SshWorkspaceKind }): SshTargetDraft {
249
+ const draft: SshTargetDraft = {
250
+ mode: defaults?.mode ?? 'direct',
251
+ host: defaults?.host ?? '',
252
+ agent: defaults?.agent ?? 'dsh',
253
+ agentCommand: '',
254
+ agentResumeCommand: '',
255
+ workspaceKind: defaults?.workspace ?? 'in-place',
256
+ gitSource: 'url',
257
+ workspacePath: '',
258
+ repositoryUrl: '',
259
+ baseBranch: '',
260
+ workspaceId: '',
261
+ }
262
+ if (target === undefined) return draft
263
+ draft.mode = target.mode
264
+ draft.host = target.host
265
+ draft.agent = target.agent.kind
266
+ if (target.agent.command !== undefined) draft.agentCommand = target.agent.command
267
+ if (target.agent.resumeCommand !== undefined) draft.agentResumeCommand = target.agent.resumeCommand
268
+ draft.workspaceKind = target.workspace.kind
269
+ if (target.workspace.kind === 'in-place') {
270
+ draft.workspacePath = target.workspace.path
271
+ return draft
272
+ }
273
+ if (target.workspace.source.kind === 'url') {
274
+ draft.gitSource = 'url'
275
+ draft.repositoryUrl = target.workspace.source.url
276
+ draft.baseBranch = target.workspace.source.base ?? ''
277
+ return draft
278
+ }
279
+ draft.gitSource = 'workspace'
280
+ draft.workspaceId = target.workspace.source.workspaceId
281
+ return draft
282
+ }
283
+
284
+ /**
285
+ * One line describing a pinned target, for the detail summary.
286
+ *
287
+ * The host, the agent and the workspace are three facts of one sentence, so
288
+ * they stay three template values rather than three labelled rows.
289
+ * @param target - the pinned target.
290
+ * @returns the pieces the caller interpolates.
291
+ */
292
+ export function targetSummaryParts(target: SshTarget): { host: string, agent: SshAgentKind, workspace: string } {
293
+ const workspace = target.workspace.kind === 'in-place'
294
+ ? target.workspace.path
295
+ : target.workspace.source.kind === 'url'
296
+ ? target.workspace.source.url
297
+ : target.workspace.source.workspaceId
298
+ return { host: target.host, agent: target.agent.kind, workspace }
299
+ }