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.
Files changed (60) hide show
  1. package/README.md +33 -31
  2. package/core/CLAUDE.md +48 -12
  3. package/core/VERSION +1 -1
  4. package/core/install.sh +173 -52
  5. package/core/lib/bootstrap.sh +41 -26
  6. package/core/lib/build-indexes.sh +283 -0
  7. package/core/lib/capture.sh +126 -55
  8. package/core/lib/check-resolvable.sh +13 -2
  9. package/core/lib/close-session.sh +172 -119
  10. package/core/lib/common.sh +505 -92
  11. package/core/lib/focus-read.sh +94 -58
  12. package/core/lib/manual-link.sh +10 -8
  13. package/core/lib/markdown.py +2 -2
  14. package/core/lib/migrate-layout.sh +92 -0
  15. package/core/lib/migrate-root.sh +497 -0
  16. package/core/lib/migrate_layout.py +2000 -0
  17. package/core/lib/new-memory.sh +33 -44
  18. package/core/lib/new-product.sh +11 -13
  19. package/core/lib/new-workspace.sh +18 -9
  20. package/core/lib/orchestrator-init.sh +80 -0
  21. package/core/lib/pack-install.sh +44 -30
  22. package/core/lib/recall.sh +1 -1
  23. package/core/lib/recall_index.py +48 -6
  24. package/core/lib/remote-backup.sh +30 -20
  25. package/core/lib/rename-heads.sh +8 -8
  26. package/core/lib/rename-workspaces.sh +3 -3
  27. package/core/lib/session-read.sh +133 -73
  28. package/core/lib/session-start.sh +238 -221
  29. package/core/lib/supersede.sh +199 -3
  30. package/core/lib/sweep.sh +5 -0
  31. package/core/manual/COMO-FUNCIONA.md +169 -58
  32. package/core/manual/HOW-IT-WORKS.md +158 -57
  33. package/core/resolver.md +4 -2
  34. package/core/skills/bootstrap.md +63 -44
  35. package/core/skills/capture.md +15 -8
  36. package/core/skills/check-resolvable.md +1 -1
  37. package/core/skills/close-session.md +9 -5
  38. package/core/skills/grill.md +3 -3
  39. package/core/skills/migrate-layout.md +48 -0
  40. package/core/skills/migrate-root.md +64 -0
  41. package/core/skills/mount-repo.md +6 -6
  42. package/core/skills/new-memory.md +20 -18
  43. package/core/skills/new-product.md +4 -3
  44. package/core/skills/new-spec.md +6 -0
  45. package/core/skills/new-workspace.md +7 -5
  46. package/core/skills/orchestrator.md +101 -0
  47. package/core/skills/supersede.md +14 -0
  48. package/core/templates/node-repo/context/open-questions.md +3 -0
  49. package/core/templates/strings.md +396 -271
  50. package/core/templates/tree.md +22 -27
  51. package/package.json +1 -1
  52. package/core/lib/my-wiki-gates.sh +0 -137
  53. package/core/lib/my-wiki.sh +0 -202
  54. package/core/lib/my_wiki_build.py +0 -548
  55. package/core/lib/my_wiki_graph.py +0 -137
  56. package/core/lib/my_wiki_overview.py +0 -392
  57. package/core/skills/my-wiki.md +0 -103
  58. package/core/templates/my-wiki-graph.js +0 -431
  59. package/core/templates/my-wiki-overview.js +0 -174
  60. package/core/templates/my-wiki.html +0 -1017
@@ -3,18 +3,19 @@
3
3
  # Las dos preguntas las hace core/skills/close-session.md. Interno: no es invocable.
4
4
  #
5
5
  # Uso: close-session.sh --brain DIR --org SLUG --material ARCHIVO
6
- # [--session-org SLUG] [--load-context]
6
+ # [--session-org SLUG] [--load-context] [--focus RUTA]
7
7
  # close-session.sh --brain DIR --workspace SLUG --material ARCHIVO
8
- # [--session-org SLUG] [--load-context]
9
- # close-session.sh --brain DIR --root --material ARCHIVO
8
+ # [--session-org SLUG] [--load-context] [--focus RUTA]
10
9
  #
11
- # `--workspace` es sinónimo exacto de `--org` (spec 039). Con `--root` distribuye a los canónicos
12
- # de la raíz (spec 018) en vez de a los de una organización: `decisions.md`, `learnings.md` y la
13
- # cabeza de la iniciativa, todos en la raíz del brain. Un `pending-from:`/`resume:` con iniciativa va
14
- # al `backlog.md` de esa iniciativa —de la raíz o de la organización, según el ámbito—, nunca a un
15
- # backlog del ámbito mismo (spec 057: una tarea cuelga de una iniciativa y solo de ahí).
16
- # `--org`/`--workspace` y `--root` son excluyentes, y la raíz no exige `--session-org` ni
17
- # `--load-context` — su identidad (`operator.md`) ya está cargada en cualquier sesión.
10
+ # `--focus` (spec 076, C17) is the head the session focused on, relative to the brain. It decides the
11
+ # `about:` every decision and learning of this close carries: the focus itself when it is an area node
12
+ # (a product, a course, a channel, an account); the focus's own `about:`, as written, when it is an
13
+ # initiative; nothing without a focus, or with any other head.
14
+ #
15
+ # `--workspace` es sinónimo exacto de `--org` (spec 039).
16
+ #
17
+ # `--root` ya no existe (spec 059): el trabajo propio del operador es el espacio de trabajo
18
+ # `personal`, con el que todo brain nace — usar `--workspace personal`.
18
19
  #
19
20
  # Formato del material — una clave por línea, `clave: valor`.
20
21
  #
@@ -53,29 +54,33 @@
53
54
  # no-capturado/tocado/retomar) during this version, and the verdict notes "old key: <es> → <en>"
54
55
  # once per old key used.
55
56
  #
56
- # Una decisión y un aprendizaje son un archivo propio (spec 043) — `decisions/<fecha>-<slug>.md` y
57
- # `learnings/<slug>.md`, sin fecha en el nombre porque un aprendizaje que se actualiza no cambia de
58
- # identidad. `decisions.md`/`learnings.md` no cambian de nombre ni de lugar: pasan a ser el índice,
59
- # una línea por cuerpo. La de un aprendizaje lleva fecha, título, link y la línea "Cuándo se lee" de
60
- # su cuerpo (`when:`; sin él el cuerpo sale con un marcador de hueco en vez de inventarse uno).
57
+ # Una decisión y un aprendizaje son un archivo propio (spec 043), plano en el espacio de trabajo
58
+ # (spec 076, C17): `<ws>/decisions/<fecha>-<slug>.md` y `<ws>/learnings/<slug>.md`, nunca adentro de
59
+ # un nodo, sin fecha en el nombre de un aprendizaje porque uno que se actualiza no cambia de
60
+ # identidad. Este cierre ya no escribe `decisions.md` ni `learnings.md`: sus índices los genera la
61
+ # lectura de arranque (`build-indexes.sh`) desde el frontmatter de cada archivo. Un aprendizaje lleva
62
+ # frontmatter con `date:`, `about:` cuando la sesión tiene foco, e `index_note:` —la línea "Cuándo se
63
+ # lee" de su cuerpo (`when:`; sin él, el marcador de hueco), que es la cola de su línea del índice—; el
64
+ # cuerpo no cambia.
61
65
  #
62
66
  # DECISIONS ARE WRITTEN IN MADR 4.0.0 (spec 070, https://adr.github.io/madr). Front matter with
63
67
  # `status: accepted`, `date:`, `decision-makers:` (only with `deciders:`) and `key:` (only with
64
68
  # `key:`, an extension of this system); then the sections whose data the material gave: why, the
65
69
  # options, what, replaces/invalidates. A section with no data is not written. The names of the
66
70
  # sections and the labels of the last one come from `core/templates/strings.md`, never from this
67
- # file. `when:` no longer exists for decisions: the verdict reports it and writes nothing. Its line
68
- # in the index is `- DATE · [clave · ][TITLE](path)`, with no tail.
71
+ # file. `when:` no longer exists for decisions: the verdict reports it and writes nothing. With a
72
+ # focus, the front matter also carries `about:` (spec 076, C17).
69
73
  #
70
- # `replaces:` marks the old decision twice and touches nothing else of it: its index line gets
71
- # "reemplazada por" (spec 043) and its front matter gets the replacement mark that `supersede`
72
- # writes (its single writer, spec 046) plus MADR's `status: superseded by <new>`. A body with no
73
- # front matter gets one; the content of the old decision is never rewritten.
74
+ # `replaces:` names the old decision by its title —`title:`, else its `# Title`— among the files of
75
+ # `decisions/`, and marks it and touches nothing else of it: its front matter gets the replacement mark
76
+ # that `supersede` writes (its single writer, spec 046) plus MADR's `status: superseded by <new>`. The
77
+ # generated index reads that mark (spec 076). A body with no front matter gets one; the content of the
78
+ # old decision is never rewritten.
74
79
  #
75
80
  # `key:` marca la decisión como clave (spec 069) y su valor es texto libre que nombra las tres
76
81
  # condiciones (cuánto cuesta revertirla, qué sorprendería sin contexto, qué alternativa se descartó;
77
82
  # la definición vive en core/skills/grill.md#key-decisions). Va en la cabecera del cuerpo y su línea
78
- # del índice suma `clave · ` entre la fecha y el título. Sin `key:` nada de eso aparece. Debajo de
83
+ # del índice generado suma `clave · ` entre la fecha y el título. Sin `key:` nada de eso aparece. Debajo de
79
84
  # `learning:`/`provisional:` se declara como clave fuera de lugar.
80
85
  #
81
86
  # Un registro se cierra cuando empieza el siguiente o cuando termina el archivo. Una clave que no
@@ -110,20 +115,21 @@ nl="${nl%x}"
110
115
  brain=""
111
116
  org=""
112
117
  workspace=""
113
- root=0
114
118
  material=""
115
119
  session_org=""
116
120
  load_context=0
121
+ focus=""
117
122
 
118
123
  while [ $# -gt 0 ]; do
119
124
  case "$1" in
120
- --brain) brain="${2:-}"; shift 2 ;;
121
- --org) org="${2:-}"; shift 2 ;;
122
- --workspace) workspace="${2:-}"; shift 2 ;;
123
- --root) root=1; shift ;;
124
- --material) material="${2:-}"; shift 2 ;;
125
- --session-org) session_org="${2:-}"; shift 2 ;;
125
+ --brain) brain="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
126
+ --org) org="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
127
+ --workspace) workspace="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
128
+ --root) os_die "--root ya no existe (spec 059): el trabajo propio del operador es el espacio de trabajo \"$OS_PERSONAL_WORKSPACE_SLUG\" — usá --workspace $OS_PERSONAL_WORKSPACE_SLUG. Si el brain todavía tiene trabajo suelto en la raíz, correr migrate-root.sh primero" ;;
129
+ --material) material="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
130
+ --session-org) session_org="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
126
131
  --load-context) load_context=1; shift ;;
132
+ --focus) focus="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
127
133
  *) os_die "argumento desconocido: $1" ;;
128
134
  esac
129
135
  done
@@ -135,11 +141,7 @@ fi
135
141
  [ -n "$org" ] || org="$workspace"
136
142
 
137
143
  [ -n "$brain" ] || os_die "falta --brain"
138
- if [ "$root" = "1" ]; then
139
- [ -z "$org" ] || os_die "--root y --org/--workspace son excluyentes"
140
- else
141
- [ -n "$org" ] || os_die "falta --org, --workspace o --root"
142
- fi
144
+ [ -n "$org" ] || os_die "falta --org o --workspace"
143
145
  [ -n "$material" ] || os_die "falta --material"
144
146
  [ -d "$brain" ] || os_die "no existe el brain: $brain"
145
147
  [ -f "$material" ] || os_die "no existe el material de la sesión: $material"
@@ -156,7 +158,7 @@ head=$(os_head_file "$brain") || true
156
158
  # stays in Spanish: that is not what this spec asked to translate.
157
159
  os_lang_load "$(os_language "$brain")" > /dev/null 2>&1
158
160
 
159
- if [ "$root" = "0" ] && ! os_org_existe "$brain" "$org"; then
161
+ if ! os_org_existe "$brain" "$org"; then
160
162
  printf 'la organización "%s" no existe. Las que hay:\n' "$org" >&2
161
163
  slugs=$(os_org_slugs "$brain")
162
164
  if [ -n "$slugs" ]; then
@@ -170,39 +172,30 @@ fi
170
172
  # Escribir en un nodo cuyo `context` no está cargado exige cargarlo primero o negarse. El cierre
171
173
  # escribe en los canónicos del nodo: es la escritura más cara de mandar al lugar equivocado.
172
174
  #
173
- # La raíz no tiene este candado: su identidad (`operator.md`) está cargada en cualquier sesión, a
174
- # cualquier ámbito — no hay `context` cross-nodo que custodiar.
175
- #
176
- # `orgprefix` es la única diferencia de ruta entre los dos ámbitos: "<wsdir>/<slug>/" para una
177
- # organización, vacío para la raíz. Todo lo que sigue arma sus rutas con este prefijo en vez de
178
- # repetir el condicional en cada canónico.
179
- if [ "$root" = "1" ]; then
180
- orgprefix=""
181
- ambito_nombre="raíz"
182
- else
183
- orgprefix="$wsdir/$org/"
184
- ambito_nombre="$org"
185
- ctx="${orgprefix}$head"
186
- res="${orgprefix}resolver.md"
187
- if [ "$session_org" != "$org" ]; then
188
- if [ "$load_context" = "0" ]; then
189
- printf 'escritura cross-nodo: la sesión está parada en "%s" y el cierre escribe en "%s".\n' \
190
- "${session_org:-(ningún ámbito declarado)}" "$org" >&2
191
- printf 'no se escribió nada. Cargá primero %s y %s, y repetí con --load-context.\n' \
192
- "$ctx" "$res" >&2
193
- exit 3
194
- fi
195
- printf 'context cargado antes de escribir en "%s":\n' "$org"
196
- for f in "$ctx" "$res"; do
197
- if [ -f "$brain/$f" ]; then
198
- printf -- '--- %s\n' "$f"
199
- cat "$brain/$f"
200
- else
201
- printf -- '--- %s: no está — se cierra degradado y se dice\n' "$f"
202
- fi
203
- done
204
- printf -- '---\n\n'
175
+ # `orgprefix` es la ruta hasta el espacio de trabajo: "<wsdir>/<slug>/". Todo lo que sigue arma sus
176
+ # rutas con este prefijo.
177
+ orgprefix="$wsdir/$org/"
178
+ ambito_nombre="$org"
179
+ ctx="${orgprefix}$head"
180
+ res="${orgprefix}.resolver.md"
181
+ if [ "$session_org" != "$org" ]; then
182
+ if [ "$load_context" = "0" ]; then
183
+ printf 'escritura cross-nodo: la sesión está parada en "%s" y el cierre escribe en "%s".\n' \
184
+ "${session_org:-(ningún ámbito declarado)}" "$org" >&2
185
+ printf 'no se escribió nada. Cargá primero %s y %s, y repetí con --load-context.\n' \
186
+ "$ctx" "$res" >&2
187
+ exit 3
205
188
  fi
189
+ printf 'context cargado antes de escribir en "%s":\n' "$org"
190
+ for f in "$ctx" "$res"; do
191
+ if [ -f "$brain/$f" ]; then
192
+ printf -- '--- %s\n' "$f"
193
+ cat "$brain/$f"
194
+ else
195
+ printf -- '--- %s: no está — se cierra degradado y se dice\n' "$f"
196
+ fi
197
+ done
198
+ printf -- '---\n\n'
206
199
  fi
207
200
 
208
201
  hoy=$(date +%Y-%m-%d)
@@ -246,7 +239,7 @@ marcar_escrito() {
246
239
  declarar_glob() {
247
240
  os_tree_ensure "$brain" "$1"
248
241
  case "$?" in
249
- 0) push_capturado "tree.md — glob declarado: $1"; marcar_escrito "tree.md" ;;
242
+ 0) push_capturado "tree.md — glob declarado: $1"; marcar_escrito "$OS_TREE_FILE" ;;
250
243
  2) push_no_capturado "falta tree.md — el glob \"$1\" quedó sin declarar" ;;
251
244
  esac
252
245
  }
@@ -254,27 +247,82 @@ declarar_glob() {
254
247
  declarar_content() {
255
248
  os_tree_ensure "$brain" "$1" content
256
249
  case "$?" in
257
- 0) push_capturado "tree.md — content declarado: $1"; marcar_escrito "tree.md" ;;
250
+ 0) push_capturado "tree.md — content declarado: $1"; marcar_escrito "$OS_TREE_FILE" ;;
258
251
  2) push_no_capturado "falta tree.md — el content \"$1\" quedó sin declarar" ;;
259
252
  esac
260
253
  }
261
254
 
262
- # ---------------------------------------------------------------- los canónicos del nodo
263
- # Un archivo que solo guarda contenido nace con su primer dato. `decisions` y `learnings` son dos de
264
- # las cinco preguntas del nodo: en un nodo carpeta, cada una es su archivo. Con `--root` son dos de
265
- # las cuatro preguntas propias de la raíz (spec 018) — mismo formato, sin `<wsdir>/<slug>/` adelante.
266
- nace_canonico() {
267
- # nace_canonico ARCHIVO TITULO SUBTITULO
268
- local file="$brain/${orgprefix}$1" glob
269
- [ -f "$file" ] && return 0
270
- {
271
- printf '# %s\n\n' "$2"
272
- printf '%s\n\n' "$3"
273
- } > "$file"
274
- push_capturado "${orgprefix}$1 nació con su primer dato"
275
- if [ "$root" = "1" ]; then glob="$1"; else glob="$wsdir/*/$1"; fi
276
- declarar_glob "$glob"
277
- return 0
255
+ # ---------------------------------------------------------------- what the session was about (spec 076, C17)
256
+ # The `about:` this close writes, decided once from `--focus`: the focus when it is an area node, the
257
+ # focus's own `about:` as written when it is an initiative, nothing otherwise.
258
+ # The focus and every node it names belong to the destination workspace: a decision of this
259
+ # workspace about a node of another one would be filed under a node its index never reads.
260
+ about=""
261
+ if [ -n "$focus" ]; then
262
+ focus=$(os_rel_norm "$focus")
263
+ if [ ! -f "$brain/$focus" ]; then
264
+ push_no_capturado "foco sin cabeza: $focus — lo de esta sesión quedó sin about"
265
+ else
266
+ case "$(os_head_kind "$wsdir" "$head" "$focus")" in
267
+ "entity $org") about="$focus" ;;
268
+ "initiative $org")
269
+ fm_read "$brain/$focus"
270
+ about_ok=""; about_n=0
271
+ while IFS= read -r v || [ -n "$v" ]; do
272
+ [ -n "$v" ] || continue
273
+ v=$(os_rel_norm "$v")
274
+ case "$(os_head_kind "$wsdir" "$head" "$v")" in
275
+ "entity $org") ;;
276
+ *) push_no_capturado "about del foco fuera de \"$org\" o que no es un nodo, no se copió: $v"; continue ;;
277
+ esac
278
+ about_n=$(( about_n + 1 ))
279
+ if [ -z "$about_ok" ]; then about_ok="$v"; else about_ok="$about_ok, $v"; fi
280
+ done <<VALS
281
+ $(os_about_values "$fm_about")
282
+ VALS
283
+ if [ "$about_n" -gt 1 ]; then about="[$about_ok]"; else about="$about_ok"; fi
284
+ ;;
285
+ entity\ *|initiative\ *) push_no_capturado "foco de otro espacio de trabajo: $focus — lo de esta sesión quedó sin about" ;;
286
+ esac
287
+ fi
288
+ fi
289
+
290
+ # about_union OLD NEW -> one `about:` value with every node of OLD and then the new ones of NEW.
291
+ about_union() {
292
+ local v out="" n=0 seen
293
+ seen=$(printf '\n')
294
+ while IFS= read -r v || [ -n "$v" ]; do
295
+ [ -n "$v" ] || continue
296
+ v=$(os_rel_norm "$v")
297
+ case "$seen" in *"
298
+ $v
299
+ "*) continue ;; esac
300
+ seen="$seen
301
+ $v
302
+ "
303
+ n=$(( n + 1 ))
304
+ if [ -z "$out" ]; then out="$v"; else out="$out, $v"; fi
305
+ done <<VALS
306
+ $(os_about_values "$1")
307
+ $(os_about_values "$2")
308
+ VALS
309
+ if [ "$n" -gt 1 ]; then printf '[%s]' "$out"; else printf '%s' "$out"; fi
310
+ }
311
+
312
+ # doc_por_titulo DIR TITLE -> the first file of that folder (never its `index.md`) whose title is
313
+ # TITLE, relative to the brain. Exit 1 when there is none.
314
+ doc_por_titulo() {
315
+ local dir="$1" titulo="$2" f rel
316
+ for f in "$brain/$dir"/*.md; do
317
+ [ -f "$f" ] || continue
318
+ rel="${f#"$brain"/}"
319
+ [ "${rel##*/}" = "index.md" ] && continue
320
+ if [ "$(os_doc_title "$f")" = "$titulo" ]; then
321
+ printf '%s' "$rel"
322
+ return 0
323
+ fi
324
+ done
325
+ return 1
278
326
  }
279
327
 
280
328
  escribir_decision() {
@@ -282,12 +330,15 @@ escribir_decision() {
282
330
  # OPCIONES: one option per line, in the order of the material.
283
331
  local titulo="$1" que="$2" porque="$3" reemplaza="$4" invalidaria="$5" opciones="$6" decisores="$7"
284
332
  local clave="${8:-}"
285
- local idx="$brain/${orgprefix}decisions.md" contentglob rel full viejo_rel opcion
286
- nace_canonico "decisions.md" "Decisiones" \
287
- "Registro append-only. Nunca se corrige: si una decisión cambia, se agrega otra que la reemplaza y la nombra."
288
- if [ "$root" = "1" ]; then contentglob="decisions/*.md"; else contentglob="$wsdir/*/decisions/*.md"; fi
333
+ local contentglob rel full viejo_rel="" opcion
334
+ contentglob="$wsdir/*/decisions/*.md"
289
335
  declarar_content "$contentglob"
290
336
  mkdir -p "$brain/${orgprefix}decisions"
337
+ # The replaced decision is found before the new file exists, so a new one with the same title is
338
+ # never mistaken for it.
339
+ if [ -n "$reemplaza" ]; then
340
+ viejo_rel=$(doc_por_titulo "${orgprefix}decisions" "$reemplaza") || viejo_rel=""
341
+ fi
291
342
  rel=$(os_decision_path "$brain" "$orgprefix" "$hoy" "$titulo")
292
343
  full="$brain/${orgprefix}$rel"
293
344
  # MADR 4.0.0 (spec 070). The keys of the header stay in English in every language; the names of
@@ -299,6 +350,7 @@ escribir_decision() {
299
350
  printf 'date: %s\n' "$hoy"
300
351
  [ -n "$decisores" ] && printf 'decision-makers: %s\n' "$decisores"
301
352
  [ -n "$clave" ] && printf 'key: %s\n' "$clave"
353
+ [ -n "$about" ] && printf 'about: %s\n' "$about"
302
354
  printf -- '---\n\n'
303
355
  printf '# %s\n\n' "$titulo"
304
356
  [ -n "$porque" ] && printf '## %s\n%s\n\n' "$S_DECISION_CONTEXT_HEADING" "$porque"
@@ -320,36 +372,27 @@ OPCIONES
320
372
  printf '\n'
321
373
  fi
322
374
  } > "$full"
323
- # The index line of a decision carries no "when it is read" tail (spec 070).
324
- if [ -n "$clave" ]; then
325
- os_index_line "$hoy" "$titulo" "$rel" "" key >> "$idx"
326
- else
327
- os_index_line "$hoy" "$titulo" "$rel" "" >> "$idx"
328
- fi
329
375
  if [ -n "$reemplaza" ]; then
330
- # The replaced body is found through the index line, before that line is marked. Its header gets
331
- # the status; its content does not change.
332
- if viejo_rel=$(os_index_link_of "$idx" "$reemplaza") && [ -f "$brain/${orgprefix}$viejo_rel" ]; then
333
- if os_decision_mark_superseded "$brain" "${orgprefix}$viejo_rel" "${orgprefix}$rel"; then
334
- marcar_escrito "${orgprefix}$viejo_rel"
376
+ # The replaced body gets the mark in its header; its content does not change.
377
+ if [ -n "$viejo_rel" ]; then
378
+ if os_decision_mark_superseded "$brain" "$viejo_rel" "${orgprefix}$rel"; then
379
+ marcar_escrito "$viejo_rel"
335
380
  else
336
- push_no_capturado "decisión reemplazada sin cabecera legible, no se marcó: ${orgprefix}$viejo_rel"
381
+ push_no_capturado "decisión reemplazada sin cabecera legible, no se marcó: $viejo_rel"
337
382
  fi
383
+ else
384
+ push_no_capturado "la decisión que esta reemplaza no está en ${orgprefix}decisions/: $reemplaza"
338
385
  fi
339
- os_index_mark_superseded "$idx" "$reemplaza" "$titulo" "$rel" || true
340
386
  fi
341
387
  push_capturado "decisión → ${orgprefix}$rel: $titulo"
342
388
  marcar_escrito "${orgprefix}$rel"
343
- marcar_escrito "${orgprefix}decisions.md"
344
389
  }
345
390
 
346
391
  escribir_learning() {
347
392
  # escribir_learning TITULO CUERPO STATUS CUANDO
348
393
  local titulo="$1" cuerpo="$2" status="$3" cuando="$4"
349
- local idx="$brain/${orgprefix}learnings.md" contentglob rel full existia=0
350
- nace_canonico "learnings.md" "Aprendizajes" \
351
- "Vivo: se actualiza o se borra. Lo que se intentó y no cerró queda con status: provisional, para que nadie lo reintente sin saberlo."
352
- if [ "$root" = "1" ]; then contentglob="learnings/*.md"; else contentglob="$wsdir/*/learnings/*.md"; fi
394
+ local contentglob rel full existia=0
395
+ contentglob="$wsdir/*/learnings/*.md"
353
396
  declarar_content "$contentglob"
354
397
  mkdir -p "$brain/${orgprefix}learnings"
355
398
  [ -n "$cuando" ] || cuando="$OS_CUANDO_FALTA"
@@ -357,20 +400,36 @@ escribir_learning() {
357
400
  full="$brain/${orgprefix}$rel"
358
401
  if [ "$existia" = "1" ]; then
359
402
  # El mismo título ya tiene archivo: es el mismo aprendizaje actualizándose, nunca un segundo
360
- # archivo (spec 043, C2) — el índice ya tiene su línea, no se agrega otra.
403
+ # archivo (spec 043, C2). Its frontmatter stays, except `about:`: the nodes of this close join the
404
+ # ones it had, so the index of the node now in focus lists it too. A body with no frontmatter
405
+ # (written before spec 076) is left as it was.
406
+ if [ -n "$about" ]; then
407
+ fm_read "$full"
408
+ if [ -z "$fm_roto" ]; then
409
+ nuevo_about=$(about_union "$fm_about" "$about")
410
+ [ "$nuevo_about" = "$fm_about" ] || os_fm_set "$full" about "$nuevo_about" || \
411
+ push_no_capturado "no se pudo sumar el about al aprendizaje: ${orgprefix}$rel"
412
+ fi
413
+ fi
361
414
  {
362
415
  printf '\n---\n\n## %s\n\n' "$hoy"
363
416
  [ "$status" = "provisional" ] && printf 'status: provisional\n\n'
364
417
  printf '%s\n' "$cuerpo"
365
418
  } >> "$full"
366
419
  else
420
+ # The same keys a decision carries where they apply (spec 076, delegated decision): `date:` and
421
+ # `about:`; `index_note:` is the tail of its index line. The body is what it always was.
367
422
  {
423
+ printf -- '---\n'
424
+ printf 'date: %s\n' "$hoy"
425
+ [ -n "$about" ] && printf 'about: %s\n' "$about"
426
+ printf 'index_note: %s\n' "$cuando"
427
+ printf -- '---\n\n'
368
428
  printf '# %s\n\n' "$titulo"
369
429
  printf '> **Cuándo se lee**: %s\n\n' "$cuando"
370
430
  [ "$status" = "provisional" ] && printf 'status: provisional\n\n'
371
431
  printf '%s\n' "$cuerpo"
372
432
  } > "$full"
373
- os_index_line "$hoy" "$titulo" "$rel" "$cuando" >> "$idx"
374
433
  fi
375
434
  if [ "$status" = "provisional" ]; then
376
435
  push_capturado "intento sin conclusión → ${orgprefix}$rel (status: provisional): $titulo"
@@ -378,7 +437,6 @@ escribir_learning() {
378
437
  push_capturado "aprendizaje → ${orgprefix}$rel: $titulo"
379
438
  fi
380
439
  marcar_escrito "${orgprefix}$rel"
381
- marcar_escrito "${orgprefix}learnings.md"
382
440
  }
383
441
 
384
442
  # ---------------------------------------------------------------- el material
@@ -494,19 +552,14 @@ CAMPOS
494
552
  fi
495
553
  if [ -z "$texto" ]; then push_no_capturado "pendiente sin texto"; continue; fi
496
554
  # Archivar una tarea suelta ya es `capture`: el cierre la llama en vez de repetir su escritura.
497
- # La raíz no manda `--session-org`: capture.sh nunca la pide para su propio ámbito. Sin
498
- # iniciativa (`pending:` a secas, o `pending-from:` sin el nombre antes del `|`) capture no
555
+ # Sin iniciativa (`pending:` a secas, o `pending-from:` sin el nombre antes del `|`) capture no
499
556
  # escribe nada (spec 057, decisión 2): se declara no capturado, nombrando qué falta.
500
557
  if [ -z "$ini" ]; then
501
558
  push_no_capturado "pendiente sin iniciativa, no se archivó: $texto"
502
559
  continue
503
560
  fi
504
- if [ "$root" = "1" ]; then
505
- salida=$("$here/capture.sh" --brain "$brain" --root --initiative "$ini" --text "$texto" 2>&1)
506
- else
507
- salida=$("$here/capture.sh" --brain "$brain" --org "$org" --session-org "$org" \
508
- --initiative "$ini" --text "$texto" 2>&1)
509
- fi
561
+ salida=$("$here/capture.sh" --brain "$brain" --org "$org" --session-org "$org" \
562
+ --initiative "$ini" --text "$texto" 2>&1)
510
563
  rc=$?
511
564
  if [ "$rc" = "0" ]; then
512
565
  detalle=$(os_trim "$(printf '%s\n' "$salida" | grep 'backlog.md — ' | head -1)")
@@ -777,7 +830,7 @@ if [ -z "$candidatas" ]; then
777
830
  printf ' ninguna escritura necesitó decidir fuera del resolver\n'
778
831
  else
779
832
  printf '%s' "$candidatas"
780
- printf ' la escribe el operador en %sresolver.md con un sí — no se escribe sola\n' "$orgprefix"
833
+ printf ' la escribe el operador en %s.resolver.md con un sí — no se escribe sola\n' "$orgprefix"
781
834
  fi
782
835
 
783
836
  printf '\nSin commitear (no es de esta sesión)\n'