@howaboua/pi-shepherdr 0.1.4 → 0.1.5
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 +4 -0
- package/README.md +2 -2
- package/index.ts +8 -15
- package/package.json +6 -6
- package/src/controller.ts +9 -55
- package/src/machine-menu.ts +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# @howaboua/pi-shepherdr
|
|
2
2
|
|
|
3
|
+
## 0.1.5
|
|
4
|
+
|
|
5
|
+
- Make the agents tool always available and start fleet monitoring automatically. `/herdr` now toggles only orchestration guidance, not tool availability.
|
|
6
|
+
|
|
3
7
|
## 0.1.4
|
|
4
8
|
|
|
5
9
|
- Preserve extension-owned messages while delivering true developer-role policy through compatible Pi Codex Responses adapters.
|
package/README.md
CHANGED
|
@@ -26,13 +26,13 @@ Pi Codex 3.0.25 or newer is optional. Without it, Shepherdr remains a normal Pi
|
|
|
26
26
|
|
|
27
27
|
## Enable orchestration
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
The agent tool is always available in Pi, Code Mode and Notebook Mode. Run Pi inside Herdr to connect the fleet and start monitoring automatically. To prioritize orchestration over direct work for the current session:
|
|
30
30
|
|
|
31
31
|
```text
|
|
32
32
|
/herdr
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
The command records one visible
|
|
35
|
+
The command only records one visible guidance message without triggering a turn. Run `/herdr` again to return to normal guidance. Resumed sessions restore their last mode; new sessions start with normal guidance. Tool availability and monitoring do not depend on this mode.
|
|
36
36
|
|
|
37
37
|
`/herdr machines` opens the Add/Remove Machine interface. Settings live at `<pi-agent-directory>/shepherdr.json`, where the directory defaults to `~/.pi/agent` and `PI_CODING_AGENT_DIR` overrides it. `/herdr connect [machine]` retries configured remotes after activation.
|
|
38
38
|
|
package/index.ts
CHANGED
|
@@ -22,30 +22,23 @@ export default async function shepherdrExtension(
|
|
|
22
22
|
|
|
23
23
|
registerAgentEventRenderer(pi);
|
|
24
24
|
pi.registerTool(tool);
|
|
25
|
-
|
|
26
|
-
registerAgentController(pi, fleet
|
|
27
|
-
onActiveChange: () => registration?.refresh(),
|
|
28
|
-
});
|
|
25
|
+
await registerAgentsInCodeMode(pi, tool);
|
|
26
|
+
registerAgentController(pi, fleet);
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
async function registerAgentsInCodeMode(
|
|
32
30
|
pi: ExtensionAPI,
|
|
33
31
|
tool: ReturnType<typeof createAgentsTool>,
|
|
34
|
-
fleet: AgentFleet,
|
|
35
32
|
) {
|
|
36
33
|
try {
|
|
37
34
|
const { adaptToolForCodeMode, registerCodeModeExtensionTools } =
|
|
38
35
|
await import("@howaboua/pi-codex-conversion/code-mode");
|
|
39
|
-
const registration = registerCodeModeExtensionTools(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}),
|
|
46
|
-
],
|
|
47
|
-
{ isActive: () => fleet.isActive() },
|
|
48
|
-
);
|
|
36
|
+
const registration = registerCodeModeExtensionTools(pi, () => [
|
|
37
|
+
adaptToolForCodeMode(tool, {
|
|
38
|
+
blocking: isBlockingAgentsCall,
|
|
39
|
+
usage: 'await tools.agents({ action: "help" }) // first call alone',
|
|
40
|
+
}),
|
|
41
|
+
]);
|
|
49
42
|
pi.on("session_shutdown", () => registration.unregister());
|
|
50
43
|
return registration;
|
|
51
44
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-shepherdr",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Persistent blocking and asynchronous Pi agents through Herdr.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"pack:dry": "npm pack --dry-run"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@howaboua/pi-codex-conversion": ">=3.0.
|
|
46
|
+
"@howaboua/pi-codex-conversion": ">=3.0.29",
|
|
47
47
|
"@earendil-works/pi-ai": ">=0.84.3",
|
|
48
48
|
"@earendil-works/pi-coding-agent": ">=0.84.3",
|
|
49
49
|
"@earendil-works/pi-tui": ">=0.84.3",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@howaboua/pi-codex-conversion": "3.0.
|
|
58
|
+
"@howaboua/pi-codex-conversion": "3.0.29",
|
|
59
59
|
"@biomejs/biome": "^2.5.10",
|
|
60
|
-
"@earendil-works/pi-ai": "0.85.
|
|
61
|
-
"@earendil-works/pi-coding-agent": "0.85.
|
|
62
|
-
"@earendil-works/pi-tui": "0.85.
|
|
60
|
+
"@earendil-works/pi-ai": "0.85.1",
|
|
61
|
+
"@earendil-works/pi-coding-agent": "0.85.1",
|
|
62
|
+
"@earendil-works/pi-tui": "0.85.1",
|
|
63
63
|
"@types/node": "^26.2.0",
|
|
64
64
|
"typebox": "1.3.18",
|
|
65
65
|
"typescript": "^7.0.2"
|
package/src/controller.ts
CHANGED
|
@@ -7,10 +7,6 @@ import type { AgentFleet } from "./fleet.js";
|
|
|
7
7
|
import { showMachineMenu } from "./machine-menu.js";
|
|
8
8
|
import { loadAgentProfiles } from "./profiles.js";
|
|
9
9
|
|
|
10
|
-
interface AgentControllerOptions {
|
|
11
|
-
onActiveChange?(): void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
10
|
const ORCHESTRATION_STATE_TYPE = "pi-shepherdr-orchestration-state";
|
|
15
11
|
const GENERAL_ORCHESTRATION_MESSAGE =
|
|
16
12
|
"Your main goal from now on is to orchestrate agents. Fan out suitable work to general agents, synthesize their results, and report the outcome. Work directly only when asked or for routine local tasks.";
|
|
@@ -21,13 +17,8 @@ const NORMAL_MESSAGE = "Work normally. Delegate only when useful or requested.";
|
|
|
21
17
|
export function registerAgentController(
|
|
22
18
|
pi: ExtensionAPI,
|
|
23
19
|
fleet: AgentFleet,
|
|
24
|
-
options: AgentControllerOptions = {},
|
|
25
20
|
): void {
|
|
26
21
|
let orchestrationEnabled = false;
|
|
27
|
-
const setActive = (active: boolean) => {
|
|
28
|
-
setToolActive(pi, "agents", active);
|
|
29
|
-
options.onActiveChange?.();
|
|
30
|
-
};
|
|
31
22
|
pi.registerCommand("herdr", {
|
|
32
23
|
description: "Toggle agent orchestration or manage Herdr machines",
|
|
33
24
|
getArgumentCompletions: (prefix) =>
|
|
@@ -38,13 +29,7 @@ export function registerAgentController(
|
|
|
38
29
|
const [rawAction = "", ...rest] = args.trim().split(/\s+/);
|
|
39
30
|
const action = rawAction.toLowerCase();
|
|
40
31
|
if (!action) {
|
|
41
|
-
orchestrationEnabled = restoreOrchestrationState(ctx)
|
|
42
|
-
if (
|
|
43
|
-
!fleet.isActive() &&
|
|
44
|
-
!(await activateController(fleet, ctx, setActive))
|
|
45
|
-
) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
32
|
+
orchestrationEnabled = restoreOrchestrationState(ctx);
|
|
48
33
|
orchestrationEnabled = !orchestrationEnabled;
|
|
49
34
|
sendPolicyMessage(
|
|
50
35
|
pi,
|
|
@@ -72,8 +57,8 @@ export function registerAgentController(
|
|
|
72
57
|
}
|
|
73
58
|
if (action === "connect") {
|
|
74
59
|
if (!fleet.isActive()) {
|
|
75
|
-
|
|
76
|
-
return;
|
|
60
|
+
await activateController(fleet, ctx);
|
|
61
|
+
if (!fleet.isActive()) return;
|
|
77
62
|
}
|
|
78
63
|
try {
|
|
79
64
|
ctx.ui.notify(fleet.connect(rest[0]), "info");
|
|
@@ -90,11 +75,8 @@ export function registerAgentController(
|
|
|
90
75
|
});
|
|
91
76
|
|
|
92
77
|
pi.on("session_start", async (_event, ctx) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
fleet.deactivate();
|
|
96
|
-
setActive(false);
|
|
97
|
-
if (state.recorded) await activateController(fleet, ctx, setActive);
|
|
78
|
+
orchestrationEnabled = restoreOrchestrationState(ctx);
|
|
79
|
+
await activateController(fleet, ctx);
|
|
98
80
|
});
|
|
99
81
|
|
|
100
82
|
pi.on("session_shutdown", () => {
|
|
@@ -108,12 +90,8 @@ async function orchestrationMessage(): Promise<string> {
|
|
|
108
90
|
: ORCHESTRATION_MESSAGE;
|
|
109
91
|
}
|
|
110
92
|
|
|
111
|
-
function restoreOrchestrationState(ctx: ExtensionContext): {
|
|
112
|
-
enabled: boolean;
|
|
113
|
-
recorded: boolean;
|
|
114
|
-
} {
|
|
93
|
+
function restoreOrchestrationState(ctx: ExtensionContext): boolean {
|
|
115
94
|
let enabled = false;
|
|
116
|
-
let recorded = false;
|
|
117
95
|
for (const entry of ctx.sessionManager.getBranch()) {
|
|
118
96
|
if (
|
|
119
97
|
(entry.type !== "custom" && entry.type !== "custom_message") ||
|
|
@@ -129,52 +107,28 @@ function restoreOrchestrationState(ctx: ExtensionContext): {
|
|
|
129
107
|
typeof state.enabled === "boolean"
|
|
130
108
|
) {
|
|
131
109
|
enabled = state.enabled;
|
|
132
|
-
recorded = true;
|
|
133
110
|
}
|
|
134
111
|
}
|
|
135
|
-
return
|
|
112
|
+
return enabled;
|
|
136
113
|
}
|
|
137
114
|
|
|
138
115
|
async function activateController(
|
|
139
116
|
fleet: AgentFleet,
|
|
140
117
|
ctx: ExtensionContext,
|
|
141
|
-
setActive: (active: boolean) => void,
|
|
142
118
|
): Promise<boolean> {
|
|
143
119
|
if (process.env["HERDR_ENV"] !== "1" || !process.env["HERDR_SOCKET_PATH"]) {
|
|
144
|
-
|
|
145
|
-
ctx.ui.notify(
|
|
146
|
-
"Agent orchestration requires Pi to run inside Herdr",
|
|
147
|
-
"error",
|
|
148
|
-
);
|
|
120
|
+
ctx.ui.notify("Shepherdr requires Pi to run inside Herdr", "error");
|
|
149
121
|
return false;
|
|
150
122
|
}
|
|
151
123
|
try {
|
|
152
124
|
await fleet.activate(ctx);
|
|
153
|
-
setActive(true);
|
|
154
125
|
return true;
|
|
155
126
|
} catch (error) {
|
|
156
127
|
fleet.deactivate();
|
|
157
|
-
setActive(false);
|
|
158
128
|
ctx.ui.notify(
|
|
159
|
-
`
|
|
129
|
+
`Shepherdr could not start: ${error instanceof Error ? error.message : String(error)}`,
|
|
160
130
|
"error",
|
|
161
131
|
);
|
|
162
132
|
return false;
|
|
163
133
|
}
|
|
164
134
|
}
|
|
165
|
-
|
|
166
|
-
function setToolActive(
|
|
167
|
-
pi: ExtensionAPI,
|
|
168
|
-
toolName: string,
|
|
169
|
-
active: boolean,
|
|
170
|
-
): void {
|
|
171
|
-
const current = pi.getActiveTools();
|
|
172
|
-
const withoutTool = current.filter((name) => name !== toolName);
|
|
173
|
-
const next = active ? [...withoutTool, toolName] : withoutTool;
|
|
174
|
-
if (
|
|
175
|
-
next.length !== current.length ||
|
|
176
|
-
next.some((name, index) => name !== current[index])
|
|
177
|
-
) {
|
|
178
|
-
pi.setActiveTools(next);
|
|
179
|
-
}
|
|
180
|
-
}
|
package/src/machine-menu.ts
CHANGED
|
@@ -94,7 +94,10 @@ export async function showMachineMenu(
|
|
|
94
94
|
]);
|
|
95
95
|
if (action === "Connect") {
|
|
96
96
|
if (!fleet.isActive()) {
|
|
97
|
-
ctx.ui.notify(
|
|
97
|
+
ctx.ui.notify(
|
|
98
|
+
"Fleet unavailable; run /herdr connect to retry",
|
|
99
|
+
"warning",
|
|
100
|
+
);
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
100
103
|
ctx.ui.notify(fleet.connect(name), "info");
|