@leing2021/super-pi 0.21.0 → 0.22.0
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 +29 -16
- package/extensions/subagent/agent-management.ts +595 -0
- package/extensions/subagent/agent-manager-chain-detail.ts +162 -0
- package/extensions/subagent/agent-manager-detail.ts +231 -0
- package/extensions/subagent/agent-manager-edit.ts +390 -0
- package/extensions/subagent/agent-manager-list.ts +278 -0
- package/extensions/subagent/agent-manager-parallel.ts +304 -0
- package/extensions/subagent/agent-manager.ts +705 -0
- package/extensions/subagent/agent-scope.ts +8 -0
- package/extensions/subagent/agent-selection.ts +25 -0
- package/extensions/subagent/agent-serializer.ts +123 -0
- package/extensions/subagent/agent-templates.ts +62 -0
- package/extensions/subagent/agents/context-builder.md +37 -0
- package/extensions/subagent/agents/delegate.md +9 -0
- package/extensions/subagent/agents/oracle.md +73 -0
- package/extensions/subagent/agents/planner.md +52 -0
- package/extensions/subagent/agents/researcher.md +50 -0
- package/extensions/subagent/agents/reviewer.md +38 -0
- package/extensions/subagent/agents/scout.md +48 -0
- package/extensions/subagent/agents/worker.md +52 -0
- package/extensions/subagent/agents.ts +761 -0
- package/extensions/subagent/artifacts.ts +100 -0
- package/extensions/subagent/async-execution.ts +520 -0
- package/extensions/subagent/async-job-tracker.ts +216 -0
- package/extensions/subagent/async-status.ts +241 -0
- package/extensions/subagent/chain-clarify.ts +1364 -0
- package/extensions/subagent/chain-execution.ts +853 -0
- package/extensions/subagent/chain-serializer.ts +126 -0
- package/extensions/subagent/completion-dedupe.ts +65 -0
- package/extensions/subagent/doctor.ts +200 -0
- package/extensions/subagent/execution.ts +738 -0
- package/extensions/subagent/file-coalescer.ts +42 -0
- package/extensions/subagent/fork-context.ts +63 -0
- package/extensions/subagent/formatters.ts +122 -0
- package/extensions/subagent/frontmatter.ts +31 -0
- package/extensions/subagent/index.ts +585 -0
- package/extensions/subagent/intercom-bridge.ts +240 -0
- package/extensions/subagent/jsonl-writer.ts +83 -0
- package/extensions/subagent/model-fallback.ts +108 -0
- package/extensions/subagent/notify.ts +110 -0
- package/extensions/subagent/parallel-utils.ts +108 -0
- package/extensions/subagent/pi-args.ts +138 -0
- package/extensions/subagent/pi-spawn.ts +100 -0
- package/extensions/subagent/post-exit-stdio-guard.ts +87 -0
- package/extensions/subagent/prompt-template-bridge.ts +399 -0
- package/extensions/subagent/prompts/gather-context-and-clarify.md +13 -0
- package/extensions/subagent/prompts/parallel-cleanup.md +42 -0
- package/extensions/subagent/prompts/parallel-research.md +50 -0
- package/extensions/subagent/prompts/parallel-review.md +40 -0
- package/extensions/subagent/render-helpers.ts +82 -0
- package/extensions/subagent/render.ts +836 -0
- package/extensions/subagent/result-intercom.ts +237 -0
- package/extensions/subagent/result-watcher.ts +171 -0
- package/extensions/subagent/run-history.ts +57 -0
- package/extensions/subagent/run-status.ts +136 -0
- package/extensions/subagent/schemas.ts +164 -0
- package/extensions/subagent/session-tokens.ts +50 -0
- package/extensions/subagent/settings.ts +367 -0
- package/extensions/subagent/single-output.ts +97 -0
- package/extensions/subagent/skills.ts +626 -0
- package/extensions/subagent/slash-bridge.ts +176 -0
- package/extensions/subagent/slash-commands.ts +303 -0
- package/extensions/subagent/slash-live-state.ts +294 -0
- package/extensions/subagent/subagent-control.ts +150 -0
- package/extensions/subagent/subagent-executor.ts +1899 -0
- package/extensions/subagent/subagent-prompt-runtime.ts +75 -0
- package/extensions/subagent/subagent-runner.ts +1470 -0
- package/extensions/subagent/subagents-status.ts +472 -0
- package/extensions/subagent/text-editor.ts +272 -0
- package/extensions/subagent/top-level-async.ts +15 -0
- package/extensions/subagent/types.ts +623 -0
- package/extensions/subagent/utils.ts +456 -0
- package/extensions/subagent/worktree.ts +579 -0
- package/extensions/super-pi-extension/index.ts +2 -55
- package/package.json +12 -6
- package/skills/pi-subagents/SKILL.md +566 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Based on pi-subagents by Nico Bailon (https://github.com/nicobailon/pi-subagents)
|
|
2
|
+
// MIT License
|
|
3
|
+
interface TimerApi {
|
|
4
|
+
setTimeout(handler: () => void, delayMs: number): unknown;
|
|
5
|
+
clearTimeout(handle: unknown): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface FileCoalescer {
|
|
9
|
+
schedule(file: string, delayMs?: number): boolean;
|
|
10
|
+
clear(): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const defaultTimerApi: TimerApi = {
|
|
14
|
+
setTimeout: (handler, delayMs) => setTimeout(handler, delayMs),
|
|
15
|
+
clearTimeout: (handle) => clearTimeout(handle as ReturnType<typeof setTimeout>),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function createFileCoalescer(
|
|
19
|
+
handler: (file: string) => void,
|
|
20
|
+
defaultDelayMs: number,
|
|
21
|
+
timerApi: TimerApi = defaultTimerApi,
|
|
22
|
+
): FileCoalescer {
|
|
23
|
+
const pending = new Map<string, unknown>();
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
schedule(file: string, delayMs = defaultDelayMs): boolean {
|
|
27
|
+
if (pending.has(file)) return false;
|
|
28
|
+
const timer = timerApi.setTimeout(() => {
|
|
29
|
+
pending.delete(file);
|
|
30
|
+
handler(file);
|
|
31
|
+
}, delayMs);
|
|
32
|
+
pending.set(file, timer);
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
clear(): void {
|
|
36
|
+
for (const timer of pending.values()) {
|
|
37
|
+
timerApi.clearTimeout(timer);
|
|
38
|
+
}
|
|
39
|
+
pending.clear();
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Based on pi-subagents by Nico Bailon (https://github.com/nicobailon/pi-subagents)
|
|
2
|
+
// MIT License
|
|
3
|
+
export type SubagentExecutionContext = "fresh" | "fork";
|
|
4
|
+
|
|
5
|
+
interface ForkableSessionManagerStatic {
|
|
6
|
+
open(path: string): { createBranchedSession(leafId: string): string | undefined };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ForkableSessionManager {
|
|
10
|
+
getSessionFile(): string | undefined;
|
|
11
|
+
getLeafId(): string | null;
|
|
12
|
+
constructor: ForkableSessionManagerStatic;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ForkContextResolver {
|
|
16
|
+
sessionFileForIndex(index?: number): string | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function resolveSubagentContext(value: unknown): SubagentExecutionContext {
|
|
20
|
+
return value === "fork" ? "fork" : "fresh";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createForkContextResolver(
|
|
24
|
+
sessionManager: ForkableSessionManager,
|
|
25
|
+
requestedContext: unknown,
|
|
26
|
+
): ForkContextResolver {
|
|
27
|
+
if (resolveSubagentContext(requestedContext) !== "fork") {
|
|
28
|
+
return {
|
|
29
|
+
sessionFileForIndex: () => undefined,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const parentSessionFile = sessionManager.getSessionFile();
|
|
34
|
+
if (!parentSessionFile) {
|
|
35
|
+
throw new Error("Forked subagent context requires a persisted parent session.");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const leafId = sessionManager.getLeafId();
|
|
39
|
+
if (!leafId) {
|
|
40
|
+
throw new Error("Forked subagent context requires a current leaf to fork from.");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const cachedSessionFiles = new Map<number, string>();
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
sessionFileForIndex(index = 0): string | undefined {
|
|
47
|
+
const cached = cachedSessionFiles.get(index);
|
|
48
|
+
if (cached) return cached;
|
|
49
|
+
try {
|
|
50
|
+
const sourceManager = sessionManager.constructor.open(parentSessionFile);
|
|
51
|
+
const sessionFile = sourceManager.createBranchedSession(leafId);
|
|
52
|
+
if (!sessionFile) {
|
|
53
|
+
throw new Error("Session manager did not return a session file.");
|
|
54
|
+
}
|
|
55
|
+
cachedSessionFiles.set(index, sessionFile);
|
|
56
|
+
return sessionFile;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
59
|
+
throw new Error(`Failed to create forked subagent session: ${cause.message}`, { cause });
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Based on pi-subagents by Nico Bailon (https://github.com/nicobailon/pi-subagents)
|
|
2
|
+
// MIT License
|
|
3
|
+
/**
|
|
4
|
+
* Formatting utilities for display output
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from "node:fs";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import type { Usage, SingleResult } from "./types.ts";
|
|
10
|
+
import type { ChainStep } from "./settings.ts";
|
|
11
|
+
import { isParallelStep } from "./settings.ts";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Format token count with k suffix for large numbers
|
|
15
|
+
*/
|
|
16
|
+
export function formatTokens(n: number): string {
|
|
17
|
+
return n < 1000 ? String(n) : n < 10000 ? `${(n / 1000).toFixed(1)}k` : `${Math.round(n / 1000)}k`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Format usage statistics into a compact string
|
|
22
|
+
*/
|
|
23
|
+
export function formatUsage(u: Usage, model?: string): string {
|
|
24
|
+
const parts: string[] = [];
|
|
25
|
+
if (u.turns) parts.push(`${u.turns} turn${u.turns > 1 ? "s" : ""}`);
|
|
26
|
+
if (u.input) parts.push(`in:${formatTokens(u.input)}`);
|
|
27
|
+
if (u.output) parts.push(`out:${formatTokens(u.output)}`);
|
|
28
|
+
if (u.cacheRead) parts.push(`R${formatTokens(u.cacheRead)}`);
|
|
29
|
+
if (u.cacheWrite) parts.push(`W${formatTokens(u.cacheWrite)}`);
|
|
30
|
+
if (u.cost) parts.push(`$${u.cost.toFixed(4)}`);
|
|
31
|
+
if (model) parts.push(model);
|
|
32
|
+
return parts.join(" ");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Format duration in human-readable form
|
|
37
|
+
*/
|
|
38
|
+
export function formatDuration(ms: number): string {
|
|
39
|
+
if (ms < 1000) return `${ms}ms`;
|
|
40
|
+
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`;
|
|
41
|
+
return `${Math.floor(ms / 60000)}m${Math.floor((ms % 60000) / 1000)}s`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Build a summary string for a completed/failed chain
|
|
46
|
+
*/
|
|
47
|
+
export function buildChainSummary(
|
|
48
|
+
steps: ChainStep[],
|
|
49
|
+
results: SingleResult[],
|
|
50
|
+
chainDir: string,
|
|
51
|
+
status: "completed" | "failed",
|
|
52
|
+
failedStep?: { index: number; error: string },
|
|
53
|
+
): string {
|
|
54
|
+
const stepNames = steps
|
|
55
|
+
.map((step) => (isParallelStep(step) ? `parallel[${step.parallel.length}]` : step.agent))
|
|
56
|
+
.join(" → ");
|
|
57
|
+
|
|
58
|
+
const totalDuration = results.reduce((sum, r) => sum + (r.progress?.durationMs || 0), 0);
|
|
59
|
+
const durationStr = formatDuration(totalDuration);
|
|
60
|
+
|
|
61
|
+
const progressPath = path.join(chainDir, "progress.md");
|
|
62
|
+
const hasProgress = fs.existsSync(progressPath);
|
|
63
|
+
const allSkills = new Set<string>();
|
|
64
|
+
for (const r of results) {
|
|
65
|
+
if (r.skills) r.skills.forEach((s) => allSkills.add(s));
|
|
66
|
+
}
|
|
67
|
+
const skillsLine = allSkills.size > 0 ? `🔧 Skills: ${[...allSkills].join(", ")}` : "";
|
|
68
|
+
|
|
69
|
+
if (status === "completed") {
|
|
70
|
+
const stepWord = results.length === 1 ? "step" : "steps";
|
|
71
|
+
return `✅ Chain completed: ${stepNames} (${results.length} ${stepWord}, ${durationStr})${skillsLine ? `\n${skillsLine}` : ""}
|
|
72
|
+
|
|
73
|
+
📋 Progress: ${hasProgress ? progressPath : "(none)"}
|
|
74
|
+
📁 Artifacts: ${chainDir}`;
|
|
75
|
+
} else {
|
|
76
|
+
const stepInfo = failedStep ? ` at step ${failedStep.index + 1}` : "";
|
|
77
|
+
const errorInfo = failedStep?.error ? `: ${failedStep.error}` : "";
|
|
78
|
+
return `❌ Chain failed${stepInfo}${errorInfo}${skillsLine ? `\n${skillsLine}` : ""}
|
|
79
|
+
|
|
80
|
+
📋 Progress: ${hasProgress ? progressPath : "(none)"}
|
|
81
|
+
📁 Artifacts: ${chainDir}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Format a tool call for display
|
|
87
|
+
*/
|
|
88
|
+
export function formatToolCall(name: string, args: Record<string, unknown>, expanded = false): string {
|
|
89
|
+
switch (name) {
|
|
90
|
+
case "bash": {
|
|
91
|
+
const command = typeof args.command === "string" ? args.command : "";
|
|
92
|
+
const maxLength = expanded ? 240 : 60;
|
|
93
|
+
return `$ ${command.slice(0, maxLength)}${command.length > maxLength ? "..." : ""}`;
|
|
94
|
+
}
|
|
95
|
+
case "read":
|
|
96
|
+
case "write":
|
|
97
|
+
case "edit": {
|
|
98
|
+
const target = typeof args.path === "string"
|
|
99
|
+
? args.path
|
|
100
|
+
: typeof args.file_path === "string"
|
|
101
|
+
? args.file_path
|
|
102
|
+
: "";
|
|
103
|
+
return `${name} ${shortenPath(target)}`;
|
|
104
|
+
}
|
|
105
|
+
default: {
|
|
106
|
+
const s = JSON.stringify(args);
|
|
107
|
+
const maxLength = expanded ? 160 : 40;
|
|
108
|
+
return `${name} ${s.slice(0, maxLength)}${s.length > maxLength ? "..." : ""}`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Shorten a path by replacing home directory with ~
|
|
115
|
+
*/
|
|
116
|
+
export function shortenPath(p: string): string {
|
|
117
|
+
const home = process.env.HOME;
|
|
118
|
+
if (home && p.startsWith(home)) {
|
|
119
|
+
return `~${p.slice(home.length)}`;
|
|
120
|
+
}
|
|
121
|
+
return p;
|
|
122
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Based on pi-subagents by Nico Bailon (https://github.com/nicobailon/pi-subagents)
|
|
2
|
+
// MIT License
|
|
3
|
+
export function parseFrontmatter(content: string): { frontmatter: Record<string, string>; body: string } {
|
|
4
|
+
const frontmatter: Record<string, string> = {};
|
|
5
|
+
const normalized = content.replace(/\r\n/g, "\n");
|
|
6
|
+
|
|
7
|
+
if (!normalized.startsWith("---")) {
|
|
8
|
+
return { frontmatter, body: normalized };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const endIndex = normalized.indexOf("\n---", 3);
|
|
12
|
+
if (endIndex === -1) {
|
|
13
|
+
return { frontmatter, body: normalized };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const frontmatterBlock = normalized.slice(4, endIndex);
|
|
17
|
+
const body = normalized.slice(endIndex + 4).trim();
|
|
18
|
+
|
|
19
|
+
for (const line of frontmatterBlock.split("\n")) {
|
|
20
|
+
const match = line.match(/^([\w-]+):\s*(.*)$/);
|
|
21
|
+
if (match) {
|
|
22
|
+
let value = match[2].trim();
|
|
23
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
24
|
+
value = value.slice(1, -1);
|
|
25
|
+
}
|
|
26
|
+
frontmatter[match[1]] = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { frontmatter, body };
|
|
31
|
+
}
|