Version: 1.1
Last Updated: 2025-12-14
Status: Official Framework Standard
Migration Notice: This document will migrate to SynkraAI/aiox-core repository in Q2 2026 (see Decision 005)
- Overview
- JavaScript/TypeScript Standards
- File Organization
- Naming Conventions
- Code Quality
- Documentation Standards
- Testing Standards
- Git Conventions
- Security Standards
This document defines the official coding standards for AIOX framework development. All code contributions must adhere to these standards to ensure consistency, maintainability, and quality.
Enforcement:
- ESLint (automated)
- Prettier (automated)
- CodeRabbit review (automated)
- Human review (manual)
// Target: ES2022 (Node.js 18+)
// TypeScript: 5.x
// ✅ GOOD: Modern syntax
const data = await fetchData();
const { id, name } = data;
// ❌ BAD: Outdated syntax
fetchData().then(function (data) {
var id = data.id;
var name = data.name;
});// tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"lib": ["ES2022"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"declaration": true,
"outDir": "./dist",
"rootDir": "./src"
}
}// ✅ GOOD: 2 spaces indentation
function processAgent(agent) {
if (agent.enabled) {
return loadAgent(agent);
}
return null;
}
// ❌ BAD: 4 spaces or tabs
function processAgent(agent) {
if (agent.enabled) {
return loadAgent(agent);
}
return null;
}Prettier Configuration:
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always"
}// ✅ GOOD: Max 100 characters
const result = await executeTask(taskName, taskArgs, { timeout: 5000, retry: 3 });
// ❌ BAD: Over 100 characters
const result = await executeTask(taskName, taskArgs, {
timeout: 5000,
retry: 3,
failureCallback: onFailure,
});// ✅ GOOD: Single quotes for strings
const agentName = 'developer';
const message = `Agent ${agentName} activated`;
// ❌ BAD: Double quotes (except JSON)
const agentName = 'developer';// ✅ GOOD: async/await
async function loadAgent(agentId) {
try {
const agent = await fetchAgent(agentId);
const config = await loadConfig(agent.configPath);
return { agent, config };
} catch (error) {
console.error(`Failed to load agent ${agentId}:`, error);
throw error;
}
}
// ❌ BAD: Promise chains
function loadAgent(agentId) {
return fetchAgent(agentId)
.then((agent) => loadConfig(agent.configPath).then((config) => ({ agent, config })))
.catch((error) => {
console.error(`Failed to load agent ${agentId}:`, error);
throw error;
});
}// ✅ GOOD: Destructuring
const { name, id, enabled } = agent;
const [first, second, ...rest] = items;
// ❌ BAD: Manual extraction
const name = agent.name;
const id = agent.id;
const enabled = agent.enabled;// ✅ GOOD: Arrow functions for callbacks
const activeAgents = agents.filter((agent) => agent.enabled);
const agentNames = agents.map((agent) => agent.name);
// ❌ BAD: Traditional functions for simple callbacks
const activeAgents = agents.filter(function (agent) {
return agent.enabled;
});// ✅ GOOD: Template literals for string interpolation
const message = `Agent ${agentName} loaded successfully`;
const path = `${baseDir}/${agentId}/config.yaml`;
// ❌ BAD: String concatenation
const message = 'Agent ' + agentName + ' loaded successfully';
const path = baseDir + '/' + agentId + '/config.yaml';// ✅ GOOD: Specific error handling with context
async function executeTask(taskName) {
try {
const task = await loadTask(taskName);
return await task.execute();
} catch (error) {
console.error(`Task execution failed [${taskName}]:`, error);
throw new Error(`Failed to execute task "${taskName}": ${error.message}`);
}
}
// ❌ BAD: Silent failures or generic errors
async function executeTask(taskName) {
try {
const task = await loadTask(taskName);
return await task.execute();
} catch (error) {
console.log('Error:', error);
return null; // Silent failure
}
}.aiox-core/
├── agents/ # Agent definitions (YAML + Markdown)
├── tasks/ # Task workflows (Markdown)
├── templates/ # Document templates (YAML/Markdown)
├── workflows/ # Multi-step workflows (YAML)
├── checklists/ # Validation checklists (Markdown)
├── data/ # Knowledge base (Markdown)
├── utils/ # Utility scripts (JavaScript)
├── tools/ # Tool integrations (YAML)
└── elicitation/ # Elicitation engines (JavaScript)
docs/
├── architecture/ # Project-specific architecture decisions
├── framework/ # Official framework docs (migrates to REPO 1)
├── stories/ # Development stories
├── epics/ # Epic planning
└── guides/ # How-to guides
// ✅ GOOD: Kebab-case for files
agent - executor.js;
task - runner.js;
greeting - builder.js;
context - detector.js;
// ❌ BAD: camelCase or PascalCase for files
agentExecutor.js;
TaskRunner.js;
GreetingBuilder.js;// ✅ GOOD: Clear module structure
// File: agent-executor.js
// 1. Imports
const fs = require('fs').promises;
const yaml = require('yaml');
const { loadConfig } = require('./config-loader');
// 2. Constants
const DEFAULT_TIMEOUT = 5000;
const MAX_RETRIES = 3;
// 3. Helper functions (private)
function validateAgent(agent) {
// ...
}
// 4. Main exports (public API)
async function executeAgent(agentId, args) {
// ...
}
async function loadAgent(agentId) {
// ...
}
// 5. Exports
module.exports = {
executeAgent,
loadAgent,
};// ✅ GOOD: camelCase for variables and functions
const agentName = 'developer';
const taskResult = await executeTask();
function loadAgentConfig(agentId) {
// ...
}
async function fetchAgentData(agentId) {
// ...
}
// ❌ BAD: snake_case or PascalCase
const agent_name = 'developer';
const TaskResult = await executeTask();
function LoadAgentConfig(agentId) {
// ...
}// ✅ GOOD: PascalCase for classes
class AgentExecutor {
constructor(config) {
this.config = config;
}
async execute(agentId) {
// ...
}
}
class TaskRunner {
// ...
}
// ❌ BAD: camelCase or snake_case
class agentExecutor {
// ...
}
class task_runner {
// ...
}// ✅ GOOD: SCREAMING_SNAKE_CASE for true constants
const MAX_RETRY_ATTEMPTS = 3;
const DEFAULT_TIMEOUT_MS = 5000;
const AGENT_STATUS_ACTIVE = 'active';
// ❌ BAD: camelCase or lowercase
const maxRetryAttempts = 3;
const defaulttimeout = 5000;// ✅ GOOD: Prefix with underscore for private (convention)
class AgentManager {
constructor() {
this._cache = new Map();
this._isInitialized = false;
}
_loadFromCache(id) {
// Private helper
return this._cache.get(id);
}
async getAgent(id) {
// Public API
return this._loadFromCache(id) || (await this._fetchAgent(id));
}
}// ✅ GOOD: is/has/should prefix
const isEnabled = true;
const hasPermission = false;
const shouldRetry = checkCondition();
// ❌ BAD: Ambiguous names
const enabled = true;
const permission = false;
const retry = checkCondition();{
"env": {
"node": true,
"es2022": true
},
"extends": ["eslint:recommended"],
"parserOptions": {
"ecmaVersion": 13,
"sourceType": "module"
},
"rules": {
"no-console": "off",
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"prefer-const": "error",
"no-var": "error",
"eqeqeq": ["error", "always"],
"curly": ["error", "all"],
"brace-style": ["error", "1tbs"],
"comma-dangle": ["error", "es5"],
"quotes": ["error", "single"],
"semi": ["error", "always"]
}
}// ✅ GOOD: Low cyclomatic complexity (< 10)
function processAgent(agent) {
if (!agent.enabled) return null;
const config = loadConfig(agent.configPath);
const result = executeAgent(agent, config);
return result;
}
// ❌ BAD: High cyclomatic complexity
function processAgent(agent) {
if (agent.type === 'dev') {
if (agent.mode === 'yolo') {
if (agent.hasStory) {
// ... nested logic
} else {
// ... more nested logic
}
} else {
// ... more branches
}
} else if (agent.type === 'qa') {
// ... more branches
}
// ... even more complexity
}Refactor complex functions:
// ✅ GOOD: Extracted helper functions
function processAgent(agent) {
if (!agent.enabled) return null;
if (agent.type === 'dev') {
return processDevAgent(agent);
}
if (agent.type === 'qa') {
return processQaAgent(agent);
}
return processDefaultAgent(agent);
}// ✅ GOOD: Reusable function
function validateAndLoad(filePath, schema) {
const content = fs.readFileSync(filePath, 'utf8');
const data = yaml.parse(content);
if (!schema.validate(data)) {
throw new Error(`Invalid schema: ${filePath}`);
}
return data;
}
const agent = validateAndLoad('agent.yaml', agentSchema);
const task = validateAndLoad('task.yaml', taskSchema);
// ❌ BAD: Repeated code
const agentContent = fs.readFileSync('agent.yaml', 'utf8');
const agentData = yaml.parse(agentContent);
if (!agentSchema.validate(agentData)) {
throw new Error('Invalid agent schema');
}
const taskContent = fs.readFileSync('task.yaml', 'utf8');
const taskData = yaml.parse(taskContent);
if (!taskSchema.validate(taskData)) {
throw new Error('Invalid task schema');
}/**
* Loads and executes an AIOX agent
*
* @param {string} agentId - Unique identifier for the agent
* @param {Object} args - Agent execution arguments
* @param {boolean} args.yoloMode - Enable autonomous mode
* @param {string} args.storyPath - Path to story file (optional)
* @param {number} [timeout=5000] - Execution timeout in milliseconds
* @returns {Promise<Object>} Agent execution result
* @throws {Error} If agent not found or execution fails
*
* @example
* const result = await executeAgent('dev', {
* yoloMode: true,
* storyPath: 'docs/stories/story-6.1.2.5.md'
* });
*/
async function executeAgent(agentId, args, timeout = 5000) {
// Implementation
}// ✅ GOOD: Explain WHY, not WHAT
// Cache agents to avoid re-parsing YAML on every activation (performance optimization)
const agentCache = new Map();
// Decision log required for yolo mode rollback (Story 6.1.2.6 requirement)
if (yoloMode) {
await createDecisionLog(storyId);
}
// ❌ BAD: Stating the obvious
// Create a new Map
const agentCache = new Map();
// If yolo mode is true
if (yoloMode) {
await createDecisionLog(storyId);
}Every module/directory should have a README.md:
# Agent Executor
**Purpose:** Loads and executes AIOX agents with configuration management.
## Usage
\`\`\`javascript
const { executeAgent } = require('./agent-executor');
const result = await executeAgent('dev', {
yoloMode: true,
storyPath: 'docs/stories/story-6.1.2.5.md'
});
\`\`\`
## API
- `executeAgent(agentId, args, timeout)` - Execute agent
- `loadAgent(agentId)` - Load agent configuration
## Dependencies
- `yaml` - YAML parsing
- `fs/promises` - File system operations# Unit tests
tests/unit/context-detector.test.js
tests/unit/git-config-detector.test.js
# Integration tests
tests/integration/contextual-greeting.test.js
tests/integration/workflow-navigation.test.js
# E2E tests
tests/e2e/agent-activation.test.js// ✅ GOOD: Descriptive test names with Given-When-Then
describe('ContextDetector', () => {
describe('detectSessionType', () => {
it('should return "new" when conversation history is empty', async () => {
// Given
const conversationHistory = [];
const sessionFile = null;
// When
const result = await detectSessionType(conversationHistory, sessionFile);
// Then
expect(result).toBe('new');
});
it('should return "workflow" when command pattern matches story_development', async () => {
// Given
const conversationHistory = [{ command: 'validate-story-draft' }, { command: 'develop' }];
// When
const result = await detectSessionType(conversationHistory, null);
// Then
expect(result).toBe('workflow');
});
});
});- Minimum: 80% for all new modules
- Target: 90% for core modules
- Critical: 100% for security/validation modules
# Run coverage
npm test -- --coverage
# Coverage thresholds in package.json
{
"jest": {
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
}
}# ✅ GOOD: Conventional Commits format
feat: implement contextual agent greeting system [Story 6.1.2.5]
fix: resolve git config cache invalidation issue [Story 6.1.2.5]
docs: update coding standards with TypeScript config
chore: update ESLint configuration
refactor: extract greeting builder into separate module
test: add unit tests for WorkflowNavigator
# ❌ BAD: Vague or non-descriptive
update files
fix bug
changes
wipFormat:
<type>: <description> [Story <id>]
<optional body>
<optional footer>
Types:
feat: New featurefix: Bug fixdocs: Documentation changeschore: Build/tooling changesrefactor: Code refactoring (no functional change)test: Test additions/modificationsperf: Performance improvementsstyle: Code style changes (formatting, etc.)
# ✅ GOOD: Descriptive branch names
feature/story-6.1.2.5-contextual-greeting
fix/git-config-cache-ttl
refactor/agent-executor-optimization
docs/update-coding-standards
# ❌ BAD: Vague branch names
update
fix
my-branch// ✅ GOOD: Validate all external inputs
function executeCommand(command) {
// Whitelist validation
const allowedCommands = ['help', 'develop', 'review', 'deploy'];
if (!allowedCommands.includes(command)) {
throw new Error(`Invalid command: ${command}`);
}
return runCommand(command);
}
// ❌ BAD: No validation
function executeCommand(command) {
return eval(command); // NEVER DO THIS
}// ✅ GOOD: Validate file paths
const path = require('path');
function loadFile(filePath) {
const basePath = path.resolve(__dirname, '.aiox-core');
const resolvedPath = path.resolve(basePath, filePath);
// Prevent directory traversal
if (!resolvedPath.startsWith(basePath)) {
throw new Error('Invalid file path');
}
return fs.readFile(resolvedPath, 'utf8');
}
// ❌ BAD: Direct path usage
function loadFile(filePath) {
return fs.readFile(filePath, 'utf8'); // Vulnerable to ../../../etc/passwd
}// ✅ GOOD: Use environment variables
const apiKey = process.env.CLICKUP_API_KEY;
if (!apiKey) {
throw new Error('CLICKUP_API_KEY environment variable not set');
}
// ❌ BAD: Hardcoded secrets
const apiKey = 'pk_12345678_abcdefgh'; // NEVER DO THIS# Regular security audits
npm audit
npm audit fix
# Use Snyk or similar for continuous monitoring# .husky/pre-commit
#!/bin/sh
npm run lint
npm run typecheck
npm test# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm test -- --coverage
- run: npm auditAll PRs automatically reviewed by CodeRabbit for:
- Code quality issues
- Security vulnerabilities
- Performance problems
- Best practice violations
- Test coverage gaps
| Version | Date | Changes | Author |
|---|---|---|---|
| 1.0 | 2025-01-15 | Initial coding standards document | Aria (architect) |
| 1.1 | 2025-12-14 | Updated migration notice to SynkraAI/aiox-core [Story 6.10] | Dex (dev) |
Related Documents:
This is an official AIOX framework standard. All code contributions must comply.