@rely-ai/caliber 1.22.0-dev.1773766400 → 1.22.0-dev.1773767049

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bin.js +101 -174
  2. package/package.json +1 -1
package/dist/bin.js CHANGED
@@ -159,12 +159,12 @@ __export(constants_exports, {
159
159
  MANIFEST_FILE: () => MANIFEST_FILE
160
160
  });
161
161
  import path9 from "path";
162
- import os3 from "os";
162
+ import os2 from "os";
163
163
  var AUTH_DIR, CALIBER_DIR, MANIFEST_FILE, BACKUPS_DIR, LEARNING_DIR, LEARNING_SESSION_FILE, LEARNING_STATE_FILE, LEARNING_MAX_EVENTS, LEARNING_ROI_FILE;
164
164
  var init_constants = __esm({
165
165
  "src/constants.ts"() {
166
166
  "use strict";
167
- AUTH_DIR = path9.join(os3.homedir(), ".caliber");
167
+ AUTH_DIR = path9.join(os2.homedir(), ".caliber");
168
168
  CALIBER_DIR = ".caliber";
169
169
  MANIFEST_FILE = path9.join(CALIBER_DIR, "manifest.json");
170
170
  BACKUPS_DIR = path9.join(CALIBER_DIR, "backups");
@@ -185,7 +185,7 @@ __export(lock_exports, {
185
185
  });
186
186
  import fs29 from "fs";
187
187
  import path23 from "path";
188
- import os6 from "os";
188
+ import os5 from "os";
189
189
  function isCaliberRunning() {
190
190
  try {
191
191
  if (!fs29.existsSync(LOCK_FILE)) return false;
@@ -218,7 +218,7 @@ var LOCK_FILE, STALE_MS;
218
218
  var init_lock = __esm({
219
219
  "src/lib/lock.ts"() {
220
220
  "use strict";
221
- LOCK_FILE = path23.join(os6.tmpdir(), ".caliber.lock");
221
+ LOCK_FILE = path23.join(os5.tmpdir(), ".caliber.lock");
222
222
  STALE_MS = 10 * 60 * 1e3;
223
223
  }
224
224
  });
@@ -1205,198 +1205,125 @@ var OpenAICompatProvider = class {
1205
1205
 
1206
1206
  // src/llm/cursor-acp.ts
1207
1207
  import { spawn, execSync as execSync3 } from "child_process";
1208
- import readline from "readline";
1209
- import os2 from "os";
1210
- var ACP_AGENT_BIN = "agent";
1208
+ var AGENT_BIN = "agent";
1211
1209
  var IS_WINDOWS = process.platform === "win32";
1212
1210
  var CursorAcpProvider = class {
1213
1211
  defaultModel;
1214
1212
  cursorApiKey;
1215
- connections = /* @__PURE__ */ new Map();
1216
- connectPromises = /* @__PURE__ */ new Map();
1217
- shutdownRequested = false;
1218
1213
  constructor(config) {
1219
1214
  this.defaultModel = config.model || "sonnet-4.6";
1220
1215
  this.cursorApiKey = process.env.CURSOR_API_KEY ?? process.env.CURSOR_AUTH_TOKEN;
1221
- process.once("exit", () => this.shutdown());
1222
1216
  }
1223
1217
  async call(options) {
1224
- const chunks = [];
1225
- await this.runPrompt(options, {
1226
- onText: (text) => chunks.push(text),
1227
- onEnd: () => {
1228
- },
1229
- onError: () => {
1230
- }
1231
- });
1232
- return chunks.join("");
1218
+ const prompt = this.buildPrompt(options);
1219
+ const model = options.model || this.defaultModel;
1220
+ return this.runPrint(model, prompt);
1233
1221
  }
1234
1222
  async stream(options, callbacks) {
1235
- await this.runPrompt(options, callbacks);
1236
- }
1237
- shutdown() {
1238
- this.shutdownRequested = true;
1239
- for (const conn of this.connections.values()) {
1240
- conn.child.stdin?.end();
1241
- conn.child.kill("SIGTERM");
1242
- }
1243
- this.connections.clear();
1244
- this.connectPromises.clear();
1245
- }
1246
- // -- Connection pool --------------------------------------------------------
1247
- resolveModel(options) {
1248
- return options.model || this.defaultModel;
1249
- }
1250
- async ensureConnection(model) {
1251
- const existing = this.connections.get(model);
1252
- if (existing && !existing.child.killed) return existing;
1253
- const pending = this.connectPromises.get(model);
1254
- if (pending) {
1255
- await pending;
1256
- return this.connections.get(model);
1257
- }
1258
- const promise = this.connect(model);
1259
- this.connectPromises.set(model, promise);
1260
- try {
1261
- await promise;
1262
- } catch (err) {
1263
- this.connectPromises.delete(model);
1264
- throw err;
1265
- }
1266
- return this.connections.get(model);
1223
+ const prompt = this.buildPrompt(options);
1224
+ const model = options.model || this.defaultModel;
1225
+ return this.runPrintStream(model, prompt, callbacks);
1267
1226
  }
1268
- async connect(model) {
1269
- const args = ["acp"];
1227
+ buildArgs(model, streaming) {
1228
+ const args = ["--print"];
1270
1229
  if (model && model !== "auto" && model !== "default") {
1271
- args.unshift("--model", model);
1230
+ args.push("--model", model);
1231
+ }
1232
+ if (streaming) {
1233
+ args.push("--output-format", "stream-json", "--stream-partial-output");
1272
1234
  }
1273
1235
  if (this.cursorApiKey) {
1274
- args.unshift("--api-key", this.cursorApiKey);
1236
+ args.push("--api-key", this.cursorApiKey);
1275
1237
  }
1276
- const child = spawn(ACP_AGENT_BIN, args, {
1277
- stdio: ["pipe", "pipe", "ignore"],
1278
- cwd: process.cwd(),
1279
- env: { ...process.env, ...this.cursorApiKey && { CURSOR_API_KEY: this.cursorApiKey } },
1280
- ...IS_WINDOWS && { shell: true }
1281
- });
1282
- const conn = {
1283
- child,
1284
- rl: readline.createInterface({ input: child.stdout, crlfDelay: Infinity }),
1285
- pending: /* @__PURE__ */ new Map(),
1286
- nextId: 1,
1287
- activeCallbacks: null
1288
- };
1289
- conn.rl.on("line", (line) => this.handleLine(conn, line));
1290
- child.on("error", (err) => {
1291
- for (const w of conn.pending.values()) w.reject(err);
1292
- conn.pending.clear();
1293
- conn.activeCallbacks?.onError(err);
1294
- });
1295
- child.on("close", () => {
1296
- if (!this.shutdownRequested) {
1297
- const err = new Error("Cursor agent process exited unexpectedly");
1298
- for (const w of conn.pending.values()) w.reject(err);
1299
- conn.pending.clear();
1300
- conn.activeCallbacks?.onError(err);
1301
- }
1302
- this.connections.delete(model);
1303
- this.connectPromises.delete(model);
1304
- });
1305
- this.connections.set(model, conn);
1306
- await this.send(conn, "initialize", {
1307
- protocolVersion: 1,
1308
- clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
1309
- clientInfo: { name: "caliber", version: "1.0.0" }
1310
- });
1311
- await this.send(conn, "authenticate", { methodId: "cursor_login" });
1238
+ return args;
1312
1239
  }
1313
- // -- JSON-RPC ---------------------------------------------------------------
1314
- send(conn, method, params) {
1315
- if (!conn.child.stdin) {
1316
- return Promise.reject(new Error("Cursor agent not connected"));
1317
- }
1240
+ runPrint(model, prompt) {
1318
1241
  return new Promise((resolve2, reject) => {
1319
- const id = conn.nextId++;
1320
- conn.pending.set(id, { resolve: resolve2, reject });
1321
- const msg = { jsonrpc: "2.0", id, method, params };
1322
- conn.child.stdin.write(JSON.stringify(msg) + "\n", (err) => {
1323
- if (err) {
1324
- conn.pending.delete(id);
1325
- reject(err);
1242
+ const args = this.buildArgs(model, false);
1243
+ const child = spawn(AGENT_BIN, args, {
1244
+ stdio: ["pipe", "pipe", "ignore"],
1245
+ env: { ...process.env, ...this.cursorApiKey && { CURSOR_API_KEY: this.cursorApiKey } },
1246
+ ...IS_WINDOWS && { shell: true }
1247
+ });
1248
+ const chunks = [];
1249
+ child.stdout.on("data", (data) => {
1250
+ chunks.push(data);
1251
+ });
1252
+ child.on("error", reject);
1253
+ child.on("close", (code) => {
1254
+ const output = Buffer.concat(chunks).toString("utf-8").trim();
1255
+ if (code !== 0 && !output) {
1256
+ reject(new Error(`Cursor agent exited with code ${code}`));
1257
+ } else {
1258
+ resolve2(output);
1326
1259
  }
1327
1260
  });
1261
+ child.stdin.write(prompt);
1262
+ child.stdin.end();
1328
1263
  });
1329
1264
  }
1330
- handleLine(conn, line) {
1331
- let msg;
1332
- try {
1333
- msg = JSON.parse(line);
1334
- } catch {
1335
- return;
1336
- }
1337
- if (msg.id != null && (msg.result !== void 0 || msg.error !== void 0)) {
1338
- const waiter = conn.pending.get(msg.id);
1339
- if (waiter) {
1340
- conn.pending.delete(msg.id);
1341
- if (msg.error) {
1342
- waiter.reject(new Error(msg.error.message || "ACP error"));
1343
- } else {
1344
- waiter.resolve(msg.result);
1265
+ runPrintStream(model, prompt, callbacks) {
1266
+ return new Promise((resolve2, reject) => {
1267
+ const args = this.buildArgs(model, true);
1268
+ const child = spawn(AGENT_BIN, args, {
1269
+ stdio: ["pipe", "pipe", "ignore"],
1270
+ env: { ...process.env, ...this.cursorApiKey && { CURSOR_API_KEY: this.cursorApiKey } },
1271
+ ...IS_WINDOWS && { shell: true }
1272
+ });
1273
+ let buffer = "";
1274
+ child.stdout.on("data", (data) => {
1275
+ buffer += data.toString("utf-8");
1276
+ const lines = buffer.split("\n");
1277
+ buffer = lines.pop() || "";
1278
+ for (const line of lines) {
1279
+ if (!line.trim()) continue;
1280
+ try {
1281
+ const event = JSON.parse(line);
1282
+ if (event.type === "assistant") {
1283
+ const text = event.message?.content?.[0]?.text || event.content;
1284
+ if (text) callbacks.onText(text);
1285
+ } else if (event.type === "result") {
1286
+ callbacks.onEnd({ stopReason: "end_turn" });
1287
+ }
1288
+ } catch {
1289
+ callbacks.onText(line);
1290
+ }
1345
1291
  }
1346
- }
1347
- if (msg.result && typeof msg.result === "object" && "stopReason" in msg.result) {
1348
- conn.activeCallbacks?.onEnd({
1349
- stopReason: msg.result.stopReason
1350
- });
1351
- }
1352
- return;
1353
- }
1354
- if (msg.method === "session/update" && msg.params?.update) {
1355
- const update = msg.params.update;
1356
- if (update.sessionUpdate === "agent_message_chunk" && update.content?.text) {
1357
- conn.activeCallbacks?.onText(update.content.text);
1358
- }
1359
- return;
1360
- }
1361
- if (msg.method === "session/request_permission" && msg.id != null) {
1362
- const response = JSON.stringify({
1363
- jsonrpc: "2.0",
1364
- id: msg.id,
1365
- result: { outcome: { outcome: "selected", optionId: "allow-once" } }
1366
- }) + "\n";
1367
- conn.child.stdin?.write(response);
1368
- }
1369
- }
1370
- // -- Prompt execution -------------------------------------------------------
1371
- async runPrompt(options, callbacks) {
1372
- const model = this.resolveModel(options);
1373
- const conn = await this.ensureConnection(model);
1374
- conn.activeCallbacks = callbacks;
1375
- try {
1376
- const sessionResult = await this.send(conn, "session/new", {
1377
- cwd: os2.tmpdir(),
1378
- mcpServers: []
1379
1292
  });
1380
- await this.send(conn, "session/prompt", {
1381
- sessionId: sessionResult.sessionId,
1382
- prompt: [{ type: "text", text: this.buildCombinedPrompt(options) }]
1293
+ child.on("error", (err) => {
1294
+ callbacks.onError(err);
1295
+ reject(err);
1383
1296
  });
1384
- } catch (err) {
1385
- const error = err instanceof Error ? err : new Error(String(err));
1386
- callbacks.onError(error);
1387
- throw error;
1388
- } finally {
1389
- conn.activeCallbacks = null;
1390
- }
1297
+ child.on("close", (code) => {
1298
+ if (buffer.trim()) {
1299
+ try {
1300
+ const event = JSON.parse(buffer);
1301
+ if (event.type === "assistant") {
1302
+ const text = event.message?.content?.[0]?.text || event.content;
1303
+ if (text) callbacks.onText(text);
1304
+ } else if (event.type === "result") {
1305
+ callbacks.onEnd({ stopReason: "end_turn" });
1306
+ }
1307
+ } catch {
1308
+ callbacks.onText(buffer);
1309
+ }
1310
+ }
1311
+ if (code !== 0 && code !== null) {
1312
+ const err = new Error(`Cursor agent exited with code ${code}`);
1313
+ callbacks.onError(err);
1314
+ reject(err);
1315
+ } else {
1316
+ resolve2();
1317
+ }
1318
+ });
1319
+ child.stdin.write(prompt);
1320
+ child.stdin.end();
1321
+ });
1391
1322
  }
1392
- buildCombinedPrompt(options) {
1323
+ buildPrompt(options) {
1393
1324
  const streamOpts = options;
1394
1325
  const hasHistory = streamOpts.messages && streamOpts.messages.length > 0;
1395
1326
  let combined = "";
1396
- combined += "IMPORTANT: You are being used as a direct LLM, not as a coding agent. ";
1397
- combined += "Do NOT use tools, do NOT read or write files, do NOT check the repository. ";
1398
- combined += "Process the prompt below and output your response directly in your message. ";
1399
- combined += "Follow the system instructions exactly.\n\n";
1400
1327
  combined += "[[System]]\n" + options.system + "\n\n";
1401
1328
  if (hasHistory) {
1402
1329
  for (const msg of streamOpts.messages) {
@@ -1412,7 +1339,7 @@ ${msg.content}
1412
1339
  };
1413
1340
  function isCursorAgentAvailable() {
1414
1341
  try {
1415
- const cmd = process.platform === "win32" ? `where ${ACP_AGENT_BIN}` : `which ${ACP_AGENT_BIN}`;
1342
+ const cmd = process.platform === "win32" ? `where ${AGENT_BIN}` : `which ${AGENT_BIN}`;
1416
1343
  execSync3(cmd, { stdio: "ignore" });
1417
1344
  return true;
1418
1345
  } catch {
@@ -3291,9 +3218,9 @@ import { createTwoFilesPatch } from "diff";
3291
3218
  import { execSync as execSync5, spawn as spawn3 } from "child_process";
3292
3219
  import fs14 from "fs";
3293
3220
  import path12 from "path";
3294
- import os4 from "os";
3221
+ import os3 from "os";
3295
3222
  var IS_WINDOWS3 = process.platform === "win32";
3296
- var DIFF_TEMP_DIR = path12.join(os4.tmpdir(), "caliber-diff");
3223
+ var DIFF_TEMP_DIR = path12.join(os3.tmpdir(), "caliber-diff");
3297
3224
  function getEmptyFilePath(proposedPath) {
3298
3225
  fs14.mkdirSync(DIFF_TEMP_DIR, { recursive: true });
3299
3226
  const tempPath = path12.join(DIFF_TEMP_DIR, path12.basename(proposedPath));
@@ -4056,9 +3983,9 @@ var SpinnerMessages = class {
4056
3983
 
4057
3984
  // src/utils/prompt.ts
4058
3985
  import chalk4 from "chalk";
4059
- import readline2 from "readline";
3986
+ import readline from "readline";
4060
3987
  function promptInput(question) {
4061
- const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
3988
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
4062
3989
  return new Promise((resolve2) => {
4063
3990
  rl.question(chalk4.cyan(`${question} `), (answer) => {
4064
3991
  rl.close();
@@ -5719,10 +5646,10 @@ import chalk7 from "chalk";
5719
5646
  // src/telemetry/config.ts
5720
5647
  import fs23 from "fs";
5721
5648
  import path18 from "path";
5722
- import os5 from "os";
5649
+ import os4 from "os";
5723
5650
  import crypto3 from "crypto";
5724
5651
  import { execSync as execSync12 } from "child_process";
5725
- var CONFIG_DIR2 = path18.join(os5.homedir(), ".caliber");
5652
+ var CONFIG_DIR2 = path18.join(os4.homedir(), ".caliber");
5726
5653
  var CONFIG_FILE2 = path18.join(CONFIG_DIR2, "config.json");
5727
5654
  var runtimeDisabled = false;
5728
5655
  function readConfig() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rely-ai/caliber",
3
- "version": "1.22.0-dev.1773766400",
3
+ "version": "1.22.0-dev.1773767049",
4
4
  "description": "Analyze your codebase and generate optimized AI agent configs (CLAUDE.md, .cursorrules, skills) — no API key needed",
5
5
  "type": "module",
6
6
  "bin": {