ai-first-os 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +226 -0
- package/bin/ai-first-os.js +72 -0
- package/core/CLAUDE.md +148 -0
- package/core/VERSION +1 -0
- package/core/agents/ambiguous-spec.md +39 -0
- package/core/agents/complete-spec.md +36 -0
- package/core/agents/scout.md +25 -0
- package/core/install.sh +243 -0
- package/core/lib/archive.sh +347 -0
- package/core/lib/bootstrap.sh +276 -0
- package/core/lib/capture.sh +188 -0
- package/core/lib/check-resolvable.sh +172 -0
- package/core/lib/close-session.sh +741 -0
- package/core/lib/common.sh +1773 -0
- package/core/lib/focus-read.sh +282 -0
- package/core/lib/manual-link.sh +111 -0
- package/core/lib/markdown.py +304 -0
- package/core/lib/migrate-backlogs.sh +207 -0
- package/core/lib/migrate-canonicals.sh +523 -0
- package/core/lib/mount-repo.sh +543 -0
- package/core/lib/my-wiki-gates.sh +137 -0
- package/core/lib/my-wiki.sh +202 -0
- package/core/lib/my_wiki_build.py +548 -0
- package/core/lib/my_wiki_graph.py +137 -0
- package/core/lib/my_wiki_overview.py +392 -0
- package/core/lib/new-memory.sh +160 -0
- package/core/lib/new-product.sh +122 -0
- package/core/lib/new-workspace.sh +105 -0
- package/core/lib/pack-install.sh +114 -0
- package/core/lib/recall.sh +235 -0
- package/core/lib/recall_index.py +295 -0
- package/core/lib/remote-backup.sh +84 -0
- package/core/lib/rename-heads.sh +354 -0
- package/core/lib/rename-workspaces.sh +271 -0
- package/core/lib/session-read.sh +203 -0
- package/core/lib/session-start.sh +854 -0
- package/core/lib/supersede.sh +436 -0
- package/core/lib/sweep.sh +473 -0
- package/core/manual/COMO-FUNCIONA.md +251 -0
- package/core/manual/HOW-IT-WORKS.md +250 -0
- package/core/resolver.md +30 -0
- package/core/skills/archive.md +95 -0
- package/core/skills/bootstrap.md +226 -0
- package/core/skills/capture.md +65 -0
- package/core/skills/check-resolvable.md +38 -0
- package/core/skills/close-session.md +108 -0
- package/core/skills/grill.md +74 -0
- package/core/skills/mount-repo.md +97 -0
- package/core/skills/my-wiki.md +103 -0
- package/core/skills/new-memory.md +76 -0
- package/core/skills/new-product.md +55 -0
- package/core/skills/new-spec.md +114 -0
- package/core/skills/new-workspace.md +53 -0
- package/core/skills/recall.md +64 -0
- package/core/skills/rename-heads.md +72 -0
- package/core/skills/rename-workspaces.md +43 -0
- package/core/skills/supersede.md +83 -0
- package/core/skills/sweep.md +40 -0
- package/core/templates/my-wiki-graph.js +431 -0
- package/core/templates/my-wiki-overview.js +174 -0
- package/core/templates/my-wiki.html +1017 -0
- package/core/templates/node-folder/README.md +11 -0
- package/core/templates/node-folder/resolver.md +9 -0
- package/core/templates/node-light.md +22 -0
- package/core/templates/node-product/README.md +8 -0
- package/core/templates/node-repo/README.md +14 -0
- package/core/templates/node-repo/context/README.md +22 -0
- package/core/templates/node-repo/context/competitors.md +8 -0
- package/core/templates/node-repo/context/glossary.md +8 -0
- package/core/templates/node-repo/context/open-questions.md +9 -0
- package/core/templates/node-repo/context/opportunities.md +9 -0
- package/core/templates/node-repo/context/problem.md +8 -0
- package/core/templates/node-repo/context/scope.md +8 -0
- package/core/templates/node-repo/context/users.md +8 -0
- package/core/templates/node-repo/context/vision.md +8 -0
- package/core/templates/node-repo/resolver.md +14 -0
- package/core/templates/operator.md +17 -0
- package/core/templates/person.md +10 -0
- package/core/templates/repo-scaffold/ARCHITECTURE.md +3 -0
- package/core/templates/repo-scaffold/CLAUDE.md +23 -0
- package/core/templates/repo-scaffold/decisions.md +3 -0
- package/core/templates/repo-scaffold/evals-run.sh +14 -0
- package/core/templates/repo-scaffold/gitignore +3 -0
- package/core/templates/repo-scaffold/settings.json +8 -0
- package/core/templates/root-resolver.md +5 -0
- package/core/templates/strings.md +1361 -0
- package/core/templates/tree.md +59 -0
- package/core/templates/voice.md +5 -0
- package/package.json +23 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Parte determinística de `new-workspace`: escribe el nodo del espacio de trabajo.
|
|
3
|
+
# La entrevista la conduce core/skills/new-workspace.md. Interno: no es invocable.
|
|
4
|
+
#
|
|
5
|
+
# Uso: new-workspace.sh --brain DIR --name NOMBRE --role ROL --owner PERSONA
|
|
6
|
+
# [--title TITULO] [--slug SLUG] [--identity-file ARCHIVO]
|
|
7
|
+
#
|
|
8
|
+
# `--role` activa un oficio de posición del pack (spec 009) y nace vacío (spec 020): es un acto
|
|
9
|
+
# deliberado, aparte de la entrevista, nombrar ahí el slug de un oficio instalado (hoy: `cpo`).
|
|
10
|
+
# `--title` es identidad —"qué hacés en esta organización", en palabras del operador— y va al
|
|
11
|
+
# cuerpo de la cabeza, nunca al frontmatter: no activa nada.
|
|
12
|
+
|
|
13
|
+
set -eu
|
|
14
|
+
|
|
15
|
+
here=$(cd "$(dirname "$0")" && pwd)
|
|
16
|
+
. "$here/common.sh"
|
|
17
|
+
|
|
18
|
+
brain=""
|
|
19
|
+
name=""
|
|
20
|
+
role=""
|
|
21
|
+
role_given=0
|
|
22
|
+
title=""
|
|
23
|
+
owner=""
|
|
24
|
+
slug=""
|
|
25
|
+
identity_file=""
|
|
26
|
+
|
|
27
|
+
while [ $# -gt 0 ]; do
|
|
28
|
+
case "$1" in
|
|
29
|
+
--brain) brain="$2"; shift 2 ;;
|
|
30
|
+
--name) name="$2"; shift 2 ;;
|
|
31
|
+
--role) role="$2"; role_given=1; shift 2 ;;
|
|
32
|
+
--title) title="$2"; shift 2 ;;
|
|
33
|
+
--owner) owner="$2"; shift 2 ;;
|
|
34
|
+
--slug) slug="$2"; shift 2 ;;
|
|
35
|
+
--identity-file) identity_file="$2"; shift 2 ;;
|
|
36
|
+
*) os_die "argumento desconocido: $1" ;;
|
|
37
|
+
esac
|
|
38
|
+
done
|
|
39
|
+
|
|
40
|
+
[ -n "$brain" ] || os_die "falta --brain"
|
|
41
|
+
[ -n "$name" ] || os_die "falta --name"
|
|
42
|
+
# El comando escribe `role:`, nunca el humano. Nace vacío (spec 020): --role "" es válido,
|
|
43
|
+
# omitir --role no lo es — la misma disciplina de antes, ahora con el valor por omisión en vacío.
|
|
44
|
+
[ "$role_given" = "1" ] || os_die "falta --role: el rol lo escribe el comando, no el humano"
|
|
45
|
+
[ -n "$owner" ] || os_die "falta --owner"
|
|
46
|
+
|
|
47
|
+
[ -n "$slug" ] || slug=$(os_slugify "$name")
|
|
48
|
+
[ -n "$slug" ] || os_die "el nombre no produce un slug utilizable: $name"
|
|
49
|
+
|
|
50
|
+
# Layout inválido frena acá, antes de cualquier $(...) que arme una ruta con el nombre de la
|
|
51
|
+
# carpeta (P2, spec 039): un `os_die` adentro de una subshell mata solo la subshell.
|
|
52
|
+
os_ws_check "$brain"
|
|
53
|
+
wsdir=$(os_ws_dir "$brain")
|
|
54
|
+
|
|
55
|
+
dir="$brain/$wsdir/$slug"
|
|
56
|
+
if [ -e "$dir" ]; then
|
|
57
|
+
os_die "ya existe: $wsdir/$slug"
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
# El idioma es dato de la raíz (spec 021): lo declara `operator.md` y no se vuelve a preguntar. Un
|
|
61
|
+
# espacio de trabajo sumado meses después nace en el mismo idioma que el resto del brain.
|
|
62
|
+
language=$(os_language "$brain")
|
|
63
|
+
os_lang_load "$language"
|
|
64
|
+
|
|
65
|
+
identity="$S_ORG_IDENTITY_PLACEHOLDER"
|
|
66
|
+
if [ -n "$identity_file" ]; then
|
|
67
|
+
[ -f "$identity_file" ] || os_die "no existe el archivo de identidad: $identity_file"
|
|
68
|
+
identity=$(cat "$identity_file")
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
templates="$here/../templates/node-folder"
|
|
72
|
+
today=$(date +%Y-%m-%d)
|
|
73
|
+
|
|
74
|
+
mkdir -p "$dir/initiatives"
|
|
75
|
+
|
|
76
|
+
# El nombre de la cabeza es dato del brain (spec 040): la forma nueva es `README.md` y un brain que
|
|
77
|
+
# todavía no la adoptó recibe su nodo nuevo en la forma que ya tiene — mezclar las dos en el mismo
|
|
78
|
+
# brain es el layout que `rename-heads` existe para reparar.
|
|
79
|
+
head=$(os_head_file "$brain") || true
|
|
80
|
+
os_render_lang "$templates/README.md" "$language" \
|
|
81
|
+
"NAME=$name" "ROLE=$role" "TITLE=$title" "OWNER=$owner" "DATE=$today" "IDENTITY=$identity" \
|
|
82
|
+
> "$dir/$head"
|
|
83
|
+
os_render_lang "$templates/resolver.md" "$language" "NAME=$name" > "$dir/resolver.md"
|
|
84
|
+
|
|
85
|
+
os_check_identity_cap "$dir/$head"
|
|
86
|
+
|
|
87
|
+
# La altura del espacio de trabajo queda declarada en el árbol, en la forma con la que este nodo
|
|
88
|
+
# acaba de nacer (spec 040). Un brain que no la tenía —uno que hasta hoy solo tuvo trabajo propio de
|
|
89
|
+
# la raíz— se quedaba con el nodo nuevo sin que ningún glob lo alcanzara: escrito y ciego para todo
|
|
90
|
+
# barrido. Los brains que ya la declaran no cambian: `os_tree_ensure` no duplica.
|
|
91
|
+
os_tree_ensure "$brain" "$wsdir/*/$head" || true
|
|
92
|
+
os_tree_ensure "$brain" "$wsdir/*/resolver.md" || true
|
|
93
|
+
os_tree_ensure "$brain" "$wsdir/*/backlog.md" || true
|
|
94
|
+
os_tree_ensure "$brain" "$wsdir/*/decisions.md" || true
|
|
95
|
+
os_tree_ensure "$brain" "$wsdir/*/learnings.md" || true
|
|
96
|
+
# Los cuerpos de esas dos preguntas, uno por decisión y por aprendizaje: alcanzados, nunca leídos
|
|
97
|
+
# como cabeza (spec 043 — misma clase `content:` que ya usa `context/`/`research/`).
|
|
98
|
+
os_tree_ensure "$brain" "$wsdir/*/decisions/*.md" content || true
|
|
99
|
+
os_tree_ensure "$brain" "$wsdir/*/learnings/*.md" content || true
|
|
100
|
+
# La altura de las iniciativas de ese nodo, en la forma que el brain tenga para esa altura: el
|
|
101
|
+
# glob sale del mismo helper que arma la ruta de una cabeza, con `*` en lugar del slug.
|
|
102
|
+
os_tree_ensure "$brain" "$wsdir/*/$(os_head_path "$brain" initiative '*')" || true
|
|
103
|
+
os_tree_ensure "$brain" "$wsdir/*/initiatives/*/*.md" content || true
|
|
104
|
+
|
|
105
|
+
printf '%s/%s — %s · resolver.md · initiatives/\n' "$wsdir" "$slug" "$head"
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# El paso del pack, diferible (spec 029). Interno: no es invocable — tiene fila de capacidad en
|
|
3
|
+
# `core/resolver.md`, igual que `remote-backup.sh`, y lo conducen `core/skills/bootstrap.md` al
|
|
4
|
+
# cerrar el bootstrap y cualquier sesión posterior que lo rutee.
|
|
5
|
+
#
|
|
6
|
+
# Uso: pack-install.sh --brain DIR [--defer] [--line]
|
|
7
|
+
#
|
|
8
|
+
# (sin flags) el ofrecimiento: qué hay instalado, qué falta y el comando exacto.
|
|
9
|
+
# --defer la salida "después": deja la tarea en el backlog de la raíz, con el comando
|
|
10
|
+
# adentro. Escribe el archivo directo, sin pasar por `capture` (spec 057): este paso
|
|
11
|
+
# es determinístico, sin ningún modelo que pueda nombrar una iniciativa.
|
|
12
|
+
# --line una línea, para el aviso de capacidad no instalada del arranque de sesión.
|
|
13
|
+
#
|
|
14
|
+
# El script NUNCA corre `npx`: bajar software a la máquina del operador escapa del sistema y se hace
|
|
15
|
+
# con su sí, en la sesión — mismo criterio que `remote-backup.sh` con `gh repo create`.
|
|
16
|
+
#
|
|
17
|
+
# Node se chequea ACÁ y en ningún otro lado del sistema (decisión 1 de la spec 029): instalar el OS
|
|
18
|
+
# pide git y nada más, y Node es requisito de este momento. Sin Node el script no falla: dice qué
|
|
19
|
+
# falta, dónde se consigue, y ofrece la salida "después".
|
|
20
|
+
#
|
|
21
|
+
# El nombre del repo del pack se escribe una sola vez —el default de `scripts/release-public.sh`— y
|
|
22
|
+
# el release lo inyecta acá donde el fuente lleva `pedroromeroluna/ai-first-product-skills`.
|
|
23
|
+
#
|
|
24
|
+
# Exit: 0 el ofrecimiento o la tarea quedaron dichos · 1 el brain no existe.
|
|
25
|
+
|
|
26
|
+
set -eu
|
|
27
|
+
|
|
28
|
+
here=$(cd "$(dirname "$0")" && pwd)
|
|
29
|
+
. "$here/common.sh"
|
|
30
|
+
|
|
31
|
+
brain=""
|
|
32
|
+
modo="ofrecer"
|
|
33
|
+
|
|
34
|
+
while [ $# -gt 0 ]; do
|
|
35
|
+
case "$1" in
|
|
36
|
+
--brain) brain="$2"; shift 2 ;;
|
|
37
|
+
--defer) modo="defer"; shift ;;
|
|
38
|
+
--line) modo="line"; shift ;;
|
|
39
|
+
*) os_die "argumento desconocido: $1" ;;
|
|
40
|
+
esac
|
|
41
|
+
done
|
|
42
|
+
|
|
43
|
+
[ -n "$brain" ] || os_die "falta --brain"
|
|
44
|
+
[ -d "$brain" ] || os_die "no existe el brain: $brain"
|
|
45
|
+
brain=$(cd "$brain" && pwd -P)
|
|
46
|
+
|
|
47
|
+
# El nombre del repo del pack: el fuente lleva el placeholder y el release lo resuelve al generar el
|
|
48
|
+
# chasis. El comando exacto se arma una sola vez acá y lo leen las tres salidas.
|
|
49
|
+
pack_repo="pedroromeroluna/ai-first-product-skills"
|
|
50
|
+
comando="npx skills add $pack_repo"
|
|
51
|
+
|
|
52
|
+
# Qué del pack ya está donde el CLI lo deja. No es una lista escrita: es lo que hay en el brain.
|
|
53
|
+
instalados=""
|
|
54
|
+
n_instalados=0
|
|
55
|
+
for d in "$brain"/.claude/skills/*/SKILL.md; do
|
|
56
|
+
[ -f "$d" ] || continue
|
|
57
|
+
d=$(dirname "$d")
|
|
58
|
+
instalados="$instalados$(basename "$d") "
|
|
59
|
+
n_instalados=$(( n_instalados + 1 ))
|
|
60
|
+
done
|
|
61
|
+
|
|
62
|
+
if [ "$modo" = "line" ]; then
|
|
63
|
+
# El aviso corto: la demanda dispara la oferta (decisión 3 de la spec 029). Con algo del pack ya
|
|
64
|
+
# instalado no hay nada que ofrecer — lo que falte es otro problema y este no es su mensaje.
|
|
65
|
+
[ "$n_instalados" = "0" ] || exit 0
|
|
66
|
+
printf 'el pack no está instalado: %s\n' "$comando"
|
|
67
|
+
exit 0
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
language=$(os_language "$brain")
|
|
71
|
+
os_lang_load "$language"
|
|
72
|
+
tarea="$S_PACK_TASK \`$comando\`"
|
|
73
|
+
|
|
74
|
+
if [ "$modo" = "defer" ]; then
|
|
75
|
+
if [ -f "$brain/backlog.md" ] && grep -qF "$tarea" "$brain/backlog.md"; then
|
|
76
|
+
printf 'pack: la tarea pendiente ya estaba en el backlog de la raíz\n'
|
|
77
|
+
exit 0
|
|
78
|
+
fi
|
|
79
|
+
# No pasa por `capture` (spec 057, decisión 2: nada entra sin clasificar): este paso corre
|
|
80
|
+
# determinístico, sin ningún modelo en el medio que pueda proponer una iniciativa y esperar la
|
|
81
|
+
# confirmación del operador — instalar el pack de skills no es trabajo de ninguna iniciativa, es
|
|
82
|
+
# un paso pendiente del propio sistema. Escribe directo en `backlog.md` de la raíz, con el mismo
|
|
83
|
+
# formato de línea y el mismo contador global que usa el resto del sistema; ese archivo, fuera de
|
|
84
|
+
# toda iniciativa, es justo el hallazgo que la spec 057 declara aparte (S057-C5) hasta que el
|
|
85
|
+
# operador corra el comando.
|
|
86
|
+
hoy=$(date +%Y-%m-%d)
|
|
87
|
+
nacio=0
|
|
88
|
+
[ -f "$brain/backlog.md" ] || nacio=1
|
|
89
|
+
[ "$nacio" = "1" ] && os_backlog_cabecera "$brain" "$(os_titulo "$brain/operator.md")" > "$brain/backlog.md"
|
|
90
|
+
id=$(os_backlog_next_id "$brain")
|
|
91
|
+
printf '%s\n' "$(os_backlog_linea "$id" "$tarea" "" "" "" "0" "$hoy")" >> "$brain/backlog.md"
|
|
92
|
+
printf 'pack: pendiente — la tarea quedó en el backlog de la raíz, con el comando adentro\n'
|
|
93
|
+
exit 0
|
|
94
|
+
fi
|
|
95
|
+
|
|
96
|
+
# --------------------------------------------------------------------- el ofrecimiento
|
|
97
|
+
if [ "$n_instalados" = "0" ]; then
|
|
98
|
+
printf 'pack: nada instalado todavía en .claude/skills\n'
|
|
99
|
+
else
|
|
100
|
+
printf 'pack: ya instalado en .claude/skills: %s\n' "$instalados"
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
# El comando baja solo lo que el pack ofrece: lo que el chasis ya provee viaja marcado interno y el
|
|
104
|
+
# CLI lo saltea sin que nadie tenga que nombrarlo (spec 029). Nunca se instala para después borrar.
|
|
105
|
+
if command -v node > /dev/null 2>&1; then
|
|
106
|
+
printf 'node: %s\n' "$(node --version 2>/dev/null || printf 'presente')"
|
|
107
|
+
printf ' comando: %s\n' "$comando"
|
|
108
|
+
printf ' tal cual: sin --all y sin --skill "*", que bajan también lo que el chasis ya provee\n'
|
|
109
|
+
printf ' lo corre la sesión con el sí del operador, desde la carpeta del brain; este script nunca lo corre\n'
|
|
110
|
+
else
|
|
111
|
+
printf 'node: falta — el instalador LTS está en nodejs.org, y lo instala el operador, nunca el agente\n'
|
|
112
|
+
printf ' con node presente: %s\n' "$comando"
|
|
113
|
+
printf ' o dejarlo para después: %s --brain %s --defer\n' "$here/pack-install.sh" "$brain"
|
|
114
|
+
fi
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Living Memory: search over everything the tree reaches, not only what the startup and the focus
|
|
3
|
+
# load (spec 050). Invocable — `core/skills/recall.md` is its contract.
|
|
4
|
+
#
|
|
5
|
+
# Usage: recall.sh --brain DIR (--workspace SLUG | --org SLUG | --root | --all) QUERY [--limit N]
|
|
6
|
+
# recall.sh --brain DIR --expand PATH
|
|
7
|
+
#
|
|
8
|
+
# `--org` is an exact synonym of `--workspace` (spec 039), same rule as `session-start.sh`: the two
|
|
9
|
+
# with the same value, or only one, work the same; the two with different values stop with an error.
|
|
10
|
+
#
|
|
11
|
+
# WHAT THIS COMMAND INDEXES. The index is `.os/living-memory.sqlite`, inside the brain: never
|
|
12
|
+
# committed (`.os/` is already in every brain's `.gitignore`, `os_gitignore_ensure`), and it is
|
|
13
|
+
# derived and discardable — deleting it just costs the next call a full reindex. It is written with
|
|
14
|
+
# `python3` and the `sqlite3` module of the standard library, using an FTS5 table: no dependency the
|
|
15
|
+
# product does not already carry (`python3` is a hard requirement since spec 030, and the sqlite3
|
|
16
|
+
# that ships with the official installers of macOS, Windows and Linux carries FTS5).
|
|
17
|
+
#
|
|
18
|
+
# THE FILE LIST HAS ONE READER. `tree.md` has two classes of line since spec 007, and the only
|
|
19
|
+
# reader of that format is `common.sh`: `os_tree_files` (the `glob:` class — what a scan reads as a
|
|
20
|
+
# head) and `os_tree_content_files` (the `content:` class — reached, never read as a head). Both are
|
|
21
|
+
# read here, in bash, and handed to the Python side over stdin: no second parser of `tree.md`.
|
|
22
|
+
#
|
|
23
|
+
# RECONCILIATION RUNS ON EVERY CALL, BEFORE SEARCHING. There is no hook — a hook is infrastructure
|
|
24
|
+
# every brain would have to install, and a stale index is worse than a slower call. Size and mtime
|
|
25
|
+
# are the first filter: a file whose size and mtime match what is stored is skipped without reading
|
|
26
|
+
# it. A file whose size or mtime changed is hashed, and only a changed hash makes it reindex — so a
|
|
27
|
+
# `git pull` or a branch switch that touches files without changing their text (mtime moves, content
|
|
28
|
+
# does not) reindexes nothing, only refreshes the stored size and mtime. A stored path the tree no
|
|
29
|
+
# longer reaches is dropped, entries and relations included.
|
|
30
|
+
#
|
|
31
|
+
# THE UNIT OF THE INDEX IS THE ENTRY, NOT THE FILE (spec 050 C2). A file is split by heading (`#`,
|
|
32
|
+
# `##`, `###`): each entry is the heading plus its body, up to the next one. A file with no heading
|
|
33
|
+
# at all, whose body is top-level list items (`backlog.md`, `inbox.md`, any canonical list of the
|
|
34
|
+
# system), splits one entry per `- ` item instead. A file that is neither is a single entry. The
|
|
35
|
+
# frontmatter block never becomes part of an entry. The reader of that block is a second reading of
|
|
36
|
+
# the same format `common.sh` reads (`fm_read`, lines 289-345 there): the bound is the same
|
|
37
|
+
# (`CAP_FRONTMATTER`, 30 lines) and the keys are the same six this feature needs
|
|
38
|
+
# (`updated`, `fecha`, `date`, `status`, `about`, `superseded_by`) — whenever the two disagree on the
|
|
39
|
+
# shape, `common.sh` is the authority, never this script.
|
|
40
|
+
#
|
|
41
|
+
# LO REEMPLAZADO NUNCA QUEDA ARRIBA DE LO VIGENTE (C4). `status` is a column of the FTS5 table
|
|
42
|
+
# itself, and the query's `ORDER BY` puts it ahead of the relevance score, before the `LIMIT` is
|
|
43
|
+
# applied — bringing everything into Python and sorting there would not satisfy this criterion, so
|
|
44
|
+
# it is never done.
|
|
45
|
+
#
|
|
46
|
+
# THE SCOPE IS THE SESSION'S, AND CROSSING IT IS EXPLICIT (C5). Exactly one of `--workspace`
|
|
47
|
+
# (`--org`), `--root` or `--all` is required outside `--expand` mode; none of the three is an error.
|
|
48
|
+
#
|
|
49
|
+
# `--expand PATH` prints the neighbours of a file one jump away — the head its `about:` names, the
|
|
50
|
+
# files whose `about:` names it, the file its `superseded_by:` names, and the files whose
|
|
51
|
+
# `superseded_by:` names it — read from the relations table the index already keeps, never from
|
|
52
|
+
# disk beyond the reconciliation every call already does. One jump is one jump, same rule
|
|
53
|
+
# `focus-read.sh` already follows: what a neighbour itself declares is never chased.
|
|
54
|
+
#
|
|
55
|
+
# Exit: 0 the search or the expansion ran, with or without results/neighbours. 1 invalid arguments
|
|
56
|
+
# (missing/contradictory flags, no scope named). 2 the named workspace does not exist (same keys as
|
|
57
|
+
# `session-start.sh`).
|
|
58
|
+
#
|
|
59
|
+
# No `set -e`: a query with no results is not a failure.
|
|
60
|
+
|
|
61
|
+
set -u
|
|
62
|
+
|
|
63
|
+
here=$(cd "$(dirname "$0")" && pwd)
|
|
64
|
+
. "$here/common.sh"
|
|
65
|
+
|
|
66
|
+
brain=""
|
|
67
|
+
org=""
|
|
68
|
+
workspace=""
|
|
69
|
+
root=0
|
|
70
|
+
all=0
|
|
71
|
+
expand=""
|
|
72
|
+
limit=5
|
|
73
|
+
query_parts=""
|
|
74
|
+
|
|
75
|
+
# A flag that takes a value checks that the value is there before consuming it: with the flag as the
|
|
76
|
+
# last argument, `shift 2` fails without consuming anything and the loop repeats forever.
|
|
77
|
+
while [ $# -gt 0 ]; do
|
|
78
|
+
case "$1" in
|
|
79
|
+
--brain) [ $# -ge 2 ] || os_die "--brain needs a value"; brain="$2"; shift 2 ;;
|
|
80
|
+
--org) [ $# -ge 2 ] || os_die "--org needs a value"; org="$2"; shift 2 ;;
|
|
81
|
+
--workspace) [ $# -ge 2 ] || os_die "--workspace needs a value"; workspace="$2"; shift 2 ;;
|
|
82
|
+
--root) root=1; shift ;;
|
|
83
|
+
--all) all=1; shift ;;
|
|
84
|
+
--expand) [ $# -ge 2 ] || os_die "--expand needs a value"; expand="$2"; shift 2 ;;
|
|
85
|
+
--limit) [ $# -ge 2 ] || os_die "--limit needs a value"; limit="$2"; shift 2 ;;
|
|
86
|
+
--) shift; while [ $# -gt 0 ]; do query_parts="$query_parts $1"; shift; done ;;
|
|
87
|
+
-*) os_die "unknown argument: $1" ;;
|
|
88
|
+
*) query_parts="$query_parts $1"; shift ;;
|
|
89
|
+
esac
|
|
90
|
+
done
|
|
91
|
+
|
|
92
|
+
[ -n "$brain" ] || os_die "missing --brain"
|
|
93
|
+
[ -d "$brain" ] || os_die "no such brain: $brain"
|
|
94
|
+
brain=$(cd "$brain" && pwd)
|
|
95
|
+
|
|
96
|
+
# `--workspace` is an exact synonym of `--org` (spec 039): nobody outside sees the word "org" — see
|
|
97
|
+
# `common.sh`, the comment above `os_ws_dir`.
|
|
98
|
+
if [ -n "$org" ] && [ -n "$workspace" ] && [ "$org" != "$workspace" ]; then
|
|
99
|
+
os_die "--org and --workspace with different values: $org / $workspace"
|
|
100
|
+
fi
|
|
101
|
+
[ -n "$workspace" ] || workspace="$org"
|
|
102
|
+
|
|
103
|
+
case "$limit" in
|
|
104
|
+
''|*[!0-9]*) os_die "--limit is not a number: $limit" ;;
|
|
105
|
+
esac
|
|
106
|
+
[ "$limit" -gt 0 ] || os_die "--limit has to be greater than 0"
|
|
107
|
+
|
|
108
|
+
lang=$(os_language "$brain")
|
|
109
|
+
os_lang_load "$lang"
|
|
110
|
+
|
|
111
|
+
os_ws_check "$brain"
|
|
112
|
+
|
|
113
|
+
if [ -n "$expand" ]; then
|
|
114
|
+
{ [ -z "$workspace" ] && [ "$root" = "0" ] && [ "$all" = "0" ]; } \
|
|
115
|
+
|| os_die "--expand is exclusive with --workspace/--org, --root and --all"
|
|
116
|
+
[ -z "$query_parts" ] || os_die "--expand is exclusive with a search query"
|
|
117
|
+
expand=$(os_rel_norm "$expand")
|
|
118
|
+
os_rel_ok "$expand" || os_die "--expand is not a path relative to the brain: $expand"
|
|
119
|
+
scope_kind="expand"
|
|
120
|
+
scope_slug=""
|
|
121
|
+
else
|
|
122
|
+
n_scope=0
|
|
123
|
+
[ -n "$workspace" ] && n_scope=$(( n_scope + 1 ))
|
|
124
|
+
[ "$root" = "1" ] && n_scope=$(( n_scope + 1 ))
|
|
125
|
+
[ "$all" = "1" ] && n_scope=$(( n_scope + 1 ))
|
|
126
|
+
[ "$n_scope" -gt "0" ] || os_die "name a scope — --workspace SLUG, --root or --all"
|
|
127
|
+
[ "$n_scope" = "1" ] || os_die "--workspace/--org, --root and --all are exclusive"
|
|
128
|
+
|
|
129
|
+
if [ -n "$workspace" ]; then
|
|
130
|
+
org_existe=0
|
|
131
|
+
org_slugs=""
|
|
132
|
+
while IFS= read -r slug || [ -n "$slug" ]; do
|
|
133
|
+
[ -n "$slug" ] || continue
|
|
134
|
+
org_slugs="$org_slugs $slug
|
|
135
|
+
"
|
|
136
|
+
[ "$slug" = "$workspace" ] && org_existe=1
|
|
137
|
+
done <<SLUGS
|
|
138
|
+
$(os_org_slugs "$brain")
|
|
139
|
+
SLUGS
|
|
140
|
+
if [ "$org_existe" = "0" ]; then
|
|
141
|
+
printf "$S_SESSION_ORG_NOT_FOUND\n" "$workspace" >&2
|
|
142
|
+
if [ -n "$org_slugs" ]; then
|
|
143
|
+
printf '%s' "$org_slugs" >&2
|
|
144
|
+
else
|
|
145
|
+
printf ' %s\n' "$S_SESSION_NO_ORGS" >&2
|
|
146
|
+
fi
|
|
147
|
+
exit 2
|
|
148
|
+
fi
|
|
149
|
+
scope_kind="workspace"
|
|
150
|
+
scope_slug="$workspace"
|
|
151
|
+
elif [ "$root" = "1" ]; then
|
|
152
|
+
scope_kind="root"
|
|
153
|
+
scope_slug=""
|
|
154
|
+
else
|
|
155
|
+
scope_kind="all"
|
|
156
|
+
scope_slug=""
|
|
157
|
+
fi
|
|
158
|
+
|
|
159
|
+
# Leading/trailing spaces only — `os_trim` does not fold repeats in the middle, and neither does
|
|
160
|
+
# this: a query is passed through, not rewritten.
|
|
161
|
+
query=$(os_trim "$query_parts")
|
|
162
|
+
[ -n "$query" ] || os_die "missing query — nothing to search for"
|
|
163
|
+
fi
|
|
164
|
+
|
|
165
|
+
wsdir=$(os_ws_dir "$brain")
|
|
166
|
+
head_file=$(os_head_file "$brain") || true
|
|
167
|
+
|
|
168
|
+
mkdir -p "$brain/.os" 2>/dev/null
|
|
169
|
+
# The index never gets committed. `.os/` is meant to be gitignored everywhere it is used
|
|
170
|
+
# (`.os/core` is the product's own symlink), but nothing before this spec had ever written the
|
|
171
|
+
# entry — this is the first thing under `.os/` a brain accumulates on disk instead of just holding a
|
|
172
|
+
# symlink, so the first call that would leave one is the one that makes sure the entry is there.
|
|
173
|
+
os_gitignore_ensure "$brain" ".os" > /dev/null 2>&1 || true
|
|
174
|
+
db="$brain/.os/living-memory.sqlite"
|
|
175
|
+
|
|
176
|
+
heads=$(os_tree_files "$brain") || os_die "no tree.md to read in: $brain"
|
|
177
|
+
contents=$(os_tree_content_files "$brain") || os_die "no tree.md to read in: $brain"
|
|
178
|
+
# The `archive:` class (spec 048) is indexed like content: archiving stops a document from being
|
|
179
|
+
# loaded, never from being found. `recall` is precisely the tool for what the focus does not load,
|
|
180
|
+
# so the class it was built for is the one it must not skip.
|
|
181
|
+
archived=$(os_tree_archive_files "$brain") || archived=""
|
|
182
|
+
|
|
183
|
+
# The subset of the `glob:` class that is a node's own identity file — the same test
|
|
184
|
+
# `os_org_propios`/`os_head_file` already apply elsewhere in the system: no new rule about what a
|
|
185
|
+
# head is, just the existing one read again.
|
|
186
|
+
true_heads=""
|
|
187
|
+
while IFS= read -r f || [ -n "$f" ]; do
|
|
188
|
+
[ -n "$f" ] || continue
|
|
189
|
+
case "$f" in
|
|
190
|
+
*/"$head_file") true_heads="$true_heads$f
|
|
191
|
+
" ;;
|
|
192
|
+
"$head_file") true_heads="$true_heads$f
|
|
193
|
+
" ;;
|
|
194
|
+
esac
|
|
195
|
+
done <<HEADS
|
|
196
|
+
$heads
|
|
197
|
+
HEADS
|
|
198
|
+
|
|
199
|
+
all_files=$(printf '%s\n%s\n' "$heads" "$contents")
|
|
200
|
+
if [ -n "$archived" ]; then
|
|
201
|
+
all_files="$all_files
|
|
202
|
+
$archived"
|
|
203
|
+
fi
|
|
204
|
+
all_files=$(printf '%s\n' "$all_files" | LC_ALL=C sort -u)
|
|
205
|
+
|
|
206
|
+
if [ -n "$expand" ]; then
|
|
207
|
+
mode="expand"
|
|
208
|
+
arg="$expand"
|
|
209
|
+
else
|
|
210
|
+
mode="search"
|
|
211
|
+
arg="$query"
|
|
212
|
+
fi
|
|
213
|
+
|
|
214
|
+
stdin_data="$true_heads
|
|
215
|
+
%%FILES%%
|
|
216
|
+
$all_files"
|
|
217
|
+
|
|
218
|
+
result=$(printf '%s\n' "$stdin_data" | python3 "$here/recall_index.py" \
|
|
219
|
+
"$db" "$brain" "$mode" "$scope_kind" "$wsdir" "$scope_slug" "$arg" "$limit")
|
|
220
|
+
rc=$?
|
|
221
|
+
if [ "$rc" != "0" ]; then
|
|
222
|
+
printf 'error: recall.sh could not run its index (python3/sqlite3)\n' >&2
|
|
223
|
+
exit 1
|
|
224
|
+
fi
|
|
225
|
+
|
|
226
|
+
if [ -z "$expand" ]; then
|
|
227
|
+
if printf '%s\n' "$result" | grep -qx '__NO_RESULTS__'; then
|
|
228
|
+
printf '%s\n' "$result" | grep -v '^__NO_RESULTS__$'
|
|
229
|
+
printf '%s\n' "$S_RECALL_NO_RESULTS"
|
|
230
|
+
exit 0
|
|
231
|
+
fi
|
|
232
|
+
fi
|
|
233
|
+
|
|
234
|
+
printf '%s\n' "$result"
|
|
235
|
+
exit 0
|