@esso0428/pi-subagents 0.15.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/CHANGELOG.md +638 -0
- package/CONTRIBUTING.md +68 -0
- package/LICENSE +21 -0
- package/README.md +745 -0
- package/SECURITY.md +95 -0
- package/dist/agent-manager.d.ts +144 -0
- package/dist/agent-manager.js +542 -0
- package/dist/agent-runner.d.ts +212 -0
- package/dist/agent-runner.js +850 -0
- package/dist/agent-types.d.ts +67 -0
- package/dist/agent-types.js +168 -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 +17 -0
- package/dist/custom-agents.js +156 -0
- package/dist/default-agents.d.ts +7 -0
- package/dist/default-agents.js +122 -0
- package/dist/enabled-models.d.ts +49 -0
- package/dist/enabled-models.js +145 -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 +16 -0
- package/dist/index.js +2209 -0
- package/dist/invocation-config.d.ts +22 -0
- package/dist/invocation-config.js +15 -0
- package/dist/memory.d.ts +53 -0
- package/dist/memory.js +165 -0
- package/dist/model-resolver.d.ts +19 -0
- package/dist/model-resolver.js +80 -0
- package/dist/nico-overrides.d.ts +53 -0
- package/dist/nico-overrides.js +169 -0
- package/dist/output-file.d.ts +24 -0
- package/dist/output-file.js +101 -0
- package/dist/prompts.d.ts +32 -0
- package/dist/prompts.js +73 -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 +141 -0
- package/dist/settings.js +162 -0
- package/dist/skill-loader.d.ts +24 -0
- package/dist/skill-loader.js +93 -0
- package/dist/status-note.d.ts +13 -0
- package/dist/status-note.js +24 -0
- package/dist/types.d.ts +197 -0
- package/dist/types.js +5 -0
- package/dist/ui/agent-widget.d.ts +160 -0
- package/dist/ui/agent-widget.js +484 -0
- package/dist/ui/conversation-viewer.d.ts +57 -0
- package/dist/ui/conversation-viewer.js +354 -0
- package/dist/ui/fleet-list.d.ts +106 -0
- package/dist/ui/fleet-list.js +345 -0
- package/dist/ui/schedule-menu.d.ts +16 -0
- package/dist/ui/schedule-menu.js +95 -0
- package/dist/ui/viewer-keys.d.ts +20 -0
- package/dist/ui/viewer-keys.js +17 -0
- package/dist/usage.d.ts +50 -0
- package/dist/usage.js +49 -0
- package/dist/worktree.d.ts +45 -0
- package/dist/worktree.js +160 -0
- package/examples/agent-tool-description.md +42 -0
- package/package.json +56 -0
- package/src/agent-manager.ts +631 -0
- package/src/agent-runner.ts +1014 -0
- package/src/agent-types.ts +202 -0
- package/src/context.ts +58 -0
- package/src/cross-extension-rpc.ts +122 -0
- package/src/custom-agents.ts +167 -0
- package/src/default-agents.ts +126 -0
- package/src/enabled-models.ts +180 -0
- package/src/env.ts +33 -0
- package/src/group-join.ts +141 -0
- package/src/index.ts +2400 -0
- package/src/invocation-config.ts +40 -0
- package/src/memory.ts +179 -0
- package/src/model-resolver.ts +100 -0
- package/src/nico-overrides.ts +235 -0
- package/src/output-file.ts +110 -0
- package/src/prompts.ts +99 -0
- package/src/schedule-store.ts +153 -0
- package/src/schedule.ts +365 -0
- package/src/settings.ts +288 -0
- package/src/skill-loader.ts +102 -0
- package/src/status-note.ts +25 -0
- package/src/types.ts +208 -0
- package/src/ui/agent-widget.ts +566 -0
- package/src/ui/conversation-viewer.ts +362 -0
- package/src/ui/fleet-list.ts +380 -0
- package/src/ui/schedule-menu.ts +104 -0
- package/src/ui/viewer-keys.ts +39 -0
- package/src/usage.ts +60 -0
- package/src/worktree.ts +191 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* default-agents.ts — Embedded default agent configurations.
|
|
3
|
+
*
|
|
4
|
+
* These are always available but can be overridden by user .md files with the same name.
|
|
5
|
+
*/
|
|
6
|
+
const READ_ONLY_TOOLS = ["read", "bash", "grep", "find", "ls"];
|
|
7
|
+
export const DEFAULT_AGENTS = new Map([
|
|
8
|
+
[
|
|
9
|
+
"general-purpose",
|
|
10
|
+
{
|
|
11
|
+
name: "general-purpose",
|
|
12
|
+
displayName: "Agent",
|
|
13
|
+
description: "General-purpose agent for researching complex questions, searching for code, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries use this agent to perform the search for you.",
|
|
14
|
+
// builtinToolNames omitted — means "all available tools" (resolved at lookup time)
|
|
15
|
+
// inheritContext / runInBackground / isolated omitted — strategy fields, callers decide per-call.
|
|
16
|
+
// Setting them to false would lock callsite intent (see resolveAgentInvocationConfig in invocation-config.ts).
|
|
17
|
+
extensions: true,
|
|
18
|
+
skills: true,
|
|
19
|
+
systemPrompt: "",
|
|
20
|
+
promptMode: "append",
|
|
21
|
+
isDefault: true,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
"Explore",
|
|
26
|
+
{
|
|
27
|
+
name: "Explore",
|
|
28
|
+
displayName: "Explore",
|
|
29
|
+
description: "Fast read-only search agent for locating code. Use it to find files by pattern (eg. \"src/components/**/*.tsx\"), grep for symbols or keywords (eg. \"API endpoints\"), or answer \"where is X defined / which files reference Y.\" Do NOT use it for code review, design-doc auditing, cross-file consistency checks, or open-ended analysis — it reads excerpts rather than whole files and will miss content past its read window. When calling, specify search breadth: \"quick\" for a single targeted lookup, \"medium\" for moderate exploration, or \"very thorough\" to search across multiple locations and naming conventions.",
|
|
30
|
+
builtinToolNames: READ_ONLY_TOOLS,
|
|
31
|
+
extensions: true,
|
|
32
|
+
skills: true,
|
|
33
|
+
// Fast/cheap model for read-only search. Provider-preferred but resilient:
|
|
34
|
+
// resolveModel matches this fuzzily (date-stamp optional) and falls back to
|
|
35
|
+
// the same model under another provider if anthropic doesn't expose it.
|
|
36
|
+
model: "anthropic/claude-haiku-4-5",
|
|
37
|
+
systemPrompt: `# CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS
|
|
38
|
+
You are a file search specialist. You excel at thoroughly navigating and exploring codebases.
|
|
39
|
+
Your role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools.
|
|
40
|
+
|
|
41
|
+
You are STRICTLY PROHIBITED from:
|
|
42
|
+
- Creating new files
|
|
43
|
+
- Modifying existing files
|
|
44
|
+
- Deleting files
|
|
45
|
+
- Moving or copying files
|
|
46
|
+
- Creating temporary files anywhere, including /tmp
|
|
47
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
48
|
+
- Running ANY commands that change system state
|
|
49
|
+
|
|
50
|
+
Use Bash ONLY for read-only operations: ls, git status, git log, git diff, find, cat, head, tail.
|
|
51
|
+
|
|
52
|
+
# Tool Usage
|
|
53
|
+
- Use the find tool for file pattern matching (NOT the bash find command)
|
|
54
|
+
- Use the grep tool for content search (NOT bash grep/rg command)
|
|
55
|
+
- Use the read tool for reading files (NOT bash cat/head/tail)
|
|
56
|
+
- Use Bash ONLY for read-only operations
|
|
57
|
+
- Make independent tool calls in parallel for efficiency
|
|
58
|
+
- Adapt search approach based on thoroughness level specified
|
|
59
|
+
|
|
60
|
+
# Output
|
|
61
|
+
- Use absolute file paths in all references
|
|
62
|
+
- Report findings as regular messages
|
|
63
|
+
- Do not use emojis
|
|
64
|
+
- Be thorough and precise`,
|
|
65
|
+
promptMode: "replace",
|
|
66
|
+
isDefault: true,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
"Plan",
|
|
71
|
+
{
|
|
72
|
+
name: "Plan",
|
|
73
|
+
displayName: "Plan",
|
|
74
|
+
description: "Software architect agent for designing implementation plans. Use this when you need to plan the implementation strategy for a task. Returns step-by-step plans, identifies critical files, and considers architectural trade-offs.",
|
|
75
|
+
builtinToolNames: READ_ONLY_TOOLS,
|
|
76
|
+
extensions: true,
|
|
77
|
+
skills: true,
|
|
78
|
+
systemPrompt: `# CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS
|
|
79
|
+
You are a software architect and planning specialist.
|
|
80
|
+
Your role is EXCLUSIVELY to explore the codebase and design implementation plans.
|
|
81
|
+
You do NOT have access to file editing tools — attempting to edit files will fail.
|
|
82
|
+
|
|
83
|
+
You are STRICTLY PROHIBITED from:
|
|
84
|
+
- Creating new files
|
|
85
|
+
- Modifying existing files
|
|
86
|
+
- Deleting files
|
|
87
|
+
- Moving or copying files
|
|
88
|
+
- Creating temporary files anywhere, including /tmp
|
|
89
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
90
|
+
- Running ANY commands that change system state
|
|
91
|
+
|
|
92
|
+
# Planning Process
|
|
93
|
+
1. Understand requirements
|
|
94
|
+
2. Explore thoroughly (read files, find patterns, understand architecture)
|
|
95
|
+
3. Design solution based on your assigned perspective
|
|
96
|
+
4. Detail the plan with step-by-step implementation strategy
|
|
97
|
+
|
|
98
|
+
# Requirements
|
|
99
|
+
- Consider trade-offs and architectural decisions
|
|
100
|
+
- Identify dependencies and sequencing
|
|
101
|
+
- Anticipate potential challenges
|
|
102
|
+
- Follow existing patterns where appropriate
|
|
103
|
+
|
|
104
|
+
# Tool Usage
|
|
105
|
+
- Use the find tool for file pattern matching (NOT the bash find command)
|
|
106
|
+
- Use the grep tool for content search (NOT bash grep/rg command)
|
|
107
|
+
- Use the read tool for reading files (NOT bash cat/head/tail)
|
|
108
|
+
- Use Bash ONLY for read-only operations
|
|
109
|
+
|
|
110
|
+
# Output Format
|
|
111
|
+
- Use absolute file paths
|
|
112
|
+
- Do not use emojis
|
|
113
|
+
- End your response with:
|
|
114
|
+
|
|
115
|
+
### Critical Files for Implementation
|
|
116
|
+
List 3-5 files most critical for implementing this plan:
|
|
117
|
+
- /absolute/path/to/file.ts - [Brief reason]`,
|
|
118
|
+
promptMode: "replace",
|
|
119
|
+
isDefault: true,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
]);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads `enabledModels` from pi's settings (global `<agentDir>/settings.json`
|
|
3
|
+
* + project-local `<cwd>/.pi/settings.json`, project wins) and resolves
|
|
4
|
+
* entries to concrete `provider/modelId` keys for scope validation.
|
|
5
|
+
*
|
|
6
|
+
* **Project overrides global**, mirroring pi's own `SettingsManager`
|
|
7
|
+
* deep-merge behavior and matching the precedence we use for our own
|
|
8
|
+
* `subagents.json` settings (see `src/settings.ts:loadSettings`). If
|
|
9
|
+
* project file has `enabledModels` set, it wholly replaces global's
|
|
10
|
+
* (array fields are replaced, not concatenated).
|
|
11
|
+
*
|
|
12
|
+
* **Limited subset of upstream's resolveModelScope.** We support exact
|
|
13
|
+
* `provider/modelId` matching only. Upstream (pi-coding-agent's
|
|
14
|
+
* `core/model-resolver.ts`) additionally supports glob patterns
|
|
15
|
+
* (`*sonnet*`, `anthropic/*`), bare model IDs without provider, and
|
|
16
|
+
* thinking-level suffixes (`provider/*:high`). Those forms are silently
|
|
17
|
+
* ignored here.
|
|
18
|
+
*
|
|
19
|
+
* In practice, pi's `/scoped-models` picker writes exact `provider/modelId`
|
|
20
|
+
* entries, so the limitation is invisible for users who configure scope
|
|
21
|
+
* through pi's UI. Hand-edited settings using globs or bare IDs will
|
|
22
|
+
* produce an empty allowed set (scope check becomes a no-op).
|
|
23
|
+
*
|
|
24
|
+
* Example:
|
|
25
|
+
* enabledModels = ["anthropic/claude-sonnet-4-6", "anthropic/claude-opus-4-6"]
|
|
26
|
+
* → resolves to { "anthropic/claude-sonnet-4-6", "anthropic/claude-opus-4-6" }
|
|
27
|
+
*/
|
|
28
|
+
/** Minimal registry shape — only the methods resolveEnabledModels actually calls. */
|
|
29
|
+
export interface ModelRegistryRef {
|
|
30
|
+
getAll(): unknown[];
|
|
31
|
+
getAvailable?(): unknown[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read enabledModels from pi's settings — project-local overrides global.
|
|
35
|
+
* Mirrors pi's SettingsManager deep-merge for the `enabledModels` field
|
|
36
|
+
* (and matches our own loadSettings precedence in src/settings.ts).
|
|
37
|
+
* Returns undefined when neither file has the field.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readEnabledModels(cwd: string): string[] | undefined;
|
|
40
|
+
export declare function resolveEnabledModels(patterns: string[] | undefined, registry: ModelRegistryRef, cwd?: string): Set<string> | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* True when `model` is in the allowed set. Centralizes the key format
|
|
43
|
+
* (`provider/id` lowercase) so callers don't have to reproduce it —
|
|
44
|
+
* both set-building (resolveExact) and lookup go through `modelKey`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isModelInScope(model: {
|
|
47
|
+
provider: string;
|
|
48
|
+
id: string;
|
|
49
|
+
}, allowed: Set<string>): boolean;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads `enabledModels` from pi's settings (global `<agentDir>/settings.json`
|
|
3
|
+
* + project-local `<cwd>/.pi/settings.json`, project wins) and resolves
|
|
4
|
+
* entries to concrete `provider/modelId` keys for scope validation.
|
|
5
|
+
*
|
|
6
|
+
* **Project overrides global**, mirroring pi's own `SettingsManager`
|
|
7
|
+
* deep-merge behavior and matching the precedence we use for our own
|
|
8
|
+
* `subagents.json` settings (see `src/settings.ts:loadSettings`). If
|
|
9
|
+
* project file has `enabledModels` set, it wholly replaces global's
|
|
10
|
+
* (array fields are replaced, not concatenated).
|
|
11
|
+
*
|
|
12
|
+
* **Limited subset of upstream's resolveModelScope.** We support exact
|
|
13
|
+
* `provider/modelId` matching only. Upstream (pi-coding-agent's
|
|
14
|
+
* `core/model-resolver.ts`) additionally supports glob patterns
|
|
15
|
+
* (`*sonnet*`, `anthropic/*`), bare model IDs without provider, and
|
|
16
|
+
* thinking-level suffixes (`provider/*:high`). Those forms are silently
|
|
17
|
+
* ignored here.
|
|
18
|
+
*
|
|
19
|
+
* In practice, pi's `/scoped-models` picker writes exact `provider/modelId`
|
|
20
|
+
* entries, so the limitation is invisible for users who configure scope
|
|
21
|
+
* through pi's UI. Hand-edited settings using globs or bare IDs will
|
|
22
|
+
* produce an empty allowed set (scope check becomes a no-op).
|
|
23
|
+
*
|
|
24
|
+
* Example:
|
|
25
|
+
* enabledModels = ["anthropic/claude-sonnet-4-6", "anthropic/claude-opus-4-6"]
|
|
26
|
+
* → resolves to { "anthropic/claude-sonnet-4-6", "anthropic/claude-opus-4-6" }
|
|
27
|
+
*/
|
|
28
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
31
|
+
/** Paths to pi's settings.json files: [project, global] (project takes precedence). */
|
|
32
|
+
function settingsPaths(cwd) {
|
|
33
|
+
return [
|
|
34
|
+
join(cwd, ".pi", "settings.json"),
|
|
35
|
+
join(getAgentDir(), "settings.json"),
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
/** Read `enabledModels` from a single settings.json file. Undefined when missing or absent. */
|
|
39
|
+
function readField(path) {
|
|
40
|
+
if (!existsSync(path))
|
|
41
|
+
return undefined;
|
|
42
|
+
try {
|
|
43
|
+
const raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
44
|
+
if (Array.isArray(raw?.enabledModels))
|
|
45
|
+
return raw.enabledModels;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
/* corrupt file — silent */
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Read enabledModels from pi's settings — project-local overrides global.
|
|
54
|
+
* Mirrors pi's SettingsManager deep-merge for the `enabledModels` field
|
|
55
|
+
* (and matches our own loadSettings precedence in src/settings.ts).
|
|
56
|
+
* Returns undefined when neither file has the field.
|
|
57
|
+
*/
|
|
58
|
+
export function readEnabledModels(cwd) {
|
|
59
|
+
const [project, global] = settingsPaths(cwd);
|
|
60
|
+
return readField(project) ?? readField(global);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolve enabledModels patterns → Set<"provider/modelId"> (lowercase keys).
|
|
64
|
+
*
|
|
65
|
+
* Only exact `provider/modelId` patterns are matched (case-insensitive).
|
|
66
|
+
* Patterns without a slash, with glob characters, or with a `:thinking`
|
|
67
|
+
* suffix are silently dropped. See module-level docstring for rationale.
|
|
68
|
+
*
|
|
69
|
+
* Cache: keyed on JSON.stringify(patterns) + mtime/size of *both*
|
|
70
|
+
* project and global settings.json files. Re-resolves when either file
|
|
71
|
+
* changes or the patterns argument differs.
|
|
72
|
+
*
|
|
73
|
+
* Returns undefined when no patterns are provided or no patterns match
|
|
74
|
+
* (scope check becomes a no-op at the call site).
|
|
75
|
+
*/
|
|
76
|
+
// Module-level cache — invalidated when either settings.json changes or patterns differ.
|
|
77
|
+
let cachedAllowed;
|
|
78
|
+
let cachedHash = "";
|
|
79
|
+
let cachedPatternsKey = "";
|
|
80
|
+
/** mtime+size hash of one file, or "missing" if absent. */
|
|
81
|
+
function hashOf(path) {
|
|
82
|
+
try {
|
|
83
|
+
const s = statSync(path);
|
|
84
|
+
return `${s.mtimeMs}-${s.size}`;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return "missing";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function resolveEnabledModels(patterns, registry, cwd = process.cwd()) {
|
|
91
|
+
// Fast path: check cache (stat both project and global settings.json files)
|
|
92
|
+
const patternsKey = JSON.stringify(patterns);
|
|
93
|
+
const [project, global] = settingsPaths(cwd);
|
|
94
|
+
const fileHash = `${hashOf(project)};${hashOf(global)}`;
|
|
95
|
+
if (fileHash === cachedHash && patternsKey === cachedPatternsKey) {
|
|
96
|
+
return cachedAllowed;
|
|
97
|
+
}
|
|
98
|
+
// Cache miss — resolve
|
|
99
|
+
if (!patterns || patterns.length === 0) {
|
|
100
|
+
cachedHash = fileHash;
|
|
101
|
+
cachedPatternsKey = patternsKey;
|
|
102
|
+
cachedAllowed = undefined;
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const available = (registry.getAvailable?.() ?? registry.getAll());
|
|
106
|
+
const allowed = new Set();
|
|
107
|
+
for (const pattern of patterns) {
|
|
108
|
+
const trimmed = pattern.trim();
|
|
109
|
+
if (!trimmed)
|
|
110
|
+
continue; // skip empty/whitespace
|
|
111
|
+
resolveExact(trimmed, available, allowed);
|
|
112
|
+
}
|
|
113
|
+
const result = allowed.size > 0 ? allowed : undefined;
|
|
114
|
+
cachedHash = fileHash;
|
|
115
|
+
cachedPatternsKey = patternsKey;
|
|
116
|
+
cachedAllowed = result;
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* True when `model` is in the allowed set. Centralizes the key format
|
|
121
|
+
* (`provider/id` lowercase) so callers don't have to reproduce it —
|
|
122
|
+
* both set-building (resolveExact) and lookup go through `modelKey`.
|
|
123
|
+
*/
|
|
124
|
+
export function isModelInScope(model, allowed) {
|
|
125
|
+
return allowed.has(modelKey(model));
|
|
126
|
+
}
|
|
127
|
+
/** Canonical lowercase `provider/id` key for the allowed set. */
|
|
128
|
+
function modelKey(model) {
|
|
129
|
+
return `${model.provider}/${model.id}`.toLowerCase();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Resolve exact model pattern. Example: "google/gemma-4-31b-it".
|
|
133
|
+
*/
|
|
134
|
+
function resolveExact(pattern, available, allowed) {
|
|
135
|
+
// "provider/modelId" — exact (colon is part of id, not split)
|
|
136
|
+
const slashIdx = pattern.indexOf("/");
|
|
137
|
+
if (slashIdx === -1)
|
|
138
|
+
return; // bare modelId not supported
|
|
139
|
+
const provider = pattern.slice(0, slashIdx).toLowerCase();
|
|
140
|
+
const modelId = pattern.slice(slashIdx + 1).toLowerCase();
|
|
141
|
+
const exact = available.find(m => m.provider.toLowerCase() === provider && m.id.toLowerCase() === modelId);
|
|
142
|
+
if (exact) {
|
|
143
|
+
allowed.add(modelKey(exact));
|
|
144
|
+
}
|
|
145
|
+
}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* env.ts — Detect environment info (git, platform) for subagent system prompts.
|
|
3
|
+
*/
|
|
4
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import type { EnvInfo } from "./types.js";
|
|
6
|
+
export declare function detectEnv(pi: ExtensionAPI, cwd: string): Promise<EnvInfo>;
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* env.ts — Detect environment info (git, platform) for subagent system prompts.
|
|
3
|
+
*/
|
|
4
|
+
export async function detectEnv(pi, cwd) {
|
|
5
|
+
let isGitRepo = false;
|
|
6
|
+
let branch = "";
|
|
7
|
+
try {
|
|
8
|
+
const result = await pi.exec("git", ["rev-parse", "--is-inside-work-tree"], { cwd, timeout: 5000 });
|
|
9
|
+
isGitRepo = result.code === 0 && result.stdout.trim() === "true";
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// Not a git repo or git not installed
|
|
13
|
+
}
|
|
14
|
+
if (isGitRepo) {
|
|
15
|
+
try {
|
|
16
|
+
const result = await pi.exec("git", ["branch", "--show-current"], { cwd, timeout: 5000 });
|
|
17
|
+
branch = result.code === 0 ? result.stdout.trim() : "unknown";
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
branch = "unknown";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
isGitRepo,
|
|
25
|
+
branch,
|
|
26
|
+
platform: process.platform,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* group-join.ts — Manages grouped background agent completion notifications.
|
|
3
|
+
*
|
|
4
|
+
* Instead of each agent individually nudging the main agent on completion,
|
|
5
|
+
* agents in a group are held until all complete (or a timeout fires),
|
|
6
|
+
* then a single consolidated notification is sent.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentRecord } from "./types.js";
|
|
9
|
+
export type DeliveryCallback = (records: AgentRecord[], partial: boolean) => void;
|
|
10
|
+
export declare class GroupJoinManager {
|
|
11
|
+
private deliverCb;
|
|
12
|
+
private groupTimeout;
|
|
13
|
+
private groups;
|
|
14
|
+
private agentToGroup;
|
|
15
|
+
constructor(deliverCb: DeliveryCallback, groupTimeout?: number);
|
|
16
|
+
/** Register a group of agent IDs that should be joined. */
|
|
17
|
+
registerGroup(groupId: string, agentIds: string[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* Called when an agent completes.
|
|
20
|
+
* Returns:
|
|
21
|
+
* - 'pass' — agent is not grouped, caller should send individual nudge
|
|
22
|
+
* - 'held' — result held, waiting for group completion
|
|
23
|
+
* - 'delivered' — this completion triggered the group notification
|
|
24
|
+
*/
|
|
25
|
+
onAgentComplete(record: AgentRecord): 'delivered' | 'held' | 'pass';
|
|
26
|
+
private onTimeout;
|
|
27
|
+
private deliver;
|
|
28
|
+
private cleanupGroup;
|
|
29
|
+
/** Check if an agent is in a group. */
|
|
30
|
+
isGrouped(agentId: string): boolean;
|
|
31
|
+
dispose(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* group-join.ts — Manages grouped background agent completion notifications.
|
|
3
|
+
*
|
|
4
|
+
* Instead of each agent individually nudging the main agent on completion,
|
|
5
|
+
* agents in a group are held until all complete (or a timeout fires),
|
|
6
|
+
* then a single consolidated notification is sent.
|
|
7
|
+
*/
|
|
8
|
+
/** Default timeout: 30s after first completion in a group. */
|
|
9
|
+
const DEFAULT_TIMEOUT = 30_000;
|
|
10
|
+
/** Straggler re-batch timeout: 15s. */
|
|
11
|
+
const STRAGGLER_TIMEOUT = 15_000;
|
|
12
|
+
export class GroupJoinManager {
|
|
13
|
+
deliverCb;
|
|
14
|
+
groupTimeout;
|
|
15
|
+
groups = new Map();
|
|
16
|
+
agentToGroup = new Map();
|
|
17
|
+
constructor(deliverCb, groupTimeout = DEFAULT_TIMEOUT) {
|
|
18
|
+
this.deliverCb = deliverCb;
|
|
19
|
+
this.groupTimeout = groupTimeout;
|
|
20
|
+
}
|
|
21
|
+
/** Register a group of agent IDs that should be joined. */
|
|
22
|
+
registerGroup(groupId, agentIds) {
|
|
23
|
+
const group = {
|
|
24
|
+
groupId,
|
|
25
|
+
agentIds: new Set(agentIds),
|
|
26
|
+
completedRecords: new Map(),
|
|
27
|
+
delivered: false,
|
|
28
|
+
isStraggler: false,
|
|
29
|
+
};
|
|
30
|
+
this.groups.set(groupId, group);
|
|
31
|
+
for (const id of agentIds) {
|
|
32
|
+
this.agentToGroup.set(id, groupId);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Called when an agent completes.
|
|
37
|
+
* Returns:
|
|
38
|
+
* - 'pass' — agent is not grouped, caller should send individual nudge
|
|
39
|
+
* - 'held' — result held, waiting for group completion
|
|
40
|
+
* - 'delivered' — this completion triggered the group notification
|
|
41
|
+
*/
|
|
42
|
+
onAgentComplete(record) {
|
|
43
|
+
const groupId = this.agentToGroup.get(record.id);
|
|
44
|
+
if (!groupId)
|
|
45
|
+
return 'pass';
|
|
46
|
+
const group = this.groups.get(groupId);
|
|
47
|
+
if (!group || group.delivered)
|
|
48
|
+
return 'pass';
|
|
49
|
+
group.completedRecords.set(record.id, record);
|
|
50
|
+
// All done — deliver immediately
|
|
51
|
+
if (group.completedRecords.size >= group.agentIds.size) {
|
|
52
|
+
this.deliver(group, false);
|
|
53
|
+
return 'delivered';
|
|
54
|
+
}
|
|
55
|
+
// First completion in this batch — start timeout
|
|
56
|
+
if (!group.timeoutHandle) {
|
|
57
|
+
const timeout = group.isStraggler ? STRAGGLER_TIMEOUT : this.groupTimeout;
|
|
58
|
+
group.timeoutHandle = setTimeout(() => {
|
|
59
|
+
this.onTimeout(group);
|
|
60
|
+
}, timeout);
|
|
61
|
+
}
|
|
62
|
+
return 'held';
|
|
63
|
+
}
|
|
64
|
+
onTimeout(group) {
|
|
65
|
+
if (group.delivered)
|
|
66
|
+
return;
|
|
67
|
+
group.timeoutHandle = undefined;
|
|
68
|
+
// Partial delivery — some agents still running
|
|
69
|
+
const remaining = new Set();
|
|
70
|
+
for (const id of group.agentIds) {
|
|
71
|
+
if (!group.completedRecords.has(id))
|
|
72
|
+
remaining.add(id);
|
|
73
|
+
}
|
|
74
|
+
// Clean up agentToGroup for delivered agents (they won't complete again)
|
|
75
|
+
for (const id of group.completedRecords.keys()) {
|
|
76
|
+
this.agentToGroup.delete(id);
|
|
77
|
+
}
|
|
78
|
+
// Deliver what we have
|
|
79
|
+
this.deliverCb([...group.completedRecords.values()], true);
|
|
80
|
+
// Set up straggler group for remaining agents
|
|
81
|
+
group.completedRecords.clear();
|
|
82
|
+
group.agentIds = remaining;
|
|
83
|
+
group.isStraggler = true;
|
|
84
|
+
// Timeout will be started when the next straggler completes
|
|
85
|
+
}
|
|
86
|
+
deliver(group, partial) {
|
|
87
|
+
if (group.timeoutHandle) {
|
|
88
|
+
clearTimeout(group.timeoutHandle);
|
|
89
|
+
group.timeoutHandle = undefined;
|
|
90
|
+
}
|
|
91
|
+
group.delivered = true;
|
|
92
|
+
this.deliverCb([...group.completedRecords.values()], partial);
|
|
93
|
+
this.cleanupGroup(group.groupId);
|
|
94
|
+
}
|
|
95
|
+
cleanupGroup(groupId) {
|
|
96
|
+
const group = this.groups.get(groupId);
|
|
97
|
+
if (!group)
|
|
98
|
+
return;
|
|
99
|
+
for (const id of group.agentIds) {
|
|
100
|
+
this.agentToGroup.delete(id);
|
|
101
|
+
}
|
|
102
|
+
this.groups.delete(groupId);
|
|
103
|
+
}
|
|
104
|
+
/** Check if an agent is in a group. */
|
|
105
|
+
isGrouped(agentId) {
|
|
106
|
+
return this.agentToGroup.has(agentId);
|
|
107
|
+
}
|
|
108
|
+
dispose() {
|
|
109
|
+
for (const group of this.groups.values()) {
|
|
110
|
+
if (group.timeoutHandle)
|
|
111
|
+
clearTimeout(group.timeoutHandle);
|
|
112
|
+
}
|
|
113
|
+
this.groups.clear();
|
|
114
|
+
this.agentToGroup.clear();
|
|
115
|
+
}
|
|
116
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-agents — A pi extension providing Claude Code-style autonomous sub-agents.
|
|
3
|
+
*
|
|
4
|
+
* Tools:
|
|
5
|
+
* Agent — LLM-callable: spawn a sub-agent
|
|
6
|
+
* get_subagent_result — LLM-callable: check background agent status/result
|
|
7
|
+
* steer_subagent — LLM-callable: send a steering message to a running agent
|
|
8
|
+
*
|
|
9
|
+
* Commands:
|
|
10
|
+
* /agents — Interactive agent management menu
|
|
11
|
+
*/
|
|
12
|
+
import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import { Container } from "@earendil-works/pi-tui";
|
|
14
|
+
import { type Theme } from "./ui/agent-widget.js";
|
|
15
|
+
export declare function renderRunningAgentStatus(frame: string, statsText: string, activity: string, theme: Pick<Theme, "fg">): Container;
|
|
16
|
+
export default function (pi: ExtensionAPI): void;
|