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.
- package/LICENSE +21 -0
- package/README.md +226 -0
- package/bin/ai-first-os.js +72 -0
- package/core/CLAUDE.md +148 -0
- package/core/VERSION +1 -0
- package/core/agents/ambiguous-spec.md +39 -0
- package/core/agents/complete-spec.md +36 -0
- package/core/agents/scout.md +25 -0
- package/core/install.sh +243 -0
- package/core/lib/archive.sh +347 -0
- package/core/lib/bootstrap.sh +276 -0
- package/core/lib/capture.sh +188 -0
- package/core/lib/check-resolvable.sh +172 -0
- package/core/lib/close-session.sh +741 -0
- package/core/lib/common.sh +1773 -0
- package/core/lib/focus-read.sh +282 -0
- package/core/lib/manual-link.sh +111 -0
- package/core/lib/markdown.py +304 -0
- package/core/lib/migrate-backlogs.sh +207 -0
- package/core/lib/migrate-canonicals.sh +523 -0
- package/core/lib/mount-repo.sh +543 -0
- package/core/lib/my-wiki-gates.sh +137 -0
- package/core/lib/my-wiki.sh +202 -0
- package/core/lib/my_wiki_build.py +548 -0
- package/core/lib/my_wiki_graph.py +137 -0
- package/core/lib/my_wiki_overview.py +392 -0
- package/core/lib/new-memory.sh +160 -0
- package/core/lib/new-product.sh +122 -0
- package/core/lib/new-workspace.sh +105 -0
- package/core/lib/pack-install.sh +114 -0
- package/core/lib/recall.sh +235 -0
- package/core/lib/recall_index.py +295 -0
- package/core/lib/remote-backup.sh +84 -0
- package/core/lib/rename-heads.sh +354 -0
- package/core/lib/rename-workspaces.sh +271 -0
- package/core/lib/session-read.sh +203 -0
- package/core/lib/session-start.sh +854 -0
- package/core/lib/supersede.sh +436 -0
- package/core/lib/sweep.sh +473 -0
- package/core/manual/COMO-FUNCIONA.md +251 -0
- package/core/manual/HOW-IT-WORKS.md +250 -0
- package/core/resolver.md +30 -0
- package/core/skills/archive.md +95 -0
- package/core/skills/bootstrap.md +226 -0
- package/core/skills/capture.md +65 -0
- package/core/skills/check-resolvable.md +38 -0
- package/core/skills/close-session.md +108 -0
- package/core/skills/grill.md +74 -0
- package/core/skills/mount-repo.md +97 -0
- package/core/skills/my-wiki.md +103 -0
- package/core/skills/new-memory.md +76 -0
- package/core/skills/new-product.md +55 -0
- package/core/skills/new-spec.md +114 -0
- package/core/skills/new-workspace.md +53 -0
- package/core/skills/recall.md +64 -0
- package/core/skills/rename-heads.md +72 -0
- package/core/skills/rename-workspaces.md +43 -0
- package/core/skills/supersede.md +83 -0
- package/core/skills/sweep.md +40 -0
- package/core/templates/my-wiki-graph.js +431 -0
- package/core/templates/my-wiki-overview.js +174 -0
- package/core/templates/my-wiki.html +1017 -0
- package/core/templates/node-folder/README.md +11 -0
- package/core/templates/node-folder/resolver.md +9 -0
- package/core/templates/node-light.md +22 -0
- package/core/templates/node-product/README.md +8 -0
- package/core/templates/node-repo/README.md +14 -0
- package/core/templates/node-repo/context/README.md +22 -0
- package/core/templates/node-repo/context/competitors.md +8 -0
- package/core/templates/node-repo/context/glossary.md +8 -0
- package/core/templates/node-repo/context/open-questions.md +9 -0
- package/core/templates/node-repo/context/opportunities.md +9 -0
- package/core/templates/node-repo/context/problem.md +8 -0
- package/core/templates/node-repo/context/scope.md +8 -0
- package/core/templates/node-repo/context/users.md +8 -0
- package/core/templates/node-repo/context/vision.md +8 -0
- package/core/templates/node-repo/resolver.md +14 -0
- package/core/templates/operator.md +17 -0
- package/core/templates/person.md +10 -0
- package/core/templates/repo-scaffold/ARCHITECTURE.md +3 -0
- package/core/templates/repo-scaffold/CLAUDE.md +23 -0
- package/core/templates/repo-scaffold/decisions.md +3 -0
- package/core/templates/repo-scaffold/evals-run.sh +14 -0
- package/core/templates/repo-scaffold/gitignore +3 -0
- package/core/templates/repo-scaffold/settings.json +8 -0
- package/core/templates/root-resolver.md +5 -0
- package/core/templates/strings.md +1361 -0
- package/core/templates/tree.md +59 -0
- package/core/templates/voice.md +5 -0
- package/package.json +23 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Focus read: what a session loads when the operator picks one node to work on (spec 049).
|
|
3
|
+
# Internal: not invocable — the session contract (core/CLAUDE.md) fires it the moment the operator
|
|
4
|
+
# names the focus, after the startup scan and the startup read.
|
|
5
|
+
#
|
|
6
|
+
# Usage: focus-read.sh --brain DIR --focus PATH
|
|
7
|
+
#
|
|
8
|
+
# `--focus` is the head of the node being worked on, relative to the brain — an initiative's head
|
|
9
|
+
# almost always, but any head a `glob:` line of `tree.md` reaches is a legitimate focus: the system
|
|
10
|
+
# has one primitive repeated at every height, and a command that only understood `initiatives/`
|
|
11
|
+
# would contradict it.
|
|
12
|
+
#
|
|
13
|
+
# READING ORDER — this comment is the only place the focus reading order is written down, and the
|
|
14
|
+
# body below is what executes it. Nothing else lists these files:
|
|
15
|
+
#
|
|
16
|
+
# 1. the head named by `--focus`
|
|
17
|
+
# 2. its body: the files a `content:` line reaches **directly inside** that node's folder,
|
|
18
|
+
# `LC_ALL=C sort` by path
|
|
19
|
+
# 3. only if that head declares `about:` — the head it names
|
|
20
|
+
# 4. and the `resolver.md` next to that head, when a `glob:` line reaches it
|
|
21
|
+
# 5. the **names** of what an `archive:` line reaches directly inside that node's folder — never
|
|
22
|
+
# their bodies (spec 048)
|
|
23
|
+
#
|
|
24
|
+
# ONE JUMP IS ONE JUMP. Step 3 reads the `about:` of the focus and of nothing else: the head loaded
|
|
25
|
+
# there may declare its own `about:`, and it is not followed. The value of this system is that the
|
|
26
|
+
# startup never opens a body; a load that chains would read half the brain to answer one question,
|
|
27
|
+
# and it would do it silently, growing with every link an operator adds. The bound is not a number
|
|
28
|
+
# to tune — it is one level, always.
|
|
29
|
+
#
|
|
30
|
+
# WHAT IS NOT LOADED, AND WHY.
|
|
31
|
+
# · The `decisions.md` of the node named by `about:`: it is append-only and unbounded, and what it
|
|
32
|
+
# holds is why past decisions were taken, not what this node is.
|
|
33
|
+
# · Whatever a `content:` line reaches **under** that node —its `context/`, its `research/`—: those
|
|
34
|
+
# are the documents the node accumulates, and loading them turns one jump into the whole folder.
|
|
35
|
+
# · The body of any node other than the focus.
|
|
36
|
+
# · Anything a second `about:` names.
|
|
37
|
+
# · The body of anything an `archive:` line reaches. Step 5 prints file names and nothing else:
|
|
38
|
+
# archiving a document is the operator saying it is no longer what you read to work, and a
|
|
39
|
+
# listing that opened them would put back exactly the cost the archive exists to remove. The
|
|
40
|
+
# folder is the index — there is no file to keep in sync — and `recall` is what searches inside.
|
|
41
|
+
# The pair loaded in steps 3 and 4 —a head and the `resolver.md` beside it— is the same pair the
|
|
42
|
+
# startup read already loads for a workspace (`session-read.sh`, steps 3 and 4): what "loading a
|
|
43
|
+
# node" means is stated once, and this command repeats the shape instead of inventing a second one.
|
|
44
|
+
#
|
|
45
|
+
# A file this command prints may carry the mark that says another file replaced it. Honouring that
|
|
46
|
+
# mark is the session's job and the rule is written once, in `core/CLAUDE.md`: this command does not
|
|
47
|
+
# follow it either — it prints files, it does not decide which of them is current.
|
|
48
|
+
#
|
|
49
|
+
# Output format, the same as `session-read.sh`:
|
|
50
|
+
# - Header per file: `── <path relative to the brain>`.
|
|
51
|
+
# - Body: the bytes of the file; a file that does not end in a newline gets one.
|
|
52
|
+
# - A file that is not there prints `── missing: <path>` and no body, and never stops the read.
|
|
53
|
+
# - Exactly one blank line between entries, nothing before the first.
|
|
54
|
+
# - The jump opens with the fixed marker `about-jump: <path>` —English in both languages, like
|
|
55
|
+
# `active-role:`— and the head's entry on the next line, with no blank line in between. The
|
|
56
|
+
# marker is hyphenated because a plain `about:` at the start of a line is what the frontmatter
|
|
57
|
+
# of a printed head looks like: a reader could not tell the jump from the file's own key.
|
|
58
|
+
# - An `about:` that does not resolve prints `about-unresolved: <value> · <reason>` in place of
|
|
59
|
+
# the jump and the read goes on: the startup scan is where a broken link is a finding, and a
|
|
60
|
+
# read that dies over one leaves the operator with nothing.
|
|
61
|
+
# - The archived listing opens with the fixed marker `archived: <n>` —English in both languages,
|
|
62
|
+
# like `about-jump:`— and one `· <file name>` line per file, `LC_ALL=C sort`. A node with
|
|
63
|
+
# nothing archived prints no marker and no lines.
|
|
64
|
+
#
|
|
65
|
+
# Exit: 0 the focus was read, with or without a jump and with or without missing files. 1 invalid
|
|
66
|
+
# arguments, or a `--focus` that is not a head the tree reaches. 2 the file named by `--focus` does
|
|
67
|
+
# not exist.
|
|
68
|
+
#
|
|
69
|
+
# No `set -e` on purpose: an unreadable file cannot abort the work the operator just picked.
|
|
70
|
+
|
|
71
|
+
set -u
|
|
72
|
+
|
|
73
|
+
here=$(cd "$(dirname "$0")" && pwd)
|
|
74
|
+
. "$here/common.sh"
|
|
75
|
+
|
|
76
|
+
nl=$(printf '\nx')
|
|
77
|
+
nl="${nl%x}"
|
|
78
|
+
|
|
79
|
+
brain=""
|
|
80
|
+
focus=""
|
|
81
|
+
# A flag that takes a value checks that the value is there before consuming it: with the flag as the
|
|
82
|
+
# last argument, `shift 2` fails without consuming anything and the loop repeats forever.
|
|
83
|
+
while [ $# -gt 0 ]; do
|
|
84
|
+
case "$1" in
|
|
85
|
+
--brain) [ $# -ge 2 ] || os_die "--brain needs a value"; brain="$2"; shift 2 ;;
|
|
86
|
+
--focus) [ $# -ge 2 ] || os_die "--focus needs a value"; focus="$2"; shift 2 ;;
|
|
87
|
+
*) os_die "unknown argument: $1" ;;
|
|
88
|
+
esac
|
|
89
|
+
done
|
|
90
|
+
|
|
91
|
+
[ -n "$brain" ] || os_die "missing --brain"
|
|
92
|
+
[ -n "$focus" ] || os_die "missing --focus"
|
|
93
|
+
[ -d "$brain" ] || os_die "no such brain: $brain"
|
|
94
|
+
brain=$(cd "$brain" && pwd)
|
|
95
|
+
|
|
96
|
+
os_ws_check "$brain"
|
|
97
|
+
head_file=$(os_head_file "$brain") || true
|
|
98
|
+
|
|
99
|
+
lang=$(os_language "$brain")
|
|
100
|
+
os_lang_load "$lang"
|
|
101
|
+
|
|
102
|
+
focus=$(os_rel_norm "$focus")
|
|
103
|
+
os_rel_ok "$focus" || os_die "--focus is not a path relative to the brain: $focus"
|
|
104
|
+
|
|
105
|
+
# The two classes of tree line, read from the one reader of the format (`common.sh`). A brain whose
|
|
106
|
+
# tree cannot be read is not a brain this command can answer about: swallowing that would print the
|
|
107
|
+
# focus and no body, which reads exactly like a node with nothing in it.
|
|
108
|
+
heads=$(os_tree_files "$brain") || os_die "no tree.md to read in: $brain"
|
|
109
|
+
contents=$(os_tree_content_files "$brain") || os_die "no tree.md to read in: $brain"
|
|
110
|
+
archived=$(os_tree_archive_files "$brain") || archived=""
|
|
111
|
+
|
|
112
|
+
es_cabeza() {
|
|
113
|
+
case "$nl$heads$nl" in *"$nl$1$nl"*) return 0 ;; esac
|
|
114
|
+
return 1
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if ! es_cabeza "$focus"; then
|
|
118
|
+
if [ ! -f "$brain/$focus" ]; then
|
|
119
|
+
printf "$S_FOCUS_NOT_A_HEAD\n" "$focus" >&2
|
|
120
|
+
exit 2
|
|
121
|
+
fi
|
|
122
|
+
printf "$S_FOCUS_NOT_A_HEAD\n" "$focus" >&2
|
|
123
|
+
exit 1
|
|
124
|
+
fi
|
|
125
|
+
|
|
126
|
+
primera=1
|
|
127
|
+
|
|
128
|
+
separar() {
|
|
129
|
+
if [ "$primera" = "1" ]; then primera=0; else printf '\n'; fi
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# cuerpo ARCHIVO — the bytes of the file, plus the closing newline it may not have.
|
|
133
|
+
cuerpo() {
|
|
134
|
+
local last
|
|
135
|
+
[ -s "$1" ] || return 0
|
|
136
|
+
cat "$1"
|
|
137
|
+
last=$(tail -c 1 "$1")
|
|
138
|
+
if [ -n "$last" ]; then printf '\n'; fi
|
|
139
|
+
return 0
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
# emitir RUTA — one entry: its header and its body, or its `missing:` line.
|
|
143
|
+
emitir() {
|
|
144
|
+
separar
|
|
145
|
+
if [ -f "$brain/$1" ]; then
|
|
146
|
+
printf '── %s\n' "$1"
|
|
147
|
+
cuerpo "$brain/$1"
|
|
148
|
+
else
|
|
149
|
+
printf '── '
|
|
150
|
+
printf "$S_SESSION_READ_MISSING\n" "$1"
|
|
151
|
+
fi
|
|
152
|
+
return 0
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# ---------------------------------------------------------------- 1 · the head of the focus
|
|
156
|
+
emitir "$focus"
|
|
157
|
+
|
|
158
|
+
# ---------------------------------------------------------------- 2 · its body
|
|
159
|
+
# Direct children of the node's folder, never everything underneath it. On an initiative the two are
|
|
160
|
+
# the same thing; on a node that keeps folders —a product with its `context/` and its `research/`—
|
|
161
|
+
# they are not, and reading everything underneath turns picking a focus into loading every dated
|
|
162
|
+
# document that node ever accumulated.
|
|
163
|
+
#
|
|
164
|
+
# A head that is not the node's folder head —a brain born before spec 040 keeps its initiatives as
|
|
165
|
+
# loose files— has no folder of its own: its siblings belong to other nodes, so nothing is added.
|
|
166
|
+
dir="${focus%/*}"
|
|
167
|
+
base="${focus##*/}"
|
|
168
|
+
if [ "$base" = "$head_file" ] && [ "$dir" != "$focus" ]; then
|
|
169
|
+
cuerpos=""
|
|
170
|
+
while IFS= read -r f || [ -n "$f" ]; do
|
|
171
|
+
[ -n "$f" ] || continue
|
|
172
|
+
[ "$f" = "$focus" ] && continue
|
|
173
|
+
case "$f" in
|
|
174
|
+
"$dir"/*) ;;
|
|
175
|
+
*) continue ;;
|
|
176
|
+
esac
|
|
177
|
+
resto="${f#"$dir"/}"
|
|
178
|
+
case "$resto" in */*) continue ;; esac
|
|
179
|
+
cuerpos="$cuerpos$f$nl"
|
|
180
|
+
done <<CONTENIDOS
|
|
181
|
+
$contents
|
|
182
|
+
CONTENIDOS
|
|
183
|
+
while IFS= read -r f || [ -n "$f" ]; do
|
|
184
|
+
[ -n "$f" ] || continue
|
|
185
|
+
emitir "$f"
|
|
186
|
+
done <<ORDENADOS
|
|
187
|
+
$(printf '%s' "$cuerpos" | LC_ALL=C sort)
|
|
188
|
+
ORDENADOS
|
|
189
|
+
fi
|
|
190
|
+
|
|
191
|
+
# ---------------------------------------------------------------- 5 · what is archived, by name
|
|
192
|
+
# Runs on every exit path of this script, because the operator's answer to "what does this node have
|
|
193
|
+
# that I am not reading" cannot depend on whether the head declared an `about:`.
|
|
194
|
+
#
|
|
195
|
+
# Same "direct children" rule as step 2, one level deeper: a file an `archive:` line reaches whose
|
|
196
|
+
# path, relative to the node's folder, is `<folder>/<name>` or `<name>`. A node that holds other
|
|
197
|
+
# nodes does not list the archives of the nodes under it: three segments away is somebody else's
|
|
198
|
+
# node, and listing those would make one focus grow with every node somebody adds beneath it.
|
|
199
|
+
listar_archivado() {
|
|
200
|
+
local f resto lista="" n=0
|
|
201
|
+
[ -n "$archived" ] || return 0
|
|
202
|
+
[ "$base" = "$head_file" ] && [ "$dir" != "$focus" ] || return 0
|
|
203
|
+
while IFS= read -r f || [ -n "$f" ]; do
|
|
204
|
+
[ -n "$f" ] || continue
|
|
205
|
+
case "$f" in
|
|
206
|
+
"$dir"/*) ;;
|
|
207
|
+
*) continue ;;
|
|
208
|
+
esac
|
|
209
|
+
resto="${f#"$dir"/}"
|
|
210
|
+
case "$resto" in
|
|
211
|
+
*/*/*) continue ;;
|
|
212
|
+
esac
|
|
213
|
+
lista="$lista${f##*/}$nl"
|
|
214
|
+
n=$(( n + 1 ))
|
|
215
|
+
done <<ARCHIVADOS
|
|
216
|
+
$archived
|
|
217
|
+
ARCHIVADOS
|
|
218
|
+
[ "$n" -gt 0 ] || return 0
|
|
219
|
+
separar
|
|
220
|
+
# Fixed marker, in English, the same in both languages — the criterion of `about-jump:` and
|
|
221
|
+
# `active-role:`: a reader matches it as a structural identifier, not as translatable prose.
|
|
222
|
+
printf 'archived: %s\n' "$n"
|
|
223
|
+
while IFS= read -r f || [ -n "$f" ]; do
|
|
224
|
+
[ -n "$f" ] || continue
|
|
225
|
+
printf '· %s\n' "$f"
|
|
226
|
+
done <<ORDENADOS
|
|
227
|
+
$(printf '%s' "$lista" | LC_ALL=C sort)
|
|
228
|
+
ORDENADOS
|
|
229
|
+
return 0
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
# ---------------------------------------------------------------- 3 y 4 · the jump
|
|
233
|
+
# The same checks the startup scan applies to the key, because the answer to "does this link resolve"
|
|
234
|
+
# has to be the same in both places: normalised, relative to the brain, a single path, a head a
|
|
235
|
+
# `glob:` line reaches, not a symbolic link, and not resolving out of the brain.
|
|
236
|
+
fm_read "$brain/$focus"
|
|
237
|
+
if [ -n "$fm_roto" ]; then
|
|
238
|
+
printf '\n'
|
|
239
|
+
printf "$S_FOCUS_UNREADABLE_HEAD\n" "$fm_roto"
|
|
240
|
+
listar_archivado
|
|
241
|
+
exit 0
|
|
242
|
+
fi
|
|
243
|
+
if [ -z "$fm_about" ]; then
|
|
244
|
+
listar_archivado
|
|
245
|
+
exit 0
|
|
246
|
+
fi
|
|
247
|
+
|
|
248
|
+
destino=$(os_rel_norm "$fm_about")
|
|
249
|
+
motivo=""
|
|
250
|
+
case "$fm_about" in
|
|
251
|
+
*,*|*' '*) motivo="$S_ABOUT_IS_A_LIST" ;;
|
|
252
|
+
esac
|
|
253
|
+
if [ -z "$motivo" ] && ! os_rel_ok "$destino"; then motivo="$S_ABOUT_NOT_RELATIVE"; fi
|
|
254
|
+
if [ -z "$motivo" ] && ! es_cabeza "$destino"; then motivo="$S_ABOUT_NOT_A_HEAD"; fi
|
|
255
|
+
if [ -z "$motivo" ] && [ "$destino" = "$focus" ]; then motivo="$S_ABOUT_SELF"; fi
|
|
256
|
+
if [ -z "$motivo" ] && [ -L "$brain/$destino" ]; then motivo="$S_ABOUT_IS_A_LINK"; fi
|
|
257
|
+
if [ -z "$motivo" ] && ! os_inside_brain "$brain" "$destino"; then motivo="$S_ABOUT_OUT_OF_BRAIN"; fi
|
|
258
|
+
|
|
259
|
+
if [ -n "$motivo" ]; then
|
|
260
|
+
printf '\n'
|
|
261
|
+
printf "$S_FOCUS_ABOUT_UNRESOLVED\n" "$fm_about" "$motivo"
|
|
262
|
+
listar_archivado
|
|
263
|
+
exit 0
|
|
264
|
+
fi
|
|
265
|
+
|
|
266
|
+
printf '\n'
|
|
267
|
+
# Fixed marker, in English, the same in both languages: `core/CLAUDE.md` matches it as a structural
|
|
268
|
+
# identifier, not as translatable prose — the same criterion as `active-role:` (spec 009).
|
|
269
|
+
printf 'about-jump: %s\n' "$destino"
|
|
270
|
+
printf '── %s\n' "$destino"
|
|
271
|
+
cuerpo "$brain/$destino"
|
|
272
|
+
|
|
273
|
+
destino_dir="${destino%/*}"
|
|
274
|
+
if [ "$destino_dir" != "$destino" ] && es_cabeza "$destino_dir/resolver.md"; then
|
|
275
|
+
primera=0
|
|
276
|
+
emitir "$destino_dir/resolver.md"
|
|
277
|
+
fi
|
|
278
|
+
|
|
279
|
+
primera=0
|
|
280
|
+
listar_archivado
|
|
281
|
+
|
|
282
|
+
exit 0
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Deja el manual de usuario enganchado en la raíz del brain, en el idioma del operador (spec 022).
|
|
3
|
+
# Interno: no es invocable. Lo corre `bootstrap.sh` al crear el brain, y lo puede volver a correr
|
|
4
|
+
# cualquier sesión posterior — es lo que le da el manual a un brain creado antes de esta spec.
|
|
5
|
+
#
|
|
6
|
+
# Uso: manual-link.sh --brain DIR [--language en|es]
|
|
7
|
+
#
|
|
8
|
+
# **El enganche es un symlink al manual del producto, no una copia.** El manual se actualiza con el
|
|
9
|
+
# producto: una copia quedaría congelada en la versión del día de la instalación, que es el defecto
|
|
10
|
+
# que este producto ya declaró en sus learnings —una entrega que hay que reinstalar es una capacidad
|
|
11
|
+
# oscura—. Es el mismo criterio con el que viajan `CLAUDE.md`, `.os/core` y los agentes.
|
|
12
|
+
#
|
|
13
|
+
# El nombre del archivo depende del idioma (`os_manual_file`) y queda declarado en `tree.md` como
|
|
14
|
+
# `content:`: se ve en la raíz del brain, y ningún barrido lo lee como trabajo ni lo reporta como no
|
|
15
|
+
# alcanzado.
|
|
16
|
+
#
|
|
17
|
+
# Exit: 0 lo enganchó o ya estaba · 2 el brain no existe o el manual no está en el producto ·
|
|
18
|
+
# 3 hay un archivo propio del operador con ese nombre y no se pisa.
|
|
19
|
+
|
|
20
|
+
set -eu
|
|
21
|
+
|
|
22
|
+
here=$(cd "$(dirname "$0")" && pwd)
|
|
23
|
+
. "$here/common.sh"
|
|
24
|
+
|
|
25
|
+
brain=""
|
|
26
|
+
language=""
|
|
27
|
+
|
|
28
|
+
while [ $# -gt 0 ]; do
|
|
29
|
+
case "$1" in
|
|
30
|
+
--brain) brain="$2"; shift 2 ;;
|
|
31
|
+
--language) language=$(os_lower "$2"); shift 2 ;;
|
|
32
|
+
*) os_die "argumento desconocido: $1" ;;
|
|
33
|
+
esac
|
|
34
|
+
done
|
|
35
|
+
|
|
36
|
+
[ -n "$brain" ] || os_die "falta --brain"
|
|
37
|
+
[ -d "$brain" ] || { printf 'error: no existe el brain: %s\n' "$brain" >&2; exit 2; }
|
|
38
|
+
# Ruta física: ver el comentario de bootstrap.sh.
|
|
39
|
+
brain=$(cd "$brain" && pwd -P)
|
|
40
|
+
|
|
41
|
+
if [ -z "$language" ]; then
|
|
42
|
+
language=$(os_language "$brain")
|
|
43
|
+
elif ! os_language_valido "$language"; then
|
|
44
|
+
os_die "idioma no soportado: $language — hoy: $OS_LANGUAGES"
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
archivo=$(os_manual_file "$language")
|
|
48
|
+
origen="$here/../manual/$archivo"
|
|
49
|
+
if [ ! -f "$origen" ]; then
|
|
50
|
+
printf 'error: el producto no trae el manual %s\n' "$archivo" >&2
|
|
51
|
+
exit 2
|
|
52
|
+
fi
|
|
53
|
+
origen=$(cd "$(dirname "$origen")" && pwd -P)/$archivo
|
|
54
|
+
destino="$brain/$archivo"
|
|
55
|
+
|
|
56
|
+
# Destino real de un symlink, para comparar destinos y no cadenas de ruta — el mismo criterio que
|
|
57
|
+
# usa `install.sh` con `CLAUDE.md`.
|
|
58
|
+
resolver_link() {
|
|
59
|
+
local link="$1" t d
|
|
60
|
+
t=$(readlink "$link") || return 0
|
|
61
|
+
case "$t" in
|
|
62
|
+
/*) ;;
|
|
63
|
+
*) t="$(dirname "$link")/$t" ;;
|
|
64
|
+
esac
|
|
65
|
+
d=$(cd "$(dirname "$t")" 2>/dev/null && pwd -P) || return 0
|
|
66
|
+
[ -n "$d" ] || return 0
|
|
67
|
+
printf '%s/%s' "$d" "$(basename "$t")"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
estado=""
|
|
71
|
+
if [ -L "$destino" ]; then
|
|
72
|
+
if [ "$(resolver_link "$destino")" = "$origen" ]; then
|
|
73
|
+
estado="ya estaba"
|
|
74
|
+
else
|
|
75
|
+
# Un symlink colgado, o hacia otro checkout del producto, es re-instalación: se relinkea callado,
|
|
76
|
+
# igual que `install.sh` con el contrato de sesión.
|
|
77
|
+
ln -sfn "$origen" "$destino"
|
|
78
|
+
estado="reenganchado"
|
|
79
|
+
fi
|
|
80
|
+
elif [ -e "$destino" ]; then
|
|
81
|
+
# Un archivo propio con ese nombre no se pisa: lo que el operador escribió no lo borra una
|
|
82
|
+
# actualización del producto.
|
|
83
|
+
printf 'error: %s ya existe y no es el manual de este producto — no se tocó nada\n' "$destino" >&2
|
|
84
|
+
exit 3
|
|
85
|
+
else
|
|
86
|
+
if ln -sfn "$origen" "$destino" 2>/dev/null; then
|
|
87
|
+
estado="enganchado"
|
|
88
|
+
else
|
|
89
|
+
# Un filesystem sin symlinks (algunos montajes de red, algunas carpetas sincronizadas) deja el
|
|
90
|
+
# manual igual, copiado, y lo dice: un manual copiado se queda en esta versión hasta la próxima
|
|
91
|
+
# corrida de este script.
|
|
92
|
+
cp "$origen" "$destino"
|
|
93
|
+
estado="copiado (este filesystem no acepta symlinks): se queda en esta versión hasta volver a correr este script"
|
|
94
|
+
fi
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
# La declaración en el árbol va siempre, también cuando el manual ya estaba: un brain bootstrapeado
|
|
98
|
+
# antes de esta spec no tiene la línea, y sin ella el barrido reporta el manual como no alcanzado.
|
|
99
|
+
os_tree_ensure "$brain" "$archivo" content || true
|
|
100
|
+
|
|
101
|
+
printf 'manual: %s — %s\n' "$archivo" "$estado"
|
|
102
|
+
|
|
103
|
+
# El manual del otro idioma quedó de una configuración anterior: se declara, no se borra.
|
|
104
|
+
for otro in $OS_LANGUAGES; do
|
|
105
|
+
[ "$otro" = "$language" ] && continue
|
|
106
|
+
viejo=$(os_manual_file "$otro")
|
|
107
|
+
[ "$viejo" = "$archivo" ] && continue
|
|
108
|
+
if [ -e "$brain/$viejo" ] || [ -L "$brain/$viejo" ]; then
|
|
109
|
+
printf 'aviso: %s quedó de un idioma anterior — sacarlo lo elige el operador\n' "$viejo" >&2
|
|
110
|
+
fi
|
|
111
|
+
done
|