ai-first-os 1.10.1 → 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
package/README.md CHANGED
@@ -94,7 +94,7 @@ places, so updating them has two halves and both run:
94
94
  1. **The system.** The agent goes to the local folder where the repository ended up, brings down the
95
95
  newest version and runs `core/install.sh` from that folder.
96
96
  2. **The pack**, if you installed it. The agent runs
97
- `npx skills add pedroromeroluna/ai-first-product-skills` again, which replaces the skills in `.claude/skills/` with the
97
+ `npx skills add pedroromeroluna/ai-first-product-skills` again, which replaces the skills in `.agents/skills/` with the
98
98
  published version. With no pack installed there is nothing to refresh, and this half is skipped.
99
99
 
100
100
  Your brain —your workspaces, your decisions, your content— is not touched: the update only
@@ -110,43 +110,42 @@ brought down, so an update refreshes every brain that points at it.
110
110
 
111
111
  ```
112
112
  my-brain/
113
- ├── CLAUDE.md # Symlink to the session contract: what the agent does at every start
114
- ├── HOW-IT-WORKS.md # The user manual, symlinked in your language (COMO-FUNCIONA.md in Spanish)
115
- ├── operator.md # Who you are and how you want to be answered — written by the interview
116
- ├── voice.md # How you write, so what the agent drafts in your name sounds like you
117
- ├── resolver.md # Your root resolver: capability → tool; its rows win over the product's
118
- ├── tree.md # Which paths a scan walks — a level of the system is a line here
119
- ├── backlog.md # Your own tasks, one line each, in priority order (born on first capture)
120
- ├── inbox.md # Transit for what could not be filed yet — never a destination
121
- ├── mounts.md # Which repos are mounted onto which initiatives (born on first mount-repo)
122
- ├── decisions.md # Index of your decisions: one line each, linking to its own file
123
- ├── decisions/<date>-<slug>.md # One decision per file: what, why, and what would invalidate it
124
- ├── learnings.md # Index of your learnings: one line each, linking to its own file
125
- ├── learnings/<slug>.md # One learning per file, no date in the name — it updates in place
126
- ├── initiatives/<slug>/README.md # Your own initiatives, one folder each, with status/horizon/owner up top
127
- ├── workspaces/ # One folder per workspace — the isolation boundary
113
+ ├── AGENTS.md # Symlink to the session contract: what the agent does at every start. Read-only on an installed copy
114
+ ├── HOW-IT-WORKS.md # The user manual, symlinked in your language (it is the Spanish manual in a Spanish brain)
115
+ ├── account/
116
+ │ ├── operator.md # Who you are and how you want to be answered — written by the interview. Your own rules go here
117
+ │ └── voice/voice.md # How you write, so what the agent drafts in your name sounds like you
118
+ ├── .system/
119
+ │ ├── resolver.md # Your root resolver: capability → tool; its rows win over the product's
120
+ │ ├── tree.md # Which paths a scan walks — a level of the system is a line here
121
+ │ └── mounts.md # Which repos are mounted onto which initiatives (born on first mount-repo)
122
+ ├── workspaces/ # One folder per workspace — the isolation boundary. `personal` is your
123
+ │ │ # own work, born with the brain; a company or a client is another one
128
124
  │ └── <workspace>/
129
125
  │ ├── README.md # Its identity, and the `role:` it activates (cpo, cto)
130
126
  │ ├── resolver.md # Where whatever gets written in this workspace goes
131
- │ ├── backlog.md # Its tasks
132
- │ ├── decisions.md # Its decisions, indexed the same way
133
- │ ├── decisions/ # Its decisions' own files
134
- │ ├── learnings.md # Its learnings, indexed the same way
135
- │ ├── learnings/ # Its learnings' own files
136
- │ ├── initiatives/ # Its initiatives, one folder each with its `README.md` inside
127
+ │ ├── decisions.md # Index of its decisions: one line each, linking to its own file
128
+ │ ├── decisions/<date>-<slug>.md # One decision per file: what, why, and what would invalidate it
129
+ │ ├── learnings.md # Index of its learnings: one line each, linking to its own file
130
+ │ ├── learnings/<slug>.md # One learning per file, no date in the name — it updates in place
131
+ │ ├── initiatives/<slug>/README.md # Its initiatives, one folder each, status/horizon/owner up top
132
+ │ ├── initiatives/<slug>/backlog.md # That initiative's tasks, one line each (born on its first capture)
137
133
  │ └── <type>/<slug>/ # A memory node of any declared type — products/ is the one this system ships with its own tool
138
134
  │ └── README.md # Born with `new-memory --type <type>` (`new-product` is its `products` shortcut); `context/` and `research/` are filled by whatever tool the type has, or by hand
139
135
  ├── .os/
140
136
  │ ├── core -> …/ai-first-os/core # The chassis by symlink: the eleven system skills in core/skills/, the shell in core/lib/
141
137
  │ └── packs/<pack> -> … # Each installed pack, by symlink
138
+ ├── .agents/skills/ # The pack's skills, left here by `npx skills add` (born with the first skill)
142
139
  └── .claude/
140
+ ├── CLAUDE.md # The same symlink as AGENTS.md: Claude Code reads the contract from here
143
141
  ├── agents/ # complete-spec, ambiguous-spec, scout — one symlink each
144
- └── skills/ # The pack's skills, left here by `npx skills add`
142
+ └── skills/ # A link to each skill of .agents/skills/, which is where Claude Code looks
145
143
  ```
146
144
 
147
- The interview writes `operator.md`, `voice.md`, `resolver.md`, `tree.md` and one `workspaces/<slug>/`
148
- per workspace you named. The rest is born the first time it is needed: `backlog.md` on the first
149
- capture, `mounts.md` on the first mounted repo, `decisions.md`/`decisions/` and
145
+ The interview writes `account/operator.md`, `account/voice/voice.md`, `.system/resolver.md`, `.system/tree.md` and `workspaces/personal/` —
146
+ your own work, the one every brain is born with — plus one more `workspaces/<slug>/` per workspace
147
+ you named. The rest is born the first time it is needed: an initiative's `backlog.md` on
148
+ its first capture, `.system/mounts.md` on the first mounted repo, `decisions.md`/`decisions/` and
150
149
  `learnings.md`/`learnings/` when there is something to record — one file per decision and per
151
150
  learning, with the `.md` index left as the table of contents so a session opens only the one it
152
151
  needs instead of the whole register.
@@ -154,9 +153,10 @@ needs instead of the whole register.
154
153
  **Where the skills live.** The eleven skills of the system are not copied into your brain: they live
155
154
  in `.os/core/skills/`, a symlink to the `core/` of the repository you brought down, and the agent
156
155
  reaches them through the resolver. The skills of the pack are what `npx skills add` installs: one
157
- folder per skill under `.claude/skills/<name>/SKILL.md` — the place your harness reads skills from,
158
- which is why they show up as `/cpo`, `/prd` and so on — plus `product-builder-resolver`, the pack's
159
- index. Your own skills, if you write any, go next to them as plain folders in `.claude/skills/`.
156
+ folder per skill under `.agents/skills/<name>/SKILL.md`, with a link to each one in `.claude/skills/`
157
+ —the place Claude Code reads skills from, which is why they show up as `/cpo`, `/prd` and so on— plus
158
+ `product-builder-resolver`, the pack's index. Your own skills, if you write any, go next to them as
159
+ plain folders in `.claude/skills/`.
160
160
 
161
161
  ## The catalog
162
162
 
@@ -172,7 +172,7 @@ context.
172
172
  | `bootstrap` | Creates the brain from scratch: identity, voice, root resolver, the tree of paths a scan walks, one folder per workspace |
173
173
  | `new-workspace` | Adds a workspace — the isolation boundary — with its identity, its resolver and its initiatives |
174
174
  | `new-product` | Adds a product to a workspace — memory: what it is, for whom, what is known — with its identity |
175
- | `new-memory` | Creates a memory-node type the first time it is used —a folder plus its five lines in `tree.md`— and adds a node to it; `--root` for a type of the operator's own work |
175
+ | `new-memory` | Creates a memory-node type the first time it is used —a folder plus its five lines in `tree.md`— and adds a node to it, inside the workspace it belongs to |
176
176
  | `sweep` | The three global scans: what is pending, what is blocked and why, how the roadmap is going |
177
177
  | `check-resolvable` | Audits the capability-to-tool graph and reports dark tools, broken links and rows pointing nowhere |
178
178
  | `capture` | Files what you throw in mid-conversation into the right backlog, without opening a discussion |
@@ -183,9 +183,11 @@ context.
183
183
  | `supersede` | Marks a file as replaced by another —`superseded_by:` in the frontmatter of the old one— so a session that opens it knows what to read instead, and audits the marks of the whole brain |
184
184
  | `rename-workspaces` | Adopts the current name of the workspaces folder on a brain born before it, run only when the operator asks |
185
185
  | `rename-heads` | Adopts the single node shape —a folder with its `README.md` inside— on a brain born before it, run only when the operator asks |
186
+ | `migrate-root` | Moves a brain's own root work —initiatives, a memory-node type, backlog, decisions, learnings— into `workspaces/personal`, run only when the operator asks |
187
+ | `migrate-layout` | Brings a brain with the old layout to the new one, printing the whole plan first and writing nothing until `--apply`; run only when the operator asks |
186
188
  | `archive` | Moves a document into the node's `archive/` so the focus lists it by name instead of loading it, rewriting every reference that pointed at it, and lists what the brain already declared replaced and still loads |
187
189
  | `recall` | Searches every file the tree reaches for a lateral question, ranked with file, line and date, current work ahead of whatever replaced it, and one jump to a result's neighbours with `--expand` |
188
- | `my-wiki` | Projects the brain as one navigable page — a workspace selector, a shelf per entity type the tree declares, the initiatives under the entity each one is about, the people, what changed and a search that runs in the page — generated by script, published as an artifact by the session |
190
+ | `orchestrator` | Optional, off until you ask: one session that hands each topic's work to that topic's session and keeps what it needs to remember in a hidden file, with a full mode in the desktop app and a reduced one in the terminal |
189
191
 
190
192
  ### Knowledge skills
191
193
 
package/core/CLAUDE.md CHANGED
@@ -1,38 +1,52 @@
1
+ > [!WARNING]
2
+ > **Do not edit this file.** It is the rule book of the system, the same for everyone who uses it,
3
+ > and it is kept read-only on purpose. If you edit it anyway, your change is lost the next time the
4
+ > system is updated, and until then your sessions follow a rule book that nobody reviewed. Your own
5
+ > rules go in `account/operator.md`.
6
+
1
7
  # Session contract
2
8
 
3
9
  This file is a symlink to the product. **It is never edited from the brain**: changing it is a PR
4
- in the product repo. Nothing about the operator lives here; that belongs in `operator.md`.
10
+ in the product repo. Nothing about the operator lives here; that belongs in `account/operator.md`.
5
11
 
6
12
  ## When the session starts
7
13
 
8
- **The first message names the scope being worked on: a workspace, or your own work (the root).**
9
- If it does not name one, list the slugs under the workspaces folder alongside the root and ask
10
- which. Never guess it: the context of one scope inside the work of another is the most expensive
11
- failure in the system.
14
+ **The first message names the scope being worked on: a workspace.** Every brain has at least one —
15
+ `personal`, the operator's own work, is the one every brain is born with. If the message does not
16
+ name one, list the slugs under the workspaces folder and ask which. Never guess it: the context of
17
+ one scope inside the work of another is the most expensive failure in the system.
12
18
 
13
19
  Before answering the first message, in this order:
14
20
 
15
- 1. Run the startup scan, with whichever scope applies:
21
+ 1. Run the startup scan, with the workspace:
16
22
 
17
23
  ```
18
24
  .os/core/lib/session-start.sh --brain . --workspace <slug>
19
- .os/core/lib/session-start.sh --brain . --root
20
25
  ```
21
26
 
22
27
  If it exits non-zero, the workspace does not exist: show the slugs it listed and ask — or the
23
28
  installation is broken (its bilingual catalog is missing), and the error message says which.
24
29
 
25
- 2. Run the startup read, with the same scope:
30
+ 2. Run the startup read, with the same workspace:
26
31
 
27
32
  ```
28
33
  .os/core/lib/session-read.sh --brain . --workspace <slug>
29
- .os/core/lib/session-read.sh --brain . --root
30
34
  ```
31
35
 
32
36
  It prints everything the session loads before answering, in the order it has to be read. That
33
37
  order lives in the header of `session-read.sh` and nowhere else: it is not repeated here, and
34
38
  it is not rebuilt by hand. What the read declares as not being there was not read.
35
39
 
40
+ If the read prints `tree-declared:`, it added a missing `content:` line to the brain's `.system/tree.md`:
41
+ commit `.system/tree.md` in that same turn, like any other file the brain edits. If it prints
42
+ `tree-declare-failed:`, that line could not be written: tell the operator, in outcome language, what
43
+ could not be written and the reason the line gives, and do not retry silently.
44
+
45
+ If the read prints `gitignore-declared:`, it generated an index for the first time and added that
46
+ exact path to the brain's `.gitignore`: commit `.gitignore` in that same turn, the same way. The
47
+ index itself is never committed. If it prints `gitignore-declare-failed:`, that index could not be
48
+ kept out of git and was not written: tell the operator, in outcome language, and do not retry silently.
49
+
36
50
  If any of them is missing, say so and continue degraded. Its content is never assumed.
37
51
 
38
52
  English is the source language of every new component of the system; Spanish exists as a
@@ -128,14 +142,36 @@ in the product's root resolver.
128
142
  which also audits the marks of the whole brain.
129
143
  - **A node declares what it is about**, with `about: <path relative to the brain>` in the
130
144
  frontmatter of its head, naming the head of the node this one is about: a product, an account, a
131
- channel — whatever a `glob:` line of the tree reaches. It names exactly one, and the focus read
132
- loads that head and the `resolver.md` beside it and stops there: one jump, never a chain. A value
133
- that names no head is a finding of the startup scan, never a key that gets ignored.
145
+ channel, a course. It can name several, on one line: `about: [<path>, <path>]`. It is optional.
146
+ The focus read loads each head it names, the `.resolver.md` beside it and its key decisions, and
147
+ stops there: one jump, never a chain — one per value. A value that names no head is a finding of the
148
+ startup scan, never a key that gets ignored.
134
149
  - **Archiving a document is moving it into the node's `archive/`**, with `archive`. The focus prints
135
150
  the names of what is archived and opens none of it; the lateral search still looks inside it and
136
151
  `supersede` still audits it. Nothing archives itself, and nothing suggests archiving by age: what
137
152
  the operator is offered is `archive --stale`, the documents the brain already declared replaced and
138
153
  still keeps outside `archive/`.
154
+ - **Before writing a text to publish, read the voice of whoever signs it**: `account/voice/voice.md`
155
+ for the operator, `workspaces/<slug>/resources/voice.md` for a brand. The startup read does not
156
+ load the voice: it is read at the moment of writing.
157
+ - **Images, video and audio live outside the brain**; the brain keeps the path to them.
158
+ - **Folders and files the system defines are named in English**; a document a person writes keeps
159
+ the language it is written in.
160
+ - **What only the system reads starts with a dot**; what a person reads or edits stays visible.
161
+ - **The AI never edits a file with `generated: true`**: it edits the source that file names.
162
+ - **What still serves once the initiative ends goes to the node; what serves only that round goes to
163
+ the initiative.** The AI applies this alone when it is clear; what changes the structure (creating
164
+ a node, moving existing content) it proposes and the operator decides; what is doubtful it asks in
165
+ one line, with its recommendation; all of it shows in the verdict of the close.
166
+ - **Every task lives in the backlog of an initiative.** The task of a node with no project of its
167
+ own goes to that node's standing initiative (`capture --about`); one that fits no initiative: the
168
+ AI proposes a small one and never creates it alone.
169
+ - **Every proposal of the AI says what it will do and what for, in plain words, and asks for
170
+ confirmation** — creating an initiative, creating a node, moving content —, with none of the
171
+ system's vocabulary. Without the confirmation it writes nothing, and says so.
172
+ - **The AI talks to the operator as in a plain conversation, with none of the system's
173
+ vocabulary.** When the operator doubts how the brain works, the AI explains it and cites the
174
+ section of `HOW-IT-WORKS.md` the explanation comes from.
139
175
  - **A lateral question — anything not already loaded by the startup or the focus — runs `recall` in
140
176
  the session's own scope before any `grep`.** Two `current` results that contradict each other are
141
177
  reported as ❓, never picked between in silence.
package/core/VERSION CHANGED
@@ -1 +1 @@
1
- 1.10.1
1
+ 2.0.0
package/core/install.sh CHANGED
@@ -5,16 +5,27 @@
5
5
  # Uso: install.sh RUTA-BRAIN [--adopt]
6
6
  #
7
7
  # Qué deja en el brain:
8
- # CLAUDE.md -> symlink al contrato de sesión del producto
8
+ # AGENTS.md -> symlink al contrato de sesión del producto (lo leen Codex, Cursor, OpenCode)
9
+ # .claude/CLAUDE.md -> symlink al mismo contrato (lo lee Claude Code)
9
10
  # .os/core -> symlink a core/
10
11
  # .os/packs/<pack> -> symlink a cada pack
11
12
  # .claude/agents/<n> -> symlink a cada agente de core/agents/, uno por archivo (el harness del
12
13
  # operador los lee de ahí; symlinkear el directorio entero se
13
14
  # llevaría por delante configuración propia del operador en .claude/)
15
+ # No crea CLAUDE.md en la raíz (spec 076): un CLAUDE.md que ya sea un enlace al producto, de una
16
+ # instalación anterior, se deja como está.
14
17
  #
15
- # --adopt: si el brain ya tiene un CLAUDE.md que no es el de este producto —propio, o symlink a
16
- # otro— lo guarda como CLAUDE.md.adopted, un nombre que ningún harness carga, y engancha el
17
- # symlink. Sin --adopt el instalador para y no toca nada.
18
+ # Los dos enlaces se crean siempre; el instalador no pregunta con qué agente se va a trabajar.
19
+ #
20
+ # Si el producto instalado es una copia (su raíz no tiene `.git`), el contrato queda en solo lectura:
21
+ # editarlo cambia el sistema de todos los que lo usan. En un checkout de desarrollo no se tocan los
22
+ # permisos y una línea lo dice.
23
+ #
24
+ # --adopt: si el brain ya tiene un reglamento que no es el de este producto —un archivo propio o un
25
+ # symlink a otro— en `CLAUDE.md`, `AGENTS.md` o `.claude/CLAUDE.md`, su contenido se agrega al final de
26
+ # `account/operator.md` (en ese orden), el archivo ajeno se borra y queda el enlace al producto. Sin
27
+ # --adopt el instalador para y no toca nada. `--adopt` necesita que `account/operator.md` exista (el
28
+ # bootstrap lo escribe): sin él, frena y no toca nada.
18
29
 
19
30
  set -eu
20
31
 
@@ -43,11 +54,35 @@ fi
43
54
  mkdir -p "$brain"
44
55
  brain=$(cd "$brain" && pwd)
45
56
 
46
- # El idioma del brain, leído una sola vez acá: lo usan tanto el aviso del nombre anterior de la
47
- # carpeta de espacios de trabajo como la línea de versión, más abajo. Mismo criterio liviano que el
48
- # resto de este script — sin `lib/`, porque el instalador es lo primero que corre.
57
+ # ---------------------------------------------------------------- lectura liviana del catálogo
58
+ # Sin `lib/`: el instalador es lo primero que se corre y no puede depender del layout de lo que
59
+ # instala. La usan el aviso del nombre anterior de la carpeta y la línea de versión, más abajo.
60
+ catalogo_linea() {
61
+ local key="$1" lang="$2" file="$core/templates/strings.md" line dentro=0 valor=""
62
+ [ -f "$file" ] || return 0
63
+ while IFS= read -r line || [ -n "$line" ]; do
64
+ case "$line" in
65
+ "key: $key") dentro=1; continue ;;
66
+ 'key: '*) [ "$dentro" = "1" ] && break; continue ;;
67
+ esac
68
+ [ "$dentro" = "1" ] || continue
69
+ case "$line" in
70
+ "$lang: "*) valor="${line#$lang: }"; break ;;
71
+ 'en: '*) [ -n "$valor" ] || valor="${line#en: }" ;;
72
+ esac
73
+ done < "$file"
74
+ printf '%s' "$valor"
75
+ }
76
+
77
+ # El idioma del brain, leído una sola vez acá: lo usan los avisos del catálogo y la línea de versión,
78
+ # más abajo. Mismo criterio liviano que el resto de este script — sin `lib/`, porque el instalador es
79
+ # lo primero que corre.
49
80
  lang="en"
50
- if [ -f "$brain/operator.md" ]; then
81
+ # A brain not migrated yet still has its `operator.md` at the root: its language is read from there so
82
+ # the messages come out in the language the operator chose (the file is only read, never moved).
83
+ lang_file="$brain/account/operator.md"
84
+ [ -f "$lang_file" ] || lang_file="$brain/operator.md"
85
+ if [ -f "$lang_file" ]; then
51
86
  while IFS= read -r line || [ -n "$line" ]; do
52
87
  case "$line" in
53
88
  'language: '*)
@@ -55,12 +90,14 @@ if [ -f "$brain/operator.md" ]; then
55
90
  break
56
91
  ;;
57
92
  esac
58
- done < "$brain/operator.md"
93
+ done < "$lang_file"
59
94
  fi
60
95
 
61
96
  claude="$brain/CLAUDE.md"
97
+ agents="$brain/AGENTS.md"
98
+ claude_dir="$brain/.claude/CLAUDE.md"
62
99
  claude_target="$core/CLAUDE.md"
63
- adopted="$brain/CLAUDE.md.adopted"
100
+ operator_file="$brain/account/operator.md"
64
101
  # Ruta física de este producto, para comparar destinos y no cadenas. El instalador resuelve esto
65
102
  # solo, sin lib/: es lo primero que se corre y no puede depender del layout de lo que instala.
66
103
  core_real=$(cd "$core" && pwd -P)
@@ -79,32 +116,96 @@ resolve_link() {
79
116
  printf '%s/%s' "$d" "$(basename "$t")"
80
117
  }
81
118
 
82
- # Chequeo antes de tocar nada. Adoptar es para un CLAUDE.md **ajeno**: un archivo propio del
119
+ # Destino real de un symlink, siguiendo la cadena de enlaces (hasta 10 saltos).
120
+ resolve_chain() {
121
+ local cur="$1" hops=0 next
122
+ while [ -L "$cur" ] && [ "$hops" -lt 10 ]; do
123
+ next=$(resolve_link "$cur")
124
+ [ -n "$next" ] || return 0
125
+ cur="$next"
126
+ hops=$(( hops + 1 ))
127
+ done
128
+ printf '%s' "$cur"
129
+ }
130
+
131
+ # Chequeo antes de tocar nada. Adoptar es para un reglamento **ajeno**: un archivo propio del
83
132
  # operador, o un symlink vivo hacia otro producto. Lo que no es adopción es re-instalación, y se
84
133
  # relinkea callado: un symlink colgado —el producto se movió— y uno que ya apunta acá escrito de
85
134
  # otra forma. Comparar por cadena de ruta trataba a los dos como ajenos: al colgado lo "adoptaba"
86
- # dejando un CLAUDE.md.adopted roto, y al otro le pedía --adopt sin motivo.
87
- needs_adopt=0
88
- if [ -L "$claude" ]; then
89
- if [ -e "$claude" ] && [ "$(resolve_link "$claude")" != "$core_real/CLAUDE.md" ]; then
90
- needs_adopt=1
135
+ # y al otro le pedía --adopt sin motivo. Se chequean los tres lugares donde un harness carga un
136
+ # reglamento: `CLAUDE.md`, `AGENTS.md` y `.claude/CLAUDE.md` (spec 076), en ese orden.
137
+ foreign=()
138
+ for loc in "$claude" "$agents" "$claude_dir"; do
139
+ if [ -L "$loc" ]; then
140
+ if [ -e "$loc" ] && [ "$(resolve_chain "$loc")" != "$core_real/CLAUDE.md" ]; then
141
+ foreign+=("$loc")
142
+ fi
143
+ elif [ -e "$loc" ]; then
144
+ foreign+=("$loc")
91
145
  fi
92
- elif [ -e "$claude" ]; then
93
- needs_adopt=1
94
- fi
146
+ done
95
147
 
96
- if [ "$needs_adopt" = "1" ]; then
148
+ if [ "${#foreign[@]}" -gt 0 ]; then
97
149
  if [ "$adopt" = "0" ]; then
98
- printf 'error: %s ya existe y no es el contrato de este producto.\n' "$claude" >&2
99
- printf ' Correlo con --adopt: lo guarda como CLAUDE.md.adopted y engancha el symlink.\n' >&2
100
- printf ' Ese nombre no lo carga ningún harness. Lo que valga de ahí se mueve a mano a\n' >&2
101
- printf ' operator.md.\n' >&2
150
+ formato=$(catalogo_linea INSTALL_FOREIGN_CONTRACT "$lang")
151
+ printf "$formato\n" "${foreign[*]}" >&2
102
152
  exit 1
103
153
  fi
104
- if [ -e "$adopted" ] || [ -L "$adopted" ]; then
105
- printf 'error: %s ya existe. Resolvelo a mano antes de volver a correr --adopt.\n' "$adopted" >&2
154
+ if [ ! -f "$operator_file" ]; then
155
+ formato=$(catalogo_linea INSTALL_ADOPT_NEEDS_OPERATOR "$lang")
156
+ printf "$formato\n" "$operator_file" >&2
106
157
  exit 1
107
158
  fi
159
+ # Snapshot of every foreign source, taken before ANY link is touched (`.os/core` included: a foreign
160
+ # `AGENTS.md` that points at the `.os/core/CLAUDE.md` of another product reads that product's text
161
+ # only until this installer relinks `.os/core`). Each source must resolve to a readable regular
162
+ # file; a link to a folder, or an unreadable file, stops the run before anything is written.
163
+ # Aliases are deduped by their resolved target (`AGENTS.md` -> `CLAUDE.md` is one text, not two).
164
+ stage_dir=$(mktemp -d)
165
+ trap 'rm -rf "$stage_dir"' EXIT
166
+ n_snap=0
167
+ seen_real=""
168
+ snap_labels=()
169
+ for loc in "${foreign[@]}"; do
170
+ if [ -L "$loc" ]; then
171
+ real=$(resolve_chain "$loc")
172
+ else
173
+ real="$(cd -P "$(dirname "$loc")" 2>/dev/null && pwd -P)/$(basename "$loc")"
174
+ fi
175
+ if [ -z "$real" ] || [ ! -f "$real" ] || [ ! -r "$real" ]; then
176
+ formato=$(catalogo_linea INSTALL_ADOPT_NOT_A_FILE "$lang")
177
+ printf "$formato\n" "$loc" >&2
178
+ exit 1
179
+ fi
180
+ case "
181
+ $seen_real
182
+ " in
183
+ *"
184
+ $real
185
+ "*) continue ;;
186
+ esac
187
+ seen_real="$seen_real
188
+ $real"
189
+ n_snap=$(( n_snap + 1 ))
190
+ cp "$real" "$stage_dir/src-$n_snap"
191
+ snap_labels+=("${loc#$brain/}")
192
+ done
193
+ # The complete new `account/operator.md`, staged: written in one step further down, so a stop
194
+ # anywhere before it leaves the file as it was and a retry never doubles the heading or a text.
195
+ cat "$operator_file" > "$stage_dir/operator.new"
196
+ if [ -s "$operator_file" ] && [ -n "$(tail -c 1 "$operator_file")" ]; then
197
+ printf '\n' >> "$stage_dir/operator.new"
198
+ fi
199
+ printf '\n## %s\n' "$(catalogo_linea INSTALL_ADOPTED_HEADING "$lang")" >> "$stage_dir/operator.new"
200
+ i_snap=0
201
+ for label in "${snap_labels[@]}"; do
202
+ i_snap=$(( i_snap + 1 ))
203
+ printf '\n### %s\n\n' "$label" >> "$stage_dir/operator.new"
204
+ cat "$stage_dir/src-$i_snap" >> "$stage_dir/operator.new"
205
+ if [ -s "$stage_dir/src-$i_snap" ] && [ -n "$(tail -c 1 "$stage_dir/src-$i_snap")" ]; then
206
+ printf '\n' >> "$stage_dir/operator.new"
207
+ fi
208
+ done
108
209
  fi
109
210
 
110
211
  # La guarda del self-link (spec 016): si el destino de un enlace por escribir resuelve —tras
@@ -137,7 +238,8 @@ for agent in "$core"/agents/*.md; do
137
238
  [ -f "$agent" ] || continue
138
239
  guard_selflink "$brain/.claude/agents/$(basename "$agent")" "$agent"
139
240
  done
140
- guard_selflink "$claude" "$claude_target"
241
+ guard_selflink "$agents" "$claude_target"
242
+ guard_selflink "$claude_dir" "$claude_target"
141
243
 
142
244
  mkdir -p "$brain/.os/packs"
143
245
  ln -sfn "$core" "$brain/.os/core"
@@ -176,15 +278,33 @@ for agent in "$core"/agents/*.md; do
176
278
  ln -sfn "$agent" "$brain/.claude/agents/$(basename "$agent")"
177
279
  done
178
280
 
179
- if [ "$needs_adopt" = "1" ]; then
180
- mv "$claude" "$adopted"
181
- printf 'aviso: el CLAUDE.md que estaba en el brain quedó como CLAUDE.md.adopted.\n' >&2
182
- printf ' Ningún harness lo carga. Lo que valga de ahí va a operator.md.\n' >&2
281
+ # Adoptar (spec 076, C4): el contenido de cada reglamento ajeno va al final de `account/operator.md`,
282
+ # bajo un encabezado fijo del catálogo y en el orden CLAUDE.md, AGENTS.md, .claude/CLAUDE.md; el
283
+ # archivo ajeno se borra y queda el enlace. Nada de esto corre antes de que todos los chequeos de
284
+ # arriba hayan pasado.
285
+ if [ "${#foreign[@]}" -gt 0 ]; then
286
+ cat "$stage_dir/operator.new" > "$operator_file"
287
+ # `AGENTS.md` and `.claude/CLAUDE.md` are replaced by their links below; only a foreign root
288
+ # `CLAUDE.md` (file or link) has no link to take its place and is removed.
289
+ for loc in "${foreign[@]}"; do
290
+ [ "$loc" = "$claude" ] && rm -f "$claude"
291
+ done
292
+ formato=$(catalogo_linea INSTALL_ADOPTED_NOTICE "$lang")
293
+ printf "$formato\n" "account/operator.md" >&2
294
+ fi
295
+
296
+ mkdir -p "$brain/.claude"
297
+ ln -sfn "$claude_target" "$agents"
298
+ ln -sfn "$claude_target" "$claude_dir"
299
+ # Un CLAUDE.md de la raíz que es un enlace roto, o ya apunta al producto, de una instalación anterior,
300
+ # se refresca para que no quede colgado; nunca se crea uno.
301
+ if [ -L "$claude" ]; then
302
+ ln -sfn "$claude_target" "$claude"
183
303
  fi
184
- ln -sfn "$claude_target" "$claude"
185
304
 
186
305
  printf 'brain: %s\n' "$brain"
187
- printf 'CLAUDE.md -> %s\n' "$claude_target"
306
+ printf 'AGENTS.md -> %s\n' "$claude_target"
307
+ printf '.claude/CLAUDE.md -> %s\n' "$claude_target"
188
308
  printf '.os/core -> %s\n' "$core"
189
309
  for pack in "$product"/packs/*; do
190
310
  [ -d "$pack" ] || continue
@@ -195,25 +315,26 @@ for agent in "$core"/agents/*.md; do
195
315
  printf '.claude/agents/%s -> %s\n' "$(basename "$agent")" "$agent"
196
316
  done
197
317
 
198
- # ---------------------------------------------------------------- lectura liviana del catálogo
199
- # Sin `lib/`: el instalador es lo primero que se corre y no puede depender del layout de lo que
200
- # instala. La usan el aviso del nombre anterior de la carpeta y la línea de versión, más abajo.
201
- catalogo_linea() {
202
- local key="$1" lang="$2" file="$core/templates/strings.md" line dentro=0 valor=""
203
- [ -f "$file" ] || return 0
204
- while IFS= read -r line || [ -n "$line" ]; do
205
- case "$line" in
206
- "key: $key") dentro=1; continue ;;
207
- 'key: '*) [ "$dentro" = "1" ] && break; continue ;;
208
- esac
209
- [ "$dentro" = "1" ] || continue
210
- case "$line" in
211
- "$lang: "*) valor="${line#$lang: }"; break ;;
212
- 'en: '*) [ -n "$valor" ] || valor="${line#en: }" ;;
213
- esac
214
- done < "$file"
215
- printf '%s' "$valor"
216
- }
318
+ # ---------------------------------------------------------------- el contrato, en solo lectura (spec 076, C6)
319
+ # Una copia instalada del producto (su raíz no tiene `.git`) deja el contrato sin permiso de escritura:
320
+ # editarlo cambia el sistema de todos los que lo usan, y las reglas propias van en
321
+ # `account/operator.md`. Un checkout de desarrollo (con `.git`, carpeta o archivo de worktree) es
322
+ # donde el contrato se edita: no se toca ningún permiso y una línea lo dice. Solo se bloquea el
323
+ # contrato; nada más del brain ni del producto.
324
+ if [ -e "$product/.git" ]; then
325
+ formato=$(catalogo_linea INSTALL_CONTRACT_DEV "$lang")
326
+ [ -z "$formato" ] || printf '%s\n' "$formato"
327
+ else
328
+ chmod a-w "$core/CLAUDE.md" 2>/dev/null || true
329
+ # Say what actually happened: the permission is checked after the `chmod`, never assumed from it.
330
+ if [ -w "$core/CLAUDE.md" ]; then
331
+ formato=$(catalogo_linea INSTALL_CONTRACT_NOT_LOCKED "$lang")
332
+ [ -z "$formato" ] || printf '%s\n' "$formato" >&2
333
+ else
334
+ formato=$(catalogo_linea INSTALL_CONTRACT_LOCKED "$lang")
335
+ [ -z "$formato" ] || printf '%s\n' "$formato"
336
+ fi
337
+ fi
217
338
 
218
339
  # ---------------------------------------------------------------- aviso del nombre anterior (P6, spec 039)
219
340
  # Un brain con la carpeta de espacios de trabajo todavía en su nombre anterior sigue funcionando