@melihmucuk/pi-crew 1.0.16 → 1.0.18

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 (38) hide show
  1. package/README.md +8 -8
  2. package/agents/code-reviewer.md +2 -2
  3. package/agents/oracle.md +1 -1
  4. package/agents/planner.md +5 -1
  5. package/agents/quality-reviewer.md +2 -2
  6. package/agents/scout.md +2 -2
  7. package/agents/worker.md +3 -3
  8. package/extension/catalog.ts +543 -0
  9. package/extension/crew.ts +383 -0
  10. package/extension/index.ts +7 -6
  11. package/extension/subagent-session.ts +270 -0
  12. package/extension/tools.ts +323 -0
  13. package/extension/ui.ts +309 -0
  14. package/package.json +8 -6
  15. package/prompts/pi-crew-plan.md +14 -13
  16. package/prompts/pi-crew-review.md +20 -16
  17. package/skills/pi-crew/REFERENCE.md +32 -20
  18. package/skills/pi-crew/SKILL.md +13 -10
  19. package/extension/agent-discovery.ts +0 -791
  20. package/extension/bootstrap-session.ts +0 -131
  21. package/extension/integration/register-renderers.ts +0 -77
  22. package/extension/integration/register-tools.ts +0 -39
  23. package/extension/integration/tool-presentation.ts +0 -50
  24. package/extension/integration/tools/crew-abort.ts +0 -126
  25. package/extension/integration/tools/crew-done.ts +0 -46
  26. package/extension/integration/tools/crew-list.ts +0 -92
  27. package/extension/integration/tools/crew-respond.ts +0 -59
  28. package/extension/integration/tools/crew-spawn.ts +0 -87
  29. package/extension/integration/tools/tool-deps.ts +0 -16
  30. package/extension/integration.ts +0 -13
  31. package/extension/runtime/crew-runtime.ts +0 -426
  32. package/extension/runtime/delivery-coordinator.ts +0 -131
  33. package/extension/runtime/subagent-registry.ts +0 -78
  34. package/extension/runtime/subagent-state.ts +0 -59
  35. package/extension/status-widget.ts +0 -107
  36. package/extension/subagent-messages.ts +0 -124
  37. package/extension/tool-registry.ts +0 -19
  38. /package/extension/{runtime/overflow-recovery.ts → overflow-recovery.ts} +0 -0
@@ -1,78 +0,0 @@
1
- import type { AgentConfig } from "../agent-discovery.js";
2
- import type { ActiveAgentSummary, SubagentState } from "./subagent-state.js";
3
- import {
4
- buildActiveAgentSummary,
5
- generateId,
6
- isAbortableStatus,
7
- } from "./subagent-state.js";
8
-
9
- export class SubagentRegistry {
10
- private activeAgents = new Map<string, SubagentState>();
11
-
12
- create(agentConfig: AgentConfig, task: string, ownerSessionId: string): SubagentState {
13
- const id = generateId(agentConfig.name, new Set(this.activeAgents.keys()));
14
- const state: SubagentState = {
15
- id,
16
- agentConfig,
17
- task,
18
- status: "running",
19
- ownerSessionId,
20
- session: null,
21
- turns: 0,
22
- contextTokens: 0,
23
- model: undefined,
24
- };
25
-
26
- this.activeAgents.set(id, state);
27
- return state;
28
- }
29
-
30
- get(id: string): SubagentState | undefined {
31
- return this.activeAgents.get(id);
32
- }
33
-
34
- hasState(state: SubagentState): boolean {
35
- return this.activeAgents.get(state.id) === state;
36
- }
37
-
38
- delete(id: string): void {
39
- this.activeAgents.delete(id);
40
- }
41
-
42
- countRunningForOwner(ownerSessionId: string, excludeId: string): number {
43
- let count = 0;
44
- for (const state of this.activeAgents.values()) {
45
- if (
46
- state.id !== excludeId &&
47
- state.ownerSessionId === ownerSessionId &&
48
- state.status === "running"
49
- ) {
50
- count++;
51
- }
52
- }
53
- return count;
54
- }
55
-
56
- getActiveSummariesForOwner(ownerSessionId: string): ActiveAgentSummary[] {
57
- return Array.from(this.activeAgents.values())
58
- .filter(
59
- (state) => isAbortableStatus(state.status) && state.ownerSessionId === ownerSessionId,
60
- )
61
- .map(buildActiveAgentSummary);
62
- }
63
-
64
- getOwnedAbortableIds(ownerSessionId: string): string[] {
65
- return Array.from(this.activeAgents.values())
66
- .filter(
67
- (state) =>
68
- state.ownerSessionId === ownerSessionId && isAbortableStatus(state.status),
69
- )
70
- .map((state) => state.id);
71
- }
72
-
73
- getAllAbortable(): SubagentState[] {
74
- return Array.from(this.activeAgents.values()).filter((state) =>
75
- isAbortableStatus(state.status),
76
- );
77
- }
78
- }
@@ -1,59 +0,0 @@
1
- import { randomBytes } from "node:crypto";
2
- import type { AgentSession } from "@earendil-works/pi-coding-agent";
3
- import type { AgentConfig } from "../agent-discovery.js";
4
- import type { SubagentStatus } from "../subagent-messages.js";
5
-
6
- export interface SubagentState {
7
- id: string;
8
- agentConfig: AgentConfig;
9
- task: string;
10
- status: SubagentStatus;
11
- ownerSessionId: string;
12
- session: AgentSession | null;
13
- turns: number;
14
- contextTokens: number;
15
- model: string | undefined;
16
- error?: string;
17
- result?: string;
18
- promptAbortController?: AbortController;
19
- unsubscribe?: () => void;
20
- }
21
-
22
- export interface ActiveAgentSummary {
23
- id: string;
24
- agentName: string;
25
- status: SubagentStatus;
26
- turns: number;
27
- contextTokens: number;
28
- model: string | undefined;
29
- }
30
-
31
- export function generateId(name: string, existingIds: Set<string>): string {
32
- for (let i = 0; i < 10; i++) {
33
- const id = `${name}-${randomBytes(4).toString("hex")}`;
34
- if (!existingIds.has(id)) return id;
35
- }
36
- return `${name}-${randomBytes(8).toString("hex")}`;
37
- }
38
-
39
- // Status may change externally via abort(). Standalone function avoids TS narrowing.
40
- export function isAborted(state: SubagentState): boolean {
41
- return state.status === "aborted";
42
- }
43
-
44
- export function isAbortableStatus(status: SubagentStatus): boolean {
45
- return status === "running" || status === "waiting";
46
- }
47
-
48
- export function buildActiveAgentSummary(
49
- state: SubagentState,
50
- ): ActiveAgentSummary {
51
- return {
52
- id: state.id,
53
- agentName: state.agentConfig.name,
54
- status: state.status,
55
- turns: state.turns,
56
- contextTokens: state.contextTokens,
57
- model: state.model,
58
- };
59
- }
@@ -1,107 +0,0 @@
1
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import { Text } from "@earendil-works/pi-tui";
3
- import type { ActiveAgentSummary } from "./runtime/crew-runtime.js";
4
- import type { CrewRuntime } from "./runtime/crew-runtime.js";
5
-
6
- const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
7
- const SPINNER_INTERVAL_MS = 80;
8
-
9
- function formatTokens(tokens: number): string {
10
- if (tokens >= 1_000_000) return `${(tokens / 1_000_000).toFixed(1)}M`;
11
- if (tokens >= 1_000) return `${(tokens / 1_000).toFixed(1)}k`;
12
- return String(tokens);
13
- }
14
-
15
- function buildLine(agent: ActiveAgentSummary, frame: string): string {
16
- const model = agent.model ?? "…";
17
- const icon = agent.status === "waiting" ? "⏳" : frame;
18
- return `${icon} ${agent.id} (${model}) · turn ${agent.turns} · ${formatTokens(agent.contextTokens)} ctx`;
19
- }
20
-
21
- interface WidgetState {
22
- ctx: ExtensionContext;
23
- text: Text;
24
- // biome-ignore lint: TUI type from factory param
25
- tui: any;
26
- timer: ReturnType<typeof setInterval>;
27
- frameIndex: number;
28
- }
29
-
30
- let widget: WidgetState | undefined;
31
-
32
- function disposeWidget(state: WidgetState): void {
33
- clearInterval(state.timer);
34
- if (widget === state) {
35
- widget = undefined;
36
- }
37
- }
38
-
39
- function clearWidget(): void {
40
- const current = widget;
41
- if (!current) return;
42
- disposeWidget(current);
43
- current.ctx.ui.setWidget("crew-status", undefined);
44
- }
45
-
46
- function hasRunningAgent(agents: ActiveAgentSummary[]): boolean {
47
- return agents.some((agent) => agent.status === "running");
48
- }
49
-
50
- function syncWidgetText(state: WidgetState, agents: ActiveAgentSummary[]): void {
51
- const frame = SPINNER_FRAMES[state.frameIndex % SPINNER_FRAMES.length];
52
- const lines = agents.map((agent) => buildLine(agent, frame));
53
- state.text.setText(lines.join("\n"));
54
- state.tui.requestRender();
55
- }
56
-
57
- export function updateWidget(ctx: ExtensionContext, crew: CrewRuntime): void {
58
- if (!ctx.hasUI) {
59
- clearWidget();
60
- return;
61
- }
62
-
63
- const ownerSessionId = ctx.sessionManager.getSessionId();
64
- const running = crew.getActiveSummariesForOwner(ownerSessionId);
65
- if (running.length === 0) {
66
- clearWidget();
67
- return;
68
- }
69
-
70
- if (widget && widget.ctx !== ctx) {
71
- clearWidget();
72
- }
73
-
74
- if (widget) {
75
- syncWidgetText(widget, running);
76
- return;
77
- }
78
-
79
- ctx.ui.setWidget("crew-status", (tui, _theme) => {
80
- const text = new Text("", 1, 0);
81
- const state: WidgetState = {
82
- ctx,
83
- text,
84
- tui,
85
- frameIndex: 0,
86
- timer: setInterval(() => {
87
- const agents = crew.getActiveSummariesForOwner(ownerSessionId);
88
- if (agents.length === 0) {
89
- clearWidget();
90
- return;
91
- }
92
- if (!hasRunningAgent(agents)) return;
93
- state.frameIndex++;
94
- syncWidgetText(state, agents);
95
- }, SPINNER_INTERVAL_MS),
96
- };
97
-
98
- widget = state;
99
- syncWidgetText(state, running);
100
-
101
- return Object.assign(text, {
102
- dispose() {
103
- disposeWidget(state);
104
- },
105
- });
106
- });
107
- }
@@ -1,124 +0,0 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
-
3
- export type SubagentStatus = "running" | "waiting" | "done" | "error" | "aborted";
4
-
5
- export type SendMessageFn = ExtensionAPI["sendMessage"];
6
-
7
- export const STATUS_ICON: Record<SubagentStatus, string> = {
8
- running: "⏳",
9
- waiting: "⏳",
10
- done: "✅",
11
- error: "❌",
12
- aborted: "⏹️",
13
- };
14
-
15
- export const STATUS_LABEL: Record<SubagentStatus, string> = {
16
- running: "running",
17
- waiting: "waiting for response",
18
- done: "done",
19
- error: "failed",
20
- aborted: "aborted",
21
- };
22
-
23
- export interface SteeringPayload {
24
- id: string;
25
- agentName: string;
26
- sessionFile?: string;
27
- status: SubagentStatus;
28
- result?: string;
29
- error?: string;
30
- }
31
-
32
- export interface CrewResultMessageDetails {
33
- agentId: string;
34
- agentName: string;
35
- sessionFile?: string;
36
- status: SubagentStatus;
37
- body?: string;
38
- }
39
-
40
- export function getCrewResultTitle(details: {
41
- agentId: string;
42
- agentName: string;
43
- status: SubagentStatus;
44
- }): string {
45
- return `Subagent '${details.agentName}' (${details.agentId}) ${STATUS_LABEL[details.status]}`;
46
- }
47
-
48
- function getSteeringBody(payload: SteeringPayload): string | undefined {
49
- return (payload.status === "error" || payload.status === "aborted")
50
- ? (payload.error ?? payload.result)
51
- : (payload.result ?? payload.error);
52
- }
53
-
54
- export function sendSteeringMessage(
55
- payload: SteeringPayload,
56
- sendMessage: SendMessageFn,
57
- opts: { isIdle: boolean; triggerTurn: boolean },
58
- ): void {
59
- const body = getSteeringBody(payload);
60
- const title = getCrewResultTitle({
61
- agentId: payload.id,
62
- agentName: payload.agentName,
63
- status: payload.status,
64
- });
65
- const content = body
66
- ? `**${STATUS_ICON[payload.status]} ${title}**\n\n${body}`
67
- : `**${STATUS_ICON[payload.status]} ${title}**`;
68
-
69
- const message = {
70
- customType: "crew-result",
71
- content,
72
- display: true,
73
- details: {
74
- agentId: payload.id,
75
- agentName: payload.agentName,
76
- sessionFile: payload.sessionFile,
77
- status: payload.status,
78
- body,
79
- } satisfies CrewResultMessageDetails,
80
- };
81
-
82
- sendMessage(
83
- message,
84
- opts.isIdle
85
- ? { triggerTurn: opts.triggerTurn }
86
- : { deliverAs: "steer", triggerTurn: opts.triggerTurn },
87
- );
88
- }
89
-
90
- export function sendRemainingNote(
91
- remainingCount: number,
92
- sendMessage: SendMessageFn,
93
- opts: { isIdle: boolean; triggerTurn: boolean },
94
- ): void {
95
- if (remainingCount <= 0) return;
96
-
97
- sendMessage(
98
- {
99
- customType: "crew-remaining",
100
- content: `⏳ ${remainingCount} subagent(s) still running`,
101
- display: true,
102
- },
103
- opts.isIdle
104
- ? { triggerTurn: opts.triggerTurn }
105
- : { deliverAs: "steer", triggerTurn: opts.triggerTurn },
106
- );
107
- }
108
-
109
- export function sendCrewListActiveWarning(
110
- sendMessage: SendMessageFn,
111
- opts: { isIdle: boolean; triggerTurn: boolean },
112
- ): void {
113
- sendMessage(
114
- {
115
- customType: "crew-list-warning",
116
- content:
117
- "⚠ Active subagents detected. Do not poll crew_list for completion — results arrive as steering messages. Continue with unrelated work or end your turn and wait for the steering messages.",
118
- display: true,
119
- },
120
- opts.isIdle
121
- ? { triggerTurn: opts.triggerTurn }
122
- : { deliverAs: "steer", triggerTurn: opts.triggerTurn },
123
- );
124
- }
@@ -1,19 +0,0 @@
1
- const SUPPORTED_TOOL_NAMES_LITERAL = [
2
- "read",
3
- "bash",
4
- "edit",
5
- "write",
6
- "grep",
7
- "find",
8
- "ls",
9
- ] as const;
10
-
11
- export type SupportedToolName = (typeof SUPPORTED_TOOL_NAMES_LITERAL)[number];
12
-
13
- export const SUPPORTED_TOOL_NAMES = Object.freeze(
14
- [...SUPPORTED_TOOL_NAMES_LITERAL] as SupportedToolName[],
15
- );
16
-
17
- export function isSupportedToolName(name: string): name is SupportedToolName {
18
- return SUPPORTED_TOOL_NAMES.includes(name as SupportedToolName);
19
- }