Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ee8a155
docs: add CLAUDE.md with architecture guidance
DavidLambauer Apr 20, 2026
f6d152c
docs: add v1.0.0 "done done" design plan
DavidLambauer Apr 20, 2026
0865a89
docs: add v1.0.0 implementation plan
DavidLambauer Apr 20, 2026
82666cd
chore: tighten composer metadata, add LICENSE and CHANGELOG
DavidLambauer Apr 20, 2026
672962e
docs: drop version field from composer.json spec
DavidLambauer Apr 20, 2026
83734fa
chore: drop version field from composer.json
DavidLambauer Apr 20, 2026
b9ecc0e
docs: capture Task 1 code-review polish items in Task 12 scope
DavidLambauer Apr 20, 2026
15c76b6
ci: add Graycore check-extension workflow and phpcs config
DavidLambauer Apr 20, 2026
9651b27
ci: target Mage-OS matrix explicitly in supported-version
DavidLambauer Apr 20, 2026
6aac75c
docs: fix README — correct interface references in usage example
DavidLambauer Apr 20, 2026
a6f7581
fix: declare explicit module sequence on Magento_Config and Magento_B…
DavidLambauer Apr 20, 2026
14db6da
fix(selector): harden getParsedConfig against null and malformed JSON
DavidLambauer Apr 20, 2026
0e2f0a1
fix(selector): cover all four guards and document insertion-order con…
DavidLambauer Apr 20, 2026
5711322
feat: add FieldDescriptor DTO for structured admin form schema
DavidLambauer Apr 20, 2026
4dbc55f
feat!: replace HTML-template config with FieldDescriptor schema
DavidLambauer Apr 20, 2026
a91f178
fix: harden admin form against injection + mark Services block final
DavidLambauer Apr 20, 2026
e6eac5d
docs: capture Task 7 model-list freshness decision in Task 12
DavidLambauer Apr 20, 2026
4f87c35
test: add parametrised smoke test covering all 11 AiServices classes
DavidLambauer Apr 20, 2026
8d1d0a2
test: add integration test covering config round-trip through ScopeCo…
DavidLambauer Apr 20, 2026
cfd62d6
test(integration): make cleanup failure-safe and tighten Config typing
DavidLambauer Apr 20, 2026
a420702
chore: add declare(strict_types=1) to remaining PHP files
DavidLambauer Apr 20, 2026
13ebfbb
chore: release-polish — correct GitHub URLs, add .gitattributes, CHAN…
DavidLambauer Apr 21, 2026
a721d3a
ci: point check-extension at repo.mage-os.org for mage-os metapackage
DavidLambauer Apr 21, 2026
4259912
ci: align repo layout with Graycore check-extension conventions
DavidLambauer Apr 21, 2026
715354f
ci: add mage-os composer mirror so magento/framework resolves
DavidLambauer Apr 21, 2026
43fdca1
ci: allow magento composer plugins pulled in via mirror
DavidLambauer Apr 21, 2026
9d30c8c
ci: bump Graycore to v6.0.0 for Mage-OS 2.2.0 support
DavidLambauer Apr 21, 2026
ee47a87
Revert "ci: bump Graycore to v6.0.0 for Mage-OS 2.2.0 support"
DavidLambauer Apr 21, 2026
593ebae
docs: add community standards design doc
DavidLambauer Apr 21, 2026
8470464
docs: add community standards implementation plan
DavidLambauer Apr 21, 2026
793c8f9
docs: add Contributor Covenant v2.1 code of conduct
DavidLambauer Apr 21, 2026
77f8ed4
docs: add CONTRIBUTING guide
DavidLambauer Apr 21, 2026
5127efb
docs: add SECURITY policy
DavidLambauer Apr 21, 2026
b45ef8a
ci: disable blank issues
DavidLambauer Apr 21, 2026
e0c6d36
ci: add bug report issue form
DavidLambauer Apr 21, 2026
9b33d0b
ci: add feature request issue form
DavidLambauer Apr 21, 2026
c31af7a
ci: add pull request template
DavidLambauer Apr 21, 2026
45fe0a4
docs: link community files from README
DavidLambauer Apr 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.github export-ignore
/docs export-ignore
/Test export-ignore
/phpcs.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/CLAUDE.md export-ignore
/.gitattributes export-ignore
56 changes: 56 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Bug report
description: Report a bug in MageOS_AiBase
title: "[Bug]: "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to file a bug report. Please fill in the fields below.
- type: input
id: module-version
attributes:
label: Module version
placeholder: "1.0.0"
validations:
required: true
- type: input
id: magento-version
attributes:
label: Magento / Mage-OS version
placeholder: "Magento 2.4.7 / Mage-OS 2.2.0"
validations:
required: true
- type: textarea
id: expected
attributes:
label: Expected behavior
description: What did you expect to happen?
validations:
required: true
- type: textarea
id: actual
attributes:
label: Actual behavior
description: What actually happened?
validations:
required: true
- type: textarea
id: reproduction
attributes:
label: Reproduction steps
description: Minimal steps to reproduce the issue.
placeholder: |
1. Go to ...
2. Click on ...
3. See error
validations:
required: true
- type: textarea
id: logs
attributes:
label: Logs / stack trace
description: Any relevant output from var/log/ or the browser console.
render: shell
validations:
required: false
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: false
26 changes: 26 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Feature request
description: Suggest a new feature or enhancement
title: "[Feature]: "
labels: ["enhancement"]
body:
- type: textarea
id: problem
attributes:
label: Problem
description: What problem are you trying to solve? Who is affected?
validations:
required: true
- type: textarea
id: solution
attributes:
label: Proposed solution
description: How would you like this to work?
validations:
required: true
- type: textarea
id: alternatives
attributes:
label: Alternatives considered
description: Any other approaches you considered and why you ruled them out.
validations:
required: false
25 changes: 25 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Summary

<!-- What does this PR do and why? 1-3 sentences. -->

## Linked issue

Closes #

## Change type

- [ ] Bug fix
- [ ] New feature
- [ ] Documentation
- [ ] Chore / refactor / CI
- [ ] Breaking change

## Test plan

<!-- How did you verify this change? Commands, manual steps, screenshots. -->

## Checklist

- [ ] Tests added or updated
- [ ] Docs / README updated if behavior changed
- [ ] `phpcs` and `phpunit` pass locally
30 changes: 30 additions & 0 deletions .github/workflows/check-extension.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check Extension

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
compute-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.supported.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: graycoreio/github-actions-magento2/supported-version@v5.1.0
id: supported
with:
project: mage-os

check-extension:
needs: compute-matrix
uses: graycoreio/github-actions-magento2/.github/workflows/check-extension.yaml@v5.1.0
with:
matrix: ${{ needs.compute-matrix.outputs.matrix }}
# The default mirror (https://mirror.mage-os.org/) only proxies magento/*
# packages; the mage-os/project-community-edition metapackage is published
# to https://repo.mage-os.org/. Without this override, composer fails with
# "Could not find package mage-os/project-community-edition".
magento_repository: https://repo.mage-os.org/
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.0.0] - 2026-04-21

### Added
- Structured `FieldDescriptorInterface` config field schema replacing the HTML-template pattern.
- `getSupportedModels(): array` method on each service for non-hardcoded model lists. Model lists ship as a curated baseline; admins may override per-install via a `<preference>` on each service class.
- GitHub Actions CI via `graycoreio/github-actions-magento2/check-extension`, matrix-targeted at `project: mage-os`.
- Unit test suite for `AiServiceSelector` (all four guards covered) and a parametrised smoke test exercising all eleven `AiServices/*` classes.
- Integration test covering round-trip of stored config through `ScopeConfigInterface`, with failure-safe cleanup in `tearDown()`.
- `AiServiceSelectorInterface` now documents its insertion-order contract.
- Admin form schema rendering hardens against HTML injection (client-side `escapeHtml()`) and preserves legacy stored values when the model list changes.

### Changed
- **BREAKING:** `AiServiceConfigurationInterface::getConfigurationTemplate(): string` replaced by `::getConfigurationFields(): FieldDescriptorInterface[]` and `::getSupportedModels(): array`.
- `composer.json` now pins `php: ^8.2` and `magento/framework: ^103.0 || ^104.0`.
- `Model/AiServiceSelector` hardened against null scope values and malformed JSON.
- `module.xml` declares explicit dependency on `Magento_Config` + `Magento_Backend`.
- `Block\Adminhtml\Configuration\Services` is now `final` with runtime validation that injected services implement `AiServiceConfigurationInterface`.

### Fixed
- `README.md` API example now references the correct `AiServiceSelectorInterface` (previously cited `AiServiceConfigurationInterface`).

[Unreleased]: https://github.com/mage-os-lab/module-ai-base/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/mage-os-lab/module-ai-base/releases/tag/v1.0.0
57 changes: 57 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## What this is

`mage-os/module-ai-base` — a small Magento 2 module (`MageOS_AiBase`) that exposes an admin configuration UI for registering multiple AI backends (OpenAI, Anthropic, Azure, Google, Grok, Deepseek, HuggingFace, LM Studio, Ollama, OpenRouter, xAI) and a consumer API for other modules to read those configured credentials. It does **not** call any AI service itself — it only stores and serves configuration.

The module is installed into a host Magento 2 app; this repo contains no runnable Magento instance. There is no test suite, no lint/format config, and no build step.

## Commands

Host-side (run inside a Magento 2 install that has this module via `composer require mage-os/module-ai-base`):

```bash
php bin/magento module:enable MageOS_AiBase
php bin/magento setup:upgrade
php bin/magento setup:di:compile
```

Admin UI lives at **Stores → Configuration → Services → AI Configuration**.

## Architecture

There are two intentionally separate interfaces — do not conflate them:

- **`Api\Data\AiServiceConfigurationInterface`** (`getCode`, `getName`, `getConfigurationTemplate`) — describes an *available* backend: its machine code, display name, and the HTML snippet used in the admin form. Implementations live in `src/AiServices/*.php`. These are wired into the admin form by the `services` array argument on `Block\Adminhtml\Configuration\Services` in `etc/di.xml`.
- **`Api\Data\AiServiceInterface`** (`getCode`, `getConfiguration`) — represents a *configured instance* (code + stored credentials/model/etc. array). Produced at runtime by `Model\AiServiceSelector` through `AiServiceInterfaceFactory`.

`AiServiceSelectorInterface` is the public consumer API:

```php
AiServiceSelectorInterface::getAll(): AiServiceInterface[]
AiServiceSelectorInterface::getByCode(string $code): AiServiceInterface[]
```

(Note: the README example shows these methods on `AiServiceConfigurationInterface` — that's wrong; they belong to `AiServiceSelectorInterface`. `getAll` also takes no arguments.) Multiple entries per code are possible because admins can add the same backend multiple times in the UI, which is why `getByCode` returns an array.

Stored data flow:

1. Admin form is an `AbstractFieldArray` rendered via `view/adminhtml/templates/system/config/form/field/services.phtml`.
2. Each `AiServiceConfigurationInterface::getConfigurationTemplate()` returns an HTML fragment using `<%- _fieldName %>` as a `mage/template` placeholder. The phtml wires those into per-row inputs when the admin clicks one of the "Add Service" buttons.
3. Magento serializes the posted rows as JSON via `Magento\Config\Model\Config\Backend\Serialized\ArraySerialized` into `core_config_data` at path **`mageos_ai/services/configuration`**.
4. `AiServiceSelector::getParsedConfig()` reads that path, json_decodes it, and wraps each row with `AiServiceInterfaceFactory`. Each row's structure is `{ _rowId: { <service_code>: { ...fields } } }`, which is why the selector does `array_first(array_keys($item))` to extract the code.

## Adding a new AI backend

1. Create `src/AiServices/<Name>.php` implementing `AiServiceConfigurationInterface`. The configuration template's input `name` attributes must follow `<%- _fieldName %>[<service_code>][<field>]` — that nesting is what the selector expects when reading back.
2. Register it in `etc/di.xml` under the `services` argument of `Block\Adminhtml\Configuration\Services`. The array key there becomes the row identifier in the admin dropdown; it should match the class's `getCode()`.
3. No other wiring is required — the admin UI and selector pick it up automatically.

## Conventions observed in this codebase

- PHP 8 constructor property promotion + `readonly` is the norm; follow it for new classes.
- No `declare(strict_types=1)` header is used in existing files — match the surrounding style unless you're explicitly modernizing.
- `composer.json` pins `minimum-stability: dev` and `magento/framework: *` — do not tighten these without a reason.
- ACL resource: `MageOS_AiBase::configuration` (defined in `etc/acl.xml`), nested under `Magento_Backend::stores_attributes`.
83 changes: 83 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.

Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at david@run-as-root.sh. All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of actions.

**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].

Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].

For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
57 changes: 57 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Contributing to MageOS_AiBase

Thanks for your interest in improving this module. This guide covers how to report issues, propose changes, and develop locally.

## Reporting bugs

Open an issue using the **Bug report** template. Please include your Magento version, module version, and reproduction steps.

## Proposing changes

For anything larger than a typo fix, please open a **Feature request** issue first so we can align on the approach before you invest time in a PR.

## Local development

This repo contains a Magento 2 module, not a runnable Magento instance. To work on it:

1. Clone this repository outside your Magento install.
2. In your Magento 2 project, add a Composer path repository pointing at your clone:
```json
"repositories": [
{ "type": "path", "url": "/absolute/path/to/module-ai-base" }
]
```
3. Require the module and enable it:
```bash
composer require mage-os/module-ai-base:@dev
bin/magento module:enable MageOS_AiBase
bin/magento setup:upgrade
bin/magento setup:di:compile
```

## Coding conventions

- PHP 8 constructor property promotion with `readonly` is the norm — match it for new classes.
- No `declare(strict_types=1)` header is used in existing files; keep things consistent unless you're explicitly modernizing in a dedicated PR.
- Coding standard: see `phpcs.xml.dist`. Run `vendor/bin/phpcs` from a host Magento install that includes this module.

## Branching and pull requests

- Branch off `main` using `feat/<short-name>` or `fix/<short-name>`.
- Target PRs at `main`.
- Keep PRs focused — one concern per PR.
- Fill in the PR template (summary, linked issue, test plan).

## Tests

Run the test suite with:

```bash
vendor/bin/phpunit -c phpunit.xml.dist
```

New PHP unit tests must be `final` classes and use `snake_case` method names.

## Commit messages

Conventional-style prefixes (`feat:`, `fix:`, `docs:`, `ci:`, `chore:`) are encouraged but not enforced.
Loading
Loading