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
@@ -4,12 +4,12 @@
4
4
  #
5
5
  # Usage: new-memory.sh --brain DIR --org SLUG --type TYPE --name NAME --owner PERSON
6
6
  # [--slug SLUG] [--identity-file FILE]
7
- # new-memory.sh --brain DIR --root --type TYPE --name NAME --owner PERSON
8
- # [--slug SLUG] [--identity-file FILE]
9
7
  # `--workspace` is an exact synonym of `--org` (spec 039), same as every other command that takes a
10
- # workspace. `--root` and `--org`/`--workspace` are mutually exclusive, same rule `session-start.sh`
11
- # already uses (spec 018/041): a flag, never a reserved value, so an operator can still name a
12
- # workspace "root" without colliding.
8
+ # workspace.
9
+ #
10
+ # `--root` no longer creates anything (spec 059): the root of the brain is machinery only, and a
11
+ # memory node is content. The flag is still accepted, only to refuse with an error that names the
12
+ # operator's own workspace (`personal`) as the destination — never silently "unknown argument".
13
13
  #
14
14
  # The carrier of "what kind of thing this is" is the folder, never a field (spec 041 decision): the
15
15
  # TYPE argument is the name of the sibling folder — `products`, `accounts`, `channels`, or one the
@@ -19,8 +19,7 @@
19
19
  # A memory node is memory — what it is, what is known — never state: it never gets `role:` (that
20
20
  # activates an oficio per organization, spec 009) and never `repo:` (mount-repo writes that once a
21
21
  # body exists, and mount-repo mounts onto an initiative, never onto a memory node). Only the head is
22
- # born here: `context/`, `resolver.md` and `decisions.md` are born with their first piece of data,
23
- # same as every other canonical file in this product.
22
+ # born here (spec 076, C15): no resolver and no decisions of its own.
24
23
 
25
24
  set -eu
26
25
 
@@ -60,10 +59,9 @@ fi
60
59
 
61
60
  [ -n "$brain" ] || os_die "falta --brain"
62
61
  if [ "$root" = "1" ]; then
63
- [ -z "$org" ] || os_die "--root y --org/--workspace son excluyentes"
64
- else
65
- [ -n "$org" ] || os_die "falta --org, --workspace o --root"
62
+ os_die "--root ya no crea nada (spec 059): la raíz solo tiene maquinaria — usá --org $OS_PERSONAL_WORKSPACE_SLUG o --workspace $OS_PERSONAL_WORKSPACE_SLUG, el espacio de trabajo propio del operador"
66
63
  fi
64
+ [ -n "$org" ] || os_die "falta --org o --workspace"
67
65
  [ -n "$type" ] || os_die "falta --type"
68
66
  case "$type" in
69
67
  */*|.|..) os_die "--type inválido: $type" ;;
@@ -81,38 +79,30 @@ wsdir=$(os_ws_dir "$brain")
81
79
  language=$(os_language "$brain")
82
80
  os_lang_load "$language"
83
81
 
84
- if [ "$root" = "0" ]; then
85
- # El ámbito se valida contra el listado real de la carpeta de espacios de trabajo, byte a byte —
86
- # mismo criterio que `session-start.sh` (spec 002/003): sin el espacio de trabajo, el comando no
87
- # escribe nada y lista los que hay, con el mismo par de claves del catálogo que ya usa el arranque
88
- # de sesión.
89
- if ! os_org_existe "$brain" "$org"; then
90
- printf "$S_SESSION_ORG_NOT_FOUND\n" "$org" >&2
91
- found=0
92
- while IFS= read -r s || [ -n "$s" ]; do
93
- [ -n "$s" ] || continue
94
- found=1
95
- printf ' %s\n' "$s" >&2
96
- done <<SLUGS
82
+ # El ámbito se valida contra el listado real de la carpeta de espacios de trabajo, byte a byte —
83
+ # mismo criterio que `session-start.sh` (spec 002/003): sin el espacio de trabajo, el comando no
84
+ # escribe nada y lista los que hay, con el mismo par de claves del catálogo que ya usa el arranque
85
+ # de sesión.
86
+ if ! os_org_existe "$brain" "$org"; then
87
+ printf "$S_SESSION_ORG_NOT_FOUND\n" "$org" >&2
88
+ found=0
89
+ while IFS= read -r s || [ -n "$s" ]; do
90
+ [ -n "$s" ] || continue
91
+ found=1
92
+ printf ' %s\n' "$s" >&2
93
+ done <<SLUGS
97
94
  $(os_org_slugs "$brain")
98
95
  SLUGS
99
- [ "$found" = "1" ] || printf ' %s\n' "$S_SESSION_NO_ORGS" >&2
100
- exit 2
101
- fi
96
+ [ "$found" = "1" ] || printf ' %s\n' "$S_SESSION_NO_ORGS" >&2
97
+ exit 2
102
98
  fi
103
99
 
104
100
  [ -n "$slug" ] || slug=$(os_slugify "$name")
105
101
  [ -n "$slug" ] || os_die "el nombre no produce un slug utilizable: $name"
106
102
 
107
- if [ "$root" = "1" ]; then
108
- dir="$brain/$type/$slug"
109
- rel="$type/$slug"
110
- tree_prefix=""
111
- else
112
- dir="$brain/$wsdir/$org/$type/$slug"
113
- rel="$wsdir/$org/$type/$slug"
114
- tree_prefix="$wsdir/*/"
115
- fi
103
+ dir="$brain/$wsdir/$org/$type/$slug"
104
+ rel="$wsdir/$org/$type/$slug"
105
+ tree_prefix="$wsdir/*/"
116
106
  if [ -e "$dir" ]; then
117
107
  os_die "ya existe: $rel"
118
108
  fi
@@ -144,17 +134,16 @@ os_render_lang "$templates/README.md" "$language" \
144
134
 
145
135
  os_check_identity_cap "$dir/$head"
146
136
 
147
- # Un tipo declara 5 líneas del árbol (spec 041 decisión cerrada): mismo reparto que `products/` ya
148
- # usaba — 3 `glob:` (cabeza, resolver.md, decisions.md) y 2 `content:` (context/*.md, research/*.md)
149
- # — a la altura del espacio de trabajo o de la raíz. La 043 suma una sexta: el cuerpo de las
150
- # decisiones, alcanzado y nunca leído como cabeza, mismo criterio que las otras dos `content:`.
151
- # Idempotente vía `os_tree_ensure`, así que sumar un segundo nodo al mismo tipo (mismo `--type`,
152
- # otro `--slug`) no duplica ninguna línea.
137
+ # The lines of a type (spec 041, revised by spec 076): the head and the hidden `.resolver.md` as
138
+ # `glob:`, and as `content:` the generated `index.md` plus `context/`, `research/` and `resources/`.
139
+ # No `decisions.md` or `decisions/` of its own: decisions live flat in the workspace with `about:`
140
+ # (C17). Idempotent through `os_tree_ensure`, so a second node of the same type duplicates nothing.
153
141
  os_tree_ensure "$brain" "${tree_prefix}${type}/*/$head" || true
154
- os_tree_ensure "$brain" "${tree_prefix}${type}/*/resolver.md" || true
155
- os_tree_ensure "$brain" "${tree_prefix}${type}/*/decisions.md" || true
156
- os_tree_ensure "$brain" "${tree_prefix}${type}/*/decisions/*.md" content || true
142
+ os_tree_ensure "$brain" "${tree_prefix}${type}/*/.resolver.md" || true
143
+ os_tree_ensure "$brain" "${tree_prefix}${type}/*/index.md" content || true
157
144
  os_tree_ensure "$brain" "${tree_prefix}${type}/*/context/*.md" content || true
158
145
  os_tree_ensure "$brain" "${tree_prefix}${type}/*/research/*.md" content || true
146
+ os_tree_ensure "$brain" "${tree_prefix}${type}/*/resources/*.md" content || true
147
+ os_tree_ensure "$brain" "${tree_prefix}${type}/*/resources/*/*.md" content || true
159
148
 
160
149
  printf '%s — %s\n' "$rel" "$head"
@@ -9,8 +9,7 @@
9
9
  # A product node is memory — what it is, for whom, what is known — never state: it never gets
10
10
  # `role:` (that activates an oficio per organization, spec 009) and never `repo:` (mount-repo writes
11
11
  # that once a body exists, and mount-repo mounts onto an initiative, never onto a product). Only the
12
- # head is born here: `context/`, `resolver.md` and `decisions.md` are born with their first piece of
13
- # data, same as every other canonical file in this product.
12
+ # head is born here (spec 076, C15): no resolver and no decisions of its own.
14
13
 
15
14
  set -eu
16
15
 
@@ -104,19 +103,18 @@ os_render_lang "$templates/README.md" "$language" \
104
103
 
105
104
  os_check_identity_cap "$dir/$head"
106
105
 
107
- # Los tres globs del nivel llegan de fábrica en `core/templates/tree.md`; acá se agregan a un brain
108
- # que ya existía antes de esta spec, sin duplicar (mismo patrón que `capture.sh`/`close-session.sh`
109
- # con los archivos que nacen con su primer dato).
106
+ # The lines of the level ship in `core/templates/tree.md`; here they are added to a brain that
107
+ # predates them, without duplicating (same pattern as every command that creates a level). A node is
108
+ # born with its head and nothing else (spec 076, C15): `.resolver.md` exists only when the node has a
109
+ # row to route outside its folder (D9), and decisions live flat in the workspace (C17), never inside
110
+ # a node. `index.md` is the one the startup read generates (C18); `context/`, `research/` and
111
+ # `resources/` are born with their first document and are content, never a head.
110
112
  os_tree_ensure "$brain" "$wsdir/*/products/*/$head" || true
111
- os_tree_ensure "$brain" "$wsdir/*/products/*/resolver.md" || true
112
- os_tree_ensure "$brain" "$wsdir/*/products/*/decisions.md" || true
113
- # El cuerpo de esa pregunta, uno por decisión: alcanzado, nunca leído como cabeza (spec 043).
114
- os_tree_ensure "$brain" "$wsdir/*/products/*/decisions/*.md" content || true
115
-
116
- # Las dos carpetas de un producto nacen con su primer dato y son contenido, nunca cabeza: `context/`
117
- # es la capa estratégica y `research/` todo documento fechado (spec 040). Se declaran acá para que el
118
- # primer archivo que el operador escriba adentro no aparezca como "ningún glob alcanza".
113
+ os_tree_ensure "$brain" "$wsdir/*/products/*/.resolver.md" || true
114
+ os_tree_ensure "$brain" "$wsdir/*/products/*/index.md" content || true
119
115
  os_tree_ensure "$brain" "$wsdir/*/products/*/context/*.md" content || true
120
116
  os_tree_ensure "$brain" "$wsdir/*/products/*/research/*.md" content || true
117
+ os_tree_ensure "$brain" "$wsdir/*/products/*/resources/*.md" content || true
118
+ os_tree_ensure "$brain" "$wsdir/*/products/*/resources/*/*.md" content || true
121
119
 
122
120
  printf '%s/%s/products/%s — %s\n' "$wsdir" "$org" "$slug" "$head"
@@ -71,7 +71,12 @@ fi
71
71
  templates="$here/../templates/node-folder"
72
72
  today=$(date +%Y-%m-%d)
73
73
 
74
- mkdir -p "$dir/initiatives"
74
+ # The workspace is born with its head, its hidden resolver and the three folders where its work
75
+ # lives (spec 076, C13): `initiatives/`, `decisions/` (one file per decision) and `learnings/` (one
76
+ # file per learning). Nothing else: `context/` is born with its first `glossary.md` or
77
+ # `context-map.md`, `resources/` with its first file, and `products/`, `courses/`, `channels/` and
78
+ # `accounts/` with their first node (D14).
79
+ mkdir -p "$dir/initiatives" "$dir/decisions" "$dir/learnings"
75
80
 
76
81
  # El nombre de la cabeza es dato del brain (spec 040): la forma nueva es `README.md` y un brain que
77
82
  # todavía no la adoptó recibe su nodo nuevo en la forma que ya tiene — mezclar las dos en el mismo
@@ -80,7 +85,8 @@ head=$(os_head_file "$brain") || true
80
85
  os_render_lang "$templates/README.md" "$language" \
81
86
  "NAME=$name" "ROLE=$role" "TITLE=$title" "OWNER=$owner" "DATE=$today" "IDENTITY=$identity" \
82
87
  > "$dir/$head"
83
- os_render_lang "$templates/resolver.md" "$language" "NAME=$name" > "$dir/resolver.md"
88
+ # Hidden (D9): only the system reads it, and Obsidian does not show a file that starts with a dot.
89
+ os_render_lang "$templates/resolver.md" "$language" "NAME=$name" > "$dir/.resolver.md"
84
90
 
85
91
  os_check_identity_cap "$dir/$head"
86
92
 
@@ -89,17 +95,20 @@ os_check_identity_cap "$dir/$head"
89
95
  # la raíz— se quedaba con el nodo nuevo sin que ningún glob lo alcanzara: escrito y ciego para todo
90
96
  # barrido. Los brains que ya la declaran no cambian: `os_tree_ensure` no duplica.
91
97
  os_tree_ensure "$brain" "$wsdir/*/$head" || true
92
- os_tree_ensure "$brain" "$wsdir/*/resolver.md" || true
93
- os_tree_ensure "$brain" "$wsdir/*/backlog.md" || true
94
- os_tree_ensure "$brain" "$wsdir/*/decisions.md" || true
95
- os_tree_ensure "$brain" "$wsdir/*/learnings.md" || true
96
- # Los cuerpos de esas dos preguntas, uno por decisión y por aprendizaje: alcanzados, nunca leídos
97
- # como cabeza (spec 043 — misma clase `content:` que ya usa `context/`/`research/`).
98
+ os_tree_ensure "$brain" "$wsdir/*/.resolver.md" || true
99
+ # One file per decision and per learning, flat in the workspace (spec 076, C17): reached, never read
100
+ # as a head. Their indexes are generated (`decisions/index.md`, `learnings/index.md`) and these same
101
+ # lines reach them.
98
102
  os_tree_ensure "$brain" "$wsdir/*/decisions/*.md" content || true
99
103
  os_tree_ensure "$brain" "$wsdir/*/learnings/*.md" content || true
100
104
  # La altura de las iniciativas de ese nodo, en la forma que el brain tenga para esa altura: el
101
105
  # glob sale del mismo helper que arma la ruta de una cabeza, con `*` en lugar del slug.
102
106
  os_tree_ensure "$brain" "$wsdir/*/$(os_head_path "$brain" initiative '*')" || true
103
107
  os_tree_ensure "$brain" "$wsdir/*/initiatives/*/*.md" content || true
108
+ # The workspace's glossary and map of contexts (spec 072) live in `context/` (spec 076, C14), and its
109
+ # brand —the voice, the visual style— in `resources/`: reached so `recall` indexes them.
110
+ os_tree_ensure "$brain" "$wsdir/*/context/*.md" content || true
111
+ os_tree_ensure "$brain" "$wsdir/*/resources/*.md" content || true
112
+ os_tree_ensure "$brain" "$wsdir/*/resources/*/*.md" content || true
104
113
 
105
- printf '%s/%s — %s · resolver.md · initiatives/\n' "$wsdir" "$slug" "$head"
114
+ printf '%s/%s — %s · .resolver.md · initiatives/ · decisions/ · learnings/\n' "$wsdir" "$slug" "$head"
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env bash
2
+ # Deterministic half of the `orchestrator` skill (spec 077): turns the orchestrator on by creating its
3
+ # state file, `.system/orchestrator.md`, with the two empty sections. Internal: not invocable.
4
+ #
5
+ # Usage: orchestrator-init.sh --brain DIR [--confirm]
6
+ #
7
+ # | `.system/orchestrator.md` | without --confirm | with --confirm |
8
+ # | does not exist | prints what it will create and the plain | creates it, |
9
+ # | | question to ask; exit 0; writes nothing | exit 0 |
10
+ # | exists | prints that it is already on; exit 0; writes nothing — same with --confirm |
11
+ #
12
+ # It writes that one file and nothing else: no visible file, no line in `.system/tree.md`, no
13
+ # `.gitignore`. The file is written to a temporary name and moved into place, so a failed write
14
+ # never leaves a half-written file, and the file is published only if absent (create-if-absent, atomic).
15
+ #
16
+ # Exit: 0 done (or nothing to do) · 1 invalid argument · 2 the brain has no `.system/` · 9 the write
17
+ # failed and nothing was left behind.
18
+
19
+ set -u
20
+
21
+ here=$(cd "$(dirname "$0")" && pwd)
22
+ . "$here/common.sh"
23
+
24
+ brain=""
25
+ confirm=0
26
+ while [ $# -gt 0 ]; do
27
+ case "$1" in
28
+ --brain) brain="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
29
+ --confirm) confirm=1; shift ;;
30
+ *) os_die "unknown argument: $1" ;;
31
+ esac
32
+ done
33
+
34
+ [ -n "$brain" ] || os_die "--brain is required"
35
+ [ -d "$brain" ] || os_die "the brain does not exist: $brain"
36
+ brain=$(cd "$brain" && pwd)
37
+ [ -d "$brain/$OS_SYSTEM_DIR" ] || { printf 'error: %s has no %s/\n' "$brain" "$OS_SYSTEM_DIR" >&2; exit 2; }
38
+
39
+ OS_ORCHESTRATOR_FILE="$OS_SYSTEM_DIR/orchestrator.md"
40
+ target="$brain/$OS_ORCHESTRATOR_FILE"
41
+
42
+ language=$(os_language "$brain")
43
+ os_lang_load "$language"
44
+
45
+ if [ -e "$target" ] || [ -L "$target" ]; then
46
+ printf 'already-active: %s\n' "$OS_ORCHESTRATOR_FILE"
47
+ printf '%s\n' "$S_ORCHESTRATOR_ACTIVE_ALREADY"
48
+ exit 0
49
+ fi
50
+
51
+ if [ "$confirm" = "0" ]; then
52
+ printf 'would-create: %s\n' "$OS_ORCHESTRATOR_FILE"
53
+ printf '%s\n' "$S_ORCHESTRATOR_ACTIVATE_QUESTION"
54
+ exit 0
55
+ fi
56
+
57
+ # Written to a private temporary file made by mktemp (never a predictable name, never through a link),
58
+ # then published only if the target is still absent: `ln` fails when it exists, so two activations at
59
+ # once cannot overwrite each other and the winner's state stays. Only this temporary file is cleaned up.
60
+ tmpf=$(mktemp "$brain/$OS_SYSTEM_DIR/.orchestrator.XXXXXX" 2>/dev/null) || {
61
+ printf 'error: could not write %s\n' "$OS_ORCHESTRATOR_FILE" >&2
62
+ exit 9
63
+ }
64
+ trap 'rm -f "$tmpf"' EXIT
65
+ if ! { printf '## Sessions by topic\n\n## In progress\n' > "$tmpf"; } 2>/dev/null; then
66
+ printf 'error: could not write %s\n' "$OS_ORCHESTRATOR_FILE" >&2
67
+ exit 9
68
+ fi
69
+ if ln "$tmpf" "$target" 2>/dev/null; then
70
+ printf 'created: %s\n' "$OS_ORCHESTRATOR_FILE"
71
+ printf '%s\n' "$S_ORCHESTRATOR_CREATED"
72
+ exit 0
73
+ fi
74
+ if [ -e "$target" ] || [ -L "$target" ]; then
75
+ printf 'already-active: %s\n' "$OS_ORCHESTRATOR_FILE"
76
+ printf '%s\n' "$S_ORCHESTRATOR_ACTIVE_ALREADY"
77
+ exit 0
78
+ fi
79
+ printf 'error: could not write %s\n' "$OS_ORCHESTRATOR_FILE" >&2
80
+ exit 9
@@ -3,12 +3,16 @@
3
3
  # `core/resolver.md`, igual que `remote-backup.sh`, y lo conducen `core/skills/bootstrap.md` al
4
4
  # cerrar el bootstrap y cualquier sesión posterior que lo rutee.
5
5
  #
6
- # Uso: pack-install.sh --brain DIR [--defer] [--line]
6
+ # Uso: pack-install.sh --brain DIR [--defer [--note]] [--line]
7
7
  #
8
8
  # (sin flags) el ofrecimiento: qué hay instalado, qué falta y el comando exacto.
9
- # --defer la salida "después": deja la tarea en el backlog de la raíz, con el comando
10
- # adentro. Escribe el archivo directo, sin pasar por `capture` (spec 057): este paso
11
- # es determinístico, sin ningún modelo que pueda nombrar una iniciativa.
9
+ # --defer la salida "después", sin escribir nada: imprime el paso pendiente y la pregunta del
10
+ # catálogo («¿Te lo anoto para después?») y sale con 7. Nada se anota solo (Gate 2 final
11
+ # de la spec 076).
12
+ # --defer --note el sí del operador en ese turno: deja la tarea, con el comando adentro, en el
13
+ # backlog de la iniciativa tasks-to-sort del workspace personal, que nace si no está
14
+ # (`os_personal_backlog_append`). Sin pasar por `capture` (spec 057): este paso es
15
+ # determinístico, sin ningún modelo que pueda nombrar una iniciativa.
12
16
  # --line una línea, para el aviso de capacidad no instalada del arranque de sesión.
13
17
  #
14
18
  # El script NUNCA corre `npx`: bajar software a la máquina del operador escapa del sistema y se hace
@@ -21,7 +25,8 @@
21
25
  # El nombre del repo del pack se escribe una sola vez —el default de `scripts/release-public.sh`— y
22
26
  # el release lo inyecta acá donde el fuente lleva `pedroromeroluna/ai-first-product-skills`.
23
27
  #
24
- # Exit: 0 el ofrecimiento o la tarea quedaron dichos · 1 el brain no existe.
28
+ # Exit: 0 el ofrecimiento o la tarea quedaron dichos · 1 el brain no existe · 7 --defer sin --note:
29
+ # la pregunta quedó impresa y no se escribió nada.
25
30
 
26
31
  set -eu
27
32
 
@@ -30,11 +35,13 @@ here=$(cd "$(dirname "$0")" && pwd)
30
35
 
31
36
  brain=""
32
37
  modo="ofrecer"
38
+ note=0
33
39
 
34
40
  while [ $# -gt 0 ]; do
35
41
  case "$1" in
36
42
  --brain) brain="$2"; shift 2 ;;
37
43
  --defer) modo="defer"; shift ;;
44
+ --note) note=1; shift ;;
38
45
  --line) modo="line"; shift ;;
39
46
  *) os_die "argumento desconocido: $1" ;;
40
47
  esac
@@ -52,11 +59,15 @@ comando="npx skills add $pack_repo"
52
59
  # Qué del pack ya está donde el CLI lo deja. No es una lista escrita: es lo que hay en el brain.
53
60
  instalados=""
54
61
  n_instalados=0
55
- for d in "$brain"/.claude/skills/*/SKILL.md; do
56
- [ -f "$d" ] || continue
57
- d=$(dirname "$d")
58
- instalados="$instalados$(basename "$d") "
59
- n_instalados=$(( n_instalados + 1 ))
62
+ for sd in $OS_SKILL_DIRS; do
63
+ for d in "$brain/$sd"/*/SKILL.md; do
64
+ [ -f "$d" ] || continue
65
+ d=$(dirname "$d")
66
+ # A skill present in both folders (the link `npx skills add` leaves) counts once.
67
+ case " $instalados" in *" $(basename "$d") "*) continue ;; esac
68
+ instalados="$instalados$(basename "$d") "
69
+ n_instalados=$(( n_instalados + 1 ))
70
+ done
60
71
  done
61
72
 
62
73
  if [ "$modo" = "line" ]; then
@@ -71,33 +82,36 @@ language=$(os_language "$brain")
71
82
  os_lang_load "$language"
72
83
  tarea="$S_PACK_TASK \`$comando\`"
73
84
 
85
+ if [ "$modo" = "defer" ] && [ "$note" = "0" ]; then
86
+ # Nothing is noted down on its own (spec 076, final Gate 2): the step and the plain question, and the
87
+ # skill that drives this step asks it; only a yes in that turn re-runs this with --note.
88
+ printf "$S_NOTE_FOR_LATER_STEP\n" "$tarea"
89
+ printf '%s\n' "$S_NOTE_FOR_LATER_QUESTION"
90
+ exit 7
91
+ fi
92
+
74
93
  if [ "$modo" = "defer" ]; then
75
- if [ -f "$brain/backlog.md" ] && grep -qF "$tarea" "$brain/backlog.md"; then
76
- printf 'pack: la tarea pendiente ya estaba en el backlog de la raíz\n'
77
- exit 0
78
- fi
79
- # No pasa por `capture` (spec 057, decisión 2: nada entra sin clasificar): este paso corre
80
- # determinístico, sin ningún modelo en el medio que pueda proponer una iniciativa y esperar la
81
- # confirmación del operador — instalar el pack de skills no es trabajo de ninguna iniciativa, es
82
- # un paso pendiente del propio sistema. Escribe directo en `backlog.md` de la raíz, con el mismo
83
- # formato de línea y el mismo contador global que usa el resto del sistema; ese archivo, fuera de
84
- # toda iniciativa, es justo el hallazgo que la spec 057 declara aparte (S057-C5) hasta que el
85
- # operador corra el comando.
86
- hoy=$(date +%Y-%m-%d)
87
- nacio=0
88
- [ -f "$brain/backlog.md" ] || nacio=1
89
- [ "$nacio" = "1" ] && os_backlog_cabecera "$brain" "$(os_titulo "$brain/operator.md")" > "$brain/backlog.md"
90
- id=$(os_backlog_next_id "$brain")
91
- printf '%s\n' "$(os_backlog_linea "$id" "$tarea" "" "" "" "0" "$hoy")" >> "$brain/backlog.md"
92
- printf 'pack: pendiente — la tarea quedó en el backlog de la raíz, con el comando adentro\n'
94
+ # No pasa por `capture` (spec 057, decisión 2: nada entra sin clasificar): instalar el pack de
95
+ # skills no es trabajo de ninguna iniciativa, es un paso pendiente del propio sistema. Va al
96
+ # backlog de la iniciativa `tasks-to-sort` del workspace `personal` (spec 076, C29: ningún backlog
97
+ # vive fuera de una iniciativa), que nace con esta tarea si no existía.
98
+ os_ws_check "$brain"
99
+ rc=0
100
+ os_personal_backlog_append "$brain" "$tarea" || rc=$?
101
+ case "$rc" in
102
+ 0) printf 'pack: pendiente — la tarea quedó en el backlog de la iniciativa tasks-to-sort del workspace personal, con el comando adentro\n' ;;
103
+ 1) printf 'pack: la tarea pendiente ya estaba en el backlog de la iniciativa tasks-to-sort del workspace personal\n' ;;
104
+ 3) printf 'pack: pendiente y sin escribir — el slug tasks-to-sort del workspace personal lo usa una iniciativa que trata sobre un nodo\n' ;;
105
+ *) printf 'pack: pendiente y sin escribir — el workspace personal no existe todavía; correr migrate-root.sh y repetir\n' ;;
106
+ esac
93
107
  exit 0
94
108
  fi
95
109
 
96
110
  # --------------------------------------------------------------------- el ofrecimiento
97
111
  if [ "$n_instalados" = "0" ]; then
98
- printf 'pack: nada instalado todavía en .claude/skills\n'
112
+ printf 'pack: nada instalado todavía en .agents/skills ni en .claude/skills\n'
99
113
  else
100
- printf 'pack: ya instalado en .claude/skills: %s\n' "$instalados"
114
+ printf 'pack: ya instalado en las carpetas de skills: %s\n' "$instalados"
101
115
  fi
102
116
 
103
117
  # El comando baja solo lo que el pack ofrece: lo que el chasis ya provee viaja marcado interno y el
@@ -215,7 +215,7 @@ stdin_data="$true_heads
215
215
  %%FILES%%
216
216
  $all_files"
217
217
 
218
- result=$(printf '%s\n' "$stdin_data" | python3 "$here/recall_index.py" \
218
+ result=$(printf '%s\n' "$stdin_data" | python3 -B "$here/recall_index.py" \
219
219
  "$db" "$brain" "$mode" "$scope_kind" "$wsdir" "$scope_slug" "$arg" "$limit")
220
220
  rc=$?
221
221
  if [ "$rc" != "0" ]; then
@@ -26,7 +26,7 @@ from markdown import DATE_RE, read_frontmatter, split_entries # noqa: E402
26
26
 
27
27
  db_path, brain, mode, scope_kind, wsdir, scope_slug, arg, limit = sys.argv[1:9]
28
28
  limit = int(limit)
29
- FM_KEYS = ("updated", "fecha", "date", "status", "about", "superseded_by")
29
+ FM_KEYS = ("updated", "fecha", "date", "status", "about", "superseded_by", "generated")
30
30
 
31
31
 
32
32
  def file_status(fm):
@@ -79,6 +79,41 @@ def parse_file(abspath, relpath):
79
79
  return fm, out_entries, status, superseded_by, title
80
80
 
81
81
 
82
+ def about_values(raw):
83
+ """The paths an `about:` value names: one, or each item of `[<path>, <path>]`. Same reading as
84
+ `os_about_values` in common.sh, which is the authority."""
85
+ raw = raw.strip()
86
+ if raw.startswith("[") and raw.endswith("]"):
87
+ inner = raw[1:-1].strip()
88
+ values = [v.strip() for v in inner.split(",") if v.strip()] if inner else []
89
+ else:
90
+ values = [raw] if raw else []
91
+ return [rel_norm(unquote(v)) for v in values]
92
+
93
+
94
+ def unquote(v):
95
+ """V without one pair of matching surrounding quotes: the rule of `os_unquote` in common.sh."""
96
+ if len(v) >= 2 and v[0] == v[-1] and v[0] in "\"'":
97
+ return v[1:-1]
98
+ return v
99
+
100
+
101
+ def rel_norm(p):
102
+ """The same spelling `os_rel_norm` (common.sh) gives a path: no leading `./`, no `//`, no `/./`,
103
+ no trailing `/` or `/.`, repeated until nothing changes."""
104
+ prev = None
105
+ while p != prev:
106
+ prev = p
107
+ if p.startswith("./"):
108
+ p = p[2:]
109
+ p = p.replace("//", "/").replace("/./", "/")
110
+ if p.endswith("/."):
111
+ p = p[:-2]
112
+ if p.endswith("/"):
113
+ p = p[:-1]
114
+ return p
115
+
116
+
82
117
  def connect(path):
83
118
  conn = sqlite3.connect(path)
84
119
  conn.execute("PRAGMA journal_mode=WAL")
@@ -176,8 +211,15 @@ def reconcile(conn, brain, all_files, true_heads):
176
211
  " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
177
212
  (rel, size, mtime, digest, node, title, status, superseded_by, about),
178
213
  )
179
- if about:
180
- cur.execute("INSERT INTO relations (src, rel, dst) VALUES (?, 'about', ?)", (rel, about))
214
+ # A file a script generated (spec 076, C18: `generated: true`) is derived from the files it
215
+ # lists: its row keeps the stat filter working, and it adds no entry and no relation, so a
216
+ # search never answers with the index instead of the document.
217
+ if fm.get("generated", "") == "true":
218
+ continue
219
+ # `about:` names one head, or several as `[<path>, <path>]` on one line (spec 076, C16): one
220
+ # relation per value, in order.
221
+ for value in about_values(about):
222
+ cur.execute("INSERT INTO relations (src, rel, dst) VALUES (?, 'about', ?)", (rel, value))
181
223
  if superseded_by:
182
224
  cur.execute(
183
225
  "INSERT INTO relations (src, rel, dst) VALUES (?, 'superseded_by', ?)",
@@ -257,9 +299,9 @@ def run_expand():
257
299
  reconcile(conn, brain, all_files, true_heads)
258
300
 
259
301
  lines = []
260
- row = conn.execute("SELECT about FROM files WHERE path=?", (arg,)).fetchone()
261
- if row and row[0]:
262
- dst = row[0]
302
+ for (dst,) in conn.execute(
303
+ "SELECT dst FROM relations WHERE rel='about' AND src=? ORDER BY rowid", (arg,)
304
+ ):
263
305
  lines.append("about · %s · %s" % (dst, title_of(conn, dst)))
264
306
  for (src,) in conn.execute(
265
307
  "SELECT src FROM relations WHERE rel='about' AND dst=?", (arg,)
@@ -3,16 +3,20 @@
3
3
  # La conduce core/skills/bootstrap.md al cerrar el bootstrap, y la puede volver a correr cualquier
4
4
  # sesión posterior — que es lo que la tarea pendiente del backlog le pide al operador.
5
5
  #
6
- # Uso: remote-backup.sh --brain DIR
6
+ # Uso: remote-backup.sh --brain DIR [--note]
7
7
  #
8
8
  # El script NUNCA crea el repo ni pushea: eso escapa del sistema —queda algo en la cuenta de una
9
9
  # persona— y se hace con la confirmación del operador en la sesión. Acá se decide cuál de las dos
10
10
  # mitades corresponde y se deja dicho:
11
11
  # - con `gh` autenticado: imprime el ofrecimiento y el comando exacto, para que lo corra la sesión
12
12
  # después del sí del operador;
13
- # - sin `gh`, o sin sesión iniciada: deja la tarea guiada en el backlog de la raíz y lo dice.
13
+ # - sin `gh`, o sin sesión iniciada: no escribe nada; imprime el paso pendiente y la pregunta del
14
+ # catálogo («¿Te lo anoto para después?») y sale con 7. Nada se anota solo (Gate 2 final de la
15
+ # spec 076): con el sí del operador en ese turno, la sesión lo vuelve a correr con `--note`, que
16
+ # deja la tarea guiada en el backlog de la iniciativa tasks-to-sort del workspace personal.
14
17
  #
15
- # Exit: 0 siempre que haya podido decidir · 1 si el brain no está versionado.
18
+ # Exit: 0 decidió (o anotó con --note) · 1 si el brain no está versionado · 7 sin gh y sin --note: la
19
+ # pregunta quedó impresa y no se escribió nada.
16
20
 
17
21
  set -eu
18
22
 
@@ -20,10 +24,12 @@ here=$(cd "$(dirname "$0")" && pwd)
20
24
  . "$here/common.sh"
21
25
 
22
26
  brain=""
27
+ note=0
23
28
 
24
29
  while [ $# -gt 0 ]; do
25
30
  case "$1" in
26
31
  --brain) brain="$2"; shift 2 ;;
32
+ --note) note=1; shift ;;
27
33
  *) os_die "argumento desconocido: $1" ;;
28
34
  esac
29
35
  done
@@ -60,25 +66,29 @@ if [ "$autenticado" = "1" ]; then
60
66
  exit 0
61
67
  fi
62
68
 
63
- # Sin gh no se puede armar el remoto hoy: la tarea queda en el backlog de la raíz, con la guía
64
- # adentro, y el que la termina es cualquier sesión posterior. Un pendiente que nadie escribe es un
65
- # pendiente que nadie completa. Ese `backlog.md` de la raíz, fuera de toda iniciativa, es el
66
- # hallazgo que la spec 057 declara aparte (S057-C5) hasta que el operador arma el remoto.
69
+ # Sin gh no se puede armar el remoto hoy: la tarea queda en el backlog del espacio de trabajo
70
+ # `personal` (spec 059: la raíz ya no tiene backlog propio), con la guía adentro, y el que la termina
71
+ # es cualquier sesión posterior. Un pendiente que nadie escribe es un pendiente que nadie completa.
72
+ # No pasa por `capture` (spec 057, decisión 2): este paso corre determinístico, sin ningún modelo
73
+ # que pueda nombrar una iniciativa — armar el remoto de respaldo no es trabajo de ninguna. Va al
74
+ # backlog de la iniciativa `tasks-to-sort` del workspace `personal` (spec 076, C29). La escritura vive
75
+ # en `os_personal_backlog_append`.
67
76
  language=$(os_language "$brain")
68
77
  os_lang_load "$language"
69
78
  tarea="$S_BACKUP_TASK"
70
-
71
- if [ -f "$brain/backlog.md" ] && grep -qF "$tarea" "$brain/backlog.md"; then
72
- printf 'respaldo remoto: la tarea pendiente ya estaba en el backlog de la raíz\n'
73
- exit 0
79
+ if [ "$note" = "0" ]; then
80
+ printf "$S_NOTE_FOR_LATER_STEP\n" "$tarea"
81
+ printf '%s\n' "$S_NOTE_FOR_LATER_QUESTION"
82
+ exit 7
74
83
  fi
75
84
 
76
- # No pasa por `capture` (spec 057, decisión 2): este paso corre determinístico, sin ningún modelo
77
- # en el medio que pueda nombrar una iniciativa y esperar la confirmación del operador — armar el
78
- # remoto de respaldo no es trabajo de ninguna iniciativa. Mismo criterio y mismo formato que
79
- # `pack-install.sh --defer`.
80
- hoy=$(date +%Y-%m-%d)
81
- [ -f "$brain/backlog.md" ] || os_backlog_cabecera "$brain" "$(os_titulo "$brain/operator.md")" > "$brain/backlog.md"
82
- id=$(os_backlog_next_id "$brain")
83
- printf '%s\n' "$(os_backlog_linea "$id" "$tarea" "" "" "" "0" "$hoy")" >> "$brain/backlog.md"
84
- printf 'respaldo remoto: pendiente — sin gh autenticado, la tarea guiada quedó en el backlog de la raíz\n'
85
+ os_ws_check "$brain"
86
+ rc=0
87
+ os_personal_backlog_append "$brain" "$tarea" || rc=$?
88
+ case "$rc" in
89
+ 0) printf 'respaldo remoto: pendiente — sin gh autenticado, la tarea guiada quedó en el backlog de la iniciativa tasks-to-sort del workspace personal\n' ;;
90
+ 1) printf 'respaldo remoto: la tarea pendiente ya estaba en el backlog de la iniciativa tasks-to-sort del workspace personal\n' ;;
91
+ 3) printf 'respaldo remoto: pendiente y sin escribir — el slug tasks-to-sort del workspace personal lo usa una iniciativa que trata sobre un nodo\n' ;;
92
+ *) printf 'respaldo remoto: pendiente y sin escribir — el workspace personal no existe todavía; correr migrate-root.sh y repetir\n' ;;
93
+ esac
94
+ exit 0