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
@@ -2,32 +2,46 @@
2
2
  # Parte determinística de `capture`: archiva un texto en el `backlog.md` de la iniciativa que
3
3
  # `core/skills/capture.md` nombra. Interno: no es invocable.
4
4
  #
5
- # Uso: capture.sh --brain DIR --text "TEXTO" --initiative SLUG
6
- # [--org SLUG | --workspace SLUG | --root] [--session-org SLUG] [--load-context]
5
+ # Uso: capture.sh --brain DIR --text "TEXTO" (--initiative SLUG | --about HEAD [--create])
6
+ # [--org SLUG | --workspace SLUG] [--session-org SLUG] [--load-context]
7
7
  # [--blocked-by REF] [--hold RAZON] [--hold-until FECHA]
8
8
  #
9
- # `--workspace` es sinónimo exacto de `--org` (spec 039). `--org`/`--workspace` y `--root` son
10
- # excluyentes.
9
+ # `--about HEAD` (spec 076, C30) files a task of an area node with no project of its own in the
10
+ # node's standing initiative: the one with `status: ongoing` whose `about:` names that head and
11
+ # nothing else, in the same workspace.
12
+ # - exactly one: the task goes to its backlog, as with `--initiative`;
13
+ # - none: nothing is written, the script prints on stdout the question the AI asks the operator
14
+ # —`CAPTURE_CREATE_QUESTION` of the strings catalog, in the language of the brain, with no word of
15
+ # the system's vocabulary— and exits 7;
16
+ # - none, with `--create` (the operator's yes, given in that turn): the initiative is created
17
+ # (`status: ongoing`, `about:` the head, the node's title, `os_ini_create`) and the task written.
18
+ # Its slug is the node's; if another initiative already uses it, the slug adds the node's type in
19
+ # the singular (`checkout-product`). The title stays the node's name, with no suffix. An
20
+ # initiative with that slug whose `about:` does not name the node is never reused;
21
+ # - two or more: nothing is written, they are named on stderr, exit 8.
22
+ #
23
+ # `--workspace` es sinónimo exacto de `--org` (spec 039).
11
24
  #
12
25
  # Spec 057, decisión 2: **nada entra sin clasificar**. `--initiative` es obligatorio siempre — sin
13
- # ella no se escribe nada, en ningún archivo: ni el backlog de la organización o de la raíz (que ya
14
- # no existen como destino de `capture`) ni el `inbox.md` de la raíz (deja de ser destino; su
15
- # desaparición de la raíz la resuelve la spec 059). La tarea va a
16
- # `<wsdir>/<org>/initiatives/<slug>/backlog.md`, o a `initiatives/<slug>/backlog.md` con `--root`,
17
- # en el formato de línea que el arranque de sesión ya lee. El id `tsk-XXX` sigue siendo único en
26
+ # ella no se escribe nada, en ningún archivo: ni el backlog de la organización (que ya no es destino
27
+ # de `capture`) ni el `inbox.md` de la raíz (la spec 059 lo saca de la raíz). La tarea va a
28
+ # `<wsdir>/<org>/initiatives/<slug>/backlog.md`, en el formato de línea que el arranque de sesión ya lee. El id `tsk-XXX` sigue siendo único en
18
29
  # todo el brain (decisión 3): sale de una pasada por cada `backlog.md` que el brain tenga
19
30
  # (`os_backlog_next_id`), nunca de un archivo de estado nuevo.
20
31
  #
21
- # El backlog de una iniciativa nunca declara su glob: `content: initiatives/*/*.md` (y su gemelo de
22
- # espacio de trabajo) ya lo alcanzan — a diferencia del backlog de organización o de raíz de antes de
23
- # esta spec, acá no hace falta escribir en `tree.md`.
32
+ # El backlog de una iniciativa nunca declara su glob: `content: <wsdir>/*/initiatives/*/*.md` ya lo
33
+ # alcanza — a diferencia del backlog de organización de antes de esta spec, acá no hace falta
34
+ # escribir en `tree.md`.
24
35
  #
25
- # La raíz no exige `--session-org` ni `--load-context`: su identidad (`operator.md`) está cargada en
26
- # cualquier sesión, a cualquier ámbito — no hay context cross-nodo que custodiar.
36
+ # `--root` ya no existe (spec 059): la raíz del brain solo tiene maquinaria, y el trabajo propio del
37
+ # operador es el espacio de trabajo `personal`, con el que todo brain nace — usar
38
+ # `--workspace personal`. El flag se acepta solo para frenar con ese destino, sin escribir nada.
27
39
  #
28
40
  # Exit: 0 escribió · 2 la organización no existe · 3 escritura cross-nodo sin el context cargado ·
29
41
  # 4 falta --initiative · 5 la iniciativa no existe en ese ámbito · 6 no se declaró ámbito (ni
30
- # --org/--workspace ni --root) — antes de esta spec ese caso caía en el inbox de la raíz.
42
+ # --org ni --workspace) — antes de la spec 057 ese caso caía en el inbox de la raíz · 7 `--about`
43
+ # sin iniciativa permanente: la pregunta está en stdout y no se escribió nada · 8 `--about` con dos
44
+ # o más iniciativas permanentes · 1 `--root` (spec 059) u otro argumento inválido.
31
45
 
32
46
  set -u
33
47
 
@@ -38,8 +52,9 @@ brain=""
38
52
  text=""
39
53
  org=""
40
54
  workspace=""
41
- root=0
42
55
  initiative=""
56
+ about=""
57
+ create=0
43
58
  session_org=""
44
59
  load_context=0
45
60
  blocked_by=""
@@ -49,17 +64,19 @@ hold_until_dado=0
49
64
 
50
65
  while [ $# -gt 0 ]; do
51
66
  case "$1" in
52
- --brain) brain="${2:-}"; shift 2 ;;
53
- --text) text="${2:-}"; shift 2 ;;
54
- --org) org="${2:-}"; shift 2 ;;
55
- --workspace) workspace="${2:-}"; shift 2 ;;
56
- --root) root=1; shift ;;
57
- --initiative) initiative="${2:-}"; shift 2 ;;
58
- --session-org) session_org="${2:-}"; shift 2 ;;
67
+ --brain) brain="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
68
+ --text) text="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
69
+ --org) org="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
70
+ --workspace) workspace="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
71
+ --root) os_die "--root ya no existe (spec 059): el trabajo propio del operador es el espacio de trabajo \"$OS_PERSONAL_WORKSPACE_SLUG\" — usá --workspace $OS_PERSONAL_WORKSPACE_SLUG. Si el brain todavía tiene trabajo suelto en la raíz, correr migrate-root.sh primero" ;;
72
+ --initiative) initiative="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
73
+ --about) about="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
74
+ --create) create=1; shift ;;
75
+ --session-org) session_org="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
59
76
  --load-context) load_context=1; shift ;;
60
- --blocked-by) blocked_by="${2:-}"; shift 2 ;;
61
- --hold) hold="${2:-}"; shift 2 ;;
62
- --hold-until) hold_until="${2:-}"; hold_until_dado=1; shift 2 ;;
77
+ --blocked-by) blocked_by="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
78
+ --hold) hold="${2:-}"; shift 2 || os_die "$1 needs a value" ;;
79
+ --hold-until) hold_until="${2:-}"; hold_until_dado=1; shift 2 || os_die "$1 needs a value" ;;
63
80
  *) os_die "argumento desconocido: $1" ;;
64
81
  esac
65
82
  done
@@ -72,7 +89,6 @@ fi
72
89
 
73
90
  [ -n "$brain" ] || os_die "falta --brain"
74
91
  [ -n "$text" ] || os_die "falta --text"
75
- [ "$root" = "0" ] || [ -z "$org" ] || os_die "--root y --org/--workspace son excluyentes"
76
92
  [ -d "$brain" ] || os_die "no existe el brain: $brain"
77
93
  brain=$(cd "$brain" && pwd)
78
94
 
@@ -89,45 +105,93 @@ text=$(os_una_linea "$text")
89
105
  hoy=$(date +%Y-%m-%d)
90
106
 
91
107
  # ---------------------------------------------------------------- el ámbito
92
- # El operador siempre está cargado —`operator.md` se lee en cualquier arranque, a cualquier ámbito—
93
- # así que la raíz no tiene escritura cross-nodo que custodiar: nunca pide `--session-org` ni
94
- # `--load-context`.
95
- if [ "$root" = "1" ]; then
96
- prefix=""
97
- ambito_label="la raíz"
98
- else
99
- # Sin --org/--workspace y sin --root no hay ámbito que resolver: antes de esta spec ese caso caía
100
- # en el inbox; ahora no hay inbox al que caer, así que se declara sin tocar nada, con el mismo
101
- # criterio que la falta de iniciativa de más abajo — spec 057, decisión 2.
102
- if [ -z "$org" ]; then
103
- printf 'no se declaró ámbito: capture no escribe nada sin --org/--workspace o --root.\n' >&2
104
- exit 6
105
- fi
106
- if ! os_org_existe "$brain" "$org"; then
107
- printf 'la organización "%s" no existe. Las que hay:\n' "$org" >&2
108
- slugs=$(os_org_slugs "$brain")
109
- if [ -n "$slugs" ]; then
110
- printf '%s\n' "$slugs" | while IFS= read -r s; do printf ' %s\n' "$s" >&2; done
111
- else
112
- printf ' (ninguna)\n' >&2
113
- fi
114
- exit 2
108
+ # Sin --org/--workspace no hay ámbito que resolver: antes de la spec 057 ese caso caía en el inbox;
109
+ # ahora no hay inbox al que caer, así que se declara sin tocar nada, con el mismo criterio que la
110
+ # falta de iniciativa de más abajo — spec 057, decisión 2.
111
+ if [ -z "$org" ]; then
112
+ printf 'no se declaró ámbito: capture no escribe nada sin --org/--workspace.\n' >&2
113
+ exit 6
114
+ fi
115
+ if ! os_org_existe "$brain" "$org"; then
116
+ printf 'la organización "%s" no existe. Las que hay:\n' "$org" >&2
117
+ slugs=$(os_org_slugs "$brain")
118
+ if [ -n "$slugs" ]; then
119
+ printf '%s\n' "$slugs" | while IFS= read -r s; do printf ' %s\n' "$s" >&2; done
120
+ else
121
+ printf ' (ninguna)\n' >&2
115
122
  fi
116
- prefix="$wsdir/$org/"
117
- ambito_label="\"$org\""
123
+ exit 2
118
124
  fi
125
+ prefix="$wsdir/$org/"
126
+ ambito_label="\"$org\""
119
127
 
120
128
  # ---------------------------------------------------------------- nada entra sin clasificar
121
129
  # Decisión 2 de la spec 057: sin iniciativa nombrada no
122
130
  # se escribe nada, en ningún archivo. Frena antes de tocar el brain — inclusive antes del chequeo de
123
131
  # escritura cross-nodo, que solo tiene sentido una vez que ya hay un destino.
132
+ [ -z "$initiative" ] || [ -z "$about" ] || os_die "--initiative y --about no van juntos: la tarea va a una sola iniciativa"
133
+ [ "$create" = "0" ] || [ -n "$about" ] || os_die "--create solo va con --about"
134
+
135
+ # ---------------------------------------------------------------- the standing initiative of a node (spec 076, C30)
136
+ crear_ini=0
137
+ if [ -n "$about" ]; then
138
+ about=$(os_rel_norm "$about")
139
+ head_name=$(os_head_file "$brain" || true)
140
+ case "$about" in
141
+ "$prefix"*) ;;
142
+ *) os_die "--about no es un nodo de $ambito_label: $about" ;;
143
+ esac
144
+ [ -f "$brain/$about" ] || os_die "--about no existe: $about"
145
+ case "$(os_head_kind "$wsdir" "$head_name" "$about")" in
146
+ "entity $org") ;;
147
+ *) os_die "--about no es la cabeza de un nodo de área (producto, curso, canal o cuenta): $about" ;;
148
+ esac
149
+ nodo_slug=$(os_entity_name "$about")
150
+ nodo_tipo="${about#"$prefix"}"; nodo_tipo="${nodo_tipo%%/*}"; nodo_tipo="${nodo_tipo%s}"
151
+ nodo_titulo=$(os_titulo "$brain/$about")
152
+ [ -n "$nodo_titulo" ] || nodo_titulo="$nodo_slug"
153
+ candidatas=""
154
+ n_candidatas=0
155
+ while IFS= read -r s_ini || [ -n "$s_ini" ]; do
156
+ [ -n "$s_ini" ] || continue
157
+ fm_read "$brain/$(os_ini_head_rel "$brain" "$prefix" "$s_ini")"
158
+ [ "$fm_status" = "ongoing" ] || continue
159
+ os_about_is_single "$fm_about" "$about" || continue
160
+ n_candidatas=$(( n_candidatas + 1 ))
161
+ candidatas="$candidatas $s_ini"
162
+ done <<INIS
163
+ $(os_ini_slugs "$brain" "$prefix")
164
+ INIS
165
+ if [ "$n_candidatas" -gt 1 ]; then
166
+ printf 'dos o más iniciativas permanentes para %s; nombrá una con --initiative:%s\n' "$about" "$candidatas" >&2
167
+ exit 8
168
+ fi
169
+ if [ "$n_candidatas" = "1" ]; then
170
+ initiative="${candidatas# }"
171
+ else
172
+ initiative="$nodo_slug"
173
+ if os_ini_existe "$brain" "$prefix" "$initiative" || [ -e "$brain/${prefix}initiatives/$initiative" ]; then
174
+ initiative="$nodo_slug-$nodo_tipo"
175
+ fi
176
+ if os_ini_existe "$brain" "$prefix" "$initiative" || [ -e "$brain/${prefix}initiatives/$initiative" ]; then
177
+ os_die "los slugs $nodo_slug y $initiative ya los usan otras iniciativas: nombrá una con --initiative"
178
+ fi
179
+ if [ "$create" = "0" ]; then
180
+ os_lang_load "$(os_language "$brain")"
181
+ printf "$S_CAPTURE_CREATE_QUESTION\n" "$nodo_titulo" "$nodo_titulo"
182
+ exit 7
183
+ fi
184
+ crear_ini=1
185
+ fi
186
+ fi
187
+
124
188
  if [ -z "$initiative" ]; then
125
189
  printf 'falta la iniciativa: capture no escribe nada sin --initiative.\n' >&2
126
190
  printf 'nombrala vos, o proponé una y esperá que el operador la confirme, y repetí con --initiative <slug>.\n' >&2
127
191
  exit 4
128
192
  fi
129
193
 
130
- if ! os_ini_existe "$brain" "$prefix" "$initiative"; then
194
+ if [ "$crear_ini" = "0" ] && ! os_ini_existe "$brain" "$prefix" "$initiative"; then
131
195
  printf 'la iniciativa "%s" no existe en %s. Las que hay:\n' "$initiative" "$ambito_label" >&2
132
196
  slugs=$(os_ini_slugs "$brain" "$prefix")
133
197
  if [ -n "$slugs" ]; then
@@ -144,9 +208,9 @@ fi
144
208
  # recordar. La excepción es la escritura cross-nodo — el resolver del destino no está cargado y el
145
209
  # agente archiva a ciegas, dejando el dato mal archivado en el nodo equivocado y en silencio.
146
210
  # Un ámbito de sesión sin declarar cuenta como no cargado: suponer lo contrario es la misma ceguera.
147
- if [ "$root" = "0" ] && [ "$session_org" != "$org" ]; then
211
+ if [ "$session_org" != "$org" ]; then
148
212
  ctx="$wsdir/$org/$(os_head_file "$brain" || true)"
149
- res="$wsdir/$org/resolver.md"
213
+ res="$wsdir/$org/.resolver.md"
150
214
  if [ "$load_context" = "0" ]; then
151
215
  printf 'escritura cross-nodo: la sesión está parada en "%s" y esto se escribe en "%s".\n' \
152
216
  "${session_org:-(ningún ámbito declarado)}" "$org" >&2
@@ -166,6 +230,13 @@ if [ "$root" = "0" ] && [ "$session_org" != "$org" ]; then
166
230
  printf -- '---\n'
167
231
  fi
168
232
 
233
+ # ---------------------------------------------------------------- the standing initiative is born (spec 076, C30)
234
+ if [ "$crear_ini" = "1" ]; then
235
+ os_ini_create "$brain" "$prefix" "$initiative" "$nodo_titulo" ongoing "$about" \
236
+ || os_die "no se pudo crear la iniciativa: ${prefix}initiatives/$initiative"
237
+ printf 'iniciativa creada: %s\n' "$(os_ini_head_rel "$brain" "$prefix" "$initiative")"
238
+ fi
239
+
169
240
  # ---------------------------------------------------------------- el backlog de la iniciativa
170
241
  backlog_rel=$(os_ini_backlog_rel "$prefix" "$initiative")
171
242
  backlog="$brain/$backlog_rel"
@@ -42,10 +42,11 @@ brain=$(cd "$brain" && pwd)
42
42
  #
43
43
  # Dos globs de pack, porque hay dos formas de tener un pack instalado:
44
44
  # `.os/packs/*/resolver.md` el pack enganchado por symlink desde el producto (017)
45
- # `.claude/skills/*-resolver/SKILL.md` el pack bajado por el CLI de skills.sh (026)
45
+ # `.agents/skills/*-resolver/SKILL.md` el pack bajado por el CLI de skills.sh (026), donde lo
46
+ # `.claude/skills/*-resolver/SKILL.md` deja primero; el enlace de la segunda cuenta una vez (076)
46
47
  # Un glob que no matchea no aporta filas: un brain sin ningún pack audita exactamente igual que
47
48
  # antes. El orden de lectura completo se enuncia en `core/CLAUDE.md`, no acá.
48
- RESOLVERS=".os/core/resolver.md .os/packs/*/resolver.md .claude/skills/*-resolver/SKILL.md resolver.md"
49
+ RESOLVERS=".os/core/resolver.md .os/packs/*/resolver.md .agents/skills/*-resolver/SKILL.md .claude/skills/*-resolver/SKILL.md $OS_ROOT_RESOLVER_FILE"
49
50
 
50
51
  hallazgos=""
51
52
  n_hallazgos=0
@@ -61,10 +62,20 @@ filas="" # capacidad-en-minúsculas por línea
61
62
  herramientas="" # nombre de herramienta por línea
62
63
  n_filas=0
63
64
 
65
+ skills_vistas=""
64
66
  for pat in $RESOLVERS; do
65
67
  for file in "$brain"/$pat; do
66
68
  [ -f "$file" ] || continue
67
69
  rel="${file#$brain/}"
70
+ # A pack present in both skills folders (the link `npx skills add` leaves) counts once, under the
71
+ # first folder of the lookup order (spec 076, C10).
72
+ case "$pat" in
73
+ */skills/*-resolver/SKILL.md)
74
+ nombre_skill=$(basename "$(dirname "$file")")
75
+ case "$nl$skills_vistas" in *"$nl$nombre_skill$nl"*) continue ;; esac
76
+ skills_vistas="$skills_vistas$nombre_skill$nl"
77
+ ;;
78
+ esac
68
79
  n=0
69
80
  while IFS= read -r line || [ -n "$line" ]; do
70
81
  n=$(( n + 1 ))