mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 04:36:59 +01:00
chore: delete the bash daemon and bridge files (Session 4b)
Session 4 of killing-the-bash-daemon plan, commit B — removes the
14 bash files that constituted the local execution stack the
TS consumers no longer reach (Session 4a wired Fleet Runner as the
sole local executor + retired the bundle endpoint).
Deleted (-4258 LoC):
scripts/fleetcrown-daemon.sh (1612)
scripts/agent-hook-bridge.sh ( 942)
scripts/agent-hook-lib.sh ( 528)
scripts/install-beacon.sh ( 214)
scripts/install-fleetcrown-daemon.sh ( 206)
scripts/fleetcrown-beacon-window.sh ( 111)
scripts/install-fleetcrown-beacon-window.sh ( 68)
scripts/_brand.sh ( 61)
scripts/smoke-beacon-stop.sh ( 63)
scripts/check-agent-runtime.sh ( 57)
scripts/install-fleetcrown-hooks.sh ( 53)
scripts/_agents.sh ( 47)
scripts/run-codex-task.sh ( 37)
scripts/run-gemini-task.sh ( 33)
Plus next.config.ts cleanup: the outputFileTracingIncludes block
for /api/agent/daemon listed 15 source paths (8 bash + 7 Python)
that Vercel's build needed in the deployment bundle. The route now
returns 410 Gone (Session 4a), so none of those paths need to be
traced — saves a few MB on each deploy and removes a class of
"build references deleted file" failures.
Net for Session 4 (a+b): -5527 LoC.
What survives:
Operational scripts unrelated to the bash daemon —
scripts/check-design-system.sh
scripts/control-states.generated.sh (regenerated by tsx)
scripts/deploy-local.sh
scripts/fleetcrown-app.sh
scripts/install-fleetcrown-app.sh
scripts/import-from-local.sh
scripts/migrate-local-to-neon.sh
scripts/mirror-desktop-release.sh
scripts/smoke.sh
scripts/test-home.sh
scripts/wait-for-vercel.sh
Plus the *.ts/*.mjs helpers under scripts/ that build the agent
bundle, run tests, generate types, etc.
Remaining ambient bash references in TS are doc comments naming
deleted files (orchestration/run, inject route, projects, watcher,
poller, config/brand, brand-env, control-presenter). They don't
break the build; they get swept in Session 4c (rename pass) along
with the cockpit→fleetcrown stale references.
The Python beacon stack (scripts/beacon.py, _beacon_config.py,
get-idle-secs.py, notify-choice.py, sync-agent-runtime-config.py,
transcribe.py) is left in place for this commit. It was called
only by the deleted bash bridge and is functionally dead, but it's
orthogonal to "no bash" — best handled in a follow-up Python-deletion
commit so this PR stays focused.
Verification: tsc clean, test:home 97/97, test:autopilot-defaults
11/11, test:dispatch-gates 11/11.
The acid test from content/thoughts/killing-the-bash-daemon.md is
fully met on this commit: `ps auxf | grep -E "bash|fleet"` shows
only fleet-runner-bin + next-server as FleetCrown-related processes.
A customer downloading Fleet Runner today never runs bash; the
founder's machine matches that stack.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a3f470ded7
commit
956ccf64c1
15 files changed
+3
-4279
No files matched your search
+3
-21
@@ -44,27 +44,9 @@ const nextConfig: NextConfig = {
|
||||
// isn't published to npm yet and the repo is private). Without explicit
|
||||
// tracing, Vercel would tree-shake the file out of the deployment bundle.
|
||||
"/api/agent/install": ["./packages/agent/bin/**"],
|
||||
// Serves the bash + python daemon bundle so a new customer can install
|
||||
// the full local execution surface without cloning the repo. Keep this
|
||||
// list in sync with FILES in src/app/api/agent/daemon/route.ts —
|
||||
// anything not traced here gets tree-shaken out of the deployment.
|
||||
"/api/agent/daemon": [
|
||||
"./scripts/fleetcrown-daemon.sh",
|
||||
"./scripts/fleet",
|
||||
"./scripts/_brand.sh",
|
||||
"./scripts/_agents.sh",
|
||||
"./scripts/agent-hook-lib.sh",
|
||||
"./scripts/agent-hook-bridge.sh",
|
||||
"./scripts/run-codex-task.sh",
|
||||
"./scripts/run-gemini-task.sh",
|
||||
"./scripts/install-fleetcrown-daemon.sh",
|
||||
"./scripts/beacon.py",
|
||||
"./scripts/_beacon_config.py",
|
||||
"./scripts/get-idle-secs.py",
|
||||
"./scripts/notify-choice.py",
|
||||
"./scripts/sync-agent-runtime-config.py",
|
||||
"./scripts/transcribe.py",
|
||||
],
|
||||
// /api/agent/daemon's bash + python bundle entries are gone — Session 4 of
|
||||
// killing-the-bash-daemon (2026-06-11) deleted the source files and the
|
||||
// route now returns 410 Gone pointing at /download for Fleet Runner.
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# _agents.sh — Single Source of Truth (bash mirror) for supported CLI agents.
|
||||
#
|
||||
# This file is intentionally small and the ONLY place in the bash layer that lists
|
||||
# agent-specific behavior for runtime (scanning, launch, quit, session dir).
|
||||
#
|
||||
# PRIMARY SSOT: src/lib/agent-registry.ts
|
||||
# - When adding a new agent, update the TypeScript registry first.
|
||||
# - Then add the corresponding entry here (keep the two in sync).
|
||||
# - Future improvement: generate this file from the TS registry at daemon tarball build time.
|
||||
#
|
||||
# Format: simple associative arrays + helper functions.
|
||||
# Adding a new agent should only require touching this file + the TS registry.
|
||||
|
||||
# Supported agents (keep in sync with AGENT_IDS in src/lib/agent-registry.ts)
|
||||
AGENTS=(claude grok codex gemini cursor openclaw)
|
||||
|
||||
# Process basenames to recognize as this agent (used by _scan_agents)
|
||||
declare -A AGENT_PROCESS_NAMES=(
|
||||
[claude]="claude"
|
||||
[grok]="grok"
|
||||
[codex]="codex"
|
||||
[gemini]="gemini"
|
||||
[cursor]="agent" # special: we do extra path checks in the scanner
|
||||
[openclaw]="openclaw"
|
||||
)
|
||||
|
||||
# Graceful quit command to send when switching away from this agent
|
||||
declare -A AGENT_QUIT_CMD=(
|
||||
[claude]="/exit"
|
||||
[grok]="/exit"
|
||||
[codex]="q"
|
||||
[gemini]="q"
|
||||
[cursor]=""
|
||||
[openclaw]="q"
|
||||
)
|
||||
|
||||
# Official one-liner / command the user should run to install the CLI for the first time.
|
||||
# These are shown in the web UI and injected by the "Install" flow.
|
||||
declare -A AGENT_INSTALL_CMD=(
|
||||
[claude]="curl -fsSL https://claude.ai/install.sh | bash || echo 'Visit https://claude.ai for manual instructions'"
|
||||
[grok]="curl -fsSL https://x.ai/cli/install.sh | bash"
|
||||
[codex]="echo 'Codex install instructions at https://platform.openai.com/docs/guides/code' ; echo 'Typically: pip install openai or use the official binary'"
|
||||
[gemini]="echo 'Install Google Gemini CLI from https://ai.google.dev/gemini-api/docs/cli'"
|
||||
[cursor]="curl https://cursor.com/install -fsS | bash"
|
||||
[openclaw]="echo 'OpenClaw: see project docs for installation'"
|
||||
)
|
||||
|
||||
# Command to launch the agent in a given directory.
|
||||
# Usage: eval "$(_agent_launch_cmd "grok" "/path/to/project" "$model")"
|
||||
_agent_launch_cmd() {
|
||||
local agent="$1" dir="$2" model="${3:-}"
|
||||
local esc_dir
|
||||
esc_dir=$(printf '%q' "$dir")
|
||||
|
||||
case "$agent" in
|
||||
claude)
|
||||
echo "source ~/.bashrc >/dev/null 2>&1 || true; cd ${esc_dir} && claude"
|
||||
;;
|
||||
grok)
|
||||
echo "source ~/.bashrc >/dev/null 2>&1 || true; cd ${esc_dir} && grok"
|
||||
;;
|
||||
gemini)
|
||||
local mflag=""
|
||||
[ -n "$model" ] && mflag=" -m $(printf '%q' "$model")"
|
||||
echo "source ~/.bashrc >/dev/null 2>&1 || true; cd ${esc_dir} && gemini${mflag}"
|
||||
;;
|
||||
codex)
|
||||
local esc_model
|
||||
esc_model=$(printf '%q' "${model:-gpt-5.4}")
|
||||
echo "source ~/.bashrc >/dev/null 2>&1 || true; cd ${esc_dir} && codex --model ${esc_model} --no-alt-screen"
|
||||
;;
|
||||
cursor)
|
||||
echo "source ~/.bashrc >/dev/null 2>&1 || true; cd ${esc_dir} && agent"
|
||||
;;
|
||||
openclaw)
|
||||
echo "source ~/.bashrc >/dev/null 2>&1 || true; cd ${esc_dir} && openclaw tui"
|
||||
;;
|
||||
*)
|
||||
echo ""
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Session directory for FleetCrown handoff files (done:/next:/status: etc.).
|
||||
# Only agents with strong native session stores get a special dir.
|
||||
# Everyone else uses the standard FleetCrown convention (currently ~/.claude/sessions for compatibility).
|
||||
_agent_session_dir() {
|
||||
local agent="${1:-claude}"
|
||||
case "$agent" in
|
||||
grok) echo "$HOME/.grok/sessions" ;;
|
||||
claude) echo "$HOME/.claude/sessions" ;;
|
||||
*) echo "$HOME/.claude/sessions" ;; # safe default for codex/gemini/cursor/openclaw handoff
|
||||
esac
|
||||
}
|
||||
|
||||
# Emit "<mtime>|<label>" for a fresh, project-scoped native activity signal,
|
||||
# when an adapter provides one. Hooks and /proc remain the universal baseline;
|
||||
# this optional capability covers prompts typed directly inside a supported TUI.
|
||||
_agent_direct_activity() {
|
||||
local agent="$1" dir="$2" file="" encoded_dir
|
||||
case "$agent" in
|
||||
grok)
|
||||
encoded_dir=$(printf '%s' "$dir" | sed 's#/#%2F#g')
|
||||
file=$(find "$HOME/.grok/sessions/$encoded_dir" -name updates.jsonl -printf '%T@ %p\n' 2>/dev/null \
|
||||
| sort -nr | head -1 | cut -d' ' -f2-)
|
||||
[ -n "$file" ] && printf '%s|Direct terminal activity\n' "$(stat -c '%Y' "$file" 2>/dev/null)"
|
||||
;;
|
||||
claude)
|
||||
# Claude Code stores per-project transcripts at
|
||||
# ~/.claude/projects/<dashed-cwd>/<session_uuid>.jsonl; the dir name is the
|
||||
# absolute path with every "/" replaced by "-". mtime updates on every
|
||||
# appended event, so a fresh mtime is reliable evidence the agent is
|
||||
# actively processing — including prompts the user typed directly into
|
||||
# the TUI (no FleetCrown dispatch sentinel exists for those).
|
||||
encoded_dir=$(printf '%s' "$dir" | tr '/' '-')
|
||||
file=$(find "$HOME/.claude/projects/$encoded_dir" -maxdepth 1 -name '*.jsonl' -printf '%T@ %p\n' 2>/dev/null \
|
||||
| sort -nr | head -1 | cut -d' ' -f2-)
|
||||
[ -n "$file" ] && printf '%s|Direct terminal activity\n' "$(stat -c '%Y' "$file" 2>/dev/null)"
|
||||
;;
|
||||
cursor)
|
||||
# Cursor Agent CLI writes agent transcripts under
|
||||
# ~/.cursor/projects/<cwd-without-leading-slash-dashes>/agent-transcripts/.
|
||||
encoded_dir=$(printf '%s' "${dir#/}" | tr '/' '-')
|
||||
file=$(find "$HOME/.cursor/projects/$encoded_dir/agent-transcripts" -name '*.jsonl' -printf '%T@ %p\n' 2>/dev/null \
|
||||
| sort -nr | head -1 | cut -d' ' -f2-)
|
||||
[ -n "$file" ] && printf '%s|Direct terminal activity\n' "$(stat -c '%Y' "$file" 2>/dev/null)"
|
||||
;;
|
||||
# Add adapters here only when they expose a stable, project-scoped log.
|
||||
# Process detection, handoffs, and web-dispatched prompts work without it.
|
||||
esac
|
||||
}
|
||||
|
||||
# Returns 0 if the given basename+full argv looks like the Cursor agent (not a random "agent" binary).
|
||||
_is_cursor_agent() {
|
||||
local basename="$1" argv0="$2"
|
||||
if [[ "$basename" == "cursor-agent" ]]; then
|
||||
[[ "$argv0" == *"cursor-agent"* ]] || [[ "$argv0" == *"/.cursor/"* ]]
|
||||
return $?
|
||||
fi
|
||||
[[ "$basename" == "agent" ]] && { [[ "$argv0" == *".local/bin/agent"* ]] || [[ "$argv0" == *"/.cursor/"* ]]; }
|
||||
}
|
||||
|
||||
# Convenience: list of process names we care about (for scanners)
|
||||
_agent_all_process_names() {
|
||||
printf '%s\n' "${AGENT_PROCESS_NAMES[@]}"
|
||||
}
|
||||
|
||||
# Scan /proc once; output lines of "<cwd> <agent_id>" for all running agents.
|
||||
# Shared by the daemon runtime push and live-adapter resolution in hooks.
|
||||
_scan_agents() {
|
||||
for pd in /proc/[0-9]*/; do
|
||||
pd="${pd%/}"
|
||||
[ -f "$pd/cmdline" ] || continue
|
||||
local argv0 basename agent_id=""
|
||||
argv0=$(tr '\0' '\n' < "$pd/cmdline" 2>/dev/null | head -1) || continue
|
||||
basename="${argv0##*/}"
|
||||
|
||||
for a in "${AGENTS[@]}"; do
|
||||
if [ "$a" = "cursor" ]; then
|
||||
_is_cursor_agent "$basename" "$argv0" || continue
|
||||
agent_id="$a"
|
||||
break
|
||||
fi
|
||||
local expected="${AGENT_PROCESS_NAMES[$a]}"
|
||||
if [ "$basename" = "$expected" ]; then
|
||||
agent_id="$a"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
[ -z "$agent_id" ] && continue
|
||||
|
||||
local cwd
|
||||
cwd=$(readlink "$pd/cwd" 2>/dev/null) || continue
|
||||
echo "$cwd $agent_id"
|
||||
done
|
||||
}
|
||||
|
||||
# Infer adapter from Zellij tab suffix: "FleetCrown Cursor" → cursor.
|
||||
_infer_adapter_from_tab_name() {
|
||||
local tab="$1"
|
||||
local lower="${tab,,}"
|
||||
local suffix
|
||||
for suffix in grok claude codex gemini cursor openclaw; do
|
||||
if [ "$lower" = "$suffix" ] || [[ "$lower" == *" ${suffix}" ]] || [[ "$lower" == *"-${suffix}" ]]; then
|
||||
echo "$suffix"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Single source of truth for the product brand on the shell side.
|
||||
# Mirrors src/config/brand.ts on the TypeScript side. To rebrand the entire
|
||||
# product, edit this file + src/config/brand.ts + the vercel.json alias +
|
||||
# DNS at the registrar — that's it.
|
||||
#
|
||||
# Visual + name rules live in brand.ts (control window mark, fleet-language
|
||||
# requirement, serious control-plane tone, TM/domain ownability, etc.).
|
||||
# Keep the two files in sync on APP_* values only.
|
||||
#
|
||||
# Sourced by: fleetcrown-daemon.sh, agent-hook-bridge.sh, fleetcrown-beacon-window.sh,
|
||||
# install-*.sh, beacon.py (via _beacon_config.py).
|
||||
|
||||
# Display name. Appears in log lines, install prompts.
|
||||
APP_NAME="FleetCrown"
|
||||
|
||||
# Lowercase kebab-case identifier. Used in /tmp/<slug>-* paths, env var
|
||||
# prefixes, package names. Changing this requires migrating any on-disk
|
||||
# state (running daemons should be restarted).
|
||||
APP_SLUG="fleetcrown"
|
||||
|
||||
# Canonical hostname for the remote deployment. Used by the daemon when no
|
||||
# local server is reachable. Override via COCKPIT_BASE_URL / APP_BASE_URL.
|
||||
APP_DOMAIN="fleetcrown.vercel.app"
|
||||
|
||||
# Resolve an env var by name preferring APP_*, then FLEETCROWN_* (current slug),
|
||||
# then COCKPIT_* (legacy) for transition. Used to migrate env-var names
|
||||
# gradually without breaking machines that already export old prefixes.
|
||||
# _brand_env DAEMON_TOKEN "" → $APP_DAEMON_TOKEN || $FLEETCROWN_DAEMON_TOKEN || $COCKPIT_DAEMON_TOKEN || ""
|
||||
_brand_env() {
|
||||
local suffix="$1" default="${2:-}"
|
||||
local app_var="APP_${suffix}"
|
||||
local slug_var="FLEETCROWN_${suffix}"
|
||||
local legacy_var="COCKPIT_${suffix}"
|
||||
echo "${!app_var:-${!slug_var:-${!legacy_var:-$default}}}"
|
||||
}
|
||||
|
||||
# Convenience: build /tmp paths through APP_SLUG so a rename moves them
|
||||
# automatically. Usage: _brand_tmp "run-${tab}" → /tmp/fleetcrown-run-<tab>
|
||||
_brand_tmp() {
|
||||
echo "/tmp/${APP_SLUG}-${1}"
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,547 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Shared utilities for local agent hooks.
|
||||
# This file is FleetCrown-owned so runtime glue can remain thin in dotfiles.
|
||||
|
||||
_CONF="${AGENT_PROJECTS_CONF:-${CLAUDE_PROJECTS_CONF:-$HOME/.config/agent-projects.conf}}"
|
||||
_PROMPTS="${AGENT_PROMPTS_FILE:-${CLAUDE_PROMPTS:-$HOME/.config/agent-prompts.json}}"
|
||||
_DBUS="unix:path=/run/user/$(id -u)/bus"
|
||||
|
||||
# Source the centralized agent definitions (bash mirror of src/lib/agent-registry.ts)
|
||||
# shellcheck source=_agents.sh
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/_agents.sh" 2>/dev/null || true
|
||||
|
||||
# FleetCrown handoff session directory per adapter.
|
||||
# Delegates to the centralized definition in _agents.sh (the bash mirror of the registry).
|
||||
_session_dir() {
|
||||
_agent_session_dir "${1:-claude}"
|
||||
}
|
||||
|
||||
_session_file() {
|
||||
local tab="$1" adapter="${2:-claude}"
|
||||
echo "$(_session_dir "$adapter")/${tab}.md"
|
||||
}
|
||||
|
||||
# Look up the declared adapter for a tab from the projects conf (3rd field).
|
||||
# Falls back to "claude" (the historical default). Case-insensitive tab match.
|
||||
resolve_adapter() {
|
||||
ADAPTER="claude"
|
||||
[ -z "${TAB_NAME:-}" ] && return
|
||||
[ -f "$_CONF" ] || return
|
||||
local lower_tab="${TAB_NAME,,}"
|
||||
while IFS='|' read -r t d a || [ -n "$t" ]; do
|
||||
[[ "$t" =~ ^[[:space:]]*# ]] && continue
|
||||
if [ -z "$t" ] || [ -z "$d" ]; then
|
||||
continue
|
||||
fi
|
||||
local tl="${t,,}"; tl="${tl%%[[:space:]]}"
|
||||
if [ "$tl" = "$lower_tab" ]; then
|
||||
local aa="$(echo "$a" | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')"
|
||||
case "$aa" in
|
||||
grok|claude|codex|gemini|openclaw|cursor) ADAPTER="$aa" ;;
|
||||
*) ADAPTER="claude" ;;
|
||||
esac
|
||||
return
|
||||
fi
|
||||
done < "$_CONF"
|
||||
}
|
||||
|
||||
# Look up the third (agent) column for a tab in agent-projects.conf. Empty
|
||||
# output means either the conf is unreadable, the tab isn't registered, or
|
||||
# the agent column is blank. Handles legacy 3-col lines and current 4-col
|
||||
# (tab|dir|agent|model) lines transparently — the unused 4th field is just
|
||||
# ignored.
|
||||
_conf_agent_for_tab() {
|
||||
local tab="$1" conf
|
||||
conf="${AGENT_PROJECTS_CONF:-${CLAUDE_PROJECTS_CONF:-$HOME/.config/agent-projects.conf}}"
|
||||
[ -r "$conf" ] || return 1
|
||||
local t _d a _m
|
||||
while IFS='|' read -r t _d a _m || [ -n "$t" ]; do
|
||||
[[ "$t" =~ ^[[:space:]]*# ]] && continue
|
||||
t=$(echo "$t" | xargs 2>/dev/null)
|
||||
[ -z "$t" ] && continue
|
||||
if [ "${t,,}" = "${tab,,}" ]; then
|
||||
a=$(echo "$a" | xargs 2>/dev/null)
|
||||
[ -n "$a" ] && { printf '%s\n' "$a"; return 0; }
|
||||
return 1
|
||||
fi
|
||||
done < "$conf"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Look up the fourth (model) column. Same shape as _conf_agent_for_tab.
|
||||
# Returns 1 (no output) for legacy 3-col conf lines or blank model field —
|
||||
# callers should default to the agent's built-in model in that case.
|
||||
_conf_model_for_tab() {
|
||||
local tab="$1" conf
|
||||
conf="${AGENT_PROJECTS_CONF:-${CLAUDE_PROJECTS_CONF:-$HOME/.config/agent-projects.conf}}"
|
||||
[ -r "$conf" ] || return 1
|
||||
local t _d _a m
|
||||
while IFS='|' read -r t _d _a m || [ -n "$t" ]; do
|
||||
[[ "$t" =~ ^[[:space:]]*# ]] && continue
|
||||
t=$(echo "$t" | xargs 2>/dev/null)
|
||||
[ -z "$t" ] && continue
|
||||
if [ "${t,,}" = "${tab,,}" ]; then
|
||||
m=$(echo "$m" | xargs 2>/dev/null)
|
||||
[ -n "$m" ] && { printf '%s\n' "$m"; return 0; }
|
||||
return 1
|
||||
fi
|
||||
done < "$conf"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Resolve the adapter actually running in a tab — not just the conf default.
|
||||
# Priority: /proc scan for project dir → current-prompt JSON adapter →
|
||||
# agent-projects.conf agent column → tab suffix → legacy resolve_adapter →
|
||||
# "claude" default. Sets ADAPTER and returns 0. Requires _agents.sh (sourced
|
||||
# above). The conf-column read closes the gap where direct hook invocations
|
||||
# (stop hook, beacon, autopilot watchdog) bypass /api/inject and would
|
||||
# otherwise default a Gemini/Cursor project to Claude on launch.
|
||||
_resolve_live_adapter() {
|
||||
local tab="$1" dir="${2:-}"
|
||||
ADAPTER=""
|
||||
|
||||
if [ -n "$dir" ] && type _scan_agents >/dev/null 2>&1; then
|
||||
while IFS=' ' read -r cwd aname; do
|
||||
[ -z "$cwd" ] && continue
|
||||
if [ "$cwd" = "$dir" ] || [[ "$cwd" == "$dir/"* ]]; then
|
||||
ADAPTER="$aname"
|
||||
return 0
|
||||
fi
|
||||
done < <(_scan_agents 2>/dev/null)
|
||||
fi
|
||||
|
||||
local pf="/tmp/agent-current-prompt-${tab}"
|
||||
if [ -f "$pf" ]; then
|
||||
local from_prompt
|
||||
from_prompt=$(jq -r '.adapter // empty' "$pf" 2>/dev/null || true)
|
||||
case "$from_prompt" in
|
||||
grok|claude|codex|gemini|openclaw|cursor)
|
||||
ADAPTER="$from_prompt"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
local from_conf
|
||||
from_conf=$(_conf_agent_for_tab "$tab" 2>/dev/null || true)
|
||||
case "$from_conf" in
|
||||
grok|claude|codex|gemini|openclaw|cursor)
|
||||
ADAPTER="$from_conf"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if type _infer_adapter_from_tab_name >/dev/null 2>&1; then
|
||||
local inferred
|
||||
inferred=$(_infer_adapter_from_tab_name "$tab" 2>/dev/null || true)
|
||||
case "$inferred" in
|
||||
grok|claude|codex|gemini|openclaw|cursor)
|
||||
ADAPTER="$inferred"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
TAB_NAME="$tab"
|
||||
resolve_adapter 2>/dev/null || true
|
||||
ADAPTER="${ADAPTER:-claude}"
|
||||
}
|
||||
|
||||
resolve_tab() {
|
||||
TAB_NAME=""
|
||||
local cwd
|
||||
cwd=$(realpath "$1" 2>/dev/null)
|
||||
|
||||
local actual_tabs
|
||||
actual_tabs=$(timeout 3 zellij action query-tab-names 2>/dev/null)
|
||||
[ -z "$actual_tabs" ] && return
|
||||
|
||||
if [ -n "${AGENT_TAB_NAME:-}" ]; then
|
||||
local requested_tab
|
||||
requested_tab=$(printf '%s\n' "$actual_tabs" | while IFS= read -r t; do
|
||||
[ "${t,,}" = "${AGENT_TAB_NAME,,}" ] && printf '%s' "$t" && break
|
||||
done)
|
||||
if [ -n "$requested_tab" ]; then
|
||||
TAB_NAME="$requested_tab"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fast path: pane identity file written by the claude() wrapper at launch time.
|
||||
# ZELLIJ_PANE_ID is inherited from the zellij environment by Claude and its subprocesses.
|
||||
# This is the most reliable resolution path when multiple tabs share the same directory.
|
||||
local pane_id="${ZELLIJ_PANE_ID:-}"
|
||||
if [ -n "$pane_id" ] && [ -f "/tmp/claude-pane-${pane_id}" ]; then
|
||||
local pane_tab
|
||||
pane_tab=$(cat "/tmp/claude-pane-${pane_id}" 2>/dev/null | tr -d '[:space:]')
|
||||
if [ -n "$pane_tab" ]; then
|
||||
local match
|
||||
match=$(printf '%s\n' "$actual_tabs" | while IFS= read -r t; do
|
||||
[ "${t,,}" = "${pane_tab,,}" ] && printf '%s' "$t" && break
|
||||
done)
|
||||
if [ -n "$match" ]; then
|
||||
TAB_NAME="$match"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
local shell_pid
|
||||
shell_pid=$(ps -o ppid= -p "$PPID" 2>/dev/null | tr -d ' ')
|
||||
if [ -n "$shell_pid" ]; then
|
||||
if [ -f "/tmp/agent-tab-${shell_pid}" ]; then
|
||||
TAB_NAME=$(cat "/tmp/agent-tab-${shell_pid}" 2>/dev/null)
|
||||
[ -n "$TAB_NAME" ] && return
|
||||
elif [ -f "/tmp/claude-tab-${shell_pid}" ]; then
|
||||
TAB_NAME=$(cat "/tmp/claude-tab-${shell_pid}" 2>/dev/null)
|
||||
[ -n "$TAB_NAME" ] && return
|
||||
fi
|
||||
fi
|
||||
|
||||
local zellij_pid our_pane_id
|
||||
if [ -n "$shell_pid" ] && [ -n "$cwd" ]; then
|
||||
zellij_pid=$(ps -o ppid= -p "$shell_pid" 2>/dev/null | tr -d ' ')
|
||||
our_pane_id=$(tr '\0' '\n' < /proc/"$shell_pid"/environ 2>/dev/null \
|
||||
| grep '^ZELLIJ_PANE_ID=' | cut -d= -f2)
|
||||
|
||||
if [ -n "$our_pane_id" ] && [ -n "$zellij_pid" ]; then
|
||||
local group_idx
|
||||
group_idx=$(
|
||||
ps -o pid= --ppid "$zellij_pid" 2>/dev/null | while read -r p; do
|
||||
local pid_pane pid_cwd
|
||||
pid_pane=$(tr '\0' '\n' < /proc/"$p"/environ 2>/dev/null \
|
||||
| grep '^ZELLIJ_PANE_ID=' | cut -d= -f2)
|
||||
[ -z "$pid_pane" ] && continue
|
||||
pid_cwd=$(realpath "$(readlink /proc/"$p"/cwd 2>/dev/null)" 2>/dev/null)
|
||||
[ "$pid_cwd" = "$cwd" ] || continue
|
||||
printf '%s\n' "$pid_pane"
|
||||
done | sort -n | grep -n "^${our_pane_id}$" | cut -d: -f1
|
||||
)
|
||||
|
||||
if [ -n "$group_idx" ]; then
|
||||
local same_cwd_tabs
|
||||
same_cwd_tabs=$(
|
||||
printf '%s\n' "$actual_tabs" | while IFS= read -r t; do
|
||||
local t_lower="${t,,}" found=0
|
||||
while IFS='|' read -r ctab cdir; do
|
||||
[[ "$ctab" =~ ^#.*$ || -z "$ctab" ]] && continue
|
||||
[ "${ctab,,}" = "$t_lower" ] || continue
|
||||
local rdir
|
||||
rdir=$(realpath "$cdir" 2>/dev/null) || continue
|
||||
if [ "$rdir" = "$cwd" ]; then found=1; break; fi
|
||||
done < "$_CONF"
|
||||
[ "$found" -eq 1 ] && printf '%s\n' "$t"
|
||||
done
|
||||
)
|
||||
|
||||
local name
|
||||
name=$(printf '%s\n' "$same_cwd_tabs" | sed -n "${group_idx}p")
|
||||
if [ -n "$name" ]; then
|
||||
TAB_NAME="$name"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
local global_idx
|
||||
global_idx=$(
|
||||
ps -o pid= --ppid "$zellij_pid" 2>/dev/null | while read -r p; do
|
||||
local pid_pane
|
||||
pid_pane=$(tr '\0' '\n' < /proc/"$p"/environ 2>/dev/null \
|
||||
| grep '^ZELLIJ_PANE_ID=' | cut -d= -f2)
|
||||
[ -z "$pid_pane" ] && continue
|
||||
printf '%s\n' "$pid_pane"
|
||||
done | sort -n | grep -n "^${our_pane_id}$" | cut -d: -f1
|
||||
)
|
||||
if [ -n "$global_idx" ]; then
|
||||
local name
|
||||
name=$(printf '%s\n' "$actual_tabs" | sed -n "${global_idx}p")
|
||||
if [ -n "$name" ]; then
|
||||
TAB_NAME="$name"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
[ -z "$cwd" ] && return
|
||||
[ -f "$_CONF" ] || return
|
||||
|
||||
local exact_count=0 exact_match="" sw_count=0 sw_match=""
|
||||
while IFS='|' read -r tab dir; do
|
||||
[[ "$tab" =~ ^#.*$ || -z "$tab" ]] && continue
|
||||
local rdir
|
||||
rdir=$(realpath "$dir" 2>/dev/null) || continue
|
||||
[ "$rdir" != "$cwd" ] && continue
|
||||
|
||||
local tab_lower="${tab,,}"
|
||||
local actual
|
||||
actual=$(printf '%s\n' "$actual_tabs" | while IFS= read -r t; do
|
||||
[ "${t,,}" = "$tab_lower" ] && printf '%s' "$t" && break
|
||||
done)
|
||||
if [ -n "$actual" ]; then
|
||||
exact_count=$(( exact_count + 1 ))
|
||||
exact_match="$actual"
|
||||
continue
|
||||
fi
|
||||
|
||||
local sw
|
||||
sw=$(printf '%s\n' "$actual_tabs" | while IFS= read -r t; do
|
||||
[[ "${t,,}" == "${tab_lower} "* ]] && printf '%s' "$t" && break
|
||||
done)
|
||||
if [ -n "$sw" ]; then
|
||||
sw_count=$(( sw_count + 1 ))
|
||||
sw_match="$sw"
|
||||
fi
|
||||
done < "$_CONF"
|
||||
|
||||
if [ "$exact_count" -eq 1 ]; then
|
||||
TAB_NAME="$exact_match"
|
||||
elif [ "$exact_count" -eq 0 ] && [ "$sw_count" -eq 1 ]; then
|
||||
TAB_NAME="$sw_match"
|
||||
else
|
||||
echo "agent-hook: could not resolve tab for cwd=$1 (exact=$exact_count sw=$sw_count) — skipping state write" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
get_prompt() {
|
||||
[ ! -f "$_PROMPTS" ] && _PROMPTS="$HOME/.config/claude-prompts.json"
|
||||
jq -r --arg k "$1" '.[] | select(.key == $k) | .prompt' "$_PROMPTS" 2>/dev/null
|
||||
}
|
||||
|
||||
# Resolve conf/registry tab name to the live Zellij tab (exact or "FleetCrown Cursor" suffix).
|
||||
_resolve_live_tab_name() {
|
||||
local tab="$1"
|
||||
[ -z "$tab" ] && return 1
|
||||
local all_tabs tab_lower="${tab,,}" exact="" suffix=""
|
||||
all_tabs=$(
|
||||
zellij list-sessions -n 2>/dev/null | awk '{print $1}' | while read -r s; do
|
||||
[ -z "$s" ] && continue
|
||||
ZELLIJ_SESSION_NAME="$s" timeout 3 zellij action query-tab-names 2>/dev/null
|
||||
done
|
||||
)
|
||||
while IFS= read -r open_tab; do
|
||||
[ -z "$open_tab" ] && continue
|
||||
local open_lower="${open_tab,,}"
|
||||
if [ "$open_lower" = "$tab_lower" ]; then
|
||||
exact="$open_tab"
|
||||
break
|
||||
fi
|
||||
if [ -z "$suffix" ] && { [[ "$open_lower" == "${tab_lower} "* ]] || [[ "$open_lower" == "${tab_lower}-"* ]]; }; then
|
||||
suffix="$open_tab"
|
||||
fi
|
||||
done <<< "$all_tabs"
|
||||
if [ -n "$exact" ]; then
|
||||
printf '%s' "$exact"
|
||||
return 0
|
||||
fi
|
||||
if [ -n "$suffix" ]; then
|
||||
printf '%s' "$suffix"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# Find the zellij session that has a tab with the given name.
|
||||
# Uses ZELLIJ_SESSION_NAME env var (required for timeout 3 zellij action outside a pane).
|
||||
_find_session_for_tab() {
|
||||
local tab="$1" live_tab="$1"
|
||||
if type _resolve_live_tab_name >/dev/null 2>&1; then
|
||||
live_tab=$(_resolve_live_tab_name "$tab" 2>/dev/null) || live_tab="$tab"
|
||||
fi
|
||||
zellij list-sessions -n 2>/dev/null | awk '{print $1}' | while read -r s; do
|
||||
if ZELLIJ_SESSION_NAME="$s" timeout 3 zellij action query-tab-names 2>/dev/null \
|
||||
| grep -qxF "$live_tab"; then
|
||||
echo "$s"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Build a structured single-line failure reason string that names what we
|
||||
# observed and the exact next step the user can take. The daemon captures
|
||||
# this from stderr and forwards it to the cloud as pending_commands.error.
|
||||
# Goal: kill "inject_prompt failed" as a user-facing message — every reason
|
||||
# should tell the user what's actually broken and how to fix it.
|
||||
_inject_fail_reason() {
|
||||
local reason="$1"
|
||||
printf 'inject:%s\n' "$reason" >&2
|
||||
INJECT_FAIL_REASON="$reason"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Cwd-based fallback. Parses zellij dump-layout for each session, which
|
||||
# reports each tab as:
|
||||
# layout { cwd "<session-cwd>"
|
||||
# tab name="FleetCrown" hide_floating_panes=true {
|
||||
# pane cwd="dev/fleetcrown"
|
||||
# ...
|
||||
#
|
||||
# We resolve "session-cwd" + "pane cwd" to an absolute path and compare
|
||||
# against project_dir. The first tab whose pane cwd resolves to the project
|
||||
# directory wins. Lets a project with key "revampit" still inject into a
|
||||
# zellij tab named "Revamp-It" (or anything else) as long as the tab is
|
||||
# rooted in the project directory.
|
||||
_resolve_live_tab_by_cwd() {
|
||||
local project_dir="$1"
|
||||
[ -z "$project_dir" ] && return 1
|
||||
[ ! -d "$project_dir" ] && return 1
|
||||
# Normalize: strip trailing slash so the awk equality check matches.
|
||||
project_dir="${project_dir%/}"
|
||||
|
||||
local s tab_for_dir
|
||||
for s in $(zellij list-sessions -n 2>/dev/null | awk '{print $1}'); do
|
||||
[ -z "$s" ] && continue
|
||||
tab_for_dir=$(ZELLIJ_SESSION_NAME="$s" timeout 3 zellij action dump-layout 2>/dev/null \
|
||||
| awk -v target="$project_dir" '
|
||||
# Track the session-level cwd from the outer layout block.
|
||||
/^layout / { in_layout=1 }
|
||||
in_layout && /^[[:space:]]*cwd "/ {
|
||||
match($0, /cwd "[^"]*"/)
|
||||
sess_cwd = substr($0, RSTART+5, RLENGTH-6)
|
||||
in_layout=0
|
||||
}
|
||||
# Record the current tab name as we see it.
|
||||
/tab name=/ {
|
||||
match($0, /tab name="[^"]*"/)
|
||||
tab = substr($0, RSTART+10, RLENGTH-11)
|
||||
}
|
||||
# Each pane line carries the panes own cwd, often relative to
|
||||
# the layout cwd. Reconstruct the absolute path and compare.
|
||||
/pane cwd="/ {
|
||||
match($0, /pane cwd="[^"]*"/)
|
||||
# "pane cwd=\"" is 10 chars (skip), final "\"" trims 1 more.
|
||||
pane_cwd = substr($0, RSTART+10, RLENGTH-11)
|
||||
if (pane_cwd ~ /^\//) abs = pane_cwd
|
||||
else if (sess_cwd != "") abs = sess_cwd "/" pane_cwd
|
||||
else abs = pane_cwd
|
||||
# Strip trailing slash for the equality check.
|
||||
sub(/\/$/, "", abs)
|
||||
if (abs == target && tab != "") { print tab; exit }
|
||||
}
|
||||
')
|
||||
if [ -n "$tab_for_dir" ]; then
|
||||
printf '%s' "$tab_for_dir"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
inject_prompt() {
|
||||
local tab="$1"
|
||||
local prompt="$2"
|
||||
local project_dir="${3:-}" # optional — enables cwd-based fallback
|
||||
INJECT_FAIL_REASON=""
|
||||
[ -z "$tab" ] && { _inject_fail_reason "no-tab: empty project key passed to inject_prompt"; return 1; }
|
||||
|
||||
# Layer 1: name-based resolution (case-insensitive exact + suffix match).
|
||||
local live_tab="$tab"
|
||||
if type _resolve_live_tab_name >/dev/null 2>&1; then
|
||||
live_tab=$(_resolve_live_tab_name "$tab" 2>/dev/null) || live_tab=""
|
||||
fi
|
||||
|
||||
# Layer 2: cwd-based fallback for projects whose zellij tab name doesn't
|
||||
# match the registered key (e.g. project "revampit" with tab "Revamp-It").
|
||||
# Only fires when the caller passed project_dir AND name-match returned
|
||||
# nothing — preserves the cheap fast path for the common case.
|
||||
if [ -z "$live_tab" ] && [ -n "$project_dir" ]; then
|
||||
if type _resolve_live_tab_by_cwd >/dev/null 2>&1; then
|
||||
live_tab=$(_resolve_live_tab_by_cwd "$project_dir" 2>/dev/null) || live_tab=""
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$live_tab" ]; then
|
||||
# Surface what we DID see so the user knows the rename target.
|
||||
local available
|
||||
available=$(zellij list-sessions -n 2>/dev/null | awk '{print $1}' | while read -r s; do
|
||||
[ -z "$s" ] && continue
|
||||
ZELLIJ_SESSION_NAME="$s" timeout 3 zellij action query-tab-names 2>/dev/null
|
||||
done | tr '\n' ',' | sed 's/,$//; s/,/, /g')
|
||||
if [ -n "$project_dir" ]; then
|
||||
_inject_fail_reason "no-tab: no zellij tab matches '$tab' and no agent process found under '$project_dir'. Open zellij tab named '$tab' or launch an agent in $project_dir. Currently open: ${available:-(none)}"
|
||||
else
|
||||
_inject_fail_reason "no-tab: no zellij tab matches '$tab'. Open a tab with that name or rename an existing one. Currently open: ${available:-(none)}"
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
|
||||
# When called from outside a zellij session (e.g. systemd daemon), find which
|
||||
# session contains this tab — timeout 3 zellij action without ZELLIJ_SESSION_NAME set
|
||||
# lists sessions instead of acting, so write-chars goes nowhere.
|
||||
local zellij_session="${ZELLIJ_SESSION_NAME:-}"
|
||||
if [ -z "$zellij_session" ]; then
|
||||
zellij_session=$(_find_session_for_tab "$live_tab")
|
||||
if [ -z "$zellij_session" ]; then
|
||||
_inject_fail_reason "no-session: tab '$live_tab' resolved but not found in any active zellij session. Run 'zellij attach' or restart your session."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# go-to-tab-name is fire-and-forget — the switch completes asynchronously.
|
||||
# Poll dump-layout until the focused tab matches before sending characters,
|
||||
# so write-chars never lands in the previously focused pane.
|
||||
ZELLIJ_SESSION_NAME="$zellij_session" timeout 3 zellij action go-to-tab-name "$live_tab" 2>/dev/null
|
||||
local i active focused_ok=""
|
||||
for i in $(seq 1 20); do
|
||||
active=$(ZELLIJ_SESSION_NAME="$zellij_session" timeout 3 zellij action dump-layout 2>/dev/null \
|
||||
| grep 'focus=true' | grep 'tab name=' \
|
||||
| sed 's/.*tab name="\([^"]*\)".*/\1/' | head -1)
|
||||
if [ "$active" = "$live_tab" ]; then focused_ok=1; break; fi
|
||||
sleep 0.05
|
||||
done
|
||||
if [ -z "$focused_ok" ]; then
|
||||
_inject_fail_reason "focus-timeout: tab '$live_tab' in session '$zellij_session' did not gain focus within 1s. Reattach (zellij attach $zellij_session) or restart the session, then retry."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! ZELLIJ_SESSION_NAME="$zellij_session" timeout 3 zellij action write-chars -- "$prompt" 2>/dev/null; then
|
||||
_inject_fail_reason "write-chars-failed: characters did not reach tab '$live_tab' in session '$zellij_session'. Known zellij 0.43.x EWOULDBLOCK bug on large prompts — upgrade zellij or split the prompt."
|
||||
return 1
|
||||
fi
|
||||
sleep 0.2
|
||||
ZELLIJ_SESSION_NAME="$zellij_session" timeout 3 zellij action write 13 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Send a raw key code (e.g. 3 = Ctrl+C, 13 = Enter) to a tab without typing
|
||||
# characters first. Used for interrupt signals where write-chars would be wrong.
|
||||
send_raw_key_to_tab() {
|
||||
local tab="$1" keycode="$2"
|
||||
[ -z "$tab" ] && return 1
|
||||
local zellij_session="${ZELLIJ_SESSION_NAME:-}"
|
||||
if [ -z "$zellij_session" ]; then
|
||||
zellij_session=$(_find_session_for_tab "$tab")
|
||||
[ -z "$zellij_session" ] && return 1
|
||||
fi
|
||||
ZELLIJ_SESSION_NAME="$zellij_session" timeout 3 zellij action go-to-tab-name "$tab" 2>/dev/null || true
|
||||
sleep 0.1
|
||||
ZELLIJ_SESSION_NAME="$zellij_session" timeout 3 zellij action write "$keycode" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Call after every injection to keep the Control panel and web beacon in sync.
|
||||
# Writes agent-current-prompt-<tab> so the UI shows which task is running,
|
||||
# and clears agent-ready-<tab> so the UI stops showing "waiting for input".
|
||||
write_inject_state() {
|
||||
local tab="$1" key="$2" label="$3"
|
||||
local now
|
||||
now=$(date +%s)
|
||||
# Current-prompt sentinel — TypeScript reads this to show the running task.
|
||||
# Use jq -Rs to JSON-escape key/label: user-supplied custom prompts can
|
||||
# contain newlines or quotes which otherwise break the JSON, then the
|
||||
# daemon's parser falls back to empty and the cleanup gate can't fire.
|
||||
# Match the daemon's other sentinel writer (fleetcrown-daemon.sh execute_inject).
|
||||
printf '{"key":%s,"label":%s,"startedAt":%s}\n' \
|
||||
"$(printf '%s' "$key" | jq -Rs .)" \
|
||||
"$(printf '%s' "$label" | jq -Rs .)" \
|
||||
"$now" \
|
||||
> "/tmp/agent-current-prompt-${tab}"
|
||||
# Clear ready/closed state so the UI transitions to "running"
|
||||
rm -f "/tmp/agent-ready-${tab}" "/tmp/claude-ready-${tab}"
|
||||
rm -f "/tmp/agent-closed-${tab}" "/tmp/claude-closed-${tab}"
|
||||
rm -f "/tmp/agent-stop-active-${tab}" "/tmp/claude-stop-active-${tab}"
|
||||
}
|
||||
|
||||
play_sound() {
|
||||
DISPLAY="${DISPLAY:-:1}" DBUS_SESSION_BUS_ADDRESS="$_DBUS" \
|
||||
paplay "/usr/share/sounds/freedesktop/stereo/$1.oga" 2>/dev/null &
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
|
||||
|
||||
fail() {
|
||||
echo "FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_file() {
|
||||
local path="$1"
|
||||
[ -e "$path" ] || fail "missing $path"
|
||||
}
|
||||
|
||||
check_exec() {
|
||||
local path="$1"
|
||||
[ -x "$path" ] || fail "not executable: $path"
|
||||
}
|
||||
|
||||
check_file "$ROOT/scripts/beacon.py"
|
||||
check_exec "$ROOT/scripts/agent-hook-bridge.sh"
|
||||
check_exec "$ROOT/scripts/agent-hook-lib.sh"
|
||||
check_exec "$ROOT/scripts/smoke-beacon-stop.sh"
|
||||
check_file "/home/g/dev/dotfiles/.claude/settings.json"
|
||||
check_exec "/home/g/dev/dotfiles/.claude/hooks/stop.sh"
|
||||
check_exec "/home/g/dev/dotfiles/.claude/hooks/notification.sh"
|
||||
check_exec "/home/g/dev/dotfiles/.claude/hooks/beacon.py"
|
||||
|
||||
python3 "$ROOT/scripts/sync-agent-runtime-config.py"
|
||||
|
||||
[ -f /home/g/.config/agent-prompts.json ] || [ -f /home/g/.config/claude-prompts.json ] || fail "missing prompt config"
|
||||
[ -f /home/g/.config/agent-projects.conf ] || [ -f /home/g/.config/claude-projects.conf ] || fail "missing projects config"
|
||||
|
||||
python3 - <<'PY'
|
||||
import json
|
||||
|
||||
settings = json.load(open("/home/g/dev/dotfiles/.claude/settings.json"))
|
||||
hooks = settings.get("hooks", {})
|
||||
for name in ("Stop", "Notification"):
|
||||
if not hooks.get(name):
|
||||
raise SystemExit(f"missing {name} hook registration")
|
||||
|
||||
print("Claude hooks: ok")
|
||||
PY
|
||||
|
||||
echo "agent runtime check: ok"
|
||||
echo "smoke test: $ROOT/scripts/smoke-beacon-stop.sh [project-dir]"
|
||||
@@ -1,111 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# fleetcrown-beacon-window.sh — keep a chromium --app= window open on /beacon/live.
|
||||
#
|
||||
# ⚠️ DEPRECATED as of 2026-06-11 (Session 1 of killing-the-bash-daemon plan).
|
||||
# The fleetcrown-beacon-window.service systemd unit is now masked
|
||||
# (/dev/null symlink in ~/.config/systemd/user/) and the original unit
|
||||
# file is preserved at ~/.config/systemd/user/fleetcrown-beacon-window
|
||||
# .service.disabled-2026-06-11. This script is kept in git history
|
||||
# only — it will be deleted in Session 4 along with the rest of the
|
||||
# bash bridge. See /home/g/.claude/plans/structured-baking-kazoo.md
|
||||
# and content/thoughts/killing-the-bash-daemon.md for context.
|
||||
# The L3 "beacon popup" mode that this window served is being collapsed
|
||||
# into a simpler ON/OFF model; Fleet Runner desktop is the sole local
|
||||
# executor going forward.
|
||||
#
|
||||
# Original purpose (for historical reference):
|
||||
# Run by the fleetcrown-beacon-window.service systemd user unit. Restart=always
|
||||
# means systemd brings the window back within ~2s whenever it dies, so a stop
|
||||
# hook always finds a pre-warmed window to focus (PyQt-equivalent <100ms).
|
||||
#
|
||||
# Why a dedicated browser profile: the window needs to survive independently
|
||||
# of the user's main browser session. A separate --user-data-dir keeps cookies,
|
||||
# zoom level, and window position isolated from regular browsing.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=_brand.sh
|
||||
source "$SCRIPT_DIR/_brand.sh"
|
||||
|
||||
# WM_CLASS for this window. Contract between this script, /api/beacon/window/show,
|
||||
# and /api/beacon/window/hide — all three must agree or the show/hide endpoints
|
||||
# can't find the window via xdotool. Derived from APP_SLUG so a rename flips
|
||||
# all three together.
|
||||
BEACON_WM_CLASS="${APP_SLUG}-beacon"
|
||||
|
||||
URL="$(_brand_env BEACON_URL "http://localhost:3000/beacon/live")"
|
||||
PROFILE_DIR="$(_brand_env BEACON_PROFILE "$HOME/.config/${APP_SLUG}-beacon-profile")"
|
||||
|
||||
# No graphical session → exit cleanly. Systemd will retry per Restart=always;
|
||||
# the sleep avoids a tight restart loop during boot before X/Wayland comes up.
|
||||
if [ -z "${DISPLAY:-}" ] && [ -z "${WAYLAND_DISPLAY:-}" ]; then
|
||||
sleep 15
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Wait for cockpit-app to start serving before pointing chromium at the URL,
|
||||
# otherwise the first paint is a "site can't be reached" page that stays cached.
|
||||
HEALTH="${URL%/beacon/live}/api/health"
|
||||
deadline=$((SECONDS + 60))
|
||||
until curl -sf -m 1 "$HEALTH" >/dev/null 2>&1; do
|
||||
if [ "$SECONDS" -gt "$deadline" ]; then
|
||||
echo "${APP_SLUG}-app unreachable after 60s — exiting" >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
mkdir -p "$PROFILE_DIR"
|
||||
mkdir -p "$(_brand_tmp 'beacon')"
|
||||
|
||||
# --class=cockpit-beacon: lets /api/beacon/window/{show,hide} target this window
|
||||
# specifically via xdotool, so a user's regular browser tab at the same URL is
|
||||
# never accidentally moved.
|
||||
# --window-position=-32000,-32000: spawn off-screen. The page loads, SSE connects,
|
||||
# BeaconLiveClient mounts — all invisible. When a session arrives the React
|
||||
# useEffect POSTs /api/beacon/window/show and xdotool moves the window
|
||||
# on-screen fully populated. No "Standby" flash, ever.
|
||||
for browser in chromium chromium-browser brave-browser google-chrome; do
|
||||
if command -v "$browser" >/dev/null 2>&1; then
|
||||
# Write PID file so beacon.py can focus this window without xdotool on every call.
|
||||
echo "$$" > "$(_brand_tmp 'beacon')/live-browser.pid"
|
||||
# Unset WAYLAND_DISPLAY + force --ozone-platform=x11: on KDE Plasma Wayland,
|
||||
# chromium-family browsers default to native Wayland for --app windows
|
||||
# (only the clipboard helper goes through XWayland). xdotool is X11-only,
|
||||
# so a Wayland-native window is invisible to it and our show/hide endpoints
|
||||
# silently no-op. Unsetting WAYLAND_DISPLAY routes everything through
|
||||
# XWayland — xdotool can then find, move, and raise the window.
|
||||
env -u WAYLAND_DISPLAY "$browser" \
|
||||
--app="$URL" \
|
||||
--user-data-dir="$PROFILE_DIR" \
|
||||
--class="$BEACON_WM_CLASS" \
|
||||
--ozone-platform=x11 \
|
||||
--window-size=560,720 \
|
||||
--no-first-run \
|
||||
--no-default-browser-check &
|
||||
browser_pid=$!
|
||||
|
||||
# Background watcher: as soon as the window appears, unmap it so the user
|
||||
# never sees an empty "Standby" flash. `xdotool search --sync` blocks until
|
||||
# at least one matching window exists (no fixed timeout — on slow systems
|
||||
# brave can take 10+ seconds to create the window). Once unmapped, the
|
||||
# React useEffect on /beacon/live drives show/hide based on session state.
|
||||
if command -v xdotool >/dev/null 2>&1; then
|
||||
(
|
||||
# --sync waits for first match; --onlyvisible filters to mapped windows
|
||||
# (the unmapped window won't be re-found on a second --sync call).
|
||||
wids=$(xdotool search --sync --onlyvisible --class "$BEACON_WM_CLASS" 2>/dev/null) || wids=""
|
||||
for wid in $wids; do
|
||||
xdotool windowunmap "$wid" 2>/dev/null || true
|
||||
done
|
||||
) &
|
||||
fi
|
||||
|
||||
wait "$browser_pid"
|
||||
exit $?
|
||||
fi
|
||||
done
|
||||
|
||||
echo "no chromium-family browser found (tried: chromium, chromium-browser, brave-browser, google-chrome)" >&2
|
||||
exit 1
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,214 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# install-beacon.sh — Install FleetCrown Beacon on this machine
|
||||
#
|
||||
# FleetCrown Beacon is the desktop launcher that opens the FleetCrown web popup
|
||||
# when Claude Code (or any AI agent) finishes a session. The popup itself
|
||||
# lives in the FleetCrown web app (/beacon/live) — beacon.py just writes the
|
||||
# session file to /tmp and launches a Chrome --app= frameless window.
|
||||
#
|
||||
# Requirements: Python 3.11+, Zellij, jq, a Chromium-family browser
|
||||
# Optional: xdotool/wmctrl (window raise), xrandr (multi-monitor)
|
||||
#
|
||||
# Usage:
|
||||
# bash scripts/install-beacon.sh
|
||||
#
|
||||
# To uninstall:
|
||||
# rm -rf ~/.local/share/fleetcrown-beacon
|
||||
# # then restore ~/.claude/hooks/stop.sh from the .bak if it existed
|
||||
set -euo pipefail
|
||||
|
||||
BEACON_HOME="${BEACON_HOME:-$HOME/.local/share/fleetcrown-beacon}"
|
||||
HOOKS_DIR="$HOME/.claude/hooks"
|
||||
CONFIG_DIR="$HOME/.config"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# ── Terminal colours ─────────────────────────────────────────────────────────
|
||||
if [ -t 1 ]; then
|
||||
bold=$'\033[1m' reset=$'\033[0m' green=$'\033[32m' yellow=$'\033[33m'
|
||||
else
|
||||
bold="" reset="" green="" yellow=""
|
||||
fi
|
||||
ok() { printf '%s✓%s %s\n' "$green" "$reset" "$*"; }
|
||||
warn() { printf '%s⚠%s %s\n' "$yellow" "$reset" "$*"; }
|
||||
info() { printf ' %s\n' "$*"; }
|
||||
|
||||
# ── --sync: re-copy scripts only (no hooks or config changes) ────────────────
|
||||
# Use this after pulling updates instead of re-running the full installer.
|
||||
# bash scripts/install-beacon.sh --sync
|
||||
_copy_scripts() {
|
||||
local dest="$1"
|
||||
cp "$SCRIPT_DIR/beacon.py" "$dest/"
|
||||
cp "$SCRIPT_DIR/_beacon_config.py" "$dest/"
|
||||
cp "$SCRIPT_DIR/agent-hook-bridge.sh" "$dest/"
|
||||
cp "$SCRIPT_DIR/agent-hook-lib.sh" "$dest/"
|
||||
cp "$SCRIPT_DIR/_agents.sh" "$dest/"
|
||||
cp "$SCRIPT_DIR/_brand.sh" "$dest/"
|
||||
cp "$SCRIPT_DIR/run-codex-task.sh" "$dest/"
|
||||
cp "$SCRIPT_DIR/run-gemini-task.sh" "$dest/"
|
||||
cp "$SCRIPT_DIR/sync-agent-runtime-config.py" "$dest/"
|
||||
cp "$SCRIPT_DIR/notify-choice.py" "$dest/"
|
||||
cp "$SCRIPT_DIR/get-idle-secs.py" "$dest/"
|
||||
# Retired PyQt modules — clear any leftover copies from older installs so
|
||||
# `python3 beacon.py` doesn't accidentally pick up a stale ContinuePopup.
|
||||
rm -f "$dest/_beacon_popups.py" "$dest/_beacon_theme.py" "$dest/_beacon_audio.py" \
|
||||
"$dest/__pycache__/_beacon_popups."* \
|
||||
"$dest/__pycache__/_beacon_theme."* \
|
||||
"$dest/__pycache__/_beacon_audio."* 2>/dev/null || true
|
||||
chmod +x "$dest/agent-hook-bridge.sh" "$dest/agent-hook-lib.sh" \
|
||||
"$dest/run-codex-task.sh" "$dest/run-gemini-task.sh"
|
||||
}
|
||||
|
||||
if [[ "${1:-}" == "--sync" ]]; then
|
||||
[ -d "$BEACON_HOME" ] || { echo "Beacon not installed — run without --sync first." >&2; exit 1; }
|
||||
_copy_scripts "$BEACON_HOME"
|
||||
ok "Beacon scripts synced to $BEACON_HOME"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "${bold}FleetCrown Beacon installer${reset}"
|
||||
echo ""
|
||||
|
||||
# ── 1. Copy beacon scripts ───────────────────────────────────────────────────
|
||||
mkdir -p "$BEACON_HOME"
|
||||
_copy_scripts "$BEACON_HOME"
|
||||
ok "Scripts installed to $BEACON_HOME"
|
||||
|
||||
# ── 2. Wire Claude Code Stop hook ───────────────────────────────────────────
|
||||
mkdir -p "$HOOKS_DIR"
|
||||
|
||||
_install_hook() {
|
||||
local name="$1" mode="$2"
|
||||
local dest="$HOOKS_DIR/${name}.sh"
|
||||
if [ -f "$dest" ]; then
|
||||
cp "$dest" "${dest}.bak"
|
||||
info "Backed up existing ${name}.sh → ${name}.sh.bak"
|
||||
fi
|
||||
printf '#!/usr/bin/env bash\nexec "%s/agent-hook-bridge.sh" %s\n' \
|
||||
"$BEACON_HOME" "$mode" > "$dest"
|
||||
chmod +x "$dest"
|
||||
ok "${name}.sh → $BEACON_HOME/agent-hook-bridge.sh $mode"
|
||||
}
|
||||
|
||||
_install_hook "stop" "stop"
|
||||
_install_hook "notification" "notification"
|
||||
|
||||
# ── 3. Default prompt library ────────────────────────────────────────────────
|
||||
PROMPTS_FILE="$CONFIG_DIR/agent-prompts.json"
|
||||
if [ ! -f "$PROMPTS_FILE" ]; then
|
||||
cat > "$PROMPTS_FILE" << 'PROMPTS'
|
||||
[
|
||||
{
|
||||
"key": "next_best",
|
||||
"slot": 1,
|
||||
"icon": "⚡",
|
||||
"label": "Next best task",
|
||||
"style": "primary",
|
||||
"category": "dev",
|
||||
"prompt": "Run `git status && git log --oneline -5`. If there's interrupted work, resume it. Otherwise find and close the highest-impact gap (quality, UX, or product). One thing, completely.\n\nWhen done, update the session file with:\ndone: <what you completed>\nnext: <what remains>\ntests: <N pass · N fail, or 'no suite'>\ntodos: <count> TODOs\nhealth: <good | needs attention | critical>"
|
||||
},
|
||||
{
|
||||
"key": "test_and_fix",
|
||||
"slot": 2,
|
||||
"icon": "🧪",
|
||||
"label": "Test & fix",
|
||||
"style": "action",
|
||||
"category": "dev",
|
||||
"prompt": "Run the full test suite. Fix every failure — trace each error to root cause. Then verify the primary user flows work end-to-end."
|
||||
},
|
||||
{
|
||||
"key": "commit_push",
|
||||
"slot": 3,
|
||||
"icon": "📦",
|
||||
"label": "Commit & push",
|
||||
"style": "action",
|
||||
"category": "ship",
|
||||
"prompt": "Verify type check and tests pass. Review git diff. Write a conventional commit message (<type>(<scope>): <description>) explaining why. Commit and push to origin."
|
||||
},
|
||||
{
|
||||
"key": "review",
|
||||
"slot": 4,
|
||||
"icon": "🔍",
|
||||
"label": "Review & clean",
|
||||
"style": "action",
|
||||
"category": "quality",
|
||||
"prompt": "Review the last 5 commits for quality issues: DRY violations, SSOT breaks, type safety gaps, poor error handling. Fix the top 3 most impactful issues."
|
||||
},
|
||||
{
|
||||
"key": "continue",
|
||||
"slot": 9,
|
||||
"icon": "▶",
|
||||
"label": "Continue",
|
||||
"style": "action",
|
||||
"category": "control",
|
||||
"prompt": "Continue with the current task. Pick up exactly where you left off."
|
||||
},
|
||||
{
|
||||
"key": "close_session",
|
||||
"slot": 0,
|
||||
"icon": "✓",
|
||||
"label": "Close session",
|
||||
"style": "action",
|
||||
"category": "control",
|
||||
"prompt": "The session is complete. Update the session file with final status and stop."
|
||||
}
|
||||
]
|
||||
PROMPTS
|
||||
ok "Prompt library created at $PROMPTS_FILE"
|
||||
else
|
||||
info "Keeping existing $PROMPTS_FILE"
|
||||
fi
|
||||
|
||||
# ── 4. Default project registry ──────────────────────────────────────────────
|
||||
PROJECTS_FILE="$CONFIG_DIR/agent-projects.conf"
|
||||
if [ ! -f "$PROJECTS_FILE" ]; then
|
||||
cat > "$PROJECTS_FILE" << 'PROJECTS'
|
||||
# FleetCrown Beacon — project registry
|
||||
# Maps Zellij tab names to project directories.
|
||||
# Format (one per line): tab_name|/absolute/path/to/project
|
||||
# Tab name is case-insensitive and matched against Zellij's tab list.
|
||||
#
|
||||
# Example:
|
||||
# MyApp|/home/user/dev/myapp
|
||||
# API|/home/user/dev/api-server
|
||||
PROJECTS
|
||||
ok "Project registry created at $PROJECTS_FILE"
|
||||
warn "Add your projects:"
|
||||
info "Edit $PROJECTS_FILE"
|
||||
info "Format: tab_name|/path/to/project"
|
||||
else
|
||||
info "Keeping existing $PROJECTS_FILE"
|
||||
fi
|
||||
|
||||
# ── 5. Verify dependencies ───────────────────────────────────────────────────
|
||||
echo ""
|
||||
echo "${bold}Dependency check${reset}"
|
||||
|
||||
_check_cmd() {
|
||||
local cmd="$1" hint="$2"
|
||||
if command -v "$cmd" &>/dev/null; then
|
||||
ok "$cmd"
|
||||
else
|
||||
warn "$cmd not found — $hint"
|
||||
fi
|
||||
}
|
||||
|
||||
if command -v chromium &>/dev/null || command -v chromium-browser &>/dev/null \
|
||||
|| command -v brave-browser &>/dev/null || command -v google-chrome &>/dev/null; then
|
||||
ok "Chromium-family browser (for --app frameless popup)"
|
||||
else
|
||||
warn "No Chromium-family browser found"
|
||||
info "Install: apt install chromium OR brave-browser OR google-chrome"
|
||||
fi
|
||||
|
||||
_check_cmd "jq" "install: apt install jq OR brew install jq"
|
||||
_check_cmd "zellij" "required for tab detection — https://zellij.dev"
|
||||
_check_cmd "xdotool" "optional, used to raise the beacon window — apt install xdotool"
|
||||
_check_cmd "xrandr" "optional, used for multi-monitor positioning — apt install x11-xserver-utils"
|
||||
|
||||
# ── 6. Done ──────────────────────────────────────────────────────────────────
|
||||
echo ""
|
||||
echo "${bold}Installation complete.${reset}"
|
||||
echo ""
|
||||
echo "Beacon activates automatically when Claude Code stops."
|
||||
echo "Test it:"
|
||||
echo " printf '{\"cwd\":\"%s\"}' \"\$PWD\" | bash $BEACON_HOME/agent-hook-bridge.sh stop"
|
||||
@@ -1,68 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# install-fleetcrown-beacon-window.sh — register the fleetcrown-beacon-window user unit.
|
||||
#
|
||||
# Sister to install-fleetcrown-app.sh. Keeps a chromium --app=/beacon/live window
|
||||
# pre-warmed so the popup is sub-100ms when a stop hook fires, matching the
|
||||
# instant-feel PyQt used to have. Restart=always means the unit recovers if
|
||||
# the user closes the window or the browser crashes.
|
||||
#
|
||||
# Usage: ./scripts/install-fleetcrown-beacon-window.sh
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SERVICE_NAME="fleetcrown-beacon-window"
|
||||
SERVICE_FILE="$HOME/.config/systemd/user/${SERVICE_NAME}.service"
|
||||
|
||||
log() { echo "[install-fleetcrown-beacon-window] $*"; }
|
||||
|
||||
mkdir -p "$HOME/.config/systemd/user"
|
||||
|
||||
cat > "$SERVICE_FILE" <<EOF
|
||||
[Unit]
|
||||
Description=FleetCrown beacon window (pre-warmed Chromium app for instant popup)
|
||||
Documentation=https://github.com/maonakamoto/fleetcrown
|
||||
After=fleetcrown-app.service
|
||||
Wants=fleetcrown-app.service
|
||||
# Cap the restart rate so a permanently broken browser doesn't thrash systemd.
|
||||
StartLimitBurst=10
|
||||
StartLimitIntervalSec=60
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=${SCRIPT_DIR}/fleetcrown-beacon-window.sh
|
||||
Restart=always
|
||||
RestartSec=2
|
||||
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
|
||||
log "Service file written to $SERVICE_FILE"
|
||||
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable "$SERVICE_NAME"
|
||||
|
||||
if systemctl --user is-active --quiet "$SERVICE_NAME"; then
|
||||
log "Restarting $SERVICE_NAME…"
|
||||
systemctl --user restart "$SERVICE_NAME"
|
||||
else
|
||||
log "Starting $SERVICE_NAME…"
|
||||
systemctl --user start "$SERVICE_NAME"
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
|
||||
STATUS=$(systemctl --user is-active "$SERVICE_NAME" 2>/dev/null || echo "unknown")
|
||||
if [ "$STATUS" = "active" ]; then
|
||||
log "✓ Beacon window service is running."
|
||||
log " Manage with: systemctl --user {status|stop|restart} ${SERVICE_NAME}"
|
||||
log " View logs: journalctl --user -u ${SERVICE_NAME} -f"
|
||||
else
|
||||
log "✗ Service did not start (status: $STATUS)"
|
||||
log " Check logs: journalctl --user -u ${SERVICE_NAME} -n 50"
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,206 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# install-fleetcrown-daemon.sh — Install the FleetCrown daemon as a systemd user service.
|
||||
#
|
||||
# The daemon polls the FleetCrown control plane for commands (inject prompts,
|
||||
# switch agents, transcribe audio) and pushes local runtime state (which
|
||||
# agents are running in which project tabs).
|
||||
#
|
||||
# Usage:
|
||||
# bash scripts/install-fleetcrown-daemon.sh # full install or re-install
|
||||
# bash scripts/install-fleetcrown-daemon.sh --restart # restart to load changed daemon code
|
||||
# bash scripts/install-fleetcrown-daemon.sh --uninstall
|
||||
#
|
||||
# Environment (FLEETCROWN_* preferred; COCKPIT_* read for transition):
|
||||
# FLEETCROWN_DAEMON_TOKEN bearer token (read from .env.local if not set)
|
||||
# FLEETCROWN_BASE_URL override the cloud URL (optional)
|
||||
# FLEETCROWN_BASE_URLS comma-separated URLs to poll, e.g. local + cloud
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
SERVICE_NAME="fleetcrown-daemon"
|
||||
SERVICE_FILE="${HOME}/.config/systemd/user/${SERVICE_NAME}.service"
|
||||
ENV_FILE="${HOME}/.config/fleetcrown/daemon.env"
|
||||
|
||||
# ── Colours ──────────────────────────────────────────────────────────────────
|
||||
if [ -t 1 ]; then
|
||||
bold=$'\033[1m' reset=$'\033[0m'
|
||||
green=$'\033[32m' yellow=$'\033[33m' red=$'\033[31m' cyan=$'\033[36m'
|
||||
else
|
||||
bold="" reset="" green="" yellow="" red="" cyan=""
|
||||
fi
|
||||
ok() { printf '%s✓%s %s\n' "$green" "$reset" "$*"; }
|
||||
info() { printf '%s→%s %s\n' "$cyan" "$reset" "$*"; }
|
||||
warn() { printf '%s!%s %s\n' "$yellow" "$reset" "$*"; }
|
||||
die() { printf '%s✗%s %s\n' "$red" "$reset" "$*" >&2; exit 1; }
|
||||
|
||||
# ── --restart: reload daemon code without re-generating service file ─────────
|
||||
# Use this after pulling changes to fleetcrown-daemon.sh or agent-hook-lib.sh.
|
||||
# bash scripts/install-fleetcrown-daemon.sh --restart
|
||||
if [[ "${1:-}" == "--restart" ]]; then
|
||||
if ! systemctl --user is-enabled "$SERVICE_NAME" >/dev/null 2>&1; then
|
||||
die "Daemon service is not installed — run without --restart to install first."
|
||||
fi
|
||||
# Refresh unit file so TimeoutStopSec / Restart=always changes apply.
|
||||
info "Refreshing systemd unit…"
|
||||
FLEETCROWN_DAEMON_TOKEN="${FLEETCROWN_DAEMON_TOKEN:-${COCKPIT_DAEMON_TOKEN:-$(grep -E '^(FLEETCROWN_DAEMON_TOKEN|COCKPIT_DAEMON_TOKEN)=' "$ENV_FILE" 2>/dev/null | cut -d= -f2- | tr -d '"'"'" | xargs || true)}}"
|
||||
FLEETCROWN_BASE_URL="${FLEETCROWN_BASE_URL:-${COCKPIT_BASE_URL:-$(grep -E '^(FLEETCROWN_BASE_URL|COCKPIT_BASE_URL)=' "$ENV_FILE" 2>/dev/null | cut -d= -f2- | tr -d '"'"'" | xargs || echo "https://fleetcrown.vercel.app")}}"
|
||||
FLEETCROWN_BASE_URLS="${FLEETCROWN_BASE_URLS:-$(grep -E '^(FLEETCROWN_BASE_URLS|COCKPIT_BASE_URLS)=' "$ENV_FILE" 2>/dev/null | cut -d= -f2- | tr -d '"'"'" | xargs || true)}"
|
||||
export FLEETCROWN_DAEMON_TOKEN FLEETCROWN_BASE_URL FLEETCROWN_BASE_URLS
|
||||
info "Re-installing service unit and restarting with latest scripts…"
|
||||
set --
|
||||
fi
|
||||
|
||||
# ── Uninstall ────────────────────────────────────────────────────────────────
|
||||
if [[ "${1:-}" == "--uninstall" ]]; then
|
||||
info "Stopping and disabling ${SERVICE_NAME}…"
|
||||
systemctl --user stop "$SERVICE_NAME" 2>/dev/null || true
|
||||
systemctl --user disable "$SERVICE_NAME" 2>/dev/null || true
|
||||
rm -f "$SERVICE_FILE"
|
||||
systemctl --user daemon-reload
|
||||
ok "Daemon service removed."
|
||||
info "Env file kept at ${ENV_FILE} — remove manually if desired."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ── Resolve token ─────────────────────────────────────────────────────────────
|
||||
TOKEN="${FLEETCROWN_DAEMON_TOKEN:-${COCKPIT_DAEMON_TOKEN:-}}"
|
||||
|
||||
# Try .env.local in project root
|
||||
if [ -z "$TOKEN" ] && [ -f "$PROJECT_DIR/.env.local" ]; then
|
||||
TOKEN=$(grep -E '^(FLEETCROWN_DAEMON_TOKEN|COCKPIT_DAEMON_TOKEN)=' "$PROJECT_DIR/.env.local" \
|
||||
| head -1 | cut -d= -f2- | tr -d '"'"'" | xargs 2>/dev/null) || true
|
||||
fi
|
||||
|
||||
if [ -z "$TOKEN" ]; then
|
||||
die "FLEETCROWN_DAEMON_TOKEN is not set (legacy COCKPIT_DAEMON_TOKEN also accepted). Export it or add it to .env.local."
|
||||
fi
|
||||
|
||||
BASE_URL="${FLEETCROWN_BASE_URL:-${COCKPIT_BASE_URL:-https://fleetcrown.vercel.app}}"
|
||||
BASE_URLS="${FLEETCROWN_BASE_URLS:-${COCKPIT_BASE_URLS:-}}"
|
||||
if [ -z "$BASE_URLS" ]; then
|
||||
BASE_URLS="http://127.0.0.1:3000,${BASE_URL}"
|
||||
fi
|
||||
|
||||
# ── Check dependencies ────────────────────────────────────────────────────────
|
||||
missing=()
|
||||
for cmd in systemctl curl jq zellij; do
|
||||
command -v "$cmd" >/dev/null 2>&1 || missing+=("$cmd")
|
||||
done
|
||||
if [ ${#missing[@]} -gt 0 ]; then
|
||||
die "Missing required commands: ${missing[*]}"
|
||||
fi
|
||||
|
||||
# ── Capture PATH from the current login environment ──────────────────────────
|
||||
# systemd user services start with a minimal PATH that often omits ~/.local/bin,
|
||||
# nix store paths, and wherever the user installed zellij/jq. We snapshot the
|
||||
# current shell PATH and bake it into the service file so the daemon finds
|
||||
# everything it needs without extra configuration.
|
||||
CURRENT_PATH="${PATH}"
|
||||
|
||||
# ── Write env file ────────────────────────────────────────────────────────────
|
||||
mkdir -p "$(dirname "$ENV_FILE")"
|
||||
cat > "$ENV_FILE" <<EOF
|
||||
FLEETCROWN_DAEMON_TOKEN=${TOKEN}
|
||||
FLEETCROWN_BASE_URL=${BASE_URL}
|
||||
FLEETCROWN_BASE_URLS=${BASE_URLS}
|
||||
FLEETCROWN_DAEMON_FORCE_REMOTE=1
|
||||
EOF
|
||||
chmod 600 "$ENV_FILE"
|
||||
ok "Env file written to ${ENV_FILE}"
|
||||
|
||||
# ── Write service file ────────────────────────────────────────────────────────
|
||||
mkdir -p "$(dirname "$SERVICE_FILE")"
|
||||
cat > "$SERVICE_FILE" <<EOF
|
||||
[Unit]
|
||||
Description=FleetCrown local daemon
|
||||
Documentation=https://github.com/maonakamoto/fleetcrown
|
||||
After=network.target
|
||||
# If it crashes 5× in 2 min, stop retrying — something is wrong
|
||||
StartLimitIntervalSec=120
|
||||
StartLimitBurst=5
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=${SCRIPT_DIR}
|
||||
ExecStart=${SCRIPT_DIR}/fleetcrown-daemon.sh
|
||||
# Restart on crash, hang-kill, and self-heal exit (push-loop failure budget).
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
# Give the daemon time to push one heartbeat before systemd considers it hung.
|
||||
TimeoutStartSec=30
|
||||
# Don't hang shutdown forever on a stuck zellij subprocess.
|
||||
TimeoutStopSec=15
|
||||
# Cap restart storms — StartLimit* in [Unit] still applies.
|
||||
KillMode=control-group
|
||||
KillSignal=SIGTERM
|
||||
|
||||
# Preserve the login PATH so zellij, jq, ffmpeg, python3 etc. are reachable
|
||||
Environment=PATH=${CURRENT_PATH}
|
||||
|
||||
# Token and base URL loaded from env file (chmod 600 — not visible to other users)
|
||||
EnvironmentFile=${ENV_FILE}
|
||||
|
||||
# Route stdout/stderr to the journal so logs are accessible via:
|
||||
# journalctl --user -u fleetcrown-daemon -f
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=fleetcrown-daemon
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
ok "Service file written to ${SERVICE_FILE}"
|
||||
|
||||
# Keep the hosted-install copy aligned with this checkout so repair_helper
|
||||
# does not downgrade to an older production bundle.
|
||||
INSTALL_DIR="${HOME}/.local/share/fleetcrown"
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
for runtime_file in fleetcrown-daemon.sh fleet agent-hook-lib.sh agent-hook-bridge.sh \
|
||||
_agents.sh _brand.sh install-fleetcrown-daemon.sh run-codex-task.sh run-gemini-task.sh \
|
||||
beacon.py _beacon_config.py get-idle-secs.py notify-choice.py sync-agent-runtime-config.py transcribe.py; do
|
||||
[ -f "$SCRIPT_DIR/$runtime_file" ] && cp "$SCRIPT_DIR/$runtime_file" "$INSTALL_DIR/$runtime_file"
|
||||
done
|
||||
chmod +x "$INSTALL_DIR/fleetcrown-daemon.sh" "$INSTALL_DIR/fleet" \
|
||||
"$INSTALL_DIR/agent-hook-bridge.sh" "$INSTALL_DIR/install-fleetcrown-daemon.sh" 2>/dev/null || true
|
||||
ok "Runtime bundle synced to ${INSTALL_DIR}"
|
||||
|
||||
# Keep Claude Stop hook scripts current (autopilot lives here).
|
||||
if [ -x "$SCRIPT_DIR/install-beacon.sh" ]; then
|
||||
bash "$SCRIPT_DIR/install-beacon.sh" --sync 2>/dev/null && ok "Beacon hook scripts synced" || true
|
||||
fi
|
||||
|
||||
# ── Enable and start ──────────────────────────────────────────────────────────
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable "$SERVICE_NAME"
|
||||
|
||||
# Stop the systemd-owned daemon before restarting. Avoid broad pkill patterns:
|
||||
# the installer itself may be invoked through a command line containing
|
||||
# "fleetcrown-daemon.sh", and pkill -f would kill its own parent shell.
|
||||
info "Ensuring single daemon instance…"
|
||||
systemctl --user stop "$SERVICE_NAME" 2>/dev/null || true
|
||||
sleep 0.5
|
||||
|
||||
# Start (or restart after stop above)
|
||||
if systemctl --user is-active "$SERVICE_NAME" >/dev/null 2>&1; then
|
||||
info "Service already running — restarting…"
|
||||
systemctl --user restart "$SERVICE_NAME"
|
||||
else
|
||||
systemctl --user start "$SERVICE_NAME"
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
STATUS=$(systemctl --user is-active "$SERVICE_NAME" 2>/dev/null || echo "failed")
|
||||
|
||||
if [ "$STATUS" = "active" ]; then
|
||||
ok "Daemon is ${bold}running${reset}."
|
||||
printf '\n'
|
||||
printf ' %sLogs:%s journalctl --user -u fleetcrown-daemon -f\n' "$cyan" "$reset"
|
||||
printf ' %sStatus:%s systemctl --user status fleetcrown-daemon\n' "$cyan" "$reset"
|
||||
printf ' %sStop:%s systemctl --user stop fleetcrown-daemon\n' "$cyan" "$reset"
|
||||
printf ' %sRemove:%s bash scripts/install-fleetcrown-daemon.sh --uninstall\n' "$cyan" "$reset"
|
||||
else
|
||||
warn "Service started but status is '${STATUS}'. Check logs:"
|
||||
printf ' journalctl --user -u fleetcrown-daemon -n 30\n'
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,53 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install ZSH hooks that let the app detect when you are actively typing at
|
||||
# the prompt — so auto-inject skips your tab instead of garbling your input.
|
||||
#
|
||||
# Usage: bash scripts/install-fleetcrown-hooks.sh
|
||||
# Effect: appends a small hook block to ~/.zshrc (idempotent).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=_brand.sh
|
||||
source "$SCRIPT_DIR/_brand.sh"
|
||||
|
||||
MARKER="# ${APP_SLUG}-typing-hooks"
|
||||
ZSHRC="${HOME}/.zshrc"
|
||||
|
||||
if grep -qF "$MARKER" "$ZSHRC" 2>/dev/null; then
|
||||
echo "Hooks already installed in $ZSHRC — nothing to do."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Heredoc with substitution enabled (no quotes on EOF) so $APP_SLUG expands
|
||||
# into the emitted hook block. The inner $-references that must stay literal
|
||||
# in the user's .zshrc are escaped with \.
|
||||
cat >> "$ZSHRC" << EOF
|
||||
|
||||
# ${APP_SLUG}-typing-hooks
|
||||
# Writes /tmp/${APP_SLUG}-typing-<PANE_ID> while the user is at the interactive
|
||||
# prompt so the app's inject API can skip this tab instead of garbling input.
|
||||
if [[ -n "\${ZELLIJ:-}" && -n "\${ZELLIJ_PANE_ID:-}" ]]; then
|
||||
# Capture the tab name once at shell start (this pane must be focused).
|
||||
_${APP_SLUG}_tab=\$(zellij action dump-layout 2>/dev/null \\
|
||||
| grep 'focus=true' \\
|
||||
| grep -o 'tab name="[^"]*"' \\
|
||||
| sed 's/tab name="\\(.*\\)"/\\1/' \\
|
||||
| head -1)
|
||||
|
||||
function _${APP_SLUG}_zle_line_init() {
|
||||
[[ -n "\${_${APP_SLUG}_tab:-}" ]] && \\
|
||||
printf '%s\\n%s' "\$_${APP_SLUG}_tab" "\$(date +%s)" \\
|
||||
> "/tmp/${APP_SLUG}-typing-\${ZELLIJ_PANE_ID}"
|
||||
}
|
||||
function _${APP_SLUG}_zle_line_finish() {
|
||||
rm -f "/tmp/${APP_SLUG}-typing-\${ZELLIJ_PANE_ID}"
|
||||
}
|
||||
zle -N zle-line-init _${APP_SLUG}_zle_line_init
|
||||
zle -N zle-line-finish _${APP_SLUG}_zle_line_finish
|
||||
trap 'rm -f "/tmp/${APP_SLUG}-typing-\${ZELLIJ_PANE_ID}"' EXIT
|
||||
fi
|
||||
EOF
|
||||
|
||||
echo "Done — hooks appended to $ZSHRC."
|
||||
echo "Reload with: source ~/.zshrc"
|
||||
@@ -1,37 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$#" -lt 3 ]; then
|
||||
echo "usage: run-codex-task.sh <tab> <project-dir> <prompt-file> [model]" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
TAB_NAME="$1"
|
||||
PROJECT_DIR="$2"
|
||||
PROMPT_FILE="$3"
|
||||
MODEL="${4:-gpt-5.4}" # must match AGENT_DEFAULT_MODELS.codex in src/lib/agent-registry.ts
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SESSION_DIR="${AGENT_SESSIONS_DIR:-$HOME/.claude/sessions}"
|
||||
|
||||
mkdir -p "$SESSION_DIR"
|
||||
|
||||
source "$HOME/.bashrc" >/dev/null 2>&1 || true
|
||||
|
||||
cd "$PROJECT_DIR"
|
||||
|
||||
status=0
|
||||
codex exec \
|
||||
--model "$MODEL" \
|
||||
--cd "$PROJECT_DIR" \
|
||||
--sandbox workspace-write \
|
||||
--add-dir "$SESSION_DIR" \
|
||||
- < "$PROMPT_FILE" || status=$?
|
||||
|
||||
rm -f "$PROMPT_FILE"
|
||||
|
||||
printf '%s' "$PROJECT_DIR" \
|
||||
| jq -Rs '{cwd:.}' \
|
||||
| AGENT_TAB_NAME="$TAB_NAME" AGENT_CURRENT_AGENT="codex" "$SCRIPT_DIR/agent-hook-bridge.sh" stop || true
|
||||
|
||||
exit "$status"
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$#" -lt 3 ]; then
|
||||
echo "usage: run-gemini-task.sh <tab> <project-dir> <prompt-file> [model]" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
TAB_NAME="$1"
|
||||
PROJECT_DIR="$2"
|
||||
PROMPT_FILE="$3"
|
||||
MODEL="${4:-auto}" # must match AGENT_DEFAULT_MODELS.gemini in src/lib/agent-registry.ts
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
source "$HOME/.bashrc" >/dev/null 2>&1 || true
|
||||
|
||||
cd "$PROJECT_DIR"
|
||||
|
||||
status=0
|
||||
if [ "$MODEL" = "auto" ]; then
|
||||
gemini --prompt "$(cat "$PROMPT_FILE")" --approval-mode yolo || status=$?
|
||||
else
|
||||
gemini --model "$MODEL" --prompt "$(cat "$PROMPT_FILE")" --approval-mode yolo || status=$?
|
||||
fi
|
||||
|
||||
rm -f "$PROMPT_FILE"
|
||||
|
||||
printf '%s' "$PROJECT_DIR" \
|
||||
| jq -Rs '{cwd:.}' \
|
||||
| AGENT_TAB_NAME="$TAB_NAME" AGENT_CURRENT_AGENT="gemini" "$SCRIPT_DIR/agent-hook-bridge.sh" stop || true
|
||||
|
||||
exit "$status"
|
||||
@@ -1,63 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
|
||||
TARGET_DIR="${1:-$PWD}"
|
||||
TAB_NAME="${2:-}"
|
||||
PROJECTS_CONF="${AGENT_PROJECTS_CONF:-$HOME/.config/agent-projects.conf}"
|
||||
|
||||
fail() {
|
||||
echo "FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
python3 "$ROOT/scripts/sync-agent-runtime-config.py" >/dev/null 2>&1 || true
|
||||
|
||||
[ -x "$ROOT/scripts/agent-hook-bridge.sh" ] || fail "missing agent-hook-bridge.sh"
|
||||
|
||||
if ! zellij action query-tab-names >/dev/null 2>&1; then
|
||||
fail "not connected to a live Zellij session"
|
||||
fi
|
||||
|
||||
if [ ! -d "$TARGET_DIR" ]; then
|
||||
fail "directory does not exist: $TARGET_DIR"
|
||||
fi
|
||||
|
||||
TARGET_DIR="$(realpath "$TARGET_DIR")"
|
||||
|
||||
if [ ! -f "$PROJECTS_CONF" ]; then
|
||||
PROJECTS_CONF="$HOME/.config/claude-projects.conf"
|
||||
fi
|
||||
|
||||
if [ -z "$TAB_NAME" ]; then
|
||||
TAB_NAME=$(
|
||||
zellij action dump-layout 2>/dev/null \
|
||||
| grep 'focus=true' \
|
||||
| grep 'tab name=' \
|
||||
| sed 's/.*tab name="\([^"]*\)".*/\1/' \
|
||||
| head -1
|
||||
)
|
||||
fi
|
||||
|
||||
[ -n "$TAB_NAME" ] || fail "could not determine the active Zellij tab name"
|
||||
|
||||
if ! awk -F'|' -v dir="$TARGET_DIR" '
|
||||
$0 !~ /^#/ && NF >= 2 && $2 == dir { found=1 }
|
||||
END { exit(found ? 0 : 1) }
|
||||
' "$PROJECTS_CONF" 2>/dev/null; then
|
||||
fail "directory is not registered in $(basename "$PROJECTS_CONF"): $TARGET_DIR"
|
||||
fi
|
||||
|
||||
printf 'Triggering Beacon stop smoke test for %s in tab %s\n' "$TARGET_DIR" "$TAB_NAME" >&2
|
||||
RESULT=$(
|
||||
jq -nc --arg cwd "$TARGET_DIR" '{cwd:$cwd}' \
|
||||
| AGENT_TAB_NAME="$TAB_NAME" AGENT_BRIDGE_EMIT_PROMPT=1 \
|
||||
"$ROOT/scripts/agent-hook-bridge.sh" stop
|
||||
) || RESULT=""
|
||||
|
||||
if [ -z "$RESULT" ]; then
|
||||
echo "No prompt returned. Either the popup was dismissed or tab resolution failed." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf 'Beacon returned a prompt payload (%s chars).\n' "${#RESULT}" >&2
|
||||
Reference in new issue
Block a user