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/common.sh
CHANGED
|
@@ -7,6 +7,28 @@
|
|
|
7
7
|
# Tope de identidad, en líneas. Única enunciación del número en el código distribuido.
|
|
8
8
|
OS_IDENTITY_CAP=40
|
|
9
9
|
|
|
10
|
+
# The machinery of the brain's root lives in one hidden folder (spec 076, C7): the tree, the root
|
|
11
|
+
# resolver and the mounts table. Only statement of the folder name in the distributed code; every
|
|
12
|
+
# reader builds its path from the constants below, never from a path spelled by hand.
|
|
13
|
+
OS_SYSTEM_DIR=".system"
|
|
14
|
+
OS_TREE_FILE="$OS_SYSTEM_DIR/tree.md"
|
|
15
|
+
OS_ROOT_RESOLVER_FILE="$OS_SYSTEM_DIR/resolver.md"
|
|
16
|
+
|
|
17
|
+
# The account (spec 076, C8): who the operator is and how they write. Visible, edited by the person.
|
|
18
|
+
OS_ACCOUNT_DIR="account"
|
|
19
|
+
OS_OPERATOR_FILE="$OS_ACCOUNT_DIR/operator.md"
|
|
20
|
+
OS_VOICE_FILE="$OS_ACCOUNT_DIR/voice/voice.md"
|
|
21
|
+
|
|
22
|
+
# Where an installed skill can live (spec 076, C10), in lookup order: the open-standard folder first,
|
|
23
|
+
# then Claude Code's. `npx skills add` leaves the skill in the first and a link in the second, so a
|
|
24
|
+
# skill present in both counts once (see `os_skill_dirs`).
|
|
25
|
+
OS_SKILL_DIRS=".agents/skills .claude/skills"
|
|
26
|
+
|
|
27
|
+
# Cap, in lines, for each of a workspace's `glossary.md` and `context-map.md` (spec 072): the startup
|
|
28
|
+
# read loads them whole, so past this the scan warns. It never truncates. Only statement of the
|
|
29
|
+
# number in the distributed code.
|
|
30
|
+
OS_GLOSSARY_CAP=100
|
|
31
|
+
|
|
10
32
|
# Separador de campos de los registros internos: nunca aparece en un archivo del operador.
|
|
11
33
|
OS_SEP=$(printf '\037')
|
|
12
34
|
|
|
@@ -31,22 +53,51 @@ OS_CUANDO_FALTA='❓ sin definir — no se declaró en el cierre'
|
|
|
31
53
|
# La cabeza no está en la lista porque su nombre es dato del brain (spec 040): la suma
|
|
32
54
|
# `os_org_propios`, leyéndolo del árbol. Esta lista es además el negativo con el que `os_head_file`
|
|
33
55
|
# reconoce la cabeza entre los globs de la altura del espacio de trabajo.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
#
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
#
|
|
56
|
+
# Since spec 076 a workspace's own files are its head and `.resolver.md`: decisions and learnings are
|
|
57
|
+
# folders, and no backlog lives outside an initiative. The names of before stay in the list so a
|
|
58
|
+
# brain not migrated yet still tells its head apart from them.
|
|
59
|
+
OS_NODE_CANONICOS=".resolver.md resolver.md backlog.md decisions.md learnings.md"
|
|
60
|
+
|
|
61
|
+
# Los archivos propios de la raíz como nodo, en un brain nacido antes de la spec 059 y todavía sin
|
|
62
|
+
# migrar: sus preguntas canónicas, más el backlog. La raíz no tiene cabeza propia —esa identidad es
|
|
63
|
+
# `operator.md`, que ya se lee siempre— así que la lista es la de arriba más los archivos que ya
|
|
64
|
+
# vivían sueltos en la raíz (`operator.md`, `inbox.md`, `mounts.md`). Desde la spec 059 la raíz solo
|
|
65
|
+
# nace con maquinaria: esta lista sigue viva porque `sweep.sh` y `recall.sh --root` siguen leyendo
|
|
66
|
+
# trabajo propio de la raíz de un brain viejo — `migrate-root.sh` es lo que lo mueve a
|
|
67
|
+
# `workspaces/personal`.
|
|
41
68
|
OS_ROOT_PROPIOS="operator.md resolver.md inbox.md mounts.md backlog.md decisions.md learnings.md"
|
|
42
69
|
|
|
43
|
-
# La etiqueta que agrupa el trabajo propio de la raíz en los barridos globales
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
# valor reservado de `--org`: un valor de texto siempre puede colisionar con lo que alguien nombre.
|
|
70
|
+
# La etiqueta que agrupa el trabajo propio de la raíz en los barridos globales, sobre un brain
|
|
71
|
+
# todavía sin migrar (spec 018, vigente para `sweep.sh` después de la 059). Nunca puede ser un slug
|
|
72
|
+
# real: `os_slugify` solo produce alfanumérico en minúscula y guiones, y esta etiqueta lleva
|
|
73
|
+
# paréntesis y una tilde.
|
|
48
74
|
OS_ROOT_LABEL="(raíz)"
|
|
49
75
|
|
|
76
|
+
# El slug fijo del espacio de trabajo con el que todo brain nuevo nace (spec 059, decisión 3): nunca
|
|
77
|
+
# lo elige el operador ni lo pregunta la entrevista. `bootstrap.sh` lo crea siempre; `migrate-root.sh`
|
|
78
|
+
# mueve ahí el trabajo de un brain viejo, creándolo si no existe.
|
|
79
|
+
OS_PERSONAL_WORKSPACE_SLUG="personal"
|
|
80
|
+
|
|
81
|
+
# os_root_gone BRAIN — the answer of a startup tool (`session-start.sh`, `session-read.sh`) asked for
|
|
82
|
+
# `--root`, which no longer exists as a scope (spec 059): names the workspaces there are and the
|
|
83
|
+
# migration, on stderr, and exits 2 — the same exit as a workspace that does not exist. Written
|
|
84
|
+
# once, here, so the two halves of the startup cannot answer differently.
|
|
85
|
+
os_root_gone() {
|
|
86
|
+
local brain="$1" slugs
|
|
87
|
+
[ -n "$brain" ] || os_die "falta --brain"
|
|
88
|
+
[ -d "$brain" ] || os_die "no existe el brain: $brain"
|
|
89
|
+
brain=$(cd "$brain" && pwd)
|
|
90
|
+
slugs=$(os_org_slugs "$brain" 2>/dev/null) || slugs=""
|
|
91
|
+
printf 'error: --root ya no existe (spec 059) — el trabajo del operador pasó a un espacio de trabajo. Los que hay:\n' >&2
|
|
92
|
+
if [ -n "$slugs" ]; then
|
|
93
|
+
printf '%s\n' "$slugs" | while IFS= read -r s; do [ -n "$s" ] && printf ' %s\n' "$s" >&2; done
|
|
94
|
+
else
|
|
95
|
+
printf ' (ninguno)\n' >&2
|
|
96
|
+
fi
|
|
97
|
+
printf 'Si el brain todavía tiene trabajo suelto en la raíz, correr .os/core/lib/migrate-root.sh --brain . primero.\n' >&2
|
|
98
|
+
exit 2
|
|
99
|
+
}
|
|
100
|
+
|
|
50
101
|
# os_cerrado ESTADO -> 0 si ese estado saca la cabeza de lo activo.
|
|
51
102
|
os_cerrado() {
|
|
52
103
|
local e
|
|
@@ -182,12 +233,12 @@ os_language_valido() {
|
|
|
182
233
|
# without anyone noticing — same criterion `os_lang_load` already uses for a key with no
|
|
183
234
|
# translation.
|
|
184
235
|
os_language() {
|
|
185
|
-
fm_read "$1
|
|
236
|
+
fm_read "$1/$OS_OPERATOR_FILE"
|
|
186
237
|
if [ -n "$fm_language" ] && os_language_valido "$fm_language"; then
|
|
187
238
|
printf '%s' "$fm_language"
|
|
188
239
|
else
|
|
189
240
|
if [ -n "$fm_language" ]; then
|
|
190
|
-
os_warn "
|
|
241
|
+
os_warn "$OS_OPERATOR_FILE — language: $fm_language is not supported: falling back to en"
|
|
191
242
|
fi
|
|
192
243
|
printf 'en'
|
|
193
244
|
fi
|
|
@@ -249,10 +300,14 @@ os_lang_load() {
|
|
|
249
300
|
return 0
|
|
250
301
|
}
|
|
251
302
|
|
|
252
|
-
#
|
|
253
|
-
#
|
|
254
|
-
#
|
|
255
|
-
|
|
303
|
+
# The name of the manual's link at the root of the brain (spec 076, C11): always the same, in every
|
|
304
|
+
# language, so the one visible file at the root has one name. The link points at the manual of the
|
|
305
|
+
# brain's language (`os_manual_file`). Only statement of the name in the distributed code.
|
|
306
|
+
OS_MANUAL_LINK="HOW-IT-WORKS.md"
|
|
307
|
+
|
|
308
|
+
# os_manual_file IDIOMA -> el nombre del archivo del manual de usuario en ese idioma, dentro de
|
|
309
|
+
# `core/manual/` (spec 022). Única enunciación del par idioma → nombre de archivo: lo leen el
|
|
310
|
+
# enlazador y los evals. El enlace de la raíz del brain no lleva este nombre sino `OS_MANUAL_LINK`.
|
|
256
311
|
os_manual_file() {
|
|
257
312
|
case "$1" in
|
|
258
313
|
es) printf 'COMO-FUNCIONA.md' ;;
|
|
@@ -307,11 +362,13 @@ CAP_FRONTMATTER=30
|
|
|
307
362
|
|
|
308
363
|
fm_status=""; fm_horizon=""; fm_waiting_on=""; fm_blocked=""; fm_role=""; fm_owner=""
|
|
309
364
|
fm_depends_on=""; fm_repo=""; fm_language=""; fm_superseded_by=""; fm_about=""
|
|
365
|
+
fm_date=""; fm_key=""; fm_title=""; fm_index_note=""; fm_generated=""
|
|
310
366
|
fm_roto=""
|
|
311
367
|
|
|
312
368
|
fm_limpiar() {
|
|
313
369
|
fm_status=""; fm_horizon=""; fm_waiting_on=""; fm_blocked=""; fm_role=""; fm_owner=""
|
|
314
370
|
fm_depends_on=""; fm_repo=""; fm_language=""; fm_superseded_by=""; fm_about=""
|
|
371
|
+
fm_date=""; fm_key=""; fm_title=""; fm_index_note=""; fm_generated=""
|
|
315
372
|
}
|
|
316
373
|
|
|
317
374
|
# fm_read ARCHIVO — deja el resultado en las variables fm_*. `fm_roto` no vacío significa que no se
|
|
@@ -336,8 +393,15 @@ fm_read() {
|
|
|
336
393
|
*:*) ;;
|
|
337
394
|
*) continue ;;
|
|
338
395
|
esac
|
|
339
|
-
|
|
340
|
-
|
|
396
|
+
# Trimmed in place, with no subshell: this loop runs once per frontmatter line of every head and
|
|
397
|
+
# every decision the reads walk (spec 076 builds the indexes on each startup read), and a `$(...)`
|
|
398
|
+
# per line was the whole cost. Same rule as `os_trim`: spaces only, both ends.
|
|
399
|
+
key="${line%%:*}"
|
|
400
|
+
while [ "${key# }" != "$key" ]; do key="${key# }"; done
|
|
401
|
+
while [ "${key% }" != "$key" ]; do key="${key% }"; done
|
|
402
|
+
value="${line#*:}"
|
|
403
|
+
while [ "${value# }" != "$value" ]; do value="${value# }"; done
|
|
404
|
+
while [ "${value% }" != "$value" ]; do value="${value% }"; done
|
|
341
405
|
case "$key" in
|
|
342
406
|
status) fm_status="$value" ;;
|
|
343
407
|
horizon) fm_horizon="$value" ;;
|
|
@@ -355,11 +419,22 @@ fm_read() {
|
|
|
355
419
|
# reaches and a content file that only a `content:` reaches — because the reader at risk is
|
|
356
420
|
# whoever opened the file, not whoever walked the tree.
|
|
357
421
|
superseded_by) fm_superseded_by="$value" ;;
|
|
358
|
-
# `about:` (spec 049) —
|
|
359
|
-
#
|
|
360
|
-
#
|
|
361
|
-
#
|
|
362
|
-
about
|
|
422
|
+
# `about:` (spec 049) — the path, relative to the brain, of the head this node is about, or a
|
|
423
|
+
# list of them on one line (spec 076, C16: `os_about_values` splits it). Kept raw here. A
|
|
424
|
+
# decision or a learning carries it too (spec 076, C17): the scan never opens those, the index
|
|
425
|
+
# generator and the focus's key decisions do.
|
|
426
|
+
# `about: []` names nothing: the same as no `about:` at all, for every reader (spec 076, C16).
|
|
427
|
+
about) case "$value" in '['*']') [ -n "$(printf '%s' "${value#\[}" | tr -d ' ]')" ] || value="" ;; esac
|
|
428
|
+
fm_about="$value" ;;
|
|
429
|
+
# The keys of the generated indexes (spec 076, C18): `date:` and `key:` of a decision or a
|
|
430
|
+
# learning, `title:` when the link text differs from the body's `# Title`, `index_note:` the
|
|
431
|
+
# tail of its index line, and `generated:` on every file a script writes so the AI and the
|
|
432
|
+
# generator never mistake it for one a person wrote.
|
|
433
|
+
date) fm_date="$value" ;;
|
|
434
|
+
key) fm_key="$value" ;;
|
|
435
|
+
title) fm_title="$value" ;;
|
|
436
|
+
index_note) fm_index_note="$value" ;;
|
|
437
|
+
generated) fm_generated="$value" ;;
|
|
363
438
|
esac
|
|
364
439
|
done < "$file"
|
|
365
440
|
if [ "$primera" = "1" ]; then fm_roto="sin frontmatter"; return 0; fi
|
|
@@ -381,7 +456,7 @@ fm_read() {
|
|
|
381
456
|
# en `tree.md`, no tocar un script.
|
|
382
457
|
os_tree_files() {
|
|
383
458
|
local brain="$1" line g
|
|
384
|
-
[ -f "$brain
|
|
459
|
+
[ -f "$brain/$OS_TREE_FILE" ] || return 1
|
|
385
460
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
386
461
|
case "$line" in
|
|
387
462
|
glob:*) ;;
|
|
@@ -390,29 +465,7 @@ os_tree_files() {
|
|
|
390
465
|
g=$(os_trim "${line#glob:}")
|
|
391
466
|
[ -n "$g" ] || continue
|
|
392
467
|
( cd "$brain" && for f in $g; do [ -e "$f" ] && printf '%s\n' "$f"; done )
|
|
393
|
-
done < "$brain
|
|
394
|
-
return 0
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
# os_tree_globs BRAIN -> the `glob:` patterns themselves, one per line, unexpanded. Exit 1 if there
|
|
398
|
-
# is no declaration: the caller decides what to say.
|
|
399
|
-
#
|
|
400
|
-
# Fourth reader of the same file, and the reason it lives here like the other three: a caller that
|
|
401
|
-
# needs to know which levels the tree DECLARES — not which files exist at them today — would
|
|
402
|
-
# otherwise parse `tree.md` on its own. `my-wiki.sh` (spec 060) derives the entity types of a brain
|
|
403
|
-
# from these patterns, so a type declared with no node in it yet is still a type.
|
|
404
|
-
os_tree_globs() {
|
|
405
|
-
local brain="$1" line g
|
|
406
|
-
[ -f "$brain/tree.md" ] || return 1
|
|
407
|
-
while IFS= read -r line || [ -n "$line" ]; do
|
|
408
|
-
case "$line" in
|
|
409
|
-
glob:*) ;;
|
|
410
|
-
*) continue ;;
|
|
411
|
-
esac
|
|
412
|
-
g=$(os_trim "${line#glob:}")
|
|
413
|
-
[ -n "$g" ] || continue
|
|
414
|
-
printf '%s\n' "$g"
|
|
415
|
-
done < "$brain/tree.md"
|
|
468
|
+
done < "$brain/$OS_TREE_FILE"
|
|
416
469
|
return 0
|
|
417
470
|
}
|
|
418
471
|
|
|
@@ -427,7 +480,7 @@ os_tree_globs() {
|
|
|
427
480
|
# este repo ya prohíbe — por eso el lector queda acá, el único lugar que lee el formato.
|
|
428
481
|
os_tree_content_files() {
|
|
429
482
|
local brain="$1" line g
|
|
430
|
-
[ -f "$brain
|
|
483
|
+
[ -f "$brain/$OS_TREE_FILE" ] || return 1
|
|
431
484
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
432
485
|
case "$line" in
|
|
433
486
|
content:*) ;;
|
|
@@ -436,7 +489,7 @@ os_tree_content_files() {
|
|
|
436
489
|
g=$(os_trim "${line#content:}")
|
|
437
490
|
[ -n "$g" ] || continue
|
|
438
491
|
( cd "$brain" && for f in $g; do [ -e "$f" ] && printf '%s\n' "$f"; done )
|
|
439
|
-
done < "$brain
|
|
492
|
+
done < "$brain/$OS_TREE_FILE"
|
|
440
493
|
return 0
|
|
441
494
|
}
|
|
442
495
|
|
|
@@ -451,7 +504,7 @@ os_tree_content_files() {
|
|
|
451
504
|
# forgetting to filter them out. The only file that parses `tree.md` is still this one.
|
|
452
505
|
os_tree_archive_files() {
|
|
453
506
|
local brain="$1" line g
|
|
454
|
-
[ -f "$brain
|
|
507
|
+
[ -f "$brain/$OS_TREE_FILE" ] || return 1
|
|
455
508
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
456
509
|
case "$line" in
|
|
457
510
|
archive:*) ;;
|
|
@@ -460,7 +513,7 @@ os_tree_archive_files() {
|
|
|
460
513
|
g=$(os_trim "${line#archive:}")
|
|
461
514
|
[ -n "$g" ] || continue
|
|
462
515
|
( cd "$brain" && for f in $g; do [ -e "$f" ] && printf '%s\n' "$f"; done )
|
|
463
|
-
done < "$brain
|
|
516
|
+
done < "$brain/$OS_TREE_FILE"
|
|
464
517
|
return 0
|
|
465
518
|
}
|
|
466
519
|
|
|
@@ -539,7 +592,7 @@ os_inside_brain() {
|
|
|
539
592
|
os_memory_types() {
|
|
540
593
|
local brain="$1" scope="$2" wsdir head prefix line g rest tipo resto2 types nl
|
|
541
594
|
nl=$(printf '\nx'); nl="${nl%x}"
|
|
542
|
-
[ -f "$brain
|
|
595
|
+
[ -f "$brain/$OS_TREE_FILE" ] || return 1
|
|
543
596
|
wsdir=$(os_ws_dir "$brain")
|
|
544
597
|
head=$(os_head_file "$brain") || true
|
|
545
598
|
if [ "$scope" = "root" ]; then prefix=""; else prefix="$wsdir/*/"; fi
|
|
@@ -562,7 +615,7 @@ os_memory_types() {
|
|
|
562
615
|
[ "$resto2" = "*/$head" ] || continue
|
|
563
616
|
case "$nl$types" in *"$nl$tipo$nl"*) continue ;; esac
|
|
564
617
|
types="$types$tipo$nl"
|
|
565
|
-
done < "$brain
|
|
618
|
+
done < "$brain/$OS_TREE_FILE"
|
|
566
619
|
printf '%s' "$types"
|
|
567
620
|
return 0
|
|
568
621
|
}
|
|
@@ -576,13 +629,13 @@ os_memory_own_file() {
|
|
|
576
629
|
local wsdir="$1" head="$2" types_org="$3" types_root="$4" f="$5" t
|
|
577
630
|
for t in $types_org; do
|
|
578
631
|
case "$f" in
|
|
579
|
-
"$wsdir"/*/"$t"/*/"$head"|"$wsdir"/*/"$t"/*/resolver.md|"$wsdir"/*/"$t"/*/decisions.md)
|
|
632
|
+
"$wsdir"/*/"$t"/*/"$head"|"$wsdir"/*/"$t"/*/.resolver.md|"$wsdir"/*/"$t"/*/resolver.md|"$wsdir"/*/"$t"/*/decisions.md)
|
|
580
633
|
return 0 ;;
|
|
581
634
|
esac
|
|
582
635
|
done
|
|
583
636
|
for t in $types_root; do
|
|
584
637
|
case "$f" in
|
|
585
|
-
"$t"/*/"$head"|"$t"/*/resolver.md|"$t"/*/decisions.md) return 0 ;;
|
|
638
|
+
"$t"/*/"$head"|"$t"/*/.resolver.md|"$t"/*/resolver.md|"$t"/*/decisions.md) return 0 ;;
|
|
586
639
|
esac
|
|
587
640
|
done
|
|
588
641
|
return 1
|
|
@@ -599,7 +652,7 @@ os_memory_own_file() {
|
|
|
599
652
|
os_head_kind() {
|
|
600
653
|
local wsdir="$1" head="$2" f="$3" ws inner mid tipo
|
|
601
654
|
|
|
602
|
-
if [ "$f" = "
|
|
655
|
+
if [ "$f" = "$OS_OPERATOR_FILE" ]; then printf 'root'; return 0; fi
|
|
603
656
|
|
|
604
657
|
case "$f" in
|
|
605
658
|
"$wsdir"/*)
|
|
@@ -657,13 +710,25 @@ os_head_kind() {
|
|
|
657
710
|
# os_tree_ensure BRAIN GLOB [CLASE]
|
|
658
711
|
# Deja declarado el glob en `tree.md` si faltaba. Es la contracara de que los archivos de solo
|
|
659
712
|
# contenido nazcan con su primer dato: el archivo aparece y ningún glob lo alcanza hasta que el
|
|
660
|
-
# comando que lo creó declara su altura. Los globs los mantienen los comandos que crean niveles
|
|
713
|
+
# comando que lo creó declara su altura. Los globs los mantienen los comandos que crean niveles; la
|
|
714
|
+
# única excepción es la lectura de arranque, para el glosario y el mapa de contextos de un espacio
|
|
715
|
+
# de trabajo escritos a mano (spec 072, `session-read.sh`).
|
|
661
716
|
# CLASE es `glob` (default, una cabeza) o `content` (alcanzado, nunca leído como cabeza — spec 007).
|
|
662
717
|
# El manual de usuario entra por `content` (spec 022): se ve en la raíz y no es trabajo.
|
|
663
718
|
# 0 lo agregó 1 ya estaba 2 no hay tree.md que mantener
|
|
719
|
+
# os_tree_line LINE -> "<class><TAB><pattern>" when LINE is a declaration of tree.md (glob, content or
|
|
720
|
+
# archive); 1 otherwise. The one place outside the readers above that knows the three prefixes — a
|
|
721
|
+
# caller that rewrites tree.md line by line (migrate-root.sh) asks here instead of parsing them.
|
|
722
|
+
os_tree_line() {
|
|
723
|
+
case "$1" in
|
|
724
|
+
glob:*|content:*|archive:*) printf '%s\t%s' "${1%%:*}" "$(os_trim "${1#*:}")"; return 0 ;;
|
|
725
|
+
esac
|
|
726
|
+
return 1
|
|
727
|
+
}
|
|
728
|
+
|
|
664
729
|
os_tree_ensure() {
|
|
665
730
|
local brain="$1" glob="$2" clase="${3:-glob}" line g
|
|
666
|
-
[ -f "$brain
|
|
731
|
+
[ -f "$brain/$OS_TREE_FILE" ] || return 2
|
|
667
732
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
668
733
|
case "$line" in
|
|
669
734
|
"$clase":*) ;;
|
|
@@ -671,8 +736,13 @@ os_tree_ensure() {
|
|
|
671
736
|
esac
|
|
672
737
|
g=$(os_trim "${line#$clase:}")
|
|
673
738
|
[ "$g" = "$glob" ] && return 1
|
|
674
|
-
done < "$brain
|
|
675
|
-
|
|
739
|
+
done < "$brain/$OS_TREE_FILE"
|
|
740
|
+
# A tree.md edited by hand can end without a newline: the new line would glue onto the last one
|
|
741
|
+
# and corrupt that declaration (Codex review of spec 072, finding 1).
|
|
742
|
+
if [ -s "$brain/$OS_TREE_FILE" ] && [ -n "$(tail -c 1 "$brain/$OS_TREE_FILE")" ]; then
|
|
743
|
+
printf '\n' >> "$brain/$OS_TREE_FILE"
|
|
744
|
+
fi
|
|
745
|
+
printf '%s: %s\n' "$clase" "$glob" >> "$brain/$OS_TREE_FILE"
|
|
676
746
|
return 0
|
|
677
747
|
}
|
|
678
748
|
|
|
@@ -706,15 +776,40 @@ os_decision_path() {
|
|
|
706
776
|
# date in the name (spec's own criterion: a learning that gets updated does not change its
|
|
707
777
|
# identity), so the same title always resolves to the same file — exit 0 when that file already
|
|
708
778
|
# existed (the caller's cue to update in place instead of writing a fresh header), 1 when it is new.
|
|
779
|
+
#
|
|
780
|
+
# A file is the same learning only if its own title (`title:`, or else its `# Title`) slugifies to the
|
|
781
|
+
# same slug as TITLE: two different titles that land on one name (`Index`, which never takes `index.md`,
|
|
782
|
+
# and `Index 1`) never share a file. The next free name is `<name>-2`, `<name>-3`, and so on, and a
|
|
783
|
+
# file there is the same learning by the same test.
|
|
709
784
|
os_learning_path() {
|
|
710
|
-
local brain="$1" prefix="$2" title="$3" slug rel
|
|
785
|
+
local brain="$1" prefix="$2" title="$3" slug want first cand n rel stored
|
|
711
786
|
slug=$(os_slugify "$title")
|
|
712
787
|
[ -n "$slug" ] || slug="sin-titulo"
|
|
713
788
|
slug=$(os_slug_cap "$slug" 80)
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
789
|
+
want="$slug"
|
|
790
|
+
first="$slug"
|
|
791
|
+
# `index.md` is the generated index of the folder (spec 076, C18): a learning never takes that name.
|
|
792
|
+
[ "$first" = "index" ] && first="index-1"
|
|
793
|
+
cand="$first"
|
|
794
|
+
n=1
|
|
795
|
+
while :; do
|
|
796
|
+
rel="learnings/${cand}.md"
|
|
797
|
+
if [ ! -f "$brain/${prefix}${rel}" ]; then
|
|
798
|
+
printf '%s' "$rel"
|
|
799
|
+
return 1
|
|
800
|
+
fi
|
|
801
|
+
fm_read "$brain/${prefix}${rel}"
|
|
802
|
+
stored="$fm_title"
|
|
803
|
+
[ -n "$stored" ] || stored=$(os_titulo "$brain/${prefix}${rel}")
|
|
804
|
+
stored=$(os_slugify "$stored")
|
|
805
|
+
[ -n "$stored" ] || stored="sin-titulo"
|
|
806
|
+
if [ "$(os_slug_cap "$stored" 80)" = "$want" ]; then
|
|
807
|
+
printf '%s' "$rel"
|
|
808
|
+
return 0
|
|
809
|
+
fi
|
|
810
|
+
n=$(( n + 1 ))
|
|
811
|
+
cand="$first-$n"
|
|
812
|
+
done
|
|
718
813
|
}
|
|
719
814
|
|
|
720
815
|
# os_index_line DATE TITLE REL WHEN -> the one line an index (`decisions.md`/`learnings.md`) carries
|
|
@@ -805,36 +900,256 @@ os_index_mark_superseded() {
|
|
|
805
900
|
[ "$found" = "1" ]
|
|
806
901
|
}
|
|
807
902
|
|
|
903
|
+
# ---------------------------------------------------------------- `about:` names one node or several (spec 076, C16)
|
|
904
|
+
# `about: <path>` names one head; `about: [<path>, <path>]` names several, on a single line, in the
|
|
905
|
+
# order they are read. The key stays optional. These two are the only readers of the list form: the
|
|
906
|
+
# scan validates each value, the focus jumps once per value, the index generator files a document
|
|
907
|
+
# under each node it names and `close-session` copies the focus's value as it is.
|
|
908
|
+
|
|
909
|
+
# os_about_values VALUE -> each path the value names, one per line, in order, trimmed. `[]` names
|
|
910
|
+
# none. An empty item between two commas is printed as an empty line, so a caller that validates
|
|
911
|
+
# reports it instead of skipping it.
|
|
912
|
+
os_about_values() {
|
|
913
|
+
local v="$1" item rest
|
|
914
|
+
case "$v" in
|
|
915
|
+
'['*']')
|
|
916
|
+
rest="${v#\[}"
|
|
917
|
+
rest="${rest%\]}"
|
|
918
|
+
while [ "${rest# }" != "$rest" ]; do rest="${rest# }"; done
|
|
919
|
+
while [ "${rest% }" != "$rest" ]; do rest="${rest% }"; done
|
|
920
|
+
[ -n "$rest" ] || return 0
|
|
921
|
+
while :; do
|
|
922
|
+
case "$rest" in
|
|
923
|
+
*,*) item="${rest%%,*}"; rest="${rest#*,}" ;;
|
|
924
|
+
*) item="$rest"; rest="" ;;
|
|
925
|
+
esac
|
|
926
|
+
while [ "${item# }" != "$item" ]; do item="${item# }"; done
|
|
927
|
+
while [ "${item% }" != "$item" ]; do item="${item% }"; done
|
|
928
|
+
printf '%s\n' "$(os_unquote "$item")"
|
|
929
|
+
[ -n "$rest" ] || break
|
|
930
|
+
done
|
|
931
|
+
;;
|
|
932
|
+
'') return 0 ;;
|
|
933
|
+
*) printf '%s\n' "$(os_unquote "$v")" ;;
|
|
934
|
+
esac
|
|
935
|
+
return 0
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
# os_unquote VALUE -> VALUE without one pair of matching surrounding quotes (`"x"` or `'x'`), the
|
|
939
|
+
# way YAML reads a quoted scalar. The layout migration (`migrate_layout.py`, `unquote`) reads `about:`
|
|
940
|
+
# with the same rule, so both recognise the same standing initiative of a node.
|
|
941
|
+
os_unquote() {
|
|
942
|
+
local v="$1"
|
|
943
|
+
case "$v" in
|
|
944
|
+
\"*\") [ "${#v}" -ge 2 ] && v="${v#\"}" && v="${v%\"}" ;;
|
|
945
|
+
\'*\') [ "${#v}" -ge 2 ] && v="${v#\'}" && v="${v%\'}" ;;
|
|
946
|
+
esac
|
|
947
|
+
printf '%s' "$v"
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
# os_about_names VALUE HEAD -> 0 if one of the paths VALUE names, normalised, is HEAD.
|
|
951
|
+
os_about_names() {
|
|
952
|
+
local v
|
|
953
|
+
while IFS= read -r v || [ -n "$v" ]; do
|
|
954
|
+
[ -n "$v" ] || continue
|
|
955
|
+
[ "$(os_rel_norm "$v")" = "$2" ] && return 0
|
|
956
|
+
done <<VALUES
|
|
957
|
+
$(os_about_values "$1")
|
|
958
|
+
VALUES
|
|
959
|
+
return 1
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
# os_about_set VALUE -> the paths VALUE names, normalised, as one string with a newline before and
|
|
963
|
+
# after each one: a caller that tests membership many times builds it once and matches it with
|
|
964
|
+
# `case "$set" in *"<newline>$head<newline>"*)`, no subshell per test. Empty for no value.
|
|
965
|
+
os_about_set() {
|
|
966
|
+
local v out=""
|
|
967
|
+
while IFS= read -r v || [ -n "$v" ]; do
|
|
968
|
+
[ -n "$v" ] || continue
|
|
969
|
+
out="$out
|
|
970
|
+
$(os_rel_norm "$v")"
|
|
971
|
+
done <<VALUES
|
|
972
|
+
$(os_about_values "$1")
|
|
973
|
+
VALUES
|
|
974
|
+
[ -n "$out" ] && printf '%s\n' "$out"
|
|
975
|
+
return 0
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
# os_about_is_single VALUE HEAD -> 0 if VALUE names HEAD and nothing else: the shape of the standing
|
|
979
|
+
# initiative of a node (spec 076, C30), as opposed to an initiative that is about several nodes.
|
|
980
|
+
os_about_is_single() {
|
|
981
|
+
local n=0 v hit=0
|
|
982
|
+
while IFS= read -r v || [ -n "$v" ]; do
|
|
983
|
+
[ -n "$v" ] || continue
|
|
984
|
+
n=$(( n + 1 ))
|
|
985
|
+
[ "$(os_rel_norm "$v")" = "$2" ] && hit=1
|
|
986
|
+
done <<VALUES
|
|
987
|
+
$(os_about_values "$1")
|
|
988
|
+
VALUES
|
|
989
|
+
[ "$n" = "1" ] && [ "$hit" = "1" ]
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
# ---------------------------------------------------------------- relative links (spec 076, C18)
|
|
993
|
+
# os_rel_link FROM_DIR TO -> TO written relative to FROM_DIR. Both are relative to the brain; FROM_DIR
|
|
994
|
+
# has no trailing slash and is empty for the brain itself. This is what makes a generated index open
|
|
995
|
+
# its lines with one click from Obsidian and from GitHub.
|
|
996
|
+
os_rel_link() {
|
|
997
|
+
local from="$1" to="$2" up=""
|
|
998
|
+
while [ -n "$from" ]; do
|
|
999
|
+
case "$to" in
|
|
1000
|
+
"$from"/*) printf '%s%s' "$up" "${to#"$from"/}"; return 0 ;;
|
|
1001
|
+
esac
|
|
1002
|
+
up="../$up"
|
|
1003
|
+
case "$from" in
|
|
1004
|
+
*/*) from="${from%/*}" ;;
|
|
1005
|
+
*) from="" ;;
|
|
1006
|
+
esac
|
|
1007
|
+
done
|
|
1008
|
+
printf '%s%s' "$up" "$to"
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
# ---------------------------------------------------------------- the index line of a decision or a learning (spec 076, C18)
|
|
1012
|
+
# Decisions and learnings live flat in the workspace (`decisions/`, `learnings/`), one file each, and
|
|
1013
|
+
# every index that lists them is generated from their frontmatter — never from a hand-kept index.
|
|
1014
|
+
# The line is the one the hand-kept index carried (spec 043, 069): date, the key label, the title as
|
|
1015
|
+
# a link, the tail, and the replacement mark at the end:
|
|
1016
|
+
#
|
|
1017
|
+
# - DATE · <key label> · [TITLE](LINK) — <index_note> — **<superseded label>**: [NEW](LINK)
|
|
1018
|
+
#
|
|
1019
|
+
# `date:` gives the date; `title:`, else the body's first `# Title`, else the file name, gives the
|
|
1020
|
+
# title; `key:` with any value but `false` gives the key label; `superseded_by:` gives the mark, with
|
|
1021
|
+
# the title of the file it names; `index_note:` gives the tail. The two labels come from the strings
|
|
1022
|
+
# catalog, so the caller has the catalog loaded.
|
|
1023
|
+
|
|
1024
|
+
# os_doc_is_key VALUE -> 0 if a `key:` value marks the document as key. The decisions of spec 069
|
|
1025
|
+
# carry the reason as free text in the key; the migration writes `true`.
|
|
1026
|
+
os_doc_is_key() {
|
|
1027
|
+
case "$1" in
|
|
1028
|
+
''|false|no) return 1 ;;
|
|
1029
|
+
esac
|
|
1030
|
+
return 0
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
# os_doc_title FILE -> the title an index shows for it: `title:`, the first `# Title`, or the name.
|
|
1034
|
+
# Reads the frontmatter itself: the caller's `fm_*` are overwritten.
|
|
1035
|
+
os_doc_title() {
|
|
1036
|
+
local t base
|
|
1037
|
+
fm_read "$1"
|
|
1038
|
+
t="$fm_title"
|
|
1039
|
+
[ -n "$t" ] || t=$(os_titulo "$1")
|
|
1040
|
+
if [ -z "$t" ]; then
|
|
1041
|
+
base="${1##*/}"
|
|
1042
|
+
t="${base%.md}"
|
|
1043
|
+
fi
|
|
1044
|
+
printf '%s' "$t"
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
# os_doc_index_line BRAIN REL FROM_DIR -> the index line of the document at REL (relative to the
|
|
1048
|
+
# brain), with its links relative to FROM_DIR. Exit 1 when the file is not there.
|
|
1049
|
+
os_doc_index_line() {
|
|
1050
|
+
local brain="$1" rel="$2" from="$3" date key title note sup line sup_title
|
|
1051
|
+
[ -f "$brain/$rel" ] || return 1
|
|
1052
|
+
title=$(os_doc_title "$brain/$rel")
|
|
1053
|
+
fm_read "$brain/$rel"
|
|
1054
|
+
date="$fm_date"; key="$fm_key"; note="$fm_index_note"; sup=$(os_rel_norm "$fm_superseded_by")
|
|
1055
|
+
line="-"
|
|
1056
|
+
[ -n "$date" ] && line="$line $date ·"
|
|
1057
|
+
os_doc_is_key "$key" && line="$line $S_INDEX_KEY_LABEL ·"
|
|
1058
|
+
line="$line [$title]($(os_rel_link "$from" "$rel"))"
|
|
1059
|
+
[ -n "$note" ] && line="$line — $note"
|
|
1060
|
+
if [ -n "$sup" ]; then
|
|
1061
|
+
if [ -f "$brain/$sup" ]; then sup_title=$(os_doc_title "$brain/$sup"); else sup_title="${sup##*/}"; fi
|
|
1062
|
+
line="$line — **$S_INDEX_SUPERSEDED_LABEL**: [$sup_title]($(os_rel_link "$from" "$sup"))"
|
|
1063
|
+
fi
|
|
1064
|
+
printf '%s' "$line"
|
|
1065
|
+
return 0
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
# os_doc_superseded -> 0 if the document `fm_read` just read is replaced: `superseded_by:` (spec 046)
|
|
1069
|
+
# or MADR's `status: superseded by ...` (spec 070), which `os_decision_mark_superseded` writes together.
|
|
1070
|
+
os_doc_superseded() {
|
|
1071
|
+
[ -n "$fm_superseded_by" ] && return 0
|
|
1072
|
+
case "$fm_status" in superseded*) return 0 ;; esac
|
|
1073
|
+
return 1
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
# os_docs_sorted BRAIN DIR_REL -> the `.md` files of that folder (never its generated `index.md`),
|
|
1077
|
+
# relative to the brain, newest `date:` first; same date, by path. An undated file goes last.
|
|
1078
|
+
os_docs_sorted() {
|
|
1079
|
+
local brain="$1" dir="$2" f rel tab
|
|
1080
|
+
tab=$(printf '\tx'); tab="${tab%x}"
|
|
1081
|
+
[ -d "$brain/$dir" ] || return 0
|
|
1082
|
+
for f in "$brain/$dir"/*.md; do
|
|
1083
|
+
[ -f "$f" ] || continue
|
|
1084
|
+
rel="${f#"$brain"/}"
|
|
1085
|
+
[ "${rel##*/}" = "index.md" ] && continue
|
|
1086
|
+
fm_read "$f"
|
|
1087
|
+
printf '%s\t%s\n' "${fm_date:-0000-00-00}" "$rel"
|
|
1088
|
+
done | LC_ALL=C sort -t "$tab" -k1,1r -k2,2 | while IFS="$tab" read -r _d rel; do
|
|
1089
|
+
printf '%s\n' "$rel"
|
|
1090
|
+
done
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
# os_key_decisions BRAIN WS_REL [NODE_HEAD] -> the key decisions of a workspace (spec 076, C19), one
|
|
1094
|
+
# index line each, links relative to its `decisions/`, newest first. Without NODE_HEAD: the key ones,
|
|
1095
|
+
# not replaced, with no `about:` — what the startup read loads. With it: the key ones, not replaced,
|
|
1096
|
+
# whose `about:` names that head — what the focus loads for that node. Read from the frontmatter of
|
|
1097
|
+
# each decision, never from an index. Nothing for a workspace without any.
|
|
1098
|
+
os_key_decisions() {
|
|
1099
|
+
local brain="$1" ws="$2" node="${3:-}" rel
|
|
1100
|
+
while IFS= read -r rel || [ -n "$rel" ]; do
|
|
1101
|
+
[ -n "$rel" ] || continue
|
|
1102
|
+
fm_read "$brain/$rel"
|
|
1103
|
+
[ -z "$fm_roto" ] || continue
|
|
1104
|
+
os_doc_is_key "$fm_key" || continue
|
|
1105
|
+
os_doc_superseded && continue
|
|
1106
|
+
if [ -z "$node" ]; then
|
|
1107
|
+
[ -z "$fm_about" ] || continue
|
|
1108
|
+
else
|
|
1109
|
+
os_about_names "$fm_about" "$node" || continue
|
|
1110
|
+
fi
|
|
1111
|
+
os_doc_index_line "$brain" "$rel" "$ws/decisions"
|
|
1112
|
+
printf '\n'
|
|
1113
|
+
done <<DOCS
|
|
1114
|
+
$(os_docs_sorted "$brain" "$ws/decisions")
|
|
1115
|
+
DOCS
|
|
1116
|
+
return 0
|
|
1117
|
+
}
|
|
1118
|
+
|
|
808
1119
|
# os_buscar_oficio BRAIN SLUG -> la ruta del archivo con `command: SLUG`, relativa al brain, por
|
|
809
1120
|
# stdout. Exit 0 si lo encontró, 1 si no. Único buscador (spec 009): la mitad negativa del arranque
|
|
810
1121
|
# de sesión (el aviso "capacidad no instalada") y la positiva (nombrar la ruta del oficio activo)
|
|
811
1122
|
# leen del mismo lugar — dos copias de este recorrido se desincronizan la primera vez que cambie
|
|
812
1123
|
# dónde vive un oficio.
|
|
813
1124
|
#
|
|
814
|
-
# Busca en `.os/core/skills`, `.os/packs/*/skills` y
|
|
815
|
-
# `
|
|
816
|
-
#
|
|
817
|
-
#
|
|
1125
|
+
# Busca en `.os/core/skills`, `.os/packs/*/skills` y después en las carpetas de skills del brain
|
|
1126
|
+
# (`OS_SKILL_DIRS`: `.agents/skills` primero, `.claude/skills` después; spec 076, C10), la marca en
|
|
1127
|
+
# primera columna: `command: SLUG` en el frontmatter de un `.md`, `# command: SLUG` en un script — el
|
|
1128
|
+
# mismo vocabulario que declara un invocable en toda la arquitectura. Se queda con el primer archivo
|
|
1129
|
+
# que matchea, así que una skill presente en las dos carpetas de skills se encuentra una sola vez.
|
|
818
1130
|
#
|
|
819
|
-
#
|
|
820
|
-
# y ahí la marca del formato Agent Skills es `name:`, no `command:` — el
|
|
821
|
-
# escribe desde el mismo `command:` del fuente. Sin este origen, un `role:`
|
|
822
|
-
# se reporta como capacidad no instalada con el oficio instalado al lado.
|
|
1131
|
+
# Las carpetas de skills del brain son donde el CLI de skills.sh deja un pack bajado por
|
|
1132
|
+
# `npx skills add` (spec 026), y ahí la marca del formato Agent Skills es `name:`, no `command:` — el
|
|
1133
|
+
# generador del release la escribe desde el mismo `command:` del fuente. Sin este origen, un `role:`
|
|
1134
|
+
# de un oficio del pack se reporta como capacidad no instalada con el oficio instalado al lado.
|
|
823
1135
|
#
|
|
824
1136
|
# La coincidencia es sin distinción de mayúsculas (spec personal-os#014, Gate 1): `role: CPO` en el
|
|
825
1137
|
# nodo activa `command: cpo` del oficio. El slug canónico del archivo sigue siendo minúscula; acá
|
|
826
1138
|
# se normaliza el slug de entrada con `os_lower` y se busca con `grep -i`.
|
|
827
1139
|
os_buscar_oficio() {
|
|
828
|
-
local brain="$1" slug="$2" d f rel slug_lc marca
|
|
1140
|
+
local brain="$1" slug="$2" d f rel slug_lc marca sd
|
|
1141
|
+
local -a dirs
|
|
829
1142
|
slug_lc=$(os_lower "$slug")
|
|
830
|
-
|
|
1143
|
+
dirs=("$brain/.os/core/skills" "$brain"/.os/packs/*/skills)
|
|
1144
|
+
for sd in $OS_SKILL_DIRS; do dirs+=("$brain/$sd"); done
|
|
1145
|
+
for d in "${dirs[@]}"; do
|
|
831
1146
|
[ -d "$d" ] || continue
|
|
832
1147
|
# La marca depende del origen, no del archivo: `name:` solo se acepta donde el formato es el del
|
|
833
1148
|
# CLI. Aceptarla en todos lados volvería invocable cualquier frontmatter con esa clave.
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
1149
|
+
marca="^(# )?command: $slug_lc\$"
|
|
1150
|
+
for sd in $OS_SKILL_DIRS; do
|
|
1151
|
+
[ "$d" = "$brain/$sd" ] && marca="^(# )?name: $slug_lc\$"
|
|
1152
|
+
done
|
|
838
1153
|
while IFS= read -r f; do
|
|
839
1154
|
[ -n "$f" ] || continue
|
|
840
1155
|
if grep -qiE "$marca" "$f"; then
|
|
@@ -843,27 +1158,51 @@ os_buscar_oficio() {
|
|
|
843
1158
|
return 0
|
|
844
1159
|
fi
|
|
845
1160
|
done <<FILES
|
|
846
|
-
$(find "$d" -type f | sort)
|
|
1161
|
+
$(find -L "$d" -type f 2>/dev/null | sort)
|
|
847
1162
|
FILES
|
|
848
1163
|
done
|
|
849
1164
|
return 1
|
|
850
1165
|
}
|
|
851
1166
|
|
|
1167
|
+
# os_skill_resolver_indexes BRAIN -> the pack indexes the brain has installed, one path per line,
|
|
1168
|
+
# relative to the brain: `<skills-dir>/<pack>-resolver/SKILL.md` for each folder of `OS_SKILL_DIRS`
|
|
1169
|
+
# that exists, in lookup order (spec 076, C10). A pack present in both folders —the link that
|
|
1170
|
+
# `npx skills add` leaves in `.claude/skills`— counts once, under the first folder. The glob of the
|
|
1171
|
+
# shell, never `find`: the CLI leaves the pack index as a symlinked folder, and pathname expansion
|
|
1172
|
+
# follows it.
|
|
1173
|
+
os_skill_resolver_indexes() {
|
|
1174
|
+
local brain="$1" sd f name seen="" nl
|
|
1175
|
+
nl=$(printf '\nx'); nl="${nl%x}"
|
|
1176
|
+
for sd in $OS_SKILL_DIRS; do
|
|
1177
|
+
[ -d "$brain/$sd" ] || continue
|
|
1178
|
+
for f in "$brain/$sd"/*-resolver/SKILL.md; do
|
|
1179
|
+
[ -f "$f" ] || continue
|
|
1180
|
+
name=$(basename "$(dirname "$f")")
|
|
1181
|
+
case "$nl$seen" in *"$nl$name$nl"*) continue ;; esac
|
|
1182
|
+
seen="$seen$name$nl"
|
|
1183
|
+
printf '%s\n' "${f#$brain/}"
|
|
1184
|
+
done
|
|
1185
|
+
done
|
|
1186
|
+
return 0
|
|
1187
|
+
}
|
|
1188
|
+
|
|
852
1189
|
# os_pack_hint BRAIN -> el ofrecimiento del pack en una línea, o vacío.
|
|
853
1190
|
# La demanda dispara la oferta (spec 029): cuando algo pide una capacidad que no está y en el brain
|
|
854
1191
|
# no hay ningún skill instalado por el CLI, lo que falta puede ser justamente lo que trae el pack, y
|
|
855
1192
|
# el aviso lleva el comando al lado en vez de dejar al operador buscándolo.
|
|
856
1193
|
#
|
|
857
|
-
# Con algo ya instalado en
|
|
858
|
-
# otro problema — ofrecer una instalación hecha es ruido en cada arranque.
|
|
1194
|
+
# Con algo ya instalado en las carpetas de skills no se ofrece nada: ahí el pack está, y lo que falte
|
|
1195
|
+
# es otro problema — ofrecer una instalación hecha es ruido en cada arranque.
|
|
859
1196
|
#
|
|
860
1197
|
# El comando exacto lo imprime `pack-install.sh --line`, único lugar donde el generador inyecta el
|
|
861
1198
|
# nombre del repo del pack. Sin ese archivo —un brain instalado desde una versión anterior— la
|
|
862
1199
|
# función no dice nada: un aviso que no puede nombrar el comando no agrega información.
|
|
863
1200
|
os_pack_hint() {
|
|
864
|
-
local brain="$1" d linea
|
|
865
|
-
for
|
|
866
|
-
|
|
1201
|
+
local brain="$1" d sd linea
|
|
1202
|
+
for sd in $OS_SKILL_DIRS; do
|
|
1203
|
+
for d in "$brain/$sd"/*/SKILL.md; do
|
|
1204
|
+
[ -f "$d" ] && return 0
|
|
1205
|
+
done
|
|
867
1206
|
done
|
|
868
1207
|
[ -x "$brain/.os/core/lib/pack-install.sh" ] || return 0
|
|
869
1208
|
linea=$("$brain/.os/core/lib/pack-install.sh" --brain "$brain" --line 2>/dev/null) || return 0
|
|
@@ -1106,6 +1445,80 @@ FILES
|
|
|
1106
1445
|
printf 'tsk-%03d' "$(( max + 1 ))"
|
|
1107
1446
|
}
|
|
1108
1447
|
|
|
1448
|
+
# The slug of a workspace's initiative for tasks that belong to no other (spec 076, Gate 1 P9). Its
|
|
1449
|
+
# title comes from the strings catalog (`TASKS_TO_SORT_TITLE`), in the language of the brain.
|
|
1450
|
+
OS_TASKS_TO_SORT_SLUG="tasks-to-sort"
|
|
1451
|
+
|
|
1452
|
+
# os_operator_name BRAIN -> the operator's name: the first `# Title` of `account/operator.md`.
|
|
1453
|
+
os_operator_name() {
|
|
1454
|
+
os_titulo "$1/$OS_OPERATOR_FILE"
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
# os_ini_render TITLE STATUS ABOUT OWNER DATE -> the text of the head of a new initiative, on stdout:
|
|
1458
|
+
# the same frontmatter a standing initiative already carries in a real brain (`status`, `owner` when
|
|
1459
|
+
# given, `horizon: later`, `about` when given, `updated`) and its title. The one place that shape is
|
|
1460
|
+
# written: `os_ini_create` writes it to disk, and the layout migration (`migrate_layout.py`) calls it
|
|
1461
|
+
# to plan the initiatives it creates, so the two can never differ.
|
|
1462
|
+
os_ini_render() {
|
|
1463
|
+
local title="$1" status="$2" about="$3" owner="$4" day="$5"
|
|
1464
|
+
printf -- '---\n'
|
|
1465
|
+
printf 'status: %s\n' "$status"
|
|
1466
|
+
[ -n "$owner" ] && printf 'owner: %s\n' "$owner"
|
|
1467
|
+
printf 'horizon: later\n'
|
|
1468
|
+
[ -n "$about" ] && printf 'about: %s\n' "$about"
|
|
1469
|
+
printf 'updated: %s\n' "$day"
|
|
1470
|
+
printf -- '---\n\n'
|
|
1471
|
+
printf '# %s\n' "$title"
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
# os_ini_create BRAIN PREFIX SLUG TITLE STATUS [ABOUT] — writes the head of a new initiative
|
|
1475
|
+
# (`os_ini_render`, owned by the operator, dated today). Never overwrites: exit 1 if the head is
|
|
1476
|
+
# already there. Its callers (spec 076) are `capture --about --create`, after the operator said
|
|
1477
|
+
# yes, and the workspace's `tasks-to-sort`, where the system files its own pending steps. Only the
|
|
1478
|
+
# new form (a folder per initiative) is written.
|
|
1479
|
+
os_ini_create() {
|
|
1480
|
+
local brain="$1" prefix="$2" slug="$3" title="$4" status="$5" about="${6:-}" rel
|
|
1481
|
+
rel=$(os_ini_head_rel "$brain" "$prefix" "$slug")
|
|
1482
|
+
[ -e "$brain/$rel" ] && return 1
|
|
1483
|
+
mkdir -p "$(dirname "$brain/$rel")" || return 1
|
|
1484
|
+
os_ini_render "$title" "$status" "$about" "$(os_operator_name "$brain")" "$(date +%Y-%m-%d)" \
|
|
1485
|
+
> "$brain/$rel" || return 1
|
|
1486
|
+
return 0
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
# os_personal_backlog_append BRAIN TASK — the one write of a task that the system does for itself, and
|
|
1490
|
+
# only after the operator's yes (spec 076, final Gate 2): `pack-install.sh --defer --note` and
|
|
1491
|
+
# `remote-backup.sh --note`; without `--note` both ask «¿Te lo anoto para después?» and write nothing. A
|
|
1492
|
+
# pending step of the system itself (installing the skill pack, setting up the remote backup),
|
|
1493
|
+
# written by a deterministic script with no model in between that could name an initiative (spec
|
|
1494
|
+
# 057, delegated decision). Since spec 076 (C29) no tool writes a `backlog.md` outside an initiative:
|
|
1495
|
+
# the step lands in the backlog of the `tasks-to-sort` initiative of the `personal` workspace —the
|
|
1496
|
+
# initiative Gate 1 (P9) set for the tasks of a workspace that fit no other—, born here with its
|
|
1497
|
+
# first task when it is not there. An existing `tasks-to-sort` is reused only if it has no `about:`.
|
|
1498
|
+
# Same line format and same brain-wide counter as `capture`.
|
|
1499
|
+
# 0 written 1 the same task was already there 2 the `personal` workspace does not
|
|
1500
|
+
# exist (a brain born before spec 059 and not migrated yet) — nothing written 3 the
|
|
1501
|
+
# `tasks-to-sort` slug is taken by an initiative that is about a node — nothing written
|
|
1502
|
+
os_personal_backlog_append() {
|
|
1503
|
+
local brain="$1" task="$2" wsdir prefix slug="$OS_TASKS_TO_SORT_SLUG" file id
|
|
1504
|
+
wsdir=$(os_ws_dir "$brain")
|
|
1505
|
+
prefix="$wsdir/$OS_PERSONAL_WORKSPACE_SLUG/"
|
|
1506
|
+
[ -d "$brain/$prefix" ] || return 2
|
|
1507
|
+
if os_ini_existe "$brain" "$prefix" "$slug"; then
|
|
1508
|
+
fm_read "$brain/$(os_ini_head_rel "$brain" "$prefix" "$slug")"
|
|
1509
|
+
[ -z "$fm_about" ] || return 3
|
|
1510
|
+
else
|
|
1511
|
+
os_lang_load "$(os_language "$brain")" > /dev/null 2>&1
|
|
1512
|
+
os_ini_create "$brain" "$prefix" "$slug" "$S_TASKS_TO_SORT_TITLE" active || return 3
|
|
1513
|
+
fi
|
|
1514
|
+
file="$brain/$(os_ini_backlog_rel "$prefix" "$slug")"
|
|
1515
|
+
if [ -f "$file" ] && grep -qF -- "$task" "$file"; then return 1; fi
|
|
1516
|
+
os_ini_backlog_asegurar "$brain" "$prefix" "$slug" || true
|
|
1517
|
+
id=$(os_backlog_next_id "$brain")
|
|
1518
|
+
printf '%s\n' "$(os_backlog_linea "$id" "$task" "" "" "" "0" "$(date +%Y-%m-%d)")" >> "$file"
|
|
1519
|
+
return 0
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1109
1522
|
# ---------------------------------------------------------------- el nombre de la carpeta (spec 039)
|
|
1110
1523
|
# El código sigue diciendo "org" —la variable, la opción `--org`, `os_org_slugs`, `os_org_existe`,
|
|
1111
1524
|
# `OS_ORG_PROPIOS`— porque nada de eso lo ve el operador (P3): renombrarlo agrandaría el diff sin
|
|
@@ -1118,7 +1531,7 @@ FILES
|
|
|
1118
1531
|
# `workspaces` — el nombre de nacimiento. Nunca aborta: solo imprime. Un layout inválido lo detecta
|
|
1119
1532
|
# `os_ws_check`, aparte.
|
|
1120
1533
|
os_ws_dir() {
|
|
1121
|
-
local tree="$1
|
|
1534
|
+
local tree="$1/$OS_TREE_FILE" line
|
|
1122
1535
|
[ -f "$tree" ] || { printf 'workspaces'; return 0; }
|
|
1123
1536
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
1124
1537
|
case "$line" in
|
|
@@ -1182,7 +1595,7 @@ os_ws_check() {
|
|
|
1182
1595
|
# quien solo quiera el nombre tiene que absorberlo (`|| true`), o `set -e` mata al script en la
|
|
1183
1596
|
# asignación.
|
|
1184
1597
|
os_head_file() {
|
|
1185
|
-
local brain="$1" tree="$1
|
|
1598
|
+
local brain="$1" tree="$1/$OS_TREE_FILE" line g base wsdir ws_head="" ini_forma=""
|
|
1186
1599
|
[ -f "$tree" ] || { printf 'README.md'; return 2; }
|
|
1187
1600
|
wsdir=$(os_ws_dir "$brain")
|
|
1188
1601
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
@@ -1380,7 +1793,7 @@ os_replace_file() {
|
|
|
1380
1793
|
# archivo ya existe es la peor de las dos.
|
|
1381
1794
|
os_tree_class_matches() {
|
|
1382
1795
|
local brain="$1" clase="$2" ruta="$3" line g
|
|
1383
|
-
[ -f "$brain
|
|
1796
|
+
[ -f "$brain/$OS_TREE_FILE" ] || return 1
|
|
1384
1797
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
1385
1798
|
case "$line" in
|
|
1386
1799
|
"$clase":*) ;;
|
|
@@ -1389,7 +1802,7 @@ os_tree_class_matches() {
|
|
|
1389
1802
|
g=$(os_trim "${line#$clase:}")
|
|
1390
1803
|
[ -n "$g" ] || continue
|
|
1391
1804
|
os_glob_path_match "$g" "$ruta" && return 0
|
|
1392
|
-
done < "$brain
|
|
1805
|
+
done < "$brain/$OS_TREE_FILE"
|
|
1393
1806
|
return 1
|
|
1394
1807
|
}
|
|
1395
1808
|
|
|
@@ -1647,7 +2060,7 @@ os_backticks() {
|
|
|
1647
2060
|
# por forma, no por posición**: separador es toda línea de `|`, `-`, `:` y blancos, y cabecera es la
|
|
1648
2061
|
# línea que precede a un separador. Con la primera tabla ubicada por posición, una segunda tabla
|
|
1649
2062
|
# reportaba su cabecera como fila ilegible — un formato canónico que se declaraba roto a sí mismo.
|
|
1650
|
-
OS_MOUNTS_ARCHIVO="mounts.md"
|
|
2063
|
+
OS_MOUNTS_ARCHIVO="$OS_SYSTEM_DIR/mounts.md"
|
|
1651
2064
|
|
|
1652
2065
|
# os_mounts_filas ARCHIVO -> una línea por fila de datos: `N<OS_SEP>remote<OS_SEP>ruta`.
|
|
1653
2066
|
# Con remote o ruta vacíos, la fila es ilegible: quien llama la declara con su número de línea, nunca
|