@howaboua/pi-shepherdr 0.2.0 → 0.2.2
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 +20 -0
- package/README.md +8 -4
- package/index.ts +4 -1
- package/package.json +4 -4
- package/src/agents-contract.ts +1 -3
- package/src/agents-operations.ts +50 -14
- package/src/agents-tool.ts +57 -46
- package/src/delivery.ts +76 -1
- package/src/herdr-client.ts +26 -2
- package/src/machine-catalog.ts +27 -10
- package/src/messages.ts +11 -5
- package/src/monitor-state.ts +22 -1
- package/src/monitor.ts +4 -2
- package/src/peer-inbox.ts +237 -0
- package/src/remote/shepherdr-peer.mjs +225 -0
- package/src/remote/shepherdr.mjs +5 -1
- package/src/remote-client.ts +43 -8
- package/src/types.ts +10 -0
- package/tsconfig.json +7 -1
package/src/remote-client.ts
CHANGED
|
@@ -5,10 +5,18 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import type { HerdrConnection } from "./herdr-client.js";
|
|
6
6
|
import type { SshMachine } from "./machine-catalog.js";
|
|
7
7
|
import type { AssistantReader } from "./session-reader.js";
|
|
8
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
HerdrEvent,
|
|
10
|
+
LatestAssistant,
|
|
11
|
+
PaneInfo,
|
|
12
|
+
PeerDelivery,
|
|
13
|
+
PeerMessage,
|
|
14
|
+
SessionView,
|
|
15
|
+
} from "./types.js";
|
|
9
16
|
|
|
10
|
-
const BRIDGE_VERSION =
|
|
17
|
+
const BRIDGE_VERSION = 6;
|
|
11
18
|
const REMOTE_HELPER = "~/.pi/agent/shepherdr.mjs";
|
|
19
|
+
const REMOTE_PEER_HELPER = "~/.pi/agent/shepherdr-peer.mjs";
|
|
12
20
|
const MAX_FRAME_BYTES = 8 * 1024 * 1024;
|
|
13
21
|
const MAX_DIAGNOSTIC_BYTES = 8 * 1024;
|
|
14
22
|
const DEPLOY_TIMEOUT_MS = 20_000;
|
|
@@ -104,12 +112,16 @@ function appendBounded(current: string, chunk: Buffer): string {
|
|
|
104
112
|
: next.slice(next.length - MAX_DIAGNOSTIC_BYTES);
|
|
105
113
|
}
|
|
106
114
|
|
|
107
|
-
async function deploy(
|
|
115
|
+
async function deploy(
|
|
116
|
+
config: SshMachine,
|
|
117
|
+
source: Buffer,
|
|
118
|
+
target: string,
|
|
119
|
+
): Promise<void> {
|
|
108
120
|
const command = [
|
|
109
121
|
"node",
|
|
110
122
|
"-e",
|
|
111
123
|
shellQuote(DEPLOY_SOURCE),
|
|
112
|
-
shellQuote(
|
|
124
|
+
shellQuote(target),
|
|
113
125
|
].join(" ");
|
|
114
126
|
const child = spawnConnector(config, command);
|
|
115
127
|
let stdout = "";
|
|
@@ -181,10 +193,16 @@ export class RemoteHerdrClient implements HerdrConnection, AssistantReader {
|
|
|
181
193
|
config: SshMachine,
|
|
182
194
|
onClose: (error: Error) => void,
|
|
183
195
|
): Promise<RemoteHerdrClient> {
|
|
184
|
-
const source = await
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
196
|
+
const [source, peerSource] = await Promise.all([
|
|
197
|
+
readFile(
|
|
198
|
+
fileURLToPath(new URL("./remote/shepherdr.mjs", import.meta.url)),
|
|
199
|
+
),
|
|
200
|
+
readFile(
|
|
201
|
+
fileURLToPath(new URL("./remote/shepherdr-peer.mjs", import.meta.url)),
|
|
202
|
+
),
|
|
203
|
+
]);
|
|
204
|
+
await deploy(config, peerSource, REMOTE_PEER_HELPER);
|
|
205
|
+
await deploy(config, source, REMOTE_HELPER);
|
|
188
206
|
const child = spawnConnector(config, remoteCommand(config));
|
|
189
207
|
const client = new RemoteHerdrClient(child, onClose);
|
|
190
208
|
try {
|
|
@@ -207,6 +225,23 @@ export class RemoteHerdrClient implements HerdrConnection, AssistantReader {
|
|
|
207
225
|
)) as T;
|
|
208
226
|
}
|
|
209
227
|
|
|
228
|
+
async sendMessage(
|
|
229
|
+
agent: PaneInfo,
|
|
230
|
+
message: PeerMessage,
|
|
231
|
+
): Promise<PeerDelivery> {
|
|
232
|
+
const result = await this.call({ op: "message", agent, message }, 26_000);
|
|
233
|
+
if (
|
|
234
|
+
!result ||
|
|
235
|
+
typeof result !== "object" ||
|
|
236
|
+
!("command" in result) ||
|
|
237
|
+
typeof result.command !== "boolean"
|
|
238
|
+
)
|
|
239
|
+
throw new Error(
|
|
240
|
+
"Invalid peer acknowledgement; inspect the target before retrying",
|
|
241
|
+
);
|
|
242
|
+
return { command: result.command };
|
|
243
|
+
}
|
|
244
|
+
|
|
210
245
|
async subscribe(
|
|
211
246
|
subscriptions: object[],
|
|
212
247
|
onEvent: (event: HerdrEvent) => void,
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
export type AgentStatus = "idle" | "working" | "blocked" | "done" | "unknown";
|
|
2
2
|
|
|
3
|
+
export interface PeerMessage {
|
|
4
|
+
text: string;
|
|
5
|
+
sender: string;
|
|
6
|
+
context?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface PeerDelivery {
|
|
10
|
+
command: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
3
13
|
export type SettledAgentStatus = Exclude<AgentStatus, "working">;
|
|
4
14
|
|
|
5
15
|
export type StableAgentActivity =
|
package/tsconfig.json
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"
|
|
3
|
+
"compilerOptions": { "allowJs": true, "checkJs": true },
|
|
4
|
+
"include": [
|
|
5
|
+
"index.ts",
|
|
6
|
+
"src/**/*.ts",
|
|
7
|
+
"src/remote/shepherdr-peer.mjs",
|
|
8
|
+
"tests/**/*.ts"
|
|
9
|
+
]
|
|
4
10
|
}
|