codeaura-embedded-runtime-agent 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/.env.example +4 -0
- package/.eslintignore +3 -0
- package/.eslintrc +97 -0
- package/CLAUDE.md +210 -0
- package/README.md +234 -0
- package/code_aura_embedded_runtime_agent_v_1_implementation_guide.md +253 -0
- package/index.js +2 -0
- package/package.json +37 -0
- package/src/agent/Agent.js +224 -0
- package/src/config/config.js +261 -0
- package/src/core/buffer/memoryBuffer.js +164 -0
- package/src/core/events/EventSchema.js +171 -0
- package/src/core/transport/httpTransport.js +242 -0
- package/src/framework/nodejs/sails/SailsAdapter.js +83 -0
- package/src/framework/nodejs/sails/sailsHook.js +248 -0
- package/src/instrumentation/nodejs/instrumentHelperTree.js +31 -0
- package/src/instrumentation/nodejs/wrappers/createEvent.js +111 -0
- package/src/instrumentation/nodejs/wrappers/handleAsyncFunction.js +39 -0
- package/src/instrumentation/nodejs/wrappers/index.js +12 -0
- package/src/instrumentation/nodejs/wrappers/wrapController.js +42 -0
- package/src/instrumentation/nodejs/wrappers/wrapFunction.js +108 -0
- package/src/instrumentation/nodejs/wrappers/wrapHelper.js +86 -0
- package/src/utils/executionContext.js +42 -0
- package/src/utils/logger.js +150 -0
- package/src/utils/publicApiClient.js +87 -0
- package/src/utils/sanitizeInputs.js +85 -0
package/.env.example
ADDED
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
// ╔═╗╔═╗╦ ╦╔╗╔╔╦╗┬─┐┌─┐
|
|
3
|
+
// ║╣ ╚═╗║ ║║║║ ║ ├┬┘│
|
|
4
|
+
// o╚═╝╚═╝╩═╝╩╝╚╝ ╩ ┴└─└─┘
|
|
5
|
+
// A set of basic code conventions designed to encourage quality and consistency
|
|
6
|
+
// across your CodeAura Embedded Runtime Agent code base. These rules are checked
|
|
7
|
+
// automatically any time you run `npm test`.
|
|
8
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
9
|
+
// For more information about any of the rules below, check out the relevant
|
|
10
|
+
// reference page on eslint.org. For example, to get details on "no-sequences",
|
|
11
|
+
// you would visit `http://eslint.org/docs/rules/no-sequences`.
|
|
12
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
13
|
+
|
|
14
|
+
"env": {
|
|
15
|
+
"node" : true,
|
|
16
|
+
"es6" : true
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
"parserOptions": {
|
|
20
|
+
"ecmaVersion": 2022,
|
|
21
|
+
"sourceType": "module"
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
"globals": {
|
|
25
|
+
"Promise": true
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
"rules": {
|
|
29
|
+
"strict": 1,
|
|
30
|
+
"block-scoped-var": ["error"],
|
|
31
|
+
"callback-return": ["error", ["done", "proceed", "next", "onwards", "callback", "cb"]],
|
|
32
|
+
"camelcase": ["warn", {"properties":"never"}],
|
|
33
|
+
"comma-style": ["warn", "last"],
|
|
34
|
+
"curly": ["warn"],
|
|
35
|
+
"eqeqeq": ["off"],
|
|
36
|
+
"eol-last": ["off"],
|
|
37
|
+
"handle-callback-err": ["error"],
|
|
38
|
+
"indent": ["warn", 4, {
|
|
39
|
+
"SwitchCase": 1,
|
|
40
|
+
"MemberExpression": "off",
|
|
41
|
+
"FunctionDeclaration": {"body":1, "parameters":"off"},
|
|
42
|
+
"FunctionExpression": {"body":1, "parameters":"off"},
|
|
43
|
+
"CallExpression": {"arguments":"off"},
|
|
44
|
+
"ArrayExpression": 1,
|
|
45
|
+
"ObjectExpression": 1,
|
|
46
|
+
"ignoredNodes": ["ConditionalExpression"]
|
|
47
|
+
}],
|
|
48
|
+
"no-dupe-keys": ["error"],
|
|
49
|
+
"no-duplicate-case": ["error"],
|
|
50
|
+
"no-extra-semi": ["warn"],
|
|
51
|
+
"no-labels": ["error"],
|
|
52
|
+
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
|
|
53
|
+
"no-redeclare": ["warn"],
|
|
54
|
+
"no-return-assign": ["error", "always"],
|
|
55
|
+
"no-sequences": ["error"],
|
|
56
|
+
"no-trailing-spaces": ["warn"],
|
|
57
|
+
"no-undef": ["warn"],
|
|
58
|
+
"no-unexpected-multiline": ["warn"],
|
|
59
|
+
"no-unreachable": ["warn"],
|
|
60
|
+
"no-unused-vars": ["warn", {"caughtErrors":"all", "caughtErrorsIgnorePattern": "^unused($|[A-Z].*$)", "argsIgnorePattern": "^unused($|[A-Z].*$)", "varsIgnorePattern": "^unused($|[A-Z].*$)" }],
|
|
61
|
+
"no-use-before-define": ["error", {"functions":false}],
|
|
62
|
+
"one-var": ["warn", "always"],
|
|
63
|
+
"prefer-arrow-callback": ["warn", {"allowNamedFunctions":true}],
|
|
64
|
+
"quotes": ["warn", "double", {"avoidEscape":false, "allowTemplateLiterals":true}],
|
|
65
|
+
"semi": ["warn", "always"],
|
|
66
|
+
"semi-spacing": ["warn", {"before":false, "after":true}],
|
|
67
|
+
"semi-style": ["warn", "last"],
|
|
68
|
+
"comma-dangle": ["error", "never"],
|
|
69
|
+
"multiline-ternary": ["error", "always-multiline"],
|
|
70
|
+
"padding-line-between-statements": [
|
|
71
|
+
"warn",
|
|
72
|
+
// Newline BEFORE variable declarations (unless top of block)
|
|
73
|
+
{ "blankLine": "always", "prev": "*", "next": ["const", "let", "var"] },
|
|
74
|
+
|
|
75
|
+
// Allow grouped variable declarations
|
|
76
|
+
{ "blankLine": "any", "prev": ["const", "let", "var"], "next": ["const", "let", "var"] },
|
|
77
|
+
|
|
78
|
+
// Newline AFTER variable declarations
|
|
79
|
+
{ "blankLine": "always", "prev": ["const", "let", "var"], "next": "*" },
|
|
80
|
+
{ "blankLine": "always", "prev": "*", "next": "return" }
|
|
81
|
+
],
|
|
82
|
+
"brace-style": ["warn", "1tbs", {
|
|
83
|
+
"allowSingleLine": false
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"object-curly-newline": ["error", {
|
|
87
|
+
"multiline": true,
|
|
88
|
+
"consistent": true
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
"function-call-argument-newline": ["warn", "consistent"],
|
|
92
|
+
"space-before-blocks": "warn",
|
|
93
|
+
"no-multiple-empty-lines": ["error", {
|
|
94
|
+
"max": 1
|
|
95
|
+
}]
|
|
96
|
+
}
|
|
97
|
+
}
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Development Commands
|
|
6
|
+
|
|
7
|
+
### Core Development
|
|
8
|
+
- **Run tests**: `npm test`
|
|
9
|
+
- **Node.js version**: >=14.0.0 (specified in package.json engines)
|
|
10
|
+
|
|
11
|
+
### Local Development Setup
|
|
12
|
+
- Install as local dependency: `npm install /path/to/codeaura-embedded-runtime-agent`
|
|
13
|
+
- Integration with Sails.js application via `config/bootstrap.js`
|
|
14
|
+
- Set environment variable:
|
|
15
|
+
- `API_KEY` - Your CodeAura API key (required)
|
|
16
|
+
- The API endpoint is pre-configured in the agent (`https://api.codeaura.dev/api/v1/runtime-agent/events`)
|
|
17
|
+
|
|
18
|
+
## Architecture Overview
|
|
19
|
+
|
|
20
|
+
This is a lightweight runtime execution tracer for JavaScript applications, with initial support for Sails.js (Node.js). The agent captures real execution behavior from a running application and sends it to the CodeAura platform for analysis.
|
|
21
|
+
|
|
22
|
+
### Core Systems
|
|
23
|
+
|
|
24
|
+
**Module Organization (src/)**
|
|
25
|
+
- `agent/` - Main agent entry point and lifecycle management
|
|
26
|
+
- `instrumentation/` - Function wrapping and HTTP interception logic
|
|
27
|
+
- `framework/` - Framework-specific hooks (Sails.js in V1)
|
|
28
|
+
- `core/` - Universal event format, transport, and buffering
|
|
29
|
+
- `config/` - Agent configuration management
|
|
30
|
+
- `utils/` - Logging and utility functions
|
|
31
|
+
|
|
32
|
+
**Agent Architecture**
|
|
33
|
+
- **Agent** - Main entry point with singleton pattern
|
|
34
|
+
- **Config** - Configuration management with safe defaults and validation
|
|
35
|
+
- **Logger** - Internal logging that never crashes the host application
|
|
36
|
+
- **EventSchema** - Universal event format for all captured executions
|
|
37
|
+
- **Transport** - Event delivery via HTTP/HTTPS to CodeAura API
|
|
38
|
+
- **Buffer** - In-memory event buffering before transmission
|
|
39
|
+
|
|
40
|
+
**Runtime Instrumentation**
|
|
41
|
+
- Function wrapping for controllers and helpers
|
|
42
|
+
- HTTP request interception
|
|
43
|
+
- Real-time execution event capture
|
|
44
|
+
- Timing, metadata, and error recording
|
|
45
|
+
- Zero-impact on host application behavior
|
|
46
|
+
|
|
47
|
+
### Key Design Principles
|
|
48
|
+
|
|
49
|
+
**Non-Intrusive Operation**
|
|
50
|
+
- Agent must never crash the host application
|
|
51
|
+
- Minimal overhead (< 5% performance impact)
|
|
52
|
+
- No debuggers or breakpoints required
|
|
53
|
+
- No code modification needed in host application
|
|
54
|
+
|
|
55
|
+
**Extensibility for Future Versions**
|
|
56
|
+
- Modular design supports future frameworks (Express, NestJS, Fastify)
|
|
57
|
+
- Architecture ready for multi-language support (Python planned)
|
|
58
|
+
- Event format designed to evolve incrementally
|
|
59
|
+
|
|
60
|
+
### Naming Conventions
|
|
61
|
+
|
|
62
|
+
**Files and Directories**: camelCase (`functionWrapper.js`, `httpTransport.js`)
|
|
63
|
+
**JavaScript**: camelCase for variables/functions, snake_case for config keys
|
|
64
|
+
**Classes**: PascalCase (`Agent`, `Config`, `Logger`, `EventSchema`)
|
|
65
|
+
**Module Exports**: Singleton pattern where applicable
|
|
66
|
+
|
|
67
|
+
### Development Guidelines
|
|
68
|
+
|
|
69
|
+
**Module Development**
|
|
70
|
+
- Follow singleton pattern for core services (Agent, Logger)
|
|
71
|
+
- Use class-based architecture for main components
|
|
72
|
+
- Implement proper error handling that never crashes host app
|
|
73
|
+
- Include comprehensive JSDoc documentation
|
|
74
|
+
- Keep V1 simple and focused - defer advanced features to future versions
|
|
75
|
+
|
|
76
|
+
**Error Handling**
|
|
77
|
+
- All errors must be caught and logged internally
|
|
78
|
+
- Never let agent errors propagate to host application
|
|
79
|
+
- Use try/catch in all critical paths
|
|
80
|
+
- Log errors with stack traces using `logger.errorWithStack()`
|
|
81
|
+
|
|
82
|
+
**Configuration Management**
|
|
83
|
+
- Provide safe defaults for all settings
|
|
84
|
+
- Support environment variable overrides
|
|
85
|
+
- Validate configuration on initialization
|
|
86
|
+
- Merge user config with defaults safely
|
|
87
|
+
|
|
88
|
+
**Event Capture**
|
|
89
|
+
- Use minimal event format (V1)
|
|
90
|
+
- Include only essential metadata
|
|
91
|
+
- Keep event schema extensible for future versions
|
|
92
|
+
- Buffer events before transmission
|
|
93
|
+
|
|
94
|
+
### Key Dependencies
|
|
95
|
+
|
|
96
|
+
**Core Runtime**: Node.js >=14.0.0
|
|
97
|
+
**HTTP Client**: axios ^1.6.0
|
|
98
|
+
**Framework Support**: Sails.js (V1), more frameworks planned
|
|
99
|
+
**Transport**: HTTP/HTTPS to CodeAura API
|
|
100
|
+
|
|
101
|
+
When modifying this codebase, always follow the established patterns for non-intrusive instrumentation, singleton management, and defensive error handling. The architecture emphasizes simplicity, safety, and extensibility.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
## Code Style & Linting Rules
|
|
105
|
+
|
|
106
|
+
### ESLint Configuration
|
|
107
|
+
All generated code must comply with the following linting rules:
|
|
108
|
+
|
|
109
|
+
**Indentation & Formatting:**
|
|
110
|
+
- Use 4-space indentation (not 2 or tabs)
|
|
111
|
+
- Switch cases should be indented 1 level from switch statement
|
|
112
|
+
- Use "1tbs" brace style (opening brace on same line, closing brace on new line)
|
|
113
|
+
- No single-line blocks allowed - always use multiline format
|
|
114
|
+
- Add space before opening braces
|
|
115
|
+
|
|
116
|
+
**Variable Declarations:**
|
|
117
|
+
- Use `one-var` style - declare multiple variables with single `var`/`let`/`const`
|
|
118
|
+
- Add blank lines before and after variable declarations
|
|
119
|
+
- Group variable declarations together when possible
|
|
120
|
+
- Handle unused variables with `unused` prefix (e.g., `unusedErr`, `unusedData`)
|
|
121
|
+
- Always define the variables at the top, outside the try/catch block except for variables used for loops
|
|
122
|
+
- When defining the variables, set the values to null, or empty string, depending on the variable use - the initialization of the variable is always done within the try/catch block unless you are initializing to a constant
|
|
123
|
+
|
|
124
|
+
**Quotes & Semicolons:**
|
|
125
|
+
- Use double quotes for all strings
|
|
126
|
+
- Allow template literals when needed
|
|
127
|
+
- Always use semicolons at end of statements
|
|
128
|
+
- Add space after semicolons, no space before
|
|
129
|
+
- No trailing commas in objects/arrays
|
|
130
|
+
|
|
131
|
+
**Functions & Callbacks:**
|
|
132
|
+
- Use camelCase for function names (no underscores in properties)
|
|
133
|
+
- Prefer arrow functions but allow named functions
|
|
134
|
+
- Handle callback errors properly - use callback names: `done`, `proceed`, `next`, `onwards`, `callback`, `cb`
|
|
135
|
+
- Functions can be used before definition
|
|
136
|
+
|
|
137
|
+
**Control Flow:**
|
|
138
|
+
- Always use curly braces for if/else/for/while blocks
|
|
139
|
+
- Use multiline ternary operators when complex
|
|
140
|
+
- No return assignments
|
|
141
|
+
- No sequences (comma operator)
|
|
142
|
+
- Equality checks: `==` and `!=` are allowed (eqeqeq is off)
|
|
143
|
+
|
|
144
|
+
**Code Quality:**
|
|
145
|
+
- Use strict mode
|
|
146
|
+
- Block-scoped variables only
|
|
147
|
+
- No duplicate keys in objects
|
|
148
|
+
- No duplicate cases in switch statements
|
|
149
|
+
- No unreachable code
|
|
150
|
+
- No undefined variables (warnings only)
|
|
151
|
+
- No mixed spaces and tabs (smart-tabs allowed)
|
|
152
|
+
- No trailing spaces
|
|
153
|
+
- No extra semicolons
|
|
154
|
+
|
|
155
|
+
**Spacing & Layout:**
|
|
156
|
+
- Add blank line before return statements
|
|
157
|
+
- Add blank lines before and after variable declarations
|
|
158
|
+
- Consistent newlines in function call arguments
|
|
159
|
+
- Multiline object literals should have consistent newlines
|
|
160
|
+
- No unexpected multiline statements
|
|
161
|
+
|
|
162
|
+
**Error Handling:**
|
|
163
|
+
- Always handle callback errors
|
|
164
|
+
- Use proper callback return patterns
|
|
165
|
+
|
|
166
|
+
## Control Flow Rules
|
|
167
|
+
|
|
168
|
+
### Mandatory Else Conditions
|
|
169
|
+
**All `if` statements must have a corresponding `else` block** except if the `else` block is empty.
|
|
170
|
+
|
|
171
|
+
## Module Development Rules
|
|
172
|
+
|
|
173
|
+
### Avoid use of inline and nested functions
|
|
174
|
+
Avoid using inline or nested functions in modules unless absolutely necessary. Any such occurrences should instead be replaced by the creation of utility helpers or separate module functions.
|
|
175
|
+
|
|
176
|
+
### Single Responsibility Modules
|
|
177
|
+
Modules should follow the Single Responsibility Principle by focusing on a single, well-defined task. However, avoid splitting functionality into excessively simplistic modules that reduce clarity or cohesion.
|
|
178
|
+
|
|
179
|
+
### Class-Based Components
|
|
180
|
+
For main components (Agent, Config, Logger, etc.), use class-based architecture with proper encapsulation and clear public APIs.
|
|
181
|
+
|
|
182
|
+
## Additional instructions
|
|
183
|
+
- Avoid adding inline comments in the code
|
|
184
|
+
- For all try/catch blocks, in the catch blocks, display the error with stack trace as `logger.errorWithStack(message, error);`
|
|
185
|
+
- Agent must never crash the host application - defensive error handling is critical
|
|
186
|
+
|
|
187
|
+
## Code Structure & Best Practices
|
|
188
|
+
|
|
189
|
+
### Variable Definition
|
|
190
|
+
- Always define all your variables at the start of the function outside the try/catch block.
|
|
191
|
+
- Initialize variables to null or empty values, then assign actual values inside try/catch.
|
|
192
|
+
|
|
193
|
+
### Singleton Pattern
|
|
194
|
+
- Use singleton pattern for core services (Agent, Logger)
|
|
195
|
+
- Export factory functions that manage singleton instances
|
|
196
|
+
- Provide both getInstance() and create new instance methods
|
|
197
|
+
|
|
198
|
+
### Defensive Programming
|
|
199
|
+
- Assume any operation can fail
|
|
200
|
+
- Wrap all critical sections in try/catch
|
|
201
|
+
- Log errors but never throw exceptions that could crash host app
|
|
202
|
+
- Validate all inputs and configuration
|
|
203
|
+
|
|
204
|
+
## V1 Scope and Limitations
|
|
205
|
+
|
|
206
|
+
This is Version 1 - a proof of concept focused on Sails.js support:
|
|
207
|
+
- Keep implementation simple and focused
|
|
208
|
+
- Defer advanced features (retries, persistence, multi-framework support) to future versions
|
|
209
|
+
- Prioritize stability and minimal overhead over feature completeness
|
|
210
|
+
- Document TODOs clearly for future enhancements
|
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# CodeAura Embedded Runtime Agent
|
|
2
|
+
|
|
3
|
+
> **Lightweight runtime execution tracer for JavaScript applications**
|
|
4
|
+
> *Initial support: Sails.js (Node.js)*
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 📌 Overview
|
|
9
|
+
|
|
10
|
+
**CodeAura Embedded Runtime Agent** is a lightweight runtime instrumentation agent designed to capture **real execution behavior** from a running JavaScript application and send it to the **CodeAura platform** for analysis, visualization, and documentation.
|
|
11
|
+
|
|
12
|
+
Unlike traditional debugging or profiling tools, the agent:
|
|
13
|
+
|
|
14
|
+
* works **without breakpoints or debuggers**
|
|
15
|
+
* runs **inside the application process**
|
|
16
|
+
* works even when the application and CodeAura run on **different servers**
|
|
17
|
+
|
|
18
|
+
The first version (V1) focuses on **Sails.js applications**, while being architected to support **other frameworks and languages in future versions**.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 🎯 Goals (V1)
|
|
23
|
+
|
|
24
|
+
The main objectives of this first version are:
|
|
25
|
+
|
|
26
|
+
* Capture **runtime execution events** from a real Sails.js application
|
|
27
|
+
* Observe how controllers and helpers are executed in production-like conditions
|
|
28
|
+
* Send structured execution events to the CodeAura API
|
|
29
|
+
* Prove that the approach is **technically viable, stable, and low-overhead**
|
|
30
|
+
|
|
31
|
+
This version is intentionally **simple and focused**.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 🚫 Non-goals (V1)
|
|
36
|
+
|
|
37
|
+
To keep the scope realistic, V1 **does not aim to**:
|
|
38
|
+
|
|
39
|
+
* Support multiple frameworks (Express, NestJS, Fastify, etc.)
|
|
40
|
+
* Support multiple languages (Python, Java, etc.)
|
|
41
|
+
* Perform deep database-level or infrastructure tracing
|
|
42
|
+
* Provide advanced retry, buffering, or persistence mechanisms
|
|
43
|
+
* Act as a full observability or APM solution
|
|
44
|
+
|
|
45
|
+
All of the above are planned for future versions.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 🧠 How It Works
|
|
50
|
+
|
|
51
|
+
At a high level:
|
|
52
|
+
|
|
53
|
+
1. The agent is installed as a Node.js dependency inside a Sails.js project
|
|
54
|
+
2. During application startup, the agent:
|
|
55
|
+
|
|
56
|
+
* hooks into the Sails lifecycle
|
|
57
|
+
* wraps selected runtime functions (controllers, helpers)
|
|
58
|
+
3. When the application runs normally:
|
|
59
|
+
|
|
60
|
+
* execution events are captured in real time
|
|
61
|
+
* timing, metadata, and errors are recorded
|
|
62
|
+
4. Events are sent via HTTP/HTTPS to the CodeAura API
|
|
63
|
+
|
|
64
|
+
No debugger, no code modification, no shared runtime required.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 🏗 High-Level Architecture
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
┌───────────────────────────┐
|
|
72
|
+
│ Sails.js Application │
|
|
73
|
+
│ │
|
|
74
|
+
│ ┌─────────────────────┐ │
|
|
75
|
+
│ │ Runtime Agent │ │
|
|
76
|
+
│ │ (installed module) │ │
|
|
77
|
+
│ └─────────────────────┘ │
|
|
78
|
+
│ │ │
|
|
79
|
+
│ ▼ │ HTTP/HTTPS
|
|
80
|
+
└─────────▶ Events ───────────────────▶ CodeAura API
|
|
81
|
+
(JSON)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 📦 Project Structure (V1)
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
codeaura-embedded-runtime-agent/
|
|
90
|
+
├── src/
|
|
91
|
+
│ ├── agent/
|
|
92
|
+
│ │ └── Agent.js # Main agent entry point
|
|
93
|
+
│ │
|
|
94
|
+
│ ├── instrumentation/
|
|
95
|
+
│ │ └── nodejs/
|
|
96
|
+
│ │ ├── functionWrapper.js # Function wrapping logic
|
|
97
|
+
│ │ └── httpInterceptor.js # HTTP request interception
|
|
98
|
+
│ │
|
|
99
|
+
│ ├── framework/
|
|
100
|
+
│ │ └── nodejs/
|
|
101
|
+
│ │ └── sails/
|
|
102
|
+
│ │ └── sailsHook.js # Sails.js-specific hook
|
|
103
|
+
│ │
|
|
104
|
+
│ ├── core/
|
|
105
|
+
│ │ ├── events/
|
|
106
|
+
│ │ │ └── EventSchema.js # Universal event format
|
|
107
|
+
│ │ ├── transport/
|
|
108
|
+
│ │ │ └── httpTransport.js # Event delivery
|
|
109
|
+
│ │ └── buffer/
|
|
110
|
+
│ │ └── memoryBuffer.js # In-memory buffering
|
|
111
|
+
│ │
|
|
112
|
+
│ ├── config/
|
|
113
|
+
│ │ └── config.js # Agent configuration
|
|
114
|
+
│ │
|
|
115
|
+
│ └── utils/
|
|
116
|
+
│ └── logger.js # Internal logging
|
|
117
|
+
│
|
|
118
|
+
├── README.md
|
|
119
|
+
└── package.json
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 📊 Event Format (V1)
|
|
125
|
+
|
|
126
|
+
Events are sent as simple JSON objects:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"type": "controller",
|
|
131
|
+
"name": "user/create",
|
|
132
|
+
"framework": "sailsjs",
|
|
133
|
+
"language": "nodejs",
|
|
134
|
+
"timestamp": "2026-01-07T12:45:02.501Z",
|
|
135
|
+
"durationMs": 12,
|
|
136
|
+
"meta": {
|
|
137
|
+
"route": "POST /user",
|
|
138
|
+
"status": 200
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
This format is intentionally minimal and will evolve over time.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## ⚙️ Installation
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
npm install codeaura-embedded-runtime-agent
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## 🔌 Integration with Sails.js
|
|
156
|
+
|
|
157
|
+
Add the agent initialization during the Sails bootstrap phase:
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
// config/bootstrap.js
|
|
161
|
+
module.exports.bootstrap = async function () {
|
|
162
|
+
require("codeaura-embedded-runtime-agent").init(sails);
|
|
163
|
+
};
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
That’s it.
|
|
167
|
+
No changes to controllers, helpers, or models are required.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 🛠 Configuration
|
|
172
|
+
|
|
173
|
+
The agent requires minimal configuration. You only need to provide your API key:
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
module.exports = {
|
|
177
|
+
apiKey: "YOUR_API_KEY"
|
|
178
|
+
};
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Or use environment variable:
|
|
182
|
+
```bash
|
|
183
|
+
export API_KEY="YOUR_API_KEY"
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Optional settings:
|
|
187
|
+
```js
|
|
188
|
+
module.exports = {
|
|
189
|
+
apiKey: "YOUR_API_KEY",
|
|
190
|
+
enabled: true // Set to false to disable the agent (default: true)
|
|
191
|
+
};
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Note:** The CodeAura API endpoint is pre-configured in the agent and does not need to be specified.
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## ⚠️ Performance & Safety
|
|
199
|
+
|
|
200
|
+
* The agent adds **minimal overhead** (typically < 5%)
|
|
201
|
+
* Events are buffered in memory before being sent
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 🧩 Extensibility & Future Support
|
|
206
|
+
|
|
207
|
+
Although V1 only supports **Sails.js on Node.js**, the architecture anticipates:
|
|
208
|
+
|
|
209
|
+
* Other Node.js frameworks (Express, NestJS, Fastify)
|
|
210
|
+
* Other languages (Python planned)
|
|
211
|
+
* Advanced buffering and retry strategies
|
|
212
|
+
* Security features (masking, anonymization)
|
|
213
|
+
* Deeper execution graphs and correlations
|
|
214
|
+
|
|
215
|
+
These will be introduced incrementally in future versions.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## ✅ Success Criteria (V1)
|
|
220
|
+
|
|
221
|
+
This version is considered successful if:
|
|
222
|
+
|
|
223
|
+
* A real Sails.js application can be instrumented
|
|
224
|
+
* Controllers and helpers are captured automatically
|
|
225
|
+
* Execution events reach CodeAura reliably
|
|
226
|
+
* The application behavior remains unchanged
|
|
227
|
+
* The codebase stays clean, readable, and maintainable
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## 📌 Status
|
|
232
|
+
|
|
233
|
+
**Version:** 0.1.0
|
|
234
|
+
**Status:** Proof of Concept (V1)
|