Automating rules import in Bob IDE.
Introduction
In modern agentic platforms and AI-assisted development environments like IBM Bob, maintaining consistent context and project-specific guidelines ("rules") across multiple repositories is crucial. However, manually copying rule files into every new project creates friction and inconsistency. To streamline this workflow, we can implement a dedicated extension that automatically imports a centralized set of rules into any newly created or opened project workspace.
In the context of agentic AI platforms like IBM Bob or Claude or..., "rules" refer to centralized configuration guidelines, project-specific instructions, and behavioral constraints that define how the assistant should interact, code, or execute tasks within a given workspace. Stored locally within project directories (such as
.bob/rules) or managed globally, these instructions ensure that the AI automatically adapts to specific coding standards, architectural patterns, and workflow preferences every time a new project or repository is opened.
This blog post explores how to design and implement a rules synchronization extension for IBM Bob and VS Code, detailing its architecture, core synchronization engine, event wiring, and quickstart setup.
Implementation
The implementation is split into two primary layers: a pure Node.js core module (syncCore.ts) that handles the file system logic safely without any IDE dependencies, and an extension host layer (extension.ts) that manages user settings, workspace events, commands, and visual feedback.
Architecture Overview
The architecture separates core synchronization logic from IDE-specific event handling to ensure clean unit testing and robust path safety.
When a project is opened or a new folder is added to the workspace, the extension triggers the synchronization pipeline:
Core Synchronization Logic (syncCore.ts)
The core module operates independently of VS Code/Bob APIs. It enforces strict path-safety models to prevent path traversal and recursive copying issues. For instance, safeChild validates each directory entry name before joining paths:
/**
* Core sync logic. Intentionally free of any `vscode` import so it can be unit tested with plain Node.
*
* Path-safety model:
* - The SOURCE directory is chosen by the user in settings (trusted, but must be absolute, NUL-free).
* - The TARGET folder is relative and must stay inside the project root (checked by `resolveTargetDir`).
* - Every child name read from disk is validated by `safeChild` before being appended to a base path.
*/
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
/* */
/* */
/* */
/* */
export function safeChild(base: string, name: string): string {
if (
!name ||
name === '.' ||
name === '..' ||
name.includes('/') ||
name.includes('\\') ||
name.includes('\0')
) {
throw new SyncAbortError(`Unsafe file name encountered: ${JSON.stringify(name)}`, 'EUNSAFE_NAME');
}
return base.endsWith(path.sep) ? base + name : base + path.sep + name;
}
The primary entry point syncRules verifies the source directory, resolves target folders safely within the project root, checks for recursion risks, and recursively copies files according to the specified conflict strategy (overwrite or skip).
Extension Event Wiring (extension.ts)
The extension binds IDE events, user settings, and commands to the synchronization engine. Upon activation, it sets up status bar items, registers commands like bobRulesSync.syncNow, and listens to workspace folder modifications:
/**
* Bob Rules Sync - VS Code / IBM Bob extension entry point.
*
* Triggers a rules sync when:
* - the extension activates (a project was opened in Bob), and
* - a folder is added to the workspace (a new project was created/added).
* Users can also run "Bob Rules Sync: Sync Rules Now" at any time.
*/
import * as vscode from 'vscode';
import { ConflictStrategy, SyncAbortError, SyncResult, summarize, syncRules } from './syncCore';
const CONFIG_SECTION = 'bobRulesSync';
let output: vscode.OutputChannel;
let statusBar: vscode.StatusBarItem;
let extensionId = '';
/* */
/* */
/* */
/* */
export function activate(context: vscode.ExtensionContext): void {
extensionId = context.extension.id;
output = vscode.window.createOutputChannel('Bob Rules Sync');
statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);
statusBar.command = 'bobRulesSync.syncNow';
context.subscriptions.push(output, statusBar);
context.subscriptions.push(
vscode.commands.registerCommand('bobRulesSync.syncNow', () => syncAll('manual command', true)),
// New project created / folder added to the workspace.
vscode.workspace.onDidChangeWorkspaceFolders(async (e) => {
for (const folder of e.added) {
await syncFolder(folder, 'folder added', false);
}
})
);
log('INFO', 'Bob Rules Sync activated.');
void syncAll('project opened', false);
}
Quickstart Guide
To get started with the rules synchronization extension in your development environment:
Make sure the source folder exists and contains your rules (default
/Users/xxxx/Devs/_myRules).Install the extension using
scripts/install.shor via the built VSIX artifact (.bob/artifacts/bob-rules-sync-1.0.0.vsix) through Extensions > ... > Install from VSIX.Reload the Bob window and open any project to automatically copy rules into
.bob/rules.Customize target folders or trigger manual syncs via the Bob command palette or status bar item.
Conclusion
By building a dedicated extension for rule importation in Bob IDE, we have successfully automated the distribution of development standards across projects. Decoupling the pure Node.js synchronization core from the IDE extension host ensures high testability, strong path safety against traversal attacks, and a seamless developer experience. This automated approach saves hours of manual configuration time and guarantees that every new workspace starts with the proper context and agent rules ready to go.
Thanks for reading 🤖
Links
- Code repository for this post: https://github.com/aairom/bob-rules-extension
- IBM Bob: https://bob.ibm.com/





Top comments (0)