@by-lua/lspec-subagents 1.0.1
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 +482 -0
- package/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/agent-manager.d.ts +108 -0
- package/dist/agent-manager.js +391 -0
- package/dist/agent-runner.d.ts +95 -0
- package/dist/agent-runner.js +377 -0
- package/dist/agent-types.d.ts +58 -0
- package/dist/agent-types.js +157 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.js +56 -0
- package/dist/cross-extension-rpc.d.ts +46 -0
- package/dist/cross-extension-rpc.js +76 -0
- package/dist/custom-agents.d.ts +14 -0
- package/dist/custom-agents.js +127 -0
- package/dist/default-agents.d.ts +12 -0
- package/dist/default-agents.js +489 -0
- package/dist/env.d.ts +6 -0
- package/dist/env.js +28 -0
- package/dist/group-join.d.ts +32 -0
- package/dist/group-join.js +116 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1863 -0
- package/dist/invocation-config.d.ts +22 -0
- package/dist/invocation-config.js +15 -0
- package/dist/memory.d.ts +49 -0
- package/dist/memory.js +151 -0
- package/dist/model-config-loader.d.ts +58 -0
- package/dist/model-config-loader.js +157 -0
- package/dist/model-resolver.d.ts +19 -0
- package/dist/model-resolver.js +62 -0
- package/dist/output-file.d.ts +24 -0
- package/dist/output-file.js +86 -0
- package/dist/prompts.d.ts +29 -0
- package/dist/prompts.js +65 -0
- package/dist/schedule-store.d.ts +38 -0
- package/dist/schedule-store.js +155 -0
- package/dist/schedule.d.ts +109 -0
- package/dist/schedule.js +338 -0
- package/dist/settings.d.ts +66 -0
- package/dist/settings.js +130 -0
- package/dist/skill-loader.d.ts +24 -0
- package/dist/skill-loader.js +93 -0
- package/dist/types.d.ts +164 -0
- package/dist/types.js +8 -0
- package/dist/ui/agent-widget.d.ts +134 -0
- package/dist/ui/agent-widget.js +451 -0
- package/dist/ui/conversation-viewer.d.ts +35 -0
- package/dist/ui/conversation-viewer.js +252 -0
- package/dist/ui/schedule-menu.d.ts +16 -0
- package/dist/ui/schedule-menu.js +95 -0
- package/dist/usage.d.ts +50 -0
- package/dist/usage.js +49 -0
- package/dist/worktree.d.ts +36 -0
- package/dist/worktree.js +139 -0
- package/install.sh +77 -0
- package/lspec-model-config.example.json +17 -0
- package/package.json +50 -0
- package/src/agent-manager.ts +483 -0
- package/src/agent-runner.ts +486 -0
- package/src/agent-types.ts +188 -0
- package/src/context.ts +58 -0
- package/src/cross-extension-rpc.ts +122 -0
- package/src/custom-agents.ts +136 -0
- package/src/default-agents.ts +501 -0
- package/src/env.ts +33 -0
- package/src/group-join.ts +141 -0
- package/src/index.ts +2032 -0
- package/src/invocation-config.ts +40 -0
- package/src/memory.ts +165 -0
- package/src/model-config-loader.ts +193 -0
- package/src/model-resolver.ts +81 -0
- package/src/output-file.ts +96 -0
- package/src/prompts.ts +91 -0
- package/src/schedule-store.ts +153 -0
- package/src/schedule.ts +365 -0
- package/src/settings.ts +186 -0
- package/src/skill-loader.ts +102 -0
- package/src/types.ts +179 -0
- package/src/ui/agent-widget.ts +533 -0
- package/src/ui/conversation-viewer.ts +261 -0
- package/src/ui/schedule-menu.ts +104 -0
- package/src/usage.ts +60 -0
- package/src/worktree.ts +162 -0
- package/uninstall.sh +55 -0
- package/update.sh +64 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* context.ts — Extract parent conversation context for subagent inheritance.
|
|
3
|
+
*/
|
|
4
|
+
import type { ExtensionContext } from "@mariozechner/pi-coding-agent";
|
|
5
|
+
/** Extract text from a message content block array. */
|
|
6
|
+
export declare function extractText(content: unknown[]): string;
|
|
7
|
+
/**
|
|
8
|
+
* Build a text representation of the parent conversation context.
|
|
9
|
+
* Used when inherit_context is true to give the subagent visibility
|
|
10
|
+
* into what has been discussed/done so far.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildParentContext(ctx: ExtensionContext): string;
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* context.ts — Extract parent conversation context for subagent inheritance.
|
|
3
|
+
*/
|
|
4
|
+
/** Extract text from a message content block array. */
|
|
5
|
+
export function extractText(content) {
|
|
6
|
+
return content
|
|
7
|
+
.filter((c) => c.type === "text")
|
|
8
|
+
.map((c) => c.text ?? "")
|
|
9
|
+
.join("\n");
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Build a text representation of the parent conversation context.
|
|
13
|
+
* Used when inherit_context is true to give the subagent visibility
|
|
14
|
+
* into what has been discussed/done so far.
|
|
15
|
+
*/
|
|
16
|
+
export function buildParentContext(ctx) {
|
|
17
|
+
const entries = ctx.sessionManager.getBranch();
|
|
18
|
+
if (!entries || entries.length === 0)
|
|
19
|
+
return "";
|
|
20
|
+
const parts = [];
|
|
21
|
+
for (const entry of entries) {
|
|
22
|
+
if (entry.type === "message") {
|
|
23
|
+
const msg = entry.message;
|
|
24
|
+
if (msg.role === "user") {
|
|
25
|
+
const text = typeof msg.content === "string"
|
|
26
|
+
? msg.content
|
|
27
|
+
: extractText(msg.content);
|
|
28
|
+
if (text.trim())
|
|
29
|
+
parts.push(`[User]: ${text.trim()}`);
|
|
30
|
+
}
|
|
31
|
+
else if (msg.role === "assistant") {
|
|
32
|
+
const text = extractText(msg.content);
|
|
33
|
+
if (text.trim())
|
|
34
|
+
parts.push(`[Assistant]: ${text.trim()}`);
|
|
35
|
+
}
|
|
36
|
+
// Skip toolResult messages — too verbose for context
|
|
37
|
+
}
|
|
38
|
+
else if (entry.type === "compaction") {
|
|
39
|
+
// Include compaction summaries — they're already condensed
|
|
40
|
+
if (entry.summary) {
|
|
41
|
+
parts.push(`[Summary]: ${entry.summary}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (parts.length === 0)
|
|
46
|
+
return "";
|
|
47
|
+
return `# Parent Conversation Context
|
|
48
|
+
The following is the conversation history from the parent session that spawned you.
|
|
49
|
+
Use this context to understand what has been discussed and decided so far.
|
|
50
|
+
|
|
51
|
+
${parts.join("\n\n")}
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
# Your Task (below)
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-extension RPC handlers for the subagents extension.
|
|
3
|
+
*
|
|
4
|
+
* Exposes ping, spawn, and stop RPCs over the pi.events event bus,
|
|
5
|
+
* using per-request scoped reply channels.
|
|
6
|
+
*
|
|
7
|
+
* Reply envelope follows pi-mono convention:
|
|
8
|
+
* success → { success: true, data?: T }
|
|
9
|
+
* error → { success: false, error: string }
|
|
10
|
+
*/
|
|
11
|
+
/** Minimal event bus interface needed by the RPC handlers. */
|
|
12
|
+
export interface EventBus {
|
|
13
|
+
on(event: string, handler: (data: unknown) => void): () => void;
|
|
14
|
+
emit(event: string, data: unknown): void;
|
|
15
|
+
}
|
|
16
|
+
/** RPC reply envelope — matches pi-mono's RpcResponse shape. */
|
|
17
|
+
export type RpcReply<T = void> = {
|
|
18
|
+
success: true;
|
|
19
|
+
data?: T;
|
|
20
|
+
} | {
|
|
21
|
+
success: false;
|
|
22
|
+
error: string;
|
|
23
|
+
};
|
|
24
|
+
/** RPC protocol version — bumped when the envelope or method contracts change. */
|
|
25
|
+
export declare const PROTOCOL_VERSION = 2;
|
|
26
|
+
/** Minimal AgentManager interface needed by the spawn/stop RPCs. */
|
|
27
|
+
export interface SpawnCapable {
|
|
28
|
+
spawn(pi: unknown, ctx: unknown, type: string, prompt: string, options: any): string;
|
|
29
|
+
abort(id: string): boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface RpcDeps {
|
|
32
|
+
events: EventBus;
|
|
33
|
+
pi: unknown;
|
|
34
|
+
getCtx: () => unknown | undefined;
|
|
35
|
+
manager: SpawnCapable;
|
|
36
|
+
}
|
|
37
|
+
export interface RpcHandle {
|
|
38
|
+
unsubPing: () => void;
|
|
39
|
+
unsubSpawn: () => void;
|
|
40
|
+
unsubStop: () => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Register ping, spawn, and stop RPC handlers on the event bus.
|
|
44
|
+
* Returns unsub functions for cleanup.
|
|
45
|
+
*/
|
|
46
|
+
export declare function registerRpcHandlers(deps: RpcDeps): RpcHandle;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-extension RPC handlers for the subagents extension.
|
|
3
|
+
*
|
|
4
|
+
* Exposes ping, spawn, and stop RPCs over the pi.events event bus,
|
|
5
|
+
* using per-request scoped reply channels.
|
|
6
|
+
*
|
|
7
|
+
* Reply envelope follows pi-mono convention:
|
|
8
|
+
* success → { success: true, data?: T }
|
|
9
|
+
* error → { success: false, error: string }
|
|
10
|
+
*/
|
|
11
|
+
import { resolveModel } from "./model-resolver.js";
|
|
12
|
+
/** RPC protocol version — bumped when the envelope or method contracts change. */
|
|
13
|
+
export const PROTOCOL_VERSION = 2;
|
|
14
|
+
/**
|
|
15
|
+
* Wire a single RPC handler: listen on `channel`, run `fn(params)`,
|
|
16
|
+
* emit the reply envelope on `channel:reply:${requestId}`.
|
|
17
|
+
*/
|
|
18
|
+
function handleRpc(events, channel, fn) {
|
|
19
|
+
return events.on(channel, async (raw) => {
|
|
20
|
+
const params = raw;
|
|
21
|
+
try {
|
|
22
|
+
const data = await fn(params);
|
|
23
|
+
const reply = { success: true };
|
|
24
|
+
if (data !== undefined)
|
|
25
|
+
reply.data = data;
|
|
26
|
+
events.emit(`${channel}:reply:${params.requestId}`, reply);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
events.emit(`${channel}:reply:${params.requestId}`, {
|
|
30
|
+
success: false, error: err?.message ?? String(err),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Register ping, spawn, and stop RPC handlers on the event bus.
|
|
37
|
+
* Returns unsub functions for cleanup.
|
|
38
|
+
*/
|
|
39
|
+
export function registerRpcHandlers(deps) {
|
|
40
|
+
const { events, pi, getCtx, manager } = deps;
|
|
41
|
+
const unsubPing = handleRpc(events, "subagents:rpc:ping", () => {
|
|
42
|
+
return { version: PROTOCOL_VERSION };
|
|
43
|
+
});
|
|
44
|
+
const unsubSpawn = handleRpc(events, "subagents:rpc:spawn", ({ type, prompt, options }) => {
|
|
45
|
+
const ctx = getCtx();
|
|
46
|
+
if (!ctx)
|
|
47
|
+
throw new Error("No active session");
|
|
48
|
+
// Cross-extension RPC callers (e.g. pi-tasks TaskExecute) naturally
|
|
49
|
+
// forward serializable values, so options.model can be a string like
|
|
50
|
+
// "openai-codex/gpt-5.5". Resolve it to a real Model instance here
|
|
51
|
+
// — same pattern the scheduler path already uses — so the spawned
|
|
52
|
+
// agent's auth lookup doesn't crash with "No API key found for
|
|
53
|
+
// undefined".
|
|
54
|
+
let normalizedOptions = options ?? {};
|
|
55
|
+
if (typeof normalizedOptions.model === "string") {
|
|
56
|
+
const registry = ctx.modelRegistry;
|
|
57
|
+
if (!registry) {
|
|
58
|
+
throw new Error(`Model override "${normalizedOptions.model}" provided but ctx.modelRegistry is unavailable`);
|
|
59
|
+
}
|
|
60
|
+
const resolved = resolveModel(normalizedOptions.model, registry);
|
|
61
|
+
if (typeof resolved === "string") {
|
|
62
|
+
// resolveModel returns a human-readable error string when the
|
|
63
|
+
// input doesn't match any available model. Surface it instead of
|
|
64
|
+
// silently falling back so the caller sees the auth/typo issue.
|
|
65
|
+
throw new Error(resolved);
|
|
66
|
+
}
|
|
67
|
+
normalizedOptions = { ...normalizedOptions, model: resolved };
|
|
68
|
+
}
|
|
69
|
+
return { id: manager.spawn(pi, ctx, type, prompt, normalizedOptions) };
|
|
70
|
+
});
|
|
71
|
+
const unsubStop = handleRpc(events, "subagents:rpc:stop", ({ agentId }) => {
|
|
72
|
+
if (!manager.abort(agentId))
|
|
73
|
+
throw new Error("Agent not found");
|
|
74
|
+
});
|
|
75
|
+
return { unsubPing, unsubSpawn, unsubStop };
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* custom-agents.ts — Load user-defined agents from project (.pi/agents/) and global ($PI_CODING_AGENT_DIR/agents/, default ~/.pi/agent/agents/) locations.
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentConfig } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Scan for custom agent .md files from multiple locations.
|
|
7
|
+
* Discovery hierarchy (higher priority wins):
|
|
8
|
+
* 1. Project: <cwd>/.pi/agents/*.md
|
|
9
|
+
* 2. Global: $PI_CODING_AGENT_DIR/agents/*.md (default: ~/.pi/agent/agents/*.md)
|
|
10
|
+
*
|
|
11
|
+
* Project-level agents override global ones with the same name.
|
|
12
|
+
* Any name is allowed — names matching defaults (e.g. "Explore") override them.
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadCustomAgents(cwd: string): Map<string, AgentConfig>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* custom-agents.ts — Load user-defined agents from project (.pi/agents/) and global ($PI_CODING_AGENT_DIR/agents/, default ~/.pi/agent/agents/) locations.
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
5
|
+
import { basename, join } from "node:path";
|
|
6
|
+
import { getAgentDir, parseFrontmatter } from "@mariozechner/pi-coding-agent";
|
|
7
|
+
import { BUILTIN_TOOL_NAMES } from "./agent-types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Scan for custom agent .md files from multiple locations.
|
|
10
|
+
* Discovery hierarchy (higher priority wins):
|
|
11
|
+
* 1. Project: <cwd>/.pi/agents/*.md
|
|
12
|
+
* 2. Global: $PI_CODING_AGENT_DIR/agents/*.md (default: ~/.pi/agent/agents/*.md)
|
|
13
|
+
*
|
|
14
|
+
* Project-level agents override global ones with the same name.
|
|
15
|
+
* Any name is allowed — names matching defaults (e.g. "Explore") override them.
|
|
16
|
+
*/
|
|
17
|
+
export function loadCustomAgents(cwd) {
|
|
18
|
+
const globalDir = join(getAgentDir(), "agents");
|
|
19
|
+
const projectDir = join(cwd, ".pi", "agents");
|
|
20
|
+
const agents = new Map();
|
|
21
|
+
loadFromDir(globalDir, agents, "global"); // lower priority
|
|
22
|
+
loadFromDir(projectDir, agents, "project"); // higher priority (overwrites)
|
|
23
|
+
return agents;
|
|
24
|
+
}
|
|
25
|
+
/** Load agent configs from a directory into the map. */
|
|
26
|
+
function loadFromDir(dir, agents, source) {
|
|
27
|
+
if (!existsSync(dir))
|
|
28
|
+
return;
|
|
29
|
+
let files;
|
|
30
|
+
try {
|
|
31
|
+
files = readdirSync(dir).filter(f => f.endsWith(".md"));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
for (const file of files) {
|
|
37
|
+
const name = basename(file, ".md");
|
|
38
|
+
let content;
|
|
39
|
+
try {
|
|
40
|
+
content = readFileSync(join(dir, file), "utf-8");
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const { frontmatter: fm, body } = parseFrontmatter(content);
|
|
46
|
+
agents.set(name, {
|
|
47
|
+
name,
|
|
48
|
+
displayName: str(fm.display_name),
|
|
49
|
+
description: str(fm.description) ?? name,
|
|
50
|
+
builtinToolNames: csvList(fm.tools, BUILTIN_TOOL_NAMES),
|
|
51
|
+
disallowedTools: csvListOptional(fm.disallowed_tools),
|
|
52
|
+
extensions: inheritField(fm.extensions ?? fm.inherit_extensions),
|
|
53
|
+
skills: inheritField(fm.skills ?? fm.inherit_skills),
|
|
54
|
+
model: str(fm.model),
|
|
55
|
+
thinking: str(fm.thinking),
|
|
56
|
+
maxTurns: nonNegativeInt(fm.max_turns),
|
|
57
|
+
systemPrompt: body.trim(),
|
|
58
|
+
promptMode: fm.prompt_mode === "append" ? "append" : "replace",
|
|
59
|
+
inheritContext: fm.inherit_context != null ? fm.inherit_context === true : undefined,
|
|
60
|
+
runInBackground: fm.run_in_background != null ? fm.run_in_background === true : undefined,
|
|
61
|
+
isolated: fm.isolated != null ? fm.isolated === true : undefined,
|
|
62
|
+
memory: parseMemory(fm.memory),
|
|
63
|
+
isolation: fm.isolation === "worktree" ? "worktree" : undefined,
|
|
64
|
+
enabled: fm.enabled !== false, // default true; explicitly false disables
|
|
65
|
+
source,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// ---- Field parsers ----
|
|
70
|
+
// All follow the same convention: omitted → default, "none"/empty → nothing, value → exact.
|
|
71
|
+
/** Extract a string or undefined. */
|
|
72
|
+
function str(val) {
|
|
73
|
+
return typeof val === "string" ? val : undefined;
|
|
74
|
+
}
|
|
75
|
+
/** Extract a non-negative integer or undefined. 0 means unlimited for max_turns. */
|
|
76
|
+
function nonNegativeInt(val) {
|
|
77
|
+
return typeof val === "number" && val >= 0 ? val : undefined;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Parse a raw CSV field value into items, or undefined if absent/empty/"none".
|
|
81
|
+
*/
|
|
82
|
+
function parseCsvField(val) {
|
|
83
|
+
if (val === undefined || val === null)
|
|
84
|
+
return undefined;
|
|
85
|
+
const s = String(val).trim();
|
|
86
|
+
if (!s || s === "none")
|
|
87
|
+
return undefined;
|
|
88
|
+
const items = s.split(",").map(t => t.trim()).filter(Boolean);
|
|
89
|
+
return items.length > 0 ? items : undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse a comma-separated list field with defaults.
|
|
93
|
+
* omitted → defaults; "none"/empty → []; csv → listed items.
|
|
94
|
+
*/
|
|
95
|
+
function csvList(val, defaults) {
|
|
96
|
+
if (val === undefined || val === null)
|
|
97
|
+
return defaults;
|
|
98
|
+
return parseCsvField(val) ?? [];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Parse an optional comma-separated list field.
|
|
102
|
+
* omitted → undefined; "none"/empty → undefined; csv → listed items.
|
|
103
|
+
*/
|
|
104
|
+
function csvListOptional(val) {
|
|
105
|
+
return parseCsvField(val);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Parse a memory scope field.
|
|
109
|
+
* omitted → undefined; "user"/"project"/"local" → MemoryScope.
|
|
110
|
+
*/
|
|
111
|
+
function parseMemory(val) {
|
|
112
|
+
if (val === "user" || val === "project" || val === "local")
|
|
113
|
+
return val;
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Parse an inherit field (extensions, skills).
|
|
118
|
+
* omitted/true → true (inherit all); false/"none"/empty → false; csv → listed names.
|
|
119
|
+
*/
|
|
120
|
+
function inheritField(val) {
|
|
121
|
+
if (val === undefined || val === null || val === true)
|
|
122
|
+
return true;
|
|
123
|
+
if (val === false || val === "none")
|
|
124
|
+
return false;
|
|
125
|
+
const items = csvList(val, []);
|
|
126
|
+
return items.length > 0 ? items : false;
|
|
127
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* default-agents.ts — L-Spec 9 embedded agent configurations.
|
|
3
|
+
*
|
|
4
|
+
* Uses model placeholders ({{model:agent_name}}) resolved at startup
|
|
5
|
+
* from lspec-model-config.json (project or global) or embedded defaults.
|
|
6
|
+
*
|
|
7
|
+
* Based on oh-my-opencode-slim agent roster:
|
|
8
|
+
* orchestrator, explorer, librarian, oracle, designer,
|
|
9
|
+
* fixer, observer, council, councillor
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentConfig } from "./types.js";
|
|
12
|
+
export declare const DEFAULT_AGENTS: Map<string, AgentConfig>;
|