| layout | title | nav_order | parent |
|---|---|---|---|
default |
Chapter 4: Multi-Agent and Parallel Execution |
4 |
CodeMachine CLI Tutorial |
Welcome to Chapter 4: Multi-Agent and Parallel Execution. In this part of CodeMachine CLI Tutorial: Orchestrating Long-Running Coding Agent Workflows, you will build an intuitive mental model first, then move into concrete implementation details and practical production tradeoffs.
CodeMachine supports assigning different workflow steps to different agent engines in parallel.
- split tasks by domain responsibility
- define merge and conflict resolution checkpoints
- monitor cross-agent context consistency
You now understand how to leverage parallelism without losing control.
Next: Chapter 5: Context Engineering and State Control
The TraceFile interface in scripts/import-telemetry.ts handles a key part of this chapter's functionality:
}
interface TraceFile {
version: number;
service: string;
exportedAt: string;
spanCount: number;
spans: SerializedSpan[];
}
interface SerializedLog {
timestamp: [number, number]; // [seconds, nanoseconds]
severityNumber: number;
severityText?: string;
body: unknown;
attributes: Record<string, unknown>;
resource?: Record<string, unknown>;
}
interface LogFile {
version: number;
service: string;
exportedAt: string;
logCount: number;
logs: SerializedLog[];
}
// Parse command line arguments
function parseArgs(): Config {
const args = process.argv.slice(2);
const config: Config = {
lokiUrl: 'http://localhost:3100',This interface is important because it defines how CodeMachine CLI Tutorial: Orchestrating Long-Running Coding Agent Workflows implements the patterns covered in this chapter.
The SerializedLog interface in scripts/import-telemetry.ts handles a key part of this chapter's functionality:
}
interface SerializedLog {
timestamp: [number, number]; // [seconds, nanoseconds]
severityNumber: number;
severityText?: string;
body: unknown;
attributes: Record<string, unknown>;
resource?: Record<string, unknown>;
}
interface LogFile {
version: number;
service: string;
exportedAt: string;
logCount: number;
logs: SerializedLog[];
}
// Parse command line arguments
function parseArgs(): Config {
const args = process.argv.slice(2);
const config: Config = {
lokiUrl: 'http://localhost:3100',
tempoUrl: 'http://localhost:4318',
logsOnly: false,
tracesOnly: false,
sourcePath: '',
};
for (let i = 0; i < args.length; i++) {
const arg = args[i];This interface is important because it defines how CodeMachine CLI Tutorial: Orchestrating Long-Running Coding Agent Workflows implements the patterns covered in this chapter.
The LogFile interface in scripts/import-telemetry.ts handles a key part of this chapter's functionality:
}
interface LogFile {
version: number;
service: string;
exportedAt: string;
logCount: number;
logs: SerializedLog[];
}
// Parse command line arguments
function parseArgs(): Config {
const args = process.argv.slice(2);
const config: Config = {
lokiUrl: 'http://localhost:3100',
tempoUrl: 'http://localhost:4318',
logsOnly: false,
tracesOnly: false,
sourcePath: '',
};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg === '--loki-url' && args[i + 1]) {
config.lokiUrl = args[++i];
} else if (arg === '--tempo-url' && args[i + 1]) {
config.tempoUrl = args[++i];
} else if (arg === '--logs-only') {
config.logsOnly = true;
} else if (arg === '--traces-only') {
config.tracesOnly = true;
} else if (!arg.startsWith('-')) {This interface is important because it defines how CodeMachine CLI Tutorial: Orchestrating Long-Running Coding Agent Workflows implements the patterns covered in this chapter.
The findPackageRoot function in bin/codemachine.js handles a key part of this chapter's functionality:
const ROOT_FALLBACK = join(__dirname, '..');
function findPackageRoot(startDir) {
let current = startDir;
const maxDepth = 10;
let depth = 0;
while (current && depth < maxDepth) {
const candidate = join(current, 'package.json');
if (existsSync(candidate)) {
try {
const pkg = JSON.parse(readFileSync(candidate, 'utf8'));
if (pkg?.name === 'codemachine') {
return current;
}
} catch {
// ignore malformed package.json
}
}
const parent = dirname(current);
if (parent === current) break;
current = parent;
depth++;
}
return undefined;
}
const DEFAULT_PACKAGE_ROOT = findPackageRoot(ROOT_FALLBACK) ?? ROOT_FALLBACK;
function runBinary(binaryPath, packageRoot) {
const child = spawn(binaryPath, process.argv.slice(2), {
stdio: 'inherit',This function is important because it defines how CodeMachine CLI Tutorial: Orchestrating Long-Running Coding Agent Workflows implements the patterns covered in this chapter.
flowchart TD
A[TraceFile]
B[SerializedLog]
C[LogFile]
D[findPackageRoot]
A --> B
B --> C
C --> D