From be58f2fe21f3a4f0924f0a789c8ec091f5247025 Mon Sep 17 00:00:00 2001 From: Daniel Rossier Date: Thu, 19 Nov 2026 18:44:32 +0100 Subject: [PATCH] Say what is missing when a container session has no model or no index Started from the container's shell with no model configured, SPEAR opened on a local server that is not there and showed its model as a question mark; the first question would have failed. The command now stops and says what to put in the configuration file. The startup check called a tree the user had just registered a corpus missing from the baked index, to be fixed by rebuilding the image. It now tells the image's own corpora, where that is a fault, from the user's, which are simply not indexed yet, and says how to index one from a session rather than with a host command the image does not have. --- client/cli/corpus_search.py | 7 +++++-- docker/entrypoint.sh | 33 +++++++++++++++++++++++++++------ docker/spear-chat | 25 +++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/client/cli/corpus_search.py b/client/cli/corpus_search.py index 037ab03..8f67b43 100644 --- a/client/cli/corpus_search.py +++ b/client/cli/corpus_search.py @@ -148,9 +148,12 @@ def federated_corpora(): try: col = client.get_collection(name=collection_name_for(sub)) except Exception: + # An image has no spear-index: a tree is indexed from a session. + + how = (f"open a session in {sub['path']} and run /reindex" + if SHIPPED_DB_PATH else f"spear-index {sub['path']}") print(f"{C_WARN}corpus '{n}' has no index yet " - f"({collection_name_for(sub)}) — index it with: " - f"spear-index {sub['path']}{C_RST}") + f"({collection_name_for(sub)}) — index it with: {how}{C_RST}") continue out.append((col, corpus_prefix(sub["path"]))) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 8f3f187..5006e57 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -67,25 +67,46 @@ print(f"corpora: {found} present, {miss} missing " # packaging fault, not a user choice. Unchecked, the harness says "no index # for this corpus yet (optional)" and starts with no retrieval at all -- which # is the entire reason the tool exists. +import json import textwrap have = {c.name for c in corpus_search._db().list_collections()} absent = sorted(n for n, spec in corpus_registry.load_projects().items() if os.path.isdir(spec["path"]) and corpus_search.collection_name_for(spec) not in have) -if absent: + +# The image's own corpora and the ones the user registered are two cases: the +# first without an index is a fault of the image, the second is a tree nobody +# has indexed yet. + +try: + with open(corpus_registry.PROJECTS_FILE) as handle: + shipped = set(json.load(handle)) +except (OSError, ValueError): + shipped = set() + +faulty = [n for n in absent if n in shipped] +unindexed = [n for n in absent if n not in shipped] + +if faulty: # Every name, not the first six. Announcing 11 and listing 6 reads as a # bug in the count -- the reader cannot tell which five are missing from # the list, and the whole point of the line is to say which corpora will # answer without retrieval. - print(f" WARNING: {len(absent)} mounted corpora have no collection in the " - f"baked index:") - for line in textwrap.wrap(", ".join(absent), 72): + print(f" WARNING: {len(faulty)} corpora of this image have no collection " + f"in its index:") + for line in textwrap.wrap(", ".join(faulty), 72): print(f" {line}") print(" They will answer without retrieval. Re-index on the host and " - "rebuild (scripts/docker/build.sh).") + "rebuild the image.") else: - print(f"index: every mounted corpus has its collection ({len(have)} total)") + print(f"index: every corpus of the image has its collection ({len(have)} total)") + +if unindexed: + print(f" {len(unindexed)} of your own corpora are not indexed yet:") + for line in textwrap.wrap(", ".join(unindexed), 72): + print(f" {line}") + print(" To index one: cd into its tree, spear-chat, then /reindex.") PY # The normative store. An image that carries a standard nothing is bound to diff --git a/docker/spear-chat b/docker/spear-chat index f8c341f..3ceecf3 100755 --- a/docker/spear-chat +++ b/docker/spear-chat @@ -10,4 +10,29 @@ case " $* " in && MODEL=(--provider "$SPEAR_CHAT_PROVIDER" ${SPEAR_CHAT_MODEL:+--model "$SPEAR_CHAT_MODEL"}) ;; esac +# With no model named anywhere the session would open on a local server that +# is not there, and only say so at the first question. + +case " $* " in + *" --provider"*|*" --api-base"*|*" --reds "*|*" --remote "*|*" --local "*|*" --help "*|*" -h "*) ;; + *) if [ -z "$SPEAR_CHAT_PROVIDER" ] && [ -z "$SPEAR_API_BASE" ]; then + cat >&2 <<'MSG' +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: + + SPEAR_PROVIDER=anthropic a hosted model, with its key + SPEAR_MODEL= + ANTHROPIC_API_KEY= + +or REDS_HOST=@ an inference host reached through ssh + SPEAR_REDS_KEY= + +`claude` needs none of this: it logs in with your own account. +MSG + exit 1 + fi ;; +esac + exec /opt/spear/entrypoint.sh "${MODEL[@]}" "$@"