@howaboua/pi-shepherdr 0.2.11 → 0.2.12
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/CHANGELOG.md +15 -0
- package/README.md +38 -10
- package/package.json +6 -6
- package/src/agents-contract.ts +15 -0
- package/src/agents-discovery.ts +6 -0
- package/src/agents-tool.ts +11 -0
- package/src/attachment-notes.ts +132 -0
- package/src/attachment-protocol.ts +142 -0
- package/src/attachment-routing.ts +171 -0
- package/src/attachment-target.ts +271 -0
- package/src/attachment.ts +299 -0
- package/src/board/config.ts +16 -3
- package/src/board/host.ts +28 -26
- package/src/board/identity.ts +14 -0
- package/src/board/membership.ts +187 -0
- package/src/board/protocol.ts +5 -0
- package/src/control-panel-actions.ts +110 -0
- package/src/control-panel-items.ts +91 -0
- package/src/control-panel-view.ts +282 -0
- package/src/control-panel.ts +142 -0
- package/src/controller.ts +79 -87
- package/src/fleet.ts +19 -4
- package/src/machine-catalog.ts +19 -13
- package/src/messages.ts +39 -0
- package/src/remote/shepherdr-checkpoints.mjs +98 -0
- package/src/remote/shepherdr-context.mjs +45 -0
- package/src/remote/shepherdr.mjs +1 -1
- package/src/remote-client.ts +10 -3
- package/src/setup-process.ts +151 -0
- package/src/shared-context.ts +44 -0
- package/src/ssh-setup.ts +144 -0
- package/src/types.ts +2 -0
- package/src/widget.ts +1 -3
- package/src/board/settings.ts +0 -98
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { PanelOwners } from "./control-panel-items.js";
|
|
3
|
+
import { type SshSetupDraft, sshSetupArgs } from "./ssh-setup.js";
|
|
4
|
+
|
|
5
|
+
export interface PanelOptions extends PanelOwners {
|
|
6
|
+
setOrchestration: (enabled: boolean, signal: AbortSignal) => Promise<void>;
|
|
7
|
+
reconnect: (
|
|
8
|
+
machine: string | undefined,
|
|
9
|
+
signal: AbortSignal,
|
|
10
|
+
) => Promise<string>;
|
|
11
|
+
signal: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Executes panel actions without owning native input or terminal handoff. */
|
|
15
|
+
export class PanelActions {
|
|
16
|
+
busy = false;
|
|
17
|
+
message: string;
|
|
18
|
+
|
|
19
|
+
private readonly ctx: ExtensionContext;
|
|
20
|
+
private readonly options: PanelOptions;
|
|
21
|
+
private readonly signal: AbortSignal;
|
|
22
|
+
private readonly current: () => boolean;
|
|
23
|
+
private readonly check: () => void;
|
|
24
|
+
private readonly rebuild: () => void;
|
|
25
|
+
private readonly requestRender: () => void;
|
|
26
|
+
private readonly finish: (result: "add" | undefined) => void;
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
ctx: ExtensionContext,
|
|
30
|
+
options: PanelOptions,
|
|
31
|
+
signal: AbortSignal,
|
|
32
|
+
message: string,
|
|
33
|
+
current: () => boolean,
|
|
34
|
+
check: () => void,
|
|
35
|
+
rebuild: () => void,
|
|
36
|
+
requestRender: () => void,
|
|
37
|
+
finish: (result: "add" | undefined) => void,
|
|
38
|
+
) {
|
|
39
|
+
this.ctx = ctx;
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.signal = signal;
|
|
42
|
+
this.current = current;
|
|
43
|
+
this.check = check;
|
|
44
|
+
this.rebuild = rebuild;
|
|
45
|
+
this.requestRender = requestRender;
|
|
46
|
+
this.finish = finish;
|
|
47
|
+
this.message = message;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
change(id: string, value: string, draft: SshSetupDraft) {
|
|
51
|
+
if (id === "ssh:add") {
|
|
52
|
+
try {
|
|
53
|
+
sshSetupArgs(draft);
|
|
54
|
+
this.finish("add");
|
|
55
|
+
} catch (error) {
|
|
56
|
+
this.message = error instanceof Error ? error.message : String(error);
|
|
57
|
+
this.rebuild();
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.run(async () => {
|
|
62
|
+
if (id === "orchestration") {
|
|
63
|
+
await this.options.setOrchestration(value === "on", this.signal);
|
|
64
|
+
this.message = "Guidance saved for this session.";
|
|
65
|
+
} else if (
|
|
66
|
+
id === "board:session" ||
|
|
67
|
+
id === "board:folder" ||
|
|
68
|
+
id === "board:global"
|
|
69
|
+
) {
|
|
70
|
+
await this.options.board.setSetting(
|
|
71
|
+
this.ctx,
|
|
72
|
+
id === "board:session"
|
|
73
|
+
? "session"
|
|
74
|
+
: id === "board:folder"
|
|
75
|
+
? "folder"
|
|
76
|
+
: "global",
|
|
77
|
+
value === "inherit" ? undefined : value === "on",
|
|
78
|
+
);
|
|
79
|
+
this.check();
|
|
80
|
+
this.message = "Board setting saved.";
|
|
81
|
+
} else if (id === "connect" || id.startsWith("machine:"))
|
|
82
|
+
this.message = await this.options.reconnect(
|
|
83
|
+
id === "connect" ? undefined : id.slice(8),
|
|
84
|
+
this.signal,
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private run(work: () => Promise<void>) {
|
|
90
|
+
if (this.busy || !this.current()) {
|
|
91
|
+
this.rebuild();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.busy = true;
|
|
95
|
+
this.message = "Working...";
|
|
96
|
+
this.requestRender();
|
|
97
|
+
void (async () => {
|
|
98
|
+
try {
|
|
99
|
+
this.check();
|
|
100
|
+
await work();
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (this.current())
|
|
103
|
+
this.message = error instanceof Error ? error.message : String(error);
|
|
104
|
+
} finally {
|
|
105
|
+
this.busy = false;
|
|
106
|
+
this.rebuild();
|
|
107
|
+
}
|
|
108
|
+
})();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { SettingItem } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { AgentBoard } from "./board/host.js";
|
|
4
|
+
import type { AgentFleet } from "./fleet.js";
|
|
5
|
+
import { type SshSetupDraft, sshSetupItems } from "./ssh-setup.js";
|
|
6
|
+
|
|
7
|
+
export const PANEL_TABS = ["Settings", "Status", "Connections"] as const;
|
|
8
|
+
export type PanelTab = (typeof PANEL_TABS)[number];
|
|
9
|
+
export interface PanelOwners {
|
|
10
|
+
fleet: AgentFleet;
|
|
11
|
+
board: AgentBoard;
|
|
12
|
+
orchestration: () => boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function buildPanelItems(
|
|
16
|
+
ctx: ExtensionContext,
|
|
17
|
+
options: PanelOwners,
|
|
18
|
+
tab: PanelTab,
|
|
19
|
+
draft: SshSetupDraft,
|
|
20
|
+
): SettingItem[] {
|
|
21
|
+
if (tab === "Connections") return sshSetupItems(draft);
|
|
22
|
+
if (tab === "Status")
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
id: "connect",
|
|
26
|
+
label: "Refresh and reconnect",
|
|
27
|
+
currentValue: "Enter",
|
|
28
|
+
values: ["Enter"],
|
|
29
|
+
description: "Reload Herdr profiles and retry connections.",
|
|
30
|
+
},
|
|
31
|
+
...options.fleet.statuses().map((machine) => ({
|
|
32
|
+
id: `machine:${machine.id}`,
|
|
33
|
+
label: machine.label ?? (machine.local ? "Local" : machine.id),
|
|
34
|
+
currentValue: machine.attempting ? "connecting" : machine.status,
|
|
35
|
+
values: ["Enter"],
|
|
36
|
+
description: [
|
|
37
|
+
machine.target,
|
|
38
|
+
machine.reason,
|
|
39
|
+
machine.monitoringIssue
|
|
40
|
+
? `Monitoring: ${machine.monitoringIssue.message}`
|
|
41
|
+
: undefined,
|
|
42
|
+
machine.contextRelayError
|
|
43
|
+
? `Sharing: ${machine.contextRelayError}`
|
|
44
|
+
: undefined,
|
|
45
|
+
"Enter to reconnect.",
|
|
46
|
+
]
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join("\n"),
|
|
49
|
+
})),
|
|
50
|
+
];
|
|
51
|
+
const rows: SettingItem[] = [
|
|
52
|
+
{
|
|
53
|
+
id: "orchestration",
|
|
54
|
+
label: "Prioritize delegation",
|
|
55
|
+
currentValue: options.orchestration() ? "on" : "off",
|
|
56
|
+
values: ["off", "on"],
|
|
57
|
+
description: "Prefer delegation over direct work in this session.",
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
try {
|
|
61
|
+
const settings = options.board.settings(ctx);
|
|
62
|
+
for (const scope of ["session", "folder", "global"] as const) {
|
|
63
|
+
if (scope === "folder" && !settings.paths.folder) continue;
|
|
64
|
+
rows.push({
|
|
65
|
+
id: `board:${scope}`,
|
|
66
|
+
label: `Board ${scope}`,
|
|
67
|
+
currentValue:
|
|
68
|
+
settings[scope] === undefined
|
|
69
|
+
? "inherit"
|
|
70
|
+
: settings[scope]
|
|
71
|
+
? "on"
|
|
72
|
+
: "off",
|
|
73
|
+
values: scope === "global" ? ["off", "on"] : ["inherit", "on", "off"],
|
|
74
|
+
description:
|
|
75
|
+
scope === "session"
|
|
76
|
+
? "Overrides folder and global defaults. Inherit removes the override."
|
|
77
|
+
: scope === "folder"
|
|
78
|
+
? "Default for this exact launch folder, unless overridden by the session."
|
|
79
|
+
: "Default for sessions without a session or folder override.",
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
rows.push({
|
|
84
|
+
id: "board-owner",
|
|
85
|
+
label: "Board settings",
|
|
86
|
+
currentValue: "unavailable",
|
|
87
|
+
description: error instanceof Error ? error.message : String(error),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return rows;
|
|
91
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ExtensionContext,
|
|
3
|
+
getSettingsListTheme,
|
|
4
|
+
type Theme,
|
|
5
|
+
} from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import {
|
|
7
|
+
getKeybindings,
|
|
8
|
+
Input,
|
|
9
|
+
Key,
|
|
10
|
+
matchesKey,
|
|
11
|
+
type SettingItem,
|
|
12
|
+
SettingsList,
|
|
13
|
+
type TUI,
|
|
14
|
+
type TuiMouseEvent,
|
|
15
|
+
truncateToWidth,
|
|
16
|
+
wrapTextWithAnsi,
|
|
17
|
+
} from "@earendil-works/pi-tui";
|
|
18
|
+
import type { PanelActions } from "./control-panel-actions.js";
|
|
19
|
+
import {
|
|
20
|
+
buildPanelItems,
|
|
21
|
+
type PanelOwners,
|
|
22
|
+
type PanelTab,
|
|
23
|
+
PANEL_TABS as TABS,
|
|
24
|
+
} from "./control-panel-items.js";
|
|
25
|
+
import type { SshSetupDraft } from "./ssh-setup.js";
|
|
26
|
+
|
|
27
|
+
const LIST_ROWS = 8;
|
|
28
|
+
|
|
29
|
+
/** Native list, field editor and mouse geometry share one selection owner. */
|
|
30
|
+
export class PanelView {
|
|
31
|
+
private selectedRow: string | undefined;
|
|
32
|
+
private editing: Input | undefined;
|
|
33
|
+
private list!: SettingsList;
|
|
34
|
+
private definitions: SettingItem[] = [];
|
|
35
|
+
private listRowOffset = 0;
|
|
36
|
+
private listHeight = 0;
|
|
37
|
+
private pressedRow: string | undefined;
|
|
38
|
+
|
|
39
|
+
private readonly ctx: ExtensionContext;
|
|
40
|
+
private readonly owners: PanelOwners;
|
|
41
|
+
private readonly tui: TUI;
|
|
42
|
+
private readonly theme: Theme;
|
|
43
|
+
tab: PanelTab;
|
|
44
|
+
private readonly draft: SshSetupDraft;
|
|
45
|
+
private readonly actions: PanelActions;
|
|
46
|
+
private readonly current: () => boolean;
|
|
47
|
+
private readonly close: () => void;
|
|
48
|
+
|
|
49
|
+
constructor(
|
|
50
|
+
ctx: ExtensionContext,
|
|
51
|
+
owners: PanelOwners,
|
|
52
|
+
tui: TUI,
|
|
53
|
+
theme: Theme,
|
|
54
|
+
tab: PanelTab,
|
|
55
|
+
draft: SshSetupDraft,
|
|
56
|
+
actions: PanelActions,
|
|
57
|
+
current: () => boolean,
|
|
58
|
+
close: () => void,
|
|
59
|
+
) {
|
|
60
|
+
this.ctx = ctx;
|
|
61
|
+
this.owners = owners;
|
|
62
|
+
this.tui = tui;
|
|
63
|
+
this.theme = theme;
|
|
64
|
+
this.tab = tab;
|
|
65
|
+
this.draft = draft;
|
|
66
|
+
this.actions = actions;
|
|
67
|
+
this.current = current;
|
|
68
|
+
this.close = close;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
rebuild() {
|
|
72
|
+
if (!this.current() || this.editing) return;
|
|
73
|
+
try {
|
|
74
|
+
this.definitions = buildPanelItems(
|
|
75
|
+
this.ctx,
|
|
76
|
+
this.owners,
|
|
77
|
+
this.tab,
|
|
78
|
+
this.draft,
|
|
79
|
+
);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
this.actions.message =
|
|
82
|
+
error instanceof Error ? error.message : String(error);
|
|
83
|
+
this.definitions = [
|
|
84
|
+
{
|
|
85
|
+
id: "error",
|
|
86
|
+
label: "Settings unavailable",
|
|
87
|
+
currentValue: "error",
|
|
88
|
+
description: this.actions.message,
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
if (!this.definitions.some((item) => item.id === this.selectedRow))
|
|
93
|
+
this.selectedRow = this.definitions[0]?.id;
|
|
94
|
+
this.list = new SettingsList(
|
|
95
|
+
this.definitions,
|
|
96
|
+
LIST_ROWS,
|
|
97
|
+
getSettingsListTheme(),
|
|
98
|
+
(id, value) => this.change(id, value),
|
|
99
|
+
this.close,
|
|
100
|
+
);
|
|
101
|
+
this.pressedRow = undefined;
|
|
102
|
+
if (this.selectedRow) this.list.selectItem(this.selectedRow);
|
|
103
|
+
this.tui.requestRender();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private change(id: string, value: string) {
|
|
107
|
+
this.selectedRow = id;
|
|
108
|
+
if (this.actions.busy || !this.current()) {
|
|
109
|
+
this.rebuild();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (id === "ssh:target" || id === "ssh:label" || id === "ssh:session") {
|
|
113
|
+
const field =
|
|
114
|
+
id === "ssh:target"
|
|
115
|
+
? "target"
|
|
116
|
+
: id === "ssh:label"
|
|
117
|
+
? "label"
|
|
118
|
+
: "session";
|
|
119
|
+
const input = new Input({
|
|
120
|
+
prompt: `${this.definitions.find((item) => item.id === id)?.label ?? field}: `,
|
|
121
|
+
});
|
|
122
|
+
input.setValue(this.draft[field]);
|
|
123
|
+
input.focused = true;
|
|
124
|
+
input.onSubmit = (text) => {
|
|
125
|
+
this.draft[field] = text.trim();
|
|
126
|
+
this.editing = undefined;
|
|
127
|
+
this.actions.message = "";
|
|
128
|
+
this.rebuild();
|
|
129
|
+
};
|
|
130
|
+
input.onEscape = () => {
|
|
131
|
+
this.editing = undefined;
|
|
132
|
+
this.rebuild();
|
|
133
|
+
};
|
|
134
|
+
this.editing = input;
|
|
135
|
+
this.tui.requestRender();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.actions.change(id, value, this.draft);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
render(width: number) {
|
|
142
|
+
const wrap = (text: string) =>
|
|
143
|
+
text
|
|
144
|
+
.split("\n")
|
|
145
|
+
.flatMap((line) =>
|
|
146
|
+
wrapTextWithAnsi(line, Math.max(1, width - 2)).map(
|
|
147
|
+
(part) => ` ${part}`,
|
|
148
|
+
),
|
|
149
|
+
);
|
|
150
|
+
const header = [
|
|
151
|
+
this.theme.fg("accent", "─".repeat(Math.max(0, width))),
|
|
152
|
+
truncateToWidth(
|
|
153
|
+
` Shepherdr · ${TABS.map((name) => (name === this.tab ? this.theme.bold(name) : this.theme.fg("dim", name))).join(" / ")}`,
|
|
154
|
+
width,
|
|
155
|
+
"",
|
|
156
|
+
),
|
|
157
|
+
"",
|
|
158
|
+
...wrap(
|
|
159
|
+
this.tab === "Settings"
|
|
160
|
+
? this.owners.board.status(this.ctx, false)
|
|
161
|
+
: this.tab === "Connections"
|
|
162
|
+
? "Remote needs Node on SSH PATH and Pi with Herdr integration. Herdr prepares its server before saving."
|
|
163
|
+
: `${this.owners.fleet.isActive() ? "" : "Run Pi inside Herdr. "}Add SSH targets in Connections; select a machine here to reconnect.`,
|
|
164
|
+
).filter((line) => line.trim()),
|
|
165
|
+
"",
|
|
166
|
+
];
|
|
167
|
+
const listLines = this.editing
|
|
168
|
+
? this.editing.render(width)
|
|
169
|
+
: this.list.render(width).slice(0, -2);
|
|
170
|
+
this.listRowOffset = header.length;
|
|
171
|
+
this.listHeight = listLines.length;
|
|
172
|
+
return [
|
|
173
|
+
...header,
|
|
174
|
+
...listLines,
|
|
175
|
+
...(this.actions.message
|
|
176
|
+
? [
|
|
177
|
+
"",
|
|
178
|
+
...wrap(this.actions.message).map((line) =>
|
|
179
|
+
this.theme.fg(this.actions.busy ? "dim" : "muted", line),
|
|
180
|
+
),
|
|
181
|
+
]
|
|
182
|
+
: []),
|
|
183
|
+
"",
|
|
184
|
+
...wrap(
|
|
185
|
+
this.editing
|
|
186
|
+
? "Enter save · Esc cancel"
|
|
187
|
+
: "Tab switch · ↑/↓ select · Enter change · Esc close",
|
|
188
|
+
).map((line) => this.theme.fg("dim", line)),
|
|
189
|
+
this.theme.fg("accent", "─".repeat(Math.max(0, width))),
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
invalidate() {
|
|
194
|
+
this.list.invalidate();
|
|
195
|
+
this.editing?.invalidate();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
handleMouse(event: TuiMouseEvent) {
|
|
199
|
+
const y = event.y - this.listRowOffset;
|
|
200
|
+
if (!this.current() || y < 0 || y >= this.listHeight) return;
|
|
201
|
+
if (this.editing) return this.editing.handleMouse({ ...event, y });
|
|
202
|
+
if (this.actions.busy) return { handled: true, render: false };
|
|
203
|
+
const index = this.definitions.findIndex(
|
|
204
|
+
(item) => item.id === this.selectedRow,
|
|
205
|
+
);
|
|
206
|
+
// Keep refresh selection aligned with SettingsList's visible window.
|
|
207
|
+
if (event.type === "wheel" && event.wheelDelta) {
|
|
208
|
+
const next = Math.max(
|
|
209
|
+
0,
|
|
210
|
+
Math.min(
|
|
211
|
+
this.definitions.length - 1,
|
|
212
|
+
index + (event.wheelDelta < 0 ? -1 : 1),
|
|
213
|
+
),
|
|
214
|
+
);
|
|
215
|
+
this.selectedRow = this.definitions[next]?.id;
|
|
216
|
+
} else if (
|
|
217
|
+
event.button === "left" &&
|
|
218
|
+
(event.type === "press" || event.type === "click")
|
|
219
|
+
) {
|
|
220
|
+
const start = Math.max(
|
|
221
|
+
0,
|
|
222
|
+
Math.min(
|
|
223
|
+
index - Math.floor(LIST_ROWS / 2),
|
|
224
|
+
this.definitions.length - LIST_ROWS,
|
|
225
|
+
),
|
|
226
|
+
);
|
|
227
|
+
const row = start + y;
|
|
228
|
+
if (
|
|
229
|
+
row >= start &&
|
|
230
|
+
row < Math.min(start + LIST_ROWS, this.definitions.length)
|
|
231
|
+
) {
|
|
232
|
+
this.selectedRow =
|
|
233
|
+
event.type === "click"
|
|
234
|
+
? (this.pressedRow ?? this.definitions[row]?.id)
|
|
235
|
+
: this.definitions[row]?.id;
|
|
236
|
+
this.pressedRow = event.type === "press" ? this.selectedRow : undefined;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return this.list.handleMouse({ ...event, y, height: this.listHeight });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
handleInput(data: string) {
|
|
243
|
+
if (this.editing) {
|
|
244
|
+
this.editing.handleInput(data);
|
|
245
|
+
this.tui.requestRender();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (matchesKey(data, Key.escape)) {
|
|
249
|
+
this.close();
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (matchesKey(data, Key.tab) || matchesKey(data, Key.shift(Key.tab))) {
|
|
253
|
+
const direction = matchesKey(data, Key.tab) ? 1 : -1;
|
|
254
|
+
this.tab =
|
|
255
|
+
TABS[
|
|
256
|
+
(TABS.indexOf(this.tab) + direction + TABS.length) % TABS.length
|
|
257
|
+
] ?? "Settings";
|
|
258
|
+
this.selectedRow = undefined;
|
|
259
|
+
this.rebuild();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (!this.actions.busy) {
|
|
263
|
+
const kb = getKeybindings();
|
|
264
|
+
if (
|
|
265
|
+
kb.matches(data, "tui.select.up") ||
|
|
266
|
+
kb.matches(data, "tui.select.down")
|
|
267
|
+
) {
|
|
268
|
+
const direction = kb.matches(data, "tui.select.up") ? -1 : 1;
|
|
269
|
+
const index = this.definitions.findIndex(
|
|
270
|
+
(item) => item.id === this.selectedRow,
|
|
271
|
+
);
|
|
272
|
+
this.selectedRow =
|
|
273
|
+
this.definitions[
|
|
274
|
+
(index + direction + this.definitions.length) %
|
|
275
|
+
this.definitions.length
|
|
276
|
+
]?.id;
|
|
277
|
+
}
|
|
278
|
+
this.list.handleInput(data);
|
|
279
|
+
}
|
|
280
|
+
this.tui.requestRender();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { PanelActions, type PanelOptions } from "./control-panel-actions.js";
|
|
3
|
+
import type { PanelTab as Tab } from "./control-panel-items.js";
|
|
4
|
+
import { PanelView } from "./control-panel-view.js";
|
|
5
|
+
import { addSshConnection, type SshSetupDraft } from "./ssh-setup.js";
|
|
6
|
+
|
|
7
|
+
export function controlPanelStatus(
|
|
8
|
+
ctx: ExtensionContext,
|
|
9
|
+
options: PanelOptions,
|
|
10
|
+
): string {
|
|
11
|
+
return [
|
|
12
|
+
`Orchestration ${options.orchestration() ? "on" : "off"}.`,
|
|
13
|
+
options.board.status(ctx),
|
|
14
|
+
...options.fleet
|
|
15
|
+
.statuses()
|
|
16
|
+
.map(
|
|
17
|
+
(machine) =>
|
|
18
|
+
`${machine.label ?? machine.id} [${machine.id}]: ${machine.status}${machine.reason ? `\n${machine.reason}` : ""}${machine.monitoringIssue ? `\nMonitoring: ${machine.monitoringIssue.message}` : ""}${machine.contextRelayError ? `\nSharing: ${machine.contextRelayError}` : ""}`,
|
|
19
|
+
),
|
|
20
|
+
...(!options.fleet.isActive()
|
|
21
|
+
? [
|
|
22
|
+
"Fleet inactive. Run Pi inside Herdr; open /herdr → Status to reconnect.",
|
|
23
|
+
]
|
|
24
|
+
: []),
|
|
25
|
+
"Open /herdr in TUI for Settings, Status and SSH Connections.",
|
|
26
|
+
].join("\n");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function openControlPanel(
|
|
30
|
+
ctx: ExtensionContext,
|
|
31
|
+
options: PanelOptions,
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
34
|
+
const lifetime = new AbortController();
|
|
35
|
+
const signal = AbortSignal.any([options.signal, lifetime.signal]);
|
|
36
|
+
const state: { tab: Tab; message: string; draft: SshSetupDraft } = {
|
|
37
|
+
tab: "Settings",
|
|
38
|
+
message: "",
|
|
39
|
+
draft: { target: "", label: "", session: "" },
|
|
40
|
+
};
|
|
41
|
+
const check = () => {
|
|
42
|
+
signal.throwIfAborted();
|
|
43
|
+
if (ctx.sessionManager.getSessionId() !== sessionId)
|
|
44
|
+
throw new Error("Session changed; reopen /herdr");
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
while (true) {
|
|
48
|
+
check();
|
|
49
|
+
const action = await showControlPanel(
|
|
50
|
+
ctx,
|
|
51
|
+
options,
|
|
52
|
+
signal,
|
|
53
|
+
sessionId,
|
|
54
|
+
state,
|
|
55
|
+
);
|
|
56
|
+
if (action !== "add") return;
|
|
57
|
+
try {
|
|
58
|
+
check();
|
|
59
|
+
const result = await addSshConnection(ctx, state.draft, signal);
|
|
60
|
+
check();
|
|
61
|
+
state.message = result.message;
|
|
62
|
+
if (result.refresh) {
|
|
63
|
+
try {
|
|
64
|
+
await options.reconnect(undefined, signal);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
state.message += ` Refresh failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
check();
|
|
71
|
+
state.message = error instanceof Error ? error.message : String(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} finally {
|
|
75
|
+
lifetime.abort();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function showControlPanel(
|
|
80
|
+
ctx: ExtensionContext,
|
|
81
|
+
options: PanelOptions,
|
|
82
|
+
signal: AbortSignal,
|
|
83
|
+
sessionId: string,
|
|
84
|
+
state: { tab: Tab; message: string; draft: SshSetupDraft },
|
|
85
|
+
): Promise<"add" | undefined> {
|
|
86
|
+
return ctx.ui.custom<"add" | undefined>((tui, theme, _kb, done) => {
|
|
87
|
+
let disposed = false;
|
|
88
|
+
const current = () =>
|
|
89
|
+
!disposed &&
|
|
90
|
+
!signal.aborted &&
|
|
91
|
+
ctx.sessionManager.getSessionId() === sessionId;
|
|
92
|
+
const check = () => {
|
|
93
|
+
signal.throwIfAborted();
|
|
94
|
+
if (!current()) throw new Error("Session changed; reopen /herdr");
|
|
95
|
+
};
|
|
96
|
+
const actions = new PanelActions(
|
|
97
|
+
ctx,
|
|
98
|
+
options,
|
|
99
|
+
signal,
|
|
100
|
+
state.message,
|
|
101
|
+
current,
|
|
102
|
+
check,
|
|
103
|
+
() => view.rebuild(),
|
|
104
|
+
() => tui.requestRender(),
|
|
105
|
+
finish,
|
|
106
|
+
);
|
|
107
|
+
const view = new PanelView(
|
|
108
|
+
ctx,
|
|
109
|
+
options,
|
|
110
|
+
tui,
|
|
111
|
+
theme,
|
|
112
|
+
state.tab,
|
|
113
|
+
state.draft,
|
|
114
|
+
actions,
|
|
115
|
+
current,
|
|
116
|
+
close,
|
|
117
|
+
);
|
|
118
|
+
function close() {
|
|
119
|
+
finish(undefined);
|
|
120
|
+
}
|
|
121
|
+
function finish(result: "add" | undefined) {
|
|
122
|
+
if (disposed) return;
|
|
123
|
+
state.tab = view.tab;
|
|
124
|
+
state.message = actions.message;
|
|
125
|
+
cleanup();
|
|
126
|
+
done(result);
|
|
127
|
+
}
|
|
128
|
+
const subscriptions = [
|
|
129
|
+
options.fleet.subscribe(() => view.rebuild()),
|
|
130
|
+
options.board.subscribe(() => view.rebuild()),
|
|
131
|
+
];
|
|
132
|
+
function cleanup() {
|
|
133
|
+
disposed = true;
|
|
134
|
+
signal.removeEventListener("abort", close);
|
|
135
|
+
for (const unsubscribe of subscriptions) unsubscribe();
|
|
136
|
+
}
|
|
137
|
+
signal.addEventListener("abort", close, { once: true });
|
|
138
|
+
view.rebuild();
|
|
139
|
+
if (signal.aborted) close();
|
|
140
|
+
return Object.assign(view, { dispose: cleanup });
|
|
141
|
+
});
|
|
142
|
+
}
|