|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Notes for AI coding agents working in this repo. Keep changes minimal, prefer editing existing files over creating new ones, and don't create planning/summary markdown documents unless asked. |
| 4 | + |
| 5 | +## What this is |
| 6 | + |
| 7 | +Nextcloud Bookmarks — a server-side Nextcloud app (PHP 8.1+) with a Vue 2 / Vuex frontend. Installs into a Nextcloud instance as `apps/bookmarks`. Published on the Nextcloud App Store; primary repo is `nextcloud/bookmarks` on GitHub. |
| 8 | + |
| 9 | +App ID: `bookmarks`. Namespace: `OCA\Bookmarks\`. Version is tracked in `appinfo/info.xml`, `package.json`, and `Makefile` — keep them in sync when bumping. |
| 10 | + |
| 11 | +## Layout |
| 12 | + |
| 13 | +- `lib/` — PHP backend (PSR-4: `OCA\Bookmarks\` → `lib/`) |
| 14 | + - `Controller/` — HTTP controllers; public APIs in `BookmarkController`, `FoldersController`, `TagsController`; the `Internal*` variants are for the Vue frontend |
| 15 | + - `Db/` — Entities and `QBMapper`s. `TreeMapper.php` is the heart of the data model (see below) |
| 16 | + - `Service/` — Business logic. `FolderService`, `BookmarkService`, `Authorizer`, `TreeCacheManager` are the most-touched |
| 17 | + - `Migration/` — Schema and repair steps |
| 18 | + - `BackgroundJobs/`, `Activity/`, `Search/`, `Dashboard/`, `Reference/`, `ContextChat/`, `Flow/`, `Hooks/` — Nextcloud integration points |
| 19 | +- `src/` — Vue frontend (entry `main.js`, store under `store/`, router in `router.js`) |
| 20 | +- `tests/` — PHPUnit tests (integration tests against a real Nextcloud + DB; see Testing) |
| 21 | +- `templates/` — Server-rendered shell templates |
| 22 | +- `docs/` — Sphinx docs published to docs.nextcloud.com (`*.rst`) |
| 23 | +- `l10n/` — Auto-generated translations from Transifex; do not hand-edit |
| 24 | +- `appinfo/` — Nextcloud app manifest, routes, DI wiring |
| 25 | +- `js/` — Webpack output; do not edit, regenerate with `npm run build` |
| 26 | + |
| 27 | +## Data model — read before touching `Db/` or sharing logic |
| 28 | + |
| 29 | +Three tables drive everything: |
| 30 | + |
| 31 | +- `bookmarks_folders` (Folder), `bookmarks` (Bookmark), `bookmarks_shared_folders` (SharedFolder — a sharee's view of a shared folder) |
| 32 | +- `bookmarks_tree` — the polymorphic tree. One row per placement: `(id, type, parent_folder, index, soft_deleted_at)`. `type` is `folder`, `bookmark`, or `share`. For `share` rows, `id` is the SharedFolder's id, not the Share's; the same SharedFolder also exists as a row in `bookmarks_shared_folders`. |
| 33 | +- `bookmarks_shares` (Share, the grant) joined to SharedFolders via `bookmarks_shared_to_shares` |
| 34 | + |
| 35 | +`soft_deleted_at` on `bookmarks_tree` is the trash bin. Soft delete cascades to all descendant tree rows (folders, bookmarks, shares). When a sharer trashes a folder, the sharee must not see it anywhere — including their own trash — because they can't restore someone else's folder. The filter for that lives at read time, not write time: see `TreeMapper::joinOriginalFolderNotSoftDeleted` and the share-recursive arm of `BookmarkMapper::_generateCTE`. |
| 36 | + |
| 37 | +`BookmarkMapper::_generateCTE` is a recursive CTE that walks a user's tree. It has two backend shapes: |
| 38 | +- MySQL: one CTE with three union arms |
| 39 | +- Postgres / sqlite: three nested CTEs (`inner_folder_tree` → `second_folder_tree` → `folder_tree`) |
| 40 | + |
| 41 | +Both backends reuse the same `$recursiveCase` / `$recursiveCaseShares` builders, so a filter added there applies to both. New positional parameters added to those builders are picked up automatically by the `array_merge(...->getParameters())` lines below. |
| 42 | + |
| 43 | +## Build, lint, test |
| 44 | + |
| 45 | +``` |
| 46 | +make dev-setup # composer install + npm ci |
| 47 | +npm run dev # build frontend (development) |
| 48 | +npm run build # build frontend (production) |
| 49 | +npm run watch # rebuild on change |
| 50 | +npm run lint[:fix] # ESLint over src/ |
| 51 | +npm run stylelint[:fix] # Stylelint over src/ |
| 52 | +
|
| 53 | +composer run lint # php -l over lib/ |
| 54 | +composer run cs:check # php-cs-fixer dry run |
| 55 | +composer run cs:fix # php-cs-fixer apply |
| 56 | +composer run psalm # static analysis (baseline: psalm-baseline.xml) |
| 57 | +composer run test:unit # phpunit -c tests/phpunit.xml |
| 58 | +``` |
| 59 | + |
| 60 | +PHP target: 8.1 (platform pinned in `composer.json`). Node: 24.x, npm: 11.x. |
| 61 | + |
| 62 | +## Testing — the gotcha |
| 63 | + |
| 64 | +`tests/bootstrap.php` requires `../../../lib/base.php` and loads the bookmarks app from a Nextcloud server install. The suite does NOT run from a standalone clone — it expects this repo to live at `<nextcloud>/apps/bookmarks` with a configured DB. `before_install.sh` shows the CI setup (clones nextcloud/server, copies the app in, sets up mysql / pgsql / oracle). |
| 65 | + |
| 66 | +If you can't run the suite, say so explicitly rather than claiming it passes. `php -l` and `composer run psalm` work standalone and catch a lot. |
| 67 | + |
| 68 | +## Conventions |
| 69 | + |
| 70 | +- Commits follow conventional-commit style with a scope, e.g. `fix(Activity/Provider): ...`, `feat(FolderService): ...`. Tag commits are `v16.2.1` shape. |
| 71 | +- The `master` branch is default; PRs target `main`. Don't push to either without being asked. |
| 72 | +- Don't hand-edit `l10n/*` — Transifex generates those (`fix(l10n): Update translations from Transifex` commits). |
| 73 | +- Don't edit `js/` — it's the webpack build output. |
| 74 | +- Authorization for HTTP endpoints goes through `Service\Authorizer`; permission checks live there, not scattered through controllers. |
| 75 | +- Tree mutation must go through `TreeMapper` so `TreeCacheManager` invalidations and the soft-delete cascade stay consistent. Don't write directly to `bookmarks_tree` from controllers/services. |
| 76 | +- Soft-delete vs hard-delete: `softDeleteEntry` / `softUndeleteEntry` for trash flow, `deleteEntry` / `deleteShare` for permanent removal. `removeFolderTangibles` cleans up shares + public folders on hard delete. |
| 77 | +- The bookmarks app is maintained in free time by a single primary maintainer (see info.xml). Keep PRs focused; one logical change per PR. |
| 78 | + |
| 79 | +## When extending shared-folder behaviour |
| 80 | + |
| 81 | +Most sharing bugs come from one of two oversights: |
| 82 | +1. Writing logic that only touches the sharer's tree, forgetting the sharee's SharedFolder tree row(s) — or vice-versa. |
| 83 | +2. Mutating tree state on the write path (soft-delete cascades) when the same condition can be expressed once as a read-time filter, which avoids clobbering independent state the other side may have set. |
| 84 | + |
| 85 | +Prefer read-time filters when the source of truth is unambiguous (e.g. the original folder's `soft_deleted_at` is authoritative for "does this share even exist right now"). |
0 commit comments