@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,418 @@
1
+ /**
2
+ * The run engine: launch interception, per-host admission, remote polling,
3
+ * reconciliation, follow-up and cancellation for one board mount.
4
+ *
5
+ * One card, one run at a time, and the card's own stored payload is the whole
6
+ * state: what it pins, which run it waits on and what it already did. That is
7
+ * what lets the local host disappear mid-run — the remote process keeps going
8
+ * under `setsid nohup`, and a Host that starts again reads the same payloads and
9
+ * picks every run back up (reconciliation), closes the ones that finished while
10
+ * it was away exactly once, and keeps polling the ones still running.
11
+ *
12
+ * Two board seams are load-bearing and both are probed, never assumed:
13
+ * `launch.intercept` takes a card over before a session exists (direct mode) or
14
+ * adds the preamble a local session starts with (proxy mode), and the board's
15
+ * action seat writes the verdict back through `record-external-outcome`. A board
16
+ * revision that serves neither still gets this extension mounted: its tools
17
+ * answer, its polls stop, and the reason is logged.
18
+ *
19
+ * @module dsh-task-board-ssh/host/engine
20
+ */
21
+ import { type SshAgentCommand, type SshAgentRunInput, type SshCustomTemplates } from '../core/adapters/index.ts';
22
+ import type { DshSshHost, DshSshService, TaskBoardExtensionHost } from '../core/contract.ts';
23
+ import { type SshAgentKind, type SshAgentTarget, type SshRunPhase, type SshRunRecord, type SshTarget } from '../core/target.ts';
24
+ import { type BoardActionSeat } from './board.ts';
25
+ import { type HostSshPayload } from './payload.ts';
26
+ import type { SshProviderSettings } from './settings.ts';
27
+ import type { HostTimerFace } from './timers.ts';
28
+ import { type SshWorkspaceStrategyResolver } from './workspace-seam.ts';
29
+ /** Poll cadence when a deployment configures none, in milliseconds. */
30
+ export declare const DEFAULT_POLL_INTERVAL_MS = 2000;
31
+ /** Consecutive unreadable polls after which a run is recorded as lost. */
32
+ export declare const LOST_AFTER_FAILURES = 3;
33
+ /** What the engine needs from its mount; every member is injectable so a spec can pin it. */
34
+ export interface SshRunEngineOptions {
35
+ /** The board's capability face for this extension. */
36
+ host: TaskBoardExtensionHost;
37
+ /** `dsh-ssh`'s forwarder: the only way this package reaches a remote host. */
38
+ ssh: DshSshService;
39
+ /** Timer seat the poll cadence runs on. */
40
+ timers: HostTimerFace;
41
+ /** Live configuration of this mount, read at use time. */
42
+ settings: () => SshProviderSettings;
43
+ /** The board's in-process action seat, resolved per call so a late one is honoured. */
44
+ seat?: () => BoardActionSeat | undefined;
45
+ /** Placement strategies; absent means this deployment prepares no working directory. */
46
+ workspaces?: SshWorkspaceStrategyResolver;
47
+ /**
48
+ * Resolve a local workspace id to the repository root a git run bundles.
49
+ *
50
+ * The engine holds no workspace face of its own (this package reaches the
51
+ * deployment only through `taskBoard` and `dshSsh`), so the mount supplies the
52
+ * lookup. Absent means a run pinned to a local workspace fails with the
53
+ * strategy's own "repository was not resolved" refusal instead of guessing a
54
+ * path.
55
+ */
56
+ localRepository?: (workspaceId: string) => string | undefined;
57
+ /** Clock (ms epoch). */
58
+ now?: () => number;
59
+ /** Identifier source for request ids. */
60
+ uuid?: () => string;
61
+ /** Poll cadence, in milliseconds. */
62
+ pollIntervalMs?: number;
63
+ /** Ceiling for one remote command, in milliseconds. */
64
+ commandTimeoutMs?: number;
65
+ /** Where a refusal or a failed remote call is reported. */
66
+ log?: (message: string, detail?: unknown) => void;
67
+ }
68
+ /** A reply to a card action or a tool call: a value the caller can act on, never a throw. */
69
+ export type SshEngineReply = {
70
+ ok: true;
71
+ taskId: string;
72
+ runId?: string;
73
+ phase?: SshRunPhase;
74
+ message?: string;
75
+ } | {
76
+ ok: false;
77
+ code: string;
78
+ error: string;
79
+ };
80
+ /** One card's remote-run state, as a card surface or a model reads it. */
81
+ export interface SshRunStatusView {
82
+ /** Card the view is about. */
83
+ taskId: string;
84
+ /** Target the card pins, when it pins one. */
85
+ target?: SshTarget;
86
+ /** Phase of the run in flight. */
87
+ phase?: SshRunPhase;
88
+ /** Run in flight. */
89
+ runId?: string;
90
+ /** Remote exit code, once the run settled. */
91
+ exitCode?: number;
92
+ /** Bytes of the run's log the remote launcher reported. */
93
+ bytes?: number;
94
+ /** Follow-up messages delivered into that run's session. */
95
+ followUps?: number;
96
+ /** Session the run reported, usable to resume it. */
97
+ sessionId?: string;
98
+ /** Summary the agent reported. */
99
+ summary?: string;
100
+ /** Failure text, when the run failed. */
101
+ error?: string;
102
+ /** Runs of this card that already settled, newest last. */
103
+ history: SshRunRecord[];
104
+ /** Whether an instruction waits for the next run. */
105
+ pending?: 'follow-up' | 'rework';
106
+ }
107
+ /** One page of a run's log. */
108
+ export type SshLogPage = {
109
+ ok: true;
110
+ taskId: string;
111
+ runId: string;
112
+ offset: number;
113
+ nextOffset: number;
114
+ bytes: number;
115
+ eof: boolean;
116
+ text: string;
117
+ } | {
118
+ ok: false;
119
+ code: string;
120
+ error: string;
121
+ };
122
+ /**
123
+ * The command templates a target's agent runs with.
124
+ *
125
+ * A deployment's override wins over everything, because it exists precisely to
126
+ * replace what this package would otherwise run. A custom agent carries its own
127
+ * templates on the target; the three built-in CLIs have none.
128
+ * @param agent - the agent the target pins.
129
+ * @param settings - live configuration.
130
+ * @returns the templates, or undefined when the built-in command line applies.
131
+ */
132
+ export declare function agentTemplates(agent: SshAgentTarget, settings: SshProviderSettings): SshCustomTemplates | undefined;
133
+ /**
134
+ * Whether one agent can continue an earlier session.
135
+ * @param kind - agent CLI kind.
136
+ * @param templates - the templates it runs with, when it has any.
137
+ * @returns true when a follow-up can resume instead of starting fresh.
138
+ */
139
+ export declare function agentResumeSupported(kind: SshAgentKind, templates: SshCustomTemplates | undefined): boolean;
140
+ /**
141
+ * The command line one run executes.
142
+ *
143
+ * A template — a custom agent's own, or a deployment's override for one of the
144
+ * built-in CLIs — replaces the built-in command line entirely, because that is
145
+ * what an override is for: the operator's own words, quoted by the template
146
+ * builder. Without one the agent's own adapter answers.
147
+ * @param input - run facts, including the session to resume when there is one.
148
+ * @param templates - the templates this run executes with, when it has any.
149
+ * @returns the quoted command line.
150
+ */
151
+ export declare function agentCommandLine(input: SshAgentRunInput, templates: SshCustomTemplates | undefined): SshAgentCommand;
152
+ export declare class SshRunEngine {
153
+ private readonly host;
154
+ private readonly ssh;
155
+ private readonly timers;
156
+ private readonly settings;
157
+ private readonly seat;
158
+ private readonly workspaces;
159
+ private readonly localRepository;
160
+ private readonly now;
161
+ private readonly uuid;
162
+ private readonly pollIntervalMs;
163
+ private readonly log;
164
+ private readonly remote;
165
+ /** Runs this process follows, keyed by card id: a card has at most one. */
166
+ private readonly jobs;
167
+ /** Known runs per card (including pre-restart history), so card deletion cleans up all remote dirs/worktrees. */
168
+ private readonly known;
169
+ /** Hosts whose admission pass is already running. */
170
+ private readonly pumping;
171
+ /** Hosts that asked for another admission pass while one was running. */
172
+ private readonly pumpAgain;
173
+ /** Cards whose settlement is in progress, so a board echo does not read as a cancel. */
174
+ private readonly settling;
175
+ /** Runs a person asked to cancel, so their settlement writes no verdict. */
176
+ private readonly cancelRequests;
177
+ /** The log windows this extension publishes; in memory, never in a payload. */
178
+ private readonly logs;
179
+ /**
180
+ * Local files one live run did not receive, keyed by card id.
181
+ *
182
+ * A workspace detail, not a run fact: the frozen run record has no member for
183
+ * it and the ledger keeps the account of runs, so it is carried here from the
184
+ * moment the workspace is prepared until the verdict is written. A Host that
185
+ * restarts mid-run no longer knows it, and that run's verdict then says only
186
+ * what the agent itself reported.
187
+ */
188
+ private readonly untracked;
189
+ private readonly disposers;
190
+ private pollCanceller;
191
+ private polling;
192
+ private disposed;
193
+ constructor(options: SshRunEngineOptions);
194
+ /** Whether the extension is on. Read at use time, so a settings edit binds the next call. */
195
+ enabled(): boolean;
196
+ /**
197
+ * Take over every launch the board routes to this extension, follow board
198
+ * events, and reconcile what the previous process left in flight.
199
+ */
200
+ start(): void;
201
+ /** Stop polling and forget what this process was following. No card data is touched. */
202
+ stop(): void;
203
+ /**
204
+ * React to a volatile settings update (for example raising `perHostCap` or
205
+ * changing defaults): pump every host with waiting runs and publish the new summary.
206
+ */
207
+ onSettingsUpdated(): void;
208
+ /** The hosts this deployment can pin a card to; every field of one is secret-free. */
209
+ hosts(): DshSshHost[];
210
+ /** Resolve one host by alias, or undefined when it is not configured. */
211
+ hostByAlias(alias: string): DshSshHost | undefined;
212
+ /** The card's payload, as this package reads it. */
213
+ payloadOf(taskId: string): HostSshPayload | undefined;
214
+ /** The target a card pins, when it pins one. */
215
+ targetOf(taskId: string): SshTarget | undefined;
216
+ /** One card's remote-run state. */
217
+ status(taskId: string): SshRunStatusView;
218
+ /**
219
+ * Pin (or replace) the target one card runs with.
220
+ *
221
+ * A target naming a host this deployment does not know is refused here instead
222
+ * of failing the card much later with a connection error nobody can place.
223
+ * @param taskId - card to retarget.
224
+ * @param target - the target to pin.
225
+ * @returns the reply the caller renders.
226
+ */
227
+ setTarget(taskId: string, target: SshTarget): SshEngineReply;
228
+ /**
229
+ * Start a card's pinned run now, through the board's own run action so the
230
+ * card reaches the running column the same way the run button puts it there.
231
+ * @param taskId - card to run.
232
+ * @returns the reply the caller renders.
233
+ */
234
+ runNow(taskId: string): SshEngineReply;
235
+ /**
236
+ * Queue one instruction for the card, and drive it into a run.
237
+ *
238
+ * While a run is in flight the instruction waits for the run to settle (there
239
+ * is no channel into a detached remote process). On a settled card it re-enters
240
+ * the launch interceptor through the board's own rerun action, which is what
241
+ * puts the card back in the running column and lets the adapter choose between
242
+ * continuing the session and starting fresh.
243
+ * @param taskId - card to instruct.
244
+ * @param text - the instruction.
245
+ * @param kind - which entry asked.
246
+ * @returns the reply the caller renders.
247
+ */
248
+ instruct(taskId: string, text: string, kind: 'follow-up' | 'rework'): Promise<SshEngineReply>;
249
+ /**
250
+ * Cancel the card's active run and write no verdict.
251
+ * @param taskId - card whose run to stop.
252
+ * @returns the reply the caller renders.
253
+ */
254
+ cancel(taskId: string): SshEngineReply;
255
+ /**
256
+ * Re-read remote state now instead of waiting for the next tick.
257
+ * @param taskId - one card, or undefined for every card this mount follows.
258
+ * @returns the reply the caller renders.
259
+ */
260
+ refresh(taskId?: string, runId?: string, offset?: number): Promise<SshEngineReply>;
261
+ /**
262
+ * Re-read one bounded page of one card's log from `offset` into the pending window.
263
+ * @param taskId - card whose run log to replay.
264
+ * @param runId - a specific run, when the viewer named one.
265
+ * @param offset - byte offset to replay from (defaults to 0).
266
+ */
267
+ private replayLog;
268
+ /**
269
+ * Read one page of a run's log.
270
+ *
271
+ * The log is a remote file read by byte offset, never a stored payload: the
272
+ * ledger keeps the account of a run, not its bytes.
273
+ * @param taskId - card whose run's log to read.
274
+ * @param options - run to read (defaults to the active one), offset and page size.
275
+ * @returns the page, or the refusal that says why there is none.
276
+ */
277
+ readLog(taskId: string, options?: {
278
+ runId?: string;
279
+ offset?: number;
280
+ limit?: number;
281
+ }): Promise<SshLogPage>;
282
+ /** The document this extension publishes into the board snapshot. */
283
+ summary(): Record<string, unknown>;
284
+ /**
285
+ * Build the published document and the log windows it carries.
286
+ *
287
+ * The window section is the one unbounded part of this document, so it is
288
+ * bounded here: SshLogWindows caps one card's window and the section as a
289
+ * whole, and a document that still came out over the body budget drops the
290
+ * section (every window then waits for the next publish rather than being
291
+ * lost or overrunning the board's ceiling).
292
+ * @returns the document and the cards whose window it delivered.
293
+ */
294
+ private buildSummary;
295
+ /**
296
+ * The board's launch gate for one card.
297
+ *
298
+ * Synchronous by contract: the run it opens is recorded here and started on
299
+ * the next microtask, because the ledger commits the running column after this
300
+ * handler returns and a payload write made inside it would be overwritten.
301
+ */
302
+ private intercept;
303
+ /** Queue one run for a card the board just decided to hand over. */
304
+ private openRun;
305
+ /** Record a run id against a card so card deletion cleans up every remote artifact. */
306
+ private rememberRun;
307
+ /** Previous git worktree run id to reuse for a follow-up / rework, when available. */
308
+ private priorWorktreeRunId;
309
+ /** The aliases this mount currently has work for. */
310
+ private aliasesInFlight;
311
+ /** Every linked card with the payload this package understands. */
312
+ private linkedEntries;
313
+ /** Admit queued runs on one host until its ceiling is reached. */
314
+ private pump;
315
+ /** One admission pass over one host. */
316
+ private admit;
317
+ /** Prepare and start one admitted run. */
318
+ private startRun;
319
+ /**
320
+ * Resolve the run's working directory through its placement strategy.
321
+ *
322
+ * The strategy may also report how much of the local work it could not send —
323
+ * a bundle carries commits, not the untracked working tree — and that note is
324
+ * kept rather than dropped: the card publishes it while the run is going and
325
+ * the verdict says it out loud.
326
+ * @param target - the target the card pins.
327
+ * @param runId - run being prepared.
328
+ * @param options - cancellation signal and optional worktree reuse id.
329
+ * @returns the absolute remote directory and the untracked-file note, when any.
330
+ */
331
+ private prepareWorkspace;
332
+ /** The strategy one target's workspace runs through, or a diagnosable refusal. */
333
+ private strategyFor;
334
+ /** Everything a placement strategy needs about one run. */
335
+ private workspaceRun;
336
+ /** One poll pass over every run this process follows. */
337
+ private poll;
338
+ /** Read one run's remote state and act on it. */
339
+ private pollJob;
340
+ /**
341
+ * Read whatever the run's log gained since the last read and hold it for the
342
+ * next publish.
343
+ *
344
+ * Bounded to one window budget per poll so a multi-megabyte burst never hits
345
+ * `dsh-ssh`'s 2 MiB stdout cap.
346
+ * @param taskId - card the run belongs to.
347
+ * @param target - the target the card pins.
348
+ * @param run - the run in flight.
349
+ * @param remoteBytes - log size the launcher just reported.
350
+ */
351
+ private readLogIncrement;
352
+ /**
353
+ * Close one run: read what it produced, put its verdict on the card exactly
354
+ * once, and hand the card's next instruction (if any) back to the launch gate.
355
+ */
356
+ private settle;
357
+ /** The phase one settled run reaches. */
358
+ private phaseOf;
359
+ /**
360
+ * Put one settled run's verdict on the card, exactly once.
361
+ *
362
+ * The verdict travels in the one free-text field an external record has, so
363
+ * everything that belongs with it is composed here: the degradation marker when
364
+ * the run was a fresh one, what the agent reported, and the workspace note when
365
+ * local files stayed behind. The note is reserved room before the agent's own
366
+ * text is cut, so a long summary can never push it out of the record.
367
+ */
368
+ private recordOutcome;
369
+ /** Bring back whatever the run's workspace strategy produced, surfacing collection failures explicitly. */
370
+ private collectWorkspace;
371
+ /** The summary the card's previous run reported, for a run that cannot resume. */
372
+ private previousSummary;
373
+ /**
374
+ * A card that left the running column while its run is live is a cancel
375
+ * request: the remote process is stopped and no verdict is written, because
376
+ * the person moved the card, the person decides what the card says.
377
+ */
378
+ private onStatusChanged;
379
+ /**
380
+ * Cancel one live run, drop any instruction it owed, and write no verdict.
381
+ *
382
+ * A card the provider itself stopped would otherwise sit in the running column
383
+ * with nothing left to observe it, and the detail view offers no cancel button
384
+ * for a settled run: the restore flag is what puts it back where a person can
385
+ * run it again.
386
+ */
387
+ private stopRun;
388
+ /**
389
+ * Put a card the provider stopped back in the todo column.
390
+ *
391
+ * Only acts when the card is STILL in the running column with no newer live
392
+ * run: if the operator already moved the card or started a fresh run while
393
+ * `remote.cancel` waited out SIGTERM, leaving it alone prevents overwriting
394
+ * the manual move or cancelling the newer run.
395
+ * @param taskId - card to move.
396
+ * @param runId - run that was stopped, recorded as the initiating party.
397
+ */
398
+ private restoreToTodo;
399
+ /** A deleted card takes all its remote run directories and git worktrees with it. */
400
+ private onTaskDeleted;
401
+ /** Put a card's waiting instruction back through the board's own rerun action. */
402
+ private reenter;
403
+ /**
404
+ * Pick up what the previous process left behind: a queued run is served in
405
+ * its place in the queue, a running one is polled at once (that is how a run
406
+ * that finished while this Host was down is recorded, once), and a run whose
407
+ * verdict never reached the board is recorded before anything else.
408
+ */
409
+ private reconcile;
410
+ /** Write one card's payload, tolerating a card that vanished under us. */
411
+ private writePayload;
412
+ /** Publish (or refresh) this extension's summary in the board snapshot. */
413
+ private publishSummary;
414
+ /** A run id the remote launcher accepts, ordered by the instant it was requested. */
415
+ private newRunId;
416
+ /** Whether a person asked for this run to stop. */
417
+ private cancelRequested;
418
+ }
@@ -0,0 +1,59 @@
1
+ import { type DshSshService, type TaskBoardExtension } from '../core/contract.ts';
2
+ import type { BoardActionSeat } from './board.ts';
3
+ import { type SshProviderSettings, type SshSettingsWriter } from './settings.ts';
4
+ import type { HostTimerFace } from './timers.ts';
5
+ import type { SshWorkspaceStrategyResolver } from './workspace-seam.ts';
6
+ /** Extension id this provider registers under, and the key of its ledger payload. */
7
+ export declare const SSH_EXTENSION_ID = "ssh";
8
+ /**
9
+ * Actions this package handles on top of the frozen card protocol.
10
+ *
11
+ * The six card actions are the board's own vocabulary and are parsed by
12
+ * `src/core/action.ts`. These three are host-half additions a settings card or a
13
+ * log viewer drives: the log pager (a remote file read by offset, never a new
14
+ * HTTP route) and the configuration read/write pair, whose write goes through the
15
+ * extension's single write path and therefore through `ctx.settings.mutate`.
16
+ */
17
+ export declare const SSH_HOST_ACTIONS: {
18
+ /** Read one page of a run's log by byte offset. */
19
+ readonly readLog: "read-log";
20
+ /** Read the extension's effective settings. */
21
+ readonly setupStatus: "setup-status";
22
+ /** Write the extension's settings through the one write path. */
23
+ readonly setupSave: "setup-save";
24
+ };
25
+ /** Everything the extension needs from its mount. */
26
+ export interface SshExtensionOptions {
27
+ /** The `dshSsh` forwarder every remote operation goes through. */
28
+ ssh: DshSshService;
29
+ /** Live configuration, read at use time. */
30
+ settings: () => SshProviderSettings;
31
+ /** The one configuration write path. */
32
+ settingsWriter: SshSettingsWriter;
33
+ /** Timer seat the poll cadence runs on. */
34
+ timers: HostTimerFace;
35
+ /** The board's in-process action seat, resolved per call so a late one is honoured. */
36
+ seat?: () => BoardActionSeat | undefined;
37
+ /** Placement strategies, when this deployment serves any. */
38
+ workspaces?: SshWorkspaceStrategyResolver;
39
+ /** Resolve a local workspace id to the repository root a git run bundles. */
40
+ localRepository?: (workspaceId: string) => string | undefined;
41
+ /** Clock (ms epoch). */
42
+ now?: () => number;
43
+ /** Identifier source for request ids and run ids. */
44
+ uuid?: () => string;
45
+ /** Poll cadence, in milliseconds. */
46
+ pollIntervalMs?: number;
47
+ /** Ceiling for one remote command, in milliseconds. */
48
+ commandTimeoutMs?: number;
49
+ /** Where a refusal or a failed remote call is reported. */
50
+ log?: (message: string, detail?: unknown) => void;
51
+ /** Register a hook invoked whenever volatile settings change while mounted. */
52
+ onSettingsHook?: (notify: (() => void) | undefined) => void;
53
+ }
54
+ /**
55
+ * Build the SSH provider extension.
56
+ * @param options - the mount's faces, settings and clock.
57
+ * @returns the extension the board registers.
58
+ */
59
+ export declare function createSshExtension(options: SshExtensionOptions): TaskBoardExtension;
@@ -0,0 +1,135 @@
1
+ /**
2
+ * The log windows this extension publishes into the board snapshot.
3
+ *
4
+ * A card's log is a file on the remote host, never part of the card: the ledger
5
+ * payload is bounded at 64 KiB and an agent's stream is unbounded, so the bytes
6
+ * travel one way only — read by byte offset over the dshSsh face, and delivered
7
+ * to the browser through the extension's published summary, which the board
8
+ * hands the client mirror as-is.
9
+ *
10
+ * The browser has no other byte channel: a dispatched action answers a boolean,
11
+ * so the log viewer decodes the windows below. Every window names the exact byte
12
+ * interval its text covers, [baseOffset, endOffset), so a decoder appends it
13
+ * without guessing, and a window that could not carry everything waiting is
14
+ * marked truncated instead of dropping the rest: the next publish carries the
15
+ * continuation, starting exactly where the previous one stopped.
16
+ *
17
+ * Windows are per card and in memory. Nothing here is ever written into a card's
18
+ * payload.
19
+ *
20
+ * @module dsh-task-board-ssh/host/logs
21
+ */
22
+ /** Largest window one card carries in a single publish, in bytes. */
23
+ export declare const LOG_WINDOW_BUDGET_BYTES: number;
24
+ /** Largest window section one publish carries across all cards, in bytes. */
25
+ export declare const PUBLISH_LOG_BUDGET_BYTES: number;
26
+ /**
27
+ * Budget for the whole published summary, in bytes of its JSON serialization.
28
+ *
29
+ * The board validates a published summary with the same predicate it applies to
30
+ * any extension payload, so the hard ceiling is TASK_BOARD_PAYLOAD_LIMIT_BYTES
31
+ * (64 KiB). This budget stays well under it, which leaves room for the host
32
+ * list, the defaults and the runs the same summary carries.
33
+ */
34
+ export declare const PUBLISH_BODY_LIMIT_BYTES: number;
35
+ /** One window a browser decodes at a known byte interval. */
36
+ export interface SshLogWindow {
37
+ /** Run the text belongs to. */
38
+ runId: string;
39
+ /** Byte offset of the first delivered byte. */
40
+ baseOffset: number;
41
+ /** Byte offset just past the last delivered byte. */
42
+ endOffset: number;
43
+ /** The delivered bytes, as text. */
44
+ text: string;
45
+ /** Whether more bytes are waiting after `endOffset` (carried in a later publish/page). */
46
+ truncated?: boolean;
47
+ /** Explicit continuation signal distinguishing trailing unread bytes from skipped leading bytes. */
48
+ hasMore?: boolean;
49
+ }
50
+ /** Byte length of a text. */
51
+ export declare function byteLength(text: string): number;
52
+ /**
53
+ * The longest prefix of a text that fits a byte budget, never splitting a
54
+ * character (which would make the delivered byte count lie).
55
+ * @param text - the text to cut.
56
+ * @param budget - largest prefix, in UTF-8 bytes.
57
+ * @returns the prefix and its byte length.
58
+ */
59
+ export declare function takeWithinBudget(text: string, budget: number): {
60
+ text: string;
61
+ bytes: number;
62
+ };
63
+ /**
64
+ * The part of a text that starts at one UTF-8 byte offset.
65
+ * @param text - the whole text.
66
+ * @param from - byte offset to start at.
67
+ * @returns the remainder.
68
+ */
69
+ export declare function sliceFromByte(text: string, from: number): string;
70
+ /** One publish's window section and the cards it delivered for. */
71
+ export interface SshLogDelivery {
72
+ /** Windows keyed by card id, in the shape the client decodes. */
73
+ logs: Record<string, SshLogWindow>;
74
+ /** Cards whose window this publish carried; they are cleared afterwards. */
75
+ delivered: string[];
76
+ }
77
+ export declare class SshLogWindows {
78
+ private readonly states;
79
+ private readonly perCardBudget;
80
+ private readonly perPublishBudget;
81
+ constructor(perCardBudget?: number, perPublishBudget?: number);
82
+ /** Forget every window (the extension stopped, or a host went away). */
83
+ clear(): void;
84
+ /** Drop one card's window (called when the card is deleted). */
85
+ remove(taskId: string): void;
86
+ /**
87
+ * Start following one run's log from an offset.
88
+ *
89
+ * Adopting a run this process already follows is a no-op, which is what keeps
90
+ * a poll from resetting the offset the card's payload recorded: a Host that
91
+ * comes back does not re-send bytes the browser already holds, and the
92
+ * viewer's own replay is the way to ask for everything from zero.
93
+ * @param taskId - card the run belongs to.
94
+ * @param runId - run whose log is followed.
95
+ * @param startOffset - first byte the next read asks for.
96
+ */
97
+ adopt(taskId: string, runId: string, startOffset: number): void;
98
+ /** The offset the next read for one card starts at, when it is followed. */
99
+ cursor(taskId: string, runId: string): number | undefined;
100
+ /**
101
+ * Add the bytes read for one card to its pending window.
102
+ * @param taskId - card the run belongs to.
103
+ * @param runId - run whose log was read.
104
+ * @param from - byte offset the read started at.
105
+ * @param text - the bytes read from `from`.
106
+ * @param remoteBytes - optional total remote log size when known (detects trailing unread bytes on bounded reads).
107
+ */
108
+ push(taskId: string, runId: string, from: number, text: string, remoteBytes?: number): void;
109
+ /**
110
+ * Replace one card's pending window with a replay from an offset.
111
+ * @param taskId - card the run belongs to.
112
+ * @param runId - run whose log was read.
113
+ * @param from - byte offset the replay starts at (zero for a full replay).
114
+ * @param text - the bytes read from `from`.
115
+ * @param hasMore - optional explicit flag when caller read a bounded window and more bytes exist past it.
116
+ */
117
+ replay(taskId: string, runId: string, from: number, text: string, hasMore?: boolean): void;
118
+ /** How many cards hold an unpublished window. */
119
+ pending(): number;
120
+ /**
121
+ * The windows one publish carries, bounded across cards.
122
+ *
123
+ * A card whose window does not fit this publish keeps it: the next publish
124
+ * carries it instead of losing it, and the iteration order is stable, so a
125
+ * backlog drains card by card.
126
+ * @returns the window section and the cards it covered.
127
+ */
128
+ take(): SshLogDelivery;
129
+ /**
130
+ * Clear the windows one publish carried, so the next one carries only what
131
+ * arrived since.
132
+ * @param taskIds - cards the publish covered.
133
+ */
134
+ markDelivered(taskIds: readonly string[]): void;
135
+ }