Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ Unreleased
its build output or its *.back snapshots, honours the registry's
exclusions, and bakes a corpus nested in another by its own rule.

• spear-run.sh runs a published image on a machine that has docker and
nothing else: tunnel to the inference host, state volume, own
checkouts over the baked trees. It is copied into the image.
• scripts/docker/spear runs a published image on a machine that has
docker and nothing else: tunnel to the inference host, state
volume, own checkouts over the baked trees. It is copied into the
image.

v0.3.0 (8 oct 2026)

Expand Down
2 changes: 1 addition & 1 deletion client/cli/bake_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
the knowledge that was accepted -> the image's common knowledge

Run as root in a container of the image, with the state mounted; the launcher
then commits that container (spear-run.sh --build).
then commits that container (spear --build).

A corpus path under the user's home is rewritten relative to it, which is how
an image names its trees: whoever has the same checkout at the same place
Expand Down
23 changes: 19 additions & 4 deletions client/tests/test_reds_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ def test_the_registry_can_be_named(self):


class TheStandaloneLauncherNeedsOnlyDocker(unittest.TestCase):
"""scripts/docker/spear-run.sh: for a machine that has the image and
"""scripts/docker/spear: for a machine that has the image and
nothing else. It is also copied into the image, so a recipient can get it
from there."""

SCRIPT = DOCKER / "spear-run.sh"
SCRIPT = DOCKER / "spear"

def run_it(self, *args, env=None):
return subprocess.run([str(self.SCRIPT), *args], env=env,
Expand Down Expand Up @@ -497,7 +497,7 @@ def test_install_copies_the_launcher_and_keeps_an_existing_configuration(self):
if not k.startswith(("SPEAR_", "XDG_"))}
env["HOME"] = tmp
first = self.run_it("--install", "--image", "registry/spear:1", env=env)
installed = Path(tmp) / ".local/bin/spear-run.sh"
installed = Path(tmp) / ".local/bin/spear"
conf = Path(tmp) / ".config/spear/local.conf"

self.assertEqual(first.returncode, 0, first.stderr)
Expand All @@ -513,7 +513,22 @@ def test_install_copies_the_launcher_and_keeps_an_existing_configuration(self):
self.assertEqual(conf.read_text(), "SPEAR_IMAGE=mine\n")
self.assertEqual(installed.read_text(), self.SCRIPT.read_text())

def test_install_removes_the_launcher_under_its_former_name(self):
with tempfile.TemporaryDirectory() as tmp:
env = {k: v for k, v in os.environ.items()
if not k.startswith(("SPEAR_", "XDG_"))}
env["HOME"] = tmp
former = Path(tmp) / ".local/bin/spear-run.sh"
former.parent.mkdir(parents=True)
former.write_text("#!/bin/bash\n")

done = self.run_it("--install", "--image", "registry/spear:1", env=env)

self.assertEqual(done.returncode, 0, done.stderr)
self.assertFalse(former.exists())
self.assertTrue((Path(tmp) / ".local/bin/spear").exists())

def test_the_image_carries_it(self):
dockerfile = (REPO / "docker" / "Dockerfile").read_text()

self.assertIn("scripts/docker/spear-run.sh /opt/spear/spear-run.sh", dockerfile)
self.assertIn("scripts/docker/spear /opt/spear/spear", dockerfile)
4 changes: 2 additions & 2 deletions doc/source/operations/directory_layout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ arrangement, and the rest of this documentation uses the names:
- ``scripts/docker/spear-docker.sh``
- the assistant in a container, this machine's trees mounted
(:doc:`/start/container`)
* - ``spear-run.sh``
- ``scripts/docker/spear-run.sh``, also ``/opt/spear/spear-run.sh`` in the image
* - ``spear``
- ``scripts/docker/spear``, also ``/opt/spear/spear`` in the image
- a published image on a machine that has docker and nothing else
(:ref:`container_run_reds`)

Expand Down
20 changes: 10 additions & 10 deletions doc/source/start/container_run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ container reaches it through an SSH tunnel you open on your machine.

2. **Pull** the image, as above.

3. **Get the launcher.** ``spear-run.sh`` needs only docker, ssh and curl; it
3. **Get the launcher.** ``spear`` needs only docker, ssh and curl; it
opens the tunnel, mounts your state and runs the image. It is in the
repository under ``scripts/docker/``, and inside the image; ``--install``
copies it to ``~/.local/bin`` and writes ``~/.config/spear/local.conf``
with the image's name, so that ``spear-run.sh`` alone is enough afterwards:
with the image's name, so that ``spear`` alone is enough afterwards:

.. code-block:: console

$ IMAGE=ghcr.io/smartobjectoriented/spear-reds:<version>-reds
$ docker run --rm --entrypoint cat $IMAGE /opt/spear/spear-run.sh > /tmp/spear-run.sh
$ bash /tmp/spear-run.sh --install --image $IMAGE
$ docker run --rm --entrypoint cat $IMAGE /opt/spear/spear > /tmp/spear
$ bash /tmp/spear --install --image $IMAGE

4. **Run** it on the corpus you want to work in, by its path under
``/corpora``. The tunnel to the inference server (port 8010 there, 8082
Expand All @@ -97,9 +97,9 @@ container reaches it through an SSH tunnel you open on your machine.

.. code-block:: console

$ spear-run.sh --reds <account>@<inference host> --key ~/.ssh/id_reds \
$ spear --reds <account>@<inference host> --key ~/.ssh/id_reds \
--corpus opencn/opencn-ng --ask
$ spear-run.sh --list # every corpus and its path
$ spear --list # every corpus and its path

What does not change from one run to the next goes in a configuration
file rather than on every command line: ``~/.config/spear/local.conf``
Expand Down Expand Up @@ -130,14 +130,14 @@ container reaches it through an SSH tunnel you open on your machine.
The paths under ``/corpora`` are those of the building machine, relative to
its home: ``opencn/opencn-ng`` (and ``opencn/opencn-ng/linux/usr``),
``soo/so3/so3``, ``soo/so3/doc``, ``sye/sye_sol``,
``pos/pos_sol/so3`` and so on; ``spear-run.sh --list`` prints them all.
``pos/pos_sol/so3`` and so on; ``spear --list`` prints them all.

5. **Work on your own checkout** rather than the baked copy: mount it at the
same path, and it shadows the copy while the index keeps serving.

.. code-block:: console

$ spear-run.sh --reds <account>@<inference host> --key ~/.ssh/id_reds \
$ spear --reds <account>@<inference host> --key ~/.ssh/id_reds \
--mount ~/opencn/opencn-ng:opencn/opencn-ng --corpus opencn/opencn-ng --ask

The index describes the baked revision; after large changes to your tree,
Expand All @@ -149,7 +149,7 @@ container reaches it through an SSH tunnel you open on your machine.

.. code-block:: console

$ cd ~/src/my-checkout && spear-run.sh
$ cd ~/src/my-checkout && spear
SPEAR image, in /corpora/<path of the corpus>
corpus <corpus name>
spear-chat SPEAR on this tree (--ask, --safe, --auto)
Expand Down Expand Up @@ -200,7 +200,7 @@ container reaches it through an SSH tunnel you open on your machine.

.. code-block:: console

$ spear-run.sh --build <registry>/spear:<version>-<name>
$ spear --build <registry>/spear:<version>-<name>
registry 1 added: <corpus>
index <collection> (<n> chunks)
knowledge <n> active records
Expand Down
2 changes: 1 addition & 1 deletion doc/source/start/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ On a workstation that also has a native installation,
opens the tunnel and chats (:ref:`image-profiles`, :ref:`container`).

At the institute there is a shorter path still: the ``reds`` image carries the
shared trees and their index, and ``spear-run.sh`` runs it with nothing but
shared trees and their index, and ``spear`` runs it with nothing but
Docker (:ref:`container_run_reds`).

The native path
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ COPY --from=baked --chmod=0777 . /corpora/
COPY --from=common . /opt/spear/common/

# The launcher for a machine that has this image and nothing else: a recipient
# copies it out (`docker run --rm --entrypoint cat <image> /opt/spear/spear-run.sh`)
# copies it out (`docker run --rm --entrypoint cat <image> /opt/spear/spear`)
# and runs the image with it, tunnel included.
COPY --from=repo scripts/docker/spear-run.sh /opt/spear/spear-run.sh
COPY --from=repo scripts/docker/spear /opt/spear/spear
ENV SPEAR_COMMON_STATE_DIR=/opt/spear/common
# The standards store stays writable, so that a standard ingested in the
# container can be bound there; it is kept apart from the state directory
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.harness
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ RUN mkdir -p "$APP/rules.d" "$APP/skills" "$APP/benches" "$APP/chromadb" \
# The launcher a recipient copies out to run the image, and the entrypoint.
# Both live in the repo, not in client/, so they come from the `repo` context.

COPY --from=repo scripts/docker/spear-run.sh /opt/spear/spear-run.sh
COPY --from=repo scripts/docker/spear /opt/spear/spear
COPY --from=repo docker/entrypoint.sh /opt/spear/entrypoint.sh
COPY --from=repo docker/spear-mcp /usr/local/bin/spear-mcp
COPY --from=repo docker/spear-claude-export /usr/local/bin/spear-claude-export
Expand All @@ -104,7 +104,7 @@ COPY --from=repo docker/spear-claude-export /usr/local/bin/spear-claude-export
COPY --from=repo docker/spear-shell docker/spear-chat docker/spear-where \
docker/spear-bake-state /usr/local/bin/
COPY --from=repo docker/claude-launcher /usr/local/bin/claude
RUN chmod +x /opt/spear/entrypoint.sh /opt/spear/spear-run.sh /usr/local/bin/spear-mcp \
RUN chmod +x /opt/spear/entrypoint.sh /opt/spear/spear /usr/local/bin/spear-mcp \
/usr/local/bin/spear-claude-export /usr/local/bin/spear-shell /usr/local/bin/spear-chat \
/usr/local/bin/spear-where /usr/local/bin/spear-bake-state /usr/local/bin/claude

Expand Down
2 changes: 1 addition & 1 deletion docker/spear-bake-state
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Write a user's state into this image's registry, index and common
# knowledge; spear-run.sh --build runs it and commits the result.
# knowledge; spear --build runs it and commits the result.

exec /opt/spear/client/bin/python /opt/spear/client/cli/bake_state.py "$@"
2 changes: 1 addition & 1 deletion docker/spear-chat
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ case " $* " in
spear-chat: no model is configured, so SPEAR could not answer.

Leave this shell, name the model in ~/.config/spear/local.conf on your
machine, and run spear-run.sh again:
machine, and run spear again:

SPEAR_PROVIDER=anthropic a hosted model, with its key
SPEAR_MODEL=<model name>
Expand Down
2 changes: 1 addition & 1 deletion docker/spear-shell
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fi

echo
echo "${DIM}What you register and index here stays in your state directory. To hand it"
echo "on as an image: leave this shell, then spear-run.sh --build <tag>${OFF}"
echo "on as an image: leave this shell, then spear --build <tag>${OFF}"
echo

# The prompt is the shell's own: the user the container runs as has no entry
Expand Down
34 changes: 19 additions & 15 deletions scripts/docker/spear-run.sh → scripts/docker/spear
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
# repository, no registry of your own. It serves any image whose corpora are
# baked.
#
# cd <your tree> && spear-run.sh
# cd <your tree> && spear
#
# opens a shell in the container, in that tree, bound at the place the image
# knows it by when it is a checkout of one of its corpora (same path under
# your home as under /corpora) and at its own path otherwise. Two commands
# are there: `spear-chat` for SPEAR, `claude` for Claude Code, each with the
# rules, skills and index of the corpus.
#
# spear-run.sh [--image IMAGE] [--pull]
# [--reds USER@HOST [--key FILE] [--port N] | --endpoint URL
# | --provider anthropic [--model NAME]]
# [--tree NAME | --corpus PATH]
# [--mount HOST_DIR:PATH]... [--state DIR] [--build TAG]
# [-- harness args, e.g. --ask, --auto, --fresh]
# spear [--image IMAGE] [--pull]
# [--reds USER@HOST [--key FILE] [--port N] | --endpoint URL
# | --provider anthropic [--model NAME]]
# [--tree NAME | --corpus PATH]
# [--mount HOST_DIR:PATH]... [--state DIR] [--build TAG]
# [-- harness args, e.g. --ask, --auto, --fresh]
#
# --image the image to run; default ghcr.io/smartobjectoriented/spear-reds
# at this release
Expand Down Expand Up @@ -100,7 +100,7 @@ MOUNTS=()
ARGS=()

usage() { sed -n '2,67p' "$0" | sed 's/^# \{0,1\}//'; exit "${1:-0}"; }
die() { echo "spear-run: $*" >&2; exit 1; }
die() { echo "spear: $*" >&2; exit 1; }

while [ $# -gt 0 ]; do
case "$1" in
Expand Down Expand Up @@ -133,19 +133,23 @@ if [ "$INSTALL" = 1 ]; then
# A link to this very file is already the install; anything else is
# replaced, a link first so that the copy does not go through it.

if [ "$(readlink -f "$BIN/spear-run.sh")" != "$(readlink -f "$0")" ]; then
rm -f "$BIN/spear-run.sh"
cp "$0" "$BIN/spear-run.sh"
chmod 755 "$BIN/spear-run.sh"
if [ "$(readlink -f "$BIN/spear")" != "$(readlink -f "$0")" ]; then
rm -f "$BIN/spear"
cp "$0" "$BIN/spear"
chmod 755 "$BIN/spear"
fi

echo "installed $BIN/spear-run.sh"
# The launcher's former name would otherwise stay beside the new one.

rm -f "$BIN/spear-run.sh"

echo "installed $BIN/spear"

if [ -e "$CONF" ]; then
echo "kept $CONF"
else
cat > "$CONF" <<EOF
# Read by spear-run.sh before its options; shell, one assignment per line.
# Read by spear before its options; shell, one assignment per line.
SPEAR_IMAGE=$IMAGE

# The model spear-chat talks to: a hosted one,
Expand Down Expand Up @@ -265,7 +269,7 @@ ENTRY=()

if [ ${#ARGS[@]} -eq 0 ]; then
ENTRY=(--entrypoint spear-shell)
backend || echo "spear-run: no model for spear-chat ($WHY)" >&2
backend || echo "spear: no model for spear-chat ($WHY)" >&2
else
backend || die "$WHY"
[ -n "$PROVIDER" ] && ARGS=(--provider "$PROVIDER" ${MODEL:+--model "$MODEL"} "${ARGS[@]}")
Expand Down
Loading