halkyon/apps/learn/halkyon_learn_agent/tool/install.sh
Tizian 「ティツィアーン」 54e212a51c
Some checks failed
CI / check (push) Failing after 1m56s
feat(learn): Learn's agent, an MCP server suggesting in shared studysets
Halkyon's ADR 0044, step 6c (D7, D49 to D52). apps/learn/halkyon_learn_agent
is one executable, `halkyon-agent --instance URL sign-in | sync | mcp`:

- sign-in keeps the token read from stdin, signs in with it, makes the
  agent's key pair on its first sign-in, keeps it before setting the
  public halves on the register (agents.setKeys), and syncs;
- it opens its data as the app's _openPersonData does, on
  halkyon_learn_core and halkyon_content: its own SQLite database, the
  sync's space router, its keys and those of the spaces shared with it,
  and the repositories of studysets, cards, notes, paths, files and
  feedback;
- mcp serves ten tools over stdio (dart_mcp): list, read and search the
  studysets shared with it, suggest a change or a new card or note,
  report, list a studyset's suggestions and reply. Each syncs first and
  a suggestion again at once; a refusal is the tool's error;
- its files live in $XDG_CONFIG_HOME/halkyon-agent/<host>, 0700 and
  0600, refused when others may read them (D50);
- tool/install.sh builds it with `dart build cli` (libsodium and SQLite
  bundled) and copies it to its user on the host, the build before kept
  (D52).

The synced gateways of learning paths and files, and the fakes of the
core's gateways, move into halkyon_learn_core (its testing.dart), which
the app's tests and the agent's share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-11-11 22:08:31 +01:00

51 lines
1.9 KiB
Shell
Executable file

#!/usr/bin/env bash
# Builds Halkyon Learn's agent on this machine and copies it to its user on
# the host it runs on (Halkyon's ADR 0044, D52), which has no Dart SDK:
#
# apps/learn/halkyon_learn_agent/tool/install.sh <ssh target>
#
# e.g. `claude@halkyon-li-host`. Each build goes into a folder of its own,
# ~/.local/lib/halkyon-agent/<commit>, `current` pointing to it and
# ~/.local/bin/halkyon-agent to its executable, so an agent still running
# keeps its files; the build before stays, the older ones go.
set -euo pipefail
target=${1:?"usage: $0 <ssh target>"}
package=$(cd "$(dirname "$0")/.." && pwd)
# `dart build cli` builds for this machine alone.
remote_arch=$(ssh "$target" uname -m)
if [[ $remote_arch != "$(uname -m)" ]]; then
echo "The host is $remote_arch, this machine $(uname -m): build on one like it." >&2
exit 1
fi
version=$(git -C "$package" rev-parse --short=12 HEAD)
if [[ -n $(git -C "$package" status --porcelain -- . ../halkyon_learn_core ../../../packages) ]]; then
version="$version-dirty-$(date +%Y%m%d%H%M%S)"
fi
build=$(mktemp -d)
trap 'rm -rf "$build"' EXIT
(cd "$package" && dart build cli -o "$build")
# tar rather than rsync, which the host may lack; for its user alone.
tar -C "$build/bundle" -cz . | ssh "$target" "
set -eu
umask 077
lib=\$HOME/.local/lib/halkyon-agent
mkdir -p \"\$lib/$version\" \"\$HOME/.local/bin\"
tar -C \"\$lib/$version\" -xz
previous=\$(readlink \"\$lib/current\" || true)
ln -sfn '$version' \"\$lib/current\"
ln -sfn \"\$lib/current/bin/halkyon_agent\" \"\$HOME/.local/bin/halkyon-agent\"
for old in \"\$lib\"/*/; do
old=\$(basename \"\$old\")
# current/ is a link to a build, never one itself.
if [ ! -L \"\$lib/\$old\" ] && [ \"\$old\" != '$version' ] && [ \"\$old\" != \"\$previous\" ]; then
rm -rf \"\$lib/\$old\"
fi
done
\"\$HOME/.local/bin/halkyon-agent\" --help > /dev/null
"
echo "Installed $version on $target: ~/.local/bin/halkyon-agent." >&2