|
| 1 | +# Project Context |
| 2 | + |
| 3 | +- **Owner:** Maor Leger |
| 4 | +- **Project:** autorest.typescript — TypeSpec TS emitter refactor to align with Rust/Go emitter architecture. |
| 5 | +- **Stack:** TypeScript, pnpm, TypeSpec, ts-morph, vitest, TCGC. |
| 6 | +- **Key paths:** |
| 7 | + - Emitter source: `packages/typespec-ts/src/` (modular/, rlc/, codemodel/, framework/, static-helpers/) |
| 8 | + - Shared RLC: `packages/rlc-common/` |
| 9 | + - Smoke fixtures: `packages/typespec-test/test/` |
| 10 | + - Unit tests: `packages/typespec-ts/test/unit` (RLC), `packages/typespec-ts/test/modularUnit` (Modular) |
| 11 | + - Integration: `test/integration`, `test/modularIntegration`, `test/azureIntegration`, `test/azureModularIntegration` |
| 12 | +- **Build/test commands:** `pnpm install`, `pnpm build`, `pnpm format`, `npm run unit-test`, `npm run lint`, `npm run integration-test-ci:{rlc|modular|azure-rlc|azure-modular}`, `npm run smoke-test`. |
| 13 | +- **Reference architectures:** `~/workspace/emitter-chain/typespec-rust`, `~/workspace/emitter-chain/autorest.go`, doc at `/home/maorleger/workspace/emitter-chain/go-rust.md`. |
| 14 | +- **Hands-off:** `packages/autorest.typescript/` is in maintenance mode. |
| 15 | +- **Existing codemodel pattern:** `src/codemodel/` already uses types.ts + build-*.ts + render-*.ts separation — likely the seed for the broader refactor. |
| 16 | +- **Created:** 2026-05-15 |
| 17 | + |
| 18 | +## Learnings |
| 19 | + |
| 20 | +<!-- Append new learnings below. Each entry is something lasting about the project. --> |
| 21 | + |
| 22 | +### 2026-05-15 — Stage 1 client context pipeline swap |
| 23 | + |
| 24 | +- Replaced the modular `$onEmit` client-context call in `packages/typespec-ts/src/index.ts` from `buildClientContext(dpgContext, subClient, modularEmitterOptions)` to `adaptSingleClient(subClient, dpgContext, modularEmitterOptions)` plus `emitClientContext(project, tsClient, generationSettings)`. |
| 25 | +- Kept `buildOperationFiles`, `buildClassicalClient`, and the rest of the modular source pipeline unchanged; only the client context path was swapped in-place. |
| 26 | +- Adjusted `packages/typespec-ts/src/codegen/clients.ts` to preserve prior client-context output semantics, including nested subfolder paths, api-version required/interface behavior, options typing, and passthrough of endpoint-assigned optional params. |
| 27 | +- Validation: `pnpm build` passed, `cd packages/typespec-ts && npm run unit-test` passed, and `cd packages/typespec-ts && npm run copy:typespec && npm run integration-test-ci:modular` passed. `npm run lint` currently fails with a pre-existing ESLint/@typescript-eslint rule loading error while linting `src/codegen/clients.ts`. |
| 28 | + |
| 29 | +### 2026-05-15 — Ripley Staged Refactor Plan: Three-Layer Pipeline (appended by Scribe) |
| 30 | + |
| 31 | +**Staged refactor plan approved and ready for implementation:** |
| 32 | + |
| 33 | +Ripley completed a 9-stage refactor plan (`.squad/decisions/ripley-staged-refactor-plan.md`) to decouple TCGC from rendering: |
| 34 | + |
| 35 | +1. **Three-layer architecture:** |
| 36 | + - **CodeModel (IR):** `TSCodeModel` capturing emitter intent, zero TCGC. |
| 37 | + - **TCGC Adapter:** Transforms TCGC → CodeModel; isolated in `src/tcgcadapter/`. |
| 38 | + - **CodeGen:** Renders CodeModel → ts-morph AST; consumed by `src/codegen/`. |
| 39 | + |
| 40 | +2. **Stage structure (Stages 1–9; Stage 10 dropped):** |
| 41 | + - Stages 1–2: Adapter validation (TCGC→CodeModel only). |
| 42 | + - Stages 3–6: Codegen expansion (clients, operations, models, classicalClient). |
| 43 | + - Stages 7–9: Helper migration, cleanup, polish. |
| 44 | + |
| 45 | +3. **Key directives applied:** |
| 46 | + - ✅ No feature flag (swap-in-place migration). |
| 47 | + - ✅ Adapter unit tests as primary validation surface. |
| 48 | + - ✅ Readability-first file organization (monolithic until needed). |
| 49 | + - ✅ Skip lint guard (trust patterns). |
| 50 | + - ✅ Skip Stage 10 (package separation). |
| 51 | + |
| 52 | +**Your work (PRD 3 onwards) aligns with Stages 3–6.** See full plan for stage boundaries and test matrix. |
| 53 | + |
| 54 | +### 2026-05-15 — Lambert Cross-Agent Summary: Architecture Analysis Findings (appended by Scribe) |
| 55 | + |
| 56 | +**From Lambert's comparative analysis** (filed to decisions.md 2026-05-15): |
| 57 | + |
| 58 | +Key findings for **Dallas** (codegen layer development): |
| 59 | +1. **Codegen target is well-defined.** The POC's `src/codegen/` provides a template. `emitFromCodeModel()` orchestrator + `emitClientContext()` renderer (for clients.ts category) show the pattern. Zero TCGC imports in this layer — verify via lint. |
| 60 | +2. **IR shape (`TSCodeModel`) needs extension.** Current POC covers client context files only. Add to IR for **your** work scope: |
| 61 | + - `TSOperationFile` for operations (PRD 3) |
| 62 | + - `TSModel`, `TSEnum`, `TSUnion` for types (PRD 7) |
| 63 | + - Model-scoped types: `TSProperty`, `TSPropertyConstraint`, `TSModelBase` (reference Rust's `codemodel/types.ts` pattern) |
| 64 | +3. **Adapter helpers reuse is pragmatic but temporary.** POC imports from old `src/modular/helpers/` (clientHelpers, operationHelpers). As each old `build*` migrates, its helpers either move into `src/tcgcadapter/` (if TCGC-aware) or into `src/codegen/` (if IR-only). Plan this as part of each adapter extension. |
| 65 | +4. **Rendering machinery is stable.** `resolveReference()` and `useDependencies()` from framework are acceptable as narrow hooks in codegen (not TCGC leakage). Equivalent to Go's `FsFacilities` injector — a contract for framework services. |
| 66 | +5. **Test all codegen outputs via integration suites.** Each category (operations, models, classicalClient, etc.) is tested by modular/azure-modular integration suites; smoke test catches compilation failures. Use these as your regression oracle. |
| 67 | + |
| 68 | +### 2026-05-15 — Stage 0 Infrastructure Verification |
| 69 | + |
| 70 | +- The `origin/poc-emitter-separation` POC commit `4459962` was already present on `squad-rewrite` under commit `3542d9e8c`, with the same additive `src/codemodel/`, `src/tcgcadapter/`, and `src/codegen/` files plus the fixture `.d.ts` deletions. |
| 71 | +- Verified the Stage 0 infrastructure remains unwired to `$onEmit`; no existing emitter entrypoints were changed as part of this slice. |
| 72 | +- `pnpm build` passed at repo root and `npm run unit-test` passed in `packages/typespec-ts/` without needing follow-up fixes. |
| 73 | + |
| 74 | +### 2026-05-15 — Stage 2 operation IR expansion |
| 75 | + |
| 76 | +- `packages/typespec-ts/src/codemodel/index.ts` now models operations with data-only shapes: `TSMethod`, `TSParameter`, `TSReturnType`, `TSRoute`, and `TSOperationGroup`. |
| 77 | +- `packages/typespec-ts/src/tcgcadapter/adapter.ts` now exports `adaptMethods()` and `adaptOperationGroups()` so operation extraction can be tested separately from full-client adaptation. |
| 78 | +- The operation-group IR keeps `prefixes` alongside `name` and `methods` so future rendering can recover nested group paths without reaching back into TCGC. |
| 79 | +- Validation for this slice was `pnpm build` at repo root and `npm run unit-test` in `packages/typespec-ts`. |
| 80 | + |
| 81 | +### 2026-05-16 — Stage 4 operations codegen wiring |
| 82 | + |
| 83 | +- `packages/typespec-ts/src/codegen/operations.ts` now serves as the modular operations renderer, consuming `TSClient`/`TSOperationGroup` IR and emitting stable `api/**/operations.ts` files directly through ts-morph. |
| 84 | +- The emitter path keeps the generated operation helpers deterministic by sorting operation files by their normalized path and running `fixMissingImports(..., { importModuleSpecifierEnding: "js" })` before trimming unused imports. |
| 85 | +- Validation for this slice was `pnpm build`, `cd packages/typespec-ts && npm run unit-test`, and `cd packages/typespec-ts && npm run copy:typespec && npm run integration-test-ci:modular`. |
| 86 | + |
| 87 | +### 2026-05-19 — squad-rewrite regression fixes |
| 88 | + |
| 89 | +- Restored top-level `api/**` recursion in `packages/typespec-ts/src/codegen/indexFiles.ts` so the root barrel once again reaches generated `./api/<resource>/index.js` subbarrels and their `*OptionalParams` exports. |
| 90 | +- Changed `packages/typespec-ts/src/codegen/clients.ts` to respect adapted `TSClientParameter.required` metadata for client contexts, and added a modular unit test that keeps defaulted client `apiVersion` optional in the generated `*Context` interface. |
| 91 | +- Switched `packages/typespec-ts/src/codegen/models.ts` to select raw model/enum/union declarations from filtered `TSCodeModel` IR lookups instead of the legacy global emit queue, which keeps paging `*ListResult` shapes internal unless the adapter actually exposes them. |
| 92 | +- Triaged user report regressions: 4 confirmed (indexFiles subpath barrel, clients apiVersion requiredness, models paging leak, dedupe workaround); 1 misdiagnosed (coreClient import text churn); 2 expected (import path normalization, beginX wrapper reappearance). |
| 93 | +- Commits: d24c6178d (indexFiles), e35c3244d (apiVersion), e8b5a8022 (models). Pushed origin/squad-rewrite tip 56aa9c54f. |
| 94 | +- Validation: `pnpm build` ✅, `npm run unit-test` in `packages/typespec-ts/` ✅. |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## 2026-05-19T23:30:29.807+00:00 — B8 Fix: Array/dict serializer helper placeholders |
| 99 | + |
| 100 | +**Task:** Fix P0 regression introduced by e8b5a8022 where `src/models/models.ts` contained |
| 101 | +unresolved `__PLACEHOLDER_*__` tokens for array/dict serializer helpers. |
| 102 | + |
| 103 | +**Strategy chosen:** Strategy A (Renderer emits the missing helpers) |
| 104 | + |
| 105 | +**Rationale:** Strategy B would require adding `helperTypes` to `TSCodeModel` and updating the |
| 106 | +tcgcadapter — a broader change. Strategy A is a targeted, correct fix: the renderer simply |
| 107 | +needs to walk the same `emitQueue` entries (array/dict kinds) that the legacy `emitTypes()` |
| 108 | +did, calling `emitType()` to register the serializer/deserializer refkeys with the binder. |
| 109 | +A TODO comment and follow-up note were left for Strategy B migration. |
| 110 | + |
| 111 | +**Files touched:** |
| 112 | +- `packages/typespec-ts/src/codegen/models.ts` — import `emitQueue`; add loop for array/dict types |
| 113 | +- `packages/typespec-ts/test/modularUnit/models-helpers.spec.ts` — new regression-locking tests |
| 114 | +- `.squad/decisions/inbox/dallas-models-helpers.md` — follow-up note for IR migration |
| 115 | + |
| 116 | +**Validation:** |
| 117 | +- `pnpm build` — passed |
| 118 | +- `npm run unit-test` (typespec-ts) — 664 tests passed, 0 failures |
| 119 | +- Regenerated `NetworkAnalytics.Management` (azure-modular tag) — zero `__PLACEHOLDER_` matches |
| 120 | +- `tsc --noEmit` on generated NetworkAnalytics package — only missing `@azure/identity` in samples (pre-existing, unrelated), zero TS2304 errors |
| 121 | +- B8 regression tests (array + dict) — both pass green |
| 122 | + |
| 123 | +**Open follow-up:** `.squad/decisions/inbox/dallas-models-helpers.md` — migrate array/dict helper types into TSCodeModel IR to remove `emitQueue` side-channel dependency from the codegen layer. |
0 commit comments