@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
84 lines • 3.18 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.spawnClaudePty = spawnClaudePty;
const pty = __importStar(require("node-pty"));
/**
* Spawns a Claude CLI process with PTY support.
*/
function spawnClaudePty(cwd, command, args) {
// Build the full command array
const fullCommand = ['claude', command, ...args, '--model=opus'];
// Spawn the PTY process
let ptyProcess;
try {
ptyProcess = pty.spawn(fullCommand[0], fullCommand.slice(1), {
name: 'xterm-256color',
cols: process.stdout.columns || 80,
rows: process.stdout.rows || 30,
cwd,
env: Object.assign(Object.assign({}, process.env), { FORCE_COLOR: '1', TERM: 'xterm-256color' })
});
}
catch (error) {
throw new Error(`Failed to spawn Claude process: ${error instanceof Error ? error.message : String(error)}`);
}
// Set stdin to raw mode to properly handle arrow keys
if (process.stdin.isTTY && process.stdin.setRawMode) {
try {
process.stdin.setRawMode(true);
}
catch (_a) {
// Ignore error if setRawMode fails
}
}
// Forward stdin to PTY
const stdinHandler = (data) => {
ptyProcess.write(data.toString());
};
process.stdin.on('data', stdinHandler);
// Handle terminal resize
const resizeHandler = () => {
ptyProcess.resize(process.stdout.columns || 80, process.stdout.rows || 30);
};
process.stdout.on('resize', resizeHandler);
// Clean up listeners when PTY exits
ptyProcess.onExit(() => {
process.stdin.removeListener('data', stdinHandler);
process.stdout.removeListener('resize', resizeHandler);
});
return ptyProcess;
}
//# sourceMappingURL=spawnClaudePty.js.map