diff --git a/.changeset/36895-studio-address-builder.md b/.changeset/36895-studio-address-builder.md new file mode 100644 index 00000000000..98a66df0136 --- /dev/null +++ b/.changeset/36895-studio-address-builder.md @@ -0,0 +1,18 @@ +--- +'@objectstack/types': patch +'@objectstack/runtime': patch +'@objectstack/cli': patch +'@object-ui/app-shell': patch +'@object-ui/console': patch +--- + +refactor(studio): every Studio address comes from one builder; no address changes + +Clause-②: yes (widening) +Metadata-protocol: none + +Studio redesign groundwork (#36895, epic #36890). Every place that produced a `/studio...` URL now calls one builder, so a later change can move an item type to its metadata address in one place. Every address is byte-for-byte what it was: no link, bookmark or redirect changes. + +- **Console.** `studioAddress.ts` in `@object-ui/app-shell` builds every Studio address: the landing, a package, a pillar, an item (`studioItemPath`), the "All metadata" area, and the draft review links. `studioAddressTable.ts` lists every address family, every `?surface=` spelling and every query parameter, with what each becomes on the metadata address. The retired `/interfaces` redirect keeps exactly the parameters that table marks. New exports from `@object-ui/app-shell`: `STUDIO_ROOT_PATH`, `STUDIO_HOME_PILLAR`, `studioLandingPath`, `studioPackagePath`. Existing exports keep their names and values. +- **Server.** `studioChangesReviewLink` and `studioItemReviewLink`, new in `@objectstack/types`, build the review links that `os meta register` prints and that the MCP authoring tools return after a draft save. The text an AI is handed is unchanged. +- **Guards.** A test under `ui/` refuses a hand-built Studio address in any ui source. A test in `@objectstack/types` refuses one in any server package, and holds the review links quoted by the `objectstack-mcp-build` skill's evals equal to what the builder returns. diff --git a/packages/cli/src/commands/meta/register.ts b/packages/cli/src/commands/meta/register.ts index 2e524e5b24b..e722565b70b 100644 --- a/packages/cli/src/commands/meta/register.ts +++ b/packages/cli/src/commands/meta/register.ts @@ -6,6 +6,7 @@ import type { MetadataValidationResult } from '@objectstack/spec/kernel'; import { printError, printInfo, printSuccess, printWarning, emitJson, errorCodeFields } from '../../utils/format.js'; import { createApiClient, requireAuth } from '../../utils/api-client.js'; import { formatOutput } from '../../utils/output-formatter.js'; +import { studioChangesReviewLink } from '@objectstack/types'; /** * [#23350] The refusal an EMPTY `--package` earns, before anything reaches the @@ -210,7 +211,7 @@ export function draftSaveLines(args: { if (args.packageId) { lines.push( `Review and publish it in Studio's Changes for package ${args.packageId} ` - + `(/studio/${encodeURIComponent(args.packageId)}/data?changes=review).`, + + `(${studioChangesReviewLink(args.packageId)}).`, ); } return lines; diff --git a/packages/runtime/src/domains/mcp-authoring.ts b/packages/runtime/src/domains/mcp-authoring.ts index 2fe455f181a..37c17196bea 100644 --- a/packages/runtime/src/domains/mcp-authoring.ts +++ b/packages/runtime/src/domains/mcp-authoring.ts @@ -168,6 +168,7 @@ import type { AIToolDefinition } from '@objectstack/spec/contracts'; import type { HttpProtocolContext } from '../http-dispatcher.js'; import type { DomainHandlerDeps } from '../domain-handler-registry.js'; import { readEffectiveTenancyPosture } from './activation-gate.js'; +import { studioChangesReviewLink, studioItemReviewLink } from '@objectstack/types'; /** The read tools' names, in the order the registry lists them. */ export const OPEN_AUTHORING_READ_TOOL_NAMES = ['list_metadata_items', 'get_metadata_item', 'list_drafts'] as const; @@ -1288,10 +1289,9 @@ function verdictOf(judgement: OpenAuthoringDraftJudgement): { * and the item's draft review on Studio's metadata area (`?review=1`). */ function reviewRoutes(packageId: string, type: string, name: string): { changes: string; item: string; note: string } { - const pkg = encodeURIComponent(packageId); return { - changes: `/studio/${pkg}/data?changes=review`, - item: `/studio/${pkg}/metadata/${encodeURIComponent(type)}/${encodeURIComponent(name)}?review=1`, + changes: studioChangesReviewLink(packageId), + item: studioItemReviewLink(packageId, type, name), note: 'Console routes. A person reviews and publishes the draft there; this server cannot publish.', }; } diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 575c25261db..9e64923a151 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -148,6 +148,10 @@ export * from './summary-recompute-answer.js'; // action or flow. Its producers (objectql, service-automation) cannot import // each other; both already depend on this package. export * from './packaged-item-turned-off.js'; +// [#36895] The Studio addresses a server hands out for a saved draft's review. +// Its producers (cli's `os meta register`, runtime's MCP authoring tools) +// cannot depend on the Console; both already depend on this package. +export * from './studio-review-links.js'; // Placeholder for Kernel interface to avoid circular dependency // The actual Kernel implementation will satisfy this interface. diff --git a/packages/types/src/studio-review-links.callers.test.ts b/packages/types/src/studio-review-links.callers.test.ts new file mode 100644 index 00000000000..6a2fa60658d --- /dev/null +++ b/packages/types/src/studio-review-links.callers.test.ts @@ -0,0 +1,170 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#36895 — no server package builds a Studio address by hand, and + * the review links the `objectstack-mcp-build` skill's evals quote are the + * ones this package builds. + * + * ── Why ────────────────────────────────────────────────────────────────────── + * + * The Studio redesign (epic #36890) moves Studio's addresses one item type at + * a time. A `/studio/...` string written out in a server package would keep + * the old address after the move, and an AI handed it would send a person to + * the wrong page. `studio-review-links.ts` is the one place a server spells + * one; the Console's builder (`studioAddress.ts` in the app-shell package) + * is held by the same kind of pin in the ui workspace. + * + * ── What it judges ─────────────────────────────────────────────────────────── + * + * 1. Every `.ts` source under `packages/` (tests, declaration files and build + * output excepted), parsed: a string or template literal that starts with + * `/studio` (then its end, `/`, `?` or `#`) is a hand-built address. Prose + * in comments is free. + * 2. The eval file of the published skill (it is governed: it is read, never + * edited here): every Studio address it quotes equals what + * `studioChangesReviewLink` / `studioItemReviewLink` return for the + * package, type and name the address names, so the two cannot drift. + * + * ── Controls ───────────────────────────────────────────────────────────────── + * + * The walk must reach the two server producers, the matcher must fire on the + * one allowed file, and the eval file must yield its quoted addresses (seven + * on the commit this landed: five Changes links, two item reviews). Zero in + * any of them means the instrument is broken, not that the tree is clean. + * + * The radius: `packages/**` `.ts` (already this package's declared glob, the + * extension boundary is the one `driver-error-classification.callers.test.ts` + * records) plus the one eval file, declared beside it. + */ + +import { describe, expect, it } from 'vitest'; +import { existsSync, readdirSync, readFileSync } from 'node:fs'; +import { dirname, join, relative, resolve, sep } from 'node:path'; +import ts from 'typescript'; +import { studioChangesReviewLink, studioItemReviewLink } from './studio-review-links.js'; + +/** + * This package is CJS-typed, so `import.meta` is not available: walk up from + * the CWD to this package's own manifest (`driver-error-classification.callers.test.ts` + * says why), then reach the repo root by arithmetic. + */ +function findUp(marker: (dir: string) => boolean, what: string): string { + let dir = process.cwd(); + for (;;) { + if (marker(dir)) return dir; + const parent = dirname(dir); + if (parent === dir) throw new Error(`could not locate ${what} walking up from ${process.cwd()}`); + dir = parent; + } +} + +const PACKAGE_ROOT = findUp((dir) => { + const manifest = join(dir, 'package.json'); + if (!existsSync(manifest)) return false; + const { name } = JSON.parse(readFileSync(manifest, 'utf8')) as { name?: string }; + return name === '@objectstack/types'; +}, 'the @objectstack/types package root'); + +const REPO_ROOT = resolve(PACKAGE_ROOT, '../..'); + +const SCANNED_TREE = join(REPO_ROOT, 'packages'); + +/** The skill eval whose quoted review links must equal the builder's. */ +const EVAL_FILE = join(REPO_ROOT, 'skills/objectstack-mcp-build/evals/draft-door-procedure.json'); + +/** The one server file that spells a Studio address. */ +const ALLOWED = 'packages/types/src/studio-review-links.ts'; + +const SKIP_DIRS = new Set(['node_modules', 'dist', 'build', 'coverage', '.turbo', '.next', '__tests__']); + +const SOURCE_FILE = (name: string): boolean => + name.endsWith('.ts') && !name.endsWith('.d.ts') && !/\.(?:test|spec)\.ts$/.test(name); + +const STUDIO_LITERAL = /^\/studio(?:$|[/?#])/; + +function sourceFilesUnder(root: string): string[] { + const out: string[] = []; + const walk = (dir: string): void => { + for (const entry of readdirSync(dir, { withFileTypes: true })) { + if (entry.isDirectory()) { + if (!SKIP_DIRS.has(entry.name)) walk(join(dir, entry.name)); + continue; + } + if (entry.isFile() && SOURCE_FILE(entry.name)) out.push(join(dir, entry.name)); + } + }; + walk(root); + return out; +} + +function handBuiltStudioAddresses(fileName: string, text: string): string[] { + if (!text.includes('/studio')) return []; + const source = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS); + const hits: string[] = []; + const visit = (node: ts.Node): void => { + const literalText = + ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) + ? node.text + : ts.isTemplateExpression(node) + ? node.head.text + : null; + if (literalText !== null && STUDIO_LITERAL.test(literalText)) { + const { line } = source.getLineAndCharacterOfPosition(node.getStart(source)); + hits.push(`${line + 1}: ${node.getText(source).replace(/\s+/g, ' ').slice(0, 120)}`); + } + ts.forEachChild(node, visit); + }; + visit(source); + return hits; +} + +/** Every Studio address quoted in a text, up to the first quote, space, backtick or paren. */ +function quotedStudioAddresses(text: string): string[] { + return [...text.matchAll(/\/studio\/[^\s"'`)]+/g)].map((m) => m[0]); +} + +/** What the builder returns for the package, type and name an address names. */ +function rebuilt(address: string): string | null { + const changes = /^\/studio\/([^/?#]+)\/data\?changes=review$/.exec(address); + if (changes) return studioChangesReviewLink(decodeURIComponent(changes[1])); + const item = /^\/studio\/([^/?#]+)\/metadata\/([^/?#]+)\/([^/?#]+)\?review=1$/.exec(address); + if (item) { + return studioItemReviewLink(decodeURIComponent(item[1]), decodeURIComponent(item[2]), decodeURIComponent(item[3])); + } + return null; +} + +describe('no server package builds a Studio address by hand (objectstack#36895)', () => { + it('the matcher sees each spelling and spares prose and look-alikes', () => { + const scan = (text: string) => handBuiltStudioAddresses('x.ts', text); + expect(scan("const a = '/studio';")).toHaveLength(1); + expect(scan('const b = `/studio/${pkg}/data?changes=review`;')).toHaveLength(1); + expect(scan("const c = 'see (/studio/x)';")).toEqual([]); + expect(scan("const d = '/api/v1/studio/runtime-config';")).toEqual([]); + expect(scan('// links to /studio/crm/data\nconst e = 1;')).toEqual([]); + expect(scan("const f = '/studios';")).toEqual([]); + }); + + it('only the shared module spells one', () => { + const files = sourceFilesUnder(SCANNED_TREE); + const rel = (file: string) => relative(REPO_ROOT, file).split(sep).join('/'); + const names = new Set(files.map(rel)); + // Controls: the walk reaches both server producers, and the matcher fires + // on the allowed module. + expect(names.has('packages/runtime/src/domains/mcp-authoring.ts')).toBe(true); + expect(names.has('packages/cli/src/commands/meta/register.ts')).toBe(true); + expect(handBuiltStudioAddresses(ALLOWED, readFileSync(join(REPO_ROOT, ALLOWED), 'utf8')).length).toBe(2); + + const offenders = files + .filter((file) => rel(file) !== ALLOWED) + .flatMap((file) => handBuiltStudioAddresses(file, readFileSync(file, 'utf8')).map((hit) => `${rel(file)}:${hit}`)); + expect(offenders).toEqual([]); + }); + + it("the skill evals quote the builder's review links, byte for byte", () => { + const quoted = quotedStudioAddresses(readFileSync(EVAL_FILE, 'utf8')); + // Control: the eval file still quotes its review links. + expect(quoted.length).toBeGreaterThanOrEqual(7); + for (const address of quoted) expect(rebuilt(address), address).toBe(address); + }); +}); diff --git a/packages/types/src/studio-review-links.test.ts b/packages/types/src/studio-review-links.test.ts new file mode 100644 index 00000000000..8f114b53d12 --- /dev/null +++ b/packages/types/src/studio-review-links.test.ts @@ -0,0 +1,24 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import { describe, expect, it } from 'vitest'; +import { studioChangesReviewLink, studioItemReviewLink } from './studio-review-links.js'; + +/** + * objectstack#36895 — the server's draft review links, byte for byte as the CLI + * and the MCP authoring tools spelled them before this module existed. The + * Console's `studioChangesReviewPath` / `studioItemReviewPath` are pinned to + * the same literals in the Console's app-shell package (`studioAddress.test.ts`). + */ +describe('the Studio review links a server hands out (objectstack#36895)', () => { + it("a package's Changes drawer on its Studio home", () => { + expect(studioChangesReviewLink('com.acme.crm')).toBe('/studio/com.acme.crm/data?changes=review'); + expect(studioChangesReviewLink('a b/c')).toBe('/studio/a%20b%2Fc/data?changes=review'); + }); + + it("an item's draft review in the All metadata area", () => { + expect(studioItemReviewLink('com.acme.crm', 'flow', 'crm_lead_created_notify')).toBe( + '/studio/com.acme.crm/metadata/flow/crm_lead_created_notify?review=1', + ); + expect(studioItemReviewLink('p q', 'object', 'a/b')).toBe('/studio/p%20q/metadata/object/a%2Fb?review=1'); + }); +}); diff --git a/packages/types/src/studio-review-links.ts b/packages/types/src/studio-review-links.ts new file mode 100644 index 00000000000..a8f338d3a51 --- /dev/null +++ b/packages/types/src/studio-review-links.ts @@ -0,0 +1,29 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The two Studio addresses a server hands out (objectstack#36895): where a + * person reviews a draft that the CLI's `os meta register` or the MCP authoring + * tools saved. Both producers (`packages/cli`, `packages/runtime`) already + * depend on this package, and neither may depend on the Console, so the + * shared spelling lives here. + * + * The Console builds the same two addresses with `studioChangesReviewPath` + * and `studioItemReviewPath` (`studioAddress.ts` in the Console's app-shell package), + * which does not depend on this package; both sides are pinned to the same + * literals, and to the literals the `objectstack-mcp-build` skill's evals + * quote (`studio-review-links.test.ts`). + * + * ⛔ A changed byte here changes the review link an AI is handed and repeats to + * a person. The addresses move only when the Studio redesign moves them, and + * then on both sides together. + */ + +/** A package's Changes drawer on its Studio home: `/studio//data?changes=review`. */ +export function studioChangesReviewLink(packageId: string): string { + return `/studio/${encodeURIComponent(packageId)}/data?changes=review`; +} + +/** An item's draft review in Studio's "All metadata" area: `/studio//metadata//?review=1`. */ +export function studioItemReviewLink(packageId: string, type: string, name: string): string { + return `/studio/${encodeURIComponent(packageId)}/metadata/${encodeURIComponent(type)}/${encodeURIComponent(name)}?review=1`; +} diff --git a/packages/types/vitest.repo-tests.json b/packages/types/vitest.repo-tests.json index 4fa1fed2ec0..919ce79aec0 100644 --- a/packages/types/vitest.repo-tests.json +++ b/packages/types/vitest.repo-tests.json @@ -1,3 +1,4 @@ [ - "src/driver-error-classification.callers.test.ts" + "src/driver-error-classification.callers.test.ts", + "src/studio-review-links.callers.test.ts" ] diff --git a/scripts/cross-package-test-inputs.mjs b/scripts/cross-package-test-inputs.mjs index 5179b99a628..f8af81272de 100644 --- a/scripts/cross-package-test-inputs.mjs +++ b/scripts/cross-package-test-inputs.mjs @@ -405,7 +405,13 @@ export const CROSS_PACKAGE_TEST_INPUTS = { // to a workspace-root marker file, so it names no root-level path and this // entry adds no new top-level root for `check-ci-filter-parity.mjs` to want // in ci.yml's `crosspkg:` filter. Its own header records that trade. - globs: ['packages/**/*.ts'], + // + // src/studio-review-links.callers.test.ts (#36895) walks the same `.ts` + // population for hand-built Studio addresses, and reads the one skill eval + // that quotes the server's draft review links, to hold each quoted link + // equal to what this package builds. That file sits under the published + // skills root, which ci.yml's `crosspkg:` filter already covers whole. + globs: ['packages/**/*.ts', 'skills/objectstack-mcp-build/evals/draft-door-procedure.json'], }, '@objectstack/organizations': { // src/no-framework-dependents.pin.test.ts is ADR-0132 D3's mechanical half. diff --git a/turbo.json b/turbo.json index 33ab50ab6e7..49ca3cabbf4 100644 --- a/turbo.json +++ b/turbo.json @@ -829,7 +829,8 @@ "!coverage/**", "!.turbo/**", "!**/node_modules/**", - "$TURBO_ROOT$/packages/**/*.ts" + "$TURBO_ROOT$/packages/**/*.ts", + "$TURBO_ROOT$/skills/objectstack-mcp-build/evals/draft-door-procedure.json" ] }, "@objectstack/runtime#test:repo": { diff --git a/ui/apps/console/src/AppContent.tsx b/ui/apps/console/src/AppContent.tsx index 6c3a3ff72c9..cdf3e490f21 100644 --- a/ui/apps/console/src/AppContent.tsx +++ b/ui/apps/console/src/AppContent.tsx @@ -20,6 +20,7 @@ import { LocalizationFetchProvider } from './LocalizationFetchProvider'; import { FirstRunChecklist } from './pages/settings/FirstRunChecklist'; import { InAppFormRoute } from './components/InternalFormRoute'; import { APPROVAL_ACTION_OBJECT, APPROVAL_REQUEST_OBJECT, routeApprovalRecordReads } from './services/approvalRequestsDataSource'; +import { studioLandingPath } from '@object-ui/app-shell'; const AppManagementPage = lazy(() => import('./pages/system/AppManagementPage').then(m => ({ default: m.AppManagementPage }))); const ProfilePage = lazy(() => import('./pages/system/ProfilePage').then(m => ({ default: m.ProfilePage }))); @@ -65,7 +66,7 @@ function ObjectRedirect() { // objectstack ADR-0146 D1 — straight to Studio's "All metadata" area, the // page Setup's `…/metadata/object` route opens there. const target = setupMetadataStudioPath(objectName ? `object/${objectName}` : 'object', location.search, location.hash); - return ; + return ; } /** @@ -175,7 +176,7 @@ function SystemObjectRedirect({ objectName }: { objectName: string }) { function SystemCatalogRedirect({ type }: { type: 'position' | 'permission' }) { // objectstack ADR-0146 D1 — the catalog is Studio's, in the "All metadata" // area's cross-package leg. - return ; + return ; } /** diff --git a/ui/apps/console/src/components/StudioRoute.tsx b/ui/apps/console/src/components/StudioRoute.tsx index ea6d7583099..cc1b4248016 100644 --- a/ui/apps/console/src/components/StudioRoute.tsx +++ b/ui/apps/console/src/components/StudioRoute.tsx @@ -45,10 +45,12 @@ import { LoadingFallback, LoadingScreen, STUDIO_ALL_PACKAGES_SEGMENT, + STUDIO_HOME_PILLAR, STUDIO_METADATA_AREA, STUDIO_ORG_SCOPE_PILLAR, STUDIO_ORG_SCOPE_SEGMENT, studioMetadataAreaPath, + studioPackagePath, useHomePath, useRecentItems, } from '@object-ui/app-shell'; @@ -282,7 +284,7 @@ function StudioPackageBuilder({ area }: { area?: typeof STUDIO_METADATA_AREA }) id: `package:${packageId}`, type: 'package', name: packageId, - href: `/studio/${encodeURIComponent(packageId)}`, + href: studioPackagePath(packageId), }); // Driven by the package alone. `addRecentItem` is a `useCallback` result, // whose identity is not a dependency (AGENTS.md #10), as in @@ -345,7 +347,7 @@ export const studioRoutes = ( path={`${STUDIO_ALL_PACKAGES_SEGMENT}/*`} element={} /> - } /> + } /> } diff --git a/ui/packages/app-shell/src/chrome/CommandPalette.tsx b/ui/packages/app-shell/src/chrome/CommandPalette.tsx index 9920f4c8268..3096d971246 100644 --- a/ui/packages/app-shell/src/chrome/CommandPalette.tsx +++ b/ui/packages/app-shell/src/chrome/CommandPalette.tsx @@ -81,7 +81,7 @@ import { useAuth } from '@object-ui/auth'; import { matchesPaletteQuery } from './paletteMatch.js'; import { fetchPackages, type PkgEntry } from '../views/studio-design/packages-io.js'; import { isPackageLessItem, studioOrgScopePath } from '../views/studio-design/studioScope.js'; -import { DESIGNER_SURFACE_PARAM, formatSurfaceParam } from '../views/metadata-admin/nav-selection.js'; +import { studioHomePath, studioItemPath } from '../views/studio-design/studioAddress.js'; import { flattenNavigation, useAppReportEntries } from '../views/appReportIndex.js'; import { useServedApps } from '../hooks/useLauncherApps.js'; import { servedObjectLabel } from '../hooks/servedObjectLabel.js'; @@ -1033,16 +1033,6 @@ interface StudioPaletteEntries { const NO_STUDIO_ENTRIES: StudioPaletteEntries = { packages: [], objects: [], flows: [], loading: false }; -/** - * A Studio pillar opened on one item, through the pillar's `?surface=` deep - * link: the shape `studioOrgScopePath` builds for the package-less scope, under - * a package. An object opens in the Data pillar and a flow in Automations, - * the pillars `StudioDesignSurface` routes those surface types to. - */ -function studioSurfacePath(packageId: string, pillar: 'data' | 'automations', surface: { type: string; name: string }): string { - return `/studio/${encodeURIComponent(packageId)}/${pillar}?${DESIGNER_SURFACE_PARAM}=${encodeURIComponent(formatSurfaceParam(surface))}`; -} - /** * The Studio's packages, objects and flows, as the `studio` scope lists them * (objectui#11863). Nothing is read until `enabled` (the palette is open in that @@ -1115,7 +1105,7 @@ function useStudioPaletteEntries(enabled: boolean): StudioPaletteEntries { key: `${pkg.id}:${item.name}`, label: resolveKeyedI18nLabel(item.label, t) || item.name, name: item.name, - href: studioSurfacePath(pkg.id, 'data', { type: 'object', name: item.name }), + href: studioItemPath(pkg.id, 'object', item.name), packageName: pkg.name, }); } @@ -1139,7 +1129,7 @@ function useStudioPaletteEntries(enabled: boolean): StudioPaletteEntries { key: `${pkg.id}:${item.name}`, label, name: item.name, - href: studioSurfacePath(pkg.id, 'automations', { type: 'flow', name: item.name }), + href: studioItemPath(pkg.id, 'flow', item.name), packageName: pkg.name, }); } @@ -1149,7 +1139,7 @@ function useStudioPaletteEntries(enabled: boolean): StudioPaletteEntries { key: pkg.id, label: pkg.name, name: pkg.id, - href: `/studio/${encodeURIComponent(pkg.id)}/data`, + href: studioHomePath(pkg.id), })), objects, flows, diff --git a/ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx b/ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx index 51faf222c3f..c999e02971a 100644 --- a/ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx +++ b/ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx @@ -54,6 +54,7 @@ import { Button, DataEmptyState } from '@object-ui/components'; import { useObjectTranslation } from '@object-ui/i18n'; import { useServedAppLabel } from '../hooks/useServedAppLabel.js'; import { useCanAuthorMetadata } from '../hooks/useCanAuthorMetadata.js'; +import { studioHomePath } from '../views/studio-design/studioAddress.js'; export interface AppNoAccessEmptyStateProps { /** The active app, as the console's metadata list carries it (`_packageId` as served). */ @@ -147,7 +148,7 @@ export function AppNoAccessEmptyState({ app, setupPath, reason = 'no-navigation' })} action={ diff --git a/ui/packages/app-shell/src/console/ai/AiChatPage.tsx b/ui/packages/app-shell/src/console/ai/AiChatPage.tsx index 9f33f1bcf4c..582e306449e 100644 --- a/ui/packages/app-shell/src/console/ai/AiChatPage.tsx +++ b/ui/packages/app-shell/src/console/ai/AiChatPage.tsx @@ -171,6 +171,7 @@ import { AiUnavailable } from './AiUnavailable.js'; import { recordWriteFormTarget } from '../../utils/recordFormAiDraft.js'; import { useUpload } from '@object-ui/fields'; import { isSpreadsheetAttachment, uploadChatAttachments, chatAttachmentNotes } from './chatAttachments.js'; +import { studioHomePath } from '../../views/studio-design/studioAddress.js'; /** * The app segment a record of `objectName` lives under: the object's owning @@ -3149,7 +3150,7 @@ export function ChatPane({ onDesignBuiltApp={(_appName, appSegment) => { const pkg = appSegment ?? boundPackageId; if (!pkg) return; - navigate(`/studio/${encodeURIComponent(pkg)}/data`); + navigate(studioHomePath(pkg)); }} designBuiltAppLabel={t('console.ai.viewBuiltAppInStudio', { defaultValue: 'View in Studio' })} // Artifact deep links: every artifact the agent built gets a one-click diff --git a/ui/packages/app-shell/src/console/ai/artifactStudioPath.ts b/ui/packages/app-shell/src/console/ai/artifactStudioPath.ts index 98d567f7d19..9a19b9922c9 100644 --- a/ui/packages/app-shell/src/console/ai/artifactStudioPath.ts +++ b/ui/packages/app-shell/src/console/ai/artifactStudioPath.ts @@ -19,27 +19,13 @@ * callers render those as plain text, not dead links. */ -import { - DESIGNER_SURFACE_PARAM, - formatSurfaceParam, -} from '../../views/metadata-admin/nav-selection.js'; -import { studioMetadataItemPath } from '../../views/studio-design/metadataArea.js'; +import { studioItemPath } from '../../views/studio-design/studioAddress.js'; export interface BuiltArtifact { type: string; name: string; } -function pillarPath( - packageId: string, - pillar: 'data' | 'automations', - surface?: BuiltArtifact, -): string { - const base = `/studio/${encodeURIComponent(packageId)}/${pillar}`; - if (!surface) return base; - return `${base}?${DESIGNER_SURFACE_PARAM}=${encodeURIComponent(formatSurfaceParam(surface))}`; -} - export function artifactStudioPath( packageId: string | undefined, artifact: BuiltArtifact, @@ -48,15 +34,15 @@ export function artifactStudioPath( const name = artifact.name?.trim(); if (!name) return null; switch (artifact.type) { + // objectstack#36895 — the item's Studio address (`studioItemPath`): its + // pillar today for an object or a flow, its "All metadata" page for the rest. case 'object': - return pillarPath(packageId, 'data', { type: 'object', name }); case 'flow': - return pillarPath(packageId, 'automations', { type: 'flow', name }); case 'dashboard': case 'page': case 'view': case 'app': - return studioMetadataItemPath(packageId, { type: artifact.type, name }); + return studioItemPath(packageId, artifact.type, name); default: return null; } diff --git a/ui/packages/app-shell/src/console/home/HomePage.tsx b/ui/packages/app-shell/src/console/home/HomePage.tsx index d57bc7f6947..e963c463a26 100644 --- a/ui/packages/app-shell/src/console/home/HomePage.tsx +++ b/ui/packages/app-shell/src/console/home/HomePage.tsx @@ -93,6 +93,7 @@ import { STUDIO_NEW_PACKAGE_PATH } from '../../views/studio-design/studioNewPack import { useOpenAssistant } from '../../layout/chatDockControl.js'; import { isProductApp } from '../../utils/homePath.js'; import { useAddAppEntries, useMayAddApp } from '../../hooks/useAddAppEntries.js'; +import { studioLandingPath } from '../../views/studio-design/studioAddress.js'; import { catalogServesBuild } from '../../hooks/surfaceAgent.js'; /** @@ -976,7 +977,7 @@ export function HomePage({ checklist }: HomePageProps = {}) { icon={Hammer} label={t('home.build.title', { defaultValue: 'Build an app' })} tone="soft" - onClick={() => navigate('/studio')} + onClick={() => navigate(studioLandingPath())} disabledReason={!canAuthorMetadata ? authoringGateReason : undefined} reasonId={authoringReasonId} testId="home-build-app" diff --git a/ui/packages/app-shell/src/hooks/useAddAppEntries.ts b/ui/packages/app-shell/src/hooks/useAddAppEntries.ts index e5583b9c2fb..dab6df502d1 100644 --- a/ui/packages/app-shell/src/hooks/useAddAppEntries.ts +++ b/ui/packages/app-shell/src/hooks/useAddAppEntries.ts @@ -17,6 +17,7 @@ import { useCanAuthorMetadata } from './useCanAuthorMetadata.js'; import { useAiSurfaceEnabled } from './useAiSurface.js'; import { isAiStudioEnabled, isMarketplaceEnabled } from '../runtime-config.js'; import { STUDIO_NEW_PACKAGE_PATH } from '../views/studio-design/studioNewPackage.js'; +import { studioLandingPath } from '../views/studio-design/studioAddress.js'; /** The marketplace, where templates and packages are installed from. */ const MARKETPLACE_PATH = '/apps/setup/system/marketplace'; @@ -55,7 +56,7 @@ export function useAddAppEntries(): AddAppEntry[] { if (isAiStudioEnabled()) { entries.push( buildServed - ? { key: 'build-with-ai', to: '/studio', label: t('home.buildWithAI', { defaultValue: 'Build with AI' }), icon: Hammer } + ? { key: 'build-with-ai', to: studioLandingPath(), label: t('home.buildWithAI', { defaultValue: 'Build with AI' }), icon: Hammer } : { key: 'new-in-studio', to: STUDIO_NEW_PACKAGE_PATH, label: t('home.build.inStudio', { defaultValue: 'New in Studio' }), icon: Hammer }, ); } diff --git a/ui/packages/app-shell/src/index.ts b/ui/packages/app-shell/src/index.ts index 835bf2fd9b6..716744bfd10 100644 --- a/ui/packages/app-shell/src/index.ts +++ b/ui/packages/app-shell/src/index.ts @@ -611,6 +611,15 @@ export { StudioMetadataArea } from './views/studio-design/StudioMetadataArea.js' // area (the datasource's stays in Setup). A host whose legacy aliases forward // onto Setup's metadata routes lands them in one hop through this. export { setupMetadataStudioPath } from './views/studio-design/setupMetadataRedirect.js'; +// objectstack#36895 — the one builder of Studio addresses. A host that +// declares the `/studio` routes, or links into them, spells every address +// through these, never by hand (`studioAddress.guard.test.ts`). +export { + STUDIO_ROOT_PATH, + STUDIO_HOME_PILLAR, + studioLandingPath, + studioPackagePath, +} from './views/studio-design/studioAddress.js'; // AI assistant bus — connects the metadata designers to the global chat. diff --git a/ui/packages/app-shell/src/utils/appRoute.ts b/ui/packages/app-shell/src/utils/appRoute.ts index f726d3ecb83..74f1cf2f9de 100644 --- a/ui/packages/app-shell/src/utils/appRoute.ts +++ b/ui/packages/app-shell/src/utils/appRoute.ts @@ -15,6 +15,8 @@ * framework-owned, app-independent page for this user (see below). */ +import { studioHomePath, studioItemPath, studioMetadataItemAddress } from '../views/studio-design/studioAddress.js'; + /** * The minimal app shape THESE ROUTE HELPERS read. * @@ -260,7 +262,7 @@ export function appStudioDesignPath( if (!isWorkspaceAdmin) return null; const packageId = studioPackageId(app); if (!packageId) return null; - return `/studio/${encodeURIComponent(packageId)}/data`; + return studioHomePath(packageId); } /** @@ -284,7 +286,9 @@ export function appStudioSurfacePath( const type = surface?.type; const name = surface?.name; if (!type || !name) return null; - return `/studio/${encodeURIComponent(packageId)}/metadata/${encodeURIComponent(type)}/${encodeURIComponent(name)}`; + // The area's item page for every type, explicitly: not `studioItemPath`, + // which sends a pillar type to its pillar. + return studioMetadataItemAddress(packageId, type, name); } /** @@ -308,8 +312,9 @@ export function appStudioObjectPath( const packageId = studioPackageId(app); if (!packageId) return null; if (!objectName) return null; - const value = `object:${encodeURIComponent(objectName)}`; - return `/studio/${encodeURIComponent(packageId)}/data?surface=${value}`; + // The `'name'` spelling (`object:` as written, the name encoded), as this + // bridge has always spelled it. + return studioItemPath(packageId, 'object', objectName, { spelling: 'name' }); } /** diff --git a/ui/packages/app-shell/src/views/DashboardInPageEditor.tsx b/ui/packages/app-shell/src/views/DashboardInPageEditor.tsx index 6e91e49edb6..e7d581fd0d4 100644 --- a/ui/packages/app-shell/src/views/DashboardInPageEditor.tsx +++ b/ui/packages/app-shell/src/views/DashboardInPageEditor.tsx @@ -57,6 +57,7 @@ import { getDashboardForm } from './metadata-admin/dashboard-schema.js'; import { useMetadataLocale, type SupportedLocale } from './metadata-admin/i18n.js'; import type { MetadataSelection } from './metadata-admin/preview-registry.js'; import { ServedWidgetTextContext, servedWidgetTextOf } from './studio-design/servedDashboardText.js'; +import { studioPackagePath } from './studio-design/studioAddress.js'; /** Where the editor would save, as read at open (nothing is written to open). */ export type WritableDashboardEditTarget = Exclude; @@ -202,7 +203,7 @@ export function filtersSectionLabel(locale: SupportedLocale): string | null { * separate entries, never open together. */ export function useDashboardEditOffered(ownerPackageId: string | null | undefined): boolean { - const path = ownerPackageId ? `/studio/${encodeURIComponent(ownerPackageId)}` : null; + const path = ownerPackageId ? studioPackagePath(ownerPackageId) : null; const gated = useStudioEntryGate(path) !== null; const designing = useDesignModeActive(); return gated && !designing; diff --git a/ui/packages/app-shell/src/views/RecordTabsConfig.tsx b/ui/packages/app-shell/src/views/RecordTabsConfig.tsx index 51f4dad4714..d320166d037 100644 --- a/ui/packages/app-shell/src/views/RecordTabsConfig.tsx +++ b/ui/packages/app-shell/src/views/RecordTabsConfig.tsx @@ -63,7 +63,7 @@ import { registerUnsavedEdits } from '../chrome/unsavedEdits.js'; import { useStudioDesignGate, useStudioEntryGate } from '../hooks/useStudioDesignGate.js'; import { useCustomizeDoorWalled } from './studio-design/StudioCustomizeControls.js'; import { relatedListEntryNames, type DerivedRelatedList } from '../utils/deriveRelatedLists.js'; -import { studioPillarItemPath } from './studio-design/metadataArea.js'; +import { studioItemPath } from './studio-design/studioAddress.js'; import { entryDetails } from './studio-design/relatedListVocabulary.js'; import { editRecordTabsDraft, @@ -109,7 +109,7 @@ export type RecordTabsMode = 'own' | 'pair'; export function recordTabsStudioPath(objectDef: RecordTabsObjectDef | null | undefined): string | null { const packageId = objectPackageId(objectDef); const name = objectDef?.name; - return packageId && typeof name === 'string' && name ? studioPillarItemPath(packageId, 'data', { type: 'object', name }) : null; + return packageId && typeof name === 'string' && name ? studioItemPath(packageId, 'object', name) : null; } interface RecordTabsSession { diff --git a/ui/packages/app-shell/src/views/metadata-admin/PackagesPage.tsx b/ui/packages/app-shell/src/views/metadata-admin/PackagesPage.tsx index 2a1fd52c846..f991b9b1dd1 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/PackagesPage.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/PackagesPage.tsx @@ -122,6 +122,7 @@ import { ProtocolCheckSkippedNote } from '../../console/marketplace/ProtocolChec import type { InstalledPackageAtEitherStage } from '@objectstack/spec/api-assembled'; import type { PackagePublishResult } from '@objectstack/spec/system'; import type { ReassignOrphanedMetadataResponse } from '@objectstack/spec/api'; +import { studioHomePath } from '../studio-design/studioAddress.js'; import { PACKAGE_SOURCES, PACKAGES_ADMIN_FACE, @@ -612,7 +613,7 @@ function InstalledAppUpdateCell({ rowId, read }: { rowId: string; read: UpdateRe * administration face's create lands here, and its "Open in Studio" link * points here (objectstack#36834). */ -const studioPackagePath = (packageId: string) => `/studio/${encodeURIComponent(packageId)}/data`; +const studioPackagePath = (packageId: string) => studioHomePath(packageId); /* -------------------------------------------------------------------------- */ /* Create-package dialog */ diff --git a/ui/packages/app-shell/src/views/studio-design/BuilderLanding.tsx b/ui/packages/app-shell/src/views/studio-design/BuilderLanding.tsx index 8246a8bd2d4..0c635df5d9d 100644 --- a/ui/packages/app-shell/src/views/studio-design/BuilderLanding.tsx +++ b/ui/packages/app-shell/src/views/studio-design/BuilderLanding.tsx @@ -68,6 +68,7 @@ import { foldCustomizationPairs } from './StudioRailCustomizations.js'; import { loadPackageLessSurfaces } from './packageSurfaces.js'; import { useMetadataClient } from '../metadata-admin/useMetadata.js'; import { newAppStep } from './newAppDoor.js'; +import { studioHomePath, studioPillarPath } from './studioAddress.js'; /** * objectui#11808 — where a read-only package's card sends the author beyond @@ -111,10 +112,6 @@ type CustomizationLine = } | { kind: 'failed'; message: string }; -/** A package's Studio address on one pillar, the way `open` below spells it. */ -const studioPillarPath = (packageId: string, pillar: 'data' | 'automations') => - `/studio/${encodeURIComponent(packageId)}/${pillar}`; - /** How many switched-off actions the landing line names before its "more" link (objectstack#34724). */ const SWITCHED_OFF_ACTIONS_NAMED = 3; @@ -169,7 +166,7 @@ export function BuilderLanding(): React.ReactElement { }; }, []); - const open = (id: string) => navigate(`/studio/${encodeURIComponent(id)}/data`); + const open = (id: string) => navigate(studioHomePath(id)); // objectstack#35196 — Manage on a card: the switcher's detail sheet, opened // on the package's full installed row (`fetchInstalledPackageRow`), so diff --git a/ui/packages/app-shell/src/views/studio-design/PackageSwitcher.tsx b/ui/packages/app-shell/src/views/studio-design/PackageSwitcher.tsx index fb35e3c41e9..eb26391cc0a 100644 --- a/ui/packages/app-shell/src/views/studio-design/PackageSwitcher.tsx +++ b/ui/packages/app-shell/src/views/studio-design/PackageSwitcher.tsx @@ -11,6 +11,7 @@ */ import type { InstalledPackageRow } from '../metadata-admin/PackagesPage.js'; +import { STUDIO_ROOT_PATH } from './studioAddress.js'; /** * One sonner id for EVERY `fetchPackages()` failure on this surface @@ -25,7 +26,7 @@ import type { InstalledPackageRow } from '../metadata-admin/PackagesPage.js'; export const PACKAGE_LIST_TOAST_ID = 'studio-package-list'; /** objectui#12513 — the Studio landing (`BuilderLanding`). */ -export const STUDIO_LANDING_PATH = '/studio'; +export const STUDIO_LANDING_PATH = STUDIO_ROOT_PATH; /** * The record the standard detail/management sheet opens on: a package's full diff --git a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx index 9e913be10fb..2e34a3043c1 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx @@ -110,10 +110,6 @@ import { import { useMetadataClient } from '../metadata-admin/useMetadata.js'; // objectui#11773 — every draft save of an existing item sends the version its buffer was built on. // objectstack#26858 — the served verdict a flow's inspectors read at their own paths. -import { - DESIGNER_SURFACE_PARAM, - formatSurfaceParam, -} from '../metadata-admin/nav-selection.js'; import { fetchPendingDrafts, usePendingDrafts } from '../../preview/usePendingDrafts.js'; import { emitMetadataRefresh, subscribeMetadataRefresh } from '../../assistant/assistantBus.js'; import { STUDIO_CHANGES_PARAM, STUDIO_CHANGES_REVIEW } from './studioChangesLink.js'; @@ -181,6 +177,7 @@ import { type DraftPublishOptions, } from '../../preview/DraftChangesPanel.js'; import { toast } from 'sonner'; +import { studioPillarItemAddress, studioPillarPath } from './studioAddress.js'; /** The batch door's `backfillApplied` receipt, by reference to what the client returns (objectui#12929). */ type PublishBackfillReceipt = NonNullable< @@ -295,7 +292,7 @@ export function StudioDesignSurface(props: StudioDesignSurfaceProps): React.Reac const pairBase = props.area ? null : customizationPairBaseOf(params.packageId ?? null); if (pairBase !== null) { const tab = params.tab ?? STUDIO_HOME_PILLAR; - return ; + return ; } return ; } @@ -931,7 +928,7 @@ function StudioDesignSurfaceBody({ aiSlot, area }: StudioDesignSurfaceProps): Re const shellNavigate = useNavigate(); React.useEffect(() => { openAccessRef.current = () => { - if (confirmLeavePillar()) shellNavigate(`/studio/${scopeSegment}/access`); + if (confirmLeavePillar()) shellNavigate(studioPillarPath(scopeSegment, 'access', { segmentEncoding: 'verbatim' })); }; }); // objectui#11181 — `label` is the app's own `I18nLabel` (a plain string or an @@ -1228,9 +1225,7 @@ function StudioDesignSurfaceBody({ aiSlot, area }: StudioDesignSurfaceProps): Re const reachable = packageId !== null || pillar === STUDIO_ORG_SCOPE_PILLAR; if (pillar && pillar !== tab && reachable) { if (!confirmLeavePillar()) return false; - shellNavigate( - `/studio/${scopeSegment}/${pillar}?${DESIGNER_SURFACE_PARAM}=${encodeURIComponent(formatSurfaceParam(target))}`, - ); + shellNavigate(studioPillarItemAddress(scopeSegment, pillar, target, { segmentEncoding: 'verbatim' })); } setChangesOpen(false); }, @@ -1314,7 +1309,7 @@ function StudioDesignSurfaceBody({ aiSlot, area }: StudioDesignSurfaceProps): Re {(packageId === null ? PILLARS.filter((p) => p.key === STUDIO_ORG_SCOPE_PILLAR) : pkgMissing ? [] : [...PILLARS, METADATA_AREA_TAB]).map((p) => ( /metadata`). */ -export const STUDIO_METADATA_AREA = 'metadata'; - -/** The reserved `/studio/` value for the area's cross-package leg. */ -export const STUDIO_ALL_PACKAGES_SEGMENT = '~all'; +import { + STUDIO_ALL_PACKAGES_SEGMENT, + STUDIO_ITEM_PILLAR, + STUDIO_ITEM_REVIEW_PARAM, + STUDIO_ITEM_REVIEW_VALUE, + studioItemPillar, + studioMetadataAreaAddress, + studioMetadataAreaRoot, + studioMetadataItemAddress, + studioPillarItemAddress, + type StudioPillarKey, +} from './studioAddress.js'; + +// objectstack#36895 — the area's segments are Studio address vocabulary, owned +// by `studioAddress.ts`; re-exported under their names here. +export { STUDIO_METADATA_AREA, STUDIO_ALL_PACKAGES_SEGMENT } from './studioAddress.js'; +export type { StudioPillarKey } from './studioAddress.js'; /** Whether a `/studio/:packageId` route segment names the cross-package leg. */ export function isStudioAllPackagesScope(segment: string | null | undefined): boolean { @@ -50,12 +60,9 @@ export function isStudioAllPackagesScope(segment: string | null | undefined): bo /** The area's root for a package, or for the cross-package leg with {@link STUDIO_ALL_PACKAGES_SEGMENT}. */ export function studioMetadataAreaPath(segment: string): string { - return `/studio/${encodeURIComponent(segment)}/${STUDIO_METADATA_AREA}`; + return studioMetadataAreaRoot(segment); } -/** The pillar keys a pillar type opens in (`StudioDesignSurface`'s `PILLARS`). */ -export type StudioPillarKey = 'data' | 'automations' | 'access'; - /** * ADR-0146 D1 — "A pillar type opened from the directory opens its pillar". * The types each pillar designs; every other type opens the area's generic @@ -66,15 +73,11 @@ export type StudioPillarKey = 'data' | 'automations' | 'access'; * and this area's generic item page is where they are read and, as a * fallback, edited as metadata. */ -export const AREA_PILLAR_FOR_TYPE: Readonly> = { - object: 'data', - flow: 'automations', - permission: 'access', -}; +export const AREA_PILLAR_FOR_TYPE: Readonly> = STUDIO_ITEM_PILLAR; /** The area's generic item page of one item of a package. */ export function studioMetadataItemPath(packageId: string, item: { type: string; name: string }): string { - return `${studioMetadataAreaPath(packageId)}/${encodeURIComponent(item.type)}/${encodeURIComponent(item.name)}`; + return studioMetadataItemAddress(packageId, item.type, item.name); } /** A pillar of a package, opened on one item through its `?surface=` deep link. */ @@ -83,7 +86,7 @@ export function studioPillarItemPath( pillar: StudioPillarKey, item: { type: string; name: string }, ): string { - return `/studio/${encodeURIComponent(packageId)}/${pillar}?${DESIGNER_SURFACE_PARAM}=${encodeURIComponent(formatSurfaceParam(item))}`; + return studioPillarItemAddress(packageId, pillar, item); } /** @@ -101,10 +104,10 @@ export function areaItemPillarPath(input: { name: string; search: URLSearchParams; }): string | null { - const pillar = AREA_PILLAR_FOR_TYPE[input.type]; + const pillar = studioItemPillar(input.type); if (!pillar || !input.packageId) return null; if (input.search.get(CATALOG_SCOPE_PARAM) === ENVIRONMENT_SCOPE) return null; - if (input.search.get('review') === '1') return null; + if (input.search.get(STUDIO_ITEM_REVIEW_PARAM) === STUDIO_ITEM_REVIEW_VALUE) return null; return studioPillarItemPath(input.packageId, pillar, { type: input.type, name: input.name }); } @@ -152,7 +155,7 @@ export function areaItemOpensFormEditor(input: { (input.readOnly === true && AREA_CUSTOMIZE_EDITOR_TYPES.includes(input.type)); if (!opens || !input.packageId) return false; if (input.search.get(CATALOG_SCOPE_PARAM) === ENVIRONMENT_SCOPE) return false; - return input.search.get('review') !== '1'; + return input.search.get(STUDIO_ITEM_REVIEW_PARAM) !== STUDIO_ITEM_REVIEW_VALUE; } /** `?package=all` is the metadata list's "every package" scope, not a package (`ResourceEditPage`'s `'all'` fold). */ @@ -181,11 +184,7 @@ const ALL_PACKAGES_VALUE = 'all'; export function areaLocationRedirect(segment: string, rest: string, search: string): string | null { const params = new URLSearchParams(search); const allLeg = isStudioAllPackagesScope(segment); - const tail = rest ? `/${rest}` : ''; - const at = (leg: string) => { - const qs = params.toString(); - return `${studioMetadataAreaPath(leg)}${tail}${qs ? `?${qs}` : ''}`; - }; + const at = (leg: string) => studioMetadataAreaAddress(leg, rest, { query: params }); if (params.get(CATALOG_SCOPE_PARAM) === ENVIRONMENT_SCOPE) { if (allLeg && !params.has('package')) return null; diff --git a/ui/packages/app-shell/src/views/studio-design/setupMetadataRedirect.ts b/ui/packages/app-shell/src/views/studio-design/setupMetadataRedirect.ts index 8cc96de9485..5bd5542fec2 100644 --- a/ui/packages/app-shell/src/views/studio-design/setupMetadataRedirect.ts +++ b/ui/packages/app-shell/src/views/studio-design/setupMetadataRedirect.ts @@ -17,7 +17,8 @@ * Datasources page, so redirecting it here would loop. */ -import { STUDIO_ALL_PACKAGES_SEGMENT, areaLocationRedirect, studioMetadataAreaPath } from './metadataArea.js'; +import { STUDIO_ALL_PACKAGES_SEGMENT, areaLocationRedirect } from './metadataArea.js'; +import { studioHomePath, studioLandingPath, studioMetadataAreaAddress, studioPillarPath } from './studioAddress.js'; /** The one metadata type whose Setup pages stay in Setup (ADR-0146 D1). */ export const SETUP_KEPT_METADATA_TYPE = 'datasource'; @@ -37,8 +38,7 @@ export function setupMetadataStudioPath(rest: string, search: string, hash = '') const tail = segments.join('/'); const onLeg = areaLocationRedirect(STUDIO_ALL_PACKAGES_SEGMENT, tail, search); if (onLeg) return `${onLeg}${hash}`; - const query = new URLSearchParams(search).toString(); - return `${studioMetadataAreaPath(STUDIO_ALL_PACKAGES_SEGMENT)}${tail ? `/${tail}` : ''}${query ? `?${query}` : ''}${hash}`; + return studioMetadataAreaAddress(STUDIO_ALL_PACKAGES_SEGMENT, tail, { query: new URLSearchParams(search), hash }); } /** @@ -68,10 +68,9 @@ export function setupMetadataRest(pathname: string): string | null { export function packagedAutomationStudioPath(search: string, hash = ''): string { const params = new URLSearchParams(search); const query = params.toString(); - const tail = `${query ? `?${query}` : ''}${hash}`; const pkg = params.get('package'); - if (pkg && pkg !== 'all') return `/studio/${encodeURIComponent(pkg)}/automations${tail}`; - return `${studioMetadataAreaPath(STUDIO_ALL_PACKAGES_SEGMENT)}/flow${tail}`; + if (pkg && pkg !== 'all') return studioPillarPath(pkg, 'automations', { query, hash }); + return studioMetadataAreaAddress(STUDIO_ALL_PACKAGES_SEGMENT, 'flow', { query, hash }); } /** @@ -88,8 +87,7 @@ export function packagedAutomationStudioPath(search: string, hash = ''): string export function packagedActionsStudioPath(search: string, hash = ''): string { const params = new URLSearchParams(search); const query = params.toString(); - const tail = `${query ? `?${query}` : ''}${hash}`; const pkg = params.get('package'); - if (pkg && pkg !== 'all') return `/studio/${encodeURIComponent(pkg)}/data${tail}`; - return `/studio${tail}`; + if (pkg && pkg !== 'all') return studioHomePath(pkg, { query, hash }); + return studioLandingPath({ query, hash }); } diff --git a/ui/packages/app-shell/src/views/studio-design/studioAddress.guard.test.ts b/ui/packages/app-shell/src/views/studio-design/studioAddress.guard.test.ts new file mode 100644 index 00000000000..d84e78d41a6 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/studioAddress.guard.test.ts @@ -0,0 +1,169 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#36895 — no Studio address is built by hand anywhere under `ui/`. + * + * The Studio redesign (epic #36890) switches each item type from its pillar + * address to its metadata address in ONE place, `STUDIO_ITEM_PILLAR` in + * `studioAddress.ts`. That holds only while every producer calls the builders + * there: a `/studio/...` string written out anywhere else keeps the old + * address after the switch, and the area's redirect then sends it in a loop. + * + * This pin parses every non-test source under `ui/packages//src` and + * `ui/apps//src` (comments are not literals, so prose is free to name an + * address) and refuses: + * + * - a string or template literal that starts with `/studio` (followed by its + * end, `/`, `?` or `#`), and + * - a path composed onto the root constant (`` `${STUDIO_ROOT_PATH}/…` ``, + * `STUDIO_ROOT_PATH + '/…'`), the same hand-build one step removed. + * + * A route PATTERN is not an address: `` declares what + * the console serves, and builds no link. It stays a plain literal, because + * the console's route table is read as source text + * (`useConsoleActionRuntime.onSuccessNavigateHost-13379.test.tsx` reads every + * top-level `path="/…"`), so the string initializer of a ``'s `path` + * attribute is spared. Every other spelling, including a `` + * or a `path` on anything but a ``, is refused. + * + * `studioAddress.ts` is the one file allowed to spell the root (and the + * mapping table beside it, which spells shapes, not links). The server's + * two review links are held by the same kind of pin in `@objectstack/types` + * (`studio-review-links.callers.test.ts`), which also holds the skill evals' + * literals equal to the builder's output. + */ + +import { describe, expect, it } from 'vitest'; +import { readdirSync, readFileSync, statSync } from 'node:fs'; +import path from 'node:path'; +import ts from 'typescript'; +import { uiRoot } from '../../../../../scripts/ui-root.mjs'; + +const UI_ROOT: string = uiRoot(); + +/** + * The one file that spells the root, and the mapping table, whose strings are + * address SHAPES with `<…>` placeholders that no link is built from + * (`studioAddress.test.ts` holds them to the builders). + */ +const ALLOWED = new Set([ + 'packages/app-shell/src/views/studio-design/studioAddress.ts', + 'packages/app-shell/src/views/studio-design/studioAddressTable.ts', +]); + +/** The root's names, as a composed path would start from them. */ +const ROOT_NAMES = new Set(['STUDIO_ROOT_PATH', 'STUDIO_LANDING_PATH']); + +const SKIP_DIRS = new Set(['node_modules', 'dist', 'build', 'coverage', '.turbo', '__tests__', '__mocks__']); + +const SOURCE = /\.(?:ts|tsx|mts)$/; +const NOT_SOURCE = /(?:\.test|\.spec|\.stories|\.d)\.(?:ts|tsx|mts)$/; + +/** A literal's text that is a Studio address. */ +const STUDIO_LITERAL = /^\/studio(?:$|[/?#])/; + +function sourcesUnder(dir: string): string[] { + const out: string[] = []; + for (const entry of readdirSync(dir)) { + const full = path.join(dir, entry); + if (statSync(full).isDirectory()) { + if (!SKIP_DIRS.has(entry)) out.push(...sourcesUnder(full)); + } else if (SOURCE.test(entry) && !NOT_SOURCE.test(entry)) { + out.push(full); + } + } + return out; +} + +/** Every `src` tree of the ui workspace's packages and apps. */ +function uiSources(): string[] { + const out: string[] = []; + for (const group of ['packages', 'apps']) { + for (const member of readdirSync(path.join(UI_ROOT, group))) { + const src = path.join(UI_ROOT, group, member, 'src'); + try { + if (statSync(src).isDirectory()) out.push(...sourcesUnder(src)); + } catch { + // A member without a `src` tree has no sources to judge. + } + } + } + return out; +} + +/** The hand-built addresses in one source text, as `line: text`. */ +function handBuiltStudioAddresses(fileName: string, text: string): string[] { + const kind = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS; + const source = ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true, kind); + const hits: string[] = []; + const hit = (node: ts.Node) => { + const { line } = source.getLineAndCharacterOfPosition(node.getStart(source)); + hits.push(`${line + 1}: ${node.getText(source).replace(/\s+/g, ' ').slice(0, 120)}`); + }; + const isRoot = (node: ts.Node) => ts.isIdentifier(node) && ROOT_NAMES.has(node.text); + // ``: a route pattern the console serves, not a link. + const isRoutePattern = (node: ts.Node) => + ts.isStringLiteral(node) && + ts.isJsxAttribute(node.parent) && + node.parent.name.getText(source) === 'path' && + ts.isJsxAttributes(node.parent.parent) && + node.parent.parent.parent.tagName.getText(source) === 'Route'; + const visit = (node: ts.Node): void => { + if (isRoutePattern(node)) { + // Spared: see the header. + } else if ((ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) && STUDIO_LITERAL.test(node.text)) { + hit(node); + } else if (ts.isTemplateExpression(node)) { + if (STUDIO_LITERAL.test(node.head.text) || (node.head.text === '' && isRoot(node.templateSpans[0].expression))) { + hit(node); + } + } else if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.PlusToken && isRoot(node.left)) { + hit(node); + } + ts.forEachChild(node, visit); + }; + visit(source); + return hits; +} + +describe('no Studio address is built by hand under ui/ (objectstack#36895)', () => { + it('the matcher sees each spelling and spares prose and look-alikes', () => { + const scan = (text: string) => handBuiltStudioAddresses('x.tsx', text); + expect(scan("const a = '/studio';")).toHaveLength(1); + expect(scan('const b = `/studio/${pkg}/data`;')).toHaveLength(1); + expect(scan('const c = "/studio?new=package";')).toHaveLength(1); + expect(scan('const d = ;')).toHaveLength(1); + expect(scan('const d2 = ;')).toHaveLength(1); + expect(scan('const d3 = ;')).toHaveLength(1); + expect(scan('const e = `${STUDIO_ROOT_PATH}/${pkg}`;')).toHaveLength(1); + expect(scan("const f = STUDIO_ROOT_PATH + '/' + pkg;")).toHaveLength(1); + // Not an address. + expect(scan("const g = '/studios';")).toEqual([]); + expect(scan("const h = '/api/v1/studio/runtime-config';")).toEqual([]); + expect(scan("const i = 'studio:builder';")).toEqual([]); + expect(scan('// opens /studio/crm/data\nconst j = 1;')).toEqual([]); + expect(scan('/** `/studio//metadata` */\nconst k = 1;')).toEqual([]); + // A route pattern is a declaration, not a link. + expect(scan('const m = } />;')).toEqual([]); + expect(scan('const n = ;')).toEqual([]); + // The builder's output is not a literal. + expect(scan('const l = studioHomePath(pkg);')).toEqual([]); + }); + + it('no ui source outside the builder spells one', () => { + const files = uiSources(); + const rel = (file: string) => path.relative(UI_ROOT, file).split(path.sep).join('/'); + const names = new Set(files.map(rel)); + // Controls: the walk reaches the packages and the console app, and the + // matcher fires on the one file allowed to spell the root. + expect(names.has('packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx')).toBe(true); + expect(names.has('apps/console/src/components/StudioRoute.tsx')).toBe(true); + const builder = path.join(UI_ROOT, 'packages/app-shell/src/views/studio-design/studioAddress.ts'); + expect(handBuiltStudioAddresses(builder, readFileSync(builder, 'utf8')).length).toBeGreaterThan(0); + + const offenders = files + .filter((file) => !ALLOWED.has(rel(file))) + .flatMap((file) => handBuiltStudioAddresses(file, readFileSync(file, 'utf8')).map((h) => `${rel(file)}:${h}`)); + expect(offenders).toEqual([]); + }); +}); diff --git a/ui/packages/app-shell/src/views/studio-design/studioAddress.test.ts b/ui/packages/app-shell/src/views/studio-design/studioAddress.test.ts new file mode 100644 index 00000000000..209034b8c31 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/studioAddress.test.ts @@ -0,0 +1,211 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#36895 — the Studio address builder returns TODAY's addresses, + * byte for byte, and the mapping table agrees with it. + * + * Every expected value below is a literal: the address as its producer spelled + * it before the builder existed. A builder that drifts by one byte (an encoded + * colon, a `+` for a space) fails here, not in a user's bookmark. + */ + +import { describe, expect, it } from 'vitest'; +import { + STUDIO_ITEM_PILLAR, + studioChangesReviewPath, + studioHomePath, + studioItemPath, + studioItemReviewPath, + studioLandingPath, + studioMetadataAreaAddress, + studioMetadataAreaRoot, + studioMetadataItemAddress, + studioMetadataTypePath, + studioPackagePath, + studioPath, + studioPillarItemAddress, + studioPillarPath, + studioSurfaceQuery, +} from './studioAddress.js'; +import { + STUDIO_ADDRESS_FAMILIES, + STUDIO_ITEM_TYPES, + STUDIO_QUERY_PARAMS, + STUDIO_RETIRED_INTERFACES_KEPT_PARAMS, +} from './studioAddressTable.js'; +import { DESIGNER_SURFACE_PARAM } from '../metadata-admin/nav-selection.js'; +import { CATALOG_SCOPE_PARAM, ENVIRONMENT_SCOPE } from '../metadata-admin/catalog-scope.js'; +import { + DESIGNER_SURFACE_ACTION_PARAM, + DESIGNER_SURFACE_NAV_PARAM, + DESIGNER_SURFACE_VIEW_PARAM, +} from './useSurfaceDeepLink.js'; +import { STUDIO_CHANGES_PARAM, STUDIO_CHANGES_REVIEW } from './studioChangesLink.js'; +import { STUDIO_NEW_PACKAGE_PATH } from './studioNewPackage.js'; +import { retiredInterfacesTarget } from './studioInterfacesRetired.js'; +import { studioOrgScopePath } from './studioScope.js'; +import { AREA_PILLAR_FOR_TYPE, areaItemPillarPath, studioMetadataItemPath, studioPillarItemPath } from './metadataArea.js'; + +describe('studioPath — the one path builder (objectstack#36895)', () => { + it('builds from the left, encoding the scope segment', () => { + expect(studioPath()).toBe('/studio'); + expect(studioPath('com.acme.crm')).toBe('/studio/com.acme.crm'); + expect(studioPath('a b/c')).toBe('/studio/a%20b%2Fc'); + expect(studioPath('crm', 'data')).toBe('/studio/crm/data'); + expect(studioPath('crm', 'metadata', 'object/account')).toBe('/studio/crm/metadata/object/account'); + // A part after an absent one names nothing. + expect(studioPath(null, 'data')).toBe('/studio'); + expect(studioPath('crm', null, 'x')).toBe('/studio/crm'); + }); + + it('writes a verbatim segment as given', () => { + expect(studioPath('a b', 'access', null, { segmentEncoding: 'verbatim' })).toBe('/studio/a b/access'); + }); + + it('appends a query, a verbatim search and a fragment, and nothing for empty ones', () => { + expect(studioPath('crm', 'data', null, { query: 'changes=review' })).toBe('/studio/crm/data?changes=review'); + expect(studioPath('crm', 'data', null, { query: new URLSearchParams({ a: 'x y' }) })).toBe('/studio/crm/data?a=x+y'); + expect(studioPath('crm', 'data', null, { query: '' })).toBe('/studio/crm/data'); + expect(studioPath('crm', 'data', null, { query: new URLSearchParams() })).toBe('/studio/crm/data'); + expect(studioPath('crm', 'data', null, { search: '?surface=object%3Aa' })).toBe('/studio/crm/data?surface=object%3Aa'); + expect(studioPath('crm', 'data', null, { search: '' })).toBe('/studio/crm/data'); + expect(studioPath(null, null, null, { query: 'new=package', hash: '#x' })).toBe('/studio?new=package#x'); + }); +}); + +describe("today's addresses, byte for byte", () => { + it('landing, package, pillar, home', () => { + expect(studioLandingPath()).toBe('/studio'); + expect(STUDIO_NEW_PACKAGE_PATH).toBe('/studio?new=package'); + expect(studioPackagePath('com.acme.crm')).toBe('/studio/com.acme.crm'); + expect(studioPillarPath('com.acme.crm', 'automations')).toBe('/studio/com.acme.crm/automations'); + expect(studioHomePath('com.acme.crm')).toBe('/studio/com.acme.crm/data'); + }); + + it('the three `?surface=` spellings stay distinct', () => { + const item = { type: 'object', name: "o'k (x)" }; + expect(studioSurfaceQuery(item)).toBe("surface=object%3Ao'k%20(x)"); + expect(studioSurfaceQuery(item, 'name')).toBe("surface=object:o'k%20(x)"); + expect(studioSurfaceQuery(item, 'form')).toBe('surface=object%3Ao%27k+%28x%29'); + expect(studioSurfaceQuery({ type: 'object', name: 'a' }, 'form', { action: 'approve' })).toBe( + 'surface=object%3Aa&action=approve', + ); + expect(studioSurfaceQuery({ type: 'object', name: 'a' }, 'component', { view: 'a.all' })).toBe( + 'surface=object%3Aa&view=a.all', + ); + }); + + it('an item opens its pillar today when the table names one, else its "All metadata" page', () => { + expect(studioItemPath('crm', 'object', 'account')).toBe('/studio/crm/data?surface=object%3Aaccount'); + expect(studioItemPath('crm', 'flow', 'notify')).toBe('/studio/crm/automations?surface=flow%3Anotify'); + expect(studioItemPath('crm', 'permission', 'admin')).toBe('/studio/crm/access?surface=permission%3Aadmin'); + expect(studioItemPath('crm', 'dashboard', 'sales')).toBe('/studio/crm/metadata/dashboard/sales'); + expect(studioItemPath('crm', 'action', 'approve')).toBe('/studio/crm/metadata/action/approve'); + // The app → Studio bridge's spelling. + expect(studioItemPath('crm', 'object', 'account', { spelling: 'name' })).toBe('/studio/crm/data?surface=object:account'); + // The switched-off action's spelling. + expect(studioItemPath('crm', 'object', 'account', { spelling: 'form', qualifiers: { action: 'approve' } })).toBe( + '/studio/crm/data?surface=object%3Aaccount&action=approve', + ); + // A name that is an Object.prototype member is not a pillar type. + expect(studioItemPath('crm', 'constructor', 'x')).toBe('/studio/crm/metadata/constructor/x'); + }); + + it('a pillar item at a verbatim segment', () => { + expect(studioPillarItemAddress('~org', 'automations', { type: 'flow', name: 'f' }, { segmentEncoding: 'verbatim' })).toBe( + '/studio/~org/automations?surface=flow%3Af', + ); + }); + + it('the "All metadata" area', () => { + expect(studioMetadataAreaRoot('~all')).toBe('/studio/~all/metadata'); + expect(studioMetadataAreaRoot('com.acme.crm')).toBe('/studio/com.acme.crm/metadata'); + expect(studioMetadataTypePath('crm', 'action')).toBe('/studio/crm/metadata/action'); + expect(studioMetadataItemAddress('crm', 'page', 'a b')).toBe('/studio/crm/metadata/page/a%20b'); + expect(studioMetadataAreaAddress('~all', '', { query: 'scope=environment' })).toBe('/studio/~all/metadata?scope=environment'); + }); + + it("the draft review links equal the server's, and the skill evals' literals", () => { + // `studioChangesReviewLink` / `studioItemReviewLink` in @objectstack/types + // are pinned to these same literals, as are the objectstack-mcp-build evals. + expect(studioChangesReviewPath('com.acme.crm')).toBe('/studio/com.acme.crm/data?changes=review'); + expect(studioItemReviewPath('com.acme.crm', 'flow', 'crm_lead_created_notify')).toBe( + '/studio/com.acme.crm/metadata/flow/crm_lead_created_notify?review=1', + ); + expect(studioItemReviewPath('com.acme.crm', 'dataset', 'crm_sales_metrics')).toBe( + '/studio/com.acme.crm/metadata/dataset/crm_sales_metrics?review=1', + ); + }); + + it('the repointed module builders keep their addresses', () => { + expect(studioOrgScopePath()).toBe('/studio/~org/automations'); + expect(studioOrgScopePath({ type: 'flow', name: 'a:b' })).toBe('/studio/~org/automations?surface=flow%3Aa%3Ab'); + expect(studioPillarItemPath('crm', 'access', { type: 'permission', name: 'p' })).toBe('/studio/crm/access?surface=permission%3Ap'); + expect(studioMetadataItemPath('crm', { type: 'object', name: 'account' })).toBe('/studio/crm/metadata/object/account'); + expect( + areaItemPillarPath({ packageId: 'crm', type: 'object', name: 'account', search: new URLSearchParams() }), + ).toBe('/studio/crm/data?surface=object%3Aaccount'); + expect( + areaItemPillarPath({ packageId: 'crm', type: 'object', name: 'account', search: new URLSearchParams('review=1') }), + ).toBeNull(); + }); +}); + +describe('the mapping table agrees with the code (objectstack#36895)', () => { + it("the area's pillar redirect and the item address read ONE type map", () => { + expect(AREA_PILLAR_FOR_TYPE).toBe(STUDIO_ITEM_PILLAR); + }); + + it('every item type the map names has its row, on the same pillar', () => { + for (const [type, pillar] of Object.entries(STUDIO_ITEM_PILLAR)) { + const row = STUDIO_ITEM_TYPES.find((r) => r.type === type); + expect(row, type).toBeDefined(); + expect(row?.pillar).toBe(pillar); + expect(row?.onMetadataAddress).toBe(`/studio//metadata/${type}/`); + } + }); + + it('every `?surface=` row instantiates to what the builder writes', () => { + for (const row of STUDIO_ITEM_TYPES) { + const [type, name] = row.surface.split(':'); + const value = name === '' ? 'n' : name; + expect(studioPillarItemAddress('p', row.pillar, { type, name: value })).toBe( + `/studio/p/${row.pillar}?surface=${encodeURIComponent(`${type}:${value}`)}`, + ); + } + }); + + it('the parameter rows name the keys the readers use', () => { + const keys = STUDIO_QUERY_PARAMS.map((row) => row.key); + expect(keys).toEqual([ + DESIGNER_SURFACE_PARAM, + DESIGNER_SURFACE_VIEW_PARAM, + DESIGNER_SURFACE_ACTION_PARAM, + DESIGNER_SURFACE_NAV_PARAM, + STUDIO_CHANGES_PARAM, + 'review', + 'package', + CATALOG_SCOPE_PARAM, + 'new', + ]); + expect(STUDIO_QUERY_PARAMS.find((row) => row.key === CATALOG_SCOPE_PARAM)?.values).toBe(ENVIRONMENT_SCOPE); + expect(STUDIO_QUERY_PARAMS.find((row) => row.key === STUDIO_CHANGES_PARAM)?.values).toBe(STUDIO_CHANGES_REVIEW); + }); + + it('the families are unique and name builders that exist', () => { + const ids = STUDIO_ADDRESS_FAMILIES.map((f) => f.id); + expect(new Set(ids).size).toBe(ids.length); + const builders = new Set([ + 'studioLandingPath', 'studioPackagePath', 'studioPillarPath', 'studioItemPath', 'studioOrgScopePath', + 'studioMetadataAreaRoot', 'studioMetadataTypePath', 'studioMetadataItemAddress', 'studioChangesReviewPath', + 'studioItemReviewPath', 'retiredInterfacesTarget', + ]); + for (const family of STUDIO_ADDRESS_FAMILIES) expect(builders.has(family.builder), family.id).toBe(true); + }); + + it('the retired `/interfaces` redirect keeps exactly what the table marks', () => { + expect(STUDIO_RETIRED_INTERFACES_KEPT_PARAMS).toEqual([STUDIO_CHANGES_PARAM]); + expect(retiredInterfacesTarget('crm', '?surface=page%3Ahome&changes=review&nav=n1')).toBe('/studio/crm/data?changes=review'); + expect(retiredInterfacesTarget('crm', '?surface=page%3Ahome')).toBe('/studio/crm/data'); + }); +}); diff --git a/ui/packages/app-shell/src/views/studio-design/studioAddress.ts b/ui/packages/app-shell/src/views/studio-design/studioAddress.ts new file mode 100644 index 00000000000..90c076380c7 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/studioAddress.ts @@ -0,0 +1,313 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The one builder of Studio addresses (objectstack#36895, Studio redesign + * epic #36890). Every place that produces a `/studio...` URL calls a builder + * here; nothing else spells one by hand, and + * `studioAddress.guard.test.ts` refuses a hand-built one anywhere under `ui/`. + * + * ## Why one builder first + * + * The epic moves objects, flows and permission sets from their pillar + * addresses (`/studio//data?surface=object:`) to metadata + * addresses (`/studio//metadata//`). Today the "All + * metadata" area sends a pillar type back to its pillar + * (`areaItemPillarPath`, read through {@link STUDIO_ITEM_PILLAR}), so + * redirecting the pillar address to the metadata one first would make the two + * rules bounce off each other. With every producer on this builder, a designer + * card switches its type in ONE place, {@link STUDIO_ITEM_PILLAR}, in the same + * PR that ships its full-screen designer: the producers and the area's + * redirect move together, so there is never a loop. + * + * ## Today's addresses, byte for byte + * + * This module changes no address. The producers it replaced did not agree on + * how to spell a `?surface=` value, and each spelling is kept, named by + * {@link StudioSurfaceSpelling}, because a changed byte is a changed address + * (a bookmark, a test pin, a link an AI was handed). The mapping table + * (`studioAddressTable.ts`) lists every address family, every `?surface=` + * spelling and every parameter carried verbatim, and is what the designer + * cards switch from. + * + * ## The server's two addresses + * + * The draft door's review links (the CLI's `os meta register` and the MCP + * authoring tools) are built by `studioChangesReviewLink` and + * `studioItemReviewLink` in `@objectstack/types`, which both server packages + * already depend on; the Console does not depend on that package, so + * {@link studioChangesReviewPath} and {@link studioItemReviewPath} are their + * Console halves, pinned to the same literals. + * + * Pure: no React, no router, so every rule is pinned without a render. + */ + +import { DESIGNER_SURFACE_PARAM, formatSurfaceParam } from '../metadata-admin/nav-selection.js'; + +// --------------------------------------------------------------------------- +// The vocabulary +// --------------------------------------------------------------------------- + +/** The root every Studio address starts with. */ +export const STUDIO_ROOT_PATH = '/studio'; + +/** The pillar a package's Studio opens on: its home. */ +export const STUDIO_HOME_PILLAR = 'data'; + +/** The "All metadata" area's route segment, beside the pillars' (`/studio//metadata`). */ +export const STUDIO_METADATA_AREA = 'metadata'; + +/** The reserved `/studio/` value for the "All metadata" area's cross-package leg. */ +export const STUDIO_ALL_PACKAGES_SEGMENT = '~all'; + +/** The reserved `/studio/` value for the package-less scope (`studioScope.ts`). */ +export const STUDIO_ORG_SCOPE_SEGMENT = '~org'; + +/** The one pillar the package-less scope offers. */ +export const STUDIO_ORG_SCOPE_PILLAR = 'automations'; + +/** The retired Interfaces pillar's route segment (objectstack#36502). No pillar answers to it any more. */ +export const RETIRED_INTERFACES_SEGMENT = 'interfaces'; + +/** The query key that opens Studio's Changes drawer (`studioChangesLink.ts`). */ +export const STUDIO_CHANGES_PARAM = 'changes'; + +/** The one {@link STUDIO_CHANGES_PARAM} value the surface acts on: review the pending drafts. */ +export const STUDIO_CHANGES_REVIEW = 'review'; + +/** The query key that opens an item page's draft review in the "All metadata" area. */ +export const STUDIO_ITEM_REVIEW_PARAM = 'review'; + +/** The one {@link STUDIO_ITEM_REVIEW_PARAM} value the item page acts on. */ +export const STUDIO_ITEM_REVIEW_VALUE = '1'; + +/** The pillar keys (`StudioDesignSurface`'s `PILLARS`). */ +export type StudioPillarKey = 'data' | 'automations' | 'access'; + +/** + * ADR-0146 D1 — "A pillar type opened from the directory opens its pillar". + * Where an item of each type opens TODAY: the pillar that designs it. Every + * type not listed opens the area's generic item page. + * + * ⭐ This is the per-type switch of the Studio redesign. A designer card that + * moves a type to its metadata address deletes that type's row here, in the + * PR that ships the designer: every producer that calls + * {@link studioItemPath}, and the area's own pillar redirect + * (`areaItemPillarPath`), then open the metadata address together. + * + * objectstack#36502 — pages, dashboards, reports and views have no pillar + * since the Interfaces pillar retired. + */ +export const STUDIO_ITEM_PILLAR: Readonly> = Object.freeze({ + object: 'data', + flow: 'automations', + permission: 'access', +}); + +/** The pillar an item of `type` opens in today, or `null` when it opens the area's generic item page. */ +export function studioItemPillar(type: string): StudioPillarKey | null { + return Object.prototype.hasOwnProperty.call(STUDIO_ITEM_PILLAR, type) ? STUDIO_ITEM_PILLAR[type] : null; +} + +// --------------------------------------------------------------------------- +// The one path builder +// --------------------------------------------------------------------------- + +/** How the first segment after `/studio` is written. */ +export type StudioSegmentEncoding = + /** `encodeURIComponent` — what every package-id producer does. The default. */ + | 'component' + /** As given: the segment is already in its URL form (a route param read back, a reserved `~` segment). */ + | 'verbatim'; + +/** The parts after the path. */ +export interface StudioPathOptions { + /** The query without its `?`, or a `URLSearchParams` (serialised as `toString()` does). Empty adds nothing. */ + query?: string | URLSearchParams | null; + /** + * A search string appended exactly as given, `?` included (`location.search`). + * For a producer that carries the current query over untouched; not with `query`. + */ + search?: string | null; + /** The fragment, `#` included. */ + hash?: string | null; + /** How the first segment is written. Default `'component'`. */ + segmentEncoding?: StudioSegmentEncoding; +} + +/** + * A Studio address: `/studio`, then the scope segment (a package id, `~org`, + * `~all`), then a section (a pillar key, `metadata`), then a rest path already + * in its URL form (`object/account`), then the query and the fragment. Every + * part is optional from the right; a part after an absent one is not allowed + * (a section names nothing without its scope). + * + * An empty segment counts as absent and drops the section and rest with it, so + * `studioHomePath('')` is `/studio`, not `/studio//data`. Callers guard a + * missing package themselves; the builder does not stand in for that check. + */ +export function studioPath( + segment?: string | null, + section?: string | null, + rest?: string | null, + options: StudioPathOptions = {}, +): string { + let path = STUDIO_ROOT_PATH; + if (segment) { + path += `/${options.segmentEncoding === 'verbatim' ? segment : encodeURIComponent(segment)}`; + if (section) { + path += `/${section}`; + if (rest) path += `/${rest}`; + } + } + const query = typeof options.query === 'string' ? options.query : options.query ? options.query.toString() : ''; + if (query) path += `?${query}`; + if (options.search) path += options.search; + if (options.hash) path += options.hash; + return path; +} + +// --------------------------------------------------------------------------- +// Landing, package, pillar +// --------------------------------------------------------------------------- + +/** The Studio landing, `/studio`, optionally with a query (`new=package`). */ +export function studioLandingPath(options: Omit = {}): string { + return studioPath(null, null, null, options); +} + +/** A package's Studio, `/studio/`: the route lands it on {@link STUDIO_HOME_PILLAR}. */ +export function studioPackagePath(packageId: string): string { + return studioPath(packageId); +} + +/** One pillar (or other section) of a scope, `/studio//`. */ +export function studioPillarPath(segment: string, pillar: string, options: StudioPathOptions = {}): string { + return studioPath(segment, pillar, null, options); +} + +/** A package's Studio home, `/studio//data`. */ +export function studioHomePath(packageId: string, options: StudioPathOptions = {}): string { + return studioPillarPath(packageId, STUDIO_HOME_PILLAR, options); +} + +// --------------------------------------------------------------------------- +// The `?surface=` deep link +// --------------------------------------------------------------------------- + +/** + * How a producer writes a `?surface=:` value. Three spellings + * reach the same surface today, and each is kept byte for byte: + * + * - `'component'`: the whole value through `encodeURIComponent`, + * `surface=object%3Aaccount`. The default; most producers. + * - `'name'`: the type and colon as written, the name through + * `encodeURIComponent`, `surface=object:account` (the app → Studio bridge, + * `appStudioObjectPath`). + * - `'form'`: `URLSearchParams` serialisation, with any qualifiers after + * it in the order given, `surface=object%3Aaccount&action=approve` + * (`switchedOffActionPath`). It differs from `'component'` for a space + * (`+`) and for `!'()~`. + */ +export type StudioSurfaceSpelling = 'component' | 'name' | 'form'; + +/** The `?surface=` query of one item, in one {@link StudioSurfaceSpelling}, with optional qualifiers (`action`, `view`, `nav`). */ +export function studioSurfaceQuery( + item: { type: string; name: string }, + spelling: StudioSurfaceSpelling = 'component', + qualifiers?: Readonly>, +): string { + if (spelling === 'form') { + return new URLSearchParams({ [DESIGNER_SURFACE_PARAM]: formatSurfaceParam(item), ...qualifiers }).toString(); + } + const value = + spelling === 'name' + ? `${item.type}:${encodeURIComponent(item.name)}` + : encodeURIComponent(formatSurfaceParam(item)); + let query = `${DESIGNER_SURFACE_PARAM}=${value}`; + for (const [key, qualifier] of Object.entries(qualifiers ?? {})) { + query += `&${encodeURIComponent(key)}=${encodeURIComponent(qualifier)}`; + } + return query; +} + +/** Options of an item address. */ +export interface StudioItemOptions { + /** How the `?surface=` value is written, when the item opens a pillar. Default `'component'`. */ + spelling?: StudioSurfaceSpelling; + /** Qualifiers after `?surface=`, when the item opens a pillar: `action`, `view`, `nav`. */ + qualifiers?: Readonly>; + /** How the scope segment is written. Default `'component'`. */ + segmentEncoding?: StudioSegmentEncoding; +} + +/** A pillar of a scope, opened on one item through its `?surface=` deep link. */ +export function studioPillarItemAddress( + segment: string, + pillar: string, + item: { type: string; name: string }, + options: StudioItemOptions = {}, +): string { + return studioPath(segment, pillar, null, { + query: studioSurfaceQuery(item, options.spelling, options.qualifiers), + segmentEncoding: options.segmentEncoding, + }); +} + +// --------------------------------------------------------------------------- +// The "All metadata" area +// --------------------------------------------------------------------------- + +/** The area's root of a scope, `/studio//metadata`. */ +export function studioMetadataAreaRoot(segment: string): string { + return studioPath(segment, STUDIO_METADATA_AREA); +} + +/** + * A path below the area's root, `rest` already in its URL form (`flow`, + * `object/account`, `''` for the root itself). + */ +export function studioMetadataAreaAddress(segment: string, rest: string, options: StudioPathOptions = {}): string { + return studioPath(segment, STUDIO_METADATA_AREA, rest, options); +} + +/** A type's list in the area, `/studio//metadata/`. */ +export function studioMetadataTypePath(segment: string, type: string): string { + return studioMetadataAreaAddress(segment, encodeURIComponent(type)); +} + +/** An item's generic page in the area, `/studio//metadata//`. */ +export function studioMetadataItemAddress(segment: string, type: string, name: string, options: StudioPathOptions = {}): string { + return studioMetadataAreaAddress(segment, `${encodeURIComponent(type)}/${encodeURIComponent(name)}`, options); +} + +// --------------------------------------------------------------------------- +// The item address — what the designer cards switch +// --------------------------------------------------------------------------- + +/** + * Where one item of a package opens today: its pillar on a `?surface=` deep + * link when {@link STUDIO_ITEM_PILLAR} names one for its type, otherwise its + * page in the "All metadata" area. `spelling` and `qualifiers` apply to the + * pillar address only. + */ +export function studioItemPath(packageId: string, type: string, name: string, options: StudioItemOptions = {}): string { + const pillar = studioItemPillar(type); + if (pillar) return studioPillarItemAddress(packageId, pillar, { type, name }, options); + return studioMetadataItemAddress(packageId, type, name, { segmentEncoding: options.segmentEncoding }); +} + +// --------------------------------------------------------------------------- +// The draft review links +// --------------------------------------------------------------------------- + +/** A package's Changes drawer, opened from outside its Studio: `/studio//data?changes=review`. */ +export function studioChangesReviewPath(packageId: string): string { + return studioHomePath(packageId, { query: `${STUDIO_CHANGES_PARAM}=${STUDIO_CHANGES_REVIEW}` }); +} + +/** An item's draft review in the area: `/studio//metadata//?review=1`. */ +export function studioItemReviewPath(packageId: string, type: string, name: string): string { + return studioMetadataItemAddress(packageId, type, name, { + query: `${STUDIO_ITEM_REVIEW_PARAM}=${STUDIO_ITEM_REVIEW_VALUE}`, + }); +} diff --git a/ui/packages/app-shell/src/views/studio-design/studioAddressTable.ts b/ui/packages/app-shell/src/views/studio-design/studioAddressTable.ts new file mode 100644 index 00000000000..c4730e3adb9 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/studioAddressTable.ts @@ -0,0 +1,264 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The Studio address mapping table (objectstack#36895, Studio redesign epic + * #36890): every address family Studio answers to today, every `?surface=` + * spelling, and every query parameter, with what each one becomes when a + * designer card moves its type to the metadata address. + * + * The builders are in `studioAddress.ts`; this is their map. It is data a + * card reads before it switches a type, and data the code reads where the + * table decides something: the retired `/interfaces` redirect keeps exactly + * the parameters this table marks as surviving it + * ({@link STUDIO_RETIRED_INTERFACES_KEPT_PARAMS}). + * + * ## How a designer card switches its type + * + * 1. Delete the type's row from `STUDIO_ITEM_PILLAR` (`studioAddress.ts`). + * Every producer calling `studioItemPath`, and the "All metadata" area's + * pillar redirect (`areaItemPillarPath`), then open the metadata address + * together, so the two never bounce. + * 2. Carry each qualifier its row below lists onto the metadata address, or + * drop it, as the row's `onMetadataAddress` says. + * 3. Add the redirect from the pillar address in that same PR. + * 4. Update the type's row here: `today` becomes the metadata address. + * + * `studioAddressTable.test.ts` holds each row's example equal to its + * builder's output, so the table cannot drift from the code. + */ + +import { DESIGNER_SURFACE_PARAM } from '../metadata-admin/nav-selection.js'; +import { CATALOG_SCOPE_PARAM, ENVIRONMENT_SCOPE } from '../metadata-admin/catalog-scope.js'; +import { + DESIGNER_SURFACE_ACTION_PARAM, + DESIGNER_SURFACE_NAV_PARAM, + DESIGNER_SURFACE_VIEW_PARAM, +} from './useSurfaceDeepLink.js'; +import { STUDIO_NEW_PACKAGE_VALUE, STUDIO_NEW_PARAM } from './studioNewPackage.js'; +import { + RETIRED_INTERFACES_SEGMENT, + STUDIO_CHANGES_PARAM, + STUDIO_CHANGES_REVIEW, + STUDIO_HOME_PILLAR, + STUDIO_ITEM_REVIEW_PARAM, + STUDIO_ITEM_REVIEW_VALUE, + type StudioPillarKey, + type StudioSurfaceSpelling, +} from './studioAddress.js'; + +// --------------------------------------------------------------------------- +// Address families +// --------------------------------------------------------------------------- + +/** One shape of Studio address, as it is today. */ +export interface StudioAddressFamily { + /** Stable id. */ + readonly id: string; + /** Today's shape; `<…>` marks a variable part. */ + readonly today: string; + /** The `studioAddress.ts` builder that produces it. */ + readonly builder: string; + /** What the shape is for. */ + readonly meaning: string; +} + +export const STUDIO_ADDRESS_FAMILIES: readonly StudioAddressFamily[] = Object.freeze([ + { id: 'landing', today: '/studio', builder: 'studioLandingPath', meaning: 'The front door: pick or create a writable package.' }, + { + id: 'landing-new-package', + today: `/studio?${STUDIO_NEW_PARAM}=${STUDIO_NEW_PACKAGE_VALUE}`, + builder: 'studioLandingPath', + meaning: 'The front door with its create-package dialog open.', + }, + { id: 'package', today: '/studio/', builder: 'studioPackagePath', meaning: `A package's Studio; the route lands it on its home pillar, \`${STUDIO_HOME_PILLAR}\`.` }, + { id: 'pillar', today: '/studio//', builder: 'studioPillarPath', meaning: 'One pillar of a package: data, automations or access.' }, + { + id: 'pillar-item', + today: `/studio//?${DESIGNER_SURFACE_PARAM}=:`, + builder: 'studioItemPath', + meaning: 'A pillar opened on one item. The family the designer cards move, one type at a time (STUDIO_ITEM_TYPES).', + }, + { id: 'org-scope', today: '/studio/~org/automations', builder: 'studioOrgScopePath', meaning: 'The package-less scope: the organization\'s own flows.' }, + { + id: 'org-scope-item', + today: `/studio/~org/automations?${DESIGNER_SURFACE_PARAM}=flow:`, + builder: 'studioOrgScopePath', + meaning: 'A package-less flow. It has no package, so no metadata address of a package; it moves with the flow designer card.', + }, + { id: 'area-root', today: '/studio//metadata', builder: 'studioMetadataAreaRoot', meaning: 'The "All metadata" area of a package, or across packages.' }, + { id: 'area-type', today: '/studio//metadata/', builder: 'studioMetadataTypePath', meaning: "A type's list in the area." }, + { + id: 'area-item', + today: '/studio//metadata//', + builder: 'studioMetadataItemAddress', + meaning: "An item's page in the area: the metadata address every type moves to.", + }, + { + id: 'changes-review', + today: `/studio//${STUDIO_HOME_PILLAR}?${STUDIO_CHANGES_PARAM}=${STUDIO_CHANGES_REVIEW}`, + builder: 'studioChangesReviewPath', + meaning: "A package's Changes drawer, opened from outside its Studio. The server's draft review link (studioChangesReviewLink in @objectstack/types) spells the same address.", + }, + { + id: 'item-review', + today: `/studio//metadata//?${STUDIO_ITEM_REVIEW_PARAM}=${STUDIO_ITEM_REVIEW_VALUE}`, + builder: 'studioItemReviewPath', + meaning: "An item's draft review. The server's draft review link (studioItemReviewLink in @objectstack/types) spells the same address.", + }, + { + id: 'retired-interfaces', + today: `/studio//${RETIRED_INTERFACES_SEGMENT}[?…]`, + builder: 'retiredInterfacesTarget', + meaning: `The retired Interfaces pillar (objectstack#36502). Redirects to the package's \`${STUDIO_HOME_PILLAR}\` pillar, keeping only STUDIO_RETIRED_INTERFACES_KEPT_PARAMS.`, + }, +]); + +// --------------------------------------------------------------------------- +// Item types: where each opens today, and what it switches to +// --------------------------------------------------------------------------- + +/** One `?surface=` type: the pillar it opens today and the metadata address it moves to. */ +export interface StudioItemTypeRow { + /** The `?surface=` type. */ + readonly type: string; + /** The pillar that opens it today. */ + readonly pillar: StudioPillarKey; + /** Today's `?surface=` value. */ + readonly surface: string; + /** The qualifiers that ride beside `?surface=` for this type today. */ + readonly qualifiers: readonly string[]; + /** The `?surface=` spellings producers write today (`StudioSurfaceSpelling`). */ + readonly spellings: readonly StudioSurfaceSpelling[]; + /** The metadata address it moves to, or `null` when it is a pillar page with no item of its own. */ + readonly onMetadataAddress: string | null; +} + +export const STUDIO_ITEM_TYPES: readonly StudioItemTypeRow[] = Object.freeze([ + { + type: 'object', + pillar: 'data', + surface: 'object:', + qualifiers: [DESIGNER_SURFACE_VIEW_PARAM, DESIGNER_SURFACE_ACTION_PARAM, DESIGNER_SURFACE_NAV_PARAM], + spellings: ['component', 'name', 'form'], + onMetadataAddress: '/studio//metadata/object/', + }, + { + type: 'flow', + pillar: 'automations', + surface: 'flow:', + qualifiers: [], + spellings: ['component'], + onMetadataAddress: '/studio//metadata/flow/', + }, + { + type: 'permission', + pillar: 'access', + surface: 'permission:', + qualifiers: [], + spellings: ['component'], + onMetadataAddress: '/studio//metadata/permission/', + }, + { + // The Access pillar's organization-wide defaults overview. Not a metadata + // item: the permission designer card decides where it lives. + type: 'owd', + pillar: 'access', + surface: 'owd:overview', + qualifiers: [], + spellings: ['component'], + onMetadataAddress: null, + }, +]); + +// --------------------------------------------------------------------------- +// Query parameters +// --------------------------------------------------------------------------- + +/** One query parameter a Studio address carries. */ +export interface StudioQueryParamRow { + readonly key: string; + /** The values it takes. */ + readonly values: string; + /** Where it is read, and what it means there. */ + readonly meaning: string; + /** + * What happens to it when an item moves to its metadata address: + * `verbatim` — carried as it is; `qualifier` — rides beside `?surface=`, and + * the designer card maps it onto its designer or drops it; `replaced` — the + * metadata address itself carries what it said. + */ + readonly onMetadataAddress: 'verbatim' | 'qualifier' | 'replaced'; + /** Whether the retired `/interfaces` redirect keeps it. */ + readonly keptOnRetiredInterfaces: boolean; +} + +export const STUDIO_QUERY_PARAMS: readonly StudioQueryParamRow[] = Object.freeze([ + { + key: DESIGNER_SURFACE_PARAM, + values: ':, owd:overview', + meaning: 'A pillar opened on one item (STUDIO_ITEM_TYPES).', + onMetadataAddress: 'replaced', + keptOnRetiredInterfaces: false, + }, + { + key: DESIGNER_SURFACE_VIEW_PARAM, + values: '.', + meaning: 'The list view an object surface shows (Data pillar).', + onMetadataAddress: 'qualifier', + keptOnRetiredInterfaces: false, + }, + { + key: DESIGNER_SURFACE_ACTION_PARAM, + values: '', + meaning: "An object surface opened on its Actions view at one action (Data pillar).", + onMetadataAddress: 'qualifier', + keptOnRetiredInterfaces: false, + }, + { + key: DESIGNER_SURFACE_NAV_PARAM, + values: '