@linxin666/dsh-client-ui-task-board-ssh 0.0.0-stage → 0.4.21
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.
- package/LICENSE +202 -0
- package/README.i18n.yaml +6 -0
- package/README.md +96 -2
- package/README.zh.md +97 -0
- package/cordis.patch.yml +15 -0
- package/icon.svg +5 -0
- package/lib/client.js +4435 -0
- package/lib/index.js +7082 -0
- package/lib/types/client/PluginSettingsCard.d.ts +255 -0
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/index.d.ts +100 -0
- package/lib/types/client/locales.d.ts +125 -0
- package/lib/types/client/seat-props.d.ts +53 -0
- package/lib/types/client/settings-entry-form.d.ts +49 -0
- package/lib/types/client/settings-form.d.ts +237 -0
- package/lib/types/client/ssh/card-decoration.d.ts +23 -0
- package/lib/types/client/ssh/compose-section.d.ts +7 -0
- package/lib/types/client/ssh/detail-section.d.ts +7 -0
- package/lib/types/client/ssh/extension.d.ts +54 -0
- package/lib/types/client/ssh/log-buffer.d.ts +128 -0
- package/lib/types/client/ssh/log-view.d.ts +37 -0
- package/lib/types/client/ssh/model.d.ts +130 -0
- package/lib/types/client/ssh/settings-section.d.ts +134 -0
- package/lib/types/client/ssh/summary.d.ts +160 -0
- package/lib/types/client/ssh/target-form.d.ts +60 -0
- package/lib/types/core/action.d.ts +89 -0
- package/lib/types/core/adapters/claude.d.ts +15 -0
- package/lib/types/core/adapters/codex.d.ts +15 -0
- package/lib/types/core/adapters/custom.d.ts +29 -0
- package/lib/types/core/adapters/dsh.d.ts +21 -0
- package/lib/types/core/adapters/index.d.ts +25 -0
- package/lib/types/core/adapters/types.d.ts +76 -0
- package/lib/types/core/contract.d.ts +453 -0
- package/lib/types/core/launcher-script.d.ts +13 -0
- package/lib/types/core/launcher.d.ts +153 -0
- package/lib/types/core/ledger.d.ts +123 -0
- package/lib/types/core/shell.d.ts +61 -0
- package/lib/types/core/target.d.ts +149 -0
- package/lib/types/core/task-record.d.ts +74 -0
- package/lib/types/core/workspace.d.ts +74 -0
- package/lib/types/host/board.d.ts +75 -0
- package/lib/types/host/engine.d.ts +563 -0
- package/lib/types/host/extension.d.ts +61 -0
- package/lib/types/host/inspect.d.ts +99 -0
- package/lib/types/host/logs.d.ts +135 -0
- package/lib/types/host/payload.d.ts +75 -0
- package/lib/types/host/prompt.d.ts +44 -0
- package/lib/types/host/queue.d.ts +53 -0
- package/lib/types/host/remote.d.ts +137 -0
- package/lib/types/host/settings.d.ts +149 -0
- package/lib/types/host/timers.d.ts +20 -0
- package/lib/types/host/tools.d.ts +17 -0
- package/lib/types/host/workspace/errors.d.ts +29 -0
- package/lib/types/host/workspace/git.d.ts +108 -0
- package/lib/types/host/workspace/in-place.d.ts +36 -0
- package/lib/types/host/workspace/index.d.ts +28 -0
- package/lib/types/host/workspace/layout.d.ts +62 -0
- package/lib/types/host/workspace/local-git.d.ts +72 -0
- package/lib/types/host/workspace/remote-git.d.ts +111 -0
- package/lib/types/host/workspace/remote.d.ts +85 -0
- package/lib/types/host/workspace/types.d.ts +28 -0
- package/lib/types/host/workspace-seam.d.ts +100 -0
- package/lib/types/index.d.ts +97 -0
- package/lib/types/mount-once.d.ts +55 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +89 -3
- package/src/client/PluginSettingsCard.tsx +838 -0
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/index.ts +195 -0
- package/src/client/locales.ts +257 -0
- package/src/client/seat-props.ts +58 -0
- package/src/client/settings-card.module.css +821 -0
- package/src/client/settings-entry-form.ts +141 -0
- package/src/client/settings-form.ts +529 -0
- package/src/client/ssh/card-decoration.tsx +55 -0
- package/src/client/ssh/compose-section.tsx +147 -0
- package/src/client/ssh/detail-section.tsx +345 -0
- package/src/client/ssh/extension.ts +271 -0
- package/src/client/ssh/log-buffer.ts +224 -0
- package/src/client/ssh/log-view.tsx +149 -0
- package/src/client/ssh/model.ts +299 -0
- package/src/client/ssh/settings-section.tsx +401 -0
- package/src/client/ssh/summary.ts +388 -0
- package/src/client/ssh/target-form.tsx +380 -0
- package/src/client/ssh.module.css +617 -0
- package/src/core/action.ts +270 -0
- package/src/core/adapters/claude.ts +64 -0
- package/src/core/adapters/codex.ts +83 -0
- package/src/core/adapters/custom.ts +88 -0
- package/src/core/adapters/dsh.ts +87 -0
- package/src/core/adapters/index.ts +74 -0
- package/src/core/adapters/types.ts +95 -0
- package/src/core/contract.ts +515 -0
- package/src/core/launcher-script.ts +313 -0
- package/src/core/launcher.ts +283 -0
- package/src/core/ledger.ts +377 -0
- package/src/core/shell.ts +77 -0
- package/src/core/target.ts +420 -0
- package/src/core/task-record.ts +73 -0
- package/src/core/workspace.ts +78 -0
- package/src/host/board.ts +107 -0
- package/src/host/engine.ts +2026 -0
- package/src/host/extension.ts +310 -0
- package/src/host/inspect.ts +264 -0
- package/src/host/logs.ts +297 -0
- package/src/host/payload.ts +134 -0
- package/src/host/prompt.ts +89 -0
- package/src/host/queue.ts +73 -0
- package/src/host/remote.ts +356 -0
- package/src/host/settings.ts +294 -0
- package/src/host/timers.ts +33 -0
- package/src/host/tools.ts +449 -0
- package/src/host/workspace/errors.ts +43 -0
- package/src/host/workspace/git.ts +305 -0
- package/src/host/workspace/in-place.ts +58 -0
- package/src/host/workspace/index.ts +37 -0
- package/src/host/workspace/layout.ts +122 -0
- package/src/host/workspace/local-git.ts +164 -0
- package/src/host/workspace/remote-git.ts +244 -0
- package/src/host/workspace/remote.ts +181 -0
- package/src/host/workspace/types.ts +34 -0
- package/src/host/workspace-seam.ts +132 -0
- package/src/index.ts +243 -0
- package/src/mount-once.ts +142 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { SshAgentTarget, SshTarget } from '../core/target.ts';
|
|
2
|
+
/** Stable refusal codes a target check or a run can answer with. */
|
|
3
|
+
export declare const SSH_PREFLIGHT_CODES: readonly ["host-unreachable", "agent-missing", "path-missing", "permission-required"];
|
|
4
|
+
/** One stable preflight code. */
|
|
5
|
+
export type SshPreflightCode = (typeof SSH_PREFLIGHT_CODES)[number];
|
|
6
|
+
/** A target check that failed, in words the caller can act on. */
|
|
7
|
+
export interface SshPreflightFailure {
|
|
8
|
+
code: SshPreflightCode;
|
|
9
|
+
message: string;
|
|
10
|
+
/** The next step, one sentence. */
|
|
11
|
+
hint: string;
|
|
12
|
+
}
|
|
13
|
+
/** Program a built-in agent kind starts on the host, or undefined when it is configured. */
|
|
14
|
+
export declare function agentProgram(agent: SshAgentTarget, override?: string): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The single remote command one preflight runs: it always exits zero and prints
|
|
17
|
+
* one `key=value` per fact, so a failed channel is told apart from a failed check.
|
|
18
|
+
*/
|
|
19
|
+
export declare function preflightCommand(target: SshTarget, program: string | undefined): string;
|
|
20
|
+
/**
|
|
21
|
+
* Read one preflight answer.
|
|
22
|
+
* @param target - the checked target.
|
|
23
|
+
* @param program - the probed program, if any.
|
|
24
|
+
* @param result - what `exec` returned.
|
|
25
|
+
* @returns the first failed check, or undefined when the target can work.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readPreflight(target: SshTarget, program: string | undefined, result: {
|
|
28
|
+
success: boolean;
|
|
29
|
+
stdout: string;
|
|
30
|
+
stderr: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
timedOut?: boolean;
|
|
33
|
+
}): SshPreflightFailure | undefined;
|
|
34
|
+
/** Longest line a filtered log returns, in bytes; longer ones are cut and marked. */
|
|
35
|
+
export declare const LOG_LINE_MAX_BYTES = 2000;
|
|
36
|
+
/** Default and ceiling of one log reply, in bytes. */
|
|
37
|
+
export declare const LOG_REPLY_DEFAULT_BYTES: number;
|
|
38
|
+
/** Lines `tail` returns when the caller names neither `tail` nor `since`. */
|
|
39
|
+
export declare const LOG_TAIL_DEFAULT_LINES = 40;
|
|
40
|
+
/** What one log query asks for. */
|
|
41
|
+
export interface SshLogQuery {
|
|
42
|
+
/** Absolute path of the run's stdout log. */
|
|
43
|
+
file: string;
|
|
44
|
+
/** Last N filtered lines (default 40). Ignored when `since` is given. */
|
|
45
|
+
tail?: number;
|
|
46
|
+
/** First filtered line to return, 1-based: the `nextSince` of an earlier reply. */
|
|
47
|
+
since?: number;
|
|
48
|
+
/** Skip the filter and read raw lines. */
|
|
49
|
+
raw?: boolean;
|
|
50
|
+
/** Cap on the reply text, in bytes. */
|
|
51
|
+
maxBytes?: number;
|
|
52
|
+
/** Count only: no text. */
|
|
53
|
+
statsOnly?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/** Counts of one log, before any text is cost. */
|
|
56
|
+
export interface SshLogStats {
|
|
57
|
+
/** Size of the raw log on the host. */
|
|
58
|
+
rawBytes: number;
|
|
59
|
+
/** Lines the filter keeps. */
|
|
60
|
+
lines: number;
|
|
61
|
+
/** Bytes the kept lines take. */
|
|
62
|
+
bytes: number;
|
|
63
|
+
}
|
|
64
|
+
/** The command that answers one log query, text after a `stats` line. */
|
|
65
|
+
export declare function logCommand(query: SshLogQuery): string;
|
|
66
|
+
/** One answered log query. */
|
|
67
|
+
export interface SshLogAnswer {
|
|
68
|
+
stats: SshLogStats | undefined;
|
|
69
|
+
/** Filtered text, complete lines only, within the cap. */
|
|
70
|
+
text: string;
|
|
71
|
+
/** Filtered lines in `text`. */
|
|
72
|
+
lines: number;
|
|
73
|
+
/** Whether lines remain after `text`. */
|
|
74
|
+
more: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Parse the answer of {@link logCommand}.
|
|
78
|
+
* @param stdout - what the command printed.
|
|
79
|
+
* @param query - the query it answered.
|
|
80
|
+
* @returns stats and the complete lines that fit the cap.
|
|
81
|
+
*/
|
|
82
|
+
export declare function readLogAnswer(stdout: string, query: SshLogQuery): SshLogAnswer;
|
|
83
|
+
/** First filtered line number a tail of `tail` lines starts at, given the totals. */
|
|
84
|
+
export declare function tailStart(stats: SshLogStats, tail: number): number;
|
|
85
|
+
/** The agent's last visible action: a tool call or a message. */
|
|
86
|
+
export interface SshActivity {
|
|
87
|
+
/** `tool_use`, `assistant` or `result`. */
|
|
88
|
+
kind: string;
|
|
89
|
+
/** Tool name for a tool call. */
|
|
90
|
+
name?: string;
|
|
91
|
+
/** One line of what it was given or said. */
|
|
92
|
+
detail: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The last tool call (or message) in a stretch of stream-json lines.
|
|
96
|
+
* @param text - filtered log lines, oldest first.
|
|
97
|
+
* @returns the last action, or undefined when none parses.
|
|
98
|
+
*/
|
|
99
|
+
export declare function lastActivity(text: string): SshActivity | undefined;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host half's reading of the payload it stores on a card.
|
|
3
|
+
*
|
|
4
|
+
* The schema itself belongs to `src/core/ledger.ts` — the target pin, the active
|
|
5
|
+
* run, the bounded history and the one instruction a future run still owes — and
|
|
6
|
+
* the host half adds no member of its own to it. What this module owns is the
|
|
7
|
+
* write: it stamps the document, keeps it under the board's 64 KiB ceiling and
|
|
8
|
+
* makes every member it clears explicit, because the board merges a written
|
|
9
|
+
* payload into the stored one key by key.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-task-board-ssh/host/payload
|
|
12
|
+
*/
|
|
13
|
+
import { SSH_INTEGRATION_KEY, type SshLedgerPayload } from '../core/ledger.ts';
|
|
14
|
+
import { type SshRunRecord } from '../core/target.ts';
|
|
15
|
+
export { SSH_INTEGRATION_KEY };
|
|
16
|
+
export type { SshPendingInstruction } from '../core/ledger.ts';
|
|
17
|
+
/** How many settled runs one card keeps here, oldest dropped first. */
|
|
18
|
+
export declare const HOST_HISTORY_LIMIT = 20;
|
|
19
|
+
/** One card's payload: exactly the frozen document, with nothing added beside it. */
|
|
20
|
+
export type HostSshPayload = Omit<SshLedgerPayload, 'version'>;
|
|
21
|
+
/**
|
|
22
|
+
* Parse one stored payload into what the host half works with.
|
|
23
|
+
* @param raw - the card's `integrations.ssh` value, or undefined when it carries none.
|
|
24
|
+
* @returns the payload, or undefined when the card carries none this build understands.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readHostPayload(raw: unknown): HostSshPayload | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Serialize one payload for storage, keeping it strictly under the board's ceiling.
|
|
29
|
+
*
|
|
30
|
+
* The frozen trimmer does the budgeting, including the room it reserves for a
|
|
31
|
+
* queued instruction, so the store may drop the oldest history and never the
|
|
32
|
+
* message a person is waiting on.
|
|
33
|
+
* @param next - the payload to store.
|
|
34
|
+
* @param now - clock instant written into the document (ms epoch).
|
|
35
|
+
* @returns the board-ready extension payload.
|
|
36
|
+
*/
|
|
37
|
+
export declare function writeHostPayload(next: HostSshPayload, now: number): Record<string, unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* The same payload carrying one run as the run in flight.
|
|
40
|
+
* @param payload - the current payload.
|
|
41
|
+
* @param run - the run to carry.
|
|
42
|
+
* @returns the next payload.
|
|
43
|
+
*/
|
|
44
|
+
export declare function withActiveRun(payload: HostSshPayload, run: SshRunRecord): HostSshPayload;
|
|
45
|
+
/**
|
|
46
|
+
* The same payload with one run settled into the bounded history.
|
|
47
|
+
* @param payload - the current payload.
|
|
48
|
+
* @param run - the settled run.
|
|
49
|
+
* @returns the next payload, the active run cleared.
|
|
50
|
+
*/
|
|
51
|
+
export declare function withSettledRun(payload: HostSshPayload, run: SshRunRecord): HostSshPayload;
|
|
52
|
+
/**
|
|
53
|
+
* One run of a card's payload by id.
|
|
54
|
+
*
|
|
55
|
+
* A run stays addressable after it settles — the detail view names a historical
|
|
56
|
+
* run to replay its log — so the search covers the run in flight and the whole
|
|
57
|
+
* bounded history.
|
|
58
|
+
* @param payload - the payload to read.
|
|
59
|
+
* @param runId - run to find.
|
|
60
|
+
* @returns the run, or undefined when this card never had it.
|
|
61
|
+
*/
|
|
62
|
+
export declare function findRun(payload: HostSshPayload | undefined, runId: string): SshRunRecord | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* The most recent session this card's runs recorded, which is the one a
|
|
65
|
+
* follow-up would continue.
|
|
66
|
+
* @param payload - the payload to read.
|
|
67
|
+
* @returns the session id, or undefined when no run of this card reported one.
|
|
68
|
+
*/
|
|
69
|
+
export declare function latestSessionId(payload: HostSshPayload): string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* The run a card is waiting on, when it is still in a phase that schedules work.
|
|
72
|
+
* @param payload - the payload to read.
|
|
73
|
+
* @returns the live run, or undefined when the card waits on nothing.
|
|
74
|
+
*/
|
|
75
|
+
export declare function liveRunOf(payload: HostSshPayload): SshRunRecord | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The text one run's prompt carries: the proxy preamble a local session starts
|
|
3
|
+
* with, and the instruction a resumed (or degraded) run reads.
|
|
4
|
+
*
|
|
5
|
+
* These are model-facing strings, so they live here rather than in a locale
|
|
6
|
+
* dictionary, exactly as the board's own tool descriptions do. Nothing in them
|
|
7
|
+
* is rendered to a person.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-task-board-ssh/host/prompt
|
|
10
|
+
*/
|
|
11
|
+
import type { TaskRecord } from '../core/task-record.ts';
|
|
12
|
+
import type { SshTarget } from '../core/target.ts';
|
|
13
|
+
import type { SshPendingInstruction } from './payload.ts';
|
|
14
|
+
/** The tool family a proxy run has to drive the host with. */
|
|
15
|
+
export declare const SSH_TOOL_FAMILY = "ssh_list, ssh_exec, ssh_upload and ssh_download";
|
|
16
|
+
/** Prefix a recorded summary carries when the instruction started a fresh run. */
|
|
17
|
+
export declare const SSH_DEGRADED_SUMMARY_MARKER = "[fresh run: this agent cannot resume, so the previous summary was carried in the prompt]";
|
|
18
|
+
/**
|
|
19
|
+
* Build the preamble a proxy card's local session opens with.
|
|
20
|
+
*
|
|
21
|
+
* The board injects it ahead of the card body on the same path it injects tag
|
|
22
|
+
* prefixes, so the session reads what this run IS before it reads the task: the
|
|
23
|
+
* work happens on a pinned host through the `ssh_*` tools, and nothing about the
|
|
24
|
+
* card is local.
|
|
25
|
+
* @param task - the card about to run.
|
|
26
|
+
* @param target - the target the card pins.
|
|
27
|
+
* @returns the preamble text.
|
|
28
|
+
*/
|
|
29
|
+
export declare function proxyPreamble(task: TaskRecord, target: SshTarget): string;
|
|
30
|
+
/**
|
|
31
|
+
* Build the prompt one run reads.
|
|
32
|
+
*
|
|
33
|
+
* A start reads the card's own prompt. A follow-up or a rework that continues the
|
|
34
|
+
* agent's session reads the instruction alone, because the session already holds
|
|
35
|
+
* the work. A degraded follow-up — the agent cannot be resumed — reads what the
|
|
36
|
+
* previous run reported before it reads the instruction, which is the whole
|
|
37
|
+
* reason that path exists.
|
|
38
|
+
* @param task - the card being run.
|
|
39
|
+
* @param pending - the instruction this run carries, when it carries one.
|
|
40
|
+
* @param previousSummary - what the previous run reported, when it is known.
|
|
41
|
+
* @param resumed - whether the run continues the agent's session.
|
|
42
|
+
* @returns the text written to the run's prompt file.
|
|
43
|
+
*/
|
|
44
|
+
export declare function runPrompt(task: TaskRecord, pending: SshPendingInstruction | undefined, previousSummary: string | undefined, resumed: boolean): string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-host admission: the concurrency ceiling and the first-in-first-out queue.
|
|
3
|
+
*
|
|
4
|
+
* The queue is not stored anywhere of its own — it is the ordered set of cards
|
|
5
|
+
* whose payload carries a queued run, which is what makes it survive a restart
|
|
6
|
+
* for free: the same cards, read in the same order, produce the same queue.
|
|
7
|
+
* Order is the instant each run was requested, with the run id as the tie-break
|
|
8
|
+
* so two runs requested in the same millisecond still have one order.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-task-board-ssh/host/queue
|
|
11
|
+
*/
|
|
12
|
+
/** One run waiting for a slot on its host. */
|
|
13
|
+
export interface SshQueueEntry {
|
|
14
|
+
/** Card waiting for the slot. */
|
|
15
|
+
taskId: string;
|
|
16
|
+
/** Run the card waits on. */
|
|
17
|
+
runId: string;
|
|
18
|
+
/** Instant the run was requested (ms epoch). */
|
|
19
|
+
startedAt: number;
|
|
20
|
+
}
|
|
21
|
+
/** What one admission pass decided. */
|
|
22
|
+
export interface SshAdmission {
|
|
23
|
+
/** Runs that may start now, in queue order. */
|
|
24
|
+
start: SshQueueEntry[];
|
|
25
|
+
/** Runs left waiting, in the order they will be reached. */
|
|
26
|
+
waiting: SshQueueEntry[];
|
|
27
|
+
}
|
|
28
|
+
/** Default ceiling of concurrent runs on one host. */
|
|
29
|
+
export declare const DEFAULT_PER_HOST_CAP = 2;
|
|
30
|
+
/** Lowest accepted ceiling; one run at a time is the smallest queue worth naming. */
|
|
31
|
+
export declare const PER_HOST_CAP_MIN = 1;
|
|
32
|
+
/** Highest accepted ceiling per host. */
|
|
33
|
+
export declare const PER_HOST_CAP_MAX = 16;
|
|
34
|
+
/**
|
|
35
|
+
* Clamp a configured ceiling into the accepted range.
|
|
36
|
+
* @param value - configured value; anything unusable falls back to the default.
|
|
37
|
+
* @returns an integer between {@link PER_HOST_CAP_MIN} and {@link PER_HOST_CAP_MAX}.
|
|
38
|
+
*/
|
|
39
|
+
export declare function normalizePerHostCap(value: unknown): number;
|
|
40
|
+
/**
|
|
41
|
+
* Order a host's queue the way it will be served.
|
|
42
|
+
* @param entries - every queued run of one host.
|
|
43
|
+
* @returns the same entries, oldest first.
|
|
44
|
+
*/
|
|
45
|
+
export declare function orderQueue(entries: readonly SshQueueEntry[]): SshQueueEntry[];
|
|
46
|
+
/**
|
|
47
|
+
* Decide which queued runs may start now.
|
|
48
|
+
* @param entries - every queued run of one host, in any order.
|
|
49
|
+
* @param running - how many runs of that host already hold a slot.
|
|
50
|
+
* @param cap - the host's ceiling.
|
|
51
|
+
* @returns the runs to start now and the ones still waiting.
|
|
52
|
+
*/
|
|
53
|
+
export declare function admitRuns(entries: readonly SshQueueEntry[], running: number, cap: number): SshAdmission;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { DshSshService } from '../core/contract.ts';
|
|
2
|
+
import type { SshAgentCommand } from '../core/adapters/types.ts';
|
|
3
|
+
import { type LauncherStatus } from '../core/launcher.ts';
|
|
4
|
+
/** Ceiling for one remote command, in milliseconds. */
|
|
5
|
+
export declare const DEFAULT_COMMAND_TIMEOUT_MS = 30000;
|
|
6
|
+
/** What one remote call addresses. */
|
|
7
|
+
export interface SshRemoteRef {
|
|
8
|
+
/** `dshSsh` host alias. */
|
|
9
|
+
alias: string;
|
|
10
|
+
/** Absolute remote state directory the provider owns on that host. */
|
|
11
|
+
stateDir: string;
|
|
12
|
+
/** Run the call addresses. */
|
|
13
|
+
runId: string;
|
|
14
|
+
}
|
|
15
|
+
/** The files one run's start writes before the launcher runs it. */
|
|
16
|
+
export interface SshRemoteRunFiles {
|
|
17
|
+
/** Prompt text the agent reads. */
|
|
18
|
+
prompt: string;
|
|
19
|
+
/** Quoted command line the launcher executes. */
|
|
20
|
+
command: SshAgentCommand;
|
|
21
|
+
/** Absolute remote directory the run works in. */
|
|
22
|
+
cwd: string;
|
|
23
|
+
/** Opaque spec the provider keeps for its own reconciliation. */
|
|
24
|
+
spec: unknown;
|
|
25
|
+
}
|
|
26
|
+
/** A remote command that could not be completed, in the host's own words. */
|
|
27
|
+
export declare class SshRemoteError extends Error {
|
|
28
|
+
/** Host the command addressed. */
|
|
29
|
+
readonly alias: string;
|
|
30
|
+
/** What the command was for. */
|
|
31
|
+
readonly what: string;
|
|
32
|
+
constructor(alias: string, what: string, message: string);
|
|
33
|
+
}
|
|
34
|
+
/** One page of a run's log, as the read verb returned it. */
|
|
35
|
+
export interface SshTailPage {
|
|
36
|
+
/** Bytes the remote log held from the requested offset to its end, as text. */
|
|
37
|
+
text: string;
|
|
38
|
+
/** Byte offset the next read starts at. */
|
|
39
|
+
bytes: number;
|
|
40
|
+
}
|
|
41
|
+
/** Options of {@link SshRemote}. */
|
|
42
|
+
export interface SshRemoteOptions {
|
|
43
|
+
/** Ceiling for one remote command, in milliseconds. */
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}
|
|
46
|
+
export declare class SshRemote {
|
|
47
|
+
private readonly ssh;
|
|
48
|
+
private readonly timeoutMs;
|
|
49
|
+
private readonly stateDirs;
|
|
50
|
+
private readonly starting;
|
|
51
|
+
private readonly installing;
|
|
52
|
+
constructor(ssh: DshSshService, options?: SshRemoteOptions);
|
|
53
|
+
/** The state directory of a host when it was already resolved, without a round trip. */
|
|
54
|
+
cachedStateDir(alias: string): string | undefined;
|
|
55
|
+
/** Forget every cached path of one host, or of all hosts when none is named. */
|
|
56
|
+
forget(alias?: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Resolve (and cache) the absolute state directory of one host.
|
|
59
|
+
* @param alias - host alias.
|
|
60
|
+
* @returns the directory the provider installs the launcher and its runs under.
|
|
61
|
+
*/
|
|
62
|
+
stateDir(alias: string): Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Install (or refresh) the launcher script on one host, deduplicating
|
|
65
|
+
* concurrent installs on the same host and state directory.
|
|
66
|
+
* @param ref - host and state directory.
|
|
67
|
+
*/
|
|
68
|
+
installLauncher(ref: {
|
|
69
|
+
alias: string;
|
|
70
|
+
stateDir: string;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Write every file one run needs before `start`.
|
|
74
|
+
*
|
|
75
|
+
* Large prompts are uploaded through SFTP instead of inlined into a single
|
|
76
|
+
* shell command line so multi-megabyte prompts never trip Linux `E2BIG`.
|
|
77
|
+
* @param ref - host, state directory and run.
|
|
78
|
+
* @param files - prompt, command line, working directory and spec.
|
|
79
|
+
*/
|
|
80
|
+
writeRunFiles(ref: SshRemoteRef, files: SshRemoteRunFiles): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Ask the launcher to start one run, joining a start already in flight.
|
|
83
|
+
* @param ref - host, state directory and run.
|
|
84
|
+
* @returns the state line the launcher printed.
|
|
85
|
+
*/
|
|
86
|
+
start(ref: SshRemoteRef): Promise<LauncherStatus>;
|
|
87
|
+
/**
|
|
88
|
+
* Read one run's state.
|
|
89
|
+
* @param ref - host, state directory and run.
|
|
90
|
+
* @returns the state line the launcher printed.
|
|
91
|
+
*/
|
|
92
|
+
status(ref: SshRemoteRef): Promise<LauncherStatus>;
|
|
93
|
+
/**
|
|
94
|
+
* Read a run's log from a byte offset, optionally capped to `limit` bytes.
|
|
95
|
+
* @param ref - host, state directory and run.
|
|
96
|
+
* @param offset - first byte to return.
|
|
97
|
+
* @param limit - optional maximum byte count to return (prevents hitting dsh-ssh's 2 MiB output cap).
|
|
98
|
+
* @returns the text and the offset the next read starts at.
|
|
99
|
+
*/
|
|
100
|
+
tail(ref: SshRemoteRef, offset: number, limit?: number): Promise<SshTailPage>;
|
|
101
|
+
/**
|
|
102
|
+
* Read the bounded tail of a run's `stderr.log`, for diagnosing failures when
|
|
103
|
+
* `stdout.log` carries no structured agent event.
|
|
104
|
+
* @param ref - host, state directory and run.
|
|
105
|
+
* @param limit - maximum bytes from the end of `stderr.log`.
|
|
106
|
+
* @returns trimmed stderr text, or empty string when unavailable.
|
|
107
|
+
*/
|
|
108
|
+
stderr(ref: SshRemoteRef, limit?: number): Promise<string>;
|
|
109
|
+
/**
|
|
110
|
+
* Ask the launcher to cancel one run.
|
|
111
|
+
* @param ref - host, state directory and run.
|
|
112
|
+
* @returns the state line the launcher printed.
|
|
113
|
+
*/
|
|
114
|
+
cancel(ref: SshRemoteRef): Promise<LauncherStatus>;
|
|
115
|
+
/**
|
|
116
|
+
* Remove one run directory from the host, tolerating its absence.
|
|
117
|
+
* @param ref - host, state directory and run.
|
|
118
|
+
*/
|
|
119
|
+
removeRun(ref: SshRemoteRef): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Run one read-only diagnostic command and hand back the raw result, whether
|
|
122
|
+
* or not it succeeded: the caller decides what a failure means.
|
|
123
|
+
* @param alias - host alias.
|
|
124
|
+
* @param command - command line, already quoted.
|
|
125
|
+
* @param timeoutMs - ceiling for this command.
|
|
126
|
+
* @returns what the forwarder reported; a thrown forwarder becomes a failed result.
|
|
127
|
+
*/
|
|
128
|
+
probe(alias: string, command: string, timeoutMs?: number): Promise<{
|
|
129
|
+
success: boolean;
|
|
130
|
+
stdout: string;
|
|
131
|
+
stderr: string;
|
|
132
|
+
error?: string;
|
|
133
|
+
timedOut: boolean;
|
|
134
|
+
}>;
|
|
135
|
+
/** Run one command and refuse a failed one in the host's own words. */
|
|
136
|
+
private run;
|
|
137
|
+
}
|