@jaibber/sdk 0.1.7 → 0.1.9

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/cli.js +87 -0
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1147,6 +1147,10 @@ ${task.description}` : `Task: ${task.title}`;
1147
1147
  };
1148
1148
 
1149
1149
  // src/cli.ts
1150
+ import { writeFileSync, mkdirSync } from "fs";
1151
+ import { execSync } from "child_process";
1152
+ import { homedir } from "os";
1153
+ import { join } from "path";
1150
1154
  function parseArgs(argv) {
1151
1155
  const args2 = {};
1152
1156
  for (let i = 0; i < argv.length; i++) {
@@ -1186,6 +1190,7 @@ PROVIDER (at least one required \u2014 first match wins):
1186
1190
  OPTIONAL:
1187
1191
  --register Create a new account (instead of logging into an existing one)
1188
1192
  --create-project <name> Create a new project and join it (prints project ID on start)
1193
+ --install-service Install as a systemd user service and start it (Linux only)
1189
1194
  --server <url> Server URL (default: https://api.jaibber.com)
1190
1195
  --instructions <text> System prompt for the agent
1191
1196
  --machine-name <name> Machine identifier shown in presence
@@ -1219,6 +1224,13 @@ EXAMPLES:
1219
1224
  --create-project "my-ubuntu-server" \\
1220
1225
  --claude-cli
1221
1226
 
1227
+ # Install as a persistent background service
1228
+ npx @jaibber/sdk \\
1229
+ --username coding-bot --password s3cret \\
1230
+ --agent-name "CodingAgent" \\
1231
+ --projects abc-123 --claude-cli \\
1232
+ --install-service
1233
+
1222
1234
  # Register new account + Gemini
1223
1235
  npx @jaibber/sdk \\
1224
1236
  --register \\
@@ -1247,6 +1259,7 @@ var instructions = args["instructions"];
1247
1259
  var machineName = args["machine-name"];
1248
1260
  var shouldRegister = args["register"] === "true";
1249
1261
  var createProjectName = args["create-project"];
1262
+ var installService = args["install-service"] === "true";
1250
1263
  var projectIds = args["projects"] ? args["projects"].split(",").map((s) => s.trim()) : void 0;
1251
1264
  if (!username) {
1252
1265
  console.error("Error: --username is required");
@@ -1293,6 +1306,80 @@ if (createProjectName) {
1293
1306
  process.exit(1);
1294
1307
  }
1295
1308
  }
1309
+ if (installService) {
1310
+ const binaryPath = process.execPath;
1311
+ const scriptPath = new URL(import.meta.url).pathname;
1312
+ const flags = [];
1313
+ flags.push(`--username`, username);
1314
+ flags.push(`--password`, password);
1315
+ flags.push(`--agent-name`, agentName);
1316
+ if (resolvedProjectIds?.length) flags.push(`--projects`, resolvedProjectIds.join(","));
1317
+ if (serverUrl !== "https://api.jaibber.com") flags.push(`--server`, serverUrl);
1318
+ if (instructions) flags.push(`--instructions`, instructions);
1319
+ if (machineName) flags.push(`--machine-name`, machineName);
1320
+ if (projectDir) flags.push(`--project-dir`, projectDir);
1321
+ if (useClaudeCli) flags.push(`--claude-cli`);
1322
+ if (anthropicKey) flags.push(`--anthropic-key`, anthropicKey);
1323
+ if (openaiKey) flags.push(`--openai-key`, openaiKey);
1324
+ if (googleKey) flags.push(`--google-key`, googleKey);
1325
+ const execStart = `${binaryPath} ${scriptPath} ${flags.map((f) => f.includes(" ") ? `"${f}"` : f).join(" ")}`;
1326
+ const serviceContent = `[Unit]
1327
+ Description=Jaibber Agent (${agentName})
1328
+ After=network-online.target
1329
+ Wants=network-online.target
1330
+
1331
+ [Service]
1332
+ Type=simple
1333
+ ExecStart=${execStart}
1334
+ Restart=on-failure
1335
+ RestartSec=10
1336
+ Environment=HOME=${homedir()}
1337
+
1338
+ [Install]
1339
+ WantedBy=default.target
1340
+ `;
1341
+ const serviceDir = join(homedir(), ".config", "systemd", "user");
1342
+ const serviceName = `jaibber-agent.service`;
1343
+ const servicePath = join(serviceDir, serviceName);
1344
+ mkdirSync(serviceDir, { recursive: true });
1345
+ writeFileSync(servicePath, serviceContent);
1346
+ try {
1347
+ execSync(`systemctl --user daemon-reload`, { stdio: "ignore" });
1348
+ execSync(`systemctl --user enable --now ${serviceName}`, { stdio: "ignore" });
1349
+ console.log(`[cli] Service installed and started (systemd).`);
1350
+ console.log(`[cli] systemctl --user status jaibber-agent`);
1351
+ console.log(`[cli] systemctl --user restart jaibber-agent`);
1352
+ console.log(`[cli] journalctl --user -u jaibber-agent -f`);
1353
+ } catch {
1354
+ const cronLine = `@reboot ${execStart} >> ${homedir()}/jaibber-agent.log 2>&1`;
1355
+ try {
1356
+ let existing = "";
1357
+ try {
1358
+ existing = execSync("crontab -l 2>/dev/null").toString();
1359
+ } catch {
1360
+ }
1361
+ const filtered = existing.split("\n").filter((l) => !l.includes("jaibber-agent")).join("\n").trimEnd();
1362
+ const newCrontab = (filtered ? filtered + "\n" : "") + cronLine + "\n";
1363
+ execSync(`echo ${JSON.stringify(newCrontab)} | crontab -`);
1364
+ console.log(`[cli] Service installed via crontab (starts on reboot).`);
1365
+ console.log(`[cli] View log: tail -f ~/jaibber-agent.log`);
1366
+ console.log(`[cli] Remove: crontab -e (delete the jaibber-agent line)`);
1367
+ console.log(`[cli] Tip: run "sudo loginctl enable-linger ${process.env.USER || "ubuntu"}" to switch to systemd for better reliability.`);
1368
+ const { spawn: spawnBg } = await import("child_process");
1369
+ spawnBg(binaryPath, [scriptPath, ...flags], {
1370
+ detached: true,
1371
+ stdio: ["ignore", "ignore", "ignore"]
1372
+ }).unref();
1373
+ console.log(`[cli] Agent started in background.`);
1374
+ } catch (cronErr) {
1375
+ console.error(`[cli] Could not install via crontab either: ${cronErr instanceof Error ? cronErr.message : cronErr}`);
1376
+ console.error(`[cli] Service file written to: ${servicePath}`);
1377
+ console.error(`[cli] Run manually: sudo loginctl enable-linger $USER && systemctl --user enable --now jaibber-agent`);
1378
+ process.exit(1);
1379
+ }
1380
+ }
1381
+ process.exit(0);
1382
+ }
1296
1383
  var agent = new JaibberAgent({
1297
1384
  serverUrl,
1298
1385
  credentials: { username, password },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaibber/sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Headless agent SDK for Jaibber — run AI agents without a desktop app",
5
5
  "license": "MIT",
6
6
  "repository": {