@nighthawklabs/mission-control 0.0.0-stage → 0.1.0

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/bin/cli.mjs ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ // npx @nighthawklabs/mission-control — set up Mission Control for every harness found (Claude Code, oh-my-pi), then start with `mc claude` or `mc omp`.
3
+ // It runs the bundled mc/install.sh against the bundled mc (MC_SRC=file://...), so the starter matches this package's version. No dependencies.
4
+ // ponytail: POSIX only (the starter is a shell script); a Node port of mc is the upgrade for Windows.
5
+ import { spawnSync } from "node:child_process";
6
+ import { existsSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const args = process.argv.slice(2);
11
+ if (args.includes("--help") || args.includes("-h")) {
12
+ console.log(`mission-control [--no-login]
13
+
14
+ Installs the mc starter and the Mission Control plugin into Claude Code and oh-my-pi (whichever are installed), and signs you in.
15
+ Then run: mc claude or mc omp
16
+ For any other agent that reads skills, it installs the portable skills (npx @nighthawklabs/cookbook).`);
17
+ process.exit(0);
18
+ }
19
+
20
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..", "mc");
21
+ const installer = join(root, "install.sh");
22
+ if (!existsSync(installer)) {
23
+ console.error("mission-control: the bundled installer is missing (run `npm pack` from the repo, or use the published package).");
24
+ process.exit(1);
25
+ }
26
+ if (process.platform === "win32") {
27
+ console.error("mission-control: Windows is not supported yet (the starter is a POSIX shell script). Use WSL.");
28
+ process.exit(1);
29
+ }
30
+
31
+ const has = (cmd) => spawnSync("sh", ["-c", `command -v ${cmd}`], { stdio: "ignore" }).status === 0;
32
+ const env = { ...process.env, MC_SRC: "file://" + join(root, "mc") };
33
+ if (args.includes("--no-login")) env.MC_NO_LOGIN = "1";
34
+ const run = spawnSync("sh", [installer], { stdio: "inherit", env });
35
+ if (run.status !== 0) process.exit(run.status ?? 1);
36
+
37
+ if (!has("claude") && !has("omp")) {
38
+ console.log("\nNeither Claude Code nor oh-my-pi was found: installing the portable skills for other agents.");
39
+ process.exit(spawnSync("npx", ["--yes", "@nighthawklabs/cookbook"], { stdio: "inherit" }).status ?? 0);
40
+ }
package/bin/stage.mjs ADDED
@@ -0,0 +1,8 @@
1
+ // prepack: copy the mc starter and its installer from the repo root into the tarball, so what npx runs is the version that was published, not whatever is on main.
2
+ import { cpSync, mkdirSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ const here = dirname(fileURLToPath(import.meta.url));
6
+ const out = join(here, "..", "mc");
7
+ mkdirSync(out, { recursive: true });
8
+ for (const f of ["mc", "install.sh"]) cpSync(join(here, "..", "..", "..", "mc", f), join(out, f));
package/mc/install.sh ADDED
@@ -0,0 +1,70 @@
1
+ #!/bin/sh
2
+ # One step to set up Mission Control for omp and Claude Code: installs websocat and mc, adds the Mission Control plugin to whichever is installed, and signs you in.
3
+ # curl -fsSL https://raw.githubusercontent.com/realnighthawk/nighthawk-plugins/main/mc/install.sh | sh
4
+ # Safe to run again: it updates what is there. Nothing needs sudo; programs go in ~/.local/bin.
5
+ # MC_NO_LOGIN=1 skips the sign-in at the end.
6
+ set -eu
7
+ BIN=${MC_BIN_DIR:-$HOME/.local/bin}
8
+ SRC=${MC_SRC:-https://raw.githubusercontent.com/realnighthawk/nighthawk-plugins/main/mc/mc}
9
+ MARKETPLACE=mission-control-plugins
10
+ MARKET_URL=https://github.com/realnighthawk/nighthawk-plugins.git
11
+ PLUGIN=mission-control@$MARKETPLACE
12
+
13
+ step() { printf '\n==> %s\n' "$*"; }
14
+ mkdir -p "$BIN"
15
+ PATH="$BIN:$PATH"; export PATH
16
+
17
+ step "websocat (connects omp's browser to your workstation)"
18
+ if command -v websocat >/dev/null 2>&1; then
19
+ echo "already installed: $(command -v websocat)"
20
+ else
21
+ case "$(uname -s)-$(uname -m)" in
22
+ Darwin-arm64) asset=aarch64-apple-darwin ;;
23
+ Darwin-x86_64) asset=x86_64-apple-darwin ;;
24
+ Linux-x86_64) asset=x86_64-unknown-linux-musl ;;
25
+ Linux-aarch64 | Linux-arm64) asset=aarch64-unknown-linux-musl ;;
26
+ *) echo "no websocat build for $(uname -s) $(uname -m): see https://github.com/vi/websocat" >&2; exit 1 ;;
27
+ esac
28
+ curl -fsSL "https://github.com/vi/websocat/releases/latest/download/websocat.$asset" -o "$BIN/websocat"
29
+ chmod +x "$BIN/websocat"
30
+ echo "installed $BIN/websocat"
31
+ fi
32
+
33
+ step "mc"
34
+ curl -fsSL "$SRC" -o "$BIN/mc"
35
+ chmod +x "$BIN/mc"
36
+ echo "installed $BIN/mc"
37
+
38
+ step "the Mission Control plugin for omp"
39
+ if ! command -v omp >/dev/null 2>&1; then
40
+ echo "omp is not installed, so the plugin was skipped. Install oh-my-pi, then run this again." >&2
41
+ else
42
+ # omp exits 0 even when a step fails, so read what it says.
43
+ run() { out=$("$@" 2>&1) || true; printf '%s\n' "$out"; case $out in *"Failed"* | *"failed"* | *"rror"*) return 1 ;; esac; }
44
+ if omp plugin marketplace list 2>&1 | grep -q "$MARKETPLACE"; then run omp plugin marketplace update "$MARKETPLACE"; else run omp plugin marketplace add "$MARKET_URL"; fi
45
+ # Not `plugin upgrade`: it compares the catalog's declared version, which a stale entry leaves unchanged. Reinstall what the marketplace holds.
46
+ run omp plugin install --force "$PLUGIN"
47
+ fi
48
+
49
+ step "the Mission Control plugin for Claude Code"
50
+ if ! command -v claude >/dev/null 2>&1; then
51
+ echo "claude is not installed, so the plugin was skipped."
52
+ else
53
+ claude plugin marketplace add "$MARKET_URL" --scope user 2>&1 || claude plugin marketplace update "$MARKETPLACE" 2>&1 || true
54
+ claude plugin install "$PLUGIN" --scope user 2>&1 || claude plugin update "$PLUGIN" 2>&1 || true
55
+ fi
56
+
57
+ # A program in ~/.local/bin is only found if that directory is on the PATH.
58
+ profile=
59
+ case "${SHELL:-}" in */zsh) profile=$HOME/.zshrc ;; */bash) profile=$HOME/.bashrc ;; esac
60
+ if [ -n "$profile" ] && ! grep -q '\.local/bin' "$profile" 2>/dev/null; then
61
+ printf '\nexport PATH="$HOME/.local/bin:$PATH"\n' >>"$profile"
62
+ echo "added ~/.local/bin to your PATH in $profile (open a new terminal to use it)"
63
+ fi
64
+
65
+ if [ -z "${MC_NO_LOGIN:-}" ]; then
66
+ step "sign in"
67
+ "$BIN/mc" login || echo "sign in later with: mc login"
68
+ fi
69
+
70
+ printf '\nDone. Start with your workstation attached: mc omp or mc claude\n'
package/mc/mc ADDED
@@ -0,0 +1,161 @@
1
+ #!/bin/sh
2
+ # mc: run omp or Claude Code with your Mission Control workstation's browser and memory attached.
3
+ #
4
+ # mc omp [omp arguments] sign in if needed, connect the workstation's browser, start omp
5
+ # mc claude [claude args] the same for Claude Code: browser as the `browser` MCP, memory recalled at start and retained at end by the plugin's hooks
6
+ # mc login sign in again (a link lasts 12 hours)
7
+ # mc status say whether the workstation is reachable
8
+ #
9
+ # It leans on existing tools: curl, python3 (a one-shot listener for the sign-in), websocat (WebSocket to a local port) and omp's own --config.
10
+ # The workstation's browser appears to omp as a local one, at a free port on 127.0.0.1. Nothing is installed besides this file and websocat.
11
+ set -eu
12
+
13
+ ROUTER=${MC_ROUTER_URL:-https://api.nighthawklabs.org}
14
+ WEB=${MC_WEB_URL:-https://mission-control.nighthawklabs.org}
15
+ DIR=${XDG_CONFIG_HOME:-$HOME/.config}/mc
16
+ TOKEN_FILE=$DIR/token
17
+ WS_URL=$(printf '%s' "$ROUTER" | sed -e 's#^https#wss#' -e 's#^http#ws#')/workstation/cdp
18
+
19
+ say() { printf 'mc: %s\n' "$*" >&2; }
20
+ need() { command -v "$1" >/dev/null 2>&1 || { say "$1 is needed. $2"; exit 1; }; }
21
+ free_port() { python3 -c 'import socket;s=socket.socket();s.bind(("127.0.0.1",0));print(s.getsockname()[1])'; }
22
+
23
+ # ok = the router accepted the token and reached the workstation; login = the token is missing or expired; down = no workstation is running.
24
+ probe() {
25
+ code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 15 -H "Authorization: Bearer $1" "$ROUTER/workstation/cdp" || echo 000)
26
+ case $code in
27
+ 400) echo ok ;;
28
+ 401) echo login ;;
29
+ 502) echo down ;;
30
+ *) echo "error $code" ;;
31
+ esac
32
+ }
33
+
34
+ # Sign in through the browser: the Mission Control page, once you confirm, sends the token to a listener on this machine's loopback.
35
+ login() {
36
+ need python3 "It runs the one-time sign-in listener."
37
+ mkdir -p "$DIR" && chmod 700 "$DIR"
38
+ port=$(free_port)
39
+ state=$(python3 -c 'import secrets;print(secrets.token_urlsafe(16))')
40
+ out=$(mktemp)
41
+ MC_STATE=$state MC_OUT=$out python3 - "$port" <<'PY' &
42
+ import http.server, os, sys, time, urllib.parse
43
+ state, out = os.environ["MC_STATE"], os.environ["MC_OUT"]
44
+ class H(http.server.BaseHTTPRequestHandler):
45
+ def do_GET(self):
46
+ q = urllib.parse.urlparse(self.path)
47
+ p = urllib.parse.parse_qs(q.query)
48
+ ok = q.path == "/callback" and p.get("state") == [state] and p.get("token")
49
+ if ok:
50
+ fd = os.open(out, os.O_WRONLY | os.O_TRUNC, 0o600)
51
+ os.write(fd, p["token"][0].encode()); os.close(fd)
52
+ self.send_response(200 if ok else 400)
53
+ self.send_header("Content-Type", "text/plain; charset=utf-8"); self.end_headers()
54
+ self.wfile.write(b"Connected. You can close this tab." if ok else b"Not the sign-in mc is waiting for.")
55
+ def log_message(self, *a): pass
56
+ srv = http.server.HTTPServer(("127.0.0.1", int(sys.argv[1])), H)
57
+ srv.timeout = 5
58
+ end = time.time() + 180
59
+ while time.time() < end and not os.path.getsize(out):
60
+ srv.handle_request()
61
+ PY
62
+ listener=$!
63
+ url="$WEB/connect?port=$port&state=$state"
64
+ say "opening $url"
65
+ (open "$url" || xdg-open "$url") >/dev/null 2>&1 || say "open that address in your browser"
66
+ wait "$listener" || true
67
+ if [ ! -s "$out" ]; then rm -f "$out"; say "no sign-in came back in 3 minutes"; exit 1; fi
68
+ mv "$out" "$TOKEN_FILE" && chmod 600 "$TOKEN_FILE"
69
+ say "signed in"
70
+ }
71
+
72
+ # Make sure there is a token that works. Sets TOKEN and STATE (ok or down).
73
+ ensure() {
74
+ TOKEN=$(cat "$TOKEN_FILE" 2>/dev/null || true)
75
+ STATE=$([ -n "$TOKEN" ] && probe "$TOKEN" || echo login)
76
+ if [ "$STATE" = login ]; then
77
+ login
78
+ TOKEN=$(cat "$TOKEN_FILE")
79
+ STATE=$(probe "$TOKEN")
80
+ fi
81
+ case $STATE in ok | down) ;; *) say "the router answered unexpectedly ($STATE)"; exit 1 ;; esac
82
+ }
83
+
84
+ # Tell Mission Control this session exists, so the Agents page lists it. One beat now and every 30 seconds; a last "offline" on exit. It reports where omp runs
85
+ # (machine, folder, version), not what is said in it, and a failed beat is ignored: it never gets in omp's way.
86
+ beat() {
87
+ body=$(printf '{"session_id":"%s","host":"%s","state":"%s","now":"Running in %s","cwd":"%s","version":"%s"}' \
88
+ "$SESSION" "$HOST" "$1" "$(printf '%s' "$PWD" | sed -e "s#^$HOME#~#" -e 's/["\\]/_/g')" "$(printf '%s' "$PWD" | sed 's/["\\]/_/g')" "$OMP_VERSION")
89
+ curl -s -o /dev/null --max-time 10 -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' -d "$body" "$ROUTER/local-agents/heartbeat" || true
90
+ }
91
+ start_beats() {
92
+ SESSION=$(python3 -c 'import secrets;print(secrets.token_hex(8))' 2>/dev/null || date +%s%N)
93
+ HOST=$(hostname -s 2>/dev/null | tr -c 'A-Za-z0-9._-\n' '_' || echo unknown)
94
+ OMP_VERSION=$("${AGENT_CMD:-omp}" --version 2>/dev/null | head -1 | tr -c 'A-Za-z0-9._ -\n' '_' || true)
95
+ ( while :; do beat idle; sleep 30; done ) &
96
+ beater=$!
97
+ }
98
+ stop_beats() {
99
+ if [ -n "${beater:-}" ]; then kill "$beater" 2>/dev/null || true; beat offline; fi
100
+ }
101
+
102
+ cmd=${1:-}
103
+ case $cmd in
104
+ login) login ;;
105
+ status)
106
+ ensure
107
+ if [ "$STATE" = ok ]; then say "connected: your workstation is reachable"; else say "your workstation is not running: create it at $WEB/workstation"; fi
108
+ ;;
109
+ omp)
110
+ shift
111
+ need omp "Install oh-my-pi first."
112
+ ensure
113
+ tmp=$(mktemp -d)
114
+ trap 'stop_beats; kill "${tunnel:-}" 2>/dev/null || true; rm -rf "$tmp"' EXIT INT TERM
115
+ start_beats
116
+ # Memory is oh-my-pi's own (its hindsight backend) on your workspace's memory server, through the router: recalled at the start of a turn, retained at the end.
117
+ # The token goes in the environment, not in the file.
118
+ printf 'memory:\n backend: hindsight\nhindsight:\n apiUrl: %s/memory\n bankId: ohmypi\n scoping: global\n mentalModelsEnabled: false\n mentalModelAutoSeed: false\n' "$ROUTER" >"$tmp/omp.yml"
119
+ export HINDSIGHT_API_TOKEN=$TOKEN MISSION_CONTROL_NATIVE_MEMORY=1
120
+ if [ "$STATE" = down ]; then
121
+ say "your workstation is not running, so omp starts without it. Create it at $WEB/workstation, then run mc omp again."
122
+ omp --config "$tmp/omp.yml" "$@"
123
+ exit $?
124
+ fi
125
+ need websocat "Install it: brew install websocat (macOS), or see https://github.com/vi/websocat"
126
+ port=$(free_port)
127
+ printf 'browser:\n cdpUrl: http://127.0.0.1:%s\n' "$port" >>"$tmp/omp.yml"
128
+ # -H takes every argument after it as a header, so it goes last.
129
+ websocat -b "tcp-l:127.0.0.1:$port" "$WS_URL" -H "Authorization: Bearer $TOKEN" >/dev/null 2>&1 &
130
+ tunnel=$!
131
+ say "your workstation's browser is attached (127.0.0.1:$port)"
132
+ omp --config "$tmp/omp.yml" "$@"
133
+ ;;
134
+ claude)
135
+ shift
136
+ need claude "Install Claude Code first."
137
+ ensure
138
+ AGENT_CMD=claude
139
+ tmp=$(mktemp -d)
140
+ trap 'stop_beats; kill "${tunnel:-}" 2>/dev/null || true; rm -rf "$tmp"' EXIT INT TERM
141
+ start_beats
142
+ # Claude Code has no memory or browser slot, so the plugin's hooks do the memory over the router's REST API (they read these three), and the browser is an MCP.
143
+ export MC_MEMORY_URL=$ROUTER/memory MC_MEMORY_TOKEN=$TOKEN MC_MEMORY_BANK=${MC_MEMORY_BANK:-claude-code}
144
+ if [ "$STATE" = down ]; then
145
+ say "your workstation is not running, so Claude Code starts without a browser. Create it at $WEB/workstation, then run mc claude again."
146
+ claude "$@"
147
+ exit $?
148
+ fi
149
+ need websocat "Install it: brew install websocat (macOS), or see https://github.com/vi/websocat"
150
+ port=$(free_port)
151
+ websocat -b "tcp-l:127.0.0.1:$port" "$WS_URL" -H "Authorization: Bearer $TOKEN" >/dev/null 2>&1 &
152
+ tunnel=$!
153
+ printf '{"mcpServers":{"browser":{"command":"npx","args":["-y","@playwright/mcp@latest","--cdp-endpoint","http://127.0.0.1:%s"]}}}' "$port" >"$tmp/mcp.json"
154
+ say "your workstation's browser is attached as the browser MCP (127.0.0.1:$port)"
155
+ claude --mcp-config "$tmp/mcp.json" --append-system-prompt "Browser work uses the browser MCP tools. They drive the person's own workstation browser, which keeps their saved logins. There is no other browser; if it cannot connect, say so once." "$@"
156
+ ;;
157
+ *)
158
+ say "usage: mc omp [omp arguments] | mc claude [claude arguments] | mc login | mc status"
159
+ exit 2
160
+ ;;
161
+ esac
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
1
  {
2
2
  "name": "@nighthawklabs/mission-control",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "One command to set up Mission Control for Claude Code and oh-my-pi: the plugin, the mc starter, the workstation browser, and sign-in.",
5
+ "type": "module",
6
+ "bin": { "mission-control": "bin/cli.mjs" },
7
+ "files": ["bin/", "mc/"],
8
+ "engines": { "node": ">=18" },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/realnighthawk/nighthawk-plugins.git",
13
+ "directory": "packages/mission-control"
14
+ },
15
+ "publishConfig": { "access": "public" },
16
+ "scripts": {
17
+ "prepack": "node bin/stage.mjs",
18
+ "test": "node bin/cli.mjs --help"
19
+ }
20
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.