@bernierllc/braingrid-cli-wrapper
v0.1.1
Published
Type-safe wrapper for BrainGrid CLI
Downloads
97
Readme
@bernierllc/braingrid-cli-wrapper
Type-safe wrapper for the BrainGrid CLI that provides a clean, programmatic interface for interacting with BrainGrid projects, requirements, and tasks.
Overview
This package provides atomic utilities for interacting with the BrainGrid CLI in a type-safe manner. It wraps BrainGrid CLI commands with Zod schema validation, ensuring type safety and proper error handling.
Features
- Type-safe API: Full TypeScript support with Zod schema validation
- Error Handling: Custom error types with detailed error information
- CLI Integration: Seamless integration with BrainGrid CLI commands
- Schema Validation: Automatic validation of CLI responses using Zod schemas
- Minimal Dependencies: Only depends on
execaandzod
Installation
npm install @bernierllc/braingrid-cli-wrapperQuick Start
import { createIdea, listProjects, createTask } from '@bernierllc/braingrid-cli-wrapper';
// Create a new requirement (IDEA)
const requirement = await createIdea('Add OAuth2 authentication', 'proj-123');
console.log(`Created requirement ${requirement.id} with status ${requirement.status}`);
// List all projects
const projects = await listProjects();
console.log(`Found ${projects.length} projects`);
// Create a task under a requirement
const task = await createTask('req-456', {
title: 'Build login UI',
description: 'Create login form component',
tags: ['DEV', 'frontend'],
dependencies: ['task-100']
});
console.log(`Created task ${task.id}`);API Reference
Commands
createIdea(prompt: string, projectId?: string): Promise<BrainGridRequirement>
Creates a new requirement (IDEA) in BrainGrid.
Input:
prompt(string, required): Description of the requirement/ideaprojectId(string, optional): Project ID to associate with the requirement
Output:
- Returns a
BrainGridRequirementobject with:id: Requirement IDprojectId: Associated project IDtitle: Requirement titlestatus: Requirement status (IDEA, PLANNED, IN_PROGRESS, COMPLETED, CANCELLED, PAUSED)description: Optional descriptioncreatedAt: Optional creation timestampupdatedAt: Optional update timestamp
Example:
const req = await createIdea('Add user authentication system');
// { id: 'req-123', projectId: 'proj-456', title: 'Add user authentication system', status: 'IDEA' }listProjects(): Promise<BrainGridProject[]>
Lists all projects in BrainGrid.
Input: None
Output:
- Returns an array of
BrainGridProjectobjects with:id: Project IDname: Project namedescription: Optional project description
Example:
const projects = await listProjects();
// [{ id: 'proj-1', name: 'My Project', description: 'Project description' }]createTask(reqId: string, options: CreateTaskOptions): Promise<BrainGridTask>
Creates a task under a requirement.
Input:
reqId(string, required): Requirement IDoptions(CreateTaskOptions, required):title(string, required): Task titledescription(string, optional): Task descriptiontags(string[], optional): Task tagsdependencies(string[], optional): Task dependency IDs
Output:
- Returns a
BrainGridTaskobject with:id: Task IDreqId: Parent requirement IDtitle: Task titlestatus: Task status (TODO, READY, BLOCKED, IN_PROGRESS, COMPLETED, FAILED, PAUSED)description: Optional descriptiontags: Optional array of tagsdependencies: Optional array of dependency IDsassignedTo: Optional assignee IDcreatedAt: Optional creation timestampupdatedAt: Optional update timestampmetadata: Optional metadata object
Example:
const task = await createTask('req-123', {
title: 'Build login UI',
description: 'Create login form component',
tags: ['DEV', 'frontend'],
dependencies: ['task-100']
});
// { id: 'task-456', reqId: 'req-123', title: 'Build login UI', status: 'TODO', ... }listTasks(options?: ListTasksOptions): Promise<BrainGridTask[]>
Lists tasks with optional filters.
Input:
options(ListTasksOptions, optional):reqId(string, optional): Filter by requirement IDstatus(TaskStatus[], optional): Filter by status arraytags(string[], optional): Filter by tags array
Output:
- Returns an array of
BrainGridTaskobjects
Example:
// List all tasks
const allTasks = await listTasks();
// List tasks for a specific requirement
const reqTasks = await listTasks({ reqId: 'req-123' });
// List tasks by status
const inProgressTasks = await listTasks({ status: ['IN_PROGRESS'] });
// Combine filters
const filteredTasks = await listTasks({
reqId: 'req-123',
status: ['TODO', 'READY'],
tags: ['DEV']
});updateTaskStatus(taskId: string, options: UpdateTaskOptions): Promise<void>
Updates task status and metadata.
Input:
taskId(string, required): Task ID to updateoptions(UpdateTaskOptions, optional):status(TaskStatus, optional): New task statusassignedTo(string, optional): Assignee IDmetadata(Record<string, unknown>, optional): Metadata object
Output: Promise that resolves when update is complete
Example:
// Update task status
await updateTaskStatus('task-123', { status: 'IN_PROGRESS' });
// Update with assignee
await updateTaskStatus('task-123', {
status: 'IN_PROGRESS',
assignedTo: 'user-456'
});
// Update with metadata
await updateTaskStatus('task-123', {
status: 'IN_PROGRESS',
metadata: { progress: 50, notes: 'Half done' }
});Types
BrainGridProject
interface BrainGridProject {
id: string;
name: string;
description?: string;
}BrainGridRequirement
interface BrainGridRequirement {
id: string;
projectId: string;
title: string;
status: RequirementStatus;
description?: string;
createdAt?: string;
updatedAt?: string;
}BrainGridTask
interface BrainGridTask {
id: string;
reqId: string;
title: string;
status: TaskStatus;
description?: string;
tags?: string[];
dependencies?: string[];
assignedTo?: string;
createdAt?: string;
updatedAt?: string;
metadata?: Record<string, unknown>;
}RequirementStatus
type RequirementStatus = 'IDEA' | 'PLANNED' | 'IN_PROGRESS' | 'COMPLETED' | 'CANCELLED' | 'PAUSED';TaskStatus
type TaskStatus = 'TODO' | 'READY' | 'BLOCKED' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED' | 'PAUSED';Error Handling
The package throws BrainGridCliError when CLI commands fail:
class BrainGridCliError extends Error {
command: string;
exitCode: number;
stderr: string;
}Example:
import { createIdea, BrainGridCliError } from '@bernierllc/braingrid-cli-wrapper';
try {
const req = await createIdea('Test requirement');
} catch (error) {
if (error instanceof BrainGridCliError) {
console.error(`CLI command failed: ${error.command}`);
console.error(`Exit code: ${error.exitCode}`);
console.error(`Error output: ${error.stderr}`);
}
}Configuration
Environment Variables
BRAINGRID_CLI_PATH: Custom path to the BrainGrid CLI executable (defaults to'braingrid')
Example:
export BRAINGRID_CLI_PATH=/custom/path/braingridUsage Examples
Complete Workflow
import {
listProjects,
createIdea,
createTask,
listTasks,
updateTaskStatus
} from '@bernierllc/braingrid-cli-wrapper';
async function workflow() {
// 1. List projects
const projects = await listProjects();
const project = projects[0];
// 2. Create a requirement
const requirement = await createIdea(
'Build user authentication system',
project.id
);
// 3. Create tasks
const task1 = await createTask(requirement.id, {
title: 'Design authentication flow',
tags: ['DESIGN']
});
const task2 = await createTask(requirement.id, {
title: 'Implement login endpoint',
tags: ['DEV', 'backend'],
dependencies: [task1.id]
});
// 4. List tasks
const tasks = await listTasks({ reqId: requirement.id });
console.log(`Created ${tasks.length} tasks`);
// 5. Update task status
await updateTaskStatus(task1.id, { status: 'COMPLETED' });
await updateTaskStatus(task2.id, {
status: 'IN_PROGRESS',
assignedTo: 'user-123'
});
}Error Handling Example
import { createIdea, BrainGridCliError } from '@bernierllc/braingrid-cli-wrapper';
async function createRequirementSafely(prompt: string) {
try {
const req = await createIdea(prompt);
return req;
} catch (error) {
if (error instanceof BrainGridCliError) {
console.error(`BrainGrid CLI error: ${error.message}`);
console.error(`Command: ${error.command}`);
console.error(`Exit code: ${error.exitCode}`);
console.error(`Stderr: ${error.stderr}`);
throw new Error('Failed to create requirement');
}
throw error;
}
}Testing
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watchIntegration Status
Logger Integration
Status: not-applicable
This is a pure utility core package with no dependencies. Logging is handled by consuming packages. Does not require @bernierllc/logger integration.
Docs-Suite Integration
Status: ready
Complete API documentation with TypeScript types and examples available for documentation suite integration.
NeverHub Integration
Status: not-applicable
Pure utility package with no runtime dependencies. NeverHub integration is handled at the service-level packages that consume this utility. Does not require @bernierllc/neverhub-adapter integration.
Core Package Compliance
This package follows the core package rules:
- ✅ Atomic functionality: Single responsibility - wraps BrainGrid CLI
- ✅ No internal dependencies: Only depends on external packages (
execa,zod) - ✅ Pure functions: Explicit inputs/outputs with type safety
- ✅ Full test coverage: Comprehensive test suite for all commands
- ✅ Single entrypoint: All exports via
index.ts - ✅ Strict typing: TypeScript strict mode enabled, no implicit
any - ✅ Documentation: Complete README with purpose, usage, and examples
License
MIT License - see LICENSE file for details.
