@animus-labs/cortex 0.2.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/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/budget-guard.d.ts +75 -0
- package/dist/budget-guard.d.ts.map +1 -0
- package/dist/budget-guard.js +142 -0
- package/dist/budget-guard.js.map +1 -0
- package/dist/compaction/compaction.d.ts +99 -0
- package/dist/compaction/compaction.d.ts.map +1 -0
- package/dist/compaction/compaction.js +302 -0
- package/dist/compaction/compaction.js.map +1 -0
- package/dist/compaction/failsafe.d.ts +57 -0
- package/dist/compaction/failsafe.d.ts.map +1 -0
- package/dist/compaction/failsafe.js +135 -0
- package/dist/compaction/failsafe.js.map +1 -0
- package/dist/compaction/index.d.ts +381 -0
- package/dist/compaction/index.d.ts.map +1 -0
- package/dist/compaction/index.js +979 -0
- package/dist/compaction/index.js.map +1 -0
- package/dist/compaction/microcompaction.d.ts +219 -0
- package/dist/compaction/microcompaction.d.ts.map +1 -0
- package/dist/compaction/microcompaction.js +536 -0
- package/dist/compaction/microcompaction.js.map +1 -0
- package/dist/compaction/observational/buffering.d.ts +225 -0
- package/dist/compaction/observational/buffering.d.ts.map +1 -0
- package/dist/compaction/observational/buffering.js +354 -0
- package/dist/compaction/observational/buffering.js.map +1 -0
- package/dist/compaction/observational/constants.d.ts +70 -0
- package/dist/compaction/observational/constants.d.ts.map +1 -0
- package/dist/compaction/observational/constants.js +507 -0
- package/dist/compaction/observational/constants.js.map +1 -0
- package/dist/compaction/observational/index.d.ts +219 -0
- package/dist/compaction/observational/index.d.ts.map +1 -0
- package/dist/compaction/observational/index.js +641 -0
- package/dist/compaction/observational/index.js.map +1 -0
- package/dist/compaction/observational/observer.d.ts +97 -0
- package/dist/compaction/observational/observer.d.ts.map +1 -0
- package/dist/compaction/observational/observer.js +424 -0
- package/dist/compaction/observational/observer.js.map +1 -0
- package/dist/compaction/observational/recall-tool.d.ts +27 -0
- package/dist/compaction/observational/recall-tool.d.ts.map +1 -0
- package/dist/compaction/observational/recall-tool.js +93 -0
- package/dist/compaction/observational/recall-tool.js.map +1 -0
- package/dist/compaction/observational/reflector.d.ts +94 -0
- package/dist/compaction/observational/reflector.d.ts.map +1 -0
- package/dist/compaction/observational/reflector.js +167 -0
- package/dist/compaction/observational/reflector.js.map +1 -0
- package/dist/compaction/observational/types.d.ts +271 -0
- package/dist/compaction/observational/types.d.ts.map +1 -0
- package/dist/compaction/observational/types.js +15 -0
- package/dist/compaction/observational/types.js.map +1 -0
- package/dist/context-manager.d.ts +134 -0
- package/dist/context-manager.d.ts.map +1 -0
- package/dist/context-manager.js +170 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/cortex-agent.d.ts +1020 -0
- package/dist/cortex-agent.d.ts.map +1 -0
- package/dist/cortex-agent.js +3589 -0
- package/dist/cortex-agent.js.map +1 -0
- package/dist/error-classifier.d.ts +48 -0
- package/dist/error-classifier.d.ts.map +1 -0
- package/dist/error-classifier.js +152 -0
- package/dist/error-classifier.js.map +1 -0
- package/dist/event-bridge.d.ts +166 -0
- package/dist/event-bridge.d.ts.map +1 -0
- package/dist/event-bridge.js +381 -0
- package/dist/event-bridge.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-client.d.ts +119 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +474 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/model-wrapper.d.ts +58 -0
- package/dist/model-wrapper.d.ts.map +1 -0
- package/dist/model-wrapper.js +86 -0
- package/dist/model-wrapper.js.map +1 -0
- package/dist/noop-logger.d.ts +4 -0
- package/dist/noop-logger.d.ts.map +1 -0
- package/dist/noop-logger.js +8 -0
- package/dist/noop-logger.js.map +1 -0
- package/dist/prompt-diagnostics.d.ts +47 -0
- package/dist/prompt-diagnostics.d.ts.map +1 -0
- package/dist/prompt-diagnostics.js +230 -0
- package/dist/prompt-diagnostics.js.map +1 -0
- package/dist/provider-manager.d.ts +224 -0
- package/dist/provider-manager.d.ts.map +1 -0
- package/dist/provider-manager.js +563 -0
- package/dist/provider-manager.js.map +1 -0
- package/dist/provider-registry.d.ts +115 -0
- package/dist/provider-registry.d.ts.map +1 -0
- package/dist/provider-registry.js +305 -0
- package/dist/provider-registry.js.map +1 -0
- package/dist/schema-converter.d.ts +20 -0
- package/dist/schema-converter.d.ts.map +1 -0
- package/dist/schema-converter.js +48 -0
- package/dist/schema-converter.js.map +1 -0
- package/dist/skill-preprocessor.d.ts +46 -0
- package/dist/skill-preprocessor.d.ts.map +1 -0
- package/dist/skill-preprocessor.js +237 -0
- package/dist/skill-preprocessor.js.map +1 -0
- package/dist/skill-registry.d.ts +107 -0
- package/dist/skill-registry.d.ts.map +1 -0
- package/dist/skill-registry.js +330 -0
- package/dist/skill-registry.js.map +1 -0
- package/dist/skill-tool.d.ts +54 -0
- package/dist/skill-tool.d.ts.map +1 -0
- package/dist/skill-tool.js +88 -0
- package/dist/skill-tool.js.map +1 -0
- package/dist/sub-agent-manager.d.ts +90 -0
- package/dist/sub-agent-manager.d.ts.map +1 -0
- package/dist/sub-agent-manager.js +192 -0
- package/dist/sub-agent-manager.js.map +1 -0
- package/dist/token-estimator.d.ts +23 -0
- package/dist/token-estimator.d.ts.map +1 -0
- package/dist/token-estimator.js +27 -0
- package/dist/token-estimator.js.map +1 -0
- package/dist/tool-contract.d.ts +68 -0
- package/dist/tool-contract.d.ts.map +1 -0
- package/dist/tool-contract.js +35 -0
- package/dist/tool-contract.js.map +1 -0
- package/dist/tool-result-persistence.d.ts +89 -0
- package/dist/tool-result-persistence.d.ts.map +1 -0
- package/dist/tool-result-persistence.js +152 -0
- package/dist/tool-result-persistence.js.map +1 -0
- package/dist/tools/bash/index.d.ts +71 -0
- package/dist/tools/bash/index.d.ts.map +1 -0
- package/dist/tools/bash/index.js +485 -0
- package/dist/tools/bash/index.js.map +1 -0
- package/dist/tools/bash/interactive.d.ts +47 -0
- package/dist/tools/bash/interactive.d.ts.map +1 -0
- package/dist/tools/bash/interactive.js +262 -0
- package/dist/tools/bash/interactive.js.map +1 -0
- package/dist/tools/bash/safety.d.ts +149 -0
- package/dist/tools/bash/safety.d.ts.map +1 -0
- package/dist/tools/bash/safety.js +1116 -0
- package/dist/tools/bash/safety.js.map +1 -0
- package/dist/tools/edit.d.ts +57 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +310 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/glob.d.ts +34 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +268 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +53 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +673 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +62 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +52 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/read.d.ts +43 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +459 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/runtime.d.ts +62 -0
- package/dist/tools/runtime.d.ts.map +1 -0
- package/dist/tools/runtime.js +116 -0
- package/dist/tools/runtime.js.map +1 -0
- package/dist/tools/shared/cwd-tracker.d.ts +32 -0
- package/dist/tools/shared/cwd-tracker.d.ts.map +1 -0
- package/dist/tools/shared/cwd-tracker.js +44 -0
- package/dist/tools/shared/cwd-tracker.js.map +1 -0
- package/dist/tools/shared/edit-history.d.ts +55 -0
- package/dist/tools/shared/edit-history.d.ts.map +1 -0
- package/dist/tools/shared/edit-history.js +72 -0
- package/dist/tools/shared/edit-history.js.map +1 -0
- package/dist/tools/shared/edit-matcher.d.ts +83 -0
- package/dist/tools/shared/edit-matcher.d.ts.map +1 -0
- package/dist/tools/shared/edit-matcher.js +359 -0
- package/dist/tools/shared/edit-matcher.js.map +1 -0
- package/dist/tools/shared/file-mutation-lock.d.ts +22 -0
- package/dist/tools/shared/file-mutation-lock.d.ts.map +1 -0
- package/dist/tools/shared/file-mutation-lock.js +35 -0
- package/dist/tools/shared/file-mutation-lock.js.map +1 -0
- package/dist/tools/shared/gitignore.d.ts +17 -0
- package/dist/tools/shared/gitignore.d.ts.map +1 -0
- package/dist/tools/shared/gitignore.js +59 -0
- package/dist/tools/shared/gitignore.js.map +1 -0
- package/dist/tools/shared/pdf-extractor.d.ts +96 -0
- package/dist/tools/shared/pdf-extractor.d.ts.map +1 -0
- package/dist/tools/shared/pdf-extractor.js +196 -0
- package/dist/tools/shared/pdf-extractor.js.map +1 -0
- package/dist/tools/shared/read-registry.d.ts +66 -0
- package/dist/tools/shared/read-registry.d.ts.map +1 -0
- package/dist/tools/shared/read-registry.js +65 -0
- package/dist/tools/shared/read-registry.js.map +1 -0
- package/dist/tools/shared/safe-env.d.ts +18 -0
- package/dist/tools/shared/safe-env.d.ts.map +1 -0
- package/dist/tools/shared/safe-env.js +70 -0
- package/dist/tools/shared/safe-env.js.map +1 -0
- package/dist/tools/sub-agent.d.ts +91 -0
- package/dist/tools/sub-agent.d.ts.map +1 -0
- package/dist/tools/sub-agent.js +89 -0
- package/dist/tools/sub-agent.js.map +1 -0
- package/dist/tools/task-output.d.ts +38 -0
- package/dist/tools/task-output.d.ts.map +1 -0
- package/dist/tools/task-output.js +186 -0
- package/dist/tools/task-output.js.map +1 -0
- package/dist/tools/tool-search/index.d.ts +40 -0
- package/dist/tools/tool-search/index.d.ts.map +1 -0
- package/dist/tools/tool-search/index.js +110 -0
- package/dist/tools/tool-search/index.js.map +1 -0
- package/dist/tools/tool-search/registry.d.ts +82 -0
- package/dist/tools/tool-search/registry.d.ts.map +1 -0
- package/dist/tools/tool-search/registry.js +238 -0
- package/dist/tools/tool-search/registry.js.map +1 -0
- package/dist/tools/undo-edit.d.ts +51 -0
- package/dist/tools/undo-edit.d.ts.map +1 -0
- package/dist/tools/undo-edit.js +231 -0
- package/dist/tools/undo-edit.js.map +1 -0
- package/dist/tools/web-fetch/cache.d.ts +49 -0
- package/dist/tools/web-fetch/cache.d.ts.map +1 -0
- package/dist/tools/web-fetch/cache.js +89 -0
- package/dist/tools/web-fetch/cache.js.map +1 -0
- package/dist/tools/web-fetch/index.d.ts +53 -0
- package/dist/tools/web-fetch/index.d.ts.map +1 -0
- package/dist/tools/web-fetch/index.js +513 -0
- package/dist/tools/web-fetch/index.js.map +1 -0
- package/dist/tools/write.d.ts +59 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +316 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +881 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/dist/working-tags.d.ts +44 -0
- package/dist/working-tags.d.ts.map +1 -0
- package/dist/working-tags.js +103 -0
- package/dist/working-tags.js.map +1 -0
- package/package.json +87 -0
- package/src/budget-guard.ts +170 -0
- package/src/compaction/compaction.ts +386 -0
- package/src/compaction/failsafe.ts +185 -0
- package/src/compaction/index.ts +1199 -0
- package/src/compaction/microcompaction.ts +709 -0
- package/src/compaction/observational/buffering.ts +430 -0
- package/src/compaction/observational/constants.ts +532 -0
- package/src/compaction/observational/index.ts +837 -0
- package/src/compaction/observational/observer.ts +510 -0
- package/src/compaction/observational/recall-tool.ts +130 -0
- package/src/compaction/observational/reflector.ts +221 -0
- package/src/compaction/observational/types.ts +343 -0
- package/src/context-manager.ts +237 -0
- package/src/cortex-agent.ts +4297 -0
- package/src/error-classifier.ts +199 -0
- package/src/event-bridge.ts +508 -0
- package/src/index.ts +292 -0
- package/src/mcp-client.ts +582 -0
- package/src/model-wrapper.ts +128 -0
- package/src/noop-logger.ts +9 -0
- package/src/prompt-diagnostics.ts +296 -0
- package/src/provider-manager.ts +823 -0
- package/src/provider-registry.ts +386 -0
- package/src/schema-converter.ts +51 -0
- package/src/skill-preprocessor.ts +314 -0
- package/src/skill-registry.ts +378 -0
- package/src/skill-tool.ts +130 -0
- package/src/sub-agent-manager.ts +236 -0
- package/src/token-estimator.ts +26 -0
- package/src/tool-contract.ts +113 -0
- package/src/tool-result-persistence.ts +197 -0
- package/src/tools/bash/index.ts +633 -0
- package/src/tools/bash/interactive.ts +302 -0
- package/src/tools/bash/safety.ts +1297 -0
- package/src/tools/edit.ts +422 -0
- package/src/tools/glob.ts +330 -0
- package/src/tools/grep.ts +819 -0
- package/src/tools/index.ts +110 -0
- package/src/tools/read.ts +580 -0
- package/src/tools/runtime.ts +173 -0
- package/src/tools/shared/cwd-tracker.ts +50 -0
- package/src/tools/shared/edit-history.ts +96 -0
- package/src/tools/shared/edit-matcher.ts +457 -0
- package/src/tools/shared/file-mutation-lock.ts +40 -0
- package/src/tools/shared/gitignore.ts +61 -0
- package/src/tools/shared/pdf-extractor.ts +290 -0
- package/src/tools/shared/read-registry.ts +93 -0
- package/src/tools/shared/safe-env.ts +82 -0
- package/src/tools/sub-agent.ts +171 -0
- package/src/tools/task-output.ts +236 -0
- package/src/tools/tool-search/index.ts +167 -0
- package/src/tools/tool-search/registry.ts +278 -0
- package/src/tools/undo-edit.ts +314 -0
- package/src/tools/web-fetch/cache.ts +112 -0
- package/src/tools/web-fetch/index.ts +604 -0
- package/src/tools/write.ts +385 -0
- package/src/types.ts +1057 -0
- package/src/working-tags.ts +118 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill Preprocessor: processes SKILL.md body at load time.
|
|
3
|
+
*
|
|
4
|
+
* Three preprocessor types run in order:
|
|
5
|
+
* 1. Variable substitution: ${VAR}, $ARGUMENTS, $N
|
|
6
|
+
* 2. Shell commands: !`command` (parallel execution)
|
|
7
|
+
* 3. Script execution: !{script: path} (parallel execution)
|
|
8
|
+
*
|
|
9
|
+
* Shell commands use the same shell selection logic as the Bash tool
|
|
10
|
+
* (PowerShell on Windows, bash/zsh on Unix).
|
|
11
|
+
*
|
|
12
|
+
* References:
|
|
13
|
+
* - docs/cortex/skill-system.md
|
|
14
|
+
* - docs/cortex/cross-platform-considerations.md
|
|
15
|
+
*/
|
|
16
|
+
import { execFile } from 'node:child_process';
|
|
17
|
+
import * as fs from 'node:fs';
|
|
18
|
+
import * as path from 'node:path';
|
|
19
|
+
import { pathToFileURL } from 'node:url';
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Constants
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
/** Timeout for each shell command or script execution. */
|
|
24
|
+
const COMMAND_TIMEOUT_MS = 10_000;
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Regex patterns
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
/** Match !`command` patterns (shell command markers). */
|
|
29
|
+
const SHELL_COMMAND_PATTERN = /^!`([^`]+)`$/gm;
|
|
30
|
+
/** Match !{script: path} or !{script: path, key: value, ...} patterns. */
|
|
31
|
+
const SCRIPT_PATTERN = /^!\{script:\s*([^,}]+)(?:,\s*([^}]+))?\}$/gm;
|
|
32
|
+
/** Match ${VAR} variable references. */
|
|
33
|
+
const VARIABLE_PATTERN = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
34
|
+
/** Match $N positional argument references (1-9). */
|
|
35
|
+
const POSITIONAL_PATTERN = /\$([1-9])/g;
|
|
36
|
+
/** Match $ARGUMENTS reference. */
|
|
37
|
+
const ARGUMENTS_PATTERN = /\$ARGUMENTS/g;
|
|
38
|
+
function getShellConfig() {
|
|
39
|
+
if (process.platform === 'win32') {
|
|
40
|
+
// PowerShell on Windows
|
|
41
|
+
const psCore = process.env['ProgramFiles'];
|
|
42
|
+
const psCorePath = psCore ? `${psCore}\\PowerShell\\7\\pwsh.exe` : null;
|
|
43
|
+
// Try pwsh (PowerShell 7+) first, fall back to Windows PowerShell
|
|
44
|
+
try {
|
|
45
|
+
if (psCorePath) {
|
|
46
|
+
fs.accessSync(psCorePath);
|
|
47
|
+
return { shell: psCorePath, args: ['-NoProfile', '-NonInteractive', '-Command'] };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Fall through
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
shell: 'powershell.exe',
|
|
55
|
+
args: ['-NoProfile', '-NonInteractive', '-Command'],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// Unix: use $SHELL, falling back to /bin/bash or /bin/sh
|
|
59
|
+
const userShell = process.env['SHELL'];
|
|
60
|
+
if (userShell && !userShell.endsWith('/fish')) {
|
|
61
|
+
return { shell: userShell, args: ['-c'] };
|
|
62
|
+
}
|
|
63
|
+
// Fall back
|
|
64
|
+
try {
|
|
65
|
+
fs.accessSync('/bin/bash');
|
|
66
|
+
return { shell: '/bin/bash', args: ['-c'] };
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return { shell: '/bin/sh', args: ['-c'] };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// Preprocessor implementation
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
/**
|
|
76
|
+
* Preprocess a SKILL.md body. Runs all three stages:
|
|
77
|
+
* 1. Variable substitution
|
|
78
|
+
* 2. Shell commands and scripts (in parallel)
|
|
79
|
+
* 3. Assemble final content
|
|
80
|
+
*/
|
|
81
|
+
export async function preprocessSkillBody(body, config) {
|
|
82
|
+
// Stage 1: Variable substitution (runs first so vars are available
|
|
83
|
+
// inside shell commands and script arguments)
|
|
84
|
+
let content = substituteVariables(body, config.variables);
|
|
85
|
+
// Stage 2: Collect shell command and script markers, execute in parallel
|
|
86
|
+
const shellReplacements = [];
|
|
87
|
+
const scriptReplacements = [];
|
|
88
|
+
// Find shell commands
|
|
89
|
+
let match;
|
|
90
|
+
const shellRegex = new RegExp(SHELL_COMMAND_PATTERN.source, 'gm');
|
|
91
|
+
while ((match = shellRegex.exec(content)) !== null) {
|
|
92
|
+
const fullMatch = match[0];
|
|
93
|
+
const command = match[1];
|
|
94
|
+
shellReplacements.push({
|
|
95
|
+
marker: fullMatch,
|
|
96
|
+
promise: executeShellCommand(command, config.skillDir),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// Find scripts
|
|
100
|
+
const scriptRegex = new RegExp(SCRIPT_PATTERN.source, 'gm');
|
|
101
|
+
while ((match = scriptRegex.exec(content)) !== null) {
|
|
102
|
+
const fullMatch = match[0];
|
|
103
|
+
const scriptPath = match[1].trim();
|
|
104
|
+
const extraArgs = match[2]?.trim() ?? '';
|
|
105
|
+
scriptReplacements.push({
|
|
106
|
+
marker: fullMatch,
|
|
107
|
+
promise: executeScript(scriptPath, extraArgs, config),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// Execute all in parallel
|
|
111
|
+
const allReplacements = [...shellReplacements, ...scriptReplacements];
|
|
112
|
+
if (allReplacements.length > 0) {
|
|
113
|
+
const results = await Promise.allSettled(allReplacements.map(r => r.promise));
|
|
114
|
+
for (let i = 0; i < allReplacements.length; i++) {
|
|
115
|
+
const replacement = allReplacements[i];
|
|
116
|
+
const result = results[i];
|
|
117
|
+
const output = result.status === 'fulfilled'
|
|
118
|
+
? result.value
|
|
119
|
+
: `[Error: ${result.reason instanceof Error ? result.reason.message : String(result.reason)}]`;
|
|
120
|
+
// Use callback to prevent $& and other replacement patterns in output
|
|
121
|
+
content = content.replace(replacement.marker, () => output);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return content;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Substitute ${VAR}, $ARGUMENTS, and $N references with their values.
|
|
128
|
+
*/
|
|
129
|
+
export function substituteVariables(body, variables) {
|
|
130
|
+
let result = body;
|
|
131
|
+
// Replace $ARGUMENTS first (before ${} to avoid partial matching)
|
|
132
|
+
result = result.replace(ARGUMENTS_PATTERN, () => variables['ARGUMENTS'] ?? '');
|
|
133
|
+
// Replace positional $1..$9
|
|
134
|
+
result = result.replace(POSITIONAL_PATTERN, (_match, num) => {
|
|
135
|
+
return variables[num] ?? '';
|
|
136
|
+
});
|
|
137
|
+
// Replace ${VAR} references
|
|
138
|
+
result = result.replace(VARIABLE_PATTERN, (_match, varName) => {
|
|
139
|
+
return variables[varName] ?? '';
|
|
140
|
+
});
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Execute a shell command and return stdout.
|
|
145
|
+
* Uses the same shell selection as the Bash tool.
|
|
146
|
+
*/
|
|
147
|
+
export function executeShellCommand(command, cwd) {
|
|
148
|
+
return new Promise((resolve) => {
|
|
149
|
+
const shellConfig = getShellConfig();
|
|
150
|
+
// Use execFile to invoke the shell directly with the command as an argument.
|
|
151
|
+
// This avoids double-shell invocation (exec spawns a shell around our shell).
|
|
152
|
+
const args = [...shellConfig.args, command];
|
|
153
|
+
const child = execFile(shellConfig.shell, args, {
|
|
154
|
+
cwd,
|
|
155
|
+
timeout: COMMAND_TIMEOUT_MS,
|
|
156
|
+
maxBuffer: 1024 * 1024, // 1MB
|
|
157
|
+
env: process.env,
|
|
158
|
+
}, (error, stdout, _stderr) => {
|
|
159
|
+
if (error) {
|
|
160
|
+
if ('killed' in error && error.killed) {
|
|
161
|
+
resolve('[Error: command timed out]');
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
const exitCode = 'code' in error && error['code'] != null
|
|
165
|
+
? error['code']
|
|
166
|
+
: 'unknown';
|
|
167
|
+
resolve(`[Error: command failed with exit code ${exitCode}]`);
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
resolve(stdout.trim());
|
|
172
|
+
});
|
|
173
|
+
child.on('error', () => {
|
|
174
|
+
resolve('[Error: failed to execute command]');
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Execute a JavaScript script and return its output.
|
|
180
|
+
* Scripts are loaded via dynamic import() and must export a default
|
|
181
|
+
* async function.
|
|
182
|
+
*/
|
|
183
|
+
export async function executeScript(scriptPath, extraArgsStr, config) {
|
|
184
|
+
const absolutePath = path.isAbsolute(scriptPath)
|
|
185
|
+
? scriptPath
|
|
186
|
+
: path.resolve(config.skillDir, scriptPath);
|
|
187
|
+
// Security: reject paths that escape the skill directory
|
|
188
|
+
const relative = path.relative(config.skillDir, absolutePath);
|
|
189
|
+
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
190
|
+
return '[Error: script path must be within the skill directory]';
|
|
191
|
+
}
|
|
192
|
+
// Parse extra args from "key: value, key2: value2" format
|
|
193
|
+
const scriptArgs = {};
|
|
194
|
+
if (extraArgsStr) {
|
|
195
|
+
const pairs = extraArgsStr.split(',');
|
|
196
|
+
for (const pair of pairs) {
|
|
197
|
+
const colonIdx = pair.indexOf(':');
|
|
198
|
+
if (colonIdx > 0) {
|
|
199
|
+
const key = pair.substring(0, colonIdx).trim();
|
|
200
|
+
const value = pair.substring(colonIdx + 1).trim();
|
|
201
|
+
scriptArgs[key] = value;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Build context: consumer context spread first, then Cortex built-ins
|
|
206
|
+
// override (skillDir and scriptArgs are Cortex-owned and cannot be
|
|
207
|
+
// overridden by consumer). args/rawArgs come pre-merged in
|
|
208
|
+
// config.scriptContext from the registry with the same precedence.
|
|
209
|
+
const ctx = {
|
|
210
|
+
...config.scriptContext,
|
|
211
|
+
skillDir: config.skillDir,
|
|
212
|
+
scriptArgs,
|
|
213
|
+
};
|
|
214
|
+
// Execute with timeout
|
|
215
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
216
|
+
setTimeout(() => resolve('[Error: script timed out]'), COMMAND_TIMEOUT_MS);
|
|
217
|
+
});
|
|
218
|
+
const executionPromise = (async () => {
|
|
219
|
+
try {
|
|
220
|
+
// Dynamic import of the script file
|
|
221
|
+
const fileUrl = pathToFileURL(absolutePath).href;
|
|
222
|
+
const mod = await import(fileUrl);
|
|
223
|
+
const fn = mod.default ?? mod;
|
|
224
|
+
if (typeof fn !== 'function') {
|
|
225
|
+
return '[Error: script does not export a function]';
|
|
226
|
+
}
|
|
227
|
+
const result = await fn(ctx);
|
|
228
|
+
return typeof result === 'string' ? result : String(result ?? '');
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
232
|
+
return `[Error: script failed: ${message}]`;
|
|
233
|
+
}
|
|
234
|
+
})();
|
|
235
|
+
return Promise.race([executionPromise, timeoutPromise]);
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=skill-preprocessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-preprocessor.js","sourceRoot":"","sources":["../src/skill-preprocessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAezC,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,0DAA0D;AAC1D,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,yDAAyD;AACzD,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAE/C,0EAA0E;AAC1E,MAAM,cAAc,GAAG,6CAA6C,CAAC;AAErE,wCAAwC;AACxC,MAAM,gBAAgB,GAAG,iCAAiC,CAAC;AAE3D,qDAAqD;AACrD,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAExC,kCAAkC;AAClC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAWzC,SAAS,cAAc;IACrB,IAAI,OAAO,CAAC,QAAQ,K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AAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO,0BAA0B,OAAO,GAAG,CAAC;QAC9C,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillRegistry: manages all known skills for the Cortex agent.
|
|
3
|
+
*
|
|
4
|
+
* Config-driven: the consumer provides paths to SKILL.md files from any
|
|
5
|
+
* source (plugins, user directories, built-ins). The registry does not
|
|
6
|
+
* scan directories.
|
|
7
|
+
*
|
|
8
|
+
* Skills are parsed at registration time (frontmatter extracted, body
|
|
9
|
+
* deferred to load time). The registry produces a compact summary for
|
|
10
|
+
* the load_skill tool description.
|
|
11
|
+
*
|
|
12
|
+
* References:
|
|
13
|
+
* - docs/cortex/skill-system.md
|
|
14
|
+
* - docs/cortex/plans/phase-4-sub-agents-and-skills.md
|
|
15
|
+
*/
|
|
16
|
+
import type { SkillConfig, SkillEntry } from './types.js';
|
|
17
|
+
/**
|
|
18
|
+
* Parse YAML frontmatter from a SKILL.md file.
|
|
19
|
+
* Expects --- delimited frontmatter at the start of the file.
|
|
20
|
+
*
|
|
21
|
+
* This is a lightweight parser that handles the common SKILL.md patterns
|
|
22
|
+
* without requiring a full YAML library. It handles:
|
|
23
|
+
* - Simple key: value pairs
|
|
24
|
+
* - Multi-line strings (using > or |)
|
|
25
|
+
* - Nested metadata maps
|
|
26
|
+
* - Space-delimited lists (for allowed-tools)
|
|
27
|
+
*/
|
|
28
|
+
declare function parseFrontmatter(content: string): {
|
|
29
|
+
frontmatter: Record<string, unknown>;
|
|
30
|
+
body: string;
|
|
31
|
+
};
|
|
32
|
+
export declare class SkillRegistry {
|
|
33
|
+
private readonly entries;
|
|
34
|
+
/** Consumer-provided variables for ${VAR} substitution. */
|
|
35
|
+
private preprocessorVariables;
|
|
36
|
+
/** Consumer-provided context for !{script:} executions. */
|
|
37
|
+
private scriptContext;
|
|
38
|
+
/**
|
|
39
|
+
* Callback fired when skills are added or removed.
|
|
40
|
+
* CortexAgent sets this to rebuild the load_skill tool description.
|
|
41
|
+
*/
|
|
42
|
+
onChange: (() => void) | null;
|
|
43
|
+
constructor(configs?: SkillConfig[]);
|
|
44
|
+
/**
|
|
45
|
+
* Add a skill from a SKILL.md file path.
|
|
46
|
+
* Reads and parses the frontmatter synchronously at registration time.
|
|
47
|
+
*
|
|
48
|
+
* If a skill with the same name already exists, the new one replaces it
|
|
49
|
+
* (last-registered wins).
|
|
50
|
+
*/
|
|
51
|
+
addSkill(config: SkillConfig): void;
|
|
52
|
+
/**
|
|
53
|
+
* Remove a skill by name.
|
|
54
|
+
*/
|
|
55
|
+
removeSkill(name: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Get a skill entry by name.
|
|
58
|
+
*/
|
|
59
|
+
getEntry(name: string): SkillEntry | null;
|
|
60
|
+
/**
|
|
61
|
+
* Get all registered skill entries.
|
|
62
|
+
*/
|
|
63
|
+
getAll(): SkillEntry[];
|
|
64
|
+
/**
|
|
65
|
+
* Get the number of registered skills.
|
|
66
|
+
*/
|
|
67
|
+
get size(): number;
|
|
68
|
+
/**
|
|
69
|
+
* Generate the available skills summary for the load_skill tool description.
|
|
70
|
+
*
|
|
71
|
+
* Skills with disable-model-invocation: true (modelInvocable: false) are
|
|
72
|
+
* excluded from the summary. The agent cannot see or auto-load them.
|
|
73
|
+
*
|
|
74
|
+
* Format: XML listing with name, source, and description per skill.
|
|
75
|
+
* Each skill consumes approximately 100 tokens.
|
|
76
|
+
*/
|
|
77
|
+
getAvailableSkillsSummary(maxTokens?: number): string;
|
|
78
|
+
/**
|
|
79
|
+
* Read and preprocess a skill's full body content.
|
|
80
|
+
* Runs variable substitution, shell commands, and scripts.
|
|
81
|
+
*
|
|
82
|
+
* @param name - The skill name
|
|
83
|
+
* @param callArgs - Arguments from the load_skill tool call
|
|
84
|
+
* @returns The preprocessed skill body
|
|
85
|
+
* @throws Error if the skill is not found
|
|
86
|
+
*/
|
|
87
|
+
getSkillBody(name: string, callArgs: {
|
|
88
|
+
args: string[];
|
|
89
|
+
rawArgs: string;
|
|
90
|
+
}): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Set consumer-provided variables for ${VAR} substitution.
|
|
93
|
+
* Called each tick during GATHER to update runtime values.
|
|
94
|
+
*/
|
|
95
|
+
setPreprocessorVariables(variables: Record<string, string>): void;
|
|
96
|
+
/**
|
|
97
|
+
* Set consumer-provided context for !{script:} executions.
|
|
98
|
+
* Called each tick during GATHER to update runtime values.
|
|
99
|
+
*/
|
|
100
|
+
setScriptContext(context: Record<string, unknown>): void;
|
|
101
|
+
/**
|
|
102
|
+
* Clear all entries. Called during destroy.
|
|
103
|
+
*/
|
|
104
|
+
clear(): void;
|
|
105
|
+
}
|
|
106
|
+
export { parseFrontmatter };
|
|
107
|
+
//# sourceMappingURL=skill-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill-registry.d.ts","sourceRoot":"","sources":["../src/skill-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAO1D;;;;;;;;;;GAUG;AACH,iBAAS,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA6FjG;AAMD,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IAEzD,2DAA2D;IAC3D,OAAO,CAAC,qBAAqB,CAA8B;IAE3D,2DAA2D;IAC3D,OAAO,CAAC,aAAa,CAA+B;IAEpD;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