Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
20 KiB
20 KiB
Scratchpad: Cross-Package Cleanup P0-P2
Key Commands Reference
Build & TypeScript
# Full build (the definitive check)
npm run build
# TypeScript check on specific package (faster than full build)
cd packages/<pkg> && npx tsc --noEmit
cd server && npx tsc --noEmit
cd ee/server && npx tsc --noEmit
cd ee/packages/workflows && npx tsc --noEmit
Cross-Package Violations (Lint)
# Authoritative violation count (use this, NOT nx run-many which undercounts ~50%)
npm run lint 2>&1 | grep "no-feature-to-feature-imports" | wc -l
# Per-source package breakdown
npm run lint 2>&1 | grep "no-feature-to-feature-imports" | sed 's/.*Feature package "\([^"]*\)".*/\1/' | sort | uniq -c | sort -rn
# Per-target package breakdown
npm run lint 2>&1 | grep "no-feature-to-feature-imports" | sed 's/.*feature package "\([^"]*\)".*/\1/' | sort | uniq -c | sort -rn
# Violations for a specific source package
npm run lint 2>&1 | grep "no-feature-to-feature-imports" | grep 'Feature package "client-portal"'
# Violations for a specific target
npm run lint 2>&1 | grep "no-feature-to-feature-imports" | grep 'feature package "documents"'
Circular Dependencies
# Generate Nx graph and check for new cycles
npx nx graph --file=/tmp/graph.json && node scripts/check-circular-deps.mjs /tmp/graph.json --baseline .github/known-cycles.json
# Update baseline after fixing cycles (include tightened baseline in commit)
npx nx graph --file=/tmp/graph.json && node scripts/check-circular-deps.mjs /tmp/graph.json --update-baseline .github/known-cycles.json
# As of 2026-03-17, the root `package.json` override `nx -> brace-expansion@^2.0.2`
# restores `npx nx graph --file=/tmp/graph.json` in this workspace.
Grep Patterns for Finding Violations
# Find all imports of a package from outside it
grep -r "@alga-psa/documents" --include="*.ts" --include="*.tsx" packages/ | grep -v "packages/documents/" | grep -v node_modules
# Find imports of auth-compat
grep -r "auth-compat" --include="*.ts" --include="*.tsx" -l | grep -v node_modules
# Find type-only cross-vertical imports
grep -rn "import type.*@alga-psa/" packages/ --include="*.ts" --include="*.tsx" | grep -v node_modules
# Check what shared/ imports from workflows
grep -r "@alga-psa/workflows" shared/ --include="*.ts" --include="*.tsx" -l | grep -v node_modules
Testing
# Run tests locally (requires .env.localtest)
npm run test:local
# Run affected tests only
npx vitest run --changed
# Run specific test file
cd server && npx vitest run path/to/test.test.ts
Decisions
- 2026-03-16: P0-1 test files moved to
ee/packages/workflows/(notpackages/workflows/) because the tests reference EE-specific domain event builders - 2026-03-16:
@alga-psa/sharedadded as devDependency toee/packages/workflows/package.jsonfor moved test imports - 2026-03-16: Removed 18 baseline cycles that all contained the resolved
@alga-psa/shared -> @alga-psa/workflowsedge; used manual baseline pruning because local Nx graph generation is still broken by thebrace_expansion_1.defaultruntime error - 2026-03-17: Added a root
overrides.nx.brace-expansion = ^2.0.2pin sonx's bundledminimatch@9resolves a compatiblebrace-expansionversion andnpx nx graphworks again locally. - 2026-03-17:
packages/storagenow owns its document/media workflow-event payload builders and no longer depends on@alga-psa/auth,@alga-psa/shared,@alga-psa/workflow-streams, or@alga-psa/workflows; this removed the last unbaselined storage-driven cycles without changing emitted payload shapes.
Current State (2026-03-17)
- Branch: cleanup/circular_deps (rebased on origin/main)
- Feature checklist: complete through
F039 - Known cycles baseline: 11 cycles after the restored Nx graph check and the storage dependency cleanup
- Authoritative lint count: 57
no-feature-to-feature-importsviolations (down from the original 103 baseline) - Build / graph status:
npm run build,cd packages/storage && npx tsc --noEmit,cd packages/storage && npx vitest run tests/storageService.workflowEvents.test.ts, andnpx nx graph --file=/tmp/graph.json && node scripts/check-circular-deps.mjs /tmp/graph.json --baseline .github/known-cycles.jsonall pass locally
2026-03-16 Progress Log
- Verified
shared/only references@alga-psa/workflowsin a comment withinshared/types/product-email-domains.d.ts. - Verified moved workflow tests compile with
cd ee/packages/workflows && npx tsc --noEmit;cd shared && npx tsc --noEmitalso passes. npx nx graph --file=/tmp/graph.jsonstill fails locally withbrace_expansion_1.default is not a function, including under Node 20, so cycle-baseline verification currently relies on the removed import edge plus baseline pruning.npm run buildpassed from repo root after the workflow test moves and cycle-baseline update; build emitted existing Next.js webpack warnings only.- Pending workflow-test file moves and the related
ee/packages/workflows/package.jsondevDependency update are ready to commit as the final P0-1 code delta. - Authoritative
npm run lintbaseline is103no-feature-to-feature-importsviolations when run directly from repo root.
P0-2 Violation Breakdown (from /tmp/p0-lint.log)
By source package
38 client-portal
14 workflows
13 tickets
12 clients
10 projects
9 billing
3 assets
2 users
2 integrations
By target package
39 documents
13 tickets
9 billing
8 sla
7 clients
6 scheduling
6 projects
6 integrations
5 workflows
4 users
- Migrated
ee/server/src/app/api/extensions/_auth.tsto callgetSession()directly from@alga-psa/auth, removing its dependency on@/lib/auth-compat. - Migrated
ee/server/src/app/api/provisioning/tenants/route.tsto callgetSession()directly from@alga-psa/auth, leavingserver/src/lib/auth-compat.tswith no remaining callers. - Deleted
server/src/lib/auth-compat.ts; the compatibility wrapper is fully retired in favor ofgetSession()from@alga-psa/auth. npm run buildstill passes after deletingserver/src/lib/auth-compat.ts; only pre-existing webpack warnings were emitted.- Auth-compat retirement is now represented by the committed
F008-F011change series, so the P1-3 code path is fully checked in. - Added
export * from './assets'topackages/msp-composition/src/index.tsto expose the existing assets composition barrel from the package root. - Added
export * from './billing'topackages/msp-composition/src/index.tsso billing composition helpers are reachable from the main barrel. - Added
export * from './clients'topackages/msp-composition/src/index.ts; the root barrel now exposes assets, billing, clients, tickets, projects, and scheduling. npm run buildpasses with the expanded@alga-psa/msp-compositionbarrel; no new build regressions surfaced.- The
msp-compositionexport wiring is now fully committed via theF013-F016change series. - P2-5a inventory:
packages/projects/src/actions/projectActions.tsis the activeprojects -> clientsdirect import (getContactByContactNameId);packages/scheduling/srccurrently has no direct@alga-psa/clientsimports. - Verified
packages/clients/src/context/ClientCrossFeatureContext.tsxalready exports the client cross-feature provider + hook surface needed for composition-layer injection. - Verified
packages/msp-composition/src/clients/MspClientCrossFeatureProvider.tsxalready bridges tickets/surveys/assets callbacks into the clients context. - Current lint baseline has
0activeprojects -> clientsand0activescheduling -> clientswarnings; the lone remaining direct import inpackages/projects/src/actions/projectActions.tsis an intentionally justified server-action exception. - P2-5a is effectively green in the current tree: the most recent root
npm run buildpassed, and the client-related pair counts are already reduced to zero warnings. - P2-5a now closes as verification/bookkeeping only because the context/provider migration had already landed before this plan pass.
- P2-5b inventory from the authoritative lint log:
documentsis still the top target with 39 warnings sourced fromprojects(10),clients(10),client-portal(7),tickets(5),assets(3),users(2),workflows(1), andbilling(1). Common import shapes are entity-image helpers, document utilities,Documents/DocumentUploadUI, and KB types. - Moved the public
uploadEntityImage/deleteEntityImageentrypoint to@alga-psa/storageand updated theclient-portal,teams,users,tenancy, andclientscallers to import from the horizontal package instead of@alga-psa/documents. - Added a horizontal
DocumentsCrossFeatureContextto@alga-psa/coreso remaining document UI imports can be replaced without introducing new vertical-to-vertical dependencies. DocumentsCrossFeatureContextmust stay off the root@alga-psa/corebarrel because exporting a client-only React context there causes server imports of@alga-psa/coreto fail Next.js builds.- T001 verified that
shared/only mentions@alga-psa/workflowsin the comment insideshared/types/product-email-domains.d.ts; there are no actual code imports left. - T002 verified
cd ee/packages/workflows && npx tsc --noEmitsucceeds after the ten test-file moves. - T003 verified a fresh repo-root
npm run buildsucceeds after the workflow moves, auth cleanup, and storage entity-image extraction work. - T004 hit the documented local skip condition:
npx nx graph --file=/tmp/graph.jsonstill fails withbrace_expansion_1.default is not a function, so cycle verification continues to rely on the pruned baseline and removed import edge. - T005 confirmed
.github/known-cycles.jsonnow contains12baselined cycles, down from the prior30. - T006 reconfirmed that the direct lint command remains the authoritative measurement path; after the later document cleanup it reports
98current violations. - T007 reconfirmed the per-source lint breakdown pipeline; the latest run is led by
client-portal,workflows,tickets,clients, andprojects. - T008 reconfirmed the per-target lint breakdown pipeline;
documentsremains the top target even after the entity-image move, followed bytickets,billing, andsla. - T009 verified there are no remaining
auth-compatsource references anywhere in the repo. - T010 verified
ee/server/src/app/api/extensions/_auth.tsnow importsgetSessiondirectly from@alga-psa/auth. - T011 verified
ee/server/src/app/api/provisioning/tenants/route.tsnow importsgetSessiondirectly from@alga-psa/auth. - T012 confirmed
server/src/lib/auth-compat.tsno longer exists on disk. - T013 reuses the latest repo-root green build to validate the auth-compat removal end-to-end.
- T014 verified
packages/msp-composition/src/index.tsexports./assetsfrom the root barrel. - T015 verified
packages/msp-composition/src/index.tsexports./billingfrom the root barrel. - T016 verified
packages/msp-composition/src/index.tsexports./clientsfrom the root barrel. - T017 reuses the latest repo-root green build to validate the expanded
msp-compositionbarrel. - T018 verified the current lint output has
0activeprojects -> clientsviolations, which is below the historical non-zero starting point for P2-5a. - T019 verified
packages/clients/src/context/ClientCrossFeatureContext.tsxexists and exports the expected provider/hook pair. - T020 reuses the latest repo-root green build to validate the current client-composition setup.
- T021 verified the latest lint run has
34documents-target violations, which is below the<36target in the plan. - T022 verified no vertical package now imports
uploadEntityImageordeleteEntityImagefrom@alga-psa/documents; those callers now resolve through@alga-psa/storage. - T023 reuses the latest repo-root green build to validate the current document-cleanup changes.
- F028 conditions are met in the current tree: repo-root build passes and the
documentstarget is down to34warnings from the earlier39baseline. - The current document-cleanup series is committed through
F025,F026, and the follow-up barrel fix, so the implemented P2-5b work is fully checked in. - Rolled the
DocumentsCrossFeatureContextout into composition providers for MSP and client-portal shells, then migrated the remaining client-side document UI/util callers inassets,tickets, andclient-portalto consume the context instead of importing@alga-psa/documentsdirectly. - Moved the client-portal document provider out of
packages/client-portaland intoserver/src/app/client-portal/ClientPortalDocumentsProvider.tsxafter lint exposed that a local provider would itself create a newclient-portal -> documentsviolation. - Validation after the provider rollout:
npm run lintnow reports91totalno-feature-to-feature-importswarnings and only27targetingdocuments(down from98/34before this pass); repo-rootnpm run buildalso passes. - F030 categorization snapshot from
/tmp/alga-lint-f030.log:client-portalnow has34remaining warnings.6are clearly fixable (client-kb.ts,ClientKBArticleView.tsx,ClientKBPage.tsxvia@alga-psa/types;ProjectDetailView.tsxvia a composition facade). The other28are inherent composition edges acrosstickets,billing,clients, andusers, where client-portal is intentionally orchestrating vertical feature APIs/components and is a reasonable candidate for justifiedeslint-disablecomments in F031. - Acceptable/inherent client-portal edges:
client-billing.ts,client-tickets.ts,clientPaymentActions.ts,BillingOverview.tsx,ClientInvoicePreview.tsx,ClientProfile.tsx,ClientDetailsSettings.tsx,ClientPasswordChangeForm.tsx,UserManagementSettings.tsx,ClientAddTicket.tsx,TicketDetails.tsx,TicketDetails.originBadge.contract.test.ts, andTicketList.tsx. - Fixable client-portal edges queued for later items:
client-kb.ts,ClientKBArticleView.tsx,ClientKBPage.tsx(type-onlydocumentsimports for P2-6), plusProjectDetailView.tsx(presentation imports fromprojects, a goodclient-portalcomposition-facade candidate for F032). - Added file-level
custom-rules/no-feature-to-feature-importsdisables with explicit justification comments to the acceptable/inherent client-portal composition files; a freshnpm run lintnow reports63total violations and only6remainingclient-portalwarnings, all in the previously identified fixable KB/project files. - Created a new horizontal
@alga-psa/client-portal-compositionpackage and moved the project metrics card composition there viaClientPortalProjectMetrics;packages/client-portal/src/components/projects/ProjectDetailView.tsxno longer imports from@alga-psa/projectsdirectly. - Validation after F032:
cd packages/client-portal && npx tsc --noEmit,cd server && npx tsc --noEmit, andnpm run lintall pass; only3client-portalviolations remain, all from the KB type-only imports targeted by P2-6. - Re-ran the full repo-root
npm run buildafter the new@alga-psa/client-portal-compositionpackage landed; the build is green, so the client-portal cleanup track is now blocked only on the planned P2-6 type extraction. - The client-portal cleanup series is now fully checkpointed through
F030-F034: acceptable edges are documented and justified, the project-detail composition moved to a horizontal package, the build is green, and only the KB type-only imports remain for P2-6. - F035 inventory: the meaningful remaining P2-6 candidates are the KB types
IKBArticleWithDocumentandArticleType, imported type-only from@alga-psa/documents/actionsinpackages/client-portal/src/actions/client-portal-actions/client-kb.ts,packages/client-portal/src/components/kb/ClientKBArticleView.tsx, andpackages/client-portal/src/components/kb/ClientKBPage.tsx. The broader grep also finds many same-package or horizontal-package type imports, but those are not cross-vertical cleanup targets. - Moved the KB domain types into
packages/types/src/lib/knowledgeBase.tsand exported them from@alga-psa/types;packages/documents/src/actions/kbArticleActions.tsnow consumes those shared definitions instead of owning them locally. - Validation after F036:
cd packages/types && npx tsc --noEmit,cd packages/client-portal && npx tsc --noEmit, andcd packages/documents && npx tsc --noEmitall pass. - Updated the three client-portal KB callers (
client-kb.ts,ClientKBArticleView.tsx,ClientKBPage.tsx) to import the extracted KB types from@alga-psa/types;npm run lintnow reports0remainingclient-portalfeature-import warnings and57total violations repo-wide. - Re-ran the full repo-root
npm run buildafter the KB type import swap; build stays green, and the lint baseline remains at57, down from the original authoritative103count. - The P2-6 type extraction series is now fully checkpointed through
F035-F039: candidates identified, KB types moved into@alga-psa/types, callers updated, build re-verified, and the feature checklist is complete. - Root-cause for the old
nx graphfailure:nx's bundledminimatch@9.0.3was resolving the repo-levelbrace-expansion@5, which breaksbraceExpand()at runtime. Pinningoverrides.nx.brace-expansionto^2.0.2and refreshingnode_modulesrestorednpx nx graph. - Removed stale
packages/storagedependencies on auth/shared/workflows and replaced its@alga-psa/workflow-streamspayload-builder imports with local equivalents inpackages/storage/src/workflowEventPayloads.ts; this eliminated the remaining storage-driven graph cycles while preserving the same published event payload fields. - Validation for the storage cleanup:
cd packages/storage && npx tsc --noEmit,cd packages/storage && npx vitest run tests/storageService.workflowEvents.test.ts,npx nx graph --file=/tmp/graph.json && node scripts/check-circular-deps.mjs /tmp/graph.json --baseline .github/known-cycles.json, and repo-rootnpm run buildall pass. - T024 now passes end-to-end: the restored graph run reports
11total cycles,.github/known-cycles.jsonhas been tightened from12to11, and the checker reportsNo new circular dependencies. - T025 verified the client-portal cleanup end-to-end:
npm run lintnow reports0remainingFeature package "client-portal"violations, which means every prior client-portal edge was either removed via composition/type extraction or intentionally suppressed with a justification comment. - T026 reuses the latest repo-root green
npm run buildafter the client-portal composition package and KB type-extraction changes, confirming the client-portal cleanup series remains build-safe. - T027 verified
grep -rn "import type.*@alga-psa/documents" packages/client-portal/ --include='*.ts' --include='*.tsx'now returns0matches. - T028 verified the new shared KB definitions live in
packages/types/src/lib/knowledgeBase.tsand are exported throughpackages/types/src/index.ts. - T029 reuses the latest repo-root green
npm run buildafter the KB type extraction and caller migration. - T030 confirmed the authoritative lint count is now
57, which is substantially below the P0-2 baseline of103.
Remaining Open Work
- None. Feature and test checklists are complete.
Gotchas
npm run lintis the correct command (notnpx nx run-many --target=lintwhich misses ~50% of violations)- The repo engine range is
>=20 <25; under the current local Nodev25.8.1,npm installemitsEBADENGINEwarnings even though the verified commands above still pass. - Never create re-export shims when migrating — update all callers directly
client-portalis inherently a composition layer — some violations may be acceptable with eslint-disable- When adding context facades, providers must go in
DefaultLayout.tsx(not per-page) because DrawerOutlet renders at layout level msp-compositionis a horizontal package so it's allowed to import from verticals — its internal violations are by design