Skip to content
Merged
24 changes: 11 additions & 13 deletions docs/public/llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1711,18 +1711,17 @@ This reads `.archgate/imports.json` and displays each source, version, and the A

## How ID remapping works

When you import ADRs, the original IDs (e.g., `TS-001`) are **remapped** to fit your project's ID sequence. For example, if your project already has `ARCH-001` through `ARCH-005`, the imported ADRs will receive `ARCH-006`, `ARCH-007`, etc.
When you import ADRs, the original IDs are **remapped** to match your project's domain prefixes. Each ADR's `domain` field determines which prefix it gets — for example, an ADR with `domain: frontend` becomes `FE-XXX`, while one with `domain: backend` becomes `BE-XXX`. Each domain has its own counter, so importing a pack with mixed domains produces correctly prefixed IDs without collisions.

You can override the prefix with `--prefix`:
For example, importing a pack with three frontend ADRs and two backend ADRs into a project that already has `FE-001` and `BE-001` produces:

```bash
archgate adr import packs/security --prefix SEC
```
- `FE-002`, `FE-003`, `FE-004` (frontend)
- `BE-002`, `BE-003` (backend)

The remapping ensures:

1. No ID collisions with existing ADRs
2. A single consistent numbering scheme across your project
2. Each domain maintains its own numbering sequence
3. Imported rules files work immediately without manual edits

## The imports.json manifest
Expand All @@ -1746,13 +1745,12 @@ This manifest lets you track provenance — where each imported ADR came from an

## Command options reference

| Option | Description |
| ------------------- | ---------------------------------------- |
| `--yes` | Skip the confirmation prompt |
| `--json` | Output results as JSON |
| `--dry-run` | Preview changes without writing files |
| `--prefix <prefix>` | Override the ID prefix for imported ADRs |
| `--list` | List previously imported ADRs |
| Option | Description |
| ----------- | ------------------------------------- |
| `--yes` | Skip the confirmation prompt |
| `--json` | Output results as JSON |
| `--dry-run` | Preview changes without writing files |
| `--list` | List previously imported ADRs |

---

Expand Down
24 changes: 11 additions & 13 deletions docs/src/content/docs/guides/importing-adrs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,17 @@ This reads `.archgate/imports.json` and displays each source, version, and the A

## How ID remapping works

When you import ADRs, the original IDs (e.g., `TS-001`) are **remapped** to fit your project's ID sequence. For example, if your project already has `ARCH-001` through `ARCH-005`, the imported ADRs will receive `ARCH-006`, `ARCH-007`, etc.
When you import ADRs, the original IDs are **remapped** to match your project's domain prefixes. Each ADR's `domain` field determines which prefix it gets — for example, an ADR with `domain: frontend` becomes `FE-XXX`, while one with `domain: backend` becomes `BE-XXX`. Each domain has its own counter, so importing a pack with mixed domains produces correctly prefixed IDs without collisions.

You can override the prefix with `--prefix`:
For example, importing a pack with three frontend ADRs and two backend ADRs into a project that already has `FE-001` and `BE-001` produces:

```bash
archgate adr import packs/security --prefix SEC
```
- `FE-002`, `FE-003`, `FE-004` (frontend)
- `BE-002`, `BE-003` (backend)

The remapping ensures:

1. No ID collisions with existing ADRs
2. A single consistent numbering scheme across your project
2. Each domain maintains its own numbering sequence
3. Imported rules files work immediately without manual edits

## The imports.json manifest
Expand All @@ -124,10 +123,9 @@ This manifest lets you track provenance — where each imported ADR came from an

## Command options reference

| Option | Description |
| ------------------- | ---------------------------------------- |
| `--yes` | Skip the confirmation prompt |
| `--json` | Output results as JSON |
| `--dry-run` | Preview changes without writing files |
| `--prefix <prefix>` | Override the ID prefix for imported ADRs |
| `--list` | List previously imported ADRs |
| Option | Description |
| ----------- | ------------------------------------- |
| `--yes` | Skip the confirmation prompt |
| `--json` | Output results as JSON |
| `--dry-run` | Preview changes without writing files |
| `--list` | List previously imported ADRs |
24 changes: 11 additions & 13 deletions docs/src/content/docs/pt-br/guides/importing-adrs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,17 @@ Isso lê `.archgate/imports.json` e exibe cada fonte, versão e os IDs de ADR pr

## Como funciona o remapeamento de IDs

Quando você importa ADRs, os IDs originais (ex: `TS-001`) são **remapeados** para se adequar à sequência de IDs do seu projeto. Por exemplo, se seu projeto já tem `ARCH-001` até `ARCH-005`, os ADRs importados receberão `ARCH-006`, `ARCH-007`, etc.
Quando você importa ADRs, os IDs originais são **remapeados** para corresponder aos prefixos de domínio do seu projeto. O campo `domain` de cada ADR determina qual prefixo ele recebe — por exemplo, um ADR com `domain: frontend` vira `FE-XXX`, enquanto um com `domain: backend` vira `BE-XXX`. Cada domínio tem seu próprio contador, então importar um pack com domínios mistos produz IDs corretamente prefixados sem colisões.

Você pode sobrescrever o prefixo com `--prefix`:
Por exemplo, importar um pack com três ADRs de frontend e dois de backend em um projeto que já tem `FE-001` e `BE-001` produz:

```bash
archgate adr import packs/security --prefix SEC
```
- `FE-002`, `FE-003`, `FE-004` (frontend)
- `BE-002`, `BE-003` (backend)

O remapeamento garante:

1. Nenhuma colisão de ID com ADRs existentes
2. Um esquema de numeração único e consistente em todo o projeto
2. Cada domínio mantém sua própria sequência de numeração
3. Arquivos de regras importados funcionam imediatamente sem edições manuais

## O manifesto imports.json
Expand All @@ -124,10 +123,9 @@ Este manifesto permite rastrear a proveniência — de onde cada ADR importado v

## Referência de opções do comando

| Opção | Descrição |
| ------------------- | ----------------------------------------------- |
| `--yes` | Pula o prompt de confirmação |
| `--json` | Saída em formato JSON |
| `--dry-run` | Preview sem escrever arquivos |
| `--prefix <prefix>` | Sobrescreve o prefixo de ID dos ADRs importados |
| `--list` | Lista ADRs importados anteriormente |
| Opção | Descrição |
| ----------- | ----------------------------------- |
| `--yes` | Pula o prompt de confirmação |
| `--json` | Saída em formato JSON |
| `--dry-run` | Preview sem escrever arquivos |
| `--list` | Lista ADRs importados anteriormente |
34 changes: 27 additions & 7 deletions src/commands/adr/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import { exitWith } from "../../helpers/exit";
import { logDebug, logError } from "../../helpers/log";
import { formatJSON, isAgentContext } from "../../helpers/output";
import { findProjectRoot } from "../../helpers/paths";
import { resolvedProjectPaths } from "../../helpers/project-config";
import {
getMergedDomainPrefixes,
resolvedProjectPaths,
} from "../../helpers/project-config";
import {
resolveSource,
shallowClone,
Expand Down Expand Up @@ -76,6 +79,7 @@ interface AdrToImport {
rulesPath: string | null;
originalId: string;
title: string;
domain?: string;
source: string;
packVersion?: string;
}
Expand Down Expand Up @@ -139,6 +143,7 @@ async function collectAdrsToImport(
rulesPath: rulesFile ?? null,
originalId: adr.frontmatter.id,
title: adr.frontmatter.title,
domain: adr.frontmatter.domain,
source,
packVersion: target.packMeta.version,
});
Expand All @@ -151,6 +156,7 @@ async function collectAdrsToImport(
rulesPath: target.rulesFile,
originalId: adr.frontmatter.id,
title: adr.frontmatter.title,
domain: adr.frontmatter.domain,
source,
});
}
Expand Down Expand Up @@ -234,7 +240,6 @@ export function registerAdrImportCommand(adr: Command) {
.option("--yes", "Skip confirmation prompt", false)
.option("--json", "Output as JSON", false)
.option("--dry-run", "Preview changes without writing", false)
.option("--prefix <prefix>", "Override ID prefix for imported ADRs")
.option("--list", "List previously imported ADRs", false)
.action(async (sources, opts) => {
const projectRoot = findProjectRoot();
Expand Down Expand Up @@ -285,21 +290,36 @@ export function registerAdrImportCommand(adr: Command) {

// ---------- Determine prefix & remap IDs ----------

const prefix = opts.prefix ?? "ARCH";
mkdirSync(paths.adrsDir, { recursive: true });

let nextIdStr = getNextId(paths.adrsDir, prefix);
// Resolve each ADR's domain to the project's prefix for that domain.
const domainPrefixes = getMergedDomainPrefixes(projectRoot);

// Track the next available ID per prefix to avoid collisions
const nextIdByPrefix = new Map<string, string>();

const idMap: Array<{ original: string; newId: string; title: string }> =
[];

for (const adr of adrsToImport) {
const prefix = (adr.domain && domainPrefixes[adr.domain]) || "ARCH";

if (!nextIdByPrefix.has(prefix)) {
nextIdByPrefix.set(prefix, getNextId(paths.adrsDir, prefix));
}

const nextId = nextIdByPrefix.get(prefix)!;
idMap.push({
original: adr.originalId,
newId: nextIdStr,
newId: nextId,
title: adr.title,
});
const num = parseInt(nextIdStr.replace(`${prefix}-`, ""), 10) + 1;
nextIdStr = `${prefix}-${String(num).padStart(3, "0")}`;

const num = parseInt(nextId.replace(`${prefix}-`, ""), 10) + 1;
nextIdByPrefix.set(
prefix,
`${prefix}-${String(num).padStart(3, "0")}`
);
}

// ---------- Preview ----------
Expand Down
2 changes: 2 additions & 0 deletions src/commands/adr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { registerDomainCommand } from "./domain/index";
import { registerAdrImportCommand } from "./import";
import { registerAdrListCommand } from "./list";
import { registerAdrShowCommand } from "./show";
import { registerAdrSyncCommand } from "./sync";
import { registerAdrUpdateCommand } from "./update";

export function registerAdrCommand(program: Command) {
Expand All @@ -18,6 +19,7 @@ export function registerAdrCommand(program: Command) {
registerAdrImportCommand(adr);
registerAdrListCommand(adr);
registerAdrShowCommand(adr);
registerAdrSyncCommand(adr);
registerAdrUpdateCommand(adr);
registerDomainCommand(adr);
}
Loading
Loading