ai-first-os 1.10.0 → 2.0.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/README.md +33 -31
- package/core/CLAUDE.md +48 -12
- package/core/VERSION +1 -1
- package/core/install.sh +173 -52
- package/core/lib/bootstrap.sh +41 -26
- package/core/lib/build-indexes.sh +283 -0
- package/core/lib/capture.sh +126 -55
- package/core/lib/check-resolvable.sh +13 -2
- package/core/lib/close-session.sh +172 -119
- package/core/lib/common.sh +505 -92
- package/core/lib/focus-read.sh +94 -58
- package/core/lib/manual-link.sh +10 -8
- package/core/lib/markdown.py +2 -2
- package/core/lib/migrate-layout.sh +92 -0
- package/core/lib/migrate-root.sh +497 -0
- package/core/lib/migrate_layout.py +2000 -0
- package/core/lib/new-memory.sh +33 -44
- package/core/lib/new-product.sh +11 -13
- package/core/lib/new-workspace.sh +18 -9
- package/core/lib/orchestrator-init.sh +80 -0
- package/core/lib/pack-install.sh +44 -30
- package/core/lib/recall.sh +1 -1
- package/core/lib/recall_index.py +48 -6
- package/core/lib/remote-backup.sh +30 -20
- package/core/lib/rename-heads.sh +8 -8
- package/core/lib/rename-workspaces.sh +3 -3
- package/core/lib/session-read.sh +133 -73
- package/core/lib/session-start.sh +238 -221
- package/core/lib/supersede.sh +199 -3
- package/core/lib/sweep.sh +5 -0
- package/core/manual/COMO-FUNCIONA.md +169 -58
- package/core/manual/HOW-IT-WORKS.md +158 -57
- package/core/resolver.md +4 -2
- package/core/skills/bootstrap.md +63 -44
- package/core/skills/capture.md +15 -8
- package/core/skills/check-resolvable.md +1 -1
- package/core/skills/close-session.md +9 -5
- package/core/skills/grill.md +3 -3
- package/core/skills/migrate-layout.md +48 -0
- package/core/skills/migrate-root.md +64 -0
- package/core/skills/mount-repo.md +6 -6
- package/core/skills/new-memory.md +20 -18
- package/core/skills/new-product.md +4 -3
- package/core/skills/new-spec.md +6 -0
- package/core/skills/new-workspace.md +7 -5
- package/core/skills/orchestrator.md +101 -0
- package/core/skills/supersede.md +14 -0
- package/core/templates/node-repo/context/open-questions.md +3 -0
- package/core/templates/strings.md +396 -271
- package/core/templates/tree.md +22 -27
- package/package.json +1 -1
- package/core/lib/my-wiki-gates.sh +0 -137
- package/core/lib/my-wiki.sh +0 -202
- package/core/lib/my_wiki_build.py +0 -548
- package/core/lib/my_wiki_graph.py +0 -137
- package/core/lib/my_wiki_overview.py +0 -392
- package/core/skills/my-wiki.md +0 -103
- package/core/templates/my-wiki-graph.js +0 -431
- package/core/templates/my-wiki-overview.js +0 -174
- package/core/templates/my-wiki.html +0 -1017
package/core/lib/bootstrap.sh
CHANGED
|
@@ -9,24 +9,31 @@
|
|
|
9
9
|
# name: nombre del operador
|
|
10
10
|
# profile: el rol en una línea ("Senior PM en una fintech")
|
|
11
11
|
# voice: una línea por ítem de la voz (se repite; la entrevista la declara opcional)
|
|
12
|
-
# workspace: Nombre | título | dueño | archivo-de-identidad (se repite; los dos últimos,
|
|
13
|
-
# El
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
12
|
+
# workspace: Nombre | título | dueño | archivo-de-identidad (se repite; los dos últimos,
|
|
13
|
+
# opcionales). El cerebro nace siempre con `workspaces/personal` — "My workspace" / "Mi
|
|
14
|
+
# workspace" — sin que la entrevista lo pregunte (spec 059, decisión 3): esta clave ya
|
|
15
|
+
# no es una pregunta de la entrevista, pero sigue siendo la forma de sumar, en el mismo
|
|
16
|
+
# acto, uno o más espacios de trabajo con nombre — lo que antes hacía nacer un brain con
|
|
17
|
+
# "una persona, un empleador"; después de este bootstrap eso mismo es `new-workspace`,
|
|
18
|
+
# corrido aparte. El título es identidad —"qué hacés ahí"— y va al cuerpo de la cabeza,
|
|
19
|
+
# nunca a `role:` (spec 020): ese campo activa un oficio del pack y nace vacío.
|
|
20
|
+
# skipped: el nombre de una pregunta opcional que el operador dejó vacía a propósito: hoy, solo
|
|
21
|
+
# `voice` (se repite). Es la diferencia entre "no contestó" y "contestó que no tiene"
|
|
22
|
+
# (spec 052): lo declarado vacío no se vuelve a preguntar. `skipped: workspace` ya no
|
|
23
|
+
# existe (spec 059): la pregunta que declaraba desapareció de la entrevista entera, así
|
|
24
|
+
# que no hay una respuesta vacía que declarar — frena con el motivo, igual que `org:`.
|
|
18
25
|
# `org:` no existe más (spec 052): el espacio de trabajo se declara con `workspace:`, que es el
|
|
19
|
-
# nombre que el usuario ve desde la spec 039. Sin retrocompatibilidad:
|
|
20
|
-
#
|
|
26
|
+
# nombre que el usuario ve desde la spec 039. Sin retrocompatibilidad: un archivo de respuestas
|
|
27
|
+
# viejo con `org:` frena con el motivo.
|
|
21
28
|
# `reply:` no existe más (spec 021): "cómo querés que te conteste" no se pregunta, y el default vive
|
|
22
29
|
# en el template de `operator.md` marcado como sección que se aprende con el uso. Sin
|
|
23
30
|
# retrocompatibilidad: un archivo viejo con `reply:` frena con el motivo.
|
|
24
31
|
# Las líneas vacías y las que empiezan con `#` se ignoran.
|
|
25
32
|
#
|
|
26
33
|
# El respaldo tiene dos mitades (spec 021). Acá va la local, que corre siempre y sin preguntar: `git
|
|
27
|
-
# init` + primer commit. La remota —crear el repo y pushear, o
|
|
28
|
-
#
|
|
29
|
-
# volver a correr.
|
|
34
|
+
# init` + primer commit. La remota —crear el repo y pushear, o preguntar si se anota la tarea guiada en
|
|
35
|
+
# el espacio de trabajo `personal` y anotarla solo con el sí— es `remote-backup.sh`, que la sesión corre
|
|
36
|
+
# después y que cualquier sesión posterior puede volver a correr.
|
|
30
37
|
|
|
31
38
|
set -eu
|
|
32
39
|
|
|
@@ -155,16 +162,14 @@ os_skipped() {
|
|
|
155
162
|
}
|
|
156
163
|
for k in $skipped; do
|
|
157
164
|
case "$k" in
|
|
158
|
-
voice
|
|
159
|
-
|
|
165
|
+
voice) ;;
|
|
166
|
+
workspace) os_die "skipped: workspace no existe desde la spec 059: la pregunta desapareció de la entrevista entera, así que no hay una respuesta vacía que declarar" ;;
|
|
167
|
+
*) os_die "skipped: solo nombra una pregunta opcional de la entrevista (voice): $k" ;;
|
|
160
168
|
esac
|
|
161
169
|
done
|
|
162
170
|
if os_skipped voice && [ -n "$voice" ]; then
|
|
163
171
|
os_die "skipped: voice junto con líneas voice: en el mismo archivo — o la voz se declaró vacía, o se contestó"
|
|
164
172
|
fi
|
|
165
|
-
if os_skipped workspace && [ -n "$workspaces" ]; then
|
|
166
|
-
os_die "skipped: workspace junto con líneas workspace: en el mismo archivo — o el espacio de trabajo se declaró vacío, o se contestó"
|
|
167
|
-
fi
|
|
168
173
|
|
|
169
174
|
# El idioma es la primera pregunta de la entrevista y gobierna todo lo que se escribe. Sin dato, se
|
|
170
175
|
# escribe en inglés y el hueco se declara abajo: elegir por el operador en silencio le deja un brain
|
|
@@ -176,6 +181,7 @@ if [ -z "$language" ]; then
|
|
|
176
181
|
elif ! os_language_valido "$language"; then
|
|
177
182
|
os_die "idioma no soportado: $language — hoy: $OS_LANGUAGES"
|
|
178
183
|
fi
|
|
184
|
+
os_lang_load "$language"
|
|
179
185
|
|
|
180
186
|
templates="$here/../templates"
|
|
181
187
|
mkdir -p "$brain"
|
|
@@ -187,7 +193,7 @@ brain=$(cd "$brain" && pwd -P)
|
|
|
187
193
|
# que el operador haya escrito encima, y eso es pérdida silenciosa. Agregar espacios de trabajo a un
|
|
188
194
|
# brain que ya existe es trabajo de new-workspace.
|
|
189
195
|
existing=""
|
|
190
|
-
for f in operator.md voice.md resolver.md tree.md; do
|
|
196
|
+
for f in "$OS_OPERATOR_FILE" "$OS_VOICE_FILE" "$OS_ROOT_RESOLVER_FILE" "$OS_TREE_FILE" operator.md voice.md resolver.md tree.md; do
|
|
191
197
|
if [ -e "$brain/$f" ]; then
|
|
192
198
|
existing="$existing $f"
|
|
193
199
|
fi
|
|
@@ -201,23 +207,23 @@ fi
|
|
|
201
207
|
# frase termina viviendo en dos lugares.
|
|
202
208
|
# La prosa fija sale del catálogo `templates/strings.md` en el idioma elegido: un solo template por
|
|
203
209
|
# archivo, una traducción por string (spec 021). Nunca un árbol de templates por idioma.
|
|
210
|
+
mkdir -p "$brain/$OS_SYSTEM_DIR" "$brain/$OS_ACCOUNT_DIR/voice"
|
|
204
211
|
os_render_lang "$templates/operator.md" "$language" \
|
|
205
|
-
"NAME=$name" "LANGUAGE=$language" "PROFILE=$profile" > "$brain
|
|
212
|
+
"NAME=$name" "LANGUAGE=$language" "PROFILE=$profile" > "$brain/$OS_OPERATOR_FILE"
|
|
206
213
|
# La voz es opcional: sin dato, el archivo lo dice en vez de nacer con una sección en blanco.
|
|
207
214
|
voice_body="$voice"
|
|
208
215
|
[ -n "$voice_body" ] || voice_body="$S_VOICE_PENDING"
|
|
209
216
|
os_render_lang "$templates/voice.md" "$language" \
|
|
210
|
-
"NAME=$name" "VOICE=$voice_body" > "$brain
|
|
211
|
-
os_render_lang "$templates/root-resolver.md" "$language" > "$brain
|
|
217
|
+
"NAME=$name" "VOICE=$voice_body" > "$brain/$OS_VOICE_FILE"
|
|
218
|
+
os_render_lang "$templates/root-resolver.md" "$language" > "$brain/$OS_ROOT_RESOLVER_FILE"
|
|
212
219
|
# El manual de usuario es del idioma del brain, y su nombre lo enuncia `os_manual_file` una sola vez
|
|
213
220
|
# (spec 022). El árbol lo declara como contenido: se ve en la raíz y ningún barrido lo lee como
|
|
214
221
|
# trabajo.
|
|
215
|
-
|
|
216
|
-
os_render "$templates/tree.md" "MANUAL=$manual" > "$brain/tree.md"
|
|
222
|
+
os_render "$templates/tree.md" "MANUAL=$OS_MANUAL_LINK" > "$brain/$OS_TREE_FILE"
|
|
217
223
|
|
|
218
|
-
os_check_identity_cap "$brain
|
|
224
|
+
os_check_identity_cap "$brain/$OS_OPERATOR_FILE"
|
|
219
225
|
|
|
220
|
-
printf '
|
|
226
|
+
printf '%s · %s · %s · %s\n' "$OS_OPERATOR_FILE" "$OS_VOICE_FILE" "$OS_ROOT_RESOLVER_FILE" "$OS_TREE_FILE"
|
|
221
227
|
|
|
222
228
|
# El manual se engancha por symlink al del producto: nace con el brain y se actualiza con el
|
|
223
229
|
# producto, sin volver a correr nada.
|
|
@@ -228,7 +234,6 @@ vacias=""
|
|
|
228
234
|
[ "$sin_language" = "0" ] || vacias="$vacias language"
|
|
229
235
|
[ -n "$profile" ] || vacias="$vacias profile"
|
|
230
236
|
if [ -z "$voice" ] && ! os_skipped voice; then vacias="$vacias voice"; fi
|
|
231
|
-
if [ -z "$workspaces" ] && ! os_skipped workspace; then vacias="$vacias workspace"; fi
|
|
232
237
|
if [ -n "$vacias" ]; then
|
|
233
238
|
printf 'sin dato:%s — las secciones quedaron vacías y hay que volver a preguntarlas\n' "$vacias"
|
|
234
239
|
fi
|
|
@@ -238,8 +243,18 @@ if [ -n "$skipped" ]; then
|
|
|
238
243
|
printf 'declarado vacío:%s — se preguntó y la respuesta fue "no tengo" o "después"; no se vuelve a preguntar\n' "$skipped"
|
|
239
244
|
fi
|
|
240
245
|
|
|
241
|
-
#
|
|
246
|
+
# El cerebro nace siempre con un espacio de trabajo (spec 059, decisión 3): la entrevista ya no lo
|
|
247
|
+
# pregunta, así que este script lo crea solo primero, con el slug fijo y el nombre visible del
|
|
248
|
+
# catálogo — nunca inventado acá. `new-workspace.sh` es el mismo comando que crea cualquier otro
|
|
249
|
+
# espacio de trabajo, así que un `workspace:` en las respuestas —para quien lo suma por su cuenta,
|
|
250
|
+
# sin pasar por la entrevista— sigue funcionando igual, después de este.
|
|
242
251
|
fallidas=""
|
|
252
|
+
if ! "$here/new-workspace.sh" --brain "$brain" --name "$S_PERSONAL_WORKSPACE_NAME" --role "" \
|
|
253
|
+
--title "" --owner "$name" --slug "$OS_PERSONAL_WORKSPACE_SLUG"; then
|
|
254
|
+
fallidas="$fallidas $S_PERSONAL_WORKSPACE_NAME"
|
|
255
|
+
fi
|
|
256
|
+
|
|
257
|
+
# Un espacio de trabajo que falla no aborta los demás, y los que no se crearon se nombran.
|
|
243
258
|
while IFS= read -r ws; do
|
|
244
259
|
[ -n "$ws" ] || continue
|
|
245
260
|
IFS='|' read -r ws_name ws_title ws_owner ws_identity <<EOF
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Generates the indexes of one workspace (spec 076, C18). Internal: not invocable — the startup read
|
|
3
|
+
# (`session-read.sh`) runs it on every read; the startup scan never does, because the scan never
|
|
4
|
+
# writes (spec 072).
|
|
5
|
+
#
|
|
6
|
+
# Usage: build-indexes.sh --brain DIR --workspace SLUG
|
|
7
|
+
#
|
|
8
|
+
# What it writes, all of it derived and none of it edited by a person:
|
|
9
|
+
# - `<ws>/decisions/index.md` — every decision of the workspace, newest `date:` first.
|
|
10
|
+
# - `<ws>/learnings/index.md` — every learning of the workspace, the same way.
|
|
11
|
+
# - `<node>/index.md` — at the root of each area node (a product, a course, a channel, an account)
|
|
12
|
+
# that an initiative, a decision or a learning of the workspace names in `about:`, with three
|
|
13
|
+
# sections: Initiatives (a table: title · status · horizon), Decisions, Learnings.
|
|
14
|
+
# The workspace itself has no `index.md` (Gate 1, P4): its folders already show its initiatives,
|
|
15
|
+
# decisions and learnings.
|
|
16
|
+
#
|
|
17
|
+
# Every line is a link relative to the index. A decision or learning line is `os_doc_index_line`
|
|
18
|
+
# (common.sh), the one place that knows the shape. Every file opens with `generated: true` in its
|
|
19
|
+
# frontmatter and then the three-line warning of D8, in the language of the brain; the third line
|
|
20
|
+
# names where that index comes from.
|
|
21
|
+
#
|
|
22
|
+
# Rules, each in its one place here:
|
|
23
|
+
# - Content unchanged, file untouched: the comparison is against the bytes on disk, so a second read
|
|
24
|
+
# keeps the `mtime`, and a hand edit of a generated index is gone on the next read.
|
|
25
|
+
# - An `index.md` that exists without `generated: true` was written by a person: it is skipped,
|
|
26
|
+
# never overwritten (the scan names it as a finding).
|
|
27
|
+
# - A generated node index whose node nobody names any more is removed: it is derived, and a stale
|
|
28
|
+
# one would list what is no longer about that node.
|
|
29
|
+
# - Before a path is written its entry goes to the brain's `.gitignore`: that exact path anchored at
|
|
30
|
+
# the root (`/<path>`), its pattern characters escaped — never a pattern that could reach an
|
|
31
|
+
# `index.md` a person wrote — and the line `gitignore-declared: <path>` is printed. If the entry
|
|
32
|
+
# cannot be written, `gitignore-declare-failed: <path>` is printed and the index is not written.
|
|
33
|
+
# The session contract (`core/CLAUDE.md`) says what the session does with either.
|
|
34
|
+
#
|
|
35
|
+
# Deterministic and offline: it reads frontmatter and first titles, nothing else. Exit 0 always —
|
|
36
|
+
# an index that cannot be written never stops the read that called it.
|
|
37
|
+
|
|
38
|
+
set -u
|
|
39
|
+
|
|
40
|
+
here=$(cd "$(dirname "$0")" && pwd)
|
|
41
|
+
. "$here/common.sh"
|
|
42
|
+
|
|
43
|
+
nl=$(printf '\nx')
|
|
44
|
+
nl="${nl%x}"
|
|
45
|
+
|
|
46
|
+
brain=""
|
|
47
|
+
ws_slug=""
|
|
48
|
+
while [ $# -gt 0 ]; do
|
|
49
|
+
case "$1" in
|
|
50
|
+
--brain) [ $# -ge 2 ] || os_die "--brain needs a value"; brain="$2"; shift 2 ;;
|
|
51
|
+
--workspace) [ $# -ge 2 ] || os_die "--workspace needs a value"; ws_slug="$2"; shift 2 ;;
|
|
52
|
+
*) os_die "unknown argument: $1" ;;
|
|
53
|
+
esac
|
|
54
|
+
done
|
|
55
|
+
[ -n "$brain" ] || os_die "missing --brain"
|
|
56
|
+
[ -n "$ws_slug" ] || os_die "missing --workspace"
|
|
57
|
+
[ -d "$brain" ] || os_die "no such brain: $brain"
|
|
58
|
+
brain=$(cd "$brain" && pwd)
|
|
59
|
+
|
|
60
|
+
os_ws_check "$brain"
|
|
61
|
+
wsdir=$(os_ws_dir "$brain")
|
|
62
|
+
head=$(os_head_file "$brain") || true
|
|
63
|
+
os_org_existe "$brain" "$ws_slug" || exit 0
|
|
64
|
+
ws="$wsdir/$ws_slug"
|
|
65
|
+
|
|
66
|
+
os_lang_load "$(os_language "$brain")"
|
|
67
|
+
|
|
68
|
+
heads=$(os_tree_files "$brain" 2>/dev/null) || heads=""
|
|
69
|
+
|
|
70
|
+
# ---------------------------------------------------------------- the documents, read once
|
|
71
|
+
# Each decision and learning is read once into these arrays; every index is then built from them with
|
|
72
|
+
# string work only. Decisions and learnings come newest first (`os_docs_sorted`).
|
|
73
|
+
d_n=0
|
|
74
|
+
leer_docs() {
|
|
75
|
+
# leer_docs KIND DIR — appends the documents of DIR to the arrays, tagged with KIND.
|
|
76
|
+
local kind="$1" dir="$2" rel
|
|
77
|
+
while IFS= read -r rel || [ -n "$rel" ]; do
|
|
78
|
+
[ -n "$rel" ] || continue
|
|
79
|
+
fm_read "$brain/$rel"
|
|
80
|
+
d_kind[$d_n]="$kind"
|
|
81
|
+
d_rel[$d_n]="$rel"
|
|
82
|
+
d_about[$d_n]="$(os_about_set "$fm_about")$nl"
|
|
83
|
+
d_n=$(( d_n + 1 ))
|
|
84
|
+
done <<DOCS
|
|
85
|
+
$(os_docs_sorted "$brain" "$dir")
|
|
86
|
+
DOCS
|
|
87
|
+
}
|
|
88
|
+
leer_docs decision "$ws/decisions"
|
|
89
|
+
leer_docs learning "$ws/learnings"
|
|
90
|
+
|
|
91
|
+
# The initiatives of the workspace: the heads a `glob:` line reaches, by kind (spec 056), by path.
|
|
92
|
+
i_n=0
|
|
93
|
+
while IFS= read -r f || [ -n "$f" ]; do
|
|
94
|
+
[ -n "$f" ] || continue
|
|
95
|
+
case "$f" in "$ws"/initiatives/*) ;; *) continue ;; esac
|
|
96
|
+
case "$(os_head_kind "$wsdir" "$head" "$f")" in
|
|
97
|
+
"initiative $ws_slug") ;;
|
|
98
|
+
*) continue ;;
|
|
99
|
+
esac
|
|
100
|
+
fm_read "$brain/$f"
|
|
101
|
+
i_rel[$i_n]="$f"
|
|
102
|
+
i_about[$i_n]="$(os_about_set "$fm_about")$nl"
|
|
103
|
+
i_status[$i_n]="$fm_status"
|
|
104
|
+
i_horizon[$i_n]="$fm_horizon"
|
|
105
|
+
t=$(os_titulo "$brain/$f")
|
|
106
|
+
[ -n "$t" ] || t=$(os_node_name "$f")
|
|
107
|
+
i_title[$i_n]="$t"
|
|
108
|
+
i_n=$(( i_n + 1 ))
|
|
109
|
+
done <<HEADS
|
|
110
|
+
$(printf '%s\n' "$heads" | LC_ALL=C sort -u)
|
|
111
|
+
HEADS
|
|
112
|
+
|
|
113
|
+
# ---------------------------------------------------------------- writing one index
|
|
114
|
+
# The `.gitignore` of the brain is read once: an unchanged index costs a string match, never a pass
|
|
115
|
+
# over the file. A missing entry is appended (with the newline the file may lack) and read back.
|
|
116
|
+
ignorados="$nl"
|
|
117
|
+
[ -f "$brain/.gitignore" ] && ignorados="$nl$(cat "$brain/.gitignore")$nl"
|
|
118
|
+
|
|
119
|
+
# ignorar_patron REL -> the exact `.gitignore` line for REL: anchored at the root, and with every
|
|
120
|
+
# character git reads as a pattern (`\ * ? [ ]`) escaped — the leading `/` keeps `!` and `#` literal — so a node folder
|
|
121
|
+
# named like `item[ab]` is still that one path and nothing else.
|
|
122
|
+
ignorar_patron() {
|
|
123
|
+
local r="$1" out="" c
|
|
124
|
+
while [ -n "$r" ]; do
|
|
125
|
+
c="${r%"${r#?}"}"; r="${r#?}"
|
|
126
|
+
case "$c" in
|
|
127
|
+
'\'|'*'|'?'|'['|']') out="$out\\$c" ;;
|
|
128
|
+
*) out="$out$c" ;;
|
|
129
|
+
esac
|
|
130
|
+
done
|
|
131
|
+
printf '/%s' "$out"
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# declarar_ignorado REL -> 0 when REL is in `.gitignore` (already, or appended now and read back); the
|
|
135
|
+
# marker `gitignore-declared:` only for a line written now. 1 when the line could not be written.
|
|
136
|
+
declarar_ignorado() {
|
|
137
|
+
local linea
|
|
138
|
+
linea=$(ignorar_patron "$1")
|
|
139
|
+
case "$ignorados" in *"$nl$linea$nl"*) return 0 ;; esac
|
|
140
|
+
if [ -s "$brain/.gitignore" ] && [ -n "$(tail -c 1 "$brain/.gitignore")" ]; then
|
|
141
|
+
printf '\n' >> "$brain/.gitignore" 2>/dev/null || return 1
|
|
142
|
+
fi
|
|
143
|
+
printf '%s\n' "$linea" >> "$brain/.gitignore" 2>/dev/null || return 1
|
|
144
|
+
grep -qxF -- "$linea" "$brain/.gitignore" 2>/dev/null || return 1
|
|
145
|
+
ignorados="$ignorados$linea$nl"
|
|
146
|
+
printf 'gitignore-declared: %s\n' "$1"
|
|
147
|
+
return 0
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
# escribir REL CONTENT — writes the generated file at REL when its bytes differ, unless a person wrote
|
|
151
|
+
# that file. The ignore entry goes first: an index is never published untracked-and-visible to git. A
|
|
152
|
+
# `.gitignore` that cannot be written is reported (`gitignore-declare-failed: <path>`) and the index is
|
|
153
|
+
# not written. The content goes to a temporary file of its own (`mktemp`), so two reads at once never
|
|
154
|
+
# publish each other's half-written file.
|
|
155
|
+
escribir() {
|
|
156
|
+
local rel="$1" content="$2" full="$brain/$1" tmp
|
|
157
|
+
if [ -e "$full" ]; then
|
|
158
|
+
fm_read "$full"
|
|
159
|
+
[ "$fm_generated" = "true" ] || return 0
|
|
160
|
+
fi
|
|
161
|
+
if ! declarar_ignorado "$rel"; then
|
|
162
|
+
printf 'gitignore-declare-failed: %s\n' "$rel"
|
|
163
|
+
return 0
|
|
164
|
+
fi
|
|
165
|
+
if [ -e "$full" ] && [ "$(cat "$full"; printf x)" = "$content${nl}x" ]; then
|
|
166
|
+
return 0
|
|
167
|
+
fi
|
|
168
|
+
mkdir -p "$(dirname "$full")" 2>/dev/null || return 0
|
|
169
|
+
tmp=$(mktemp "$full.os-tmp.XXXXXX" 2>/dev/null) || return 0
|
|
170
|
+
printf '%s\n' "$content" > "$tmp" 2>/dev/null || { rm -f "$tmp"; return 0; }
|
|
171
|
+
mv -f "$tmp" "$full" 2>/dev/null || { rm -f "$tmp"; return 0; }
|
|
172
|
+
return 0
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
# cabecera SOURCE_LINE — the frontmatter and the three lines of D8.
|
|
176
|
+
cabecera() {
|
|
177
|
+
printf -- '---\ngenerated: true\n---\n\n%s\n%s\n%s\n' \
|
|
178
|
+
"$S_INDEX_WARNING_TITLE" "$S_INDEX_WARNING_NOT_SAVED" "$1"
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
# md_cell TEXT -> the text safe inside a table cell or a link label: backslash, `|`, `[` and `]` escaped.
|
|
182
|
+
md_cell() {
|
|
183
|
+
local t="$1"
|
|
184
|
+
t="${t//\\/\\\\}"
|
|
185
|
+
t="${t//|/\\|}"
|
|
186
|
+
t="${t//[/\\[}"
|
|
187
|
+
t="${t//]/\\]}"
|
|
188
|
+
printf '%s' "$t"
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
# md_dest PATH -> the path as a link destination: space, parentheses, `|`, `<`, `>` and `%` encoded.
|
|
192
|
+
md_dest() {
|
|
193
|
+
local t="$1"
|
|
194
|
+
t="${t//%/%25}"
|
|
195
|
+
t="${t// /%20}"
|
|
196
|
+
t="${t//(/%28}"
|
|
197
|
+
t="${t//)/%29}"
|
|
198
|
+
t="${t//|/%7C}"
|
|
199
|
+
t="${t//</%3C}"
|
|
200
|
+
t="${t//>/%3E}"
|
|
201
|
+
printf '%s' "$t"
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
# linea_ini I FROM — the table row of initiative I, its title linked from the folder FROM. Every cell and
|
|
205
|
+
# the link label are escaped and the destination encoded, so a row never splits and a link never breaks.
|
|
206
|
+
linea_ini() {
|
|
207
|
+
local i="$1" from="$2"
|
|
208
|
+
printf '| [%s](%s) | %s | %s |' "$(md_cell "${i_title[$i]}")" "$(md_dest "$(os_rel_link "$from" "${i_rel[$i]}")")" \
|
|
209
|
+
"$(md_cell "${i_status[$i]}")" "$(md_cell "${i_horizon[$i]}")"
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
# ---------------------------------------------------------------- decisions/index.md, learnings/index.md
|
|
213
|
+
carpeta_index() {
|
|
214
|
+
# carpeta_index KIND FOLDER SOURCE_LINE
|
|
215
|
+
local kind="$1" folder="$2" source="$3" body="" i
|
|
216
|
+
i=0
|
|
217
|
+
while [ "$i" -lt "$d_n" ]; do
|
|
218
|
+
if [ "${d_kind[$i]}" = "$kind" ]; then
|
|
219
|
+
body="$body$(os_doc_index_line "$brain" "${d_rel[$i]}" "$folder")$nl"
|
|
220
|
+
fi
|
|
221
|
+
i=$(( i + 1 ))
|
|
222
|
+
done
|
|
223
|
+
[ -n "$body" ] || body="$S_INDEX_EMPTY$nl"
|
|
224
|
+
escribir "$folder/index.md" "$(cabecera "$source")$nl$nl${body%"$nl"}"
|
|
225
|
+
}
|
|
226
|
+
carpeta_index decision "$ws/decisions" "$S_INDEX_SOURCE_DECISIONS"
|
|
227
|
+
carpeta_index learning "$ws/learnings" "$S_INDEX_SOURCE_LEARNINGS"
|
|
228
|
+
|
|
229
|
+
# ---------------------------------------------------------------- the index of each area node
|
|
230
|
+
seccion() {
|
|
231
|
+
# seccion TITLE BODY — the heading, a blank line and the lines, with no trailing newline.
|
|
232
|
+
if [ -n "$2" ]; then
|
|
233
|
+
printf '## %s\n\n%s' "$1" "${2%"$nl"}"
|
|
234
|
+
else
|
|
235
|
+
printf '## %s\n\n%s' "$1" "$S_INDEX_EMPTY"
|
|
236
|
+
fi
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
while IFS= read -r node || [ -n "$node" ]; do
|
|
240
|
+
[ -n "$node" ] || continue
|
|
241
|
+
case "$node" in "$ws"/*/*/*) ;; *) continue ;; esac
|
|
242
|
+
case "$(os_head_kind "$wsdir" "$head" "$node")" in
|
|
243
|
+
"entity $ws_slug") ;;
|
|
244
|
+
*) continue ;;
|
|
245
|
+
esac
|
|
246
|
+
from="${node%/*}"
|
|
247
|
+
inis=""; decs=""; lrns=""
|
|
248
|
+
i=0
|
|
249
|
+
while [ "$i" -lt "$i_n" ]; do
|
|
250
|
+
case "${i_about[$i]}" in
|
|
251
|
+
*"$nl$node$nl"*) inis="$inis$(linea_ini "$i" "$from")$nl" ;;
|
|
252
|
+
esac
|
|
253
|
+
i=$(( i + 1 ))
|
|
254
|
+
done
|
|
255
|
+
i=0
|
|
256
|
+
while [ "$i" -lt "$d_n" ]; do
|
|
257
|
+
case "${d_about[$i]}" in
|
|
258
|
+
*"$nl$node$nl"*)
|
|
259
|
+
l="$(os_doc_index_line "$brain" "${d_rel[$i]}" "$from")$nl"
|
|
260
|
+
if [ "${d_kind[$i]}" = "decision" ]; then decs="$decs$l"; else lrns="$lrns$l"; fi
|
|
261
|
+
;;
|
|
262
|
+
esac
|
|
263
|
+
i=$(( i + 1 ))
|
|
264
|
+
done
|
|
265
|
+
idx="$from/index.md"
|
|
266
|
+
if [ -n "$inis" ]; then
|
|
267
|
+
inis="| $S_INDEX_COL_INITIATIVE | $S_INDEX_COL_STATUS | $S_INDEX_COL_HORIZON |$nl|---|---|---|$nl$inis"
|
|
268
|
+
fi
|
|
269
|
+
if [ -z "$decs$lrns" ] && [ -z "$inis" ]; then
|
|
270
|
+
# Nobody names this node: a generated index left from before goes; one a person wrote stays.
|
|
271
|
+
if [ -f "$brain/$idx" ]; then
|
|
272
|
+
fm_read "$brain/$idx"
|
|
273
|
+
[ "$fm_generated" = "true" ] && rm -f "$brain/$idx"
|
|
274
|
+
fi
|
|
275
|
+
continue
|
|
276
|
+
fi
|
|
277
|
+
contenido="$(cabecera "$S_INDEX_SOURCE_NODE")$nl$nl$(seccion "$S_INDEX_INITIATIVES" "$inis")$nl$nl$(seccion "$S_INDEX_DECISIONS" "$decs")$nl$nl$(seccion "$S_INDEX_LEARNINGS" "$lrns")"
|
|
278
|
+
escribir "$idx" "$contenido"
|
|
279
|
+
done <<NODES
|
|
280
|
+
$(printf '%s\n' "$heads" | LC_ALL=C sort -u)
|
|
281
|
+
NODES
|
|
282
|
+
|
|
283
|
+
exit 0
|