@shipers-dev/multi 0.9.0 → 0.9.1

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.
package/dist/index.js CHANGED
@@ -5689,13 +5689,14 @@ var LOG_PATH2 = join3(MULTI_DIR, "logs", "agent.log");
5689
5689
  var SKILLS_DIR = join3(MULTI_DIR, "skills");
5690
5690
  var STOP_PATH = join3(MULTI_DIR, "stop.flag");
5691
5691
  var TASKS_DB_PATH = join3(MULTI_DIR, "tasks.db");
5692
- var VERSION = "0.8.0";
5692
+ var VERSION = "0.9.1";
5693
5693
  var COMMANDS = {
5694
5694
  setup: "Register this device with a workspace",
5695
5695
  connect: "Connect device to realtime hub and execute assigned tasks",
5696
5696
  link: "Link this device to an agent (agent_id required)",
5697
5697
  status: "Show current status",
5698
5698
  stop: "Stop the running daemon",
5699
+ restart: "Stop and relaunch the daemon in background",
5699
5700
  logs: "View execution logs"
5700
5701
  };
5701
5702
  function ensureDirs() {
@@ -5761,6 +5762,9 @@ async function main() {
5761
5762
  case "stop":
5762
5763
  await cmdStop();
5763
5764
  break;
5765
+ case "restart":
5766
+ await cmdRestart(apiUrl);
5767
+ break;
5764
5768
  case "logs":
5765
5769
  await cmdLogs();
5766
5770
  break;
@@ -5782,6 +5786,7 @@ Commands:
5782
5786
  connect ${COMMANDS.connect}
5783
5787
  status ${COMMANDS.status}
5784
5788
  stop ${COMMANDS.stop}
5789
+ restart ${COMMANDS.restart}
5785
5790
  logs ${COMMANDS.logs}
5786
5791
 
5787
5792
  Options:
@@ -6738,7 +6743,11 @@ async function executePlanActions(apiUrl, parentTask, actions, ctx) {
6738
6743
  }
6739
6744
  })();
6740
6745
  const headers = { "x-agent-id": parentTask.agent_id };
6741
- await ctx.refreshLocalAgents();
6746
+ if (typeof ctx.refreshLocalAgents === "function") {
6747
+ try {
6748
+ await ctx.refreshLocalAgents();
6749
+ } catch {}
6750
+ }
6742
6751
  for (const a of actions) {
6743
6752
  try {
6744
6753
  if (a.type === "create") {
@@ -7151,6 +7160,50 @@ async function cmdStop() {
7151
7160
  console.log(`Sent SIGTERM to ${pid}`);
7152
7161
  } catch {}
7153
7162
  }
7163
+ async function cmdRestart(apiUrl) {
7164
+ if (existsSync3(PID_PATH)) {
7165
+ const pid = Number(readFileSync3(PID_PATH, "utf8").trim());
7166
+ if (pid && isRunning(pid)) {
7167
+ ensureDirs();
7168
+ writeFileSync3(STOP_PATH, "1");
7169
+ try {
7170
+ process.kill(pid, "SIGTERM");
7171
+ } catch {}
7172
+ console.log(`\u23F9 Stopping daemon (pid ${pid})...`);
7173
+ const deadline = Date.now() + 1e4;
7174
+ while (Date.now() < deadline && isRunning(pid))
7175
+ await sleep(200);
7176
+ if (isRunning(pid)) {
7177
+ try {
7178
+ process.kill(pid, "SIGKILL");
7179
+ } catch {}
7180
+ await sleep(300);
7181
+ }
7182
+ }
7183
+ try {
7184
+ if (existsSync3(PID_PATH))
7185
+ unlinkSync(PID_PATH);
7186
+ } catch {}
7187
+ }
7188
+ try {
7189
+ if (existsSync3(STOP_PATH))
7190
+ unlinkSync(STOP_PATH);
7191
+ } catch {}
7192
+ console.log("\uD83D\uDD04 Relaunching daemon...");
7193
+ ensureDirs();
7194
+ const args = Bun.argv.slice(1).filter((a) => a !== "-d" && a !== "--detach" && a !== "restart");
7195
+ if (!args.includes("connect"))
7196
+ args.splice(1, 0, "connect");
7197
+ const proc = Bun.spawn([process.execPath, ...args, "--api", apiUrl], {
7198
+ stdio: ["ignore", "ignore", "ignore"],
7199
+ env: { ...process.env, MULTI_DETACHED: "1" }
7200
+ });
7201
+ proc.unref?.();
7202
+ await sleep(500);
7203
+ console.log(`\u2705 Daemon restarted (pid ${proc.pid}).`);
7204
+ console.log(` Tail logs: multi-agent logs`);
7205
+ process.exit(0);
7206
+ }
7154
7207
  async function cmdLogs() {
7155
7208
  if (!existsSync3(LOG_PATH2)) {
7156
7209
  console.log("No logs yet.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipers-dev/multi",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "multi-agent": "./dist/index.js"
package/src/index.ts CHANGED
@@ -18,7 +18,7 @@ const LOG_PATH = join(MULTI_DIR, 'logs', 'agent.log');
18
18
  const SKILLS_DIR = join(MULTI_DIR, 'skills');
19
19
  const STOP_PATH = join(MULTI_DIR, 'stop.flag');
20
20
  const TASKS_DB_PATH = join(MULTI_DIR, 'tasks.db');
21
- const VERSION = '0.8.0';
21
+ const VERSION = '0.9.1';
22
22
 
23
23
  const COMMANDS = {
24
24
  setup: 'Register this device with a workspace',
@@ -26,6 +26,7 @@ const COMMANDS = {
26
26
  link: 'Link this device to an agent (agent_id required)',
27
27
  status: 'Show current status',
28
28
  stop: 'Stop the running daemon',
29
+ restart: 'Stop and relaunch the daemon in background',
29
30
  logs: 'View execution logs',
30
31
  } as const;
31
32
 
@@ -98,6 +99,9 @@ async function main() {
98
99
  case 'stop':
99
100
  await cmdStop();
100
101
  break;
102
+ case 'restart':
103
+ await cmdRestart(apiUrl);
104
+ break;
101
105
  case 'logs':
102
106
  await cmdLogs();
103
107
  break;
@@ -120,6 +124,7 @@ Commands:
120
124
  connect ${COMMANDS.connect}
121
125
  status ${COMMANDS.status}
122
126
  stop ${COMMANDS.stop}
127
+ restart ${COMMANDS.restart}
123
128
  logs ${COMMANDS.logs}
124
129
 
125
130
  Options:
@@ -989,7 +994,9 @@ async function executePlanActions(apiUrl: string, parentTask: any, actions: Plan
989
994
  const headers = { 'x-agent-id': parentTask.agent_id };
990
995
 
991
996
  // Refresh the set of agents linked to this device once per plan execution.
992
- await ctx.refreshLocalAgents();
997
+ if (typeof ctx.refreshLocalAgents === 'function') {
998
+ try { await ctx.refreshLocalAgents(); } catch {}
999
+ }
993
1000
 
994
1001
  for (const a of actions) {
995
1002
  try {
@@ -1352,6 +1359,40 @@ async function cmdStop() {
1352
1359
  try { process.kill(pid, 'SIGTERM'); console.log(`Sent SIGTERM to ${pid}`); } catch {}
1353
1360
  }
1354
1361
 
1362
+ async function cmdRestart(apiUrl: string) {
1363
+ if (existsSync(PID_PATH)) {
1364
+ const pid = Number(readFileSync(PID_PATH, 'utf8').trim());
1365
+ if (pid && isRunning(pid)) {
1366
+ ensureDirs();
1367
+ writeFileSync(STOP_PATH, '1');
1368
+ try { process.kill(pid, 'SIGTERM'); } catch {}
1369
+ console.log(`⏹ Stopping daemon (pid ${pid})...`);
1370
+ const deadline = Date.now() + 10_000;
1371
+ while (Date.now() < deadline && isRunning(pid)) await sleep(200);
1372
+ if (isRunning(pid)) {
1373
+ try { process.kill(pid, 'SIGKILL'); } catch {}
1374
+ await sleep(300);
1375
+ }
1376
+ }
1377
+ try { if (existsSync(PID_PATH)) unlinkSync(PID_PATH); } catch {}
1378
+ }
1379
+ try { if (existsSync(STOP_PATH)) unlinkSync(STOP_PATH); } catch {}
1380
+ console.log('🔄 Relaunching daemon...');
1381
+ ensureDirs();
1382
+ // Spawn `connect` detached (don't re-exec `restart` — would loop).
1383
+ const args = Bun.argv.slice(1).filter(a => a !== '-d' && a !== '--detach' && a !== 'restart');
1384
+ if (!args.includes('connect')) args.splice(1, 0, 'connect');
1385
+ const proc = Bun.spawn([process.execPath, ...args, '--api', apiUrl], {
1386
+ stdio: ['ignore', 'ignore', 'ignore'],
1387
+ env: { ...process.env, MULTI_DETACHED: '1' },
1388
+ });
1389
+ (proc as any).unref?.();
1390
+ await sleep(500);
1391
+ console.log(`✅ Daemon restarted (pid ${proc.pid}).`);
1392
+ console.log(` Tail logs: multi-agent logs`);
1393
+ process.exit(0);
1394
+ }
1395
+
1355
1396
  async function cmdLogs() {
1356
1397
  if (!existsSync(LOG_PATH)) { console.log('No logs yet.'); return; }
1357
1398
  const content = readFileSync(LOG_PATH, 'utf8');