Skip to content

Commit 82e2efe

Browse files
committed
📘 docs(READMEs): Improving README structure and consistency
Also improving `AGENTS.md` file structure to better optimize agent context and performance. [[NT-2776](https://contentful.atlassian.net/browse/NT-2776)]
1 parent 9e9f210 commit 82e2efe

60 files changed

Lines changed: 2236 additions & 3717 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.husky/pre-push

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ package_tarballs_exist() {
1111
find pkgs -maxdepth 1 -name "contentful-*.tgz" -print -quit 2>/dev/null | grep -q .
1212
}
1313

14+
is_documentation_file() {
15+
local file=$1
16+
17+
case "$file" in
18+
*.md | *.mdx | *.markdown | documentation/* | docs/* | */documentation/* | */docs/*)
19+
return 0
20+
;;
21+
*)
22+
return 1
23+
;;
24+
esac
25+
}
26+
1427
# Collect changed files for each pushed ref from pre-push hook input
1528
# Input rows: <local ref> <local sha> <remote ref> <remote sha>
1629
changed_files=""
@@ -46,6 +59,25 @@ done
4659

4760
changed_files=$(printf "%s" "$changed_files" | sed '/^$/d' | sort -u)
4861

62+
if [ -z "$changed_files" ]; then
63+
echo "No changed files detected for checks."
64+
exit 0
65+
fi
66+
67+
substantive_changed_files=""
68+
while IFS= read -r changed_file; do
69+
if ! is_documentation_file "$changed_file"; then
70+
substantive_changed_files+="$changed_file"$'\n'
71+
fi
72+
done <<<"$changed_files"
73+
74+
substantive_changed_files=$(printf "%s" "$substantive_changed_files" | sed '/^$/d' | sort -u)
75+
76+
if [ -z "$substantive_changed_files" ]; then
77+
echo "Only documentation-related changes detected; skipping build and check hook."
78+
exit 0
79+
fi
80+
4981
# List workspaces (relative paths)
5082
workspaces=$(pnpm ls -r --depth -1 --json | jq -r ".[].path" | sed "s|^$REPO_ROOT/||")
5183

@@ -55,7 +87,7 @@ implementations=$(find implementations -mindepth 1 -maxdepth 1 -type d -exec bas
5587
# Find changed workspaces with tsconfig.json
5688
changed_workspaces=()
5789
for workspace in $workspaces; do
58-
if echo "$changed_files" | grep -q "^$workspace/"; then
90+
if echo "$substantive_changed_files" | grep -q "^$workspace/"; then
5991
[ -f "$workspace/tsconfig.json" ] && changed_workspaces+=("$workspace")
6092
fi
6193
done
@@ -64,7 +96,7 @@ done
6496
changed_implementations=()
6597
for implementation in $implementations; do
6698
implementation_path="implementations/$implementation"
67-
if echo "$changed_files" | grep -q "^$implementation_path/"; then
99+
if echo "$substantive_changed_files" | grep -q "^$implementation_path/"; then
68100
[ -f "$implementation_path/tsconfig.json" ] && changed_implementations+=("$implementation")
69101
fi
70102
done

AGENTS.md

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# AGENTS.md
22

3-
This file defines repository-wide rules only. For any change, read this file first, then read the
4-
nearest `AGENTS.md` in the subtree you are editing.
3+
This file defines repository-wide rules only. For any change, read this file first, then read each
4+
applicable child `AGENTS.md` from outermost to nearest in the subtree you are editing.
55

66
## Hierarchy
77

88
- The root `AGENTS.md` owns stable repo-wide policy.
9-
- `lib/*/AGENTS.md`, `packages/**/AGENTS.md`, and `implementations/*/AGENTS.md` own local
10-
instructions, commands, and gotchas.
9+
- `packages/AGENTS.md` and `implementations/AGENTS.md` own shared policy for all packages and
10+
reference implementations.
11+
- `lib/*/AGENTS.md`, `packages/**/AGENTS.md`, and `implementations/*/AGENTS.md` own more specific
12+
local instructions, commands, and gotchas.
1113
- If local guidance conflicts with this file, follow the more specific `AGENTS.md` for that subtree.
1214
- When adding a new workspace package or implementation, add a sibling `AGENTS.md` in the same
1315
change.
@@ -106,14 +108,7 @@ Do not hand-edit generated or local-only artifacts unless the task is explicitly
106108
before finishing if the change grew.
107109
- For `implementations/` edits, prefer `pnpm implementation:lint` after the first meaningful patch
108110
and again before finishing if the change grew.
109-
- For a single workspace package, prefer targeted `typecheck`, `test:unit`, and `build`.
110-
- For built workspace packages, run the package `size:check` script when runtime code, published
111-
dependencies, bundler config, exports, or bundle shape changes.
112111
- For cross-cutting changes, broaden validation to affected downstream packages or implementations.
113-
- For package changes used by implementations, run `pnpm build:pkgs` before reinstalling or running
114-
implementation tests.
115-
- For implementation-only changes, use `pnpm implementation:lint`, targeted implementation
116-
`typecheck`, and targeted E2E as needed.
117112
- If you skip a relevant check because of time or environment constraints, say exactly what was not
118113
run and why.
119114

@@ -175,32 +170,66 @@ High-signal repo-wide commands:
175170
- what you already tried
176171
- the smallest next action, user input, or approval needed
177172

178-
Common repo-specific failure modes:
179-
180-
- An implementation does not reflect a package change: run `pnpm build:pkgs`, then rerun the
181-
relevant `pnpm implementation:run -- <implementation> implementation:install`.
182-
- If the goal is E2E setup rather than the narrowest possible refresh step, prefer the combined root
183-
wrapper `pnpm setup:e2e:<implementation>`. For a full E2E run, prefer
184-
`pnpm test:e2e:<implementation>`.
185-
- Implementation-specific runtime failures such as Docker availability, Playwright browser setup,
186-
emulator requirements, `.env` drift, PM2 state, and local port conflicts belong in the relevant
187-
implementation `AGENTS.md`, not here.
188-
189173
## Docs, Specs, And CI
190174

191-
- When public SDK behavior changes, update the relevant TSDoc or JSDoc and the affected package
192-
`README.md` in the same change.
193175
- Authored supporting docs live in `documentation/`; generated TypeDoc output lives in `docs/`.
194-
- If a package includes a package-local dev harness or other meaningful local dev surface, keep that
195-
surface relevant to the current SDK behavior and update it in the same change when the package's
196-
developer-facing flows, configuration, or core capabilities change.
197176
- If the repository later adds any replacement design, architecture, or specification artifacts for
198177
the changed area, keep them aligned in the same change.
199178
- `docs/` is generated by TypeDoc and is gitignored.
200179
- Implementation E2E in `.github/workflows/main-pipeline.yaml` is intentionally path-filtered. If a
201180
change should alter E2E coverage, update the workflow and keep it aligned with
202181
[CONTRIBUTING.md](./CONTRIBUTING.md).
203182

183+
## README And Markdown Standards
184+
185+
- Treat README files as maintained source-of-truth orientation for humans. Keep them aligned with
186+
package exports, implementation scripts, local `.env.example` files, and authored documentation in
187+
the same change as behavior or workflow updates.
188+
- Preserve the README family already used by the target directory:
189+
- root, published package, and reference implementation READMEs use the centered Contentful logo
190+
header, `Contentful Personalization & Analytics` title, subtype `<h3>`, navigation links, and
191+
pre-release warning.
192+
- `documentation/**/README.md` files are navigation indexes with frontmatter.
193+
- placeholder and internal-only README files may use a plain Markdown `#` title plus explicit
194+
status or internal-use admonitions.
195+
- Use title case for Markdown headings, preserving official product, package, API, component, hook,
196+
and file casing.
197+
- Lead with reader intent and scope: what to use, when to use it, and what belongs elsewhere. Prefer
198+
concrete implementation guidance over marketing language.
199+
- Keep terminology consistent: "Optimization SDK Suite", "Personalization", "Analytics", "Experience
200+
API", "Insights API", "reference implementation", and exact package names such as
201+
`@contentful/optimization-web`.
202+
- Use fenced code blocks with language tags (`sh`, `ts`, `tsx`, `json`, `html`) and prefer `pnpm`
203+
commands. Do not introduce npm, yarn, or undocumented global-tool instructions.
204+
- Use GitHub admonitions intentionally: warning/caution for pre-release, internal, destructive, or
205+
unsafe flows; important for required contracts; note for helpful context that is not required.
206+
- Match README depth to the README category, not to the amount of available detail:
207+
- application-facing package READMEs orient the integrator, preserve common setup options, and
208+
link to authored guides or generated reference docs for deep workflows and exhaustive API
209+
details
210+
- lower-level package READMEs orient SDK maintainers and package authors, explain the layer's
211+
role, and avoid application-integration tutorial depth
212+
- reference implementation READMEs stay procedural and point readers to the code being
213+
demonstrated instead of duplicating package API tutorials
214+
- internal and placeholder READMEs stay short, explicit, and status-oriented
215+
- Move step-by-step implementation material into `documentation/guides/` when an existing guide is
216+
the right home; create a new guide only when no existing guide covers that reader goal. Use
217+
generated TypeDoc reference for exhaustive signatures, method catalogs, callback payload shapes,
218+
and exported type details.
219+
- Before changing README navigation or cross-document links, account for every render target that
220+
consumes that README: GitHub source browsing, TypeDoc project documents, and npmjs package README
221+
rendering for published packages.
222+
- Keep relative links pointed at source-of-truth files in this repository when the README is only
223+
consumed in-repo or by TypeDoc, or when the package README publish rewrite flow is known to
224+
rewrite that link for npm. Use stable absolute URLs for links that must work unchanged across
225+
GitHub, TypeDoc, and npm.
226+
- Link to generated reference docs for API reference and shared README header navigation that needs
227+
to work in all render targets, not as a replacement for source README guidance.
228+
- When a README has a collapsible table of contents, preserve the exact `<!-- mtoc-start -->` and
229+
`<!-- mtoc-end -->` markers and keep entries synchronized with headings.
230+
- For Markdown edits, run Prettier on touched files when practical and at least run
231+
`git diff --check` before finishing.
232+
204233
## Safety Rules
205234

206235
- Never overwrite or delete ignored local files just to get a clean run.
@@ -211,7 +240,7 @@ Common repo-specific failure modes:
211240
## Preferred Workflow
212241

213242
1. Read the root `AGENTS.md`.
214-
2. Read the nearest `AGENTS.md` in the subtree you will edit.
243+
2. Read each applicable child `AGENTS.md` from outermost to nearest in the subtree you will edit.
215244
3. Make the narrowest source-of-truth change in the correct layer.
216245
4. Run the smallest meaningful validation set.
217246
5. Broaden validation only when exports, build tooling, mocks, or shared behavior changed.

CONTRIBUTING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ gotchas.
4545
- [Validation Matrix](#validation-matrix)
4646
- [Code Style and Local Hooks](#code-style-and-local-hooks)
4747
- [Documentation](#documentation)
48+
- [README Depth and Render Targets](#readme-depth-and-render-targets)
4849
- [Local Troubleshooting](#local-troubleshooting)
4950
- [Troubleshooting CI Issues](#troubleshooting-ci-issues)
5051
- [E2E Coverage and Environment](#e2e-coverage-and-environment)
@@ -325,6 +326,27 @@ keep these artifacts aligned:
325326
`documentation/` contains source markdown that TypeDoc publishes. `docs/` is generated output. Do
326327
not hand-edit generated TypeDoc output.
327328

329+
### README Depth and Render Targets
330+
331+
READMEs are orientation surfaces, not the only place every detail should live. Match depth to the
332+
README category:
333+
334+
- Application-facing package READMEs keep purpose, install, minimal setup, common options, critical
335+
caveats, and links to guides, reference implementations, and generated API reference.
336+
- Lower-level package READMEs explain the package's role in the SDK stack, who should use it
337+
directly, common setup options where useful, and where exhaustive API details live.
338+
- Reference implementation READMEs stay procedural: what the implementation demonstrates,
339+
prerequisites, setup, run/test commands, environment notes, and related package links.
340+
- Internal and placeholder READMEs stay short, explicit, and status-oriented.
341+
342+
Move step-by-step implementation material into the existing guide for that runtime when one exists.
343+
Create a new guide only when no existing guide covers the reader goal. Keep exhaustive method
344+
catalogs, callback payload shapes, and exported type details in TypeDoc.
345+
346+
Package README links must work in GitHub source browsing, generated TypeDoc project documents, and
347+
npmjs README rendering. Use canonical generated-doc URLs for shared header navigation and verify
348+
repo-relative links before relying on package README publish rewriting.
349+
328350
## Local Troubleshooting
329351

330352
- An implementation is not reflecting your latest package change: run `pnpm build:pkgs`, then

README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enables developers and content creators to ship their products faster.
4040

4141
- [Choosing a Package](#choosing-a-package)
4242
- [Published Packages](#published-packages)
43-
- [Planned SDKs](#planned-sdks)
43+
- [Native and Planned SDKs](#native-and-planned-sdks)
4444
- [Reference Implementations](#reference-implementations)
4545
- [Repository Layout](#repository-layout)
4646
- [Get Involved](#get-involved)
@@ -55,9 +55,11 @@ enables developers and content creators to ship their products faster.
5555
If you are deciding which SDK or library belongs in your application, start with
5656
[Choosing the Right SDK](./documentation/guides/choosing-the-right-sdk.md).
5757

58-
For additional narrative documentation, see the [Guides](./documentation/README.md) section.
58+
For step-by-step implementation docs, start with the [Guides](./documentation/guides/README.md)
59+
index. For behavior explanations, start with the [Concepts](./documentation/concepts/README.md)
60+
index.
5961

60-
Package README files listed below are package-level overviews. Generated
62+
Package README files listed below are package-level guides and API surface summaries. Generated
6163
[reference documentation](https://contentful.github.io/optimization) remains the source of truth for
6264
exported API signatures.
6365

@@ -84,11 +86,20 @@ General selection rules:
8486
- `@contentful/optimization-api-client` and `@contentful/optimization-api-schemas` are lower-level
8587
building blocks.
8688

87-
## Planned SDKs
89+
## Native and Planned SDKs
8890

89-
These packages or layers are planned, but are not currently published from this repository:
91+
React Native support is available today through
92+
[`@contentful/optimization-react-native`](./packages/react-native-sdk/README.md).
93+
94+
Native iOS work is also present in this repository as a pre-release Swift Package under
95+
[`packages/ios`](./packages/ios/README.md), backed by the
96+
[`@contentful/optimization-ios-bridge`](./packages/ios/ios-jsc-bridge/README.md) JavaScriptCore
97+
adapter and the [iOS reference app](./implementations/ios-sdk/README.md). Treat this surface as
98+
alpha implementation work rather than a stable public native SDK.
99+
100+
The following native and framework SDKs are still planned and are not currently published from this
101+
repository:
90102

91-
- iOS Swift SDK
92103
- Android Kotlin SDK
93104
- Android Java SDK
94105
- Nest.js SDK
@@ -101,14 +112,19 @@ These packages or layers are planned, but are not currently published from this
101112
Reference implementations exist to exercise critical flows end to end and to document common usage
102113
patterns with intentionally minimal application code.
103114

104-
- [Web Vanilla](./implementations/web-sdk/README.md): static browser integration for the Web SDK
105-
- [React Web](./implementations/web-sdk_react/README.md): React-based browser integration
106-
- [Node SSR Only](./implementations/node-sdk/README.md): server-rendered integration using the Node
115+
- [Web Vanilla](./implementations/web-sdk/README.md) - static browser integration for the Web SDK
116+
- [React Web](./implementations/react-web-sdk/README.md) - primary React browser integration using
117+
the official React Web SDK package
118+
- [Web SDK React Adapter](./implementations/web-sdk_react/README.md) - adapter-based React example
119+
built directly on top of the Web SDK
120+
- [Node SSR Only](./implementations/node-sdk/README.md) - server-rendered integration using the Node
107121
SDK
108-
- [Node SSR + Web Vanilla](./implementations/node-sdk+web-sdk/README.md): split server/browser flow
122+
- [Node SSR + Web Vanilla](./implementations/node-sdk+web-sdk/README.md) - split server/browser flow
109123
using Node and Web SDKs together
110-
- [React Native](./implementations/react-native-sdk/README.md): mobile application integration for
124+
- [React Native](./implementations/react-native-sdk/README.md) - mobile application integration for
111125
Android and iOS targets
126+
- [iOS Reference App](./implementations/ios-sdk/README.md) - native app and XCUITest surface for
127+
current iOS bridge and preview-panel scenarios; this is not a published iOS SDK package
112128

113129
## Repository Layout
114130

0 commit comments

Comments
 (0)