@aexol/spectral 0.7.1 → 0.7.5
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 +5 -0
- package/dist/agent/agents.js +1 -1
- package/dist/agent/index.js +199 -184
- package/dist/commands/serve.js +0 -3
- package/dist/designer/data/systems/renault/DESIGN.md +1 -1
- package/dist/designer/philosophies.js +668 -0
- package/dist/mcp/sampling-handler.js +1 -1
- package/dist/memory/commands/status.js +1 -1
- package/dist/memory/compaction.js +2 -2
- package/dist/memory/config.js +1 -1
- package/dist/memory/debug-log.js +1 -1
- package/dist/memory/hooks/compaction-hook.js +29 -0
- package/dist/memory/index.js +2 -0
- package/dist/memory/observer.js +2 -2
- package/dist/memory/project-observations-store.js +14 -0
- package/dist/memory/tokens.js +1 -1
- package/dist/memory/tools/read-project-observations.js +82 -0
- package/dist/memory/tools/recall-observation.js +2 -2
- package/dist/pi/agent-core/agent-loop.js +501 -0
- package/dist/pi/agent-core/agent.js +401 -0
- package/dist/pi/agent-core/harness/agent-harness.js +899 -0
- package/dist/pi/agent-core/harness/compaction/branch-summarization.js +173 -0
- package/dist/pi/agent-core/harness/compaction/compaction.js +532 -0
- package/dist/pi/agent-core/harness/compaction/utils.js +130 -0
- package/dist/pi/agent-core/harness/env/nodejs.js +485 -0
- package/dist/pi/agent-core/harness/messages.js +101 -0
- package/dist/pi/agent-core/harness/prompt-templates.js +229 -0
- package/dist/pi/agent-core/harness/session/jsonl-repo.js +100 -0
- package/dist/pi/agent-core/harness/session/jsonl-storage.js +230 -0
- package/dist/pi/agent-core/harness/session/memory-repo.js +41 -0
- package/dist/pi/agent-core/harness/session/memory-storage.js +113 -0
- package/dist/pi/agent-core/harness/session/repo-utils.js +38 -0
- package/dist/pi/agent-core/harness/session/session.js +196 -0
- package/dist/pi/agent-core/harness/session/uuid.js +49 -0
- package/dist/pi/agent-core/harness/skills.js +310 -0
- package/dist/pi/agent-core/harness/system-prompt.js +29 -0
- package/dist/pi/agent-core/harness/types.js +93 -0
- package/dist/pi/agent-core/harness/utils/shell-output.js +125 -0
- package/dist/pi/agent-core/harness/utils/truncate.js +289 -0
- package/dist/pi/agent-core/index.js +24 -0
- package/dist/pi/agent-core/node.js +2 -0
- package/dist/pi/agent-core/proxy.js +277 -0
- package/dist/pi/agent-core/types.js +1 -0
- package/dist/pi/ai/api-registry.js +43 -0
- package/dist/pi/ai/cli.js +120 -0
- package/dist/pi/ai/env-api-keys.js +169 -0
- package/dist/pi/ai/image-models.generated.js +441 -0
- package/dist/pi/ai/image-models.js +22 -0
- package/dist/pi/ai/images-api-registry.js +21 -0
- package/dist/pi/ai/images.js +13 -0
- package/dist/pi/ai/index.js +18 -0
- package/dist/pi/ai/models.generated.js +16220 -0
- package/dist/pi/ai/models.js +70 -0
- package/dist/pi/ai/oauth.js +1 -0
- package/dist/pi/ai/providers/anthropic.js +945 -0
- package/dist/pi/ai/providers/faux.js +367 -0
- package/dist/pi/ai/providers/github-copilot-headers.js +28 -0
- package/dist/pi/ai/providers/openai-completions.js +945 -0
- package/dist/pi/ai/providers/openai-prompt-cache.js +9 -0
- package/dist/pi/ai/providers/register-builtins.js +97 -0
- package/dist/pi/ai/providers/simple-options.js +40 -0
- package/dist/pi/ai/providers/transform-messages.js +183 -0
- package/dist/pi/ai/session-resources.js +21 -0
- package/dist/pi/ai/stream.js +26 -0
- package/dist/pi/ai/types.js +1 -0
- package/dist/pi/ai/utils/diagnostics.js +24 -0
- package/dist/pi/ai/utils/event-stream.js +80 -0
- package/dist/pi/ai/utils/hash.js +13 -0
- package/dist/pi/ai/utils/headers.js +7 -0
- package/dist/pi/ai/utils/json-parse.js +112 -0
- package/dist/pi/ai/utils/node-http-proxy.js +96 -0
- package/dist/pi/ai/utils/oauth/anthropic.js +334 -0
- package/dist/pi/ai/utils/oauth/device-code.js +54 -0
- package/dist/pi/ai/utils/oauth/github-copilot.js +270 -0
- package/dist/pi/ai/utils/oauth/index.js +121 -0
- package/dist/pi/ai/utils/oauth/oauth-page.js +104 -0
- package/dist/pi/ai/utils/oauth/openai-codex.js +384 -0
- package/dist/pi/ai/utils/oauth/pkce.js +30 -0
- package/dist/pi/ai/utils/oauth/types.js +1 -0
- package/dist/pi/ai/utils/overflow.js +150 -0
- package/dist/pi/ai/utils/sanitize-unicode.js +25 -0
- package/dist/pi/ai/utils/typebox-helpers.js +20 -0
- package/dist/pi/ai/utils/validation.js +280 -0
- package/dist/pi/coding-agent/bun/cli.js +7 -0
- package/dist/pi/coding-agent/bun/restore-sandbox-env.js +31 -0
- package/dist/pi/coding-agent/cli/args.js +340 -0
- package/dist/pi/coding-agent/cli/file-processor.js +82 -0
- package/dist/pi/coding-agent/cli/initial-message.js +21 -0
- package/dist/pi/coding-agent/cli.js +17 -0
- package/dist/pi/coding-agent/config.js +414 -0
- package/dist/pi/coding-agent/core/agent-session-runtime.js +299 -0
- package/dist/pi/coding-agent/core/agent-session-services.js +117 -0
- package/dist/pi/coding-agent/core/agent-session.js +2498 -0
- package/dist/pi/coding-agent/core/auth-guidance.js +20 -0
- package/dist/pi/coding-agent/core/auth-storage.js +441 -0
- package/dist/pi/coding-agent/core/bash-executor.js +110 -0
- package/dist/pi/coding-agent/core/compaction/branch-summarization.js +242 -0
- package/dist/pi/coding-agent/core/compaction/compaction.js +624 -0
- package/dist/pi/coding-agent/core/compaction/index.js +6 -0
- package/dist/pi/coding-agent/core/compaction/utils.js +152 -0
- package/dist/pi/coding-agent/core/defaults.js +1 -0
- package/dist/pi/coding-agent/core/diagnostics.js +1 -0
- package/dist/pi/coding-agent/core/event-bus.js +24 -0
- package/dist/pi/coding-agent/core/exec.js +74 -0
- package/dist/pi/coding-agent/core/export-html/ansi-to-html.js +248 -0
- package/dist/pi/coding-agent/core/export-html/index.js +225 -0
- package/dist/pi/coding-agent/core/export-html/tool-renderer.js +107 -0
- package/dist/pi/coding-agent/core/extensions/index.js +8 -0
- package/dist/pi/coding-agent/core/extensions/loader.js +485 -0
- package/dist/pi/coding-agent/core/extensions/runner.js +824 -0
- package/dist/pi/coding-agent/core/extensions/types.js +44 -0
- package/dist/pi/coding-agent/core/extensions/wrapper.js +21 -0
- package/dist/pi/coding-agent/core/footer-data-provider.js +309 -0
- package/dist/pi/coding-agent/core/http-dispatcher.js +47 -0
- package/dist/pi/coding-agent/core/index.js +11 -0
- package/dist/pi/coding-agent/core/keybindings.js +294 -0
- package/dist/pi/coding-agent/core/messages.js +122 -0
- package/dist/pi/coding-agent/core/model-registry.js +728 -0
- package/dist/pi/coding-agent/core/model-resolver.js +494 -0
- package/dist/pi/coding-agent/core/output-guard.js +58 -0
- package/dist/pi/coding-agent/core/package-manager.js +2020 -0
- package/dist/pi/coding-agent/core/prompt-templates.js +237 -0
- package/dist/pi/coding-agent/core/provider-display-names.js +32 -0
- package/dist/pi/coding-agent/core/resolve-config-value.js +125 -0
- package/dist/pi/coding-agent/core/resource-loader.js +733 -0
- package/dist/pi/coding-agent/core/sdk.js +282 -0
- package/dist/pi/coding-agent/core/session-cwd.js +37 -0
- package/dist/pi/coding-agent/core/session-manager.js +1146 -0
- package/dist/pi/coding-agent/core/settings-manager.js +794 -0
- package/dist/pi/coding-agent/core/skills.js +386 -0
- package/dist/pi/coding-agent/core/slash-commands.js +24 -0
- package/dist/pi/coding-agent/core/source-info.js +18 -0
- package/dist/pi/coding-agent/core/system-prompt.js +122 -0
- package/dist/pi/coding-agent/core/telemetry.js +8 -0
- package/dist/pi/coding-agent/core/timings.js +30 -0
- package/dist/pi/coding-agent/core/tools/bash.js +341 -0
- package/dist/pi/coding-agent/core/tools/edit-diff.js +344 -0
- package/dist/pi/coding-agent/core/tools/edit.js +324 -0
- package/dist/pi/coding-agent/core/tools/file-mutation-queue.js +36 -0
- package/dist/pi/coding-agent/core/tools/find.js +297 -0
- package/dist/pi/coding-agent/core/tools/grep.js +303 -0
- package/dist/pi/coding-agent/core/tools/index.js +111 -0
- package/dist/pi/coding-agent/core/tools/ls.js +168 -0
- package/dist/pi/coding-agent/core/tools/output-accumulator.js +183 -0
- package/dist/pi/coding-agent/core/tools/path-utils.js +61 -0
- package/dist/pi/coding-agent/core/tools/read.js +288 -0
- package/dist/pi/coding-agent/core/tools/render-utils.js +48 -0
- package/dist/pi/coding-agent/core/tools/tool-definition-wrapper.js +33 -0
- package/dist/pi/coding-agent/core/tools/truncate.js +214 -0
- package/dist/pi/coding-agent/core/tools/write.js +212 -0
- package/dist/pi/coding-agent/index.js +41 -0
- package/dist/pi/coding-agent/main.js +5 -0
- package/dist/pi/coding-agent/migrations.js +280 -0
- package/dist/pi/coding-agent/modes/index.js +7 -0
- package/dist/pi/coding-agent/modes/interactive/components/diff.js +132 -0
- package/dist/pi/coding-agent/modes/interactive/components/keybinding-hints.js +35 -0
- package/dist/pi/coding-agent/modes/interactive/components/visual-truncate.js +32 -0
- package/dist/pi/coding-agent/modes/interactive/interactive-mode.js +3 -0
- package/dist/pi/coding-agent/modes/interactive/theme/theme.js +1023 -0
- package/dist/pi/coding-agent/modes/print-mode.js +130 -0
- package/dist/pi/coding-agent/modes/rpc/jsonl.js +48 -0
- package/dist/pi/coding-agent/modes/rpc/rpc-client.js +409 -0
- package/dist/pi/coding-agent/modes/rpc/rpc-mode.js +600 -0
- package/dist/pi/coding-agent/modes/rpc/rpc-types.js +7 -0
- package/dist/pi/coding-agent/utils/ansi.js +51 -0
- package/dist/pi/coding-agent/utils/changelog.js +86 -0
- package/dist/pi/coding-agent/utils/child-process.js +87 -0
- package/dist/pi/coding-agent/utils/clipboard-image.js +244 -0
- package/dist/pi/coding-agent/utils/clipboard-native.js +13 -0
- package/dist/pi/coding-agent/utils/clipboard.js +116 -0
- package/dist/pi/coding-agent/utils/exif-orientation.js +157 -0
- package/dist/pi/coding-agent/utils/frontmatter.js +25 -0
- package/dist/pi/coding-agent/utils/fs-watch.js +24 -0
- package/dist/pi/coding-agent/utils/git.js +162 -0
- package/dist/pi/coding-agent/utils/html.js +39 -0
- package/dist/pi/coding-agent/utils/image-convert.js +38 -0
- package/dist/pi/coding-agent/utils/image-resize.js +136 -0
- package/dist/pi/coding-agent/utils/mime.js +68 -0
- package/dist/pi/coding-agent/utils/paths.js +91 -0
- package/dist/pi/coding-agent/utils/photon.js +120 -0
- package/dist/pi/coding-agent/utils/pi-user-agent.js +4 -0
- package/dist/pi/coding-agent/utils/shell.js +194 -0
- package/dist/pi/coding-agent/utils/sleep.js +16 -0
- package/dist/pi/coding-agent/utils/syntax-highlight.js +117 -0
- package/dist/pi/coding-agent/utils/tools-manager.js +327 -0
- package/dist/pi/coding-agent/utils/version-check.js +81 -0
- package/dist/pi/coding-agent/utils/windows-self-update.js +76 -0
- package/dist/pi/tui/autocomplete.js +631 -0
- package/dist/pi/tui/components/box.js +103 -0
- package/dist/pi/tui/components/cancellable-loader.js +34 -0
- package/dist/pi/tui/components/editor.js +1915 -0
- package/dist/pi/tui/components/image.js +88 -0
- package/dist/pi/tui/components/input.js +425 -0
- package/dist/pi/tui/components/loader.js +68 -0
- package/dist/pi/tui/components/markdown.js +633 -0
- package/dist/pi/tui/components/select-list.js +158 -0
- package/dist/pi/tui/components/settings-list.js +184 -0
- package/dist/pi/tui/components/spacer.js +22 -0
- package/dist/pi/tui/components/text.js +88 -0
- package/dist/pi/tui/components/truncated-text.js +50 -0
- package/dist/pi/tui/editor-component.js +1 -0
- package/dist/pi/tui/fuzzy.js +109 -0
- package/dist/pi/tui/index.js +31 -0
- package/dist/pi/tui/keybindings.js +173 -0
- package/dist/pi/tui/keys.js +1172 -0
- package/dist/pi/tui/kill-ring.js +43 -0
- package/dist/pi/tui/stdin-buffer.js +360 -0
- package/dist/pi/tui/terminal-image.js +335 -0
- package/dist/pi/tui/terminal.js +324 -0
- package/dist/pi/tui/tui.js +1076 -0
- package/dist/pi/tui/undo-stack.js +24 -0
- package/dist/pi/tui/utils.js +1016 -0
- package/dist/relay/dispatcher.js +30 -0
- package/dist/server/handlers/queue.js +52 -0
- package/dist/server/pi-bridge.js +9 -1
- package/dist/server/session-stream.js +76 -111
- package/dist/server/storage.js +154 -2
- package/dist/server/title-generator.js +14 -153
- package/package.json +24 -6
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join, resolve, sep } from "node:path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { CONFIG_DIR_NAME } from "../config.js";
|
|
5
|
+
import { loadThemeFromPath } from "../modes/interactive/theme/theme.js";
|
|
6
|
+
import { canonicalizePath, isLocalPath, resolvePath } from "../utils/paths.js";
|
|
7
|
+
import { createEventBus } from "./event-bus.js";
|
|
8
|
+
import { createExtensionRuntime, loadExtensionFromFactory, loadExtensions } from "./extensions/loader.js";
|
|
9
|
+
import { DefaultPackageManager } from "./package-manager.js";
|
|
10
|
+
import { loadPromptTemplates } from "./prompt-templates.js";
|
|
11
|
+
import { SettingsManager } from "./settings-manager.js";
|
|
12
|
+
import { loadSkills } from "./skills.js";
|
|
13
|
+
import { createSourceInfo } from "./source-info.js";
|
|
14
|
+
function resolvePromptInput(input, description) {
|
|
15
|
+
if (!input) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (existsSync(input)) {
|
|
19
|
+
try {
|
|
20
|
+
return readFileSync(input, "utf-8");
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.error(chalk.yellow(`Warning: Could not read ${description} file ${input}: ${error}`));
|
|
24
|
+
return input;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
function loadContextFileFromDir(dir) {
|
|
30
|
+
const candidates = ["AGENTS.md", "AGENTS.MD", "CLAUDE.md", "CLAUDE.MD"];
|
|
31
|
+
for (const filename of candidates) {
|
|
32
|
+
const filePath = join(dir, filename);
|
|
33
|
+
if (existsSync(filePath)) {
|
|
34
|
+
try {
|
|
35
|
+
return {
|
|
36
|
+
path: filePath,
|
|
37
|
+
content: readFileSync(filePath, "utf-8"),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(chalk.yellow(`Warning: Could not read ${filePath}: ${error}`));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
export function loadProjectContextFiles(options) {
|
|
48
|
+
const resolvedCwd = resolvePath(options.cwd);
|
|
49
|
+
const resolvedAgentDir = resolvePath(options.agentDir);
|
|
50
|
+
const contextFiles = [];
|
|
51
|
+
const seenPaths = new Set();
|
|
52
|
+
const globalContext = loadContextFileFromDir(resolvedAgentDir);
|
|
53
|
+
if (globalContext) {
|
|
54
|
+
contextFiles.push(globalContext);
|
|
55
|
+
seenPaths.add(globalContext.path);
|
|
56
|
+
}
|
|
57
|
+
const ancestorContextFiles = [];
|
|
58
|
+
let currentDir = resolvedCwd;
|
|
59
|
+
const root = resolve("/");
|
|
60
|
+
while (true) {
|
|
61
|
+
const contextFile = loadContextFileFromDir(currentDir);
|
|
62
|
+
if (contextFile && !seenPaths.has(contextFile.path)) {
|
|
63
|
+
ancestorContextFiles.unshift(contextFile);
|
|
64
|
+
seenPaths.add(contextFile.path);
|
|
65
|
+
}
|
|
66
|
+
if (currentDir === root)
|
|
67
|
+
break;
|
|
68
|
+
const parentDir = resolve(currentDir, "..");
|
|
69
|
+
if (parentDir === currentDir)
|
|
70
|
+
break;
|
|
71
|
+
currentDir = parentDir;
|
|
72
|
+
}
|
|
73
|
+
contextFiles.push(...ancestorContextFiles);
|
|
74
|
+
return contextFiles;
|
|
75
|
+
}
|
|
76
|
+
export class DefaultResourceLoader {
|
|
77
|
+
cwd;
|
|
78
|
+
agentDir;
|
|
79
|
+
settingsManager;
|
|
80
|
+
eventBus;
|
|
81
|
+
packageManager;
|
|
82
|
+
additionalExtensionPaths;
|
|
83
|
+
additionalSkillPaths;
|
|
84
|
+
additionalPromptTemplatePaths;
|
|
85
|
+
additionalThemePaths;
|
|
86
|
+
extensionFactories;
|
|
87
|
+
noExtensions;
|
|
88
|
+
noSkills;
|
|
89
|
+
noPromptTemplates;
|
|
90
|
+
noThemes;
|
|
91
|
+
noContextFiles;
|
|
92
|
+
systemPromptSource;
|
|
93
|
+
appendSystemPromptSource;
|
|
94
|
+
extensionsOverride;
|
|
95
|
+
skillsOverride;
|
|
96
|
+
promptsOverride;
|
|
97
|
+
themesOverride;
|
|
98
|
+
agentsFilesOverride;
|
|
99
|
+
systemPromptOverride;
|
|
100
|
+
appendSystemPromptOverride;
|
|
101
|
+
extensionsResult;
|
|
102
|
+
skills;
|
|
103
|
+
skillDiagnostics;
|
|
104
|
+
prompts;
|
|
105
|
+
promptDiagnostics;
|
|
106
|
+
themes;
|
|
107
|
+
themeDiagnostics;
|
|
108
|
+
agentsFiles;
|
|
109
|
+
systemPrompt;
|
|
110
|
+
appendSystemPrompt;
|
|
111
|
+
lastSkillPaths;
|
|
112
|
+
extensionSkillSourceInfos;
|
|
113
|
+
extensionPromptSourceInfos;
|
|
114
|
+
extensionThemeSourceInfos;
|
|
115
|
+
lastPromptPaths;
|
|
116
|
+
lastThemePaths;
|
|
117
|
+
constructor(options) {
|
|
118
|
+
this.cwd = resolvePath(options.cwd);
|
|
119
|
+
this.agentDir = resolvePath(options.agentDir);
|
|
120
|
+
this.settingsManager = options.settingsManager ?? SettingsManager.create(this.cwd, this.agentDir);
|
|
121
|
+
this.eventBus = options.eventBus ?? createEventBus();
|
|
122
|
+
this.packageManager = new DefaultPackageManager({
|
|
123
|
+
cwd: this.cwd,
|
|
124
|
+
agentDir: this.agentDir,
|
|
125
|
+
settingsManager: this.settingsManager,
|
|
126
|
+
});
|
|
127
|
+
this.additionalExtensionPaths = options.additionalExtensionPaths ?? [];
|
|
128
|
+
this.additionalSkillPaths = options.additionalSkillPaths ?? [];
|
|
129
|
+
this.additionalPromptTemplatePaths = options.additionalPromptTemplatePaths ?? [];
|
|
130
|
+
this.additionalThemePaths = options.additionalThemePaths ?? [];
|
|
131
|
+
this.extensionFactories = options.extensionFactories ?? [];
|
|
132
|
+
this.noExtensions = options.noExtensions ?? false;
|
|
133
|
+
this.noSkills = options.noSkills ?? false;
|
|
134
|
+
this.noPromptTemplates = options.noPromptTemplates ?? false;
|
|
135
|
+
this.noThemes = options.noThemes ?? false;
|
|
136
|
+
this.noContextFiles = options.noContextFiles ?? false;
|
|
137
|
+
this.systemPromptSource = options.systemPrompt;
|
|
138
|
+
this.appendSystemPromptSource = options.appendSystemPrompt;
|
|
139
|
+
this.extensionsOverride = options.extensionsOverride;
|
|
140
|
+
this.skillsOverride = options.skillsOverride;
|
|
141
|
+
this.promptsOverride = options.promptsOverride;
|
|
142
|
+
this.themesOverride = options.themesOverride;
|
|
143
|
+
this.agentsFilesOverride = options.agentsFilesOverride;
|
|
144
|
+
this.systemPromptOverride = options.systemPromptOverride;
|
|
145
|
+
this.appendSystemPromptOverride = options.appendSystemPromptOverride;
|
|
146
|
+
this.extensionsResult = { extensions: [], errors: [], runtime: createExtensionRuntime() };
|
|
147
|
+
this.skills = [];
|
|
148
|
+
this.skillDiagnostics = [];
|
|
149
|
+
this.prompts = [];
|
|
150
|
+
this.promptDiagnostics = [];
|
|
151
|
+
this.themes = [];
|
|
152
|
+
this.themeDiagnostics = [];
|
|
153
|
+
this.agentsFiles = [];
|
|
154
|
+
this.appendSystemPrompt = [];
|
|
155
|
+
this.lastSkillPaths = [];
|
|
156
|
+
this.extensionSkillSourceInfos = new Map();
|
|
157
|
+
this.extensionPromptSourceInfos = new Map();
|
|
158
|
+
this.extensionThemeSourceInfos = new Map();
|
|
159
|
+
this.lastPromptPaths = [];
|
|
160
|
+
this.lastThemePaths = [];
|
|
161
|
+
}
|
|
162
|
+
getExtensions() {
|
|
163
|
+
return this.extensionsResult;
|
|
164
|
+
}
|
|
165
|
+
getSkills() {
|
|
166
|
+
return { skills: this.skills, diagnostics: this.skillDiagnostics };
|
|
167
|
+
}
|
|
168
|
+
getPrompts() {
|
|
169
|
+
return { prompts: this.prompts, diagnostics: this.promptDiagnostics };
|
|
170
|
+
}
|
|
171
|
+
getThemes() {
|
|
172
|
+
return { themes: this.themes, diagnostics: this.themeDiagnostics };
|
|
173
|
+
}
|
|
174
|
+
getAgentsFiles() {
|
|
175
|
+
return { agentsFiles: this.agentsFiles };
|
|
176
|
+
}
|
|
177
|
+
getSystemPrompt() {
|
|
178
|
+
return this.systemPrompt;
|
|
179
|
+
}
|
|
180
|
+
getAppendSystemPrompt() {
|
|
181
|
+
return this.appendSystemPrompt;
|
|
182
|
+
}
|
|
183
|
+
extendResources(paths) {
|
|
184
|
+
const skillPaths = this.normalizeExtensionPaths(paths.skillPaths ?? []);
|
|
185
|
+
const promptPaths = this.normalizeExtensionPaths(paths.promptPaths ?? []);
|
|
186
|
+
const themePaths = this.normalizeExtensionPaths(paths.themePaths ?? []);
|
|
187
|
+
for (const entry of skillPaths) {
|
|
188
|
+
this.extensionSkillSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));
|
|
189
|
+
}
|
|
190
|
+
for (const entry of promptPaths) {
|
|
191
|
+
this.extensionPromptSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));
|
|
192
|
+
}
|
|
193
|
+
for (const entry of themePaths) {
|
|
194
|
+
this.extensionThemeSourceInfos.set(entry.path, createSourceInfo(entry.path, entry.metadata));
|
|
195
|
+
}
|
|
196
|
+
if (skillPaths.length > 0) {
|
|
197
|
+
this.lastSkillPaths = this.mergePaths(this.lastSkillPaths, skillPaths.map((entry) => entry.path));
|
|
198
|
+
this.updateSkillsFromPaths(this.lastSkillPaths);
|
|
199
|
+
}
|
|
200
|
+
if (promptPaths.length > 0) {
|
|
201
|
+
this.lastPromptPaths = this.mergePaths(this.lastPromptPaths, promptPaths.map((entry) => entry.path));
|
|
202
|
+
this.updatePromptsFromPaths(this.lastPromptPaths);
|
|
203
|
+
}
|
|
204
|
+
if (themePaths.length > 0) {
|
|
205
|
+
this.lastThemePaths = this.mergePaths(this.lastThemePaths, themePaths.map((entry) => entry.path));
|
|
206
|
+
this.updateThemesFromPaths(this.lastThemePaths);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async reload() {
|
|
210
|
+
await this.settingsManager.reload();
|
|
211
|
+
const resolvedPaths = await this.packageManager.resolve();
|
|
212
|
+
const cliExtensionPaths = await this.packageManager.resolveExtensionSources(this.additionalExtensionPaths, {
|
|
213
|
+
temporary: true,
|
|
214
|
+
});
|
|
215
|
+
const metadataByPath = new Map();
|
|
216
|
+
this.extensionSkillSourceInfos = new Map();
|
|
217
|
+
this.extensionPromptSourceInfos = new Map();
|
|
218
|
+
this.extensionThemeSourceInfos = new Map();
|
|
219
|
+
// Helper to extract enabled paths and store metadata
|
|
220
|
+
const getEnabledResources = (resources) => {
|
|
221
|
+
for (const r of resources) {
|
|
222
|
+
if (!metadataByPath.has(r.path)) {
|
|
223
|
+
metadataByPath.set(r.path, r.metadata);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return resources.filter((r) => r.enabled);
|
|
227
|
+
};
|
|
228
|
+
const getEnabledPaths = (resources) => getEnabledResources(resources).map((r) => r.path);
|
|
229
|
+
const enabledExtensions = getEnabledPaths(resolvedPaths.extensions);
|
|
230
|
+
const enabledSkillResources = getEnabledResources(resolvedPaths.skills);
|
|
231
|
+
const enabledPrompts = getEnabledPaths(resolvedPaths.prompts);
|
|
232
|
+
const enabledThemes = getEnabledPaths(resolvedPaths.themes);
|
|
233
|
+
const mapSkillPath = (resource) => {
|
|
234
|
+
if (resource.metadata.source !== "auto" && resource.metadata.origin !== "package") {
|
|
235
|
+
return resource.path;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
const stats = statSync(resource.path);
|
|
239
|
+
if (!stats.isDirectory()) {
|
|
240
|
+
return resource.path;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
return resource.path;
|
|
245
|
+
}
|
|
246
|
+
const skillFile = join(resource.path, "SKILL.md");
|
|
247
|
+
if (existsSync(skillFile)) {
|
|
248
|
+
if (!metadataByPath.has(skillFile)) {
|
|
249
|
+
metadataByPath.set(skillFile, resource.metadata);
|
|
250
|
+
}
|
|
251
|
+
return skillFile;
|
|
252
|
+
}
|
|
253
|
+
return resource.path;
|
|
254
|
+
};
|
|
255
|
+
const enabledSkills = enabledSkillResources.map(mapSkillPath);
|
|
256
|
+
// Add CLI paths metadata
|
|
257
|
+
for (const r of cliExtensionPaths.extensions) {
|
|
258
|
+
if (!metadataByPath.has(r.path)) {
|
|
259
|
+
metadataByPath.set(r.path, { source: "cli", scope: "temporary", origin: "top-level" });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
for (const r of cliExtensionPaths.skills) {
|
|
263
|
+
if (!metadataByPath.has(r.path)) {
|
|
264
|
+
metadataByPath.set(r.path, { source: "cli", scope: "temporary", origin: "top-level" });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const cliEnabledExtensions = getEnabledPaths(cliExtensionPaths.extensions);
|
|
268
|
+
const cliEnabledSkills = getEnabledPaths(cliExtensionPaths.skills);
|
|
269
|
+
const cliEnabledPrompts = getEnabledPaths(cliExtensionPaths.prompts);
|
|
270
|
+
const cliEnabledThemes = getEnabledPaths(cliExtensionPaths.themes);
|
|
271
|
+
const extensionPaths = this.noExtensions
|
|
272
|
+
? cliEnabledExtensions
|
|
273
|
+
: this.mergePaths(cliEnabledExtensions, enabledExtensions);
|
|
274
|
+
const extensionsResult = await loadExtensions(extensionPaths, this.cwd, this.eventBus);
|
|
275
|
+
const inlineExtensions = await this.loadExtensionFactories(extensionsResult.runtime);
|
|
276
|
+
extensionsResult.extensions.push(...inlineExtensions.extensions);
|
|
277
|
+
extensionsResult.errors.push(...inlineExtensions.errors);
|
|
278
|
+
// Detect extension conflicts (tools, commands, flags with same names from different extensions)
|
|
279
|
+
// Keep all extensions loaded. Conflicts are reported as diagnostics, and precedence is handled by load order.
|
|
280
|
+
const conflicts = this.detectExtensionConflicts(extensionsResult.extensions);
|
|
281
|
+
for (const conflict of conflicts) {
|
|
282
|
+
extensionsResult.errors.push({ path: conflict.path, error: conflict.message });
|
|
283
|
+
}
|
|
284
|
+
for (const p of this.additionalExtensionPaths) {
|
|
285
|
+
if (isLocalPath(p)) {
|
|
286
|
+
const resolved = this.resolveResourcePath(p);
|
|
287
|
+
if (!existsSync(resolved)) {
|
|
288
|
+
extensionsResult.errors.push({ path: resolved, error: `Extension path does not exist: ${resolved}` });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
this.extensionsResult = this.extensionsOverride ? this.extensionsOverride(extensionsResult) : extensionsResult;
|
|
293
|
+
this.applyExtensionSourceInfo(this.extensionsResult.extensions, metadataByPath);
|
|
294
|
+
const skillPaths = this.noSkills
|
|
295
|
+
? this.mergePaths(cliEnabledSkills, this.additionalSkillPaths)
|
|
296
|
+
: this.mergePaths([...cliEnabledSkills, ...enabledSkills], this.additionalSkillPaths);
|
|
297
|
+
this.lastSkillPaths = skillPaths;
|
|
298
|
+
this.updateSkillsFromPaths(skillPaths, metadataByPath);
|
|
299
|
+
for (const p of this.additionalSkillPaths) {
|
|
300
|
+
if (isLocalPath(p)) {
|
|
301
|
+
const resolved = this.resolveResourcePath(p);
|
|
302
|
+
if (!existsSync(resolved) && !this.skillDiagnostics.some((d) => d.path === resolved)) {
|
|
303
|
+
this.skillDiagnostics.push({ type: "error", message: "Skill path does not exist", path: resolved });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const promptPaths = this.noPromptTemplates
|
|
308
|
+
? this.mergePaths(cliEnabledPrompts, this.additionalPromptTemplatePaths)
|
|
309
|
+
: this.mergePaths([...cliEnabledPrompts, ...enabledPrompts], this.additionalPromptTemplatePaths);
|
|
310
|
+
this.lastPromptPaths = promptPaths;
|
|
311
|
+
this.updatePromptsFromPaths(promptPaths, metadataByPath);
|
|
312
|
+
for (const p of this.additionalPromptTemplatePaths) {
|
|
313
|
+
if (isLocalPath(p)) {
|
|
314
|
+
const resolved = this.resolveResourcePath(p);
|
|
315
|
+
if (!existsSync(resolved) && !this.promptDiagnostics.some((d) => d.path === resolved)) {
|
|
316
|
+
this.promptDiagnostics.push({
|
|
317
|
+
type: "error",
|
|
318
|
+
message: "Prompt template path does not exist",
|
|
319
|
+
path: resolved,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const themePaths = this.noThemes
|
|
325
|
+
? this.mergePaths(cliEnabledThemes, this.additionalThemePaths)
|
|
326
|
+
: this.mergePaths([...cliEnabledThemes, ...enabledThemes], this.additionalThemePaths);
|
|
327
|
+
this.lastThemePaths = themePaths;
|
|
328
|
+
this.updateThemesFromPaths(themePaths, metadataByPath);
|
|
329
|
+
for (const p of this.additionalThemePaths) {
|
|
330
|
+
const resolved = this.resolveResourcePath(p);
|
|
331
|
+
if (!existsSync(resolved) && !this.themeDiagnostics.some((d) => d.path === resolved)) {
|
|
332
|
+
this.themeDiagnostics.push({ type: "error", message: "Theme path does not exist", path: resolved });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const agentsFiles = {
|
|
336
|
+
agentsFiles: this.noContextFiles ? [] : loadProjectContextFiles({ cwd: this.cwd, agentDir: this.agentDir }),
|
|
337
|
+
};
|
|
338
|
+
const resolvedAgentsFiles = this.agentsFilesOverride ? this.agentsFilesOverride(agentsFiles) : agentsFiles;
|
|
339
|
+
this.agentsFiles = resolvedAgentsFiles.agentsFiles;
|
|
340
|
+
const baseSystemPrompt = resolvePromptInput(this.systemPromptSource ?? this.discoverSystemPromptFile(), "system prompt");
|
|
341
|
+
this.systemPrompt = this.systemPromptOverride ? this.systemPromptOverride(baseSystemPrompt) : baseSystemPrompt;
|
|
342
|
+
const appendSources = this.appendSystemPromptSource ??
|
|
343
|
+
(this.discoverAppendSystemPromptFile() ? [this.discoverAppendSystemPromptFile()] : []);
|
|
344
|
+
const baseAppend = appendSources
|
|
345
|
+
.map((s) => resolvePromptInput(s, "append system prompt"))
|
|
346
|
+
.filter((s) => s !== undefined);
|
|
347
|
+
this.appendSystemPrompt = this.appendSystemPromptOverride
|
|
348
|
+
? this.appendSystemPromptOverride(baseAppend)
|
|
349
|
+
: baseAppend;
|
|
350
|
+
}
|
|
351
|
+
normalizeExtensionPaths(entries) {
|
|
352
|
+
return entries.map((entry) => {
|
|
353
|
+
const metadata = entry.metadata.baseDir
|
|
354
|
+
? { ...entry.metadata, baseDir: this.resolveResourcePath(entry.metadata.baseDir) }
|
|
355
|
+
: entry.metadata;
|
|
356
|
+
return {
|
|
357
|
+
path: this.resolveResourcePath(entry.path),
|
|
358
|
+
metadata,
|
|
359
|
+
};
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
updateSkillsFromPaths(skillPaths, metadataByPath) {
|
|
363
|
+
let skillsResult;
|
|
364
|
+
if (this.noSkills && skillPaths.length === 0) {
|
|
365
|
+
skillsResult = { skills: [], diagnostics: [] };
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
skillsResult = loadSkills({
|
|
369
|
+
cwd: this.cwd,
|
|
370
|
+
agentDir: this.agentDir,
|
|
371
|
+
skillPaths,
|
|
372
|
+
includeDefaults: false,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
const resolvedSkills = this.skillsOverride ? this.skillsOverride(skillsResult) : skillsResult;
|
|
376
|
+
this.skills = resolvedSkills.skills.map((skill) => ({
|
|
377
|
+
...skill,
|
|
378
|
+
sourceInfo: this.findSourceInfoForPath(skill.filePath, this.extensionSkillSourceInfos, metadataByPath) ??
|
|
379
|
+
skill.sourceInfo ??
|
|
380
|
+
this.getDefaultSourceInfoForPath(skill.filePath),
|
|
381
|
+
}));
|
|
382
|
+
this.skillDiagnostics = resolvedSkills.diagnostics;
|
|
383
|
+
}
|
|
384
|
+
updatePromptsFromPaths(promptPaths, metadataByPath) {
|
|
385
|
+
let promptsResult;
|
|
386
|
+
if (this.noPromptTemplates && promptPaths.length === 0) {
|
|
387
|
+
promptsResult = { prompts: [], diagnostics: [] };
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
const allPrompts = loadPromptTemplates({
|
|
391
|
+
cwd: this.cwd,
|
|
392
|
+
agentDir: this.agentDir,
|
|
393
|
+
promptPaths,
|
|
394
|
+
includeDefaults: false,
|
|
395
|
+
});
|
|
396
|
+
promptsResult = this.dedupePrompts(allPrompts);
|
|
397
|
+
}
|
|
398
|
+
const resolvedPrompts = this.promptsOverride ? this.promptsOverride(promptsResult) : promptsResult;
|
|
399
|
+
this.prompts = resolvedPrompts.prompts.map((prompt) => ({
|
|
400
|
+
...prompt,
|
|
401
|
+
sourceInfo: this.findSourceInfoForPath(prompt.filePath, this.extensionPromptSourceInfos, metadataByPath) ??
|
|
402
|
+
prompt.sourceInfo ??
|
|
403
|
+
this.getDefaultSourceInfoForPath(prompt.filePath),
|
|
404
|
+
}));
|
|
405
|
+
this.promptDiagnostics = resolvedPrompts.diagnostics;
|
|
406
|
+
}
|
|
407
|
+
updateThemesFromPaths(themePaths, metadataByPath) {
|
|
408
|
+
let themesResult;
|
|
409
|
+
if (this.noThemes && themePaths.length === 0) {
|
|
410
|
+
themesResult = { themes: [], diagnostics: [] };
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
const loaded = this.loadThemes(themePaths, false);
|
|
414
|
+
const deduped = this.dedupeThemes(loaded.themes);
|
|
415
|
+
themesResult = { themes: deduped.themes, diagnostics: [...loaded.diagnostics, ...deduped.diagnostics] };
|
|
416
|
+
}
|
|
417
|
+
const resolvedThemes = this.themesOverride ? this.themesOverride(themesResult) : themesResult;
|
|
418
|
+
this.themes = resolvedThemes.themes.map((theme) => {
|
|
419
|
+
const sourcePath = theme.sourcePath;
|
|
420
|
+
theme.sourceInfo = sourcePath
|
|
421
|
+
? (this.findSourceInfoForPath(sourcePath, this.extensionThemeSourceInfos, metadataByPath) ??
|
|
422
|
+
theme.sourceInfo ??
|
|
423
|
+
this.getDefaultSourceInfoForPath(sourcePath))
|
|
424
|
+
: theme.sourceInfo;
|
|
425
|
+
return theme;
|
|
426
|
+
});
|
|
427
|
+
this.themeDiagnostics = resolvedThemes.diagnostics;
|
|
428
|
+
}
|
|
429
|
+
applyExtensionSourceInfo(extensions, metadataByPath) {
|
|
430
|
+
for (const extension of extensions) {
|
|
431
|
+
extension.sourceInfo =
|
|
432
|
+
this.findSourceInfoForPath(extension.path, undefined, metadataByPath) ??
|
|
433
|
+
this.getDefaultSourceInfoForPath(extension.path);
|
|
434
|
+
for (const command of extension.commands.values()) {
|
|
435
|
+
command.sourceInfo = extension.sourceInfo;
|
|
436
|
+
}
|
|
437
|
+
for (const tool of extension.tools.values()) {
|
|
438
|
+
tool.sourceInfo = extension.sourceInfo;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
findSourceInfoForPath(resourcePath, extraSourceInfos, metadataByPath) {
|
|
443
|
+
if (!resourcePath) {
|
|
444
|
+
return undefined;
|
|
445
|
+
}
|
|
446
|
+
if (resourcePath.startsWith("<")) {
|
|
447
|
+
return this.getDefaultSourceInfoForPath(resourcePath);
|
|
448
|
+
}
|
|
449
|
+
const normalizedResourcePath = resolve(resourcePath);
|
|
450
|
+
if (extraSourceInfos) {
|
|
451
|
+
for (const [sourcePath, sourceInfo] of extraSourceInfos.entries()) {
|
|
452
|
+
const normalizedSourcePath = resolve(sourcePath);
|
|
453
|
+
if (normalizedResourcePath === normalizedSourcePath ||
|
|
454
|
+
normalizedResourcePath.startsWith(`${normalizedSourcePath}${sep}`)) {
|
|
455
|
+
return { ...sourceInfo, path: resourcePath };
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
if (metadataByPath) {
|
|
460
|
+
const exact = metadataByPath.get(normalizedResourcePath) ?? metadataByPath.get(resourcePath);
|
|
461
|
+
if (exact) {
|
|
462
|
+
return createSourceInfo(resourcePath, exact);
|
|
463
|
+
}
|
|
464
|
+
for (const [sourcePath, metadata] of metadataByPath.entries()) {
|
|
465
|
+
const normalizedSourcePath = resolve(sourcePath);
|
|
466
|
+
if (normalizedResourcePath === normalizedSourcePath ||
|
|
467
|
+
normalizedResourcePath.startsWith(`${normalizedSourcePath}${sep}`)) {
|
|
468
|
+
return createSourceInfo(resourcePath, metadata);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return undefined;
|
|
473
|
+
}
|
|
474
|
+
getDefaultSourceInfoForPath(filePath) {
|
|
475
|
+
if (filePath.startsWith("<") && filePath.endsWith(">")) {
|
|
476
|
+
return {
|
|
477
|
+
path: filePath,
|
|
478
|
+
source: filePath.slice(1, -1).split(":")[0] || "temporary",
|
|
479
|
+
scope: "temporary",
|
|
480
|
+
origin: "top-level",
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
const normalizedPath = resolve(filePath);
|
|
484
|
+
const agentRoots = [
|
|
485
|
+
join(this.agentDir, "skills"),
|
|
486
|
+
join(this.agentDir, "prompts"),
|
|
487
|
+
join(this.agentDir, "themes"),
|
|
488
|
+
join(this.agentDir, "extensions"),
|
|
489
|
+
];
|
|
490
|
+
const projectRoots = [
|
|
491
|
+
join(this.cwd, CONFIG_DIR_NAME, "skills"),
|
|
492
|
+
join(this.cwd, CONFIG_DIR_NAME, "prompts"),
|
|
493
|
+
join(this.cwd, CONFIG_DIR_NAME, "themes"),
|
|
494
|
+
join(this.cwd, CONFIG_DIR_NAME, "extensions"),
|
|
495
|
+
];
|
|
496
|
+
for (const root of agentRoots) {
|
|
497
|
+
if (this.isUnderPath(normalizedPath, root)) {
|
|
498
|
+
return { path: filePath, source: "local", scope: "user", origin: "top-level", baseDir: root };
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
for (const root of projectRoots) {
|
|
502
|
+
if (this.isUnderPath(normalizedPath, root)) {
|
|
503
|
+
return { path: filePath, source: "local", scope: "project", origin: "top-level", baseDir: root };
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
path: filePath,
|
|
508
|
+
source: "local",
|
|
509
|
+
scope: "temporary",
|
|
510
|
+
origin: "top-level",
|
|
511
|
+
baseDir: statSync(normalizedPath).isDirectory() ? normalizedPath : resolve(normalizedPath, ".."),
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
mergePaths(primary, additional) {
|
|
515
|
+
const merged = [];
|
|
516
|
+
const seen = new Set();
|
|
517
|
+
for (const p of [...primary, ...additional]) {
|
|
518
|
+
const resolved = this.resolveResourcePath(p);
|
|
519
|
+
const canonicalPath = canonicalizePath(resolved);
|
|
520
|
+
if (seen.has(canonicalPath))
|
|
521
|
+
continue;
|
|
522
|
+
seen.add(canonicalPath);
|
|
523
|
+
merged.push(resolved);
|
|
524
|
+
}
|
|
525
|
+
return merged;
|
|
526
|
+
}
|
|
527
|
+
resolveResourcePath(p) {
|
|
528
|
+
return resolvePath(p, this.cwd, { trim: true });
|
|
529
|
+
}
|
|
530
|
+
loadThemes(paths, includeDefaults = true) {
|
|
531
|
+
const themes = [];
|
|
532
|
+
const diagnostics = [];
|
|
533
|
+
if (includeDefaults) {
|
|
534
|
+
const defaultDirs = [join(this.agentDir, "themes"), join(this.cwd, CONFIG_DIR_NAME, "themes")];
|
|
535
|
+
for (const dir of defaultDirs) {
|
|
536
|
+
this.loadThemesFromDir(dir, themes, diagnostics);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
for (const p of paths) {
|
|
540
|
+
const resolved = this.resolveResourcePath(p);
|
|
541
|
+
if (!existsSync(resolved)) {
|
|
542
|
+
diagnostics.push({ type: "warning", message: "theme path does not exist", path: resolved });
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
try {
|
|
546
|
+
const stats = statSync(resolved);
|
|
547
|
+
if (stats.isDirectory()) {
|
|
548
|
+
this.loadThemesFromDir(resolved, themes, diagnostics);
|
|
549
|
+
}
|
|
550
|
+
else if (stats.isFile() && resolved.endsWith(".json")) {
|
|
551
|
+
this.loadThemeFromFile(resolved, themes, diagnostics);
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
diagnostics.push({ type: "warning", message: "theme path is not a json file", path: resolved });
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
const message = error instanceof Error ? error.message : "failed to read theme path";
|
|
559
|
+
diagnostics.push({ type: "warning", message, path: resolved });
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return { themes, diagnostics };
|
|
563
|
+
}
|
|
564
|
+
loadThemesFromDir(dir, themes, diagnostics) {
|
|
565
|
+
if (!existsSync(dir)) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
try {
|
|
569
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
570
|
+
for (const entry of entries) {
|
|
571
|
+
let isFile = entry.isFile();
|
|
572
|
+
if (entry.isSymbolicLink()) {
|
|
573
|
+
try {
|
|
574
|
+
isFile = statSync(join(dir, entry.name)).isFile();
|
|
575
|
+
}
|
|
576
|
+
catch {
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
if (!isFile) {
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
if (!entry.name.endsWith(".json")) {
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
this.loadThemeFromFile(join(dir, entry.name), themes, diagnostics);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
catch (error) {
|
|
590
|
+
const message = error instanceof Error ? error.message : "failed to read theme directory";
|
|
591
|
+
diagnostics.push({ type: "warning", message, path: dir });
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
loadThemeFromFile(filePath, themes, diagnostics) {
|
|
595
|
+
try {
|
|
596
|
+
themes.push(loadThemeFromPath(filePath));
|
|
597
|
+
}
|
|
598
|
+
catch (error) {
|
|
599
|
+
const message = error instanceof Error ? error.message : "failed to load theme";
|
|
600
|
+
diagnostics.push({ type: "warning", message, path: filePath });
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
async loadExtensionFactories(runtime) {
|
|
604
|
+
const extensions = [];
|
|
605
|
+
const errors = [];
|
|
606
|
+
for (const [index, factory] of this.extensionFactories.entries()) {
|
|
607
|
+
const extensionPath = `<inline:${index + 1}>`;
|
|
608
|
+
try {
|
|
609
|
+
const extension = await loadExtensionFromFactory(factory, this.cwd, this.eventBus, runtime, extensionPath);
|
|
610
|
+
extensions.push(extension);
|
|
611
|
+
}
|
|
612
|
+
catch (error) {
|
|
613
|
+
const message = error instanceof Error ? error.message : "failed to load extension";
|
|
614
|
+
errors.push({ path: extensionPath, error: message });
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return { extensions, errors };
|
|
618
|
+
}
|
|
619
|
+
dedupePrompts(prompts) {
|
|
620
|
+
const seen = new Map();
|
|
621
|
+
const diagnostics = [];
|
|
622
|
+
for (const prompt of prompts) {
|
|
623
|
+
const existing = seen.get(prompt.name);
|
|
624
|
+
if (existing) {
|
|
625
|
+
diagnostics.push({
|
|
626
|
+
type: "collision",
|
|
627
|
+
message: `name "/${prompt.name}" collision`,
|
|
628
|
+
path: prompt.filePath,
|
|
629
|
+
collision: {
|
|
630
|
+
resourceType: "prompt",
|
|
631
|
+
name: prompt.name,
|
|
632
|
+
winnerPath: existing.filePath,
|
|
633
|
+
loserPath: prompt.filePath,
|
|
634
|
+
},
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
seen.set(prompt.name, prompt);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return { prompts: Array.from(seen.values()), diagnostics };
|
|
642
|
+
}
|
|
643
|
+
dedupeThemes(themes) {
|
|
644
|
+
const seen = new Map();
|
|
645
|
+
const diagnostics = [];
|
|
646
|
+
for (const t of themes) {
|
|
647
|
+
const name = t.name ?? "unnamed";
|
|
648
|
+
const existing = seen.get(name);
|
|
649
|
+
if (existing) {
|
|
650
|
+
diagnostics.push({
|
|
651
|
+
type: "collision",
|
|
652
|
+
message: `name "${name}" collision`,
|
|
653
|
+
path: t.sourcePath,
|
|
654
|
+
collision: {
|
|
655
|
+
resourceType: "theme",
|
|
656
|
+
name,
|
|
657
|
+
winnerPath: existing.sourcePath ?? "<builtin>",
|
|
658
|
+
loserPath: t.sourcePath ?? "<builtin>",
|
|
659
|
+
},
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
else {
|
|
663
|
+
seen.set(name, t);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return { themes: Array.from(seen.values()), diagnostics };
|
|
667
|
+
}
|
|
668
|
+
discoverSystemPromptFile() {
|
|
669
|
+
const projectPath = join(this.cwd, CONFIG_DIR_NAME, "SYSTEM.md");
|
|
670
|
+
if (existsSync(projectPath)) {
|
|
671
|
+
return projectPath;
|
|
672
|
+
}
|
|
673
|
+
const globalPath = join(this.agentDir, "SYSTEM.md");
|
|
674
|
+
if (existsSync(globalPath)) {
|
|
675
|
+
return globalPath;
|
|
676
|
+
}
|
|
677
|
+
return undefined;
|
|
678
|
+
}
|
|
679
|
+
discoverAppendSystemPromptFile() {
|
|
680
|
+
const projectPath = join(this.cwd, CONFIG_DIR_NAME, "APPEND_SYSTEM.md");
|
|
681
|
+
if (existsSync(projectPath)) {
|
|
682
|
+
return projectPath;
|
|
683
|
+
}
|
|
684
|
+
const globalPath = join(this.agentDir, "APPEND_SYSTEM.md");
|
|
685
|
+
if (existsSync(globalPath)) {
|
|
686
|
+
return globalPath;
|
|
687
|
+
}
|
|
688
|
+
return undefined;
|
|
689
|
+
}
|
|
690
|
+
isUnderPath(target, root) {
|
|
691
|
+
const normalizedRoot = resolve(root);
|
|
692
|
+
if (target === normalizedRoot) {
|
|
693
|
+
return true;
|
|
694
|
+
}
|
|
695
|
+
const prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;
|
|
696
|
+
return target.startsWith(prefix);
|
|
697
|
+
}
|
|
698
|
+
detectExtensionConflicts(extensions) {
|
|
699
|
+
const conflicts = [];
|
|
700
|
+
// Track which extension registered each tool and flag
|
|
701
|
+
const toolOwners = new Map();
|
|
702
|
+
const flagOwners = new Map();
|
|
703
|
+
for (const ext of extensions) {
|
|
704
|
+
// Check tools
|
|
705
|
+
for (const toolName of ext.tools.keys()) {
|
|
706
|
+
const existingOwner = toolOwners.get(toolName);
|
|
707
|
+
if (existingOwner && existingOwner !== ext.path) {
|
|
708
|
+
conflicts.push({
|
|
709
|
+
path: ext.path,
|
|
710
|
+
message: `Tool "${toolName}" conflicts with ${existingOwner}`,
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
else {
|
|
714
|
+
toolOwners.set(toolName, ext.path);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
// Check flags
|
|
718
|
+
for (const flagName of ext.flags.keys()) {
|
|
719
|
+
const existingOwner = flagOwners.get(flagName);
|
|
720
|
+
if (existingOwner && existingOwner !== ext.path) {
|
|
721
|
+
conflicts.push({
|
|
722
|
+
path: ext.path,
|
|
723
|
+
message: `Flag "--${flagName}" conflicts with ${existingOwner}`,
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
else {
|
|
727
|
+
flagOwners.set(flagName, ext.path);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return conflicts;
|
|
732
|
+
}
|
|
733
|
+
}
|