@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.
Files changed (128) hide show
  1. package/LICENSE +202 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +96 -2
  4. package/README.zh.md +97 -0
  5. package/cordis.patch.yml +15 -0
  6. package/icon.svg +5 -0
  7. package/lib/client.js +4435 -0
  8. package/lib/index.js +7082 -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 +453 -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 +149 -0
  40. package/lib/types/core/task-record.d.ts +74 -0
  41. package/lib/types/core/workspace.d.ts +74 -0
  42. package/lib/types/host/board.d.ts +75 -0
  43. package/lib/types/host/engine.d.ts +563 -0
  44. package/lib/types/host/extension.d.ts +61 -0
  45. package/lib/types/host/inspect.d.ts +99 -0
  46. package/lib/types/host/logs.d.ts +135 -0
  47. package/lib/types/host/payload.d.ts +75 -0
  48. package/lib/types/host/prompt.d.ts +44 -0
  49. package/lib/types/host/queue.d.ts +53 -0
  50. package/lib/types/host/remote.d.ts +137 -0
  51. package/lib/types/host/settings.d.ts +149 -0
  52. package/lib/types/host/timers.d.ts +20 -0
  53. package/lib/types/host/tools.d.ts +17 -0
  54. package/lib/types/host/workspace/errors.d.ts +29 -0
  55. package/lib/types/host/workspace/git.d.ts +108 -0
  56. package/lib/types/host/workspace/in-place.d.ts +36 -0
  57. package/lib/types/host/workspace/index.d.ts +28 -0
  58. package/lib/types/host/workspace/layout.d.ts +62 -0
  59. package/lib/types/host/workspace/local-git.d.ts +72 -0
  60. package/lib/types/host/workspace/remote-git.d.ts +111 -0
  61. package/lib/types/host/workspace/remote.d.ts +85 -0
  62. package/lib/types/host/workspace/types.d.ts +28 -0
  63. package/lib/types/host/workspace-seam.d.ts +100 -0
  64. package/lib/types/index.d.ts +97 -0
  65. package/lib/types/mount-once.d.ts +55 -0
  66. package/locale/en.json +6 -0
  67. package/locale/zh.json +6 -0
  68. package/package.json +89 -3
  69. package/src/client/PluginSettingsCard.tsx +838 -0
  70. package/src/client/RangeBubble.tsx +164 -0
  71. package/src/client/SegmentGroup.tsx +93 -0
  72. package/src/client/css-modules.d.ts +5 -0
  73. package/src/client/index.ts +195 -0
  74. package/src/client/locales.ts +257 -0
  75. package/src/client/seat-props.ts +58 -0
  76. package/src/client/settings-card.module.css +821 -0
  77. package/src/client/settings-entry-form.ts +141 -0
  78. package/src/client/settings-form.ts +529 -0
  79. package/src/client/ssh/card-decoration.tsx +55 -0
  80. package/src/client/ssh/compose-section.tsx +147 -0
  81. package/src/client/ssh/detail-section.tsx +345 -0
  82. package/src/client/ssh/extension.ts +271 -0
  83. package/src/client/ssh/log-buffer.ts +224 -0
  84. package/src/client/ssh/log-view.tsx +149 -0
  85. package/src/client/ssh/model.ts +299 -0
  86. package/src/client/ssh/settings-section.tsx +401 -0
  87. package/src/client/ssh/summary.ts +388 -0
  88. package/src/client/ssh/target-form.tsx +380 -0
  89. package/src/client/ssh.module.css +617 -0
  90. package/src/core/action.ts +270 -0
  91. package/src/core/adapters/claude.ts +64 -0
  92. package/src/core/adapters/codex.ts +83 -0
  93. package/src/core/adapters/custom.ts +88 -0
  94. package/src/core/adapters/dsh.ts +87 -0
  95. package/src/core/adapters/index.ts +74 -0
  96. package/src/core/adapters/types.ts +95 -0
  97. package/src/core/contract.ts +515 -0
  98. package/src/core/launcher-script.ts +313 -0
  99. package/src/core/launcher.ts +283 -0
  100. package/src/core/ledger.ts +377 -0
  101. package/src/core/shell.ts +77 -0
  102. package/src/core/target.ts +420 -0
  103. package/src/core/task-record.ts +73 -0
  104. package/src/core/workspace.ts +78 -0
  105. package/src/host/board.ts +107 -0
  106. package/src/host/engine.ts +2026 -0
  107. package/src/host/extension.ts +310 -0
  108. package/src/host/inspect.ts +264 -0
  109. package/src/host/logs.ts +297 -0
  110. package/src/host/payload.ts +134 -0
  111. package/src/host/prompt.ts +89 -0
  112. package/src/host/queue.ts +73 -0
  113. package/src/host/remote.ts +356 -0
  114. package/src/host/settings.ts +294 -0
  115. package/src/host/timers.ts +33 -0
  116. package/src/host/tools.ts +449 -0
  117. package/src/host/workspace/errors.ts +43 -0
  118. package/src/host/workspace/git.ts +305 -0
  119. package/src/host/workspace/in-place.ts +58 -0
  120. package/src/host/workspace/index.ts +37 -0
  121. package/src/host/workspace/layout.ts +122 -0
  122. package/src/host/workspace/local-git.ts +164 -0
  123. package/src/host/workspace/remote-git.ts +244 -0
  124. package/src/host/workspace/remote.ts +181 -0
  125. package/src/host/workspace/types.ts +34 -0
  126. package/src/host/workspace-seam.ts +132 -0
  127. package/src/index.ts +243 -0
  128. package/src/mount-once.ts +142 -0
@@ -0,0 +1,149 @@
1
+ /**
2
+ * This extension's own configuration: reading it live, and the single path that
3
+ * writes it back.
4
+ *
5
+ * The fields are `volatile()` in the Config schema, so the Host's settings
6
+ * surface commits a write into the running fiber without a remount and every
7
+ * consumer here reads them at use time. That is why this module has no cache and
8
+ * no second store: a settings write reaches the next admission, the next run and
9
+ * the next tool call through {@link SshProviderSettings} alone.
10
+ *
11
+ * @module dsh-task-board-ssh/host/settings
12
+ */
13
+ import { type SshCustomTemplates } from '../core/adapters/index.ts';
14
+ import { type SshAgentKind, type SshExecutionMode } from '../core/target.ts';
15
+ /** Default agent CLI a card starts when neither the card nor the deployment pins one. */
16
+ export declare const DEFAULT_AGENT_KIND: SshAgentKind;
17
+ /** Default execution mode of a card that pins no target yet. */
18
+ export declare const DEFAULT_EXECUTION_MODE: SshExecutionMode;
19
+ /** Profile entry ids this package's rows carry, most specific first. */
20
+ export declare const SSH_ENTRY_IDS: readonly string[];
21
+ /** The effective configuration of one mount. */
22
+ export interface SshProviderSettings {
23
+ /** Master switch of the extension. */
24
+ enabled: boolean;
25
+ /** Host a card opens with when neither the card nor the browser pins one. */
26
+ defaultHost: string;
27
+ /** Agent CLI a card opens with. */
28
+ defaultAgent: SshAgentKind;
29
+ /** Execution mode a card opens with. */
30
+ defaultMode: SshExecutionMode;
31
+ /** How many runs one host executes at once; the rest wait in the queue. */
32
+ perHostCap: number;
33
+ /** Per-agent command templates that replace the built-in command line. */
34
+ agentCommands: Partial<Record<SshAgentKind, SshCustomTemplates>>;
35
+ }
36
+ /** What a deployment that configured nothing gets. */
37
+ export declare const DEFAULT_SSH_SETTINGS: SshProviderSettings;
38
+ /**
39
+ * Read one config field's live value.
40
+ *
41
+ * A `volatile()` field arrives as a live reference the Loader updates in place,
42
+ * so it is unwrapped on every read instead of being captured once.
43
+ * @param field - the field as the Loader handed it.
44
+ * @param fallback - value when the field is absent.
45
+ * @returns the effective value.
46
+ */
47
+ export declare function readConfigField<T>(field: unknown, fallback: T): T;
48
+ /**
49
+ * Normalize the row's own configuration.
50
+ * @param config - the config the Loader activated this row with.
51
+ * @returns the settings every consumer reads.
52
+ */
53
+ export declare function parseSshSettings(config: unknown): SshProviderSettings;
54
+ /** One path-addressed edit the settings surface accepts. */
55
+ export type SettingsPathOp = {
56
+ op: 'set';
57
+ path: readonly string[];
58
+ value: unknown;
59
+ } | {
60
+ op: 'unset';
61
+ path: readonly string[];
62
+ };
63
+ /** One entry the settings surface reports. */
64
+ export interface SettingsDescriptor {
65
+ /** Profile entry id the form belongs to. */
66
+ ns?: unknown;
67
+ /** Revision the form was built from. */
68
+ revision?: unknown;
69
+ }
70
+ /** The slice of the Host settings surface this extension uses. */
71
+ export interface SettingsFace {
72
+ /** Whether the active profile accepts form edits. */
73
+ readonly writable: boolean;
74
+ /** Read the live forms. */
75
+ describe(options?: {
76
+ redactSecrets?: boolean;
77
+ }): SettingsDescriptor[];
78
+ /** Apply field edits to one entry against the revision it was read at. */
79
+ mutate(ns: string, ops: readonly SettingsPathOp[], expectedRevision?: number): Promise<void>;
80
+ }
81
+ /** A configuration write this deployment refused, in the term the caller acts on. */
82
+ export declare class SshSettingsError extends Error {
83
+ /** Stable machine code the action reply and the tool carry. */
84
+ readonly code: string;
85
+ constructor(code: string, message: string);
86
+ }
87
+ /**
88
+ * Read the settings surface off the injected `settings` service.
89
+ * @param value - the service as the injected scope carries it.
90
+ * @returns the face, or undefined when this deployment serves none.
91
+ */
92
+ export declare function readSettingsFace(value: unknown): SettingsFace | undefined;
93
+ /**
94
+ * Find this extension's own entry among the settings surface's forms.
95
+ * @param face - the settings surface.
96
+ * @returns the entry id and its current revision, or undefined when this
97
+ * deployment exposes no form for this extension.
98
+ */
99
+ export declare function findSshSettingsEntry(face: SettingsFace): {
100
+ ns: string;
101
+ revision: number;
102
+ } | undefined;
103
+ /** One configuration change a caller may ask for. */
104
+ export interface SshSettingsPatch {
105
+ /** Master switch. */
106
+ enabled?: boolean;
107
+ /** Host a card opens with. */
108
+ defaultHost?: string;
109
+ /** Agent CLI a card opens with. */
110
+ defaultAgent?: SshAgentKind;
111
+ /** Execution mode a card opens with. */
112
+ defaultMode?: SshExecutionMode;
113
+ /** Concurrent runs per host. */
114
+ perHostCap?: number;
115
+ /** Full replacement of the per-agent command overrides. */
116
+ agentCommands?: ReadonlyArray<{
117
+ kind: SshAgentKind;
118
+ command: string;
119
+ resumeCommand?: string;
120
+ }>;
121
+ }
122
+ /** What one accepted write stored. */
123
+ export interface SshSettingsWriteResult {
124
+ /** Profile entry the write landed in. */
125
+ entry: string;
126
+ /** Fields the write addressed, in the order they were applied. */
127
+ fields: string[];
128
+ }
129
+ /**
130
+ * The one write path of this extension's configuration.
131
+ *
132
+ * Every caller — a settings card, an action, a future host route — composes a
133
+ * patch and hands it here; nothing else calls `settings.mutate` for this
134
+ * extension, so there is exactly one place where a value is validated, one
135
+ * revision it is written against, and one set of volatile fields it may name.
136
+ */
137
+ export declare class SshSettingsWriter {
138
+ private readonly face;
139
+ constructor(face: () => SettingsFace | undefined);
140
+ /** Whether a write can be attempted at all right now. */
141
+ available(): boolean;
142
+ /**
143
+ * Validate one patch and write it in a single batch.
144
+ * @param patch - the change to store.
145
+ * @returns which entry and fields the write addressed.
146
+ * @throws SshSettingsError when the patch is unusable or the deployment refuses.
147
+ */
148
+ save(patch: SshSettingsPatch): Promise<SshSettingsWriteResult>;
149
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The timer seat the run engine schedules through.
3
+ *
4
+ * The engine never reaches for a global timer directly: the host entry injects
5
+ * this face, so the poll cadence is observable, cancellable and — in tests —
6
+ * advanced by hand instead of waited on. A deployment with no opinion gets
7
+ * {@link processTimers}, which unrefs both handles so a board that is polling
8
+ * nothing keeps the process free to exit.
9
+ *
10
+ * @module dsh-task-board-ssh/host/timers
11
+ */
12
+ /** The timer operations the engine needs, each returning its own canceller. */
13
+ export interface HostTimerFace {
14
+ /** Run `callback` once after `delay` ms. */
15
+ timeout(callback: () => void, delay: number): () => void;
16
+ /** Run `callback` every `delay` ms. */
17
+ interval(callback: () => void, delay: number): () => void;
18
+ }
19
+ /** The process timer face: what a real Host mount uses. */
20
+ export declare const processTimers: HostTimerFace;
@@ -0,0 +1,17 @@
1
+ import { type ToolDefinition } from '@deepseek-ai/dsh-tools';
2
+ import { type SshExecutionMode } from '../core/target.ts';
3
+ import type { SshRunEngine } from './engine.ts';
4
+ import { SSH_PREFLIGHT_CODES } from './inspect.ts';
5
+ /** Tool names, in registration order; the first is the one surface, the rest are the compatibility layer. */
6
+ export declare const SSH_TOOL_NAMES: readonly ["task_board_ssh", "task_board_ssh_target", "task_board_ssh_status", "task_board_ssh_follow_up"];
7
+ /** One tool name. */
8
+ export type SshToolName = (typeof SSH_TOOL_NAMES)[number];
9
+ /**
10
+ * Build every tool this extension registers.
11
+ * @param engine - the live run engine behind them.
12
+ * @returns the tool definitions, in registration order.
13
+ */
14
+ export declare function buildSshTools(engine: SshRunEngine): ToolDefinition[];
15
+ /** Re-exported for the specs: the modes a target may pin and the stable preflight codes. */
16
+ export type { SshExecutionMode };
17
+ export { SSH_PREFLIGHT_CODES };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The one failure type the workspace strategies raise.
3
+ *
4
+ * Every failure a strategy throws is this class, so the run engine can record a
5
+ * workspace that could not be prepared as a run failure without matching on
6
+ * message text. Each message names what was attempted and the host, path or
7
+ * command it failed on, because it lands in a card where the user has no shell
8
+ * to look behind it.
9
+ *
10
+ * @module dsh-task-board-ssh/host/workspace/errors
11
+ */
12
+ /** A workspace that cannot be prepared or collected. */
13
+ export declare class SshWorkspaceError extends Error {
14
+ /**
15
+ * @param message - what failed, in one sentence a person can act on.
16
+ * @param options - standard error options, used to keep the underlying failure.
17
+ */
18
+ constructor(message: string, options?: ErrorOptions);
19
+ }
20
+ /**
21
+ * The one line worth quoting out of a command's failure text.
22
+ *
23
+ * A tool prints progress first and the diagnosis last, so the last non-empty
24
+ * line is the part a person needs; the whole output is bounded away because it
25
+ * would bury the sentence it is quoted in.
26
+ * @param text - captured stderr, stdout or an error message.
27
+ * @returns that line, or undefined when there is nothing to quote.
28
+ */
29
+ export declare function boundedLine(text: string | undefined): string | undefined;
@@ -0,0 +1,108 @@
1
+ import type { SshGitSource } from '../../core/target.ts';
2
+ import type { SshWorkspaceCollection, SshWorkspaceRun } from '../../core/workspace.ts';
3
+ import { type GitWorkspaceLayout } from './layout.ts';
4
+ import type { SshWorkspacePreparationNote, SshWorkspaceStrategyWithNote } from './types.ts';
5
+ /** A repository the host reaches by URL. */
6
+ type UrlSource = Extract<SshGitSource, {
7
+ kind: 'url';
8
+ }>;
9
+ /** The local workspace repository, sent as a bundle. */
10
+ type WorkspaceSource = Extract<SshGitSource, {
11
+ kind: 'workspace';
12
+ }>;
13
+ /**
14
+ * The git mechanism's shared state machine.
15
+ *
16
+ * A subclass only answers where the cache's start commit comes from and where
17
+ * `collect` publishes the branch; the cache, the worktree, the base ref and the
18
+ * "did the run commit anything" question are the same for both sources.
19
+ */
20
+ declare abstract class GitWorkspaceStrategyBase implements SshWorkspaceStrategyWithNote {
21
+ readonly kind: "git";
22
+ /** What makes this repository source unique on one host. */
23
+ private readonly sourceIdentity;
24
+ /**
25
+ * @param sourceIdentity - cache key identity of the pinned source.
26
+ */
27
+ protected constructor(sourceIdentity: string);
28
+ /** Effective run whose worktree/branch this operation owns (reused on follow-up/rework). */
29
+ private layoutFor;
30
+ /**
31
+ * Make the run's worktree exist on its branch, or confirm it already does.
32
+ * @param run - the run being prepared.
33
+ * @returns the worktree path, plus the source's note when it has one.
34
+ * @throws SshWorkspaceError when the host, the source or git refused.
35
+ */
36
+ prepare(run: SshWorkspaceRun): Promise<SshWorkspacePreparationNote>;
37
+ /**
38
+ * Bring the run's branch back, when the run committed anything.
39
+ * @param run - the settled run.
40
+ * @returns the branch that carries the result, or nothing when there is none.
41
+ * @throws SshWorkspaceError when no workspace was prepared or publishing failed.
42
+ */
43
+ collect(run: SshWorkspaceRun): Promise<SshWorkspaceCollection>;
44
+ /** Best-effort reclamation of a run's remote worktree, branch and base ref. */
45
+ cleanup(run: SshWorkspaceRun): Promise<void>;
46
+ /**
47
+ * Put the repository in the cache and pin the commit the branch starts from.
48
+ * @param run - the run being prepared.
49
+ * @param layout - the run's paths.
50
+ * @returns the ref or commit `git worktree add` branches from.
51
+ */
52
+ protected abstract seed(run: SshWorkspaceRun, layout: GitWorkspaceLayout): Promise<string>;
53
+ /**
54
+ * Publish the run branch where this source keeps its results.
55
+ * @param run - the settled run.
56
+ * @param layout - the run's paths.
57
+ */
58
+ protected abstract publish(run: SshWorkspaceRun, layout: GitWorkspaceLayout): Promise<void>;
59
+ /**
60
+ * Describe what the source did not send, for the card to explain.
61
+ * @param run - the run being prepared.
62
+ * @returns the note to merge into the preparation; nothing by default.
63
+ */
64
+ protected sourceNote(_run: SshWorkspaceRun): Promise<{
65
+ untrackedFiles?: number;
66
+ }>;
67
+ /**
68
+ * Read how many commits the run branch carries past the commit it started from.
69
+ * @param run - the run being collected.
70
+ * @param layout - the run's paths.
71
+ * @returns the commit count.
72
+ * @throws SshWorkspaceError when the count could not be read as one.
73
+ */
74
+ private countRunCommits;
75
+ }
76
+ /** A repository the host clones for itself; the run's branch is pushed back. */
77
+ export declare class GitUrlWorkspaceStrategy extends GitWorkspaceStrategyBase {
78
+ /** The pinned url source. */
79
+ private readonly source;
80
+ /**
81
+ * @param source - repository URL the host can reach, and its optional base.
82
+ */
83
+ constructor(source: UrlSource);
84
+ protected seed(run: SshWorkspaceRun, layout: GitWorkspaceLayout): Promise<string>;
85
+ protected publish(run: SshWorkspaceRun, layout: GitWorkspaceLayout): Promise<void>;
86
+ }
87
+ /** The local workspace repository, sent as a bundle and fetched back as one. */
88
+ export declare class GitWorkspaceSourceStrategy extends GitWorkspaceStrategyBase {
89
+ /** The pinned workspace source. */
90
+ private readonly source;
91
+ /**
92
+ * @param source - workspace whose local repository the run starts from.
93
+ */
94
+ constructor(source: WorkspaceSource);
95
+ protected sourceNote(run: SshWorkspaceRun): Promise<{
96
+ untrackedFiles: number;
97
+ }>;
98
+ protected seed(run: SshWorkspaceRun, layout: GitWorkspaceLayout): Promise<string>;
99
+ protected publish(run: SshWorkspaceRun, layout: GitWorkspaceLayout): Promise<void>;
100
+ /**
101
+ * Read the local repository the run starts from.
102
+ * @param run - the run being served.
103
+ * @returns the absolute local repository root.
104
+ * @throws SshWorkspaceError when the run carries no resolved repository.
105
+ */
106
+ private requireRepository;
107
+ }
108
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Runs in a remote directory the user already has.
3
+ *
4
+ * The pinned directory is the whole strategy: nothing is created, copied or
5
+ * versioned, so the agent's changes land where the user pointed and `collect`
6
+ * has nothing to bring back. An absent directory fails the run instead of being
7
+ * created, because a typo in a path must not turn into a silently new, empty
8
+ * place to work in.
9
+ *
10
+ * @module dsh-task-board-ssh/host/workspace/in-place
11
+ */
12
+ import type { SshWorkspaceCollection, SshWorkspaceRun } from '../../core/workspace.ts';
13
+ import type { SshWorkspacePreparationNote, SshWorkspaceStrategyWithNote } from './types.ts';
14
+ /** The pinned remote directory, checked but never created. */
15
+ export declare class InPlaceWorkspaceStrategy implements SshWorkspaceStrategyWithNote {
16
+ readonly kind: "in-place";
17
+ /** The directory the card pinned. */
18
+ private readonly path;
19
+ /**
20
+ * @param path - absolute remote directory the run works in.
21
+ * @throws SshWorkspaceError when the path is not absolute.
22
+ */
23
+ constructor(path: string);
24
+ /**
25
+ * Check that the pinned directory exists and hand it back.
26
+ * @param run - the run being prepared.
27
+ * @returns the pinned directory as the working directory.
28
+ * @throws SshWorkspaceError when it is missing or the host is unreachable.
29
+ */
30
+ prepare(run: SshWorkspaceRun): Promise<SshWorkspacePreparationNote>;
31
+ /**
32
+ * Collect nothing: in-place work stays where it was made.
33
+ * @returns an empty collection, because files in place are already the result.
34
+ */
35
+ collect(): Promise<SshWorkspaceCollection>;
36
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The workspace strategies behind one factory.
3
+ *
4
+ * `in-place` and `git` are the two mechanisms the proposal settled; the git
5
+ * mechanism splits by where its repository comes from, because only the
6
+ * workspace source needs a local repository and only it brings a branch back
7
+ * into one. The split happens here and nowhere else, so the run engine holds
8
+ * one strategy per pinned target and never a condition of its own.
9
+ *
10
+ * The source is read from the target, not from the run: a run's `source` field
11
+ * repeats what the card pinned, and one authority for "which repository is this
12
+ * run about" is what keeps `prepare` and `collect` from ever disagreeing.
13
+ *
14
+ * @module dsh-task-board-ssh/host/workspace
15
+ */
16
+ import type { SshWorkspaceTarget } from '../../core/target.ts';
17
+ import type { SshWorkspaceStrategyWithNote } from './types.ts';
18
+ /**
19
+ * Build the strategy one pinned target names.
20
+ *
21
+ * @param target - filesystem mechanism the card pins, with its source.
22
+ * @returns the strategy for that mechanism; assignable to the frozen
23
+ * `SshWorkspaceStrategy`, and narrowed to a preparation that carries the
24
+ * untracked-file note.
25
+ */
26
+ export declare function createSshWorkspaceStrategy(target: SshWorkspaceTarget): SshWorkspaceStrategyWithNote;
27
+ export type { SshWorkspacePreparationNote, SshWorkspaceStrategyWithNote } from './types.ts';
28
+ export { SshWorkspaceError } from './errors.ts';
@@ -0,0 +1,62 @@
1
+ import type { SshWorkspaceRun } from '../../core/workspace.ts';
2
+ /** Branch prefix every git run commits on: `dsh-task/<runId>`. */
3
+ export declare const RUN_BRANCH_PREFIX = "dsh-task/";
4
+ /** Paths and refs one git run uses. */
5
+ export interface GitWorkspaceLayout {
6
+ /** Absolute remote state directory the provider owns on the host. */
7
+ stateDir: string;
8
+ /** Run identifier every derived name carries. */
9
+ runId: string;
10
+ /** Directory holding one bare cache per repository source. */
11
+ reposDir: string;
12
+ /** Bare cache of this run's repository. */
13
+ cacheDir: string;
14
+ /** Directory holding one worktree per run. */
15
+ workspacesDir: string;
16
+ /** Worktree the agent works in. */
17
+ worktreeDir: string;
18
+ /** Directory bundles travel through. */
19
+ bundlesDir: string;
20
+ /** Branch name the run commits on. */
21
+ branch: string;
22
+ /** Full ref of {@link branch}. */
23
+ branchRef: string;
24
+ /** Ref pinning the commit the branch started from. */
25
+ baseRef: string;
26
+ }
27
+ /**
28
+ * Short digest of one repository's identity, used as its cache directory name.
29
+ *
30
+ * A digest rather than the URL itself: a clone URL may carry credentials, and
31
+ * a path or a workspace id may carry characters a directory name should not.
32
+ * @param identity - what makes the source unique on this host.
33
+ * @returns sixteen lower-case hex characters.
34
+ */
35
+ export declare function cacheKey(identity: string): string;
36
+ /**
37
+ * Refuse a run id that cannot be a git ref component.
38
+ *
39
+ * The launcher's grammar already bounds the characters; git additionally
40
+ * refuses `..`, a leading or trailing dot and a `.lock` suffix, and a run id
41
+ * that reached `git worktree add` with one of those would fail far from here.
42
+ * @param runId - candidate run identifier.
43
+ * @returns the run id, unchanged.
44
+ * @throws SshWorkspaceError when git could not name a branch after it.
45
+ */
46
+ export declare function assertRefSafeRunId(runId: string): string;
47
+ /**
48
+ * Require one absolute remote directory, without its trailing slashes.
49
+ * @param path - candidate directory.
50
+ * @param what - which directory it is, for the diagnostic.
51
+ * @returns the path with trailing slashes removed.
52
+ * @throws SshWorkspaceError when the path is relative or is the filesystem root.
53
+ */
54
+ export declare function assertRemoteDirectory(path: string, what: string): string;
55
+ /**
56
+ * Derive every path and ref one git run uses.
57
+ * @param run - the run being prepared or collected.
58
+ * @param sourceIdentity - what makes the repository source unique on this host.
59
+ * @returns the run's layout.
60
+ * @throws SshWorkspaceError when the run carries a path or id git cannot use.
61
+ */
62
+ export declare function gitWorkspaceLayout(run: SshWorkspaceRun, sourceIdentity: string): GitWorkspaceLayout;
@@ -0,0 +1,72 @@
1
+ /** What a working-tree snapshot found, and what it left behind. */
2
+ export interface LocalWorkspaceSnapshot {
3
+ /** Commit `HEAD` points at. */
4
+ head: string;
5
+ /** Commit the run branch starts from: the snapshot when dirty, `head` otherwise. */
6
+ base: string;
7
+ /** Whether tracked but uncommitted changes were folded in. */
8
+ dirty: boolean;
9
+ }
10
+ /**
11
+ * Run one git command against one repository.
12
+ * @param repository - path handed to `git -C`, so no working directory is shared.
13
+ * @param args - git arguments, unquoted and unjoined.
14
+ * @param signal - cancellation of the run this command serves.
15
+ * @returns captured standard output.
16
+ * @throws SshWorkspaceError when git failed, or the abort itself when cancelled.
17
+ */
18
+ export declare function runLocalGit(repository: string, args: readonly string[], signal?: AbortSignal): Promise<string>;
19
+ /**
20
+ * Require one path to be the root of a working tree.
21
+ * @param repository - candidate repository path.
22
+ * @param signal - cancellation of the run this command serves.
23
+ * @throws SshWorkspaceError when the path is not a work tree of any repository.
24
+ */
25
+ export declare function assertLocalWorkTree(repository: string, signal?: AbortSignal): Promise<void>;
26
+ /**
27
+ * Count the untracked files a bundle does not carry.
28
+ *
29
+ * Ignored files stay out: a `node_modules` is not something the card has to
30
+ * warn about, and counting it would make the number meaningless.
31
+ * @param repository - local workspace repository.
32
+ * @param signal - cancellation of the run this command serves.
33
+ * @returns how many untracked, non-ignored files the working tree holds.
34
+ */
35
+ export declare function countUntrackedFiles(repository: string, signal?: AbortSignal): Promise<number>;
36
+ /**
37
+ * Bundle the state a remote run starts from.
38
+ *
39
+ * `HEAD` is the history the bundle carries. When the working tree holds tracked
40
+ * uncommitted changes, their snapshot commit travels with it, so the run starts
41
+ * from what the user has on disk rather than from what they last committed.
42
+ * @param input - repository, destination and cancellation.
43
+ * @returns the commit the run branch starts from, and whether it was a snapshot.
44
+ * @throws SshWorkspaceError when the repository has no commit or git refused.
45
+ */
46
+ export declare function createWorkspaceBundle(input: {
47
+ /** Local workspace repository. */
48
+ repository: string;
49
+ /** Local path the bundle is written to. */
50
+ bundlePath: string;
51
+ /** Cancellation of the run this bundle serves. */
52
+ signal?: AbortSignal;
53
+ }): Promise<LocalWorkspaceSnapshot>;
54
+ /**
55
+ * Fetch the branch a host bundled back into the local repository.
56
+ *
57
+ * The working tree, the index, `HEAD` and the stash list are untouched: a fetch
58
+ * writes the branch ref and objects only, and the run's result stays a branch
59
+ * the user can inspect before doing anything with it.
60
+ * @param input - repository, bundle and destination branch.
61
+ * @throws SshWorkspaceError when the bundle does not apply or git refused.
62
+ */
63
+ export declare function fetchRunBranch(input: {
64
+ /** Local workspace repository. */
65
+ repository: string;
66
+ /** Local path of the downloaded bundle. */
67
+ bundlePath: string;
68
+ /** Branch ref the bundle's branch is written to. */
69
+ branchRef: string;
70
+ /** Cancellation of the run this fetch serves. */
71
+ signal?: AbortSignal;
72
+ }): Promise<void>;
@@ -0,0 +1,111 @@
1
+ import type { SshGitSource } from '../../core/target.ts';
2
+ import type { GitWorkspaceLayout } from './layout.ts';
3
+ /**
4
+ * Ref a fetched url source leaves its start commit on.
5
+ * @param source - the pinned url source.
6
+ * @returns the remote branch's ref, or the remote HEAD's when no base was pinned.
7
+ */
8
+ export declare function remoteStartRef(source: Extract<SshGitSource, {
9
+ kind: 'url';
10
+ }>): string;
11
+ /**
12
+ * Build the probe that answers whether one absolute directory exists.
13
+ * @param path - absolute remote directory.
14
+ * @returns one shell command.
15
+ */
16
+ export declare function directoryProbeCommand(path: string): string;
17
+ /**
18
+ * Build the probe that answers whether a run's worktree is already in place.
19
+ * @param layout - the run's paths.
20
+ * @returns one shell command that exits zero only when both halves hold.
21
+ */
22
+ export declare function preparedProbeCommand(layout: GitWorkspaceLayout): string;
23
+ /**
24
+ * Build the probe that answers whether a run's branch exists in the cache.
25
+ * @param layout - the run's paths.
26
+ * @returns one shell command.
27
+ */
28
+ export declare function branchProbeCommand(layout: GitWorkspaceLayout): string;
29
+ /**
30
+ * Build the command that creates the bare cache and drops dead worktrees.
31
+ *
32
+ * `git init --bare` on an existing cache is a no-op, which is what makes this
33
+ * safe to replay; `worktree prune` forgets registrations whose directory is
34
+ * gone, so a worktree a person deleted by hand can be re-attached instead of
35
+ * refused as "already registered".
36
+ * @param layout - the run's paths.
37
+ * @returns one shell command.
38
+ */
39
+ export declare function prepareCacheCommand(layout: GitWorkspaceLayout): string;
40
+ /**
41
+ * Build the command that fetches a url source's branches into the cache.
42
+ * @param layout - the run's paths.
43
+ * @param url - clone URL the host can reach.
44
+ * @returns one shell command.
45
+ */
46
+ export declare function fetchUrlCommand(layout: GitWorkspaceLayout, url: string): string;
47
+ /**
48
+ * Build the command that unpacks an uploaded bundle into the cache.
49
+ *
50
+ * Uses `git bundle unbundle` instead of `git fetch +HEAD:...`: when the local
51
+ * working tree is dirty (`git stash create`), `git bundle` only advertises
52
+ * `HEAD` as a ref header while carrying the snapshot commit in the packfile.
53
+ * On a second run where `HEAD` has not moved, `git fetch` sees `HEAD` already
54
+ * in the bare cache and skips unpacking the packfile, leaving the snapshot
55
+ * commit missing. `bundle unbundle` unconditionally unpacks every object so
56
+ * {@link pinBaseCommand} can pin the snapshot SHA directly.
57
+ * @param layout - the run's paths.
58
+ * @param bundlePath - absolute remote path of the uploaded bundle.
59
+ * @returns one shell command.
60
+ */
61
+ export declare function fetchBundleCommand(layout: GitWorkspaceLayout, bundlePath: string): string;
62
+ /**
63
+ * Build the command that pins the commit a run branch starts from.
64
+ * @param layout - the run's paths.
65
+ * @param commit - object name to pin.
66
+ * @returns one shell command.
67
+ */
68
+ export declare function pinBaseCommand(layout: GitWorkspaceLayout, commit: string): string;
69
+ /**
70
+ * Build the command that creates a run's worktree on a new branch.
71
+ * @param layout - the run's paths.
72
+ * @param startRef - ref or commit the branch starts from.
73
+ * @returns one shell command.
74
+ */
75
+ export declare function addWorktreeCommand(layout: GitWorkspaceLayout, startRef: string): string;
76
+ /**
77
+ * Build the command that re-attaches a run's worktree to its existing branch.
78
+ * @param layout - the run's paths.
79
+ * @returns one shell command.
80
+ */
81
+ export declare function attachWorktreeCommand(layout: GitWorkspaceLayout): string;
82
+ /**
83
+ * Build the command that counts the commits a run branch carries past its base.
84
+ * @param layout - the run's paths.
85
+ * @returns one shell command that prints one integer.
86
+ */
87
+ export declare function countRunCommitsCommand(layout: GitWorkspaceLayout): string;
88
+ /**
89
+ * Build the command that pushes a run branch to a url source's repository.
90
+ * @param layout - the run's paths.
91
+ * @param url - clone URL the host can reach.
92
+ * @returns one shell command.
93
+ */
94
+ export declare function pushBranchCommand(layout: GitWorkspaceLayout, url: string): string;
95
+ /**
96
+ * Build the command that bundles a run branch without its base.
97
+ *
98
+ * The base commit is the local repository's own HEAD or its working-tree
99
+ * snapshot, so leaving it out keeps the download to the commits the run made.
100
+ * @param layout - the run's paths.
101
+ * @param bundlePath - absolute remote path to write.
102
+ * @returns one shell command.
103
+ */
104
+ export declare function bundleResultCommand(layout: GitWorkspaceLayout, bundlePath: string): string;
105
+ /**
106
+ * Build the best-effort command that removes one run's worktree, branch and
107
+ * base ref from the shared bare cache when its card is deleted.
108
+ * @param layout - the run's paths.
109
+ * @returns one shell command.
110
+ */
111
+ export declare function removeWorktreeCommand(layout: GitWorkspaceLayout): string;