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,6 +4,7 @@
4
4
  #
5
5
  # Usage: supersede.sh --brain DIR --file PATH --by PATH
6
6
  # supersede.sh --brain DIR --check
7
+ # supersede.sh --brain DIR --file PATH --unmark
7
8
  #
8
9
  # Git does not answer "is this document still current?": the agent reads the working tree, never the
9
10
  # history. A research file from March and one from July that contradicts it are two equally valid
@@ -62,6 +63,20 @@
62
63
  # In those three the mark is written, the head is left as it was, the output names the reason, and
63
64
  # the exit code is 3 so that a script never reads the pending decision as a plain success.
64
65
  #
66
+ # THE CALLOUT (spec 077). Next to the key, the mark writes one line at the top of the body, right
67
+ # after the frontmatter, followed by a blank line: `> [!WARNING] This file was replaced by <path>`
68
+ # (`SUPERSEDE_CALLOUT` of the strings catalog, in the language of the brain). A reader who opens the
69
+ # file in Obsidian or GitHub sees it without reading the frontmatter. Running the mark again changes
70
+ # nothing; marking with another `--by` rewrites that one line; `--unmark` removes the key and the
71
+ # callout and leaves the rest of the file byte for byte as it was before the mark. The callout is
72
+ # recognised by an ownership marker at the end of its line (`<!-- os:superseded -->`, hidden when
73
+ # rendered), never by its text, so a warning someone wrote by hand is never touched and a callout in
74
+ # another language is still found after the brain changes language. The variant `os:superseded:fm`
75
+ # records that the mark created the frontmatter block of a file that had none: only then does the
76
+ # unmark remove a frontmatter it leaves empty. The key is written and removed with the reader's
77
+ # whitespace rule, and everything else in the file is copied byte for byte. The audit
78
+ # (`--check`) reads only the key and does not look at the callout.
79
+ #
65
80
  # Exit: 0 wrote, or the file already said the same thing · 1 invalid arguments, a refusal, or
66
81
  # `--check` with findings · 2 a named file does not exist · 3 the mark was written and the head
67
82
  # needs a decision from the operator.
@@ -87,6 +102,7 @@ brain=""
87
102
  file=""
88
103
  by=""
89
104
  check=0
105
+ unmark=0
90
106
  # A flag that takes a value checks that the value is there before consuming it: with the flag as the
91
107
  # last argument, `shift 2` fails without consuming anything and the loop repeats forever.
92
108
  while [ $# -gt 0 ]; do
@@ -95,6 +111,7 @@ while [ $# -gt 0 ]; do
95
111
  --file) [ $# -ge 2 ] || os_die "--file needs a value"; file="$2"; shift 2 ;;
96
112
  --by) [ $# -ge 2 ] || os_die "--by needs a value"; by="$2"; shift 2 ;;
97
113
  --check) check=1; shift ;;
114
+ --unmark) unmark=1; shift ;;
98
115
  *) os_die "unknown argument: $1" ;;
99
116
  esac
100
117
  done
@@ -105,6 +122,9 @@ brain=$(cd "$brain" && pwd)
105
122
 
106
123
  if [ "$check" = "1" ]; then
107
124
  { [ -z "$file" ] && [ -z "$by" ]; } || os_die "--check is exclusive with --file and --by"
125
+ elif [ "$unmark" = "1" ]; then
126
+ [ -n "$file" ] || os_die "--unmark needs --file"
127
+ [ -z "$by" ] || os_die "--unmark is exclusive with --by"
108
128
  else
109
129
  [ -n "$file" ] || os_die "missing --file or --check"
110
130
  [ -n "$by" ] || os_die "missing --by"
@@ -188,6 +208,137 @@ alcanzado() {
188
208
  return 1
189
209
  }
190
210
 
211
+ # ---------------------------------------------------------------- the callout of the mark (spec 077)
212
+ # The managed callout carries its ownership in a trailing HTML comment: `<!-- os:superseded -->`, or
213
+ # `<!-- os:superseded:fm -->` when the mark created the frontmatter block of a file that had none. The
214
+ # marker is what makes a callout the command's own — never its text, so a warning written by hand, even
215
+ # one that opens with the same words, is left verbatim, and a callout written in another language is
216
+ # still recognised after the brain changes language.
217
+ CALLOUT_MARK='<!-- os:superseded -->'
218
+ CALLOUT_MARK_FM='<!-- os:superseded:fm -->'
219
+
220
+ # fm_end FILE -> prints the number of the line that closes the frontmatter (the second `---`). Only
221
+ # called on a file whose frontmatter `fm_read` could read.
222
+ fm_end() {
223
+ local l n=0 hits=0
224
+ while IFS= read -r l || [ -n "$l" ]; do
225
+ n=$(( n + 1 ))
226
+ if [ "$l" = "---" ]; then
227
+ hits=$(( hits + 1 ))
228
+ if [ "$hits" = "2" ]; then printf '%s' "$n"; return 0; fi
229
+ fi
230
+ done < "$1"
231
+ return 1
232
+ }
233
+
234
+ # callout_managed LINE -> 0 if the line is a callout this command wrote (it ends with the marker).
235
+ callout_managed() {
236
+ case "$1" in
237
+ "> [!WARNING] "*"$CALLOUT_MARK"|"> [!WARNING] "*"$CALLOUT_MARK_FM") return 0 ;;
238
+ esac
239
+ return 1
240
+ }
241
+
242
+ # callout_created_fm LINE -> 0 if the managed callout says the mark created the frontmatter block.
243
+ callout_created_fm() {
244
+ case "$1" in *"$CALLOUT_MARK_FM") return 0 ;; esac
245
+ return 1
246
+ }
247
+
248
+ # callout_set RELFILE BY [new-fm] -> the callout is the first line of the body with the text for BY,
249
+ # followed by a blank line. Byte-exact for everything else: the file is spliced with head and tail,
250
+ # never re-read line by line. An existing managed callout keeps its `:fm` flag. Returns 1 on failure.
251
+ callout_set() {
252
+ local f="$brain/$1" end next line tmp mark="$CALLOUT_MARK"
253
+ end=$(fm_end "$f") || return 1
254
+ next=$(tail -n +"$(( end + 1 ))" "$f" | head -n 1)
255
+ if { [ "${3:-}" = "new-fm" ]; } || { callout_managed "$next" && callout_created_fm "$next"; }; then
256
+ mark="$CALLOUT_MARK_FM"
257
+ fi
258
+ line="> [!WARNING] $(printf "$S_SUPERSEDE_CALLOUT" "$2") $mark"
259
+ tmp="$f.os-tmp"
260
+ rm -f "$tmp"
261
+ if callout_managed "$next"; then
262
+ if ! { head -n "$end" "$f"; printf '%s\n' "$line"; tail -n +"$(( end + 2 ))" "$f"; } 2>/dev/null > "$tmp"; then rm -f "$tmp"; return 1; fi
263
+ else
264
+ if ! { head -n "$end" "$f"; printf '%s\n\n' "$line"; tail -n +"$(( end + 1 ))" "$f"; } 2>/dev/null > "$tmp"; then rm -f "$tmp"; return 1; fi
265
+ fi
266
+ os_replace_file "$tmp" "$f"
267
+ }
268
+
269
+ # callout_unset RELFILE -> removes the managed callout and the blank line that follows it, if there.
270
+ callout_unset() {
271
+ local f="$brain/$1" end next after skip tmp
272
+ end=$(fm_end "$f") || return 1
273
+ next=$(tail -n +"$(( end + 1 ))" "$f" | head -n 1)
274
+ callout_managed "$next" || return 0
275
+ after=$(tail -n +"$(( end + 2 ))" "$f" | head -n 1)
276
+ skip=$(( end + 2 ))
277
+ [ -z "$after" ] && [ "$(tail -n +"$(( end + 2 ))" "$f" | wc -c | tr -d ' ')" != "0" ] && skip=$(( end + 3 ))
278
+ tmp="$f.os-tmp"
279
+ rm -f "$tmp"
280
+ if ! { head -n "$end" "$f"; tail -n +"$skip" "$f"; } 2>/dev/null > "$tmp"; then rm -f "$tmp"; return 1; fi
281
+ os_replace_file "$tmp" "$f"
282
+ }
283
+
284
+ # is_key LINE KEY -> 0 if the frontmatter line is that key, with the reader's rule (`fm_read`): the text
285
+ # before the first colon, without the spaces around it.
286
+ is_key() {
287
+ local k="${1%%:*}"
288
+ case "$1" in *:*) ;; *) return 1 ;; esac
289
+ while [ "${k# }" != "$k" ]; do k="${k# }"; done
290
+ while [ "${k% }" != "$k" ]; do k="${k% }"; done
291
+ [ "$k" = "$2" ]
292
+ }
293
+
294
+ # fm_key_set RELFILE KEY VALUE -> sets the key inside the frontmatter (replacing a line that holds it,
295
+ # otherwise before the closing `---`) and copies the body byte for byte, so a body with no final
296
+ # newline keeps having none.
297
+ fm_key_set() {
298
+ local f="$brain/$1" key="$2" value="$3" end l n=0 put=0 tmp
299
+ end=$(fm_end "$f") || return 1
300
+ tmp="$f.os-tmp"
301
+ rm -f "$tmp"
302
+ if ! {
303
+ while IFS= read -r l || [ -n "$l" ]; do
304
+ n=$(( n + 1 ))
305
+ [ "$n" -le "$end" ] || break
306
+ if [ "$n" -gt 1 ] && [ "$n" -lt "$end" ] && is_key "$l" "$key"; then
307
+ if [ "$put" = "0" ]; then printf '%s: %s\n' "$key" "$value"; put=1; fi
308
+ continue
309
+ fi
310
+ if [ "$n" = "$end" ] && [ "$put" = "0" ]; then printf '%s: %s\n' "$key" "$value"; put=1; fi
311
+ printf '%s\n' "$l"
312
+ done < "$f"
313
+ tail -n +"$(( end + 1 ))" "$f"
314
+ } 2>/dev/null > "$tmp"; then rm -f "$tmp"; return 1; fi
315
+ os_replace_file "$tmp" "$f"
316
+ }
317
+
318
+ # key_unset RELFILE DROP_EMPTY -> removes every `superseded_by` line of the frontmatter (the reader's
319
+ # whitespace rule); with DROP_EMPTY=1 a frontmatter left with nothing in it goes too. The key must be
320
+ # gone afterwards, or it fails.
321
+ key_unset() {
322
+ local f="$brain/$1" drop="$2" end l n=0 kept="" tmp
323
+ end=$(fm_end "$f") || return 1
324
+ tmp="$f.os-tmp"
325
+ rm -f "$tmp"
326
+ while IFS= read -r l || [ -n "$l" ]; do
327
+ n=$(( n + 1 ))
328
+ [ "$n" -le "$end" ] || break
329
+ if [ "$n" -gt 1 ] && [ "$n" -lt "$end" ] && is_key "$l" superseded_by; then continue; fi
330
+ kept="$kept$l$nl"
331
+ done < "$f"
332
+ if ! {
333
+ if [ "$drop" = "1" ] && [ "$kept" = "---$nl---$nl" ]; then :; else printf '%s' "$kept"; fi
334
+ tail -n +"$(( end + 1 ))" "$f"
335
+ } 2>/dev/null > "$tmp"; then rm -f "$tmp"; return 1; fi
336
+ os_replace_file "$tmp" "$f" || return 1
337
+ fm_read "$f"
338
+ [ -z "$fm_superseded_by" ] || return 1
339
+ return 0
340
+ }
341
+
191
342
  # ================================================================ --check
192
343
  if [ "$check" = "1" ]; then
193
344
  hallazgos=""
@@ -255,6 +406,40 @@ TODOS
255
406
  exit 1
256
407
  fi
257
408
 
409
+ # ================================================================ --unmark
410
+ if [ "$unmark" = "1" ]; then
411
+ file=$(rel_norm "$file")
412
+ rel_ok "$file" || os_die "--file is not a path relative to the brain: $file"
413
+ case "$file" in
414
+ *.md) ;;
415
+ *) printf "$S_SUPERSEDE_NOT_MD\n" "$file" >&2; exit 1 ;;
416
+ esac
417
+ inside_brain "$file" || { printf "$S_SUPERSEDE_OUT_OF_BRAIN\n" "$file" >&2; exit 1; }
418
+ if [ -L "$brain/$file" ]; then printf "$S_SUPERSEDE_IS_LINK\n" "$file" >&2; exit 1; fi
419
+ [ -f "$brain/$file" ] || { printf "$S_SUPERSEDE_NO_FILE\n" "$file" >&2; exit 2; }
420
+ alcanzado "$file" || { printf "$S_SUPERSEDE_NOT_IN_TREE\n" "$file" >&2; exit 1; }
421
+ fm_of "$file"
422
+ if [ -n "$fm_roto" ]; then
423
+ case "$fm_roto" in
424
+ 'sin frontmatter') printf "$S_SUPERSEDE_NOT_MARKED\n" "$file"; exit 0 ;;
425
+ *) printf "$S_SUPERSEDE_UNREADABLE\n" "$file" "$fm_roto" >&2; exit 1 ;;
426
+ esac
427
+ fi
428
+ if [ -z "$fm_superseded_by" ]; then
429
+ printf "$S_SUPERSEDE_NOT_MARKED\n" "$file"
430
+ exit 0
431
+ fi
432
+ drop=0
433
+ first=$(tail -n +"$(( $(fm_end "$brain/$file") + 1 ))" "$brain/$file" | head -n 1)
434
+ if callout_managed "$first" && callout_created_fm "$first"; then drop=1; fi
435
+ callout_unset "$file" && key_unset "$file" "$drop" || {
436
+ printf "$S_SUPERSEDE_WRITE_FAILED\n" "$file" >&2
437
+ exit 1
438
+ }
439
+ printf "$S_SUPERSEDE_UNMARKED\n" "$file"
440
+ exit 0
441
+ fi
442
+
258
443
  # ================================================================ writing the mark
259
444
  file=$(rel_norm "$file")
260
445
  by=$(rel_norm "$by")
@@ -314,6 +499,10 @@ fm_of "$file"
314
499
  case "$fm_roto" in
315
500
  "")
316
501
  if [ "$fm_superseded_by" = "$by" ]; then
502
+ callout_set "$file" "$by" || {
503
+ printf "$S_SUPERSEDE_WRITE_FAILED\n" "$file" >&2
504
+ exit 1
505
+ }
317
506
  printf "$S_SUPERSEDE_ALREADY\n" "$file" "$by"
318
507
  exit 0
319
508
  fi
@@ -323,7 +512,11 @@ case "$fm_roto" in
323
512
  printf "$S_SUPERSEDE_NOT_FRONTMATTER\n" "$file" >&2
324
513
  exit 1
325
514
  }
326
- os_fm_set "$brain/$file" superseded_by "$by" || {
515
+ fm_key_set "$file" superseded_by "$by" || {
516
+ printf "$S_SUPERSEDE_WRITE_FAILED\n" "$file" >&2
517
+ exit 1
518
+ }
519
+ callout_set "$file" "$by" || {
327
520
  printf "$S_SUPERSEDE_WRITE_FAILED\n" "$file" >&2
328
521
  exit 1
329
522
  }
@@ -338,7 +531,6 @@ case "$fm_roto" in
338
531
  printf -- '---\n'
339
532
  printf 'superseded_by: %s\n' "$by"
340
533
  printf -- '---\n'
341
- printf '\n'
342
534
  cat "$brain/$file"
343
535
  } 2>/dev/null > "$tmp"; then
344
536
  rm -f "$tmp"
@@ -349,6 +541,10 @@ case "$fm_roto" in
349
541
  printf "$S_SUPERSEDE_WRITE_FAILED\n" "$file" >&2
350
542
  exit 1
351
543
  }
544
+ callout_set "$file" "$by" new-fm || {
545
+ printf "$S_SUPERSEDE_WRITE_FAILED\n" "$file" >&2
546
+ exit 1
547
+ }
352
548
  ;;
353
549
  *)
354
550
  # Unclosed, or over `CAP_FRONTMATTER`. Writing over a frontmatter that cannot be read is
@@ -415,7 +611,7 @@ if es_cabeza "$file"; then
415
611
  pendiente=1
416
612
  motivo=$(printf "$S_SUPERSEDE_HEAD_DEPENDED_ON" "$file" "$dependientes" "$by")
417
613
  elif [ "$estado" = "active" ]; then
418
- os_fm_set "$brain/$file" status closed || {
614
+ fm_key_set "$file" status closed || {
419
615
  printf "$S_SUPERSEDE_WRITE_FAILED\n" "$file" >&2
420
616
  exit 1
421
617
  }
package/core/lib/sweep.sh CHANGED
@@ -108,6 +108,10 @@ os_canon_check() {
108
108
  carpeta="$brain/${prefijo}${nombre}"
109
109
  relidx="${prefijo}${nombre}.md"
110
110
  nl2=$(printf '\nx'); nl2="${nl2%x}"
111
+ # Since spec 076 a workspace keeps no hand-written index: `decisions/index.md` and
112
+ # `learnings/index.md` are generated from the files themselves, so there is nothing to keep in sync
113
+ # and nothing to check. The check stays for a brain that still has the hand-written one.
114
+ [ -f "$idx" ] || return 0
111
115
  if [ -f "$idx" ]; then
112
116
  while IFS= read -r line || [ -n "$line" ]; do
113
117
  case "$line" in
@@ -127,6 +131,7 @@ os_canon_check() {
127
131
  for f in "$carpeta"/*.md; do
128
132
  [ -e "$f" ] || continue
129
133
  base=$(basename "$f")
134
+ [ "$base" = "index.md" ] && continue
130
135
  rel="$nombre/$base"
131
136
  case "$nl2$linked" in
132
137
  *"$nl2$rel$nl2"*) ;;