# AGENTS.md — mgt2-compendium-amiral-denisov

## First read

- `.github/copilot-instructions.md` — packs, icons, module.json conventions (this file builds on it, don't repeat it)

## No package manager / no build

There is **no** `package.json`, no lockfile, no bundler. JavaScript is plain ESM loaded directly by FoundryVTT. Do not run `npm install` or any build command.

## Commands

5 chat commands registered at runtime (not declared in `module.json`):

| Command | Entrypoint | Dialog |
|---|---|---|
| `/commerce` | `scripts/commerce.js` | `CommerceDialog` (3 tabs) |
| `/pnj` | `scripts/npc.js` | `NpcDialog` (4 tabs) |
| `/rencontre` | `scripts/npc.js` | same dialog (tab 2) |
| `/mission` | `scripts/npc.js` | same dialog (tab 3) |
| `/sector` | `scripts/sector.js` | `SectorMapApp` (IFRAME Traveller Map, clics→chat) |
| `/subsector` | `scripts/sector.js` | `SectorMapApp` (IFRAME) |

Commands are registered via `ChatLogV2.CHAT_COMMANDS` — not Hooks.on("chatMessage") as the copilot-instructions say (that file is stale). See `commerce.js:15` and `npc.js:15` for the actual pattern.

## Framework quirks

- **ApplicationV2** + `HandlebarsApplicationMixin` for all dialogs.
- Foundry v13/v14 dual code paths: some hooks must handle both jQuery (v13) and DOM (v14) APIs.
- Dice rolls: `await new Roll(formula).evaluate()` — always async.
- Skill FQN format for `game.i18n`: e.g. `pilot.spacecraft`, `electronics.computers`, `gunner.turret`.

## Runtime systems (run at `ready` hook, GM only)

1. **Migration** (`mgt2eMigration.js`): converts legacy item types to mgt2e (armor→armour, equipment→item/augment, computer→hardware, etc.). Tracked via `game.settings` version flag. Forced re-run requires deleting the setting.

2. **NPC RollTable sync** (`npcRollTableSync.js`): writes D66 tables from `scripts/data/npcTables.js` into the `tables-pnj` compendium pack. Checksums to avoid redundant writes.

## Testing

Deux fichiers de test, pas de build :

```sh
# Tests Jest (globals importés via @jest/globals, flag ESM requis)
NODE_OPTIONS="--experimental-vm-modules" npx jest scripts/tests/travellerNpcGenerator.test.js

# Mini-runner maison (Jest rapporte un faux positif « at least one test »)
node scripts/tests/allyEnemyGenerator.test.js
```

- `travellerNpcGenerator.test.js` : Jest (`describe`/`it`/`expect`), mock FoundryVTT fait main, ~1100 lignes. Couvre : utilitaires, lookups, validation, caractéristiques/compétences, conversion de compétences, génération complète, ModuleCache, erreurs, config validation.
- `allyEnemyGenerator.test.js` : son propre runner (`test()`/`assertEqual`), 39 tests, à lancer avec `node` directement.
- Config Jest minimale dans `jest.config.cjs` (`testMatch` + `transform: {}`).
- Pas de CI test step — à lancer manuellement.

## Versioning

- `module.json` → `"version"` is the single source of truth.
- Git tag format: `v1.3.0` (CI strips `v`).
- No changelog file.

## CI/CD (Gitea)

- Only triggers on **`release: [published]`** — not on push/PR.
- Builds a zip archive of `module.json + assets/ + packs/ + scripts/ + styles/ + templates/` and uploads to the release.
- No test step in CI.

## Deprecated packs (still on disk, NOT in module.json)

- `packs/arme/` → superseded by `armes`
- `packs/carriere/` → superseded by `carrieres`
- `packs/talent-psy/` → superseded by `talents-psioniques`

Do not re-add them to `module.json`. They remain for historical data recovery only.

## All content is in French

Labels, comments, commit messages, UI strings, icon file names, rule references — everything. Check French naming before searching/grepping.
