@melihmucuk/pi-crew 1.0.4 → 1.0.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/README.md CHANGED
@@ -8,10 +8,18 @@ Non-blocking subagent orchestration for [pi](https://pi.dev). Spawn isolated sub
8
8
 
9
9
  ## Install
10
10
 
11
+ From npm:
12
+
11
13
  ```bash
12
14
  pi install npm:@melihmucuk/pi-crew
13
15
  ```
14
16
 
17
+ From git:
18
+
19
+ ```bash
20
+ pi install git:github.com/melihmucuk/pi-crew
21
+ ```
22
+
15
23
  This installs the extension, bundled prompt template, and bundled subagent definitions. Bundled subagents are automatically discovered and ready to use without any extra setup.
16
24
 
17
25
  ## Architecture
package/dist/index.js CHANGED
@@ -1,27 +1,49 @@
1
1
  import { dirname } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
+ import { discoverAgents } from "./agent-discovery.js";
3
4
  import { CrewManager } from "./crew-manager.js";
4
5
  import { registerCrewIntegration } from "./integration.js";
6
+ import { formatAgentsForPrompt } from "./prompt-injection.js";
5
7
  import { updateWidget } from "./status-widget.js";
6
8
  const extensionDir = dirname(fileURLToPath(import.meta.url));
7
9
  export default function (pi) {
8
10
  const crewManager = new CrewManager(extensionDir);
9
11
  let currentCtx;
12
+ let cachedPromptSuffix = "";
10
13
  const refreshWidget = () => {
11
14
  if (currentCtx)
12
15
  updateWidget(currentCtx, crewManager);
13
16
  };
17
+ const rebuildPromptCache = (cwd) => {
18
+ const { agents } = discoverAgents(cwd);
19
+ cachedPromptSuffix = formatAgentsForPrompt(agents);
20
+ };
14
21
  const activateSession = (ctx) => {
15
22
  currentCtx = ctx;
16
23
  crewManager.activateSession(ctx.sessionManager.getSessionId(), () => ctx.isIdle(), pi);
17
24
  refreshWidget();
18
25
  };
19
26
  crewManager.onWidgetUpdate = refreshWidget;
20
- pi.on("session_start", (_event, ctx) => activateSession(ctx));
27
+ pi.on("session_start", (_event, ctx) => {
28
+ rebuildPromptCache(ctx.cwd);
29
+ activateSession(ctx);
30
+ });
21
31
  pi.on("session_switch", (_event, ctx) => activateSession(ctx));
22
32
  pi.on("session_fork", (_event, ctx) => activateSession(ctx));
23
33
  pi.on("session_shutdown", (_event, ctx) => {
24
34
  crewManager.abortForOwner(ctx.sessionManager.getSessionId(), pi);
25
35
  });
36
+ pi.on("before_agent_start", (event) => {
37
+ if (!cachedPromptSuffix)
38
+ return;
39
+ const marker = "\nCurrent date: ";
40
+ const idx = event.systemPrompt.lastIndexOf(marker);
41
+ if (idx === -1) {
42
+ return { systemPrompt: event.systemPrompt + cachedPromptSuffix };
43
+ }
44
+ const before = event.systemPrompt.slice(0, idx);
45
+ const after = event.systemPrompt.slice(idx);
46
+ return { systemPrompt: before + cachedPromptSuffix + after };
47
+ });
26
48
  registerCrewIntegration(pi, crewManager);
27
49
  }
@@ -0,0 +1,8 @@
1
+ import type { AgentConfig } from "./agent-discovery.js";
2
+ /**
3
+ * Format discovered agent definitions for inclusion in the system prompt.
4
+ * Uses XML format consistent with pi's skill injection.
5
+ *
6
+ * Returns an empty string when no agents are available.
7
+ */
8
+ export declare function formatAgentsForPrompt(agents: AgentConfig[]): string;
@@ -0,0 +1,39 @@
1
+ function escapeXml(str) {
2
+ return str
3
+ .replace(/&/g, "&")
4
+ .replace(/</g, "&lt;")
5
+ .replace(/>/g, "&gt;")
6
+ .replace(/"/g, "&quot;")
7
+ .replace(/'/g, "&apos;");
8
+ }
9
+ /**
10
+ * Format discovered agent definitions for inclusion in the system prompt.
11
+ * Uses XML format consistent with pi's skill injection.
12
+ *
13
+ * Returns an empty string when no agents are available.
14
+ */
15
+ export function formatAgentsForPrompt(agents) {
16
+ if (agents.length === 0)
17
+ return "";
18
+ const lines = [
19
+ "",
20
+ "",
21
+ "---",
22
+ "The following subagents can be spawned via crew_spawn to handle tasks in parallel.",
23
+ "Use crew_list to see their current status. Interactive subagents stay alive after responding;",
24
+ "use crew_respond to continue and crew_done to close them.",
25
+ "",
26
+ "<available_subagents>",
27
+ ];
28
+ for (const agent of agents) {
29
+ lines.push(" <subagent>");
30
+ lines.push(` <name>${escapeXml(agent.name)}</name>`);
31
+ lines.push(` <description>${escapeXml(agent.description)}</description>`);
32
+ lines.push(` <interactive>${agent.interactive ? "true" : "false"}</interactive>`);
33
+ lines.push(" </subagent>");
34
+ }
35
+ lines.push("</available_subagents>");
36
+ lines.push("---");
37
+ lines.push("");
38
+ return lines.join("\n");
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melihmucuk/pi-crew",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "description": "Non-blocking subagent orchestration for pi coding agent",
6
6
  "files": [
@@ -31,7 +31,8 @@
31
31
  "scripts": {
32
32
  "clean": "rm -rf dist",
33
33
  "build": "npm run clean && tsc",
34
- "typecheck": "tsc --noEmit"
34
+ "typecheck": "tsc --noEmit",
35
+ "prepare": "npm run build"
35
36
  },
36
37
  "peerDependencies": {
37
38
  "@mariozechner/pi-ai": "*",