ai-first-os 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +226 -0
  3. package/bin/ai-first-os.js +72 -0
  4. package/core/CLAUDE.md +148 -0
  5. package/core/VERSION +1 -0
  6. package/core/agents/ambiguous-spec.md +39 -0
  7. package/core/agents/complete-spec.md +36 -0
  8. package/core/agents/scout.md +25 -0
  9. package/core/install.sh +243 -0
  10. package/core/lib/archive.sh +347 -0
  11. package/core/lib/bootstrap.sh +276 -0
  12. package/core/lib/capture.sh +188 -0
  13. package/core/lib/check-resolvable.sh +172 -0
  14. package/core/lib/close-session.sh +741 -0
  15. package/core/lib/common.sh +1773 -0
  16. package/core/lib/focus-read.sh +282 -0
  17. package/core/lib/manual-link.sh +111 -0
  18. package/core/lib/markdown.py +304 -0
  19. package/core/lib/migrate-backlogs.sh +207 -0
  20. package/core/lib/migrate-canonicals.sh +523 -0
  21. package/core/lib/mount-repo.sh +543 -0
  22. package/core/lib/my-wiki-gates.sh +137 -0
  23. package/core/lib/my-wiki.sh +202 -0
  24. package/core/lib/my_wiki_build.py +548 -0
  25. package/core/lib/my_wiki_graph.py +137 -0
  26. package/core/lib/my_wiki_overview.py +392 -0
  27. package/core/lib/new-memory.sh +160 -0
  28. package/core/lib/new-product.sh +122 -0
  29. package/core/lib/new-workspace.sh +105 -0
  30. package/core/lib/pack-install.sh +114 -0
  31. package/core/lib/recall.sh +235 -0
  32. package/core/lib/recall_index.py +295 -0
  33. package/core/lib/remote-backup.sh +84 -0
  34. package/core/lib/rename-heads.sh +354 -0
  35. package/core/lib/rename-workspaces.sh +271 -0
  36. package/core/lib/session-read.sh +203 -0
  37. package/core/lib/session-start.sh +854 -0
  38. package/core/lib/supersede.sh +436 -0
  39. package/core/lib/sweep.sh +473 -0
  40. package/core/manual/COMO-FUNCIONA.md +251 -0
  41. package/core/manual/HOW-IT-WORKS.md +250 -0
  42. package/core/resolver.md +30 -0
  43. package/core/skills/archive.md +95 -0
  44. package/core/skills/bootstrap.md +226 -0
  45. package/core/skills/capture.md +65 -0
  46. package/core/skills/check-resolvable.md +38 -0
  47. package/core/skills/close-session.md +108 -0
  48. package/core/skills/grill.md +74 -0
  49. package/core/skills/mount-repo.md +97 -0
  50. package/core/skills/my-wiki.md +103 -0
  51. package/core/skills/new-memory.md +76 -0
  52. package/core/skills/new-product.md +55 -0
  53. package/core/skills/new-spec.md +114 -0
  54. package/core/skills/new-workspace.md +53 -0
  55. package/core/skills/recall.md +64 -0
  56. package/core/skills/rename-heads.md +72 -0
  57. package/core/skills/rename-workspaces.md +43 -0
  58. package/core/skills/supersede.md +83 -0
  59. package/core/skills/sweep.md +40 -0
  60. package/core/templates/my-wiki-graph.js +431 -0
  61. package/core/templates/my-wiki-overview.js +174 -0
  62. package/core/templates/my-wiki.html +1017 -0
  63. package/core/templates/node-folder/README.md +11 -0
  64. package/core/templates/node-folder/resolver.md +9 -0
  65. package/core/templates/node-light.md +22 -0
  66. package/core/templates/node-product/README.md +8 -0
  67. package/core/templates/node-repo/README.md +14 -0
  68. package/core/templates/node-repo/context/README.md +22 -0
  69. package/core/templates/node-repo/context/competitors.md +8 -0
  70. package/core/templates/node-repo/context/glossary.md +8 -0
  71. package/core/templates/node-repo/context/open-questions.md +9 -0
  72. package/core/templates/node-repo/context/opportunities.md +9 -0
  73. package/core/templates/node-repo/context/problem.md +8 -0
  74. package/core/templates/node-repo/context/scope.md +8 -0
  75. package/core/templates/node-repo/context/users.md +8 -0
  76. package/core/templates/node-repo/context/vision.md +8 -0
  77. package/core/templates/node-repo/resolver.md +14 -0
  78. package/core/templates/operator.md +17 -0
  79. package/core/templates/person.md +10 -0
  80. package/core/templates/repo-scaffold/ARCHITECTURE.md +3 -0
  81. package/core/templates/repo-scaffold/CLAUDE.md +23 -0
  82. package/core/templates/repo-scaffold/decisions.md +3 -0
  83. package/core/templates/repo-scaffold/evals-run.sh +14 -0
  84. package/core/templates/repo-scaffold/gitignore +3 -0
  85. package/core/templates/repo-scaffold/settings.json +8 -0
  86. package/core/templates/root-resolver.md +5 -0
  87. package/core/templates/strings.md +1361 -0
  88. package/core/templates/tree.md +59 -0
  89. package/core/templates/voice.md +5 -0
  90. package/package.json +23 -0
@@ -0,0 +1,543 @@
1
+ #!/usr/bin/env bash
2
+ # Parte determinística de `mount-repo`: monta un repo git como cuerpo de un nodo. La entrevista la
3
+ # conduce core/skills/mount-repo.md. Interno: no es invocable.
4
+ #
5
+ # Uso: mount-repo.sh --brain DIR --head RUTA --remote REMOTE [--clone-root RUTA] [--new]
6
+ #
7
+ # --head la cabeza, relativa al brain: `workspaces/<slug>/initiatives/<nombre>/README.md`
8
+ # --remote lo que se escribe en `repo:` — el remote textual, nunca una ruta local
9
+ # --clone-root la raíz de clonado de esta máquina. Se pregunta una sola vez: si `mounts.md` ya la
10
+ # declara, esa gana y el argumento se ignora diciéndolo.
11
+ # --new the repo does not exist yet: instead of cloning, it is born from the product's
12
+ # scaffold (`templates/repo-scaffold/`), with its first commit on `main` and
13
+ # `origin` declared. The remote is never created and nothing is ever pushed: that
14
+ # escapes the system, and the commands to do it are printed for the operator (spec
15
+ # 034, same pattern as `remote-backup.sh`).
16
+ #
17
+ # Los tres actos son uno solo —decidir construir y montar el repo son el mismo acto—: `repo:` en la
18
+ # cabeza, el clon plano fuera del brain, y la fila remote -> ruta local en la tabla del entorno.
19
+ # With `--new` the birth of the repo takes the clone's place: deciding to build, giving birth to the
20
+ # repo and mounting it are the same act too.
21
+ #
22
+ # Idempotente: montar dos veces el mismo remote no duplica la fila ni vuelve a clonar. Sobre una
23
+ # máquina nueva —la tabla no viaja— reconstruye el clon y la fila sin tocar la cabeza. `--new` is
24
+ # idempotent the same way: over a repo already born with this `origin`, it does not give birth again
25
+ # and the other four acts run — a birth interrupted halfway is resumed by re-running the same
26
+ # command.
27
+ #
28
+ # Everything the operator reads comes out of the bilingual catalog (`templates/strings.md`) in the
29
+ # brain's language, `en` as source (spec 033/034). What stays in Spanish and is not translated: the
30
+ # argument errors of `os_die` —they are read by whoever wires the command, not by the operator— and
31
+ # the header `mounts.md` is born with, which is file content and not a message.
32
+ #
33
+ # Exit: 0 montó o ya estaba · 2 argumentos o cabeza inválidos · 3 el remote no responde
34
+ # 4 la cabeza ya declara otro `repo:` · 5 la raíz de clonado falta o es inválida
35
+ # 6 falta `python3` — requisito duro del producto junto a `git` (spec 030)
36
+ # 7 `--new` on a remote that does answer: there is nothing to create (spec 034)
37
+ # 8 `--new`: the birth of the repo failed — the message names why (spec 034)
38
+ #
39
+ # Nada se escribe antes de que las seis validaciones pasen —siete con `--new`, que suma la del
40
+ # destino—: una negativa a mitad de camino deja el nodo montado a medias, que es peor que no
41
+ # montarlo.
42
+
43
+ set -u
44
+
45
+ here=$(cd "$(dirname "$0")" && pwd)
46
+ . "$here/common.sh"
47
+
48
+ brain=""
49
+ head_rel=""
50
+ remote=""
51
+ clone_root_arg=""
52
+ new=0
53
+
54
+ while [ $# -gt 0 ]; do
55
+ case "$1" in
56
+ --brain) brain="${2:-}"; shift 2 ;;
57
+ --head) head_rel="${2:-}"; shift 2 ;;
58
+ --remote) remote="${2:-}"; shift 2 ;;
59
+ --clone-root) clone_root_arg="${2:-}"; shift 2 ;;
60
+ # A flag with no value: the remote stays mandatory and textual with `--new` too — it is what
61
+ # travels in `repo:` and what `origin` gets pointed at.
62
+ --new) new=1; shift ;;
63
+ *) os_die "argumento desconocido: $1" ;;
64
+ esac
65
+ done
66
+
67
+ [ -n "$brain" ] || os_die "falta --brain"
68
+ [ -n "$head_rel" ] || os_die "falta --head"
69
+ [ -n "$remote" ] || os_die "falta --remote"
70
+ [ -d "$brain" ] || os_die "no existe el brain: $brain"
71
+
72
+ # Layout inválido frena acá, antes de escribir nada (P2, spec 039).
73
+ os_ws_check "$brain"
74
+
75
+ # ---------------------------------------------------------------- lo que se lee del remote
76
+ # remote_repo_name REMOTE -> the checkout name, the same one `git clone` uses with no destination
77
+ # argument. Stated once: the destination, the `--new` hint of exit 3 and the name offered to
78
+ # `gh repo create` all read it from here.
79
+ remote_repo_name() {
80
+ local n="${1%/}"
81
+ n="${n##*/}"
82
+ n="${n##*:}"
83
+ printf '%s' "${n%.git}"
84
+ }
85
+
86
+ # remote_github_slug REMOTE -> `owner/name` when the remote is a GitHub one, empty otherwise.
87
+ # Reads the two forms that travel in `repo:` (`git@github.com:owner/name(.git)` and
88
+ # `https://github.com/owner/name(.git)`, plus `ssh://git@github.com/owner/name.git`). The owner is
89
+ # what makes the difference: `gh repo create <name>` creates it under the authenticated user, so a
90
+ # remote naming another owner would end up pointing at a repo that is not the one that was created.
91
+ remote_github_slug() {
92
+ local r="${1%/}" rest owner name
93
+ r="${r%.git}"
94
+ case "$r" in
95
+ git@github.com:*) rest="${r#git@github.com:}" ;;
96
+ ssh://git@github.com/*) rest="${r#ssh://git@github.com/}" ;;
97
+ https://github.com/*) rest="${r#https://github.com/}" ;;
98
+ http://github.com/*) rest="${r#http://github.com/}" ;;
99
+ *) return 0 ;;
100
+ esac
101
+ owner="${rest%%/*}"
102
+ name="${rest#*/}"
103
+ # Exactly two segments: anything else is not a repo address and is not guessed at.
104
+ case "$name" in ''|*/*) return 0 ;; esac
105
+ [ -n "$owner" ] || return 0
106
+ printf '%s/%s' "$owner" "$name"
107
+ }
108
+
109
+ # python3 es requisito duro del producto, junto a git (spec 030): el cuarto acto —autorizar el
110
+ # checkout para el harness— lo necesita para leer y escribir el JSON de settings.local.json. Se
111
+ # chequea antes de la primera escritura, con el mismo criterio que el resto de las validaciones.
112
+ # The language of what gets written is the brain's, declared once in `operator.md` (spec 021), and
113
+ # it is loaded before the first message: `os_language` runs in a subshell of its own, so the
114
+ # frontmatter it reads never lands on the head's.
115
+ language=$(os_language "$brain")
116
+ os_lang_load "$language"
117
+
118
+ command -v python3 > /dev/null 2>&1 || {
119
+ printf '%s\n' "$S_MOUNT_NO_PYTHON3" >&2
120
+ printf '%s\n' "$S_MOUNT_NOTHING_WRITTEN" >&2
121
+ exit 6
122
+ }
123
+ # `pwd -P`, acá y en la raíz de clonado: el guard anti-anidado compara las dos rutas como texto, y
124
+ # con una sola de las dos resuelta a físico un symlink en el medio lo evade — el clon termina adentro
125
+ # del brain o de otro repo, que es justo lo que la forma repo evita. Las dos mitades tienen que estar
126
+ # en el mismo sistema de coordenadas o la comparación no significa nada.
127
+ brain=$(cd "$brain" && pwd -P)
128
+
129
+ mounts="$brain/$OS_MOUNTS_ARCHIVO"
130
+
131
+ # ---------------------------------------------------------------- 1. la cabeza
132
+ # Relativa al brain, como todas las rutas del sistema. Una absoluta funciona en una sola máquina, y
133
+ # una que sube con `..` escribe fuera del árbol.
134
+ case "$head_rel" in
135
+ /*) printf "$S_MOUNT_HEAD_ABSOLUTE\n" "$head_rel" >&2; exit 2 ;;
136
+ *..*) printf "$S_MOUNT_HEAD_ESCAPES\n" "$head_rel" >&2; exit 2 ;;
137
+ esac
138
+ head_abs="$brain/$head_rel"
139
+ if [ ! -f "$head_abs" ]; then
140
+ printf "$S_MOUNT_HEAD_MISSING\n" "$head_rel" >&2
141
+ exit 2
142
+ fi
143
+
144
+ fm_read "$head_abs"
145
+ if [ -n "$fm_roto" ]; then
146
+ printf "$S_MOUNT_HEAD_FM_BROKEN\n" "$head_rel" "$fm_roto" >&2
147
+ exit 2
148
+ fi
149
+
150
+ # Un `repo:` distinto ya escrito es del operador: dos cuerpos para una cabeza no lo resuelve un
151
+ # script. Se frena antes de tocar nada.
152
+ if [ -n "$fm_repo" ] && [ "$fm_repo" != "$remote" ]; then
153
+ printf "$S_MOUNT_HEAD_REPO_CONFLICT\n" "$head_rel" "$fm_repo" >&2
154
+ printf "$S_MOUNT_HEAD_REPO_CONFLICT_TAIL\n" "$remote" >&2
155
+ exit 4
156
+ fi
157
+
158
+ # ---------------------------------------------------------------- 2. el remote responde
159
+ # Si no responde, no hay nada que montar: negarse antes de escribir es más barato que dejar una
160
+ # cabeza apuntando a un remote que no existe.
161
+ # The same check, read in both directions (spec 034): `--new` is for a remote that does NOT answer,
162
+ # so a live remote is its refusal — there is nothing to create, and the plain command mounts it.
163
+ # `GIT_TERMINAL_PROMPT=0` and stdin closed: over HTTPS with no stored credential, git asks for a
164
+ # user and a password on the terminal and the whole command hangs waiting for an answer nobody is
165
+ # going to type. With the prompt off it fails, which is the answer this check needs.
166
+ if GIT_TERMINAL_PROMPT=0 git ls-remote "$remote" > /dev/null 2>&1 < /dev/null; then
167
+ if [ "$new" = "1" ]; then
168
+ printf "$S_MOUNT_NEW_REMOTE_ALIVE\n" "$remote" >&2
169
+ printf '%s\n' "$S_MOUNT_NOTHING_WRITTEN" >&2
170
+ exit 7
171
+ fi
172
+ elif [ "$new" = "0" ]; then
173
+ printf "$S_MOUNT_REMOTE_DOWN\n" "$remote" >&2
174
+ # A repo already born locally is not a repo that is missing: pointing at `--new` there would send
175
+ # the operator to a command that is going to refuse. The hint reads the standard path —the only
176
+ # one `--new` writes to— without touching anything.
177
+ hint_root=$(os_mounts_clone_root "$mounts")
178
+ [ -n "$hint_root" ] || hint_root="$clone_root_arg"
179
+ hint_path="$hint_root/$(remote_repo_name "$remote")"
180
+ if [ -n "$hint_root" ] && [ -d "$hint_path/.git" ] \
181
+ && [ "$(git -C "$hint_path" remote get-url origin 2>/dev/null)" = "$remote" ]; then
182
+ printf "$S_MOUNT_NEW_ALREADY_BORN_HINT\n" "$hint_path" >&2
183
+ else
184
+ printf '%s\n' "$S_MOUNT_NEW_HINT" >&2
185
+ fi
186
+ printf '%s\n' "$S_MOUNT_NOTHING_WRITTEN" >&2
187
+ exit 3
188
+ fi
189
+
190
+ # ---------------------------------------------------------------- 3. la raíz de clonado
191
+ clone_root=$(os_mounts_clone_root "$mounts")
192
+ declarada=0
193
+ if [ -n "$clone_root" ]; then
194
+ declarada=1
195
+ if [ -n "$clone_root_arg" ] && [ "$clone_root_arg" != "$clone_root" ]; then
196
+ printf "$S_MOUNT_CLONE_ROOT_DECLARED\n" "$clone_root"
197
+ fi
198
+ else
199
+ clone_root="$clone_root_arg"
200
+ fi
201
+
202
+ if [ -z "$clone_root" ]; then
203
+ printf "$S_MOUNT_CLONE_ROOT_MISSING\n" "$OS_MOUNTS_ARCHIVO" >&2
204
+ exit 5
205
+ fi
206
+
207
+ case "$clone_root" in
208
+ /*) ;;
209
+ *) printf "$S_MOUNT_CLONE_ROOT_RELATIVE\n" "$clone_root" >&2; exit 5 ;;
210
+ esac
211
+
212
+ # El cuerpo se clona plano y afuera: adentro del brain el brain deja de clonarse liviano, y adentro
213
+ # de otro repo aparecen repos anidados —gitlinks o submódulos—, que es el terreno que la forma repo
214
+ # evita. Se mira el ancestro existente más cercano: la raíz puede no existir todavía.
215
+ ancestro="$clone_root"
216
+ while [ ! -d "$ancestro" ]; do
217
+ case "$ancestro" in
218
+ */*) ancestro="${ancestro%/*}"; [ -n "$ancestro" ] || ancestro="/" ;;
219
+ *) ancestro="/"; break ;;
220
+ esac
221
+ done
222
+ ancestro=$(cd "$ancestro" && pwd -P)
223
+
224
+ case "$ancestro/" in
225
+ "$brain"/*) printf "$S_MOUNT_CLONE_ROOT_IN_BRAIN\n" "$clone_root" >&2
226
+ exit 5 ;;
227
+ esac
228
+
229
+ dentro_de_repo=""
230
+ d="$ancestro"
231
+ while :; do
232
+ [ -e "$d/.git" ] && dentro_de_repo="$d"
233
+ [ "$d" = "/" ] && break
234
+ d="${d%/*}"
235
+ [ -n "$d" ] || d="/"
236
+ done
237
+ if [ -n "$dentro_de_repo" ]; then
238
+ printf "$S_MOUNT_CLONE_ROOT_IN_REPO\n" "$dentro_de_repo" >&2
239
+ exit 5
240
+ fi
241
+
242
+ # ---------------------------------------------------------------- 4. el destino
243
+ nombre=$(remote_repo_name "$remote")
244
+ if [ -z "$nombre" ]; then
245
+ printf "$S_MOUNT_NAME_UNDERIVABLE\n" "$remote" >&2
246
+ exit 2
247
+ fi
248
+ destino="$clone_root/$nombre"
249
+ # The standard path is kept: with `--new` it is the only one where a repo is born, however the table
250
+ # may have moved `destino`.
251
+ destino_estandar="$destino"
252
+
253
+ # ---------------------------------------------------------------- 5. qué había ya montado
254
+ # Las filas del remote se juntan todas, no solo la última: una tabla con el mismo remote dos veces es
255
+ # ambigua, y elegir en silencio es la clase de barrido incompleto que el sistema prohíbe. Se usa la
256
+ # última —la más reciente— y se declara cuáles había.
257
+ fila_previa=""
258
+ filas_remote=""
259
+ n_filas=0
260
+ escanear_filas() {
261
+ fila_previa=""
262
+ filas_remote=""
263
+ n_filas=0
264
+ while IFS="$OS_SEP" read -r n r_remote r_ruta || [ -n "$n" ]; do
265
+ [ -n "$n" ] || continue
266
+ [ "$r_remote" = "$remote" ] || continue
267
+ n_filas=$(( n_filas + 1 ))
268
+ fila_previa="$n"
269
+ [ -n "$filas_remote" ] && filas_remote="$filas_remote $n" || filas_remote="$n"
270
+ [ -n "$r_ruta" ] && destino="$r_ruta"
271
+ done <<FILAS
272
+ $(os_mounts_filas "$mounts")
273
+ FILAS
274
+ }
275
+
276
+ # lista_lineas "4 6 8" -> "line 4, 6 and 8", in the brain's language.
277
+ lista_lineas() {
278
+ local acc="" x total=0 i=0
279
+ for x in $1; do total=$(( total + 1 )); done
280
+ for x in $1; do
281
+ i=$(( i + 1 ))
282
+ if [ "$i" = "1" ]; then acc="$x"
283
+ elif [ "$i" = "$total" ]; then acc="$acc $S_MOUNT_TABLE_LINE_AND $x"
284
+ else acc="$acc, $x"; fi
285
+ done
286
+ printf "$S_MOUNT_TABLE_LINE_LIST" "$acc"
287
+ }
288
+
289
+ escanear_filas
290
+
291
+ clonado=0
292
+ if [ -d "$destino/.git" ]; then
293
+ clonado=1
294
+ fi
295
+
296
+ # ---------------------------------------------------------------- 6. el destino con `--new`
297
+ # A row pointing this remote somewhere else does not move a birth: with `--new` the repo is born at
298
+ # `<clone root>/<name>` and nowhere else — a stale row would give birth anywhere on the disk. Which
299
+ # one stays belongs to the operator, same criterion as a head that already declares another `repo:`.
300
+ ya_nacio=0
301
+ if [ "$new" = "1" ]; then
302
+ if [ "$destino" != "$destino_estandar" ]; then
303
+ printf "$S_MOUNT_NEW_ROW_ELSEWHERE\n" \
304
+ "$OS_MOUNTS_ARCHIVO" "$destino" "$fila_previa" "$destino_estandar" >&2
305
+ printf '%s\n' "$S_MOUNT_NOTHING_WRITTEN" >&2
306
+ exit 5
307
+ fi
308
+ # A repo already born with this `origin` is the birth that already happened: same treatment as
309
+ # "the checkout was already there" on the clone side. That is what makes an interrupted birth
310
+ # resumable — without it, re-running is exit 5 and there is no way back.
311
+ if [ -d "$destino/.git" ] \
312
+ && [ "$(git -C "$destino" remote get-url origin 2>/dev/null)" = "$remote" ]; then
313
+ ya_nacio=1
314
+ elif [ -e "$destino" ]; then
315
+ printf "$S_MOUNT_NEW_DEST_EXISTS\n" "$destino" >&2
316
+ printf '%s\n' "$S_MOUNT_NOTHING_WRITTEN" >&2
317
+ exit 5
318
+ fi
319
+ fi
320
+
321
+ # repo_birth DEST NAME
322
+ # Writes the product's scaffold into DEST, makes the first commit on `main` and declares `origin`.
323
+ # The prose of every file comes out of `templates/strings.md` in the brain's language: one template
324
+ # tree, one translation per string — never a copy of the scaffold per language (spec 021).
325
+ # It never creates the remote and it never pushes: that escapes the system —something ends up in a
326
+ # person's account— and it is left printed for the operator, same pattern as `remote-backup.sh`.
327
+ # Leaves `generic_identity` at 1 when git had no identity configured and the commit had to be signed
328
+ # with the product's, and `birth_error` with the reason when it returns 1.
329
+ generic_identity=0
330
+ birth_error=""
331
+ repo_birth() {
332
+ local dest="$1" name="$2" tpl="$here/../templates/repo-scaffold" d
333
+ birth_error=""
334
+ mkdir -p "$dest/.claude" "$dest/specs/done" "$dest/docs/postmortems" "$dest/docs/research" \
335
+ "$dest/learnings" "$dest/evals" || { birth_error="mkdir $dest"; return 1; }
336
+ os_render_lang "$tpl/CLAUDE.md" "$language" "NAME=$name" > "$dest/CLAUDE.md" \
337
+ || { birth_error="CLAUDE.md"; return 1; }
338
+ os_render_lang "$tpl/ARCHITECTURE.md" "$language" "NAME=$name" > "$dest/ARCHITECTURE.md" \
339
+ || { birth_error="ARCHITECTURE.md"; return 1; }
340
+ os_render_lang "$tpl/decisions.md" "$language" "NAME=$name" > "$dest/decisions.md" \
341
+ || { birth_error="decisions.md"; return 1; }
342
+ os_render_lang "$tpl/evals-run.sh" "$language" "NAME=$name" > "$dest/evals/run.sh" \
343
+ || { birth_error="evals/run.sh"; return 1; }
344
+ chmod +x "$dest/evals/run.sh" || { birth_error="chmod evals/run.sh"; return 1; }
345
+ # The two files with no prose travel as they are: the harness guardrails —agents neither push nor
346
+ # merge— and the ignore list that keeps a secret out of the first commit.
347
+ cp "$tpl/settings.json" "$dest/.claude/settings.json" || { birth_error=".claude/settings.json"; return 1; }
348
+ cp "$tpl/gitignore" "$dest/.gitignore" || { birth_error=".gitignore"; return 1; }
349
+ # git does not track empty folders: without a keep file the taxonomy does not survive the first
350
+ # clone, and the next agent finds a tree that is not the one that was born.
351
+ for d in specs/done docs/postmortems docs/research learnings; do
352
+ : > "$dest/$d/.gitkeep" || { birth_error="$d/.gitkeep"; return 1; }
353
+ done
354
+
355
+ git init --quiet "$dest" > /dev/null 2>&1 || { birth_error="git init"; return 1; }
356
+ # `main` without depending on the git version: `git init -b main` needs 2.28 and the product asks
357
+ # for no version of git. On an empty repo, moving HEAD is the same thing.
358
+ git -C "$dest" symbolic-ref HEAD refs/heads/main > /dev/null 2>&1 \
359
+ || { birth_error="git symbolic-ref"; return 1; }
360
+ # `core.excludesFile` off for this one command: the operator's global ignore list is theirs, and
361
+ # more than one has `.claude/` in it — with it applied, the repo would be born without the
362
+ # guardrails file and the command would say it went fine. The scaffold's own `.gitignore` keeps
363
+ # applying: what is off is the global list, not the repo's.
364
+ git -C "$dest" -c core.excludesFile=/dev/null add -A > /dev/null 2>&1 \
365
+ || { birth_error="git add"; return 1; }
366
+ if ! git -C "$dest" commit -q -m "$S_REPO_FIRST_COMMIT" > /dev/null 2>&1; then
367
+ # Same fallback as `bootstrap.sh` for a machine with no git identity configured: the repo being
368
+ # born is worth more than the signature, and the fallback is declared, never silent.
369
+ git -C "$dest" -c user.name="AI First OS" -c user.email="bootstrap@ai-first-os.local" \
370
+ commit -q -m "$S_REPO_FIRST_COMMIT" > /dev/null 2>&1 || { birth_error="git commit"; return 1; }
371
+ generic_identity=1
372
+ fi
373
+ # The guardrails are checked in the commit, not in the folder: whatever kept them out —a global
374
+ # ignore, a failed copy— makes this a failed birth, never a birth reported as fine.
375
+ git -C "$dest" ls-files --error-unmatch .claude/settings.json > /dev/null 2>&1 \
376
+ || { birth_error=".claude/settings.json did not make it into the first commit"; return 1; }
377
+ git -C "$dest" remote add origin "$remote" > /dev/null 2>&1 || { birth_error="git remote add"; return 1; }
378
+ return 0
379
+ }
380
+
381
+ # ---------------------------------------------------------------- los cuatro actos
382
+ printf '%s\n' "$S_MOUNT_TITLE"
383
+
384
+ # --- el clon, o el nacimiento
385
+ if [ "$new" = "1" ]; then
386
+ if [ "$ya_nacio" = "1" ]; then
387
+ printf "$S_MOUNT_NEW_ALREADY_BORN\n" "$destino"
388
+ else
389
+ # Whether the clone root existed before decides what the cleanup can remove: "nothing was
390
+ # written" is only true if what the command created is what gets removed.
391
+ clone_root_existia=1
392
+ [ -d "$clone_root" ] || clone_root_existia=0
393
+ mkdir -p "$clone_root" || {
394
+ printf "$S_MOUNT_CLONE_ROOT_UNWRITABLE\n" "$clone_root" >&2; exit 5; }
395
+ if ! repo_birth "$destino" "$nombre"; then
396
+ printf "$S_MOUNT_NEW_FAILED\n" "$birth_error" >&2
397
+ rm -rf "$destino" 2>/dev/null
398
+ [ "$clone_root_existia" = "1" ] || rmdir "$clone_root" 2>/dev/null
399
+ if [ -e "$destino" ]; then
400
+ printf "$S_MOUNT_NEW_LEFTOVER\n" "$destino" >&2
401
+ else
402
+ printf "$S_MOUNT_NEW_CLEANED\n" "$destino" >&2
403
+ printf '%s\n' "$S_MOUNT_NOTHING_WRITTEN" >&2
404
+ fi
405
+ exit 8
406
+ fi
407
+ printf "$S_MOUNT_NEW_BORN\n" "$destino"
408
+ [ "$generic_identity" = "0" ] || printf '%s\n' "$S_MOUNT_NEW_GENERIC_IDENTITY"
409
+ fi
410
+ elif [ "$clonado" = "1" ]; then
411
+ printf "$S_MOUNT_CHECKOUT_ALREADY\n" "$destino"
412
+ else
413
+ if [ -e "$destino" ]; then
414
+ printf "$S_MOUNT_DEST_NOT_REPO\n" "$destino" >&2
415
+ printf '%s\n' "$S_MOUNT_NOTHING_WRITTEN" >&2
416
+ exit 5
417
+ fi
418
+ mkdir -p "$clone_root" || {
419
+ printf "$S_MOUNT_CLONE_ROOT_UNWRITABLE\n" "$clone_root" >&2; exit 5; }
420
+ if ! git clone --quiet "$remote" "$destino" > /dev/null 2>&1; then
421
+ printf "$S_MOUNT_CLONE_FAILED\n" "$remote" "$destino" >&2
422
+ printf '%s\n' "$S_MOUNT_NOTHING_WRITTEN" >&2
423
+ exit 3
424
+ fi
425
+ printf "$S_MOUNT_CHECKOUT\n" "$destino"
426
+ fi
427
+
428
+ # --- `repo:` en la cabeza
429
+ # En una máquina nueva la cabeza ya lo tiene —viaja con el brain— y la tabla no: reconstruir el
430
+ # montaje no la toca.
431
+ if [ "$fm_repo" = "$remote" ]; then
432
+ printf "$S_MOUNT_HEAD_REPO_ALREADY\n" "$head_rel"
433
+ else
434
+ if os_fm_set "$head_abs" repo "$remote"; then
435
+ printf "$S_MOUNT_HEAD_REPO_WRITTEN\n" "$head_rel" "$remote"
436
+ else
437
+ printf "$S_MOUNT_HEAD_REPO_WRITE_FAILED\n" "$head_rel" >&2
438
+ exit 2
439
+ fi
440
+ fi
441
+
442
+ # --- la fila de la tabla del entorno
443
+ nacio=0
444
+ if [ ! -f "$mounts" ]; then
445
+ nacio=1
446
+ {
447
+ printf '# Montajes — el entorno de esta máquina\n\n'
448
+ printf 'Remote -> ruta local. Es dato de esta máquina y **no viaja**: en una máquina nueva no\n'
449
+ printf 'está, los barridos reportan el montaje como no alcanzado y `mount-repo` sobre el mismo\n'
450
+ printf 'remote lo reconstruye. Lo escribe `mount-repo`.\n\n'
451
+ printf 'clone-root: `%s`\n\n' "$clone_root"
452
+ printf '| Remote | Ruta local |\n'
453
+ printf '|---|---|\n'
454
+ } > "$mounts"
455
+ fi
456
+
457
+ # La raíz de clonado se pregunta una vez y queda escrita — también cuando la tabla la escribió alguien
458
+ # a mano y le falta la línea. Sin esto, una tabla nacida a mano vuelve a pedirla en cada corrida, que
459
+ # es la pregunta repetida que la decisión evita. Se inserta antes de la primera fila, y las filas
460
+ # corren dos líneas: por eso se vuelve a escanear.
461
+ if [ "$nacio" = "0" ] && [ "$declarada" = "0" ]; then
462
+ tmp_mounts="$mounts.os-tmp"
463
+ : > "$tmp_mounts"
464
+ puesto=0
465
+ while IFS= read -r line || [ -n "$line" ]; do
466
+ if [ "$puesto" = "0" ]; then
467
+ case "$line" in
468
+ '|'*) printf 'clone-root: `%s`\n\n' "$clone_root" >> "$tmp_mounts"; puesto=1 ;;
469
+ esac
470
+ fi
471
+ printf '%s\n' "$line" >> "$tmp_mounts"
472
+ done < "$mounts"
473
+ [ "$puesto" = "1" ] || printf 'clone-root: `%s`\n' "$clone_root" >> "$tmp_mounts"
474
+ mv "$tmp_mounts" "$mounts"
475
+ printf "$S_MOUNT_TABLE_CLONE_ROOT_ADDED\n" "$OS_MOUNTS_ARCHIVO" "$clone_root"
476
+ escanear_filas
477
+ fi
478
+
479
+ # Dos filas para el mismo remote no se resuelven en silencio: se usa la última y se dice cuáles había.
480
+ if [ "$n_filas" -gt 1 ]; then
481
+ printf "$S_MOUNT_TABLE_MANY_ROWS\n" \
482
+ "$OS_MOUNTS_ARCHIVO" "$n_filas" "$(lista_lineas "$filas_remote")"
483
+ fi
484
+
485
+ if [ -n "$fila_previa" ]; then
486
+ printf "$S_MOUNT_TABLE_ROW_ALREADY\n" "$OS_MOUNTS_ARCHIVO" "$fila_previa"
487
+ else
488
+ printf '| `%s` | `%s` |\n' "$remote" "$destino" >> "$mounts"
489
+ printf ' %s: | `%s` | `%s` |\n' "$OS_MOUNTS_ARCHIVO" "$remote" "$destino"
490
+ fi
491
+ [ "$nacio" = "1" ] && printf "$S_MOUNT_TABLE_BORN\n" "$OS_MOUNTS_ARCHIVO"
492
+
493
+ # --- la autorización del checkout (spec 030)
494
+ # Montar y autorizar son el mismo acto: el checkout queda legible sin prompt para el harness desde
495
+ # la próxima sesión, sin que el operador tenga que ponerlo a mano.
496
+ os_settings_authorize "$brain" "$destino"
497
+ case "$?" in
498
+ 0) printf "$S_MOUNT_SETTINGS_ADDED\n" "$OS_SETTINGS_ARCHIVO" "$destino" ;;
499
+ 1) printf "$S_MOUNT_SETTINGS_ALREADY\n" "$OS_SETTINGS_ARCHIVO" ;;
500
+ 2) printf "$S_MOUNT_SETTINGS_INVALID\n" "$OS_SETTINGS_ARCHIVO" "$brain/$OS_SETTINGS_ARCHIVO" ;;
501
+ esac
502
+
503
+ # La tabla no viaja: la frontera es el gitignore del brain, y la escribe el comando que crea el
504
+ # archivo. Y como todo archivo de solo contenido, declara su altura: el `tree.md` del brain es una
505
+ # copia del template, así que agregar el glob al template no lo agrega a los brains ya bootstrapeados.
506
+ if os_gitignore_ensure "$brain" "$OS_MOUNTS_ARCHIVO"; then
507
+ printf "$S_MOUNT_GITIGNORE_DECLARED\n" "$OS_MOUNTS_ARCHIVO"
508
+ fi
509
+ if os_gitignore_ensure "$brain" "$OS_SETTINGS_ARCHIVO"; then
510
+ printf "$S_MOUNT_GITIGNORE_DECLARED\n" "$OS_SETTINGS_ARCHIVO"
511
+ fi
512
+ os_tree_ensure "$brain" "$OS_MOUNTS_ARCHIVO"
513
+ case "$?" in
514
+ 0) printf "$S_MOUNT_TREE_GLOB_DECLARED\n" "$OS_MOUNTS_ARCHIVO" ;;
515
+ 2) printf "$S_MOUNT_TREE_MISSING\n" "$OS_MOUNTS_ARCHIVO" ;;
516
+ esac
517
+
518
+ # --- el remoto que todavía no existe (spec 034)
519
+ # Last lines of the birth, and the only thing left outside the system: the repo lives locally with
520
+ # `origin` declared, and creating the remote is the operator's act. `gh auth status` only reads; no
521
+ # other `gh` command runs from here, and nothing is ever pushed.
522
+ # Two commands, never `--source … --push`: over a checkout that already declares `origin`, gh adds
523
+ # the remote unconditionally, fails with "Unable to add remote origin" and does not push. And the
524
+ # name it is given is `owner/name` read from the remote itself: `gh repo create <name>` creates it
525
+ # under the authenticated user, which is not the owner the remote names.
526
+ if [ "$new" = "1" ]; then
527
+ slug=$(remote_github_slug "$remote")
528
+ autenticado=0
529
+ if command -v gh > /dev/null 2>&1; then
530
+ if gh auth status > /dev/null 2>&1 < /dev/null; then
531
+ autenticado=1
532
+ fi
533
+ fi
534
+ if [ "$autenticado" = "1" ] && [ -n "$slug" ]; then
535
+ printf '%s\n' "$S_MOUNT_NEW_REMOTE_GH"
536
+ printf "$S_MOUNT_NEW_REMOTE_GH_CREATE\n" "$slug"
537
+ else
538
+ printf "$S_MOUNT_NEW_REMOTE_MANUAL\n" "${slug:-$nombre}"
539
+ fi
540
+ printf "$S_MOUNT_NEW_REMOTE_PUSH\n" "$destino"
541
+ fi
542
+
543
+ exit 0
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env bash
2
+ # The gates of the mounted repos, for My Wiki's Overview (spec 062, C4). Internal: it is called by
3
+ # `my-wiki.sh` and has no `command:` header of its own.
4
+ #
5
+ # Usage: my-wiki-gates.sh — the mount rows arrive on stdin, one per line:
6
+ # remote<TAB>local path<TAB>last merge date
7
+ #
8
+ # Prints one row per gate, tab separated:
9
+ # gate<TAB>repo<TAB>spec file<TAB>title<TAB>date<TAB>branch
10
+ #
11
+ # gate `1` a spec of `specs/` that declares it is waiting for its Gate 1
12
+ # `2` a branch that declares `status: implementada` in `specs/done/` and is not merged
13
+ # date the day the row can be aged from: the spec file's own last change for a Gate 1, the
14
+ # branch's last commit for a Gate 2.
15
+ #
16
+ # GIT IS READ HERE AND NOWHERE ELSE. `my_wiki_overview.py` never shells out: the branch state of a
17
+ # repo is git's answer, and it arrives already resolved, the same way the tree and the mount table
18
+ # do. A repo this machine did not mount produces no rows and no error.
19
+
20
+ set -u
21
+
22
+ here=$(cd "$(dirname "$0")" && pwd)
23
+ . "$here/common.sh"
24
+
25
+ # A spec's `status:` that means "a person has to approve it before anything is implemented". The
26
+ # list is here, once: `pendiente`/`pending` is what the product writes today, and `esperando gate 1`
27
+ # is what a spec writes when it says so in full.
28
+ GATE1_STATES="pendiente pending esperando-gate-1 waiting-gate-1"
29
+ # What a branch declares when it says its work is finished and is asking to be merged.
30
+ GATE2_STATE="implementada"
31
+
32
+ norm() { printf '%s' "$1" | tr 'A-Z' 'a-z' | tr ' _' '--'; }
33
+
34
+ is_gate1() {
35
+ local want; want=$(norm "$1")
36
+ local s
37
+ for s in $GATE1_STATES; do [ "$want" = "$s" ] && return 0; done
38
+ return 1
39
+ }
40
+
41
+ # The last two segments of a remote — `owner/repo` — which is how a person names it.
42
+ short_repo() {
43
+ local r="${1%/}" last rest
44
+ case "$r" in *.git) r="${r%.git}" ;; esac
45
+ last="${r##*/}"
46
+ rest="${r%/*}"
47
+ if [ "$rest" = "$r" ]; then printf '%s' "$last"; else printf '%s/%s' "${rest##*/}" "$last"; fi
48
+ }
49
+
50
+ # The `status:` of a file's frontmatter, read off a stream. `fm_read` takes a path and this reads
51
+ # what `git show` prints, which never touches the working tree.
52
+ fm_status_of_stream() {
53
+ local line n=0
54
+ while IFS= read -r line; do
55
+ n=$(( n + 1 ))
56
+ if [ "$n" = "1" ]; then [ "$line" = "---" ] || return 0; continue; fi
57
+ [ "$line" = "---" ] && return 0
58
+ [ "$n" -ge 60 ] && return 0
59
+ case "$line" in
60
+ status:*) printf '%s' "$(os_trim "${line#status:}")"; return 0 ;;
61
+ estado:*) printf '%s' "$(os_trim "${line#estado:}")"; return 0 ;;
62
+ esac
63
+ done
64
+ return 0
65
+ }
66
+
67
+ # The `# ` heading of a file, read off the same stream.
68
+ title_of_stream() {
69
+ local line
70
+ while IFS= read -r line; do
71
+ case "$line" in '# '*) printf '%s' "${line#\# }"; return 0 ;; esac
72
+ done
73
+ return 0
74
+ }
75
+
76
+ while IFS= read -r row || [ -n "$row" ]; do
77
+ [ -n "$row" ] || continue
78
+ remote=""; path=""; i=0
79
+ while IFS= read -r cell; do
80
+ i=$(( i + 1 ))
81
+ [ "$i" = "1" ] && remote="$cell"
82
+ [ "$i" = "2" ] && path="$cell"
83
+ done <<CELLS
84
+ $(printf '%s' "$row" | tr '\t' '\n')
85
+ CELLS
86
+ [ -n "$path" ] || continue
87
+ [ -d "$path/.git" ] || continue
88
+ short=$(short_repo "$remote")
89
+
90
+ # --- Gate 1: a spec of the working tree that is waiting for a person to approve it.
91
+ if [ -d "$path/specs" ]; then
92
+ for file in "$path"/specs/*.md; do
93
+ [ -f "$file" ] || continue
94
+ fm_read "$file"
95
+ is_gate1 "${fm_status:-}" || continue
96
+ title=$(os_titulo "$file")
97
+ [ -n "$title" ] || title=$(basename "$file" .md)
98
+ when=$(git -C "$path" log -1 --format=%cs -- "specs/$(basename "$file")" 2>/dev/null || true)
99
+ [ -n "$when" ] || when=""
100
+ printf '1\t%s\t%s\t%s\t%s\t\n' "$short" "specs/$(basename "$file")" "$title" "$when"
101
+ done
102
+ fi
103
+
104
+ # --- Gate 2: a branch that declares itself finished and is not in the default branch yet.
105
+ #
106
+ # THE BRANCH IS READ FROM GIT, NEVER FROM THE WORKING TREE. What the checkout has on disk is one
107
+ # branch; a branch that finished and is waiting to be merged is usually not that one, and its
108
+ # `specs/done/` only exists inside the branch.
109
+ base=$(git -C "$path" symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null || true)
110
+ base="${base#origin/}"
111
+ if [ -z "$base" ]; then
112
+ for cand in main master; do
113
+ git -C "$path" rev-parse --verify --quiet "refs/heads/$cand" > /dev/null 2>&1 && { base="$cand"; break; }
114
+ done
115
+ fi
116
+ [ -n "$base" ] || continue
117
+ branches=$(git -C "$path" for-each-ref --format='%(refname:short)' refs/heads 2>/dev/null || true)
118
+ for branch in $branches; do
119
+ [ "$branch" = "$base" ] && continue
120
+ git -C "$path" merge-base --is-ancestor "$branch" "$base" > /dev/null 2>&1 && continue
121
+ # WHAT THE BRANCH ADDED, not what the branch holds: `specs/done/` drags along everything
122
+ # already merged, and every branch would claim the finished work of all the ones before it.
123
+ done_files=$(git -C "$path" diff --name-only --diff-filter=AM "$base...$branch" -- specs/done/ 2>/dev/null || true)
124
+ [ -n "$done_files" ] || continue
125
+ when=$(git -C "$path" log -1 --format=%cs "$branch" 2>/dev/null || true)
126
+ for done_file in $done_files; do
127
+ case "$done_file" in *.md) ;; *) continue ;; esac
128
+ state=$(git -C "$path" show "$branch:$done_file" 2>/dev/null | fm_status_of_stream)
129
+ [ "$(norm "${state:-}")" = "$GATE2_STATE" ] || continue
130
+ title=$(git -C "$path" show "$branch:$done_file" 2>/dev/null | title_of_stream)
131
+ [ -n "$title" ] || title=$(basename "$done_file" .md)
132
+ printf '2\t%s\t%s\t%s\t%s\t%s\n' "$short" "$done_file" "$title" "$when" "$branch"
133
+ done
134
+ done
135
+ done
136
+
137
+ exit 0