@agentrix/shared 2.2.4 → 2.2.6

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/dist/node.cjs ADDED
@@ -0,0 +1,254 @@
1
+ 'use strict';
2
+
3
+ var node_fs = require('node:fs');
4
+ var node_path = require('node:path');
5
+ var errors = require('./errors-myQvpVrM.cjs');
6
+ var os = require('node:os');
7
+ require('zod');
8
+
9
+ function _interopNamespaceDefault(e) {
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n.default = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
27
+
28
+ function validateAgentDirectory(agentDir) {
29
+ const errors = [];
30
+ const warnings = [];
31
+ if (!node_fs.existsSync(agentDir)) {
32
+ errors.push(`Agent directory does not exist: ${agentDir}`);
33
+ return { valid: false, errors, warnings };
34
+ }
35
+ if (!node_fs.statSync(agentDir).isDirectory()) {
36
+ errors.push(`Path is not a directory: ${agentDir}`);
37
+ return { valid: false, errors, warnings };
38
+ }
39
+ const agentJsonPath = node_path.join(agentDir, "agent.json");
40
+ if (!node_fs.existsSync(agentJsonPath)) {
41
+ errors.push("Missing required file: agent.json");
42
+ }
43
+ const readmePath = node_path.join(agentDir, "README.md");
44
+ if (!node_fs.existsSync(readmePath)) {
45
+ warnings.push("Missing README.md (recommended)");
46
+ }
47
+ return {
48
+ valid: errors.length === 0,
49
+ errors,
50
+ warnings
51
+ };
52
+ }
53
+ function validateFrameworkDirectory(frameworkDir, framework) {
54
+ const errors = [];
55
+ const warnings = [];
56
+ if (!node_fs.existsSync(frameworkDir)) {
57
+ errors.push(`Framework directory does not exist: ${frameworkDir}`);
58
+ return { valid: false, errors, warnings };
59
+ }
60
+ const configPath = node_path.join(frameworkDir, "config.json");
61
+ if (!node_fs.existsSync(configPath)) {
62
+ errors.push(`Missing required file: ${framework}/config.json`);
63
+ }
64
+ if (framework === "claude") {
65
+ const mcpServersDir = node_path.join(frameworkDir, "mcp-servers");
66
+ if (!node_fs.existsSync(mcpServersDir)) {
67
+ warnings.push("Missing mcp-servers directory (optional)");
68
+ }
69
+ const skillsDir = node_path.join(frameworkDir, "skills");
70
+ if (!node_fs.existsSync(skillsDir)) {
71
+ warnings.push("Missing skills directory (optional)");
72
+ }
73
+ }
74
+ return {
75
+ valid: errors.length === 0,
76
+ errors,
77
+ warnings
78
+ };
79
+ }
80
+ function assertFileExists(filePath, description) {
81
+ if (!node_fs.existsSync(filePath)) {
82
+ throw new errors.MissingAgentFileError(description || filePath);
83
+ }
84
+ }
85
+ function assertAgentExists(agentDir, agentId) {
86
+ if (!node_fs.existsSync(agentDir)) {
87
+ throw new errors.AgentNotFoundError(agentId);
88
+ }
89
+ }
90
+
91
+ function discoverPlugins(pluginsDir) {
92
+ if (!node_fs.existsSync(pluginsDir)) {
93
+ return [];
94
+ }
95
+ return node_fs.readdirSync(pluginsDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => node_path.join(pluginsDir, dirent.name)).filter((pluginPath) => isValidPluginDirectory(pluginPath));
96
+ }
97
+ function isValidPluginDirectory(pluginDir) {
98
+ const manifestPath = node_path.join(pluginDir, ".claude-plugin", "plugin.json");
99
+ return node_fs.existsSync(manifestPath);
100
+ }
101
+
102
+ async function loadAgentConfig(options) {
103
+ const { agentId, framework, validateOnly = false, agentDir: providedAgentDir } = options;
104
+ const agentContext = errors.getAgentContext();
105
+ const agentDir = providedAgentDir || agentContext.resolveAgentDir(agentId);
106
+ assertAgentExists(agentDir, agentId);
107
+ const validation = validateAgentDirectory(agentDir);
108
+ if (!validation.valid) {
109
+ throw new errors.AgentConfigValidationError(
110
+ `Agent directory validation failed for "${agentId}"`,
111
+ validation.errors
112
+ );
113
+ }
114
+ if (validation.warnings.length > 0) {
115
+ console.warn(`[AGENT] Warnings for agent "${agentId}":`, validation.warnings);
116
+ }
117
+ const metadata = await loadAgentMetadata(agentDir);
118
+ const frameworkDirName = framework === "claude" ? "claude" : `.${framework}`;
119
+ const frameworkDir = node_path.join(agentDir, frameworkDirName);
120
+ if (!node_fs.existsSync(frameworkDir)) {
121
+ throw new errors.FrameworkNotSupportedError(agentId, framework);
122
+ }
123
+ if (validateOnly) {
124
+ return {
125
+ metadata,
126
+ framework
127
+ };
128
+ }
129
+ if (framework === "claude") {
130
+ const claudeConfig = await loadClaudeConfiguration(agentDir);
131
+ return {
132
+ metadata,
133
+ framework,
134
+ claude: claudeConfig
135
+ };
136
+ }
137
+ throw new errors.AgentLoadError(`Framework "${framework}" loader not implemented`);
138
+ }
139
+ async function loadAgentMetadata(agentDir) {
140
+ const agentJsonPath = node_path.join(agentDir, "agent.json");
141
+ assertFileExists(agentJsonPath, "agent.json");
142
+ try {
143
+ const content = node_fs.readFileSync(agentJsonPath, "utf-8");
144
+ const rawData = JSON.parse(content);
145
+ const metadata = errors.AgentMetadataSchema.parse(rawData);
146
+ return metadata;
147
+ } catch (error) {
148
+ if (error instanceof SyntaxError) {
149
+ throw new errors.AgentConfigValidationError("Invalid JSON in agent.json");
150
+ }
151
+ throw new errors.AgentConfigValidationError(
152
+ `Invalid agent metadata: ${error instanceof Error ? error.message : String(error)}`
153
+ );
154
+ }
155
+ }
156
+ async function loadClaudeConfiguration(agentDir, metadata) {
157
+ const claudeDir = node_path.join(agentDir, "claude");
158
+ const validation = validateFrameworkDirectory(claudeDir, "claude");
159
+ if (!validation.valid) {
160
+ throw new errors.AgentConfigValidationError(
161
+ "Claude framework directory validation failed",
162
+ validation.errors
163
+ );
164
+ }
165
+ const config = await loadClaudeConfig(claudeDir);
166
+ let systemPrompt;
167
+ if (config.systemPrompt) {
168
+ systemPrompt = await loadSystemPrompt(claudeDir, config.systemPrompt.path);
169
+ }
170
+ let prPromptTemplate;
171
+ if (config.pullRequestPrompt) {
172
+ prPromptTemplate = await loadSystemPrompt(claudeDir, config.pullRequestPrompt.path);
173
+ }
174
+ const pluginsDir = node_path.join(claudeDir, "plugins");
175
+ const plugins = discoverPlugins(pluginsDir);
176
+ return {
177
+ config,
178
+ systemPrompt,
179
+ prPromptTemplate,
180
+ plugins
181
+ };
182
+ }
183
+ async function loadClaudeConfig(claudeDir) {
184
+ const configPath = node_path.join(claudeDir, "config.json");
185
+ assertFileExists(configPath, "claude/config.json");
186
+ try {
187
+ const content = node_fs.readFileSync(configPath, "utf-8");
188
+ const rawConfig = JSON.parse(content);
189
+ const config = errors.ClaudeConfigSchema.parse(rawConfig);
190
+ return config;
191
+ } catch (error) {
192
+ if (error instanceof SyntaxError) {
193
+ throw new errors.AgentConfigValidationError(
194
+ "Invalid JSON in claude/config.json"
195
+ );
196
+ }
197
+ throw new errors.AgentConfigValidationError(
198
+ `Invalid Claude configuration: ${error instanceof Error ? error.message : String(error)}`
199
+ );
200
+ }
201
+ }
202
+ async function loadSystemPrompt(claudeDir, promptFile) {
203
+ const promptPath = node_path.join(claudeDir, promptFile);
204
+ if (!node_fs.existsSync(promptPath)) {
205
+ throw new errors.MissingAgentFileError(`claude/${promptFile}`);
206
+ }
207
+ try {
208
+ return node_fs.readFileSync(promptPath, "utf-8");
209
+ } catch (error) {
210
+ throw new errors.AgentLoadError(
211
+ `Failed to read system prompt: ${error instanceof Error ? error.message : String(error)}`
212
+ );
213
+ }
214
+ }
215
+ function replacePromptPlaceholders(template, cwd, extra) {
216
+ const vars = {
217
+ WORKING_DIR: cwd,
218
+ PLATFORM: process.platform,
219
+ OS_VERSION: `${os__namespace.type()} ${os__namespace.release()}`,
220
+ DATE: (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
221
+ ...extra
222
+ };
223
+ let result = template.replace(
224
+ /\{\{#if\s+(\w+)\s*(==|!=)\s*(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g,
225
+ (_match, key, op, expected, content) => {
226
+ const actual = vars[key] ?? "";
227
+ const matches = op === "==" ? actual === expected : actual !== expected;
228
+ return matches ? content : "";
229
+ }
230
+ );
231
+ for (const [key, value] of Object.entries(vars)) {
232
+ result = result.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), value);
233
+ }
234
+ return result;
235
+ }
236
+
237
+ exports.AgentConfigValidationError = errors.AgentConfigValidationError;
238
+ exports.AgentError = errors.AgentError;
239
+ exports.AgentLoadError = errors.AgentLoadError;
240
+ exports.AgentMetadataSchema = errors.AgentMetadataSchema;
241
+ exports.AgentNotFoundError = errors.AgentNotFoundError;
242
+ exports.ClaudeConfigSchema = errors.ClaudeConfigSchema;
243
+ exports.FRAMEWORK_TYPES = errors.FRAMEWORK_TYPES;
244
+ exports.FrameworkNotSupportedError = errors.FrameworkNotSupportedError;
245
+ exports.MissingAgentFileError = errors.MissingAgentFileError;
246
+ exports.getAgentContext = errors.getAgentContext;
247
+ exports.setAgentContext = errors.setAgentContext;
248
+ exports.assertAgentExists = assertAgentExists;
249
+ exports.assertFileExists = assertFileExists;
250
+ exports.discoverPlugins = discoverPlugins;
251
+ exports.loadAgentConfig = loadAgentConfig;
252
+ exports.replacePromptPlaceholders = replacePromptPlaceholders;
253
+ exports.validateAgentDirectory = validateAgentDirectory;
254
+ exports.validateFrameworkDirectory = validateFrameworkDirectory;
@@ -0,0 +1,52 @@
1
+ import { aT as LoadAgentOptions, b as AgentConfig, cH as ValidationResult, aD as FrameworkType } from './errors-BdwSwKpv.cjs';
2
+ export { c as AgentConfigValidationError, d as AgentContext, e as AgentError, f as AgentLoadError, g as AgentMetadata, h as AgentMetadataSchema, i as AgentNotFoundError, j as AgentrixContext, X as ClaudeAgentConfig, Y as ClaudeConfigSchema, au as FRAMEWORK_TYPES, aC as FrameworkNotSupportedError, aG as HookFactory, b3 as MissingAgentFileError, bn as RepositoryInitHookInput, d7 as getAgentContext, di as setAgentContext } from './errors-BdwSwKpv.cjs';
3
+ import '@anthropic-ai/claude-agent-sdk';
4
+ import 'zod';
5
+
6
+ /**
7
+ * Agent configuration loader - main entry point for loading agent configurations
8
+ */
9
+
10
+ declare function loadAgentConfig(options: LoadAgentOptions): Promise<AgentConfig>;
11
+ declare function replacePromptPlaceholders(template: string, cwd: string, extra?: Record<string, string>): string;
12
+
13
+ /**
14
+ * Agent directory structure and configuration validation
15
+ */
16
+
17
+ /**
18
+ * Validate that agent directory exists and has basic structure
19
+ */
20
+ declare function validateAgentDirectory(agentDir: string): ValidationResult;
21
+ /**
22
+ * Validate framework-specific directory structure
23
+ */
24
+ declare function validateFrameworkDirectory(frameworkDir: string, framework: FrameworkType): ValidationResult;
25
+ /**
26
+ * Assert that a file exists, throw error if not
27
+ */
28
+ declare function assertFileExists(filePath: string, description?: string): void;
29
+ /**
30
+ * Assert that agent directory exists
31
+ */
32
+ declare function assertAgentExists(agentDir: string, agentId: string): void;
33
+
34
+ /**
35
+ * Plugin loader for agent system
36
+ *
37
+ * Auto-discovers plugins in the plugins directory by looking for
38
+ * directories containing .claude-plugin/plugin.json manifest files.
39
+ * The SDK handles manifest parsing - we only need to verify existence.
40
+ */
41
+ /**
42
+ * Discover plugins in the plugins directory
43
+ *
44
+ * Scans the plugins directory for subdirectories containing valid plugin manifests
45
+ * (.claude-plugin/plugin.json). Returns absolute paths to valid plugin directories.
46
+ *
47
+ * @param pluginsDir - Path to claude/plugins/ directory
48
+ * @returns Array of absolute paths to valid plugin directories
49
+ */
50
+ declare function discoverPlugins(pluginsDir: string): string[];
51
+
52
+ export { AgentConfig, FrameworkType, LoadAgentOptions, ValidationResult, assertAgentExists, assertFileExists, discoverPlugins, loadAgentConfig, replacePromptPlaceholders, validateAgentDirectory, validateFrameworkDirectory };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentrix/shared",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "description": "Shared types and schemas for Agentrix projects",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",
@@ -8,6 +8,10 @@
8
8
  ".": {
9
9
  "types": "./dist/index.d.cts",
10
10
  "default": "./dist/index.cjs"
11
+ },
12
+ "./node": {
13
+ "types": "./dist/node.d.cts",
14
+ "default": "./dist/node.cjs"
11
15
  }
12
16
  },
13
17
  "scripts": {
@@ -17,7 +21,9 @@
17
21
  "dependencies": {
18
22
  "@anthropic-ai/claude-agent-sdk": "^0.2.31",
19
23
  "@anthropic-ai/sdk": "^0.71.2",
24
+ "@types/crypto-js": "^4.2.2",
20
25
  "base64-js": "^1.5.1",
26
+ "crypto-js": "^4.2.0",
21
27
  "tweetnacl": "^1.0.3",
22
28
  "zod": "^4.0.0"
23
29
  },