@ilya-lesikov/pi-pi 0.1.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/3p/pi-ask-user/index.ts +1835 -0
- package/3p/pi-ask-user/package.json +50 -0
- package/3p/pi-ask-user/single-select-layout.ts +203 -0
- package/3p/pi-lsp/extensions/lsp/client.ts +542 -0
- package/3p/pi-lsp/extensions/lsp/config.ts +135 -0
- package/3p/pi-lsp/extensions/lsp/effects/command.ts +42 -0
- package/3p/pi-lsp/extensions/lsp/effects/filesystem.ts +50 -0
- package/3p/pi-lsp/extensions/lsp/effects/runtime.ts +21 -0
- package/3p/pi-lsp/extensions/lsp/errors.ts +113 -0
- package/3p/pi-lsp/extensions/lsp/formatting.ts +315 -0
- package/3p/pi-lsp/extensions/lsp/index.ts +231 -0
- package/3p/pi-lsp/extensions/lsp/protocol.ts +209 -0
- package/3p/pi-lsp/extensions/lsp/retry.ts +39 -0
- package/3p/pi-lsp/extensions/lsp/tools/programs.ts +293 -0
- package/3p/pi-lsp/extensions/lsp/tools.ts +89 -0
- package/3p/pi-lsp/extensions/lsp/types.ts +243 -0
- package/3p/pi-lsp/package.json +54 -0
- package/3p/pi-plannotator/AGENTS.md +583 -0
- package/3p/pi-plannotator/apps/pi-extension/README.md +228 -0
- package/3p/pi-plannotator/apps/pi-extension/assistant-message.ts +128 -0
- package/3p/pi-plannotator/apps/pi-extension/config.test.ts +166 -0
- package/3p/pi-plannotator/apps/pi-extension/config.ts +318 -0
- package/3p/pi-plannotator/apps/pi-extension/current-pi-session.ts +147 -0
- package/3p/pi-plannotator/apps/pi-extension/index.ts +1279 -0
- package/3p/pi-plannotator/apps/pi-extension/package.json +56 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.test.ts +13 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-browser.ts +616 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator-events.ts +342 -0
- package/3p/pi-plannotator/apps/pi-extension/plannotator.json +12 -0
- package/3p/pi-plannotator/apps/pi-extension/server/agent-jobs.ts +515 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ai-runtime.ts +169 -0
- package/3p/pi-plannotator/apps/pi-extension/server/annotations.ts +85 -0
- package/3p/pi-plannotator/apps/pi-extension/server/external-annotations.ts +189 -0
- package/3p/pi-plannotator/apps/pi-extension/server/handlers.ts +210 -0
- package/3p/pi-plannotator/apps/pi-extension/server/helpers.ts +78 -0
- package/3p/pi-plannotator/apps/pi-extension/server/ide.ts +46 -0
- package/3p/pi-plannotator/apps/pi-extension/server/integrations.ts +195 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.test.ts +158 -0
- package/3p/pi-plannotator/apps/pi-extension/server/network.ts +268 -0
- package/3p/pi-plannotator/apps/pi-extension/server/pr.ts +126 -0
- package/3p/pi-plannotator/apps/pi-extension/server/project.ts +64 -0
- package/3p/pi-plannotator/apps/pi-extension/server/reference.ts +362 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverAnnotate.ts +199 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverPlan.ts +505 -0
- package/3p/pi-plannotator/apps/pi-extension/server/serverReview.ts +1229 -0
- package/3p/pi-plannotator/apps/pi-extension/server/vcs.ts +121 -0
- package/3p/pi-plannotator/apps/pi-extension/server.test.ts +966 -0
- package/3p/pi-plannotator/apps/pi-extension/server.ts +44 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.test.ts +88 -0
- package/3p/pi-plannotator/apps/pi-extension/tool-scope.ts +39 -0
- package/3p/pi-plannotator/apps/pi-extension/tsconfig.json +16 -0
- package/3p/pi-plannotator/apps/pi-extension/vendor.sh +48 -0
- package/3p/pi-plannotator/package.json +53 -0
- package/3p/pi-plannotator/packages/ai/ai.test.ts +1407 -0
- package/3p/pi-plannotator/packages/ai/base-session.ts +94 -0
- package/3p/pi-plannotator/packages/ai/context.ts +250 -0
- package/3p/pi-plannotator/packages/ai/endpoints.ts +326 -0
- package/3p/pi-plannotator/packages/ai/index.ts +105 -0
- package/3p/pi-plannotator/packages/ai/package.json +21 -0
- package/3p/pi-plannotator/packages/ai/provider.ts +103 -0
- package/3p/pi-plannotator/packages/ai/providers/claude-agent-sdk.ts +447 -0
- package/3p/pi-plannotator/packages/ai/providers/codex-sdk.ts +430 -0
- package/3p/pi-plannotator/packages/ai/providers/command-path.ts +115 -0
- package/3p/pi-plannotator/packages/ai/providers/opencode-sdk.ts +546 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-events.ts +110 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk-node.ts +425 -0
- package/3p/pi-plannotator/packages/ai/providers/pi-sdk.ts +469 -0
- package/3p/pi-plannotator/packages/ai/session-manager.ts +195 -0
- package/3p/pi-plannotator/packages/ai/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/ai/types.ts +379 -0
- package/3p/pi-plannotator/packages/server/agent-jobs.ts +538 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.test.ts +135 -0
- package/3p/pi-plannotator/packages/server/agent-review-message.ts +243 -0
- package/3p/pi-plannotator/packages/server/ai-runtime.ts +108 -0
- package/3p/pi-plannotator/packages/server/annotate.ts +401 -0
- package/3p/pi-plannotator/packages/server/browser.test.ts +87 -0
- package/3p/pi-plannotator/packages/server/browser.ts +245 -0
- package/3p/pi-plannotator/packages/server/claude-review.ts +352 -0
- package/3p/pi-plannotator/packages/server/code-nav.ts +73 -0
- package/3p/pi-plannotator/packages/server/codex-review-schema.json +41 -0
- package/3p/pi-plannotator/packages/server/codex-review.ts +330 -0
- package/3p/pi-plannotator/packages/server/config.ts +8 -0
- package/3p/pi-plannotator/packages/server/draft.ts +1 -0
- package/3p/pi-plannotator/packages/server/editor-annotations.ts +76 -0
- package/3p/pi-plannotator/packages/server/external-annotations.test.ts +18 -0
- package/3p/pi-plannotator/packages/server/external-annotations.ts +207 -0
- package/3p/pi-plannotator/packages/server/git.ts +141 -0
- package/3p/pi-plannotator/packages/server/goal-setup.test.ts +55 -0
- package/3p/pi-plannotator/packages/server/goal-setup.ts +248 -0
- package/3p/pi-plannotator/packages/server/ide.ts +43 -0
- package/3p/pi-plannotator/packages/server/image.test.ts +63 -0
- package/3p/pi-plannotator/packages/server/image.ts +66 -0
- package/3p/pi-plannotator/packages/server/index.ts +648 -0
- package/3p/pi-plannotator/packages/server/integrations.test.ts +172 -0
- package/3p/pi-plannotator/packages/server/integrations.ts +214 -0
- package/3p/pi-plannotator/packages/server/jj.test.ts +69 -0
- package/3p/pi-plannotator/packages/server/jj.ts +86 -0
- package/3p/pi-plannotator/packages/server/p4.ts +417 -0
- package/3p/pi-plannotator/packages/server/package.json +40 -0
- package/3p/pi-plannotator/packages/server/path-utils.ts +18 -0
- package/3p/pi-plannotator/packages/server/pr.ts +146 -0
- package/3p/pi-plannotator/packages/server/project.test.ts +115 -0
- package/3p/pi-plannotator/packages/server/project.ts +45 -0
- package/3p/pi-plannotator/packages/server/reference-handlers.ts +404 -0
- package/3p/pi-plannotator/packages/server/remote.test.ts +150 -0
- package/3p/pi-plannotator/packages/server/remote.ts +74 -0
- package/3p/pi-plannotator/packages/server/repo.ts +80 -0
- package/3p/pi-plannotator/packages/server/resolve-file.test.ts +310 -0
- package/3p/pi-plannotator/packages/server/review-workspace.test.ts +1032 -0
- package/3p/pi-plannotator/packages/server/review-workspace.ts +48 -0
- package/3p/pi-plannotator/packages/server/review.ts +1318 -0
- package/3p/pi-plannotator/packages/server/sessions.ts +111 -0
- package/3p/pi-plannotator/packages/server/share-url.ts +53 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.test.ts +43 -0
- package/3p/pi-plannotator/packages/server/shared-handlers.ts +177 -0
- package/3p/pi-plannotator/packages/server/storage.test.ts +176 -0
- package/3p/pi-plannotator/packages/server/storage.ts +17 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.test.ts +146 -0
- package/3p/pi-plannotator/packages/server/tour/tour-review.ts +604 -0
- package/3p/pi-plannotator/packages/server/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/server/vcs.test.ts +48 -0
- package/3p/pi-plannotator/packages/server/vcs.ts +80 -0
- package/3p/pi-plannotator/packages/shared/agent-jobs.ts +132 -0
- package/3p/pi-plannotator/packages/shared/agents.ts +53 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.test.ts +386 -0
- package/3p/pi-plannotator/packages/shared/annotate-args.ts +107 -0
- package/3p/pi-plannotator/packages/shared/at-reference.test.ts +99 -0
- package/3p/pi-plannotator/packages/shared/at-reference.ts +52 -0
- package/3p/pi-plannotator/packages/shared/checklist.ts +52 -0
- package/3p/pi-plannotator/packages/shared/code-file.test.ts +112 -0
- package/3p/pi-plannotator/packages/shared/code-file.ts +41 -0
- package/3p/pi-plannotator/packages/shared/code-nav.test.ts +515 -0
- package/3p/pi-plannotator/packages/shared/code-nav.ts +436 -0
- package/3p/pi-plannotator/packages/shared/compress.ts +51 -0
- package/3p/pi-plannotator/packages/shared/config.ts +262 -0
- package/3p/pi-plannotator/packages/shared/crypto.test.ts +172 -0
- package/3p/pi-plannotator/packages/shared/crypto.ts +97 -0
- package/3p/pi-plannotator/packages/shared/data-dir.ts +42 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.test.ts +30 -0
- package/3p/pi-plannotator/packages/shared/diff-paths.ts +137 -0
- package/3p/pi-plannotator/packages/shared/draft.ts +64 -0
- package/3p/pi-plannotator/packages/shared/external-annotation.ts +397 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.test.ts +59 -0
- package/3p/pi-plannotator/packages/shared/extract-code-paths.ts +66 -0
- package/3p/pi-plannotator/packages/shared/favicon.ts +5 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.test.ts +65 -0
- package/3p/pi-plannotator/packages/shared/feedback-templates.ts +29 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.test.ts +231 -0
- package/3p/pi-plannotator/packages/shared/goal-setup.ts +336 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.test.ts +62 -0
- package/3p/pi-plannotator/packages/shared/html-to-markdown.ts +32 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.test.ts +135 -0
- package/3p/pi-plannotator/packages/shared/improvement-hooks.ts +115 -0
- package/3p/pi-plannotator/packages/shared/integrations-common.ts +243 -0
- package/3p/pi-plannotator/packages/shared/jj-core.test.ts +236 -0
- package/3p/pi-plannotator/packages/shared/jj-core.ts +433 -0
- package/3p/pi-plannotator/packages/shared/package.json +55 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.test.ts +88 -0
- package/3p/pi-plannotator/packages/shared/pfm-reminder.ts +80 -0
- package/3p/pi-plannotator/packages/shared/pr-github.ts +661 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.test.ts +202 -0
- package/3p/pi-plannotator/packages/shared/pr-gitlab.ts +620 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.test.ts +266 -0
- package/3p/pi-plannotator/packages/shared/pr-provider.ts +123 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.test.ts +104 -0
- package/3p/pi-plannotator/packages/shared/pr-stack.ts +194 -0
- package/3p/pi-plannotator/packages/shared/pr-types.ts +326 -0
- package/3p/pi-plannotator/packages/shared/project.ts +71 -0
- package/3p/pi-plannotator/packages/shared/prompts-integration.test.ts +421 -0
- package/3p/pi-plannotator/packages/shared/prompts.test.ts +504 -0
- package/3p/pi-plannotator/packages/shared/prompts.ts +247 -0
- package/3p/pi-plannotator/packages/shared/reference-common.ts +87 -0
- package/3p/pi-plannotator/packages/shared/repo.ts +71 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.test.ts +113 -0
- package/3p/pi-plannotator/packages/shared/resolve-file.ts +509 -0
- package/3p/pi-plannotator/packages/shared/review-args.test.ts +64 -0
- package/3p/pi-plannotator/packages/shared/review-args.ts +85 -0
- package/3p/pi-plannotator/packages/shared/review-core.test.ts +286 -0
- package/3p/pi-plannotator/packages/shared/review-core.ts +895 -0
- package/3p/pi-plannotator/packages/shared/review-workspace-node.ts +230 -0
- package/3p/pi-plannotator/packages/shared/review-workspace.ts +436 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff-types.ts +76 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.test.ts +322 -0
- package/3p/pi-plannotator/packages/shared/semantic-diff.ts +520 -0
- package/3p/pi-plannotator/packages/shared/storage.ts +378 -0
- package/3p/pi-plannotator/packages/shared/tour.ts +61 -0
- package/3p/pi-plannotator/packages/shared/tsconfig.json +15 -0
- package/3p/pi-plannotator/packages/shared/types.ts +29 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.test.ts +177 -0
- package/3p/pi-plannotator/packages/shared/url-to-markdown.ts +351 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.test.ts +332 -0
- package/3p/pi-plannotator/packages/shared/vcs-core.ts +482 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.test.ts +162 -0
- package/3p/pi-plannotator/packages/shared/worktree-pool.ts +103 -0
- package/3p/pi-plannotator/packages/shared/worktree.ts +119 -0
- package/3p/pi-subagents/package.json +50 -0
- package/3p/pi-subagents/src/agent-manager.ts +413 -0
- package/3p/pi-subagents/src/agent-runner.ts +502 -0
- package/3p/pi-subagents/src/agent-types.ts +248 -0
- package/3p/pi-subagents/src/context.ts +58 -0
- package/3p/pi-subagents/src/cross-extension-rpc.ts +135 -0
- package/3p/pi-subagents/src/custom-agents.ts +137 -0
- package/3p/pi-subagents/src/default-agents.ts +144 -0
- package/3p/pi-subagents/src/env.ts +33 -0
- package/3p/pi-subagents/src/group-join.ts +141 -0
- package/3p/pi-subagents/src/index.ts +1811 -0
- package/3p/pi-subagents/src/invocation-config.ts +40 -0
- package/3p/pi-subagents/src/memory.ts +165 -0
- package/3p/pi-subagents/src/model-resolver.ts +81 -0
- package/3p/pi-subagents/src/output-file.ts +77 -0
- package/3p/pi-subagents/src/prompts.ts +85 -0
- package/3p/pi-subagents/src/skill-loader.ts +79 -0
- package/3p/pi-subagents/src/types.ts +111 -0
- package/3p/pi-subagents/src/ui/agent-widget.ts +496 -0
- package/3p/pi-subagents/src/ui/conversation-viewer.ts +250 -0
- package/3p/pi-subagents/src/worktree.ts +162 -0
- package/3p/pi-tasks/package.json +52 -0
- package/3p/pi-tasks/src/auto-clear.ts +91 -0
- package/3p/pi-tasks/src/index.ts +1150 -0
- package/3p/pi-tasks/src/process-tracker.ts +140 -0
- package/3p/pi-tasks/src/reminder-cadence.ts +90 -0
- package/3p/pi-tasks/src/task-store.ts +324 -0
- package/3p/pi-tasks/src/tasks-config.ts +27 -0
- package/3p/pi-tasks/src/types.ts +40 -0
- package/3p/pi-tasks/src/ui/settings-menu.ts +152 -0
- package/3p/pi-tasks/src/ui/task-widget.ts +296 -0
- package/AGENTS.md +28 -0
- package/LICENSE +201 -0
- package/extensions/orchestrator/agents/brainstorm-reviewer.ts +77 -0
- package/extensions/orchestrator/agents/code-reviewer.ts +89 -0
- package/extensions/orchestrator/agents/explore.ts +33 -0
- package/extensions/orchestrator/agents/librarian.ts +43 -0
- package/extensions/orchestrator/agents/plan-reviewer.ts +75 -0
- package/extensions/orchestrator/agents/planner.ts +61 -0
- package/extensions/orchestrator/agents/registry.ts +156 -0
- package/extensions/orchestrator/agents/task.ts +50 -0
- package/extensions/orchestrator/agents/tool-routing.ts +84 -0
- package/extensions/orchestrator/ast-search.ts +85 -0
- package/extensions/orchestrator/cbm.ts +330 -0
- package/extensions/orchestrator/command-handlers.test.ts +163 -0
- package/extensions/orchestrator/command-handlers.ts +116 -0
- package/extensions/orchestrator/commands.test.ts +81 -0
- package/extensions/orchestrator/commands.ts +75 -0
- package/extensions/orchestrator/config.test.ts +221 -0
- package/extensions/orchestrator/config.ts +230 -0
- package/extensions/orchestrator/context.test.ts +293 -0
- package/extensions/orchestrator/context.ts +206 -0
- package/extensions/orchestrator/event-handlers.test.ts +190 -0
- package/extensions/orchestrator/event-handlers.ts +1416 -0
- package/extensions/orchestrator/exa.ts +104 -0
- package/extensions/orchestrator/flant-infra.ts +486 -0
- package/extensions/orchestrator/index.ts +80 -0
- package/extensions/orchestrator/integration.test.ts +1214 -0
- package/extensions/orchestrator/orchestrator.test.ts +252 -0
- package/extensions/orchestrator/orchestrator.ts +538 -0
- package/extensions/orchestrator/phases/brainstorm.test.ts +15 -0
- package/extensions/orchestrator/phases/brainstorm.ts +273 -0
- package/extensions/orchestrator/phases/implementation.ts +40 -0
- package/extensions/orchestrator/phases/machine.test.ts +293 -0
- package/extensions/orchestrator/phases/machine.ts +209 -0
- package/extensions/orchestrator/phases/planning.ts +255 -0
- package/extensions/orchestrator/phases/review.ts +193 -0
- package/extensions/orchestrator/plannotator.ts +56 -0
- package/extensions/orchestrator/pp-menu.ts +866 -0
- package/extensions/orchestrator/state.test.ts +343 -0
- package/extensions/orchestrator/state.ts +237 -0
- package/extensions/orchestrator/validate-artifacts.test.ts +88 -0
- package/extensions/orchestrator/validate-artifacts.ts +272 -0
- package/extensions/orchestrator/vendor.d.ts +26 -0
- package/package.json +73 -0
- package/scripts/postinstall.sh +18 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-types.ts — Unified agent type registry.
|
|
3
|
+
*
|
|
4
|
+
* Merges embedded default agents with user-defined agents from .pi/agents/*.md.
|
|
5
|
+
* User agents override defaults with the same name. Disabled agents are kept but excluded from spawning.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
9
|
+
import {
|
|
10
|
+
createBashTool,
|
|
11
|
+
createEditTool,
|
|
12
|
+
createFindTool,
|
|
13
|
+
createGrepTool,
|
|
14
|
+
createLsTool,
|
|
15
|
+
createReadTool,
|
|
16
|
+
createWriteTool,
|
|
17
|
+
} from "@earendil-works/pi-coding-agent";
|
|
18
|
+
import { DEFAULT_AGENTS } from "./default-agents.js";
|
|
19
|
+
import type { AgentConfig } from "./types.js";
|
|
20
|
+
|
|
21
|
+
type ToolFactory = (cwd: string) => AgentTool<any>;
|
|
22
|
+
|
|
23
|
+
const TOOL_FACTORIES: Record<string, ToolFactory> = {
|
|
24
|
+
read: (cwd) => createReadTool(cwd),
|
|
25
|
+
bash: (cwd) => createBashTool(cwd),
|
|
26
|
+
edit: (cwd) => createEditTool(cwd),
|
|
27
|
+
write: (cwd) => createWriteTool(cwd),
|
|
28
|
+
grep: (cwd) => createGrepTool(cwd),
|
|
29
|
+
find: (cwd) => createFindTool(cwd),
|
|
30
|
+
ls: (cwd) => createLsTool(cwd),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** All known built-in tool names, derived from the factory registry. */
|
|
34
|
+
export const BUILTIN_TOOL_NAMES = Object.keys(TOOL_FACTORIES);
|
|
35
|
+
|
|
36
|
+
/** Unified runtime registry of all agents (defaults + user-defined). */
|
|
37
|
+
const agents = new Map<string, AgentConfig>();
|
|
38
|
+
|
|
39
|
+
/** Extension-injected agents (highest priority, survive reloads). */
|
|
40
|
+
const extensionAgents = new Map<string, AgentConfig>();
|
|
41
|
+
|
|
42
|
+
/** When true, only extension-registered agents are used. Defaults and user .md files are skipped. */
|
|
43
|
+
let extensionOnlyMode = false;
|
|
44
|
+
|
|
45
|
+
/** Enable extension-only mode: skip defaults and user .md agents entirely. */
|
|
46
|
+
export function setExtensionOnlyMode(enabled: boolean): void {
|
|
47
|
+
extensionOnlyMode = enabled;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Register agents into the unified registry.
|
|
52
|
+
* Priority (highest wins): extension agents > user .md files > defaults.
|
|
53
|
+
* In extension-only mode, defaults and user agents are skipped entirely.
|
|
54
|
+
* Disabled agents (enabled === false) are kept in the registry but excluded from spawning.
|
|
55
|
+
*/
|
|
56
|
+
export function registerAgents(userAgents: Map<string, AgentConfig>): void {
|
|
57
|
+
agents.clear();
|
|
58
|
+
|
|
59
|
+
if (!extensionOnlyMode) {
|
|
60
|
+
// Start with defaults
|
|
61
|
+
for (const [name, config] of DEFAULT_AGENTS) {
|
|
62
|
+
agents.set(name, config);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Overlay user agents (overrides defaults with same name)
|
|
66
|
+
for (const [name, config] of userAgents) {
|
|
67
|
+
agents.set(name, config);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Overlay extension-injected agents (highest priority)
|
|
72
|
+
for (const [name, config] of extensionAgents) {
|
|
73
|
+
agents.set(name, config);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Register agents from another extension (e.g. pi-pi).
|
|
79
|
+
* These persist across reloadCustomAgents() calls and take highest priority.
|
|
80
|
+
*/
|
|
81
|
+
export function registerExtensionAgents(newAgents: Map<string, AgentConfig>): void {
|
|
82
|
+
for (const [name, config] of newAgents) {
|
|
83
|
+
extensionAgents.set(name, config);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Remove extension-registered agents by name.
|
|
89
|
+
*/
|
|
90
|
+
export function unregisterExtensionAgents(names: string[]): void {
|
|
91
|
+
for (const name of names) {
|
|
92
|
+
extensionAgents.delete(name);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Remove extension-registered agents whose names start with a prefix.
|
|
98
|
+
*/
|
|
99
|
+
export function unregisterExtensionAgentsByPrefix(prefix: string): void {
|
|
100
|
+
for (const name of extensionAgents.keys()) {
|
|
101
|
+
if (name.startsWith(prefix)) {
|
|
102
|
+
extensionAgents.delete(name);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Remove all extension-registered agents.
|
|
109
|
+
*/
|
|
110
|
+
export function clearExtensionAgents(): void {
|
|
111
|
+
extensionAgents.clear();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Case-insensitive key resolution. */
|
|
115
|
+
function resolveKey(name: string): string | undefined {
|
|
116
|
+
if (agents.has(name)) return name;
|
|
117
|
+
const lower = name.toLowerCase();
|
|
118
|
+
for (const key of agents.keys()) {
|
|
119
|
+
if (key.toLowerCase() === lower) return key;
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Resolve a type name case-insensitively. Returns the canonical key or undefined. */
|
|
125
|
+
export function resolveType(name: string): string | undefined {
|
|
126
|
+
return resolveKey(name);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Get the agent config for a type (case-insensitive). */
|
|
130
|
+
export function getAgentConfig(name: string): AgentConfig | undefined {
|
|
131
|
+
const key = resolveKey(name);
|
|
132
|
+
return key ? agents.get(key) : undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Get all enabled type names (for spawning and tool descriptions). */
|
|
136
|
+
export function getAvailableTypes(): string[] {
|
|
137
|
+
return [...agents.entries()]
|
|
138
|
+
.filter(([_, config]) => config.enabled !== false)
|
|
139
|
+
.map(([name]) => name);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Get all type names including disabled (for UI listing). */
|
|
143
|
+
export function getAllTypes(): string[] {
|
|
144
|
+
return [...agents.keys()];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Get names of default agents currently in the registry. */
|
|
148
|
+
export function getDefaultAgentNames(): string[] {
|
|
149
|
+
return [...agents.entries()]
|
|
150
|
+
.filter(([_, config]) => config.isDefault === true)
|
|
151
|
+
.map(([name]) => name);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Get names of user-defined agents (non-defaults) currently in the registry. */
|
|
155
|
+
export function getUserAgentNames(): string[] {
|
|
156
|
+
return [...agents.entries()]
|
|
157
|
+
.filter(([_, config]) => config.isDefault !== true)
|
|
158
|
+
.map(([name]) => name);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Check if a type is valid and enabled (case-insensitive). */
|
|
162
|
+
export function isValidType(type: string): boolean {
|
|
163
|
+
const key = resolveKey(type);
|
|
164
|
+
if (!key) return false;
|
|
165
|
+
return agents.get(key)?.enabled !== false;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Tool names required for memory management. */
|
|
169
|
+
const MEMORY_TOOL_NAMES = ["read", "write", "edit"];
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get the tools needed for memory management (read, write, edit).
|
|
173
|
+
* Only returns tools that are NOT already in the provided set.
|
|
174
|
+
*/
|
|
175
|
+
export function getMemoryTools(cwd: string, existingToolNames: Set<string>): AgentTool<any>[] {
|
|
176
|
+
return MEMORY_TOOL_NAMES
|
|
177
|
+
.filter(n => !existingToolNames.has(n) && n in TOOL_FACTORIES)
|
|
178
|
+
.map(n => TOOL_FACTORIES[n](cwd));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Tool names needed for read-only memory access. */
|
|
182
|
+
const READONLY_MEMORY_TOOL_NAMES = ["read"];
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get only the read tool for read-only memory access.
|
|
186
|
+
* Only returns tools that are NOT already in the provided set.
|
|
187
|
+
*/
|
|
188
|
+
export function getReadOnlyMemoryTools(cwd: string, existingToolNames: Set<string>): AgentTool<any>[] {
|
|
189
|
+
return READONLY_MEMORY_TOOL_NAMES
|
|
190
|
+
.filter(n => !existingToolNames.has(n) && n in TOOL_FACTORIES)
|
|
191
|
+
.map(n => TOOL_FACTORIES[n](cwd));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Get built-in tools for a type (case-insensitive). */
|
|
195
|
+
export function getToolsForType(type: string, cwd: string): AgentTool<any>[] {
|
|
196
|
+
const key = resolveKey(type);
|
|
197
|
+
const raw = key ? agents.get(key) : undefined;
|
|
198
|
+
const config = raw?.enabled !== false ? raw : undefined;
|
|
199
|
+
const toolNames = config?.builtinToolNames?.length ? config.builtinToolNames : BUILTIN_TOOL_NAMES;
|
|
200
|
+
return toolNames.filter((n) => n in TOOL_FACTORIES).map((n) => TOOL_FACTORIES[n](cwd));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Get config for a type (case-insensitive, returns a SubagentTypeConfig-compatible object). Falls back to general-purpose. */
|
|
204
|
+
export function getConfig(type: string): {
|
|
205
|
+
displayName: string;
|
|
206
|
+
description: string;
|
|
207
|
+
builtinToolNames: string[];
|
|
208
|
+
extensions: true | string[] | false;
|
|
209
|
+
skills: true | string[] | false;
|
|
210
|
+
promptMode: "replace" | "append";
|
|
211
|
+
} {
|
|
212
|
+
const key = resolveKey(type);
|
|
213
|
+
const config = key ? agents.get(key) : undefined;
|
|
214
|
+
if (config && config.enabled !== false) {
|
|
215
|
+
return {
|
|
216
|
+
displayName: config.displayName ?? config.name,
|
|
217
|
+
description: config.description,
|
|
218
|
+
builtinToolNames: config.builtinToolNames ?? BUILTIN_TOOL_NAMES,
|
|
219
|
+
extensions: config.extensions,
|
|
220
|
+
skills: config.skills,
|
|
221
|
+
promptMode: config.promptMode,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Fallback for unknown/disabled types — general-purpose config
|
|
226
|
+
const gp = agents.get("general-purpose");
|
|
227
|
+
if (gp && gp.enabled !== false) {
|
|
228
|
+
return {
|
|
229
|
+
displayName: gp.displayName ?? gp.name,
|
|
230
|
+
description: gp.description,
|
|
231
|
+
builtinToolNames: gp.builtinToolNames ?? BUILTIN_TOOL_NAMES,
|
|
232
|
+
extensions: gp.extensions,
|
|
233
|
+
skills: gp.skills,
|
|
234
|
+
promptMode: gp.promptMode,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Absolute fallback (should never happen)
|
|
239
|
+
return {
|
|
240
|
+
displayName: "Agent",
|
|
241
|
+
description: "General-purpose agent for complex, multi-step tasks",
|
|
242
|
+
builtinToolNames: BUILTIN_TOOL_NAMES,
|
|
243
|
+
extensions: true,
|
|
244
|
+
skills: true,
|
|
245
|
+
promptMode: "append",
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* context.ts — Extract parent conversation context for subagent inheritance.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
|
|
7
|
+
/** Extract text from a message content block array. */
|
|
8
|
+
export function extractText(content: unknown[]): string {
|
|
9
|
+
return content
|
|
10
|
+
.filter((c: any) => c.type === "text")
|
|
11
|
+
.map((c: any) => c.text ?? "")
|
|
12
|
+
.join("\n");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Build a text representation of the parent conversation context.
|
|
17
|
+
* Used when inherit_context is true to give the subagent visibility
|
|
18
|
+
* into what has been discussed/done so far.
|
|
19
|
+
*/
|
|
20
|
+
export function buildParentContext(ctx: ExtensionContext): string {
|
|
21
|
+
const entries = ctx.sessionManager.getBranch();
|
|
22
|
+
if (!entries || entries.length === 0) return "";
|
|
23
|
+
|
|
24
|
+
const parts: string[] = [];
|
|
25
|
+
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (entry.type === "message") {
|
|
28
|
+
const msg = entry.message;
|
|
29
|
+
if (msg.role === "user") {
|
|
30
|
+
const text = typeof msg.content === "string"
|
|
31
|
+
? msg.content
|
|
32
|
+
: extractText(msg.content);
|
|
33
|
+
if (text.trim()) parts.push(`[User]: ${text.trim()}`);
|
|
34
|
+
} else if (msg.role === "assistant") {
|
|
35
|
+
const text = extractText(msg.content);
|
|
36
|
+
if (text.trim()) parts.push(`[Assistant]: ${text.trim()}`);
|
|
37
|
+
}
|
|
38
|
+
// Skip toolResult messages — too verbose for context
|
|
39
|
+
} else if (entry.type === "compaction") {
|
|
40
|
+
// Include compaction summaries — they're already condensed
|
|
41
|
+
if (entry.summary) {
|
|
42
|
+
parts.push(`[Summary]: ${entry.summary}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (parts.length === 0) return "";
|
|
48
|
+
|
|
49
|
+
return `# Parent Conversation Context
|
|
50
|
+
The following is the conversation history from the parent session that spawned you.
|
|
51
|
+
Use this context to understand what has been discussed and decided so far.
|
|
52
|
+
|
|
53
|
+
${parts.join("\n\n")}
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
# Your Task (below)
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
|
|
12
|
+
/** Minimal event bus interface needed by the RPC handlers. */
|
|
13
|
+
export interface EventBus {
|
|
14
|
+
on(event: string, handler: (data: unknown) => void): () => void;
|
|
15
|
+
emit(event: string, data: unknown): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** RPC reply envelope — matches pi-mono's RpcResponse shape. */
|
|
19
|
+
export type RpcReply<T = void> =
|
|
20
|
+
| { success: true; data?: T }
|
|
21
|
+
| { success: false; error: string };
|
|
22
|
+
|
|
23
|
+
/** RPC protocol version — bumped when the envelope or method contracts change. */
|
|
24
|
+
export const PROTOCOL_VERSION = 2;
|
|
25
|
+
|
|
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
|
+
|
|
32
|
+
export interface SpawnRequest {
|
|
33
|
+
requestId: string;
|
|
34
|
+
type: string;
|
|
35
|
+
prompt: string;
|
|
36
|
+
options?: any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface RpcDeps {
|
|
40
|
+
events: EventBus;
|
|
41
|
+
pi: unknown; // passed through to manager.spawn
|
|
42
|
+
getCtx: () => unknown | undefined; // returns current ExtensionContext
|
|
43
|
+
isSubagentSession?: (ctx: unknown) => boolean;
|
|
44
|
+
manager: SpawnCapable;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface RpcHandle {
|
|
48
|
+
unsubPing: () => void;
|
|
49
|
+
unsubSpawn: () => void;
|
|
50
|
+
unsubStop: () => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function emitReply(events: EventBus, channel: string, requestId: string, reply: RpcReply<unknown>): void {
|
|
54
|
+
events.emit(`${channel}:reply:${requestId}`, reply);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Wire a single RPC handler: listen on `channel`, run `fn(params)`,
|
|
59
|
+
* emit the reply envelope on `channel:reply:${requestId}`.
|
|
60
|
+
*/
|
|
61
|
+
function handleRpc<P extends { requestId: string }>(
|
|
62
|
+
events: EventBus,
|
|
63
|
+
channel: string,
|
|
64
|
+
fn: (params: P) => unknown | Promise<unknown>,
|
|
65
|
+
): () => void {
|
|
66
|
+
return events.on(channel, async (raw: unknown) => {
|
|
67
|
+
const params = raw as P;
|
|
68
|
+
try {
|
|
69
|
+
const data = await fn(params);
|
|
70
|
+
const reply: { success: true; data?: unknown } = { success: true };
|
|
71
|
+
if (data !== undefined) reply.data = data;
|
|
72
|
+
events.emit(`${channel}:reply:${params.requestId}`, reply);
|
|
73
|
+
} catch (err: any) {
|
|
74
|
+
events.emit(`${channel}:reply:${params.requestId}`, {
|
|
75
|
+
success: false, error: err?.message ?? String(err),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Register ping, spawn, and stop RPC handlers on the event bus.
|
|
83
|
+
* Returns unsub functions for cleanup.
|
|
84
|
+
*/
|
|
85
|
+
export function registerRpcHandlers(deps: RpcDeps): RpcHandle {
|
|
86
|
+
const { events, pi, getCtx, isSubagentSession, manager } = deps;
|
|
87
|
+
|
|
88
|
+
const unsubPing = handleRpc(events, "subagents:rpc:ping", () => {
|
|
89
|
+
return { version: PROTOCOL_VERSION };
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const unsubSpawn = events.on("subagents:rpc:spawn", (raw: unknown) => {
|
|
93
|
+
const params = raw as SpawnRequest;
|
|
94
|
+
const ctx = getCtx();
|
|
95
|
+
if (!ctx) {
|
|
96
|
+
emitReply(events, "subagents:rpc:spawn", params.requestId, { success: false, error: "No active session" });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (isSubagentSession?.(ctx)) {
|
|
100
|
+
emitReply(events, "subagents:rpc:spawn", params.requestId, {
|
|
101
|
+
success: false,
|
|
102
|
+
error: "Cannot spawn subagents from a subagent session context",
|
|
103
|
+
});
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
queueMicrotask(() => {
|
|
108
|
+
try {
|
|
109
|
+
const rawOpts = params.options ?? {};
|
|
110
|
+
const spawnOpts = { ...rawOpts, isBackground: rawOpts.isBackground ?? rawOpts.run_in_background ?? true };
|
|
111
|
+
const id = manager.spawn(pi, ctx, params.type, params.prompt, spawnOpts);
|
|
112
|
+
events.emit("subagents:created", {
|
|
113
|
+
id,
|
|
114
|
+
type: params.type,
|
|
115
|
+
description: params.options?.description ?? params.type,
|
|
116
|
+
isBackground: params.options?.run_in_background ?? true,
|
|
117
|
+
});
|
|
118
|
+
emitReply(events, "subagents:rpc:spawn", params.requestId, { success: true, data: { id } });
|
|
119
|
+
} catch (err: any) {
|
|
120
|
+
emitReply(events, "subagents:rpc:spawn", params.requestId, {
|
|
121
|
+
success: false,
|
|
122
|
+
error: err?.message ?? String(err),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const unsubStop = handleRpc<{ requestId: string; agentId: string }>(
|
|
129
|
+
events, "subagents:rpc:stop", ({ agentId }) => {
|
|
130
|
+
if (!manager.abort(agentId)) throw new Error("Agent not found");
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return { unsubPing, unsubSpawn, unsubStop };
|
|
135
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* custom-agents.ts — Load user-defined agents from project (.pi/agents/) and global (~/.pi/agent/agents/) locations.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { basename, join } from "node:path";
|
|
8
|
+
import { parseFrontmatter } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { BUILTIN_TOOL_NAMES } from "./agent-types.js";
|
|
10
|
+
import type { AgentConfig, MemoryScope, ThinkingLevel } from "./types.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Scan for custom agent .md files from multiple locations.
|
|
14
|
+
* Discovery hierarchy (higher priority wins):
|
|
15
|
+
* 1. Project: <cwd>/.pi/agents/*.md
|
|
16
|
+
* 2. Global: ~/.pi/agent/agents/*.md
|
|
17
|
+
*
|
|
18
|
+
* Project-level agents override global ones with the same name.
|
|
19
|
+
* Any name is allowed — names matching defaults (e.g. "Explore") override them.
|
|
20
|
+
*/
|
|
21
|
+
export function loadCustomAgents(cwd: string): Map<string, AgentConfig> {
|
|
22
|
+
const globalDir = join(homedir(), ".pi", "agent", "agents");
|
|
23
|
+
const projectDir = join(cwd, ".pi", "agents");
|
|
24
|
+
|
|
25
|
+
const agents = new Map<string, AgentConfig>();
|
|
26
|
+
loadFromDir(globalDir, agents, "global"); // lower priority
|
|
27
|
+
loadFromDir(projectDir, agents, "project"); // higher priority (overwrites)
|
|
28
|
+
return agents;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Load agent configs from a directory into the map. */
|
|
32
|
+
function loadFromDir(dir: string, agents: Map<string, AgentConfig>, source: "project" | "global"): void {
|
|
33
|
+
if (!existsSync(dir)) return;
|
|
34
|
+
|
|
35
|
+
let files: string[];
|
|
36
|
+
try {
|
|
37
|
+
files = readdirSync(dir).filter(f => f.endsWith(".md"));
|
|
38
|
+
} catch {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
const name = basename(file, ".md");
|
|
44
|
+
|
|
45
|
+
let content: string;
|
|
46
|
+
try {
|
|
47
|
+
content = readFileSync(join(dir, file), "utf-8");
|
|
48
|
+
} catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { frontmatter: fm, body } = parseFrontmatter<Record<string, unknown>>(content);
|
|
53
|
+
|
|
54
|
+
agents.set(name, {
|
|
55
|
+
name,
|
|
56
|
+
displayName: str(fm.display_name),
|
|
57
|
+
description: str(fm.description) ?? name,
|
|
58
|
+
builtinToolNames: csvList(fm.tools, BUILTIN_TOOL_NAMES),
|
|
59
|
+
disallowedTools: csvListOptional(fm.disallowed_tools),
|
|
60
|
+
extensions: inheritField(fm.extensions ?? fm.inherit_extensions),
|
|
61
|
+
skills: inheritField(fm.skills ?? fm.inherit_skills),
|
|
62
|
+
model: str(fm.model),
|
|
63
|
+
thinking: str(fm.thinking) as ThinkingLevel | undefined,
|
|
64
|
+
maxTurns: nonNegativeInt(fm.max_turns),
|
|
65
|
+
systemPrompt: body.trim(),
|
|
66
|
+
promptMode: fm.prompt_mode === "append" ? "append" : "replace",
|
|
67
|
+
inheritContext: fm.inherit_context != null ? fm.inherit_context === true : undefined,
|
|
68
|
+
runInBackground: fm.run_in_background != null ? fm.run_in_background === true : undefined,
|
|
69
|
+
isolated: fm.isolated != null ? fm.isolated === true : undefined,
|
|
70
|
+
memory: parseMemory(fm.memory),
|
|
71
|
+
isolation: fm.isolation === "worktree" ? "worktree" : undefined,
|
|
72
|
+
enabled: fm.enabled !== false, // default true; explicitly false disables
|
|
73
|
+
source,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ---- Field parsers ----
|
|
79
|
+
// All follow the same convention: omitted → default, "none"/empty → nothing, value → exact.
|
|
80
|
+
|
|
81
|
+
/** Extract a string or undefined. */
|
|
82
|
+
function str(val: unknown): string | undefined {
|
|
83
|
+
return typeof val === "string" ? val : undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Extract a non-negative integer or undefined. 0 means unlimited for max_turns. */
|
|
87
|
+
function nonNegativeInt(val: unknown): number | undefined {
|
|
88
|
+
return typeof val === "number" && val >= 0 ? val : undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Parse a raw CSV field value into items, or undefined if absent/empty/"none".
|
|
93
|
+
*/
|
|
94
|
+
function parseCsvField(val: unknown): string[] | undefined {
|
|
95
|
+
if (val === undefined || val === null) return undefined;
|
|
96
|
+
const s = String(val).trim();
|
|
97
|
+
if (!s || s === "none") return undefined;
|
|
98
|
+
const items = s.split(",").map(t => t.trim()).filter(Boolean);
|
|
99
|
+
return items.length > 0 ? items : undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Parse a comma-separated list field with defaults.
|
|
104
|
+
* omitted → defaults; "none"/empty → []; csv → listed items.
|
|
105
|
+
*/
|
|
106
|
+
function csvList(val: unknown, defaults: string[]): string[] {
|
|
107
|
+
if (val === undefined || val === null) return defaults;
|
|
108
|
+
return parseCsvField(val) ?? [];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Parse an optional comma-separated list field.
|
|
113
|
+
* omitted → undefined; "none"/empty → undefined; csv → listed items.
|
|
114
|
+
*/
|
|
115
|
+
function csvListOptional(val: unknown): string[] | undefined {
|
|
116
|
+
return parseCsvField(val);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Parse a memory scope field.
|
|
121
|
+
* omitted → undefined; "user"/"project"/"local" → MemoryScope.
|
|
122
|
+
*/
|
|
123
|
+
function parseMemory(val: unknown): MemoryScope | undefined {
|
|
124
|
+
if (val === "user" || val === "project" || val === "local") return val;
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Parse an inherit field (extensions, skills).
|
|
130
|
+
* omitted/true → true (inherit all); false/"none"/empty → false; csv → listed names.
|
|
131
|
+
*/
|
|
132
|
+
function inheritField(val: unknown): true | string[] | false {
|
|
133
|
+
if (val === undefined || val === null || val === true) return true;
|
|
134
|
+
if (val === false || val === "none") return false;
|
|
135
|
+
const items = csvList(val, []);
|
|
136
|
+
return items.length > 0 ? items : false;
|
|
137
|
+
}
|