anhedral 0.19.0 → 0.21.0

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.
Files changed (40) hide show
  1. package/README.md +11 -7
  2. package/dist/capability-catalog.d.ts +1 -1
  3. package/dist/capability-catalog.js +1 -1
  4. package/dist/capability-command.d.ts +8 -0
  5. package/dist/capability-command.js +3 -3
  6. package/dist/capability-editor.js +21 -1
  7. package/dist/cli-arguments.js +2 -0
  8. package/dist/cli-commands.js +4 -4
  9. package/dist/cli-errors.js +3 -5
  10. package/dist/command-schema.js +35 -39
  11. package/dist/completion.js +0 -3
  12. package/dist/credential-helper.d.ts +2 -0
  13. package/dist/credential-helper.js +44 -0
  14. package/dist/launch.js +4 -2
  15. package/dist/platform-state.d.ts +2 -1
  16. package/dist/platform-state.js +5 -4
  17. package/dist/platforms/tanstack.js +0 -3
  18. package/dist/registry/usage.js +2 -1
  19. package/dist/release-artifact.d.ts +18 -0
  20. package/dist/release-artifact.js +169 -0
  21. package/dist/stack-update.d.ts +39 -0
  22. package/dist/stack-update.js +346 -0
  23. package/dist/transaction.d.ts +1 -0
  24. package/dist/transaction.js +2 -0
  25. package/dist/version.d.ts +1 -1
  26. package/dist/version.js +1 -1
  27. package/docs/capabilities.md +1 -1
  28. package/docs/software-factory.md +29 -1
  29. package/docs/stack-standard.md +1 -1
  30. package/docs/ui.md +10 -13
  31. package/package.json +1 -4
  32. package/assets/ui/LICENSE.react-native-reusables +0 -21
  33. package/assets/ui/catalog.json +0 -603
  34. package/assets/ui/extensions/registry.json +0 -6
  35. package/dist/ui-catalog.d.ts +0 -24
  36. package/dist/ui-catalog.js +0 -15
  37. package/dist/ui-command.d.ts +0 -5
  38. package/dist/ui-command.js +0 -221
  39. package/dist/ui-project.d.ts +0 -24
  40. package/dist/ui-project.js +0 -112
@@ -1,221 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { MAX_PROJECT_JSON_BYTES, readBoundedFile } from './bounded-file.js';
3
- import path from 'node:path';
4
- import { stripVTControlCharacters } from 'node:util';
5
- import { spawn, spawnSync } from 'node:child_process';
6
- import { commandArguments, commandArgumentError } from './cli-arguments.js';
7
- import { resolveCommand } from './command.js';
8
- import { ANHEDRAL_STACK } from './capability-catalog.js';
9
- import { createReporter } from './cli-output.js';
10
- import { UI_CATALOG, resolveUiItems } from './ui-catalog.js';
11
- import { assertUiMetadataPaths, detectUiTargets, initializeUiMetadata, inspectUiTarget, } from './ui-project.js';
12
- function runUpstream(args, cwd) {
13
- const invocation = resolveCommand('pnpm', [
14
- 'dlx',
15
- `shadcn@${UI_CATALOG.shadcnCliVersion}`,
16
- ...args,
17
- ]);
18
- return new Promise((resolve, reject) => {
19
- const child = spawn(invocation.command, invocation.args, {
20
- cwd,
21
- shell: false,
22
- detached: process.platform !== 'win32',
23
- windowsHide: true,
24
- stdio: ['pipe', 'pipe', 'pipe'],
25
- env: { ...process.env, CI: '1', NO_COLOR: '1' },
26
- });
27
- let stdout = '', stderr = '', answered = 0, bytes = 0;
28
- const fail = (reason) => {
29
- clearTimeout(timer);
30
- if (child.pid) {
31
- if (process.platform === 'win32')
32
- spawnSync('taskkill', ['/pid', String(child.pid), '/T', '/F'], {
33
- shell: false,
34
- stdio: 'ignore',
35
- windowsHide: true,
36
- timeout: 5000,
37
- });
38
- else {
39
- try {
40
- process.kill(-child.pid, 'SIGKILL');
41
- }
42
- catch {
43
- child.kill();
44
- }
45
- }
46
- }
47
- reject(Error(`Upstream UI command failed in ${cwd}: ${reason}`));
48
- };
49
- const timer = setTimeout(() => fail('installer timed out; inspect consumer changes before retrying'), 120000);
50
- child.stdin.on('error', () => {
51
- /* Process exit can close stdin before its final answer. */
52
- });
53
- child.stdout.setEncoding('utf8');
54
- child.stderr.setEncoding('utf8');
55
- const receive = (chunk, stream) => {
56
- bytes += Buffer.byteLength(chunk);
57
- if (bytes > 4 * 1024 * 1024)
58
- return fail('installer output exceeded its bound');
59
- if (stream === 'stdout')
60
- stdout += chunk;
61
- else
62
- stderr += chunk;
63
- // shadcn --yes skips confirmation, not overwrite prompts. Reply to each
64
- // pinned CLI prompt when it appears; prefeeding stdin loses later answers.
65
- const visible = stripVTControlCharacters(stdout + stderr);
66
- const prompts = visible.match(/› \(y\/N\)/g)?.length ?? 0;
67
- while (answered < prompts) {
68
- answered++;
69
- child.stdin.write('n\r');
70
- }
71
- // prompts retains a stdin listener after confirmations. Close input only
72
- // after the pinned installer reports its completed file operations.
73
- if (answered && /(?:Created|Updated|Skipped) \d+ files?\b/.test(visible))
74
- child.stdin.end();
75
- };
76
- child.stdout.on('data', (chunk) => receive(chunk, 'stdout'));
77
- child.stderr.on('data', (chunk) => receive(chunk, 'stderr'));
78
- child.on('error', (error) => {
79
- clearTimeout(timer);
80
- reject(error);
81
- });
82
- child.on('close', (status) => {
83
- clearTimeout(timer);
84
- if (status !== 0)
85
- reject(Error(`Upstream UI command failed in ${cwd}: ${stderr.slice(-2000) || 'check the project configuration'}`));
86
- else
87
- resolve(stdout);
88
- });
89
- });
90
- }
91
- function assertAnhedralStackTarget(target) {
92
- const dependencies = { ...target.manifest.devDependencies, ...target.manifest.dependencies };
93
- if (target.platform !== 'web' || !dependencies['@tanstack/react-start'])
94
- throw commandArgumentError('ui', 'Anhedral UI requires the Anhedral Stack web foundation. Run anhedral init <directory>.');
95
- let root = target.root;
96
- for (;;) {
97
- const metadata = path.join(root, 'anhedral.json');
98
- if (existsSync(metadata)) {
99
- const project = JSON.parse(readBoundedFile(metadata, MAX_PROJECT_JSON_BYTES).toString('utf8'));
100
- if (project?.schemaVersion !== 1 ||
101
- project.setup?.stack !== ANHEDRAL_STACK.id ||
102
- project.composition?.contractVersion !== 2 ||
103
- project.composition?.foundation !== ANHEDRAL_STACK.foundation.id ||
104
- path.join(root, 'apps', 'web') !== target.root)
105
- throw commandArgumentError('ui', 'Select apps/web in an Anhedral Stack project. Run anhedral ui --help.');
106
- return;
107
- }
108
- if (existsSync(path.join(root, '.git')) || path.dirname(root) === root)
109
- break;
110
- root = path.dirname(root);
111
- }
112
- throw commandArgumentError('ui', 'No Anhedral Stack project found. Run anhedral init <directory>.');
113
- }
114
- /** Public UI surface: one Anhedral Stack web target, with no native install fallback. */
115
- export async function runAnhedralUiCommand(args, output, run = runUpstream) {
116
- return runUiCommand(args, output, run);
117
- }
118
- export async function runUiCommand(args, output, run = runUpstream) {
119
- if (args.some((arg) => /^--(?:native|all)(?:=|$)/.test(arg)))
120
- throw commandArgumentError('ui', 'Anhedral UI supports the Anhedral Stack web application only. Use --web or select apps/web with --cwd.');
121
- const parsed = commandArguments('ui', args);
122
- const [action, ...names] = parsed.positional;
123
- if (!['init', 'add', 'list', 'diff', 'doctor'].includes(action))
124
- throw commandArgumentError('ui', 'Choose ui init, add, list, diff or doctor.');
125
- if (['add', 'diff'].includes(action) ? !names.length || names.length > 50 : names.length > 0)
126
- throw commandArgumentError('ui', 'Supply component names only for add/diff (at most 50).');
127
- const selector = 'web';
128
- let result;
129
- if (action === 'list') {
130
- result = {
131
- catalogRevision: UI_CATALOG.revision,
132
- ...{ platform: 'web' },
133
- components: UI_CATALOG.components
134
- .filter((item) => item[selector])
135
- .map((item) => ({ name: item.name, web: item.web })),
136
- };
137
- }
138
- else {
139
- const targets = detectUiTargets(process.cwd(), selector);
140
- for (const target of targets)
141
- assertAnhedralStackTarget(target);
142
- if (action === 'doctor') {
143
- const reports = targets.map(inspectUiTarget);
144
- result = {
145
- targets: reports,
146
- configurationReady: reports.every((report) => report.configurationReady),
147
- };
148
- if (!reports.every((report) => report.configurationReady))
149
- process.exitCode = 1;
150
- }
151
- else {
152
- // Preflight every target before invoking any installer, before source installation.
153
- const plans = targets.map((target) => {
154
- assertUiMetadataPaths(target.root);
155
- const report = inspectUiTarget(target);
156
- const configExists = existsSync(path.join(target.root, 'components.json'));
157
- const issues = report.issues;
158
- if ((action !== 'init' || configExists) && issues.length)
159
- throw Error(issues.join('\n') + '\n' + report.guide);
160
- const items = action === 'init' ? [] : resolveUiItems(names, target.platform);
161
- return {
162
- root: target.root,
163
- platform: target.platform,
164
- items,
165
- command: action === 'init'
166
- ? configExists
167
- ? []
168
- : ['init', '--base', 'base', '--defaults', '--no-reinstall', '--no-monorepo']
169
- : [
170
- 'add',
171
- ...items.map((item) => item.item),
172
- '--yes',
173
- ...(action === 'diff' ? ['--diff'] : []),
174
- ],
175
- };
176
- });
177
- if (!parsed.has('--dry-run')) {
178
- for (const plan of plans) {
179
- const vendorOutput = plan.command.length ? await run(plan.command, plan.root) : '';
180
- if (action === 'init' || action === 'add')
181
- initializeUiMetadata(plan.root, plan.platform);
182
- Object.assign(plan, { output: vendorOutput });
183
- }
184
- }
185
- result = {
186
- action,
187
- dryRun: parsed.has('--dry-run'),
188
- installer: `shadcn@${UI_CATALOG.shadcnCliVersion}`,
189
- targets: plans,
190
- };
191
- }
192
- }
193
- createReporter(output, () => action === 'list'
194
- ? UI_CATALOG.components
195
- .filter((item) => item[selector])
196
- .map((item) => `${item.name}\tshadcn`)
197
- .join('\n')
198
- : action === 'doctor'
199
- ? result.targets
200
- .map((report) => [
201
- `${report.platform}: ${report.configurationReady ? 'configuration ready' : 'setup needed'} (${report.root})`,
202
- ...report.issues,
203
- 'Runtime acceptance: not evaluated.',
204
- ].join('\n'))
205
- .join('\n\n')
206
- : result.targets
207
- .map((target) => [
208
- `${action}${parsed.has('--dry-run') ? ' (dry run)' : ''}: ${target.platform} (${target.root})`,
209
- ...(parsed.has('--dry-run')
210
- ? [
211
- target.command.length
212
- ? `shadcn@${UI_CATALOG.shadcnCliVersion} ${target.command.join(' ')}`
213
- : 'Validate existing configuration; initialize metadata and attribution if absent.',
214
- ]
215
- : []),
216
- target.output?.trim() ?? '',
217
- ]
218
- .filter(Boolean)
219
- .join('\n'))
220
- .join('\n\n')).result(result);
221
- }
@@ -1,24 +0,0 @@
1
- import { type UiPlatform } from './ui-catalog.js';
2
- type Manifest = {
3
- dependencies?: Record<string, string>;
4
- devDependencies?: Record<string, string>;
5
- };
6
- export interface UiTarget {
7
- root: string;
8
- platform: UiPlatform;
9
- manifest: Manifest;
10
- }
11
- export declare function detectUiTargets(cwd: string, selector?: UiPlatform): UiTarget[];
12
- export declare function inspectUiTarget(target: UiTarget): {
13
- root: string;
14
- platform: "web";
15
- configurationReady: boolean;
16
- issues: string[];
17
- runtimeAcceptance: string;
18
- guide: string;
19
- };
20
- /** Check CLI-owned destinations before upstream or attribution writes. */
21
- export declare function assertUiMetadataPaths(root: string): void;
22
- /** New metadata and attribution only; never overwrite consumer-owned files. */
23
- export declare function initializeUiMetadata(root: string, platform: UiPlatform): void;
24
- export {};
@@ -1,112 +0,0 @@
1
- import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from './bounded-file.js';
2
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync, } from 'node:fs';
3
- import path from 'node:path';
4
- import { UI_CATALOG } from './ui-catalog.js';
5
- // Consumer JSON links remain supported; the resolved target must be a bounded regular file.
6
- function readUiJson(file) {
7
- return JSON.parse(readBoundedFile(realpathSync(file), MAX_PROJECT_JSON_BYTES).toString('utf8'));
8
- }
9
- export function detectUiTargets(cwd, selector) {
10
- let root = realpathSync(cwd);
11
- let targets = [];
12
- function inspect(directory) {
13
- const file = path.join(directory, 'package.json');
14
- if (!existsSync(file))
15
- return;
16
- const manifest = readUiJson(file);
17
- const dependencies = { ...manifest.devDependencies, ...manifest.dependencies };
18
- if (dependencies['@tanstack/react-start'])
19
- targets.push({ root: directory, platform: 'web', manifest });
20
- }
21
- for (;;) {
22
- inspect(root);
23
- if (!targets.length && existsSync(path.join(root, 'apps'))) {
24
- for (const entry of readdirSync(path.join(root, 'apps'), { withFileTypes: true }))
25
- if (entry.isDirectory() && !entry.isSymbolicLink())
26
- inspect(path.join(root, 'apps', entry.name));
27
- }
28
- if (targets.length || existsSync(path.join(root, '.git')))
29
- break;
30
- const parent = path.dirname(root);
31
- if (parent === root)
32
- break;
33
- root = parent;
34
- }
35
- if (selector)
36
- targets = targets.filter((target) => target.platform === selector);
37
- if (!targets.length)
38
- throw Error('No Anhedral Stack TanStack Start application found. Use --cwd to select apps/web.');
39
- if (targets.length > 1)
40
- throw Error('Multiple web applications found. Use --cwd to select apps/web.');
41
- if (new Set(targets.map((target) => target.root)).size !== targets.length)
42
- throw Error('UI application directories must be distinct.');
43
- return targets;
44
- }
45
- export function inspectUiTarget(target) {
46
- const issues = [];
47
- const file = path.join(target.root, 'components.json');
48
- const config = existsSync(file) ? readUiJson(file) : null;
49
- if (!config)
50
- issues.push('Missing components.json. Run anhedral ui init for this application.');
51
- if (config && (!config.aliases?.ui || !config.aliases?.utils || !config.tailwind?.css))
52
- issues.push('components.json needs UI/utils aliases and a Tailwind CSS entry.');
53
- const marker = path.join(target.root, '.anhedral-ui.json');
54
- if (existsSync(marker) && readUiJson(marker).platform !== target.platform)
55
- issues.push('Existing Anhedral UI configuration targets another platform.');
56
- return {
57
- root: target.root,
58
- platform: target.platform,
59
- configurationReady: issues.length === 0,
60
- issues,
61
- runtimeAcceptance: 'not evaluated',
62
- guide: 'https://ui.shadcn.com/docs/installation/tanstack',
63
- };
64
- }
65
- /** Check CLI-owned destinations before upstream or attribution writes. */
66
- export function assertUiMetadataPaths(root) {
67
- for (const [relative, directory] of [
68
- ['.anhedral-ui.json', false],
69
- ['ANHEDRAL_UI_LICENSES', true],
70
- ['ANHEDRAL_UI_LICENSES/LICENSE.shadcn', false],
71
- ['ANHEDRAL_UI_LICENSES/LICENSE.react-native-reusables', false],
72
- ]) {
73
- let info;
74
- try {
75
- info = lstatSync(path.join(root, relative));
76
- }
77
- catch (error) {
78
- if (error.code === 'ENOENT')
79
- continue;
80
- throw error;
81
- }
82
- if (info.isSymbolicLink() || (directory ? !info.isDirectory() : !info.isFile()))
83
- throw Error(`Unsafe UI metadata path: ${relative}. Preserve it and reconcile before installing.`);
84
- }
85
- }
86
- /** New metadata and attribution only; never overwrite consumer-owned files. */
87
- export function initializeUiMetadata(root, platform) {
88
- assertUiMetadataPaths(root);
89
- const file = path.join(root, '.anhedral-ui.json');
90
- if (existsSync(file)) {
91
- const existing = readUiJson(file);
92
- if (existing.platform !== platform)
93
- throw Error('Existing Anhedral UI configuration targets another platform.');
94
- }
95
- else
96
- writeFileSync(file, JSON.stringify({
97
- schemaVersion: 1,
98
- platform,
99
- catalogRevision: UI_CATALOG.revision,
100
- sourceOwned: true,
101
- automaticUpdates: false,
102
- }, null, 2) + '\n', { flag: 'wx' });
103
- const licenses = path.join(root, 'ANHEDRAL_UI_LICENSES');
104
- mkdirSync(licenses, { recursive: true });
105
- for (const name of ['LICENSE.shadcn']) {
106
- const destination = path.join(licenses, name);
107
- if (!existsSync(destination))
108
- writeFileSync(destination, readFileSync(new URL(`../assets/ui/${name}`, import.meta.url)), {
109
- flag: 'wx',
110
- });
111
- }
112
- }