Skip to content

rfc: absorb the Utopia libraries, tooling and the first package - #13700

Merged
loks0n merged 181 commits into
mainfrom
claude/utopia-libraries-consolidation-3b308b
Sep 15, 2026
Merged

loks0n merged 181 commits into
mainfrom
claude/utopia-libraries-consolidation-3b308b

Conversation

@loks0n

@loks0n loks0n commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 1 of rfc/monorepo.md, as five commits on top of main:

  1. chore: import utopia-php/agents into packages/agents: git subtree add from the library's main, full history.
  2. docs: add the RFC: the plan for making this repository the home of every utopia-php/* library. Each library lives at packages/<name> in one standard shape, is autoloaded directly by the root composer.json (no Composer dependency, no path repository), and keeps being split to its utopia-php/<name> mirror so Packagist consumers are unaffected.
  3. refactor: load agents directly from packages/: the proving package. Standard shape (Utopia\Agents\ => src/, tests tiered into unit and tests/e2e/), root autoload entries, utopia-php/agents gone from require, a packages PHPUnit suite, COPY ./packages in the Dockerfile, AGENTS.md pointing at packages/.
  4. chore: add bin/monorepo and the mirror workflows: the monorepo tool ported from utopia-php/monorepo (list, absorb, split, release, validate, check, test, dependents, plus a new autoload that generates the root map), the split, split-dev and mirror-redirect workflows, and a changed-package job in ci.yml that runs validate, then check and test per changed package and its dependents.
  5. chore(agents): mirror plumbing: mirror.yml, README banner, and the files the mirror no longer needs.

What validate enforces

Per package: utopia-php/<name> name, license, no version; exactly one PSR-4 prefix Utopia\<Ns>\ => src/ with <Ns> matching the slug; Utopia\<Ns>\Tests\ => tests/; no lock file; none of the QA files the root hoists; a phpstan.neon; a mirror.yml; Packagist constraints for siblings. Root: the two autoload lines per package and no require of an absorbed package, regenerated by bin/monorepo autoload.

Decisions

  • Packages are analysed under their own phpstan.neon with the root binary, never the root config: at Appwrite's level 4 their level-max ignore comments become errors.
  • Tests that reach a provider or a service live in tests/e2e/ even when they would skip without a key; agents' conversation suites errored on DNS rather than skipping.
  • The Dockerfile change is only the copy: the composer stage's optimised autoloader falls back to PSR-4 for classes outside its class map.
  • graph and benchmark were not ported.

Setup

  • Repository variable SPLIT_APP_ID and secret SPLIT_APP_PRIVATE_KEY on this repository done 2026-09-15 (app utopia-php-monorepo, fresh key; the app's installation on utopia-php is what the token targets).
  • The mirror ruleset on utopia-php/agents done 2026-09-15 via bin/monorepo absorb agents (PR-only, no force-push, split app bypasses).
  • A branch-ruleset allowance for merge commits not needed: main has no ruleset and the repository allows merge commits; the reviewer just has to pick "Create a merge commit".

Merging

Merge with a merge commit, not a squash. Commit 1 carries the git-subtree annotation the split continues from; bin/monorepo split agents --dry-run synthesises a head whose parent chain reaches the mirror's current head. A squash orphans the package from its mirror history.

Verification

  • bin/monorepo validate: all packages valid
  • bin/monorepo check agents: Pint passed, PHPStan no errors
  • bin/monorepo test agents and vendor/bin/phpunit --testsuite packages: 134 tests, 4 skipped, green
  • bin/monorepo split agents --dry-run: head synthesised, tree equals HEAD:packages/agents
  • Root PHPStan clean on every Appwrite file that consumes agents; composer validate valid; the lock drops only utopia-php/agents

🤖 Generated with Claude Code

@loks0n loks0n self-assigned this Sep 15, 2026
@greptile-apps

greptile-apps Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The latest changes appear safe to merge, with no newly introduced actionable failure identified.

Fix All in Claude CodeFindings

  1. P1 Span Dependency Is Missing ▶
  2. P1 Package Containers Cannot Build ▶
  3. P2 Benchmarks Use Stale Path ▶
  4. P2 Tests Mirror Configuration ▶
  5. P2 Package Tests Bypass CI ▶
  6. P2 Test Database Is Leaked ▶
  7. P2 PHP Requirements Are Wrong ▶
Fix with agent prompt
### Issue 1
packages/bus/composer.json:11-13
`Bus::dispatch()` calls `Utopia\Span\Span`, but this standalone manifest does not require `utopia-php/span`. The root application currently masks the omission by supplying that package itself. A Packagist consumer installing Bus alone will get a class-not-found error when dispatching a listener.

### Issue 2
packages/abuse/docker-compose.yml:17-20
This service references `Dockerfile.php-${PHP_VERSION:-8.4}`, which is absent after the import. The Agents Compose file likewise expects an absent default `Dockerfile` and `ollama.dockerfile`, and Agents has no standard `test:e2e` Composer script. As a result, the documented package tests and planned Compose-backed e2e workflow fail before any tests can start.

### Issue 3
packages/abuse/phpbench.json:undefined-4
The benchmark configuration still points to the pre-flattening `tests/Abuse/Bench` tree, while the imported benchmarks now live under `tests/bench`. The retained `composer bench` command consequently discovers none of these benchmarks.

```suggestion
    "runner.path": "tests/bench",
```

### Issue 4
packages/agents/tests/Adapters/Adapter.php:45-51
This exact-equality model-list test mirrors provider configuration instead of testing observable behavior, contrary to the repository directive that tests must not mirror source code, configuration, or version pins. OpenRouter is circular: its expected list is the same `Models::MODELS` constant returned by production. The TablesDB tests similarly assert exact column sizes, bounds, index names, types, and ordering. Replace these mirrored assertions with behavioral contracts such as model selection, request behavior, and successful rate limiting. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 5
phpunit.xml:19-23
This adds a separate `packages` suite, but the current unit job still invokes the test runner with the explicit `/usr/src/code/tests/unit` path. That command bypasses this suite, so regressions in the newly absorbed packages can merge without their tests running until the deferred package matrix is added.

### Issue 6
packages/abuse/tests/e2e/TablesDBTest.php:176-178
Class setup creates a uniquely named `abuse-cicd-*` database, but teardown performs no corresponding deletion. Every suite run therefore leaves another database and its abuse rows in the configured Appwrite project, causing persistent test-resource accumulation and possible environment contamination.

### Issue 7
packages/abuse/README.md:127-129
This README advertises PHP 8.0 compatibility, while the Abuse manifest requires PHP 8.4.1 or later. The Agents README makes the same PHP 8.0 claim despite requiring PHP 8.3. Standalone consumers following this documentation will be rejected by Composer.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR establishes the first phase of the Utopia monorepo migration by absorbing Agents and adding package validation, testing, splitting, and release automation.

  • Loads Agents directly from packages/agents through the root Composer autoloader.
  • Adds changed-package CI, root package tests, and reusable package checks.
  • Adds mirror, development-split, and release workflows.
  • The latest changes restore checks for linked packages, retain Compose-required Dockerfiles, and fix the Agents generator path and README example.

Reviews (4) · Last reviewed commit: "fix: address the review on the tooling s..."

Comment thread packages/bus/composer.json Outdated
Comment on lines +11 to +13
"require": {
"php": ">=8.5"
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Span Dependency Is Missing

Bus::dispatch() calls Utopia\Span\Span, but this standalone manifest does not require utopia-php/span. The root application currently masks the omission by supplying that package itself. A Packagist consumer installing Bus alone will get a class-not-found error when dispatching a listener.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/bus/composer.json
Line: 11-13

Comment:
**Span Dependency Is Missing**

`Bus::dispatch()` calls `Utopia\Span\Span`, but this standalone manifest does not require `utopia-php/span`. The root application currently masks the omission by supplying that package itself. A Packagist consumer installing Bus alone will get a class-not-found error when dispatching a listener.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Comment thread packages/abuse/docker-compose.yml Outdated
Comment on lines +17 to +20
tests:
build:
context: .
dockerfile: Dockerfile.php-${PHP_VERSION:-8.4}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Package Containers Cannot Build

This service references Dockerfile.php-${PHP_VERSION:-8.4}, which is absent after the import. The Agents Compose file likewise expects an absent default Dockerfile and ollama.dockerfile, and Agents has no standard test:e2e Composer script. As a result, the documented package tests and planned Compose-backed e2e workflow fail before any tests can start.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/abuse/docker-compose.yml
Line: 17-20

Comment:
**Package Containers Cannot Build**

This service references `Dockerfile.php-${PHP_VERSION:-8.4}`, which is absent after the import. The Agents Compose file likewise expects an absent default `Dockerfile` and `ollama.dockerfile`, and Agents has no standard `test:e2e` Composer script. As a result, the documented package tests and planned Compose-backed e2e workflow fail before any tests can start.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Comment thread packages/abuse/phpbench.json Outdated
{
"$schema": "vendor/phpbench/phpbench/phpbench.schema.json",
"runner.bootstrap": "vendor/autoload.php",
"runner.path": "tests/Abuse/Bench",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Benchmarks Use Stale Path

The benchmark configuration still points to the pre-flattening tests/Abuse/Bench tree, while the imported benchmarks now live under tests/bench. The retained composer bench command consequently discovers none of these benchmarks.

Suggested change
"runner.path": "tests/Abuse/Bench",
"runner.path": "tests/bench",
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/abuse/phpbench.json
Line: 4

Comment:
**Benchmarks Use Stale Path**

The benchmark configuration still points to the pre-flattening `tests/Abuse/Bench` tree, while the imported benchmarks now live under `tests/bench`. The retained `composer bench` command consequently discovers none of these benchmarks.

```suggestion
    "runner.path": "tests/bench",
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Comment on lines +45 to +51
public function testModelsContract(): void
{
$adapter = $this->createAdapter();
$models = $adapter->getModels();

$this->assertSame($this->expectedModels(), $models);
$this->assertNotEmpty($models);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests Mirror Configuration

This exact-equality model-list test mirrors provider configuration instead of testing observable behavior, contrary to the repository directive that tests must not mirror source code, configuration, or version pins. OpenRouter is circular: its expected list is the same Models::MODELS constant returned by production. The TablesDB tests similarly assert exact column sizes, bounds, index names, types, and ordering. Replace these mirrored assertions with behavioral contracts such as model selection, request behavior, and successful rate limiting. This repository requirement must be satisfied before merging.

Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/agents/tests/Adapters/Adapter.php
Line: 45-51

Comment:
**Tests Mirror Configuration**

This exact-equality model-list test mirrors provider configuration instead of testing observable behavior, contrary to the repository directive that tests must not mirror source code, configuration, or version pins. OpenRouter is circular: its expected list is the same `Models::MODELS` constant returned by production. The TablesDB tests similarly assert exact column sizes, bounds, index names, types, and ordering. Replace these mirrored assertions with behavioral contracts such as model selection, request behavior, and successful rate limiting. This repository requirement must be satisfied before merging.

**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

Comment thread phpunit.xml
Comment on lines +19 to +23
<testsuite name="packages">
<directory>./packages/*/tests</directory>
<exclude>./packages/*/tests/e2e</exclude>
<exclude>./packages/*/tests/bench</exclude>
</testsuite>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Package Tests Bypass CI

This adds a separate packages suite, but the current unit job still invokes the test runner with the explicit /usr/src/code/tests/unit path. That command bypasses this suite, so regressions in the newly absorbed packages can merge without their tests running until the deferred package matrix is added.

Prompt To Fix With AI
This is a comment left during a code review.
Path: phpunit.xml
Line: 19-23

Comment:
**Package Tests Bypass CI**

This adds a separate `packages` suite, but the current unit job still invokes the test runner with the explicit `/usr/src/code/tests/unit` path. That command bypasses this suite, so regressions in the newly absorbed packages can merge without their tests running until the deferred package matrix is added.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Comment on lines +176 to +178
public static function tearDownAfterClass(): void
{
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test Database Is Leaked

Class setup creates a uniquely named abuse-cicd-* database, but teardown performs no corresponding deletion. Every suite run therefore leaves another database and its abuse rows in the configured Appwrite project, causing persistent test-resource accumulation and possible environment contamination.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/abuse/tests/e2e/TablesDBTest.php
Line: 176-178

Comment:
**Test Database Is Leaked**

Class setup creates a uniquely named `abuse-cicd-*` database, but teardown performs no corresponding deletion. Every suite run therefore leaves another database and its abuse rows in the configured Appwrite project, causing persistent test-resource accumulation and possible environment contamination.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Comment thread packages/agents/README.md Resolved
Comment thread packages/abuse/README.md Outdated
Comment on lines +127 to +129
## System Requirements

Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 PHP Requirements Are Wrong

This README advertises PHP 8.0 compatibility, while the Abuse manifest requires PHP 8.4.1 or later. The Agents README makes the same PHP 8.0 claim despite requiring PHP 8.3. Standalone consumers following this documentation will be rejected by Composer.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/abuse/README.md
Line: 127-129

Comment:
**PHP Requirements Are Wrong**

This README advertises PHP 8.0 compatibility, while the Abuse manifest requires PHP 8.4.1 or later. The Agents README makes the same PHP 8.0 claim despite requiring PHP 8.3. Standalone consumers following this documentation will be rejected by Composer.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → claude/utopia-libraries-consolidation-3b308b (after).

Metric Before After Change
🚀 Requests/sec 258.69 256.83 ⚪ -0.7%
⏱️ Latency P50 67.6 ms 68.31 ms ⚪ +1%
⏱️ Latency P95 156.42 ms 158.15 ms ⚪ +1.1%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 68.31 158.15 15,960 256.83 +1.73
Account 130.63 234.43 840 13.96 +4.7
TablesDB 65.75 122.31 8,680 141.45 -0.53
Storage 63.17 141.66 4,200 70.32 +1.52
Functions 96.29 189.08 2,240 38.22 +2.78

Top API waits (after)

API request Max wait (ms)
account.name.update 396.95
storage.files.create 388.26
functions.delete 356.16
storage.buckets.create 348.59
tablesdb.rows.create 323.21

loks0n and others added 5 commits September 15, 2026 12:10
git-subtree-dir: packages/agents
git-subtree-mainline: 256b080
git-subtree-split: c978583
Appwrite becomes the home of every utopia-php library, loads each one directly from packages/<name> through the root autoload, and keeps mirroring them to Packagist for other consumers. The RFC records the target shape, the standard package layout, version gaps, the phase plan and open questions.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
First slice of rfc/monorepo.md, proving package for the tooling. agents
sits under packages/agents in the standard shape (Utopia\Agents\ => src/,
Utopia\Agents\Tests\ => tests/, tests/e2e/ for the suites that need a
provider key or a service) and the root composer.json autoloads it;
utopia-php/agents leaves require. It was imported from its main branch with
history (the preceding subtree merge).

Root wiring: a `packages` PHPUnit suite over the unit tiers, COPY ./packages
in the Dockerfile (the optimised autoloader falls back to PSR-4 for classes
outside its class map, so no re-dump is needed), dockerignore entries, and
AGENTS.md pointing at packages/.

Packages are analysed under their own phpstan.neon with the root binary, not
by the root config: at Appwrite's level 4 their level-max ignore comments
become errors.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Phase 1 tooling from rfc/monorepo.md, ported from utopia-php/monorepo.
bin/monorepo keeps list, absorb, split, release, validate, check, test and
dependents; graph and benchmark are dropped. Mirrors stay under utopia-php,
every link back now points at packages/<name> here. validate enforces the
standard package shape (one Utopia\<Ns>\ prefix over src/, its Tests\
prefix over tests/, no lock, no hoisted QA, a phpstan.neon, mirror.yml)
and the root autoload wiring; the new autoload subcommand regenerates the
root entries from the package manifests. check analyses each package under
its own phpstan.neon with the root binaries, Rector first so --fix leaves
formatted output.

split.yml, split-dev.yml and mirror-redirect.yml move over with pinned
actions. ci.yml validates packages in the checks job, runs the packages
PHPUnit suite in the unit job (packages/ is mounted like tests/), and gains
the changed-package matrix: diff against the base ref, expand through
dependents, check and test each package, linked for dependents.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Add the mirror.yml that redirects pull requests and issues opened on
utopia-php/agents back here, the read-only-mirror banner under the README
H1, and drop what the mirror no longer needs: the issue templates, the
docker-compose.yml that referenced a Dockerfile removed with the shape
change (agents defines no e2e tier), and its .env.example.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@loks0n
loks0n force-pushed the claude/utopia-libraries-consolidation-3b308b branch from 9ffb4b0 to 1d9de22 Compare September 15, 2026 11:26
@loks0n loks0n changed the title rfc: absorb the Utopia libraries into packages/, first slice rfc: absorb the Utopia libraries, tooling and the first package Sep 15, 2026
Comment thread .github/workflows/ci.yml Resolved
Comment thread bin/monorepo Resolved
- ci.yml: run `bin/monorepo check` for every changed package, linked ones
  included; only tests were being run for a package that also depends on
  another changed package.
- bin/monorepo: keep the Dockerfiles a package's docker-compose.yml builds
  an e2e service from; absorb and validate only treat the rest as hoisted
  tooling.
- agents: the OpenRouter model sync script wrote to the pre-flattening
  src/Agents path; the README example had an unterminated string.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@loks0n
loks0n merged commit 10893f0 into main Sep 15, 2026
48 checks passed
@loks0n

loks0n commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

Post-merge check: the first Split run on the merge commit (run 35031863660) succeeded. utopia-php/agents main moved from c978583394 to ff90733aab, the exact head bin/monorepo split agents --dry-run predicted before merge, so the subtree annotation survived the merge commit and the mirror history is continuous.

Setup that was done outside the PR: SPLIT_APP_ID variable and SPLIT_APP_PRIVATE_KEY secret on this repository (app utopia-php-monorepo, key generated 2026-09-15), and the mirror ruleset on utopia-php/agents via bin/monorepo absorb agents.

What to watch: every push to main now runs Split; a failure there means the mirror is behind and the next bin/monorepo release agents <version> would tag stale code. Nothing else changes for Appwrite itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants