Specialized guidance for developing cc-sessions API commands and subsystems for state management, task operations, configuration, and protocol execution
Type: WRITE-CAPABLE DAIC Modes: IMPLEMENT only Priority: High
This skill activates on:
sessions/api/**/*.jsFrom: skill-rules.json - cc-sessions-api configuration
Specialized guidance for developing cc-sessions API commands and subsystems. The API provides CLI commands for state management, task operations, configuration, and protocol execution.
When activated in IMPLEMENT mode with an active cc-sessions task:
API Architecture
Entry Point: sessions/bin/sessions (CLI binary)
Router: sessions/api/router.js (command dispatch)
Subsystems:
state_commands.js - State managementtask_commands.js - Task operationsconfig_commands.js - Configurationprotocol_commands.js - Protocol executionCommand Subsystems
State Commands (state_commands.js)
sessions state show # Display current session state
sessions state mode [value] # Get/set DAIC mode
sessions state task [value] # Get/set active task
sessions state todos # Manage todo list
sessions state flags # View/modify session flags
sessions state update # Update state values
Task Commands (task_commands.js)
sessions tasks idx list # List task indexes
sessions tasks idx <index-name> # View tasks in index
sessions tasks start <task-file> # Start a task
Config Commands (config_commands.js)
sessions config show # Display all configuration
sessions config phrases # View startup phrases
sessions config git # Git integration settings
sessions config env # Environment variables
sessions config features # Feature flags
sessions config read <key> # Read specific config value
sessions config write # Write config values
sessions config tools # Tool configurations
Protocol Commands (protocol_commands.js)
sessions protocol startup-load # Startup initialization
Command Development Pattern
Basic Command Structure:
// sessions/api/example_commands.js
module.exports = {
name: 'example',
description: 'Example command subsystem',
async execute(args) {
const [subcommand, ...rest] = args;
switch (subcommand) {
case 'action1':
return this.handleAction1(rest);
case 'action2':
return this.handleAction2(rest);
default:
return this.showHelp();
}
},
async handleAction1(args) {
// Implementation
return { success: true, message: 'Action completed' };
},
showHelp() {
return {
success: true,
message: `
Usage: sessions example
Actions: action1 - Description of action1 action2 - Description of action2 `.trim() }; } };
4. **State Management Patterns**
**Reading State:**
```javascript
const fs = require('fs');
const path = require('path');
const statePath = path.join(__dirname, '../sessions-state.json');
const state = JSON.parse(fs.readFileSync(statePath, 'utf8'));
console.log('Current mode:', state.mode);
console.log('Active task:', state.task.name);
Writing State:
// Read-modify-write pattern
const state = loadState();
state.mode = 'IMPLEMENT';
state.task.status = 'in_progress';
saveState(state);
Validation:
function validateMode(mode) {
const validModes = ['DISCUSS', 'ALIGN', 'IMPLEMENT', 'CHECK'];
if (!validModes.includes(mode)) {
throw new Error(`Invalid mode: ${mode}. Must be one of: ${validModes.join(', ')}`);
}
}
Error Handling
Consistent Error Format:
if (errorCondition) {
return {
success: false,
error: 'Clear, actionable error message',
hint: 'Optional suggestion for user'
};
}
Input Validation:
async execute(args) {
if (args.length === 0) {
return {
success: false,
error: 'Missing required argument: <action>',
hint: 'Use "sessions example help" for usage'
};
}
// ...
}
Output Formatting
Success Messages:
return {
success: true,
message: 'โ Task started successfully',
data: { taskName, branch }
};
Informational Output:
console.log('=== Session State ===');
console.log(`Mode: ${state.mode}`);
console.log(`Task: ${state.task.name}`);
CRITICAL WRITE-GATING RULES:
API-Specific Safety:
State Integrity:
โ "Add a new command: sessions tasks archive" โ "Modify state show to include task branch" โ "Fix the task idx command to handle missing indexes" โ "Create a new subsystem for managing LCMP files" โ "Add validation to the state mode command"
โ In DISCUSS/ALIGN/CHECK mode (API development requires IMPLEMENT) โ No active cc-sessions task (violates write-gating) โ User wants to work on hooks (use cc-sessions-hooks) โ User wants general framework features (use cc-sessions-core)
Before deploying a new or modified command:
async execute(args) {
if (args.length === 0) {
// GET: Show current value
return { success: true, data: state.value };
} else {
// SET: Update value
state.value = args[0];
saveState(state);
return { success: true, message: 'Value updated' };
}
}
async handleList() {
const items = loadItems();
if (items.length === 0) {
return { success: true, message: 'No items found' };
}
console.log('Available items:');
items.forEach(item => console.log(` โข ${item.name}`));
return { success: true };
}
async execute(args) {
const [subcommand, ...rest] = args;
const handlers = {
'list': this.handleList,
'add': this.handleAdd,
'remove': this.handleRemove
};
const handler = handlers[subcommand];
if (!handler) {
return { success: false, error: `Unknown subcommand: ${subcommand}` };
}
return handler.call(this, rest);
}
When creating or modifying commands, log in context/decisions.md:
### API Change: [Date]
- **Command:** sessions tasks archive
- **Change:** New command to move completed tasks to done/ directory
- **Rationale:** Users need way to clean up task list without deleting history
- **API:** sessions tasks archive <task-name>
- **State Impact:** Updates task index, moves file, logs action
- **Testing:** Verified with 3 test tasks, handles missing files gracefully
Last Updated: 2025-11-15 Framework Version: 2.0