@sesamespace/hivemind 0.3.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sesamespace/hivemind",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Cognitive architecture for AI agents with multi-layered memory",
5
5
  "scripts": {
6
6
  "build": "pnpm -r build",
@@ -0,0 +1,158 @@
1
+ import { execSync } from "child_process";
2
+ import { resolve } from "path";
3
+ import { existsSync, readFileSync } from "fs";
4
+
5
+ const PACKAGE_NAME = "@sesamespace/hivemind";
6
+
7
+ interface VersionInfo {
8
+ current: string;
9
+ latest: string;
10
+ updateAvailable: boolean;
11
+ }
12
+
13
+ function getCurrentVersion(): string {
14
+ try {
15
+ // Check the installed package version
16
+ const output = execSync(`npm ls -g ${PACKAGE_NAME} --json 2>/dev/null`, { encoding: "utf-8" });
17
+ const parsed = JSON.parse(output);
18
+ const deps = parsed.dependencies?.[PACKAGE_NAME];
19
+ if (deps?.version) return deps.version;
20
+ } catch {
21
+ // Fallback: read from the package.json in the hivemind dir
22
+ }
23
+
24
+ const hivemindHome = process.env.HIVEMIND_HOME || resolve(process.env.HOME || "~", "hivemind");
25
+ const pkgPath = resolve(hivemindHome, "node_modules", PACKAGE_NAME, "package.json");
26
+ if (existsSync(pkgPath)) {
27
+ try {
28
+ return JSON.parse(readFileSync(pkgPath, "utf-8")).version;
29
+ } catch {
30
+ // fall through
31
+ }
32
+ }
33
+
34
+ return "unknown";
35
+ }
36
+
37
+ function getLatestVersion(target?: string): string {
38
+ try {
39
+ const tag = target || "latest";
40
+ const output = execSync(`npm view ${PACKAGE_NAME}@${tag} version 2>/dev/null`, { encoding: "utf-8" });
41
+ return output.trim();
42
+ } catch {
43
+ throw new Error("Failed to check npm registry for latest version");
44
+ }
45
+ }
46
+
47
+ async function checkVersion(target?: string): Promise<VersionInfo> {
48
+ const current = getCurrentVersion();
49
+ const latest = target || getLatestVersion();
50
+ return {
51
+ current,
52
+ latest,
53
+ updateAvailable: current !== latest && current !== "unknown",
54
+ };
55
+ }
56
+
57
+ export async function runUpgradeCommand(args: string[]): Promise<void> {
58
+ const checkOnly = args.includes("--check") || args.includes("-c");
59
+ const force = args.includes("--force") || args.includes("-f");
60
+ const dryRun = args.includes("--dry-run") || args.includes("-n");
61
+
62
+ // Target version (optional positional arg)
63
+ const targetVersion = args.find((a) => !a.startsWith("-"));
64
+
65
+ if (args.includes("--help") || args.includes("-h")) {
66
+ printHelp();
67
+ return;
68
+ }
69
+
70
+ console.log(`
71
+ ╦ ╦╦╦ ╦╔═╗╔╦╗╦╔╗╔╔╦╗
72
+ ╠═╣║╚╗╔╝║╣ ║║║║║║║ ║║
73
+ ╩ ╩╩ ╚╝ ╚═╝╩ ╩╩╝╚╝═╩╝
74
+ Agent Upgrade
75
+ `);
76
+
77
+ // --- Check versions ---
78
+ console.log("→ Checking versions...");
79
+ const info = await checkVersion(targetVersion);
80
+ console.log(` Current: ${info.current}`);
81
+ console.log(` Latest: ${info.latest}`);
82
+
83
+ if (!info.updateAvailable && !force) {
84
+ console.log("\n ✓ Already up to date!");
85
+ return;
86
+ }
87
+
88
+ if (info.updateAvailable) {
89
+ console.log(`\n ⬆ Update available: ${info.current} → ${info.latest}`);
90
+ }
91
+
92
+ if (checkOnly) {
93
+ return;
94
+ }
95
+
96
+ // --- Perform upgrade ---
97
+ const target = targetVersion ? `${PACKAGE_NAME}@${targetVersion}` : `${PACKAGE_NAME}@latest`;
98
+
99
+ if (dryRun) {
100
+ console.log(`\n→ [dry-run] Would run: npm install -g ${target}`);
101
+ console.log("→ [dry-run] Would restart the agent service");
102
+ return;
103
+ }
104
+
105
+ console.log(`\n→ Installing ${target}...`);
106
+ try {
107
+ execSync(`npm install -g ${target}`, { stdio: "inherit" });
108
+ console.log(" ✓ Package updated");
109
+ } catch (err) {
110
+ console.error(` ✗ npm install failed: ${(err as Error).message}`);
111
+ process.exit(1);
112
+ }
113
+
114
+ // --- Restart agent ---
115
+ console.log("\n→ Restarting agent...");
116
+ try {
117
+ // Try launchctl first (macOS service)
118
+ const plistName = "com.hivemind.agent";
119
+ execSync(`launchctl list ${plistName} 2>/dev/null`, { encoding: "utf-8" });
120
+ // Service exists — restart it
121
+ execSync(`launchctl kickstart -k gui/$(id -u)/${plistName}`, { stdio: "inherit" });
122
+ console.log(" ✓ Agent restarted via launchd");
123
+ } catch {
124
+ // No launchd service — try finding and restarting the process
125
+ try {
126
+ execSync("pkill -f 'hivemind start'", { stdio: "inherit" });
127
+ console.log(" ✓ Old process killed");
128
+ console.log(" ! Start the agent manually: hivemind start");
129
+ } catch {
130
+ console.log(" ! No running agent found — start manually: hivemind start");
131
+ }
132
+ }
133
+
134
+ // --- Verify ---
135
+ const newVersion = getCurrentVersion();
136
+ console.log(`\n ✓ Upgrade complete: ${info.current} → ${newVersion}`);
137
+ }
138
+
139
+ function printHelp(): void {
140
+ console.log(`hivemind upgrade — Upgrade the Hivemind agent runtime
141
+
142
+ Usage: hivemind upgrade [version] [options]
143
+
144
+ Arguments:
145
+ version Target version (default: latest)
146
+
147
+ Options:
148
+ -c, --check Check for updates only (don't install)
149
+ -f, --force Force reinstall even if up to date
150
+ -n, --dry-run Show what would happen without doing it
151
+ -h, --help Show this help
152
+
153
+ Examples:
154
+ hivemind upgrade # Upgrade to latest
155
+ hivemind upgrade 0.3.0 # Upgrade to specific version
156
+ hivemind upgrade --check # Just check if update available
157
+ `);
158
+ }
@@ -4,6 +4,7 @@ import { runFleetCommand } from "./commands/fleet.js";
4
4
  import { runStartCommand } from "./commands/start.js";
5
5
  import { runInitCommand } from "./commands/init.js";
6
6
  import { runServiceCommand } from "./commands/service.js";
7
+ import { runUpgradeCommand } from "./commands/upgrade.js";
7
8
 
8
9
  const [command, ...args] = process.argv.slice(2);
9
10
 
@@ -36,14 +37,22 @@ switch (command) {
36
37
  });
37
38
  break;
38
39
 
40
+ case "upgrade":
41
+ runUpgradeCommand(args).catch((err) => {
42
+ console.error(err instanceof Error ? err.message : String(err));
43
+ process.exit(1);
44
+ });
45
+ break;
46
+
39
47
  default:
40
- console.log(`hivemind cli v0.1.0
48
+ console.log(`hivemind cli v0.3.0
41
49
 
42
50
  Usage: hivemind <command> [args]
43
51
 
44
52
  Commands:
45
53
  init Initialize agent from Sesame API key
46
54
  start Start the Hivemind agent
55
+ upgrade Upgrade the Hivemind runtime
47
56
  service Manage launchd services (install/uninstall/status/logs)
48
57
  fleet Manage the worker fleet
49
58
  `);