@specdest/devkit 0.4.16 → 0.4.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,6 +31,7 @@ npx @specdest/devkit flow complete
31
31
 
32
32
  - `status` reads the cached canonical catalog and reports applicable/current/missing/outdated rules plus registered predefined packages. Use `--refresh` to refresh the catalog from GitHub and `--json` for machine-readable output.
33
33
  - `add <package>` applies or adopts a predefined package recipe. Package recipes use only three relationship primitives: `requires`, `conflicts`, and environment-selected `variants`. `requires` is evaluated against packages registered in Devkit state; conflicts and variant selection also consider packages physically detected in the project. Status/doctor report stale package state, while sync/check/rules refuse to run against invalid package metadata. The supported foundational packages are `vite`, `expo`, `supabase`, and `convex`. Additional predefined packages are `auth`, `multi-tenancy`, `abac`, `sentry`, `logging`, `payments`, `shadcn`, `tanstack-router`, `tanstack-query`, `tanstack-form`, `storybook`, `playwright`, `vitest`, `local-logging`, `firebase-hosting`, `zod`, `tailwind`, `husky`, `nps`, `oxlint`, `oxfmt`, and `stryker`. Create-or-adopt recipes include the foundations (`vite`, `expo`, `supabase`, `convex`) and deterministic self-contained tooling (`zod`, `vitest`, `oxlint`, `oxfmt`, `husky`, `nps`, `tanstack-form`, `playwright`, `stryker`). They create minimal local dependencies/configuration when absent, then run `pnpm install`; when an integration already exists they adopt it without rewriting project-owned application files. Runtime-wired or product-specific recipes remain adoption-only until Devkit has a deterministic, product-neutral installation contract. Recipes record the recipe version separately from any detected dependency version in `.spd/installed.json`; Devkit does not invent product-specific auth, tenancy, authorization, logging, or payment architecture. Generated/adopted application code remains project-owned. Package lifecycle is deliberately fire-and-forget: there is no package `remove` or `upgrade` command. Developers remove packages manually; to update a recipe, re-run `add <package>`. Re-adding applies only the current recipe and does not remove files/settings that existed only in an older recipe. See [`docs/package-model.md`](docs/package-model.md). Supabase creation also scaffolds the canonical guarded declarative production-release workflow; registering Supabase activates the corresponding database rule/checker for ongoing enforcement. When Devkit-created foundation packages resolve a supported stack, required canonical setup packages are installed automatically (for example Oxlint/Husky for React stack gates and NPS for Supabase database commands); adopted stacks remain non-invasive and report missing setup through canonical checks.
34
+ - `add admin-ui` adopts an established shared admin page system or creates project-owned shadcn-based admin source components without overwriting existing files. See [`docs/admin-ui.md`](docs/admin-ui.md).
34
35
  - `sync` refreshes the canonical catalog, downloads only missing rule-cache entries, installs missing applicable rules, and updates outdated ones.
35
36
  - `check` executes each distinct canonical checker implementation once from the local Devkit cache and projects that result onto every rule backed by that checker. Use `--refresh` to refresh the canonical catalog/checker cache first without reconciling project files. `--staged` resolves target paths/content from the Git index; `--files` supplies explicit project-relative paths. Repository-scoped checkers still run globally. Targeted checks are ephemeral and do not update `.spd/state.json`; only a full check records canonical project status.
36
37
  - `rules` loads AI-facing guidance without dumping the whole catalog. Use `--id <rule>`, `--category <category>`, `--failed`, or `--json`; with no selector it returns only rules marked `ai.load = "always"`.
@@ -1,5 +1,6 @@
1
1
  import { spawnSync } from 'node:child_process';
2
- import { existsSync } from 'node:fs';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { basename, resolve } from 'node:path';
3
4
  import { projectFromCwd } from "./supabase-local.js";
4
5
  const TOOLS = {
5
6
  device: 'agent-device',
@@ -13,7 +14,20 @@ const NPS_BIN_ENV = {
13
14
  };
14
15
  /** Forward unchanged arguments through Controller's queue, or its trusted NPS host context. */
15
16
  export function runHostAutomation(command, args, cwd = process.cwd(), invoke = spawnSync, gatewayExists = existsSync, env = process.env) {
16
- const project = projectFromCwd(cwd);
17
+ // Non-Supabase admin frontend: identity is used only to request access;
18
+ // Controller's root-owned allowlist still decides whether automation is authorized.
19
+ const adminManifest = resolve(cwd, 'package.json');
20
+ const isAdmin = basename(resolve(cwd)) === 'mycone-admin' &&
21
+ existsSync(adminManifest) &&
22
+ (() => {
23
+ try {
24
+ return JSON.parse(readFileSync(adminManifest, 'utf8')).name === 'mycone-admin';
25
+ }
26
+ catch {
27
+ return false;
28
+ }
29
+ })();
30
+ const project = projectFromCwd(cwd) ?? (isAdmin ? 'mycone-admin' : undefined);
17
31
  if (!project) {
18
32
  process.stderr.write('Controller project registration required.\n');
19
33
  return 2;
@@ -0,0 +1,46 @@
1
+ import type { ReactNode } from 'react';
2
+ import {
3
+ AlertDialog,
4
+ AlertDialogAction,
5
+ AlertDialogCancel,
6
+ AlertDialogContent,
7
+ AlertDialogDescription,
8
+ AlertDialogFooter,
9
+ AlertDialogHeader,
10
+ AlertDialogTitle,
11
+ AlertDialogTrigger,
12
+ } from '@/components/ui/alert-dialog';
13
+
14
+ type AdminConfirmDialogProps = {
15
+ trigger: ReactNode;
16
+ title: ReactNode;
17
+ description: ReactNode;
18
+ onConfirm: () => void;
19
+ confirmLabel?: string;
20
+ cancelLabel?: string;
21
+ };
22
+
23
+ export function AdminConfirmDialog({
24
+ trigger,
25
+ title,
26
+ description,
27
+ onConfirm,
28
+ confirmLabel = 'Confirm',
29
+ cancelLabel = 'Cancel',
30
+ }: AdminConfirmDialogProps) {
31
+ return (
32
+ <AlertDialog>
33
+ <AlertDialogTrigger asChild>{trigger}</AlertDialogTrigger>
34
+ <AlertDialogContent>
35
+ <AlertDialogHeader>
36
+ <AlertDialogTitle>{title}</AlertDialogTitle>
37
+ <AlertDialogDescription>{description}</AlertDialogDescription>
38
+ </AlertDialogHeader>
39
+ <AlertDialogFooter>
40
+ <AlertDialogCancel>{cancelLabel}</AlertDialogCancel>
41
+ <AlertDialogAction onClick={onConfirm}>{confirmLabel}</AlertDialogAction>
42
+ </AlertDialogFooter>
43
+ </AlertDialogContent>
44
+ </AlertDialog>
45
+ );
46
+ }
@@ -0,0 +1,49 @@
1
+ import type { ReactNode } from 'react';
2
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
3
+
4
+ export type AdminColumn<T> = {
5
+ id: string;
6
+ header: ReactNode;
7
+ cell: (row: T) => ReactNode;
8
+ };
9
+
10
+ type AdminDataTableProps<T> = {
11
+ columns: readonly AdminColumn<T>[];
12
+ rows: readonly T[];
13
+ getRowId: (row: T) => string;
14
+ empty?: ReactNode;
15
+ };
16
+
17
+ export function AdminDataTable<T>({
18
+ columns,
19
+ rows,
20
+ getRowId,
21
+ empty = 'No results',
22
+ }: AdminDataTableProps<T>) {
23
+ return (
24
+ <div className="w-full min-w-0 overflow-x-auto rounded-lg border">
25
+ <Table>
26
+ <TableHeader>
27
+ <TableRow>
28
+ {columns.map((column) => <TableHead key={column.id}>{column.header}</TableHead>)}
29
+ </TableRow>
30
+ </TableHeader>
31
+ <TableBody>
32
+ {rows.length === 0 ? (
33
+ <TableRow>
34
+ <TableCell colSpan={columns.length} className="h-24 text-center text-muted-foreground">
35
+ {empty}
36
+ </TableCell>
37
+ </TableRow>
38
+ ) : (
39
+ rows.map((row) => (
40
+ <TableRow key={getRowId(row)}>
41
+ {columns.map((column) => <TableCell key={column.id}>{column.cell(row)}</TableCell>)}
42
+ </TableRow>
43
+ ))
44
+ )}
45
+ </TableBody>
46
+ </Table>
47
+ </div>
48
+ );
49
+ }
@@ -0,0 +1,15 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ type AdminDetailLayoutProps = {
4
+ main: ReactNode;
5
+ aside?: ReactNode;
6
+ };
7
+
8
+ export function AdminDetailLayout({ main, aside }: AdminDetailLayoutProps) {
9
+ return (
10
+ <div className={aside ? 'grid min-w-0 gap-6 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]' : 'min-w-0'}>
11
+ <div className="min-w-0 space-y-6">{main}</div>
12
+ {aside ? <aside className="min-w-0 space-y-6">{aside}</aside> : null}
13
+ </div>
14
+ );
15
+ }
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ type AdminEmptyStateProps = {
4
+ title: ReactNode;
5
+ description?: ReactNode;
6
+ action?: ReactNode;
7
+ };
8
+
9
+ export function AdminEmptyState({ title, description, action }: AdminEmptyStateProps) {
10
+ return (
11
+ <div className="flex min-h-40 flex-col items-center justify-center gap-3 rounded-lg border p-6 text-center">
12
+ <p className="font-medium">{title}</p>
13
+ {description ? <p className="text-sm text-muted-foreground">{description}</p> : null}
14
+ {action}
15
+ </div>
16
+ );
17
+ }
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ type AdminFilterBarProps = {
4
+ children: ReactNode;
5
+ actions?: ReactNode;
6
+ label?: string;
7
+ };
8
+
9
+ export function AdminFilterBar({ children, actions, label = 'Filters' }: AdminFilterBarProps) {
10
+ return (
11
+ <section aria-label={label} className="flex flex-wrap items-end gap-3 rounded-lg border bg-card p-4">
12
+ <div className="flex min-w-0 flex-1 flex-wrap items-end gap-3">{children}</div>
13
+ {actions ? <div className="flex shrink-0 items-end gap-2">{actions}</div> : null}
14
+ </section>
15
+ );
16
+ }
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ type AdminFormLayoutProps = {
4
+ children: ReactNode;
5
+ aside?: ReactNode;
6
+ actions?: ReactNode;
7
+ };
8
+
9
+ export function AdminFormLayout({ children, aside, actions }: AdminFormLayoutProps) {
10
+ return (
11
+ <div className="space-y-6">
12
+ <div className={aside ? 'grid min-w-0 gap-6 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]' : 'min-w-0'}>
13
+ <div className="min-w-0 space-y-6">{children}</div>
14
+ {aside ? <aside className="min-w-0 space-y-6">{aside}</aside> : null}
15
+ </div>
16
+ {actions ? <div className="flex flex-wrap justify-end gap-2">{actions}</div> : null}
17
+ </div>
18
+ );
19
+ }
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ type AdminPageVariant = 'list' | 'detail' | 'form' | 'dashboard';
4
+
5
+ type AdminPageProps = {
6
+ variant: AdminPageVariant;
7
+ children: ReactNode;
8
+ };
9
+
10
+ const widths: Record<AdminPageVariant, string> = {
11
+ list: 'w-full',
12
+ detail: 'max-w-6xl',
13
+ form: 'max-w-3xl',
14
+ dashboard: 'w-full',
15
+ };
16
+
17
+ export function AdminPage({ variant, children }: AdminPageProps) {
18
+ return <div className={'mx-auto min-w-0 space-y-6 p-4 md:p-6 ' + widths[variant]}>{children}</div>;
19
+ }
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ type AdminPageHeaderProps = {
4
+ title: ReactNode;
5
+ description?: ReactNode;
6
+ actions?: ReactNode;
7
+ };
8
+
9
+ export function AdminPageHeader({ title, description, actions }: AdminPageHeaderProps) {
10
+ return (
11
+ <header className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
12
+ <div className="min-w-0 space-y-1">
13
+ <h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
14
+ {description ? <p className="text-sm text-muted-foreground">{description}</p> : null}
15
+ </div>
16
+ {actions ? <div className="flex shrink-0 flex-wrap gap-2">{actions}</div> : null}
17
+ </header>
18
+ );
19
+ }
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ type AdminPaginationProps = {
4
+ page: number;
5
+ totalPages: number;
6
+ previous?: ReactNode;
7
+ next?: ReactNode;
8
+ };
9
+
10
+ export function AdminPagination({ page, totalPages, previous, next }: AdminPaginationProps) {
11
+ return (
12
+ <nav aria-label="Pagination" className="flex flex-wrap items-center justify-between gap-3 rounded-lg border p-3">
13
+ <div className="min-w-0">{previous}</div>
14
+ <span className="text-sm text-muted-foreground" aria-live="polite">
15
+ Page {page} of {totalPages}
16
+ </span>
17
+ <div className="min-w-0">{next}</div>
18
+ </nav>
19
+ );
20
+ }
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from 'react';
2
+ import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar';
3
+
4
+ type AdminShellProps = {
5
+ sidebar: ReactNode;
6
+ header?: ReactNode;
7
+ children: ReactNode;
8
+ };
9
+
10
+ export function AdminShell({ sidebar, header, children }: AdminShellProps) {
11
+ return (
12
+ <SidebarProvider>
13
+ {sidebar}
14
+ <SidebarInset className="min-w-0">
15
+ {header}
16
+ <main className="min-w-0 flex-1">{children}</main>
17
+ </SidebarInset>
18
+ </SidebarProvider>
19
+ );
20
+ }
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from 'react';
2
+ import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader } from '@/components/ui/sidebar';
3
+
4
+ type AdminSidebarProps = {
5
+ navigation: ReactNode;
6
+ header?: ReactNode;
7
+ footer?: ReactNode;
8
+ };
9
+
10
+ export function AdminSidebar({ navigation, header, footer }: AdminSidebarProps) {
11
+ return (
12
+ <Sidebar>
13
+ {header ? <SidebarHeader>{header}</SidebarHeader> : null}
14
+ <SidebarContent>{navigation}</SidebarContent>
15
+ {footer ? <SidebarFooter>{footer}</SidebarFooter> : null}
16
+ </Sidebar>
17
+ );
18
+ }
@@ -0,0 +1,22 @@
1
+ import type { ReactNode } from 'react';
2
+ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
3
+
4
+ type AdminStatCardProps = {
5
+ label: ReactNode;
6
+ value: ReactNode;
7
+ description?: ReactNode;
8
+ };
9
+
10
+ export function AdminStatCard({ label, value, description }: AdminStatCardProps) {
11
+ return (
12
+ <Card>
13
+ <CardHeader>
14
+ <CardTitle className="text-sm font-medium text-muted-foreground">{label}</CardTitle>
15
+ </CardHeader>
16
+ <CardContent className="space-y-1">
17
+ <div className="text-2xl font-semibold tabular-nums">{value}</div>
18
+ {description ? <p className="text-sm text-muted-foreground">{description}</p> : null}
19
+ </CardContent>
20
+ </Card>
21
+ );
22
+ }
@@ -0,0 +1,2 @@
1
+ import type { PackageRecipe } from './types.ts';
2
+ export declare const adminUiRecipe: PackageRecipe;
@@ -0,0 +1,79 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { writeProjectFileIfMissing } from "./install.js";
4
+ import { pathExists } from "./project-signals.js";
5
+ const components = [
6
+ 'AdminShell',
7
+ 'AdminSidebar',
8
+ 'AdminPage',
9
+ 'AdminPageHeader',
10
+ 'AdminFilterBar',
11
+ 'AdminDataTable',
12
+ 'AdminPagination',
13
+ 'AdminFormLayout',
14
+ 'AdminDetailLayout',
15
+ 'AdminStatCard',
16
+ 'AdminEmptyState',
17
+ 'AdminConfirmDialog',
18
+ ];
19
+ const primitives = ['alert-dialog', 'card', 'sidebar', 'table'];
20
+ async function hasExistingAdminUi(root) {
21
+ // Existing project-owned shared admin page systems are adopted, not replaced.
22
+ return ((await pathExists(root, 'src/components/extra/admin-list-layout.tsx')) &&
23
+ (await pathExists(root, 'src/components/extra/admin-list-states.tsx')));
24
+ }
25
+ async function templateCount(root) {
26
+ const files = await Promise.all(components.map((name) => pathExists(root, 'src/components/admin/' + name + '.tsx')));
27
+ return files.filter(Boolean).length;
28
+ }
29
+ export const adminUiRecipe = {
30
+ id: 'admin-ui',
31
+ recipeVersion: '1.0.0',
32
+ role: 'feature',
33
+ requires: ['shadcn'],
34
+ async detect(root) {
35
+ if (await hasExistingAdminUi(root)) {
36
+ return { present: true, compatible: true, detectedVersion: null };
37
+ }
38
+ const count = await templateCount(root);
39
+ return {
40
+ present: count > 0,
41
+ compatible: count === components.length,
42
+ detectedVersion: null,
43
+ ...(count > 0 && count < components.length
44
+ ? {
45
+ reason: 'Admin UI has only ' + count + ' of ' + components.length + ' source components',
46
+ }
47
+ : {}),
48
+ };
49
+ },
50
+ async apply(root) {
51
+ if (await hasExistingAdminUi(root))
52
+ return { source: 'adopted' };
53
+ const rawConfig = JSON.parse(await readFile(join(root, 'components.json'), 'utf8'));
54
+ const aliases = rawConfig !== null && typeof rawConfig === 'object' && 'aliases' in rawConfig
55
+ ? rawConfig.aliases
56
+ : null;
57
+ if (aliases === null ||
58
+ typeof aliases !== 'object' ||
59
+ !('ui' in aliases) ||
60
+ aliases.ui !== '@/components/ui' ||
61
+ !('components' in aliases) ||
62
+ aliases.components !== '@/components') {
63
+ throw new Error('admin-ui requires shadcn aliases for @/components and @/components/ui');
64
+ }
65
+ const missing = (await Promise.all(primitives.map(async (name) => (await pathExists(root, 'src/components/ui/' + name + '.tsx')) ? null : name))).filter((name) => name !== null);
66
+ if (missing.length) {
67
+ throw new Error('admin-ui requires shadcn components: ' + missing.join(', ') + '. Add them first.');
68
+ }
69
+ // Read all inputs before changing the project; generated files become project-owned.
70
+ const templates = await Promise.all(components.map(async (name) => ({
71
+ name,
72
+ content: await readFile(new URL('./admin-ui-templates/' + name + '.tsx.template', import.meta.url), 'utf8'),
73
+ })));
74
+ for (const { name, content } of templates) {
75
+ await writeProjectFileIfMissing(root, 'src/components/admin/' + name + '.tsx', content);
76
+ }
77
+ return { source: 'installed' };
78
+ },
79
+ };
@@ -1,4 +1,5 @@
1
1
  import { abacRecipe } from "./abac.js";
2
+ import { adminUiRecipe } from "./admin-ui.js";
2
3
  import { authRecipe } from "./auth.js";
3
4
  import { convexRecipe } from "./convex.js";
4
5
  import { expoRecipe } from "./expo.js";
@@ -32,6 +33,7 @@ const RECIPES = new Map([
32
33
  [authRecipe.id, authRecipe],
33
34
  [multiTenancyRecipe.id, multiTenancyRecipe],
34
35
  [abacRecipe.id, abacRecipe],
36
+ [adminUiRecipe.id, adminUiRecipe],
35
37
  [sentryRecipe.id, sentryRecipe],
36
38
  [loggingRecipe.id, loggingRecipe],
37
39
  [paymentsRecipe.id, paymentsRecipe],
package/dist/npm/slack.js CHANGED
@@ -100,6 +100,7 @@ export async function sendSlackFiles(args, io = process, options = {}) {
100
100
  (await slackJson(transport, token, 'chat.postMessage', { channel, text: message })).ts;
101
101
  if (!parent)
102
102
  throw new Error('Slack did not return a thread timestamp');
103
+ const uploaded = [];
103
104
  for (const file of files) {
104
105
  const slot = await slackJson(transport, token, 'files.getUploadURLExternal', {
105
106
  filename: file.name,
@@ -114,13 +115,16 @@ export async function sendSlackFiles(args, io = process, options = {}) {
114
115
  });
115
116
  if (!response.ok)
116
117
  throw new Error(`Slack file upload HTTP ${response.status}`);
117
- await slackJson(transport, token, 'files.completeUploadExternal', {
118
- files: JSON.stringify([{ id: slot.file_id, title: file.name }]),
119
- channel_id: channel,
120
- thread_ts: parent,
121
- });
122
- io.stdout.write(`Uploaded ${file.name}\n`);
118
+ uploaded.push({ id: slot.file_id, title: file.name });
123
119
  }
120
+ await slackJson(transport, token, 'files.completeUploadExternal', {
121
+ files: JSON.stringify(uploaded),
122
+ channel_id: channel,
123
+ thread_ts: parent,
124
+ ...(thread ? { initial_comment: message } : {}),
125
+ });
126
+ for (const file of files)
127
+ io.stdout.write(`Uploaded ${file.name}\n`);
124
128
  io.stdout.write(`Slack thread: ${parent}\n`);
125
129
  return 0;
126
130
  }
package/dist/npm/state.js CHANGED
@@ -127,6 +127,17 @@ export async function ensureMetadataNamespace(projectRoot) {
127
127
  if (!canonicalExists && legacyExists)
128
128
  await rename(legacyRoot, canonicalRoot);
129
129
  }
130
+ async function readMetadataDirectory(projectRoot) {
131
+ const canonicalRoot = join(projectRoot, METADATA_DIRECTORY);
132
+ const legacyRoot = join(projectRoot, LEGACY_METADATA_DIRECTORY);
133
+ const [canonicalExists, legacyExists] = await Promise.all([
134
+ pathExists(canonicalRoot),
135
+ pathExists(legacyRoot),
136
+ ]);
137
+ if (canonicalExists && legacyExists)
138
+ await assertCompatibleNamespaces(projectRoot);
139
+ return !canonicalExists && legacyExists ? LEGACY_METADATA_DIRECTORY : METADATA_DIRECTORY;
140
+ }
130
141
  async function readJsonOrDefault(filePath, fallback) {
131
142
  try {
132
143
  return JSON.parse(await readFile(filePath, 'utf8'));
@@ -138,9 +149,18 @@ async function readJsonOrDefault(filePath, fallback) {
138
149
  }
139
150
  }
140
151
  async function writeJsonAtomic(filePath, value) {
152
+ const formatted = formatJsonState(value);
153
+ try {
154
+ if ((await readFile(filePath, 'utf8')) === formatted)
155
+ return;
156
+ }
157
+ catch (error) {
158
+ if (error.code !== 'ENOENT')
159
+ throw error;
160
+ }
141
161
  await mkdir(dirname(filePath), { recursive: true });
142
162
  const temp = `${filePath}.${process.pid}.tmp`;
143
- await writeFile(temp, formatJsonState(value), 'utf8');
163
+ await writeFile(temp, formatted, 'utf8');
144
164
  await rename(temp, filePath);
145
165
  }
146
166
  function validId(value) {
@@ -176,15 +196,13 @@ function validateChecksState(state) {
176
196
  return parsed;
177
197
  }
178
198
  export async function readInstalledState(projectRoot) {
179
- await ensureMetadataNamespace(projectRoot);
180
- const path = join(projectRoot, INSTALLED_RELATIVE_PATH);
199
+ const directory = await readMetadataDirectory(projectRoot);
200
+ const path = join(projectRoot, directory, 'installed.json');
181
201
  const raw = await readJsonOrDefault(path, EMPTY_INSTALLED);
182
202
  const state = validateInstalledState(raw);
183
203
  if (state.schemaVersion !== STATE_SCHEMA_VERSION)
184
204
  return state;
185
205
  const migrated = migrateInstalledStateRuleIds(state);
186
- if (JSON.stringify(migrated) !== JSON.stringify(state))
187
- await writeJsonAtomic(path, migrated);
188
206
  return validateInstalledState(migrated);
189
207
  }
190
208
  export async function writeInstalledState(projectRoot, state) {
@@ -192,11 +210,16 @@ export async function writeInstalledState(projectRoot, state) {
192
210
  validateInstalledState(state);
193
211
  if (state.schemaVersion !== STATE_SCHEMA_VERSION)
194
212
  throw new Error('Cannot write legacy .spd/installed.json state');
195
- await writeJsonAtomic(join(projectRoot, INSTALLED_RELATIVE_PATH), migrateInstalledStateRuleIds(state));
213
+ const path = join(projectRoot, INSTALLED_RELATIVE_PATH);
214
+ const next = migrateInstalledStateRuleIds(state);
215
+ const persisted = await readJsonOrDefault(path, null);
216
+ if (persisted !== null && JSON.stringify(persisted) === JSON.stringify(next))
217
+ return;
218
+ await writeJsonAtomic(path, next);
196
219
  }
197
220
  export async function readChecksState(projectRoot) {
198
- await ensureMetadataNamespace(projectRoot);
199
- const statePath = join(projectRoot, STATE_RELATIVE_PATH);
221
+ const directory = await readMetadataDirectory(projectRoot);
222
+ const statePath = join(projectRoot, directory, 'state.json');
200
223
  let state;
201
224
  try {
202
225
  state = JSON.parse(await readFile(statePath, 'utf8'));
@@ -204,14 +227,12 @@ export async function readChecksState(projectRoot) {
204
227
  catch (error) {
205
228
  if (error.code !== 'ENOENT')
206
229
  throw error;
207
- state = await readJsonOrDefault(join(projectRoot, LEGACY_CHECKS_RELATIVE_PATH), EMPTY_CHECKS);
230
+ state = await readJsonOrDefault(join(projectRoot, directory, 'checks.json'), EMPTY_CHECKS);
208
231
  }
209
232
  const validated = validateChecksState(state);
210
233
  if (validated.schemaVersion !== CHECKS_SCHEMA_VERSION)
211
234
  return validated;
212
235
  const migrated = migrateChecksStateRuleIds(validated);
213
- if (JSON.stringify(migrated) !== JSON.stringify(validated))
214
- await writeJsonAtomic(statePath, migrated);
215
236
  return validateChecksState(migrated);
216
237
  }
217
238
  export async function writeChecksState(projectRoot, state) {
@@ -219,10 +240,11 @@ export async function writeChecksState(projectRoot, state) {
219
240
  validateChecksState(state);
220
241
  if (state.schemaVersion !== CHECKS_SCHEMA_VERSION)
221
242
  throw new Error('Cannot write legacy .spd/state.json state');
222
- const current = migrateChecksStateRuleIds(await readJsonOrDefault(join(projectRoot, STATE_RELATIVE_PATH), {
243
+ const persisted = await readJsonOrDefault(join(projectRoot, STATE_RELATIVE_PATH), {
223
244
  schemaVersion: CHECKS_SCHEMA_VERSION,
224
245
  results: {},
225
- }));
246
+ });
247
+ const current = migrateChecksStateRuleIds(persisted);
226
248
  const next = migrateChecksStateRuleIds({
227
249
  ...current,
228
250
  ...state,
@@ -239,7 +261,9 @@ export async function writeChecksState(projectRoot, state) {
239
261
  }
240
262
  const { checkedAt: _previousCheckedAt, ...previousMeaningful } = current;
241
263
  const { checkedAt: _nextCheckedAt, ...nextMeaningful } = next;
242
- if (fileExists && JSON.stringify(previousMeaningful) === JSON.stringify(nextMeaningful))
264
+ if (fileExists &&
265
+ JSON.stringify(previousMeaningful) === JSON.stringify(nextMeaningful) &&
266
+ JSON.stringify(persisted) === JSON.stringify(current))
243
267
  return;
244
268
  await writeJsonAtomic(join(projectRoot, STATE_RELATIVE_PATH), next);
245
269
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specdest/devkit",
3
- "version": "0.4.16",
3
+ "version": "0.4.18",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "specdest": "dist/npm/cli.js"
@@ -37,7 +37,7 @@
37
37
  "rules:audit": "node scripts/generate-rule-audit.mjs --check",
38
38
  "rules:audit:write": "node scripts/generate-rule-audit.mjs",
39
39
  "typecheck:checkers": "node scripts/typecheck-checkers.mjs",
40
- "build": "node -e \"require('node:fs').rmSync('dist/npm',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
40
+ "build": "node -e \"require('node:fs').rmSync('dist/npm',{recursive:true,force:true})\" && tsc -p tsconfig.build.json && node scripts/copy-admin-ui-templates.mjs",
41
41
  "prepack": "pnpm run build",
42
42
  "format:check": "oxfmt --check src/*.ts",
43
43
  "format": "oxfmt --write src/*.ts"