ai-first-os 1.10.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -31
- package/core/CLAUDE.md +48 -12
- package/core/VERSION +1 -1
- package/core/install.sh +173 -52
- package/core/lib/bootstrap.sh +41 -26
- package/core/lib/build-indexes.sh +283 -0
- package/core/lib/capture.sh +126 -55
- package/core/lib/check-resolvable.sh +13 -2
- package/core/lib/close-session.sh +172 -119
- package/core/lib/common.sh +505 -92
- package/core/lib/focus-read.sh +94 -58
- package/core/lib/manual-link.sh +10 -8
- package/core/lib/markdown.py +2 -2
- package/core/lib/migrate-layout.sh +92 -0
- package/core/lib/migrate-root.sh +497 -0
- package/core/lib/migrate_layout.py +2000 -0
- package/core/lib/new-memory.sh +33 -44
- package/core/lib/new-product.sh +11 -13
- package/core/lib/new-workspace.sh +18 -9
- package/core/lib/orchestrator-init.sh +80 -0
- package/core/lib/pack-install.sh +44 -30
- package/core/lib/recall.sh +1 -1
- package/core/lib/recall_index.py +48 -6
- package/core/lib/remote-backup.sh +30 -20
- package/core/lib/rename-heads.sh +8 -8
- package/core/lib/rename-workspaces.sh +3 -3
- package/core/lib/session-read.sh +133 -73
- package/core/lib/session-start.sh +238 -221
- package/core/lib/supersede.sh +199 -3
- package/core/lib/sweep.sh +5 -0
- package/core/manual/COMO-FUNCIONA.md +169 -58
- package/core/manual/HOW-IT-WORKS.md +158 -57
- package/core/resolver.md +4 -2
- package/core/skills/bootstrap.md +63 -44
- package/core/skills/capture.md +15 -8
- package/core/skills/check-resolvable.md +1 -1
- package/core/skills/close-session.md +9 -5
- package/core/skills/grill.md +3 -3
- package/core/skills/migrate-layout.md +48 -0
- package/core/skills/migrate-root.md +64 -0
- package/core/skills/mount-repo.md +6 -6
- package/core/skills/new-memory.md +20 -18
- package/core/skills/new-product.md +4 -3
- package/core/skills/new-spec.md +6 -0
- package/core/skills/new-workspace.md +7 -5
- package/core/skills/orchestrator.md +101 -0
- package/core/skills/supersede.md +14 -0
- package/core/templates/node-repo/context/open-questions.md +3 -0
- package/core/templates/strings.md +396 -271
- package/core/templates/tree.md +22 -27
- package/package.json +1 -1
- package/core/lib/my-wiki-gates.sh +0 -137
- package/core/lib/my-wiki.sh +0 -202
- package/core/lib/my_wiki_build.py +0 -548
- package/core/lib/my_wiki_graph.py +0 -137
- package/core/lib/my_wiki_overview.py +0 -392
- package/core/skills/my-wiki.md +0 -103
- package/core/templates/my-wiki-graph.js +0 -431
- package/core/templates/my-wiki-overview.js +0 -174
- package/core/templates/my-wiki.html +0 -1017
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# migrate-root.sh — moves the operator's own work, written before spec 059 directly at the brain's
|
|
3
|
+
# root, into the `personal` folder under this brain's own workspaces folder (`os_ws_dir`, spec 039 —
|
|
4
|
+
# `workspaces/` on a brain born today, the older name on one that has not renamed it yet), the
|
|
5
|
+
# workspace every brain is born with today. Internal: not invocable, run at the operator's request
|
|
6
|
+
# only — never from install.sh, bootstrap.sh or any startup script.
|
|
7
|
+
#
|
|
8
|
+
# Usage: migrate-root.sh --brain DIR [--mounts-reviewed]
|
|
9
|
+
#
|
|
10
|
+
# Same discipline as rename-workspaces.sh (spec 039's precedent, cited by spec 059): on request only,
|
|
11
|
+
# resumable, moves only structure and rewrites only routing, lists the rest, never commits.
|
|
12
|
+
#
|
|
13
|
+
# WHAT MOVES — one item at a time, each a single rename, when present at the brain's root:
|
|
14
|
+
# - initiatives/<entry> → <wsdir>/personal/initiatives/<entry>: a folder (with its own
|
|
15
|
+
# `backlog.md`, spec 057, and its `archive/`) or a loose file of the old head shape (spec 040)
|
|
16
|
+
# - <type>/<entry>, for every memory-node type the root declares in tree.md (spec 041)
|
|
17
|
+
# - backlog.md → <wsdir>/personal/backlog.md, where the startup declares it as a backlog outside an
|
|
18
|
+
# initiative (spec 057); `migrate-backlogs.sh` splits it, and the verdict names that command
|
|
19
|
+
# - decisions.md, decisions/, learnings.md, learnings/ → the same names under personal: a body's
|
|
20
|
+
# link inside its index is relative to the node, so moving index and folder keeps every link
|
|
21
|
+
# - inbox.md never moves: when it holds nothing but whitespace it is deleted; otherwise every
|
|
22
|
+
# non-blank line is listed for the operator to route by hand and the file stays (decision 4)
|
|
23
|
+
# What never moves: operator.md, voice.md, voice/, mounts.md, resolver.md, tree.md, roles/.
|
|
24
|
+
#
|
|
25
|
+
# STOPS before moving anything, exit 1, naming the reason:
|
|
26
|
+
# - `<wsdir>/personal` already exists and this migration did not create it (spec 059's stop
|
|
27
|
+
# condition: merging two workspaces is not this command's job);
|
|
28
|
+
# - the destination of an item already exists;
|
|
29
|
+
# - a mounted repo (each local path in a row of mounts.md's table that exists) references the root
|
|
30
|
+
# path of an initiative or a memory node about to move (spec 059's stop condition: a mounted repo
|
|
31
|
+
# is code, never migrated from the brain). The stop names every hit, file and line; once the
|
|
32
|
+
# operator has read them and decided they can stay — a repo's own history, a fixture that only
|
|
33
|
+
# shares the name — `--mounts-reviewed` runs the migration and lists them again as findings. A
|
|
34
|
+
# repo is never written. Generic names —`backlog.md`, `decisions.md`, `decisions/`…— are not
|
|
35
|
+
# looked for there: a repo has its own, and they cannot be told apart.
|
|
36
|
+
# And stops midway, exit 1, when a move does not leave its source gone and its destination present.
|
|
37
|
+
#
|
|
38
|
+
# RESUMABLE BY INSPECTION. Before its first write the run records its state —that it created
|
|
39
|
+
# personal, the root's memory types, and every move it is about to make— in `.os/migrate-root.state`
|
|
40
|
+
# (the installation's own folder, never versioned). A later run reads it back: a run cut after any
|
|
41
|
+
# move still knows that personal is its own, which paths moved where, and which rewrites are
|
|
42
|
+
# pending. The file is deleted when a run reaches its end. With no root item, no pending state and
|
|
43
|
+
# no inbox there is nothing to do: it says so and changes nothing.
|
|
44
|
+
#
|
|
45
|
+
# REWRITES, from the moves actually made (the map in the state file, never a fixed prefix list):
|
|
46
|
+
# - tree.md: every root-height line (glob/content/archive) whose pattern starts with a moved root
|
|
47
|
+
# name becomes the same line under `<wsdir>/*/` (declared with os_tree_ensure, then read back),
|
|
48
|
+
# and the root line goes; `glob: inbox.md` goes once inbox.md is gone.
|
|
49
|
+
# - the `about:` line of every head under personal whose value names a moved path.
|
|
50
|
+
# - routing: the root's resolver.md, mounts.md, and every resolver.md and backlog.md under
|
|
51
|
+
# personal. Never another workspace's files: a bare `initiatives/x` there is relative to that
|
|
52
|
+
# workspace, not to the root. A moved path is rewritten only right after a start-of-line, space,
|
|
53
|
+
# tab, backtick, pipe, paren, quote, `[` or `<`, and only when what follows ends the path — never
|
|
54
|
+
# after a slash, colon, dot, dash, underscore, letter or digit: that is a URL or someone else's.
|
|
55
|
+
# Everything else that still names a moved path is listed with its count, for the operator. Outside
|
|
56
|
+
# the root's own files only the distinctive paths (an initiative's or a memory node's) are counted.
|
|
57
|
+
#
|
|
58
|
+
# Exit: 0 nothing to migrate, or migrated (findings notwithstanding) · 1 stopped, with the reason.
|
|
59
|
+
#
|
|
60
|
+
# `OS_MIGRATE_ROOT_INTERRUPT_AFTER=N` (evals only) exits 3 right after the Nth move, the way a
|
|
61
|
+
# killed run would leave the brain — it is how the suite proves the resume.
|
|
62
|
+
#
|
|
63
|
+
# No `set -e` on purpose: every step checks its own result and says which one failed.
|
|
64
|
+
|
|
65
|
+
set -u
|
|
66
|
+
|
|
67
|
+
here=$(cd "$(dirname "$0")" && pwd)
|
|
68
|
+
. "$here/common.sh"
|
|
69
|
+
|
|
70
|
+
brain=""
|
|
71
|
+
mounts_reviewed=0
|
|
72
|
+
while [ $# -gt 0 ]; do
|
|
73
|
+
case "$1" in
|
|
74
|
+
--brain) brain="${2:-}"; shift 2 ;;
|
|
75
|
+
--mounts-reviewed) mounts_reviewed=1; shift ;;
|
|
76
|
+
*) os_die "unknown argument: $1" ;;
|
|
77
|
+
esac
|
|
78
|
+
done
|
|
79
|
+
|
|
80
|
+
[ -n "$brain" ] || os_die "missing --brain"
|
|
81
|
+
[ -d "$brain" ] || os_die "no such brain: $brain"
|
|
82
|
+
brain=$(cd "$brain" && pwd)
|
|
83
|
+
|
|
84
|
+
os_ws_check "$brain"
|
|
85
|
+
wsdir=$(os_ws_dir "$brain")
|
|
86
|
+
slug="$OS_PERSONAL_WORKSPACE_SLUG"
|
|
87
|
+
dest="$wsdir/$slug"
|
|
88
|
+
|
|
89
|
+
lang=$(os_language "$brain")
|
|
90
|
+
os_lang_load "$lang"
|
|
91
|
+
|
|
92
|
+
tab=$(printf '\t')
|
|
93
|
+
nl=$(printf '\nx'); nl="${nl%x}"
|
|
94
|
+
state="$brain/.os/migrate-root.state"
|
|
95
|
+
interrupt_after="${OS_MIGRATE_ROOT_INTERRUPT_AFTER:-0}"
|
|
96
|
+
|
|
97
|
+
stop() {
|
|
98
|
+
printf 'stopped:\n'
|
|
99
|
+
printf ' %s\n' "$@"
|
|
100
|
+
exit 1
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# ---------------------------------------------------------------- the state of a previous run
|
|
104
|
+
state_created=0
|
|
105
|
+
state_types=""
|
|
106
|
+
if [ -f "$state" ]; then
|
|
107
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
108
|
+
case "$line" in
|
|
109
|
+
"created$tab"*) state_created=1 ;;
|
|
110
|
+
"type$tab"*) state_types="$state_types ${line#type$tab}" ;;
|
|
111
|
+
esac
|
|
112
|
+
done < "$state"
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
# ---------------------------------------------------------------- what there is to move
|
|
116
|
+
tipos_root=$(os_memory_types "$brain" root) || tipos_root=""
|
|
117
|
+
tipos=""
|
|
118
|
+
for t in $tipos_root $state_types; do
|
|
119
|
+
case " $tipos " in *" $t "*) ;; *) tipos="$tipos $t" ;; esac
|
|
120
|
+
done
|
|
121
|
+
|
|
122
|
+
items=""
|
|
123
|
+
if [ -d "$brain/initiatives" ]; then
|
|
124
|
+
for e in "$brain/initiatives/"*; do
|
|
125
|
+
[ -e "$e" ] && items="${items}initiatives/$(basename "$e")$nl"
|
|
126
|
+
done
|
|
127
|
+
fi
|
|
128
|
+
for t in $tipos; do
|
|
129
|
+
[ -d "$brain/$t" ] || continue
|
|
130
|
+
for e in "$brain/$t/"*; do
|
|
131
|
+
[ -e "$e" ] && items="$items$t/$(basename "$e")$nl"
|
|
132
|
+
done
|
|
133
|
+
done
|
|
134
|
+
for f in backlog.md decisions.md decisions learnings.md learnings; do
|
|
135
|
+
[ -e "$brain/$f" ] && items="$items$f$nl"
|
|
136
|
+
done
|
|
137
|
+
|
|
138
|
+
hay_inbox=0; [ -f "$brain/inbox.md" ] && hay_inbox=1
|
|
139
|
+
|
|
140
|
+
if [ -z "$items" ] && [ ! -f "$state" ] && [ "$hay_inbox" = "0" ]; then
|
|
141
|
+
printf 'nothing at the root to migrate\n'
|
|
142
|
+
exit 0
|
|
143
|
+
fi
|
|
144
|
+
|
|
145
|
+
# ---------------------------------------------------------------- stops, before moving anything
|
|
146
|
+
mount_hits=""
|
|
147
|
+
if [ -n "$items" ]; then
|
|
148
|
+
if [ -e "$brain/$dest" ] && [ "$state_created" = "0" ]; then
|
|
149
|
+
stop "$dest already exists and this migration did not create it — merging two workspaces is not this command's job; nothing moved" \
|
|
150
|
+
"rename or move it by hand, with the operator, and run again"
|
|
151
|
+
fi
|
|
152
|
+
|
|
153
|
+
conflictos=""
|
|
154
|
+
while IFS= read -r it || [ -n "$it" ]; do
|
|
155
|
+
[ -n "$it" ] || continue
|
|
156
|
+
# An empty folder the workspace was born with (spec 076, C13: `decisions/`, `learnings/`) is free.
|
|
157
|
+
if [ -d "$brain/$dest/$it" ] && [ -z "$(ls -A "$brain/$dest/$it" 2>/dev/null)" ]; then continue; fi
|
|
158
|
+
[ -e "$brain/$dest/$it" ] && conflictos="$conflictos$dest/$it already exists — nothing moved$nl"
|
|
159
|
+
done <<ITEMS
|
|
160
|
+
$items
|
|
161
|
+
ITEMS
|
|
162
|
+
if [ -n "$conflictos" ]; then
|
|
163
|
+
printf 'stopped:\n'
|
|
164
|
+
printf '%s' "$conflictos" | while IFS= read -r c; do printf ' %s\n' "$c"; done
|
|
165
|
+
exit 1
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
if [ -f "$brain/$OS_MOUNTS_ARCHIVO" ]; then
|
|
169
|
+
pat=""
|
|
170
|
+
while IFS= read -r it || [ -n "$it" ]; do
|
|
171
|
+
case "$it" in */*) ;; *) continue ;; esac
|
|
172
|
+
esc="${it//./\\.}"
|
|
173
|
+
if [ -z "$pat" ]; then pat="$esc"; else pat="$pat|$esc"; fi
|
|
174
|
+
done <<ITEMS
|
|
175
|
+
$items
|
|
176
|
+
ITEMS
|
|
177
|
+
if [ -n "$pat" ]; then
|
|
178
|
+
re="(^|[[:space:]\`|(\"'[<])($pat)([/[:space:]\`|)\"'>,;:]|\$)"
|
|
179
|
+
hits=""
|
|
180
|
+
while IFS= read -r ruta || [ -n "$ruta" ]; do
|
|
181
|
+
[ -n "$ruta" ] && [ -d "$ruta" ] || continue
|
|
182
|
+
case "$ruta/" in "$brain/"*) continue ;; esac
|
|
183
|
+
if git -C "$ruta" rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
|
184
|
+
h=$(git -C "$ruta" grep -n -I -E "$re" 2>/dev/null | head -5)
|
|
185
|
+
else
|
|
186
|
+
h=$(grep -r -n -I -E "$re" "$ruta" 2>/dev/null | head -5)
|
|
187
|
+
fi
|
|
188
|
+
[ -n "$h" ] && hits="$hits$ruta$nl$h$nl"
|
|
189
|
+
done <<MOUNTS
|
|
190
|
+
$(grep -E '^[[:space:]]*\|' "$brain/$OS_MOUNTS_ARCHIVO" 2>/dev/null | grep -oE '`/[^`]+`' | tr -d '`')
|
|
191
|
+
MOUNTS
|
|
192
|
+
if [ -n "$hits" ] && [ "$mounts_reviewed" = "1" ]; then
|
|
193
|
+
mount_hits="$hits"
|
|
194
|
+
elif [ -n "$hits" ]; then
|
|
195
|
+
printf 'stopped:\n'
|
|
196
|
+
printf ' %s\n' "$S_MIGRATE_ROOT_MOUNTS_STOP"
|
|
197
|
+
printf '%s' "$hits" | while IFS= read -r c; do [ -n "$c" ] && printf ' %s\n' "$c"; done
|
|
198
|
+
exit 1
|
|
199
|
+
fi
|
|
200
|
+
fi
|
|
201
|
+
fi
|
|
202
|
+
fi
|
|
203
|
+
|
|
204
|
+
# ---------------------------------------------------------------- the state file, before any write
|
|
205
|
+
mkdir -p "$brain/.os" 2> /dev/null || stop "could not create .os/ for the state file; nothing moved"
|
|
206
|
+
[ -f "$state" ] || : > "$state" 2> /dev/null || stop "could not write $state; nothing moved"
|
|
207
|
+
for t in $tipos_root; do
|
|
208
|
+
grep -qxF "type$tab$t" "$state" || printf 'type\t%s\n' "$t" >> "$state"
|
|
209
|
+
done
|
|
210
|
+
|
|
211
|
+
# ---------------------------------------------------------------- the destination workspace
|
|
212
|
+
if [ -n "$items" ] && [ ! -e "$brain/$dest" ]; then
|
|
213
|
+
printf 'created\t%s\n' "$dest" >> "$state"
|
|
214
|
+
owner=$(os_titulo "$brain/$OS_OPERATOR_FILE")
|
|
215
|
+
[ -n "$owner" ] || owner="$S_PERSONAL_WORKSPACE_NAME"
|
|
216
|
+
"$here/new-workspace.sh" --brain "$brain" --name "$S_PERSONAL_WORKSPACE_NAME" --role "" \
|
|
217
|
+
--title "" --owner "$owner" --slug "$slug" > /dev/null \
|
|
218
|
+
|| stop "could not create $dest with new-workspace.sh; nothing moved"
|
|
219
|
+
printf '%s created\n' "$dest"
|
|
220
|
+
fi
|
|
221
|
+
|
|
222
|
+
# ---------------------------------------------------------------- the moves
|
|
223
|
+
movidos=""
|
|
224
|
+
n_mov=0
|
|
225
|
+
while IFS= read -r it || [ -n "$it" ]; do
|
|
226
|
+
[ -n "$it" ] || continue
|
|
227
|
+
grep -qxF "move$tab$it$tab$dest/$it" "$state" || printf 'move\t%s\t%s\n' "$it" "$dest/$it" >> "$state"
|
|
228
|
+
mkdir -p "$(dirname "$brain/$dest/$it")"
|
|
229
|
+
# A workspace born since spec 076 (C13) already has empty `decisions/` and `learnings/`: an empty
|
|
230
|
+
# folder in the way is not a conflict, and `mv` would otherwise nest the moved one inside it.
|
|
231
|
+
[ -d "$brain/$dest/$it" ] && rmdir "$brain/$dest/$it" 2> /dev/null
|
|
232
|
+
# A plain rename, never `git mv`: it moves tracked and untracked files alike, and git sees the
|
|
233
|
+
# rename at the next commit. The result is checked, never assumed.
|
|
234
|
+
if ! mv "$brain/$it" "$brain/$dest/$it" 2> /dev/null || [ -e "$brain/$it" ] || [ ! -e "$brain/$dest/$it" ]; then
|
|
235
|
+
[ -n "$movidos" ] && printf 'moved before stopping:\n%s' "$movidos"
|
|
236
|
+
stop "could not move $it to $dest/$it — the rest is left as it was; run again once fixed"
|
|
237
|
+
fi
|
|
238
|
+
movidos="$movidos $it → $dest/$it$nl"
|
|
239
|
+
n_mov=$(( n_mov + 1 ))
|
|
240
|
+
if [ "$interrupt_after" != "0" ] && [ "$n_mov" -ge "$interrupt_after" ]; then
|
|
241
|
+
exit 3
|
|
242
|
+
fi
|
|
243
|
+
done <<ITEMS
|
|
244
|
+
$items
|
|
245
|
+
ITEMS
|
|
246
|
+
for t in $tipos; do rmdir "$brain/$t" 2> /dev/null || true; done
|
|
247
|
+
rmdir "$brain/initiatives" 2> /dev/null || true
|
|
248
|
+
|
|
249
|
+
# The map of everything moved, by this run or by a previous one: FROM<tab>TO per line.
|
|
250
|
+
mapa=""
|
|
251
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
252
|
+
case "$line" in
|
|
253
|
+
"move$tab"*) mapa="$mapa${line#move$tab}$nl" ;;
|
|
254
|
+
esac
|
|
255
|
+
done < "$state"
|
|
256
|
+
|
|
257
|
+
# ---------------------------------------------------------------- inbox.md — never lost
|
|
258
|
+
inbox_listado=""
|
|
259
|
+
if [ "$hay_inbox" = "1" ]; then
|
|
260
|
+
if [ -z "$(tr -d ' \t\r\n' < "$brain/inbox.md")" ]; then
|
|
261
|
+
rm -f "$brain/inbox.md"
|
|
262
|
+
movidos="$movidos inbox.md — empty, removed$nl"
|
|
263
|
+
else
|
|
264
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
265
|
+
[ -n "$(printf '%s' "$line" | tr -d ' \t\r')" ] || continue
|
|
266
|
+
inbox_listado="$inbox_listado $line$nl"
|
|
267
|
+
done < "$brain/inbox.md"
|
|
268
|
+
fi
|
|
269
|
+
fi
|
|
270
|
+
|
|
271
|
+
# ---------------------------------------------------------------- the matcher
|
|
272
|
+
# With `solo_distintivos=1` only the paths with a slash in them (an initiative's, a memory node's)
|
|
273
|
+
# count: outside the root's own files, a bare `backlog.md` or `decisions/` is relative to its node.
|
|
274
|
+
solo_distintivos=0
|
|
275
|
+
|
|
276
|
+
# moved_at LINE I -> prints "FROM<tab>TO" for the moved path that starts at position I of LINE, with
|
|
277
|
+
# a safe character before it and a path end after it; returns 1 otherwise.
|
|
278
|
+
moved_at() {
|
|
279
|
+
local line="$1" i="$2" from to prevc nextc rest
|
|
280
|
+
if [ "$i" -gt 0 ]; then
|
|
281
|
+
prevc="${line:$((i - 1)):1}"
|
|
282
|
+
case "$prevc" in
|
|
283
|
+
' '|"$tab"|'`'|'|'|'('|'"'|"'"|'['|'<') ;;
|
|
284
|
+
*) return 1 ;;
|
|
285
|
+
esac
|
|
286
|
+
fi
|
|
287
|
+
rest="${line:$i}"
|
|
288
|
+
while IFS="$tab" read -r from to || [ -n "$from" ]; do
|
|
289
|
+
[ -n "$from" ] || continue
|
|
290
|
+
if [ "$solo_distintivos" = "1" ]; then
|
|
291
|
+
case "$from" in */*) ;; *) continue ;; esac
|
|
292
|
+
fi
|
|
293
|
+
case "$rest" in
|
|
294
|
+
"$from"*) ;;
|
|
295
|
+
*) continue ;;
|
|
296
|
+
esac
|
|
297
|
+
nextc="${rest:${#from}:1}"
|
|
298
|
+
case "$nextc" in
|
|
299
|
+
''|'/'|' '|"$tab"|'`'|'|'|')'|'"'|"'"|']'|'>'|','|';'|':'|'#')
|
|
300
|
+
printf '%s\t%s' "$from" "$to"; return 0 ;;
|
|
301
|
+
'.')
|
|
302
|
+
# a sentence-ending dot, never the dot of an extension
|
|
303
|
+
case "${rest:$(( ${#from} + 1 )):1}" in
|
|
304
|
+
''|' '|"$tab") printf '%s\t%s' "$from" "$to"; return 0 ;;
|
|
305
|
+
esac
|
|
306
|
+
;;
|
|
307
|
+
esac
|
|
308
|
+
done <<MAPA
|
|
309
|
+
$mapa
|
|
310
|
+
MAPA
|
|
311
|
+
return 1
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
# prefiltro LINE -> 0 if LINE contains any moved path at all: the rest are never walked char by char.
|
|
315
|
+
prefiltro() {
|
|
316
|
+
local line="$1" from to
|
|
317
|
+
while IFS="$tab" read -r from to || [ -n "$from" ]; do
|
|
318
|
+
[ -n "$from" ] || continue
|
|
319
|
+
case "$line" in *"$from"*) return 0 ;; esac
|
|
320
|
+
done <<MAPA
|
|
321
|
+
$mapa
|
|
322
|
+
MAPA
|
|
323
|
+
return 1
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
rewrite_line() {
|
|
327
|
+
local line="$1" out="" i=0 len=${#1} m from to
|
|
328
|
+
while [ "$i" -lt "$len" ]; do
|
|
329
|
+
if m=$(moved_at "$line" "$i"); then
|
|
330
|
+
from="${m%%$tab*}"; to="${m#*$tab}"
|
|
331
|
+
out="$out$to"
|
|
332
|
+
i=$(( i + ${#from} ))
|
|
333
|
+
continue
|
|
334
|
+
fi
|
|
335
|
+
out="$out${line:$i:1}"
|
|
336
|
+
i=$(( i + 1 ))
|
|
337
|
+
done
|
|
338
|
+
printf '%s' "$out"
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
count_line() {
|
|
342
|
+
local line="$1" i=0 len=${#1} n=0 m from
|
|
343
|
+
while [ "$i" -lt "$len" ]; do
|
|
344
|
+
if m=$(moved_at "$line" "$i"); then
|
|
345
|
+
from="${m%%$tab*}"
|
|
346
|
+
n=$(( n + 1 ))
|
|
347
|
+
i=$(( i + ${#from} ))
|
|
348
|
+
continue
|
|
349
|
+
fi
|
|
350
|
+
i=$(( i + 1 ))
|
|
351
|
+
done
|
|
352
|
+
printf '%s' "$n"
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
# rewrite_file RELPATH [about] -> 0 rewrote, 1 not present or nothing matched. With `about`, only
|
|
356
|
+
# the frontmatter's `about:` line is touched.
|
|
357
|
+
rewrite_file() {
|
|
358
|
+
local rel="$1" solo_about="${2:-}" file="$brain/$1" tmp line nueva cambio=0
|
|
359
|
+
[ -f "$file" ] || return 1
|
|
360
|
+
tmp="$file.os-tmp"
|
|
361
|
+
: > "$tmp"
|
|
362
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
363
|
+
nueva="$line"
|
|
364
|
+
if [ -z "$solo_about" ] || [ "${line#about: }" != "$line" ]; then
|
|
365
|
+
prefiltro "$line" && nueva=$(rewrite_line "$line")
|
|
366
|
+
fi
|
|
367
|
+
[ "$nueva" = "$line" ] || cambio=1
|
|
368
|
+
printf '%s\n' "$nueva"
|
|
369
|
+
done < "$file" >> "$tmp"
|
|
370
|
+
if [ "$cambio" = "1" ]; then
|
|
371
|
+
mv "$tmp" "$file"
|
|
372
|
+
return 0
|
|
373
|
+
fi
|
|
374
|
+
rm -f "$tmp"
|
|
375
|
+
return 1
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
# ---------------------------------------------------------------- about: of every head under personal
|
|
379
|
+
abouts=""
|
|
380
|
+
if [ -n "$mapa" ] && [ -d "$brain/$dest" ]; then
|
|
381
|
+
while IFS= read -r f || [ -n "$f" ]; do
|
|
382
|
+
[ -n "$f" ] || continue
|
|
383
|
+
if rewrite_file "${f#$brain/}" about; then abouts="$abouts ${f#$brain/}$nl"; fi
|
|
384
|
+
done <<LISTADO_ABOUT
|
|
385
|
+
$(find "$brain/$dest" -type f -name '*.md' -print 2>/dev/null)
|
|
386
|
+
LISTADO_ABOUT
|
|
387
|
+
fi
|
|
388
|
+
|
|
389
|
+
# ---------------------------------------------------------------- tree.md — root lines move height
|
|
390
|
+
tree_cambios=""
|
|
391
|
+
if [ -f "$brain/$OS_TREE_FILE" ]; then
|
|
392
|
+
prefijos=""
|
|
393
|
+
while IFS="$tab" read -r from to || [ -n "$from" ]; do
|
|
394
|
+
[ -n "$from" ] || continue
|
|
395
|
+
p="${from%%/*}"
|
|
396
|
+
case " $prefijos " in *" $p "*) ;; *) prefijos="$prefijos $p" ;; esac
|
|
397
|
+
done <<MAPA
|
|
398
|
+
$mapa
|
|
399
|
+
MAPA
|
|
400
|
+
tmp="$brain/$OS_TREE_FILE.os-tmp"; : > "$tmp"; cambio=0; nuevas=""
|
|
401
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
402
|
+
clase=""; pat=""
|
|
403
|
+
if decl=$(os_tree_line "$line"); then clase="${decl%%$tab*}"; pat="${decl#*$tab}"; fi
|
|
404
|
+
mover_linea=0
|
|
405
|
+
if [ -n "$clase" ]; then
|
|
406
|
+
for p in $prefijos; do
|
|
407
|
+
case "$pat" in
|
|
408
|
+
"$p"|"$p"/*) mover_linea=1 ;;
|
|
409
|
+
esac
|
|
410
|
+
done
|
|
411
|
+
fi
|
|
412
|
+
if [ "$mover_linea" = "1" ]; then
|
|
413
|
+
nuevas="$nuevas$clase$tab$wsdir/*/$pat$nl"
|
|
414
|
+
cambio=1
|
|
415
|
+
tree_cambios="$tree_cambios $clase: $pat → $clase: $wsdir/*/$pat$nl"
|
|
416
|
+
continue
|
|
417
|
+
fi
|
|
418
|
+
if [ "$line" = "glob: inbox.md" ] && [ ! -f "$brain/inbox.md" ]; then
|
|
419
|
+
cambio=1
|
|
420
|
+
tree_cambios="$tree_cambios glob: inbox.md — removed$nl"
|
|
421
|
+
continue
|
|
422
|
+
fi
|
|
423
|
+
printf '%s\n' "$line" >> "$tmp"
|
|
424
|
+
done < "$brain/$OS_TREE_FILE"
|
|
425
|
+
if [ "$cambio" = "1" ]; then
|
|
426
|
+
mv "$tmp" "$brain/$OS_TREE_FILE"
|
|
427
|
+
while IFS="$tab" read -r clase pat || [ -n "$clase" ]; do
|
|
428
|
+
[ -n "$clase" ] || continue
|
|
429
|
+
os_tree_ensure "$brain" "$pat" "$clase" > /dev/null
|
|
430
|
+
grep -qxF "$clase: $pat" "$brain/$OS_TREE_FILE" || stop "tree.md: could not declare $clase: $pat"
|
|
431
|
+
done <<NUEVAS
|
|
432
|
+
$nuevas
|
|
433
|
+
NUEVAS
|
|
434
|
+
else
|
|
435
|
+
rm -f "$tmp"
|
|
436
|
+
fi
|
|
437
|
+
fi
|
|
438
|
+
|
|
439
|
+
# ---------------------------------------------------------------- routing rewrite
|
|
440
|
+
rewritten=""
|
|
441
|
+
if [ -n "$mapa" ]; then
|
|
442
|
+
objetivos="$OS_ROOT_RESOLVER_FILE$nl$OS_MOUNTS_ARCHIVO$nl"
|
|
443
|
+
if [ -d "$brain/$dest" ]; then
|
|
444
|
+
objetivos="$objetivos$(cd "$brain" && find "$dest" -type f \( -name resolver.md -o -name backlog.md \) -print 2>/dev/null)$nl"
|
|
445
|
+
fi
|
|
446
|
+
while IFS= read -r rel || [ -n "$rel" ]; do
|
|
447
|
+
[ -n "$rel" ] || continue
|
|
448
|
+
if rewrite_file "$rel"; then rewritten="$rewritten $rel$nl"; fi
|
|
449
|
+
done <<OBJ
|
|
450
|
+
$objetivos
|
|
451
|
+
OBJ
|
|
452
|
+
fi
|
|
453
|
+
|
|
454
|
+
# ---------------------------------------------------------------- what still names a moved path
|
|
455
|
+
faltan=""
|
|
456
|
+
if [ -n "$mapa" ]; then
|
|
457
|
+
while IFS= read -r f || [ -n "$f" ]; do
|
|
458
|
+
[ -n "$f" ] || continue
|
|
459
|
+
rel="${f#$brain/}"
|
|
460
|
+
case "$rel" in
|
|
461
|
+
*/decisions.md|*/learnings.md) continue ;; # index links are relative to their node (043)
|
|
462
|
+
*/*) solo_distintivos=1 ;;
|
|
463
|
+
*) solo_distintivos=0 ;;
|
|
464
|
+
esac
|
|
465
|
+
n=0
|
|
466
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
467
|
+
prefiltro "$line" || continue
|
|
468
|
+
c=$(count_line "$line"); n=$(( n + c ))
|
|
469
|
+
done < "$f"
|
|
470
|
+
[ "$n" = "0" ] || faltan="$faltan $rel ($n)$nl"
|
|
471
|
+
done <<LISTADO
|
|
472
|
+
$(find "$brain" -type d \( -name .git -o -name .os -o -name .claude \) -prune -o -type f -name '*.md' -print)
|
|
473
|
+
LISTADO
|
|
474
|
+
solo_distintivos=0
|
|
475
|
+
fi
|
|
476
|
+
|
|
477
|
+
# ---------------------------------------------------------------- the verdict
|
|
478
|
+
[ -n "$movidos" ] && printf 'moved:\n%s' "$movidos"
|
|
479
|
+
[ -n "$tree_cambios" ] && printf 'tree.md:\n%s' "$tree_cambios"
|
|
480
|
+
[ -n "$abouts" ] && printf 'rewrote about:\n%s' "$abouts"
|
|
481
|
+
[ -n "$rewritten" ] && printf 'rewrote:\n%s' "$rewritten"
|
|
482
|
+
[ -n "$inbox_listado" ] && printf 'inbox.md — kept, for the operator to route by hand:\n%s' "$inbox_listado"
|
|
483
|
+
[ -n "$faltan" ] && printf 'still names a moved path — fix by hand:\n%s' "$faltan"
|
|
484
|
+
if [ -n "$mount_hits" ]; then
|
|
485
|
+
printf '%s\n' "$S_MIGRATE_ROOT_MOUNTS_REVIEWED"
|
|
486
|
+
printf '%s' "$mount_hits" | while IFS= read -r c; do [ -n "$c" ] && printf ' %s\n' "$c"; done
|
|
487
|
+
fi
|
|
488
|
+
if [ -f "$brain/$dest/backlog.md" ]; then
|
|
489
|
+
printf 'next: %s/backlog.md is outside any initiative — split it with migrate-backlogs.sh\n' "$dest"
|
|
490
|
+
fi
|
|
491
|
+
if [ -z "$movidos$tree_cambios$abouts$rewritten" ] && [ -n "$inbox_listado" ]; then
|
|
492
|
+
printf 'nothing at the root to move; only inbox.md is left\n'
|
|
493
|
+
fi
|
|
494
|
+
|
|
495
|
+
# Reached the end: every move and every rewrite is done — the state has nothing left to resume.
|
|
496
|
+
rm -f "$state"
|
|
497
|
+
exit 0
|