@melihmucuk/pi-crew 1.0.17 → 1.0.19
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/agents/code-reviewer.md +16 -11
- package/agents/quality-reviewer.md +8 -17
- package/extension/catalog.ts +543 -0
- package/extension/crew.ts +377 -0
- package/extension/index.ts +35 -18
- package/extension/subagent-session.ts +257 -0
- package/extension/tools.ts +323 -0
- package/extension/ui.ts +291 -0
- package/package.json +6 -6
- package/prompts/pi-crew-review.md +25 -16
- package/skills/pi-crew/SKILL.md +3 -1
- package/extension/agent-catalog.ts +0 -369
- package/extension/agent-config-fields.ts +0 -359
- package/extension/agent-discovery.ts +0 -123
- package/extension/bootstrap-session.ts +0 -131
- package/extension/integration/crew-tool-actions.ts +0 -306
- package/extension/integration/crew-tool-executor.ts +0 -109
- package/extension/integration/register-renderers.ts +0 -77
- package/extension/integration/register-tools.ts +0 -47
- package/extension/integration/tool-presentation.ts +0 -30
- package/extension/integration/tools/crew-abort.ts +0 -56
- package/extension/integration/tools/crew-done.ts +0 -27
- package/extension/integration/tools/crew-list.ts +0 -36
- package/extension/integration/tools/crew-respond.ts +0 -38
- package/extension/integration/tools/crew-spawn.ts +0 -46
- package/extension/message-delivery-policy.ts +0 -22
- package/extension/runtime/crew-runtime.ts +0 -263
- package/extension/runtime/overflow-recovery.ts +0 -211
- package/extension/runtime/owner-session-coordinator.ts +0 -138
- package/extension/runtime/subagent-lifecycle.ts +0 -203
- package/extension/runtime/subagent-registry.ts +0 -122
- package/extension/runtime/subagent-transitions.ts +0 -100
- package/extension/status-widget.ts +0 -107
- package/extension/subagent-messages.ts +0 -116
- package/extension/tool-registry.ts +0 -19
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { SubagentStatus } from "../subagent-messages.js";
|
|
2
|
-
import type { SubagentState } from "./subagent-registry.js";
|
|
3
|
-
|
|
4
|
-
export type SettledSubagentStatus = Extract<
|
|
5
|
-
SubagentStatus,
|
|
6
|
-
"done" | "waiting" | "error" | "aborted"
|
|
7
|
-
>;
|
|
8
|
-
|
|
9
|
-
export interface SubagentTransitionOutcome {
|
|
10
|
-
result?: string;
|
|
11
|
-
error?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type SubagentTransitionResult =
|
|
15
|
-
| { ok: true; state: SubagentState }
|
|
16
|
-
| { ok: false; error: string };
|
|
17
|
-
|
|
18
|
-
export function isAborted(state: SubagentState): boolean {
|
|
19
|
-
return state.status === "aborted";
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function isAbortableStatus(status: SubagentStatus): boolean {
|
|
23
|
-
return status === "running" || status === "waiting";
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function canAbortSubagent(
|
|
27
|
-
state: SubagentState | undefined,
|
|
28
|
-
): state is SubagentState {
|
|
29
|
-
return Boolean(state && isAbortableStatus(state.status));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function validateOwnedSubagent(
|
|
33
|
-
state: SubagentState | undefined,
|
|
34
|
-
id: string,
|
|
35
|
-
callerSessionId: string,
|
|
36
|
-
missingMessage: string,
|
|
37
|
-
): SubagentTransitionResult {
|
|
38
|
-
if (!state) return { ok: false, error: missingMessage };
|
|
39
|
-
if (state.ownerSessionId !== callerSessionId) {
|
|
40
|
-
return { ok: false, error: `Subagent "${id}" belongs to a different session` };
|
|
41
|
-
}
|
|
42
|
-
return { ok: true, state };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function startSubagentResponse(
|
|
46
|
-
state: SubagentState | undefined,
|
|
47
|
-
id: string,
|
|
48
|
-
callerSessionId: string,
|
|
49
|
-
): SubagentTransitionResult {
|
|
50
|
-
const owned = validateOwnedSubagent(
|
|
51
|
-
state,
|
|
52
|
-
id,
|
|
53
|
-
callerSessionId,
|
|
54
|
-
`No subagent with id "${id}"`,
|
|
55
|
-
);
|
|
56
|
-
if (!owned.ok) return owned;
|
|
57
|
-
|
|
58
|
-
if (owned.state.status !== "waiting") {
|
|
59
|
-
return {
|
|
60
|
-
ok: false,
|
|
61
|
-
error: `Subagent "${id}" is not waiting for a response (status: ${owned.state.status})`,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (!owned.state.session) {
|
|
65
|
-
return { ok: false, error: `Subagent "${id}" has no active session` };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
owned.state.status = "running";
|
|
69
|
-
return owned;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function validateSubagentDone(
|
|
73
|
-
state: SubagentState | undefined,
|
|
74
|
-
id: string,
|
|
75
|
-
callerSessionId: string,
|
|
76
|
-
): SubagentTransitionResult {
|
|
77
|
-
const owned = validateOwnedSubagent(
|
|
78
|
-
state,
|
|
79
|
-
id,
|
|
80
|
-
callerSessionId,
|
|
81
|
-
`No active subagent with id "${id}"`,
|
|
82
|
-
);
|
|
83
|
-
if (!owned.ok) return owned;
|
|
84
|
-
|
|
85
|
-
if (owned.state.status !== "waiting") {
|
|
86
|
-
return { ok: false, error: `Subagent "${id}" is not in waiting state` };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return owned;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function settleSubagent(
|
|
93
|
-
state: SubagentState,
|
|
94
|
-
status: SettledSubagentStatus,
|
|
95
|
-
outcome: SubagentTransitionOutcome,
|
|
96
|
-
): void {
|
|
97
|
-
state.status = status;
|
|
98
|
-
state.result = outcome.result;
|
|
99
|
-
state.error = outcome.error;
|
|
100
|
-
}
|
|
@@ -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,116 +0,0 @@
|
|
|
1
|
-
import { sendWithDeliveryPolicy, type SendMessageFn } from "./message-delivery-policy.js";
|
|
2
|
-
|
|
3
|
-
export type { SendMessageFn } from "./message-delivery-policy.js";
|
|
4
|
-
export type SubagentStatus = "running" | "waiting" | "done" | "error" | "aborted";
|
|
5
|
-
|
|
6
|
-
export const STATUS_ICON: Record<SubagentStatus, string> = {
|
|
7
|
-
running: "⏳",
|
|
8
|
-
waiting: "⏳",
|
|
9
|
-
done: "✅",
|
|
10
|
-
error: "❌",
|
|
11
|
-
aborted: "⏹️",
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const STATUS_LABEL: Record<SubagentStatus, string> = {
|
|
15
|
-
running: "running",
|
|
16
|
-
waiting: "waiting for response",
|
|
17
|
-
done: "done",
|
|
18
|
-
error: "failed",
|
|
19
|
-
aborted: "aborted",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export interface SteeringPayload {
|
|
23
|
-
id: string;
|
|
24
|
-
agentName: string;
|
|
25
|
-
sessionFile?: string;
|
|
26
|
-
status: SubagentStatus;
|
|
27
|
-
result?: string;
|
|
28
|
-
error?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface CrewResultMessageDetails {
|
|
32
|
-
agentId: string;
|
|
33
|
-
agentName: string;
|
|
34
|
-
sessionFile?: string;
|
|
35
|
-
status: SubagentStatus;
|
|
36
|
-
body?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function getCrewResultTitle(details: {
|
|
40
|
-
agentId: string;
|
|
41
|
-
agentName: string;
|
|
42
|
-
status: SubagentStatus;
|
|
43
|
-
}): string {
|
|
44
|
-
return `Subagent '${details.agentName}' (${details.agentId}) ${STATUS_LABEL[details.status]}`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getSteeringBody(payload: SteeringPayload): string | undefined {
|
|
48
|
-
return (payload.status === "error" || payload.status === "aborted")
|
|
49
|
-
? (payload.error ?? payload.result)
|
|
50
|
-
: (payload.result ?? payload.error);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function sendSteeringMessage(
|
|
54
|
-
payload: SteeringPayload,
|
|
55
|
-
sendMessage: SendMessageFn,
|
|
56
|
-
opts: { isIdle: boolean; triggerTurn: boolean },
|
|
57
|
-
): void {
|
|
58
|
-
const body = getSteeringBody(payload);
|
|
59
|
-
const title = getCrewResultTitle({
|
|
60
|
-
agentId: payload.id,
|
|
61
|
-
agentName: payload.agentName,
|
|
62
|
-
status: payload.status,
|
|
63
|
-
});
|
|
64
|
-
const content = body
|
|
65
|
-
? `**${STATUS_ICON[payload.status]} ${title}**\n\n${body}`
|
|
66
|
-
: `**${STATUS_ICON[payload.status]} ${title}**`;
|
|
67
|
-
|
|
68
|
-
const message = {
|
|
69
|
-
customType: "crew-result",
|
|
70
|
-
content,
|
|
71
|
-
display: true,
|
|
72
|
-
details: {
|
|
73
|
-
agentId: payload.id,
|
|
74
|
-
agentName: payload.agentName,
|
|
75
|
-
sessionFile: payload.sessionFile,
|
|
76
|
-
status: payload.status,
|
|
77
|
-
body,
|
|
78
|
-
} satisfies CrewResultMessageDetails,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
sendWithDeliveryPolicy(message, sendMessage, opts);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function sendRemainingNote(
|
|
85
|
-
remainingCount: number,
|
|
86
|
-
sendMessage: SendMessageFn,
|
|
87
|
-
opts: { isIdle: boolean; triggerTurn: boolean },
|
|
88
|
-
): void {
|
|
89
|
-
if (remainingCount <= 0) return;
|
|
90
|
-
|
|
91
|
-
sendWithDeliveryPolicy(
|
|
92
|
-
{
|
|
93
|
-
customType: "crew-remaining",
|
|
94
|
-
content: `⏳ ${remainingCount} subagent(s) still running`,
|
|
95
|
-
display: true,
|
|
96
|
-
},
|
|
97
|
-
sendMessage,
|
|
98
|
-
opts,
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function sendCrewListActiveWarning(
|
|
103
|
-
sendMessage: SendMessageFn,
|
|
104
|
-
opts: { isIdle: boolean; triggerTurn: boolean },
|
|
105
|
-
): void {
|
|
106
|
-
sendWithDeliveryPolicy(
|
|
107
|
-
{
|
|
108
|
-
customType: "crew-list-warning",
|
|
109
|
-
content:
|
|
110
|
-
"⚠ 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.",
|
|
111
|
-
display: true,
|
|
112
|
-
},
|
|
113
|
-
sendMessage,
|
|
114
|
-
opts,
|
|
115
|
-
);
|
|
116
|
-
}
|
|
@@ -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
|
-
}
|