anhedral 0.16.0 → 0.18.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.
- package/README.md +42 -20
- package/assets/contracts/LICENSE +201 -0
- package/assets/contracts/LICENSE.environment +201 -0
- package/assets/contracts/LICENSE.operations +201 -0
- package/assets/contracts/deployment-provenance.json +15 -0
- package/assets/contracts/environment-provenance.json +11 -0
- package/assets/contracts/operations-provenance.json +11 -0
- package/assets/launch/application.server.ts.txt +13 -0
- package/assets/launch/auth-client.ts.txt +4 -0
- package/assets/launch/home.tsx.txt +20 -0
- package/assets/launch/minimal-application.server.ts.txt +5 -0
- package/assets/launch/minimal-server.ts.txt +7 -0
- package/assets/launch/request-context.ts.txt +3 -0
- package/assets/launch/root.tsx.txt +27 -0
- package/assets/launch/router.tsx.txt +21 -0
- package/assets/launch/server.ts.txt +13 -0
- package/assets/launch/sign-in.tsx.txt +53 -0
- package/assets/launch/styles.css.txt +19 -0
- package/assets/security/credential-patterns.d.mts +3 -0
- package/assets/security/credential-patterns.mjs +59 -0
- package/assets/stack/api-index.ts.txt +6 -1
- package/assets/stack/event-retention.sql.txt +10 -0
- package/assets/stack/stripe.ts.txt +30 -13
- package/assets/ui/UPSTREAM.json +1 -18
- package/dist/bin.js +55 -36
- package/dist/capabilities.d.ts +1 -1
- package/dist/capability-catalog.d.ts +44 -11
- package/dist/capability-catalog.js +96 -11
- package/dist/capability-command.d.ts +2 -2
- package/dist/capability-command.js +178 -27
- package/dist/capability-editor.js +6 -5
- package/dist/capability-recipes.js +54 -6
- package/dist/cli-arguments.d.ts +2 -0
- package/dist/cli-arguments.js +101 -50
- package/dist/cli-commands.d.ts +1 -1
- package/dist/cli-commands.js +30 -6
- package/dist/cli-errors.d.ts +18 -0
- package/dist/cli-errors.js +63 -0
- package/dist/cli-output.d.ts +22 -0
- package/dist/cli-output.js +42 -7
- package/dist/command-runner.d.ts +1 -0
- package/dist/command-runner.js +88 -0
- package/dist/command-schema.d.ts +16 -0
- package/dist/command-schema.js +390 -21
- package/dist/completion.d.ts +2 -0
- package/dist/completion.js +201 -0
- package/dist/composition.d.ts +35 -0
- package/dist/composition.js +28 -0
- package/dist/contracts/cli-transport.d.ts +217 -0
- package/dist/contracts/cli-transport.js +167 -0
- package/dist/contracts/deployment.d.ts +282 -0
- package/dist/contracts/deployment.js +234 -0
- package/dist/contracts/environment-file.d.ts +7 -0
- package/dist/contracts/environment-file.js +112 -0
- package/dist/contracts/environment-transport.d.ts +79 -0
- package/dist/contracts/environment-transport.js +110 -0
- package/dist/contracts/runtime-logs-transport.d.ts +127 -0
- package/dist/contracts/runtime-logs-transport.js +50 -0
- package/dist/contracts/source-bundle.d.ts +11 -0
- package/dist/contracts/source-bundle.js +197 -0
- package/dist/contracts/source-profile.d.ts +4 -0
- package/dist/contracts/source-profile.js +5 -0
- package/dist/contracts/staging-transport.d.ts +79 -0
- package/dist/contracts/staging-transport.js +43 -0
- package/dist/dependencies.d.ts +10 -4
- package/dist/dependencies.js +17 -54
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/launch.d.ts +21 -0
- package/dist/launch.js +250 -0
- package/dist/platform-command.d.ts +9 -0
- package/dist/platform-command.js +584 -0
- package/dist/platform-environment.d.ts +18 -0
- package/dist/platform-environment.js +257 -0
- package/dist/platform-operations.d.ts +26 -0
- package/dist/platform-operations.js +155 -0
- package/dist/platform-source.d.ts +8 -0
- package/dist/platform-source.js +111 -0
- package/dist/platform-state.d.ts +13 -0
- package/dist/platform-state.js +207 -0
- package/dist/platforms/tanstack.d.ts +8 -0
- package/dist/platforms/tanstack.js +155 -0
- package/dist/registry/options.js +34 -31
- package/dist/registry/resolve.js +2 -0
- package/dist/registry/usage.d.ts +4 -1
- package/dist/registry/usage.js +58 -4
- package/dist/scaffold/documentation.js +17 -48
- package/dist/scaffold/styling.d.ts +1 -1
- package/dist/scaffold/workspace.js +11 -7
- package/dist/stack-registry.d.ts +2 -4
- package/dist/stack-registry.js +1 -11
- package/dist/standard.js +21 -6
- package/dist/transaction.js +28 -3
- package/dist/ui-command.d.ts +4 -2
- package/dist/ui-command.js +79 -38
- package/dist/ui-project.d.ts +2 -0
- package/dist/ui-project.js +38 -8
- package/dist/util.js +40 -61
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/capabilities.md +22 -88
- package/docs/software-factory.md +189 -16
- package/docs/stack-standard.md +6 -18
- package/docs/ui.md +9 -22
- package/docs/verification.md +6 -1067
- package/package.json +33 -22
- package/assets/ui/native/_controls.tsx +0 -521
- package/assets/ui/native/_core.tsx +0 -118
- package/assets/ui/native/_data.tsx +0 -200
- package/assets/ui/native/_display.tsx +0 -453
- package/assets/ui/native/_feedback.tsx +0 -242
- package/assets/ui/native/_legacy-dialog.tsx +0 -38
- package/assets/ui/native/_motion.tsx +0 -520
- package/assets/ui/native/_overlay.tsx +0 -402
- package/assets/ui/native/_selection.tsx +0 -366
- package/assets/ui/native/accordion.tsx +0 -1
- package/assets/ui/native/alert-dialog.tsx +0 -11
- package/assets/ui/native/alert.tsx +0 -1
- package/assets/ui/native/aspect-ratio.tsx +0 -1
- package/assets/ui/native/attachment.tsx +0 -8
- package/assets/ui/native/avatar.tsx +0 -8
- package/assets/ui/native/badge.tsx +0 -1
- package/assets/ui/native/breadcrumb.tsx +0 -9
- package/assets/ui/native/bubble.tsx +0 -1
- package/assets/ui/native/button-group.tsx +0 -1
- package/assets/ui/native/button.tsx +0 -86
- package/assets/ui/native/calendar.tsx +0 -170
- package/assets/ui/native/card.tsx +0 -44
- package/assets/ui/native/carousel.tsx +0 -1
- package/assets/ui/native/chart.tsx +0 -193
- package/assets/ui/native/checkbox.tsx +0 -1
- package/assets/ui/native/code-block.tsx +0 -137
- package/assets/ui/native/collapsible.tsx +0 -1
- package/assets/ui/native/combobox.tsx +0 -1
- package/assets/ui/native/command.tsx +0 -11
- package/assets/ui/native/context-menu.tsx +0 -16
- package/assets/ui/native/data-table.tsx +0 -1
- package/assets/ui/native/date-picker.tsx +0 -43
- package/assets/ui/native/dialog.tsx +0 -15
- package/assets/ui/native/direction.tsx +0 -1
- package/assets/ui/native/drawer.tsx +0 -10
- package/assets/ui/native/dropdown-menu.tsx +0 -16
- package/assets/ui/native/empty.tsx +0 -8
- package/assets/ui/native/field.tsx +0 -13
- package/assets/ui/native/hover-card.tsx +0 -1
- package/assets/ui/native/input-group.tsx +0 -8
- package/assets/ui/native/input-otp.tsx +0 -1
- package/assets/ui/native/input.tsx +0 -28
- package/assets/ui/native/item.tsx +0 -12
- package/assets/ui/native/kbd.tsx +0 -1
- package/assets/ui/native/label.tsx +0 -4
- package/assets/ui/native/layout.tsx +0 -26
- package/assets/ui/native/marker.tsx +0 -1
- package/assets/ui/native/menubar.tsx +0 -17
- package/assets/ui/native/message-scroller.tsx +0 -6
- package/assets/ui/native/message.tsx +0 -10
- package/assets/ui/native/native-select.tsx +0 -1
- package/assets/ui/native/navigation-menu.tsx +0 -10
- package/assets/ui/native/pagination.tsx +0 -9
- package/assets/ui/native/popover.tsx +0 -1
- package/assets/ui/native/progress.tsx +0 -1
- package/assets/ui/native/questionnaire.tsx +0 -130
- package/assets/ui/native/radio-group.tsx +0 -1
- package/assets/ui/native/registry.json +0 -1103
- package/assets/ui/native/resizable.tsx +0 -1
- package/assets/ui/native/scroll-area.tsx +0 -1
- package/assets/ui/native/select.tsx +0 -11
- package/assets/ui/native/separator.tsx +0 -1
- package/assets/ui/native/sheet.tsx +0 -10
- package/assets/ui/native/sidebar.tsx +0 -22
- package/assets/ui/native/skeleton.tsx +0 -1
- package/assets/ui/native/slider.tsx +0 -1
- package/assets/ui/native/spinner.tsx +0 -1
- package/assets/ui/native/switch.tsx +0 -1
- package/assets/ui/native/table.tsx +0 -10
- package/assets/ui/native/tabs.tsx +0 -1
- package/assets/ui/native/text.tsx +0 -20
- package/assets/ui/native/textarea.tsx +0 -1
- package/assets/ui/native/theme-switcher.tsx +0 -22
- package/assets/ui/native/toast.tsx +0 -11
- package/assets/ui/native/toggle-group.tsx +0 -1
- package/assets/ui/native/toggle.tsx +0 -1
- package/assets/ui/native/tooltip.tsx +0 -1
- package/assets/ui/native/trace.tsx +0 -20
- package/assets/ui/native/typography.tsx +0 -15
- package/assets/ui/theme-storage.ts +0 -25
- package/assets/ui/theme.tsx +0 -66
- package/dist/platforms/mobile.d.ts +0 -2
- package/dist/platforms/mobile.js +0 -137
- package/dist/scaffold/expo-runtime.d.ts +0 -3
- package/dist/scaffold/expo-runtime.js +0 -42
- package/dist/scaffold/native-ui.d.ts +0 -2
- package/dist/scaffold/native-ui.js +0 -74
- package/docs/anhedral-stack.md +0 -7
- package/docs/native-ui.md +0 -102
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { existsSync, realpathSync, statSync, chmodSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { commandArguments, commandArgumentError } from './cli-arguments.js';
|
|
4
|
-
import {
|
|
4
|
+
import { createReporter } from './cli-output.js';
|
|
5
|
+
import { ANHEDRAL_STACK, PUBLIC_STACK_ADDITIONS, CAPABILITIES, CAPABILITY_IDS, capabilityOrder, } from './capability-catalog.js';
|
|
5
6
|
import { CapabilityEditor } from './capability-editor.js';
|
|
6
7
|
import { addCapabilityRecipe, composeCapabilities } from './capability-recipes.js';
|
|
7
|
-
import { PostCommitError, runStagedTransaction } from './transaction.js';
|
|
8
|
+
import { PostCommitError, runStagedTransaction, recoverInterruptedTransaction, } from './transaction.js';
|
|
8
9
|
import { put } from './scaffold/files.js';
|
|
9
10
|
import { execFile } from './util.js';
|
|
10
11
|
import { capabilityReferences } from './capability-references.js';
|
|
11
12
|
import { configureDependencyPatches } from './dependency-patches.js';
|
|
12
|
-
|
|
13
|
+
import { composeSourceProvenance } from './composition.js';
|
|
14
|
+
function projectRoot(cwd, allowRecovery = false) {
|
|
13
15
|
let root = realpathSync(cwd);
|
|
14
16
|
for (;;) {
|
|
15
|
-
if (existsSync(path.join(root, 'anhedral.json'))
|
|
17
|
+
if (existsSync(path.join(root, 'anhedral.json')) ||
|
|
18
|
+
(allowRecovery && existsSync(path.join(root, '.anhedral-journal.json'))))
|
|
16
19
|
return root;
|
|
17
20
|
if (existsSync(path.join(root, '.git')))
|
|
18
21
|
break;
|
|
@@ -40,27 +43,126 @@ function readState(e) {
|
|
|
40
43
|
throw Error(`Invalid capability state: ${id} requires ${parent}.`);
|
|
41
44
|
return { installed, managedFiles: state.managedFiles };
|
|
42
45
|
}
|
|
43
|
-
|
|
46
|
+
const archivedStack = 'codex/preserved-progressive-stack-20261102';
|
|
47
|
+
const publicGroups = {
|
|
48
|
+
backend: ['hono', 'database-auth'],
|
|
49
|
+
r2: ['r2'],
|
|
50
|
+
stripe: ['stripe'],
|
|
51
|
+
};
|
|
52
|
+
function publicScopeError(command = 'add') {
|
|
53
|
+
return commandArgumentError(command, `The active CLI edits only the Anhedral Stack. Preserved broader source workflows are on ${archivedStack}.`);
|
|
54
|
+
}
|
|
55
|
+
/** Identify the source before any recovery or source mutation. One missing manifest can be an interrupted add. */
|
|
56
|
+
function assertPublicWorkspace(root, allowRecovery = false, command = 'add') {
|
|
57
|
+
const editor = new CapabilityEditor(root, {});
|
|
58
|
+
const recovering = allowRecovery && existsSync(path.join(root, '.anhedral-journal.json'));
|
|
59
|
+
const hasWeb = existsSync(path.join(root, 'apps/web/package.json'));
|
|
60
|
+
const hasConfiguration = existsSync(path.join(root, 'anhedral.json'));
|
|
61
|
+
if (!hasWeb && !hasConfiguration)
|
|
62
|
+
throw publicScopeError(command);
|
|
63
|
+
if (hasWeb) {
|
|
64
|
+
const dependencies = editor.json('apps/web/package.json').dependencies;
|
|
65
|
+
if (!dependencies?.['@tanstack/react-start'] || dependencies.next)
|
|
66
|
+
throw publicScopeError(command);
|
|
67
|
+
}
|
|
68
|
+
else if (!recovering)
|
|
69
|
+
throw publicScopeError(command);
|
|
70
|
+
if (hasConfiguration) {
|
|
71
|
+
const configuration = editor.json('anhedral.json');
|
|
72
|
+
const composition = configuration.composition;
|
|
73
|
+
if (Array.isArray(configuration.capabilities?.installed) &&
|
|
74
|
+
configuration.capabilities.installed.some((id) => !['hono', 'database-auth', 'r2', 'stripe'].includes(id)))
|
|
75
|
+
throw publicScopeError(command);
|
|
76
|
+
if (composition?.contractVersion !== 2 || composition?.foundation !== 'tanstack-start')
|
|
77
|
+
throw publicScopeError(command);
|
|
78
|
+
}
|
|
79
|
+
else if (!recovering)
|
|
80
|
+
throw publicScopeError(command);
|
|
81
|
+
}
|
|
82
|
+
function publicStackState(root, state) {
|
|
83
|
+
if (state.installed.some((id) => !['hono', 'database-auth', 'r2', 'stripe'].includes(id)))
|
|
84
|
+
throw publicScopeError('stack');
|
|
85
|
+
const additions = PUBLIC_STACK_ADDITIONS.map((id) => {
|
|
86
|
+
const item = ANHEDRAL_STACK.additions[id];
|
|
87
|
+
const group = publicGroups[id];
|
|
88
|
+
const present = group.filter((capability) => state.installed.includes(capability));
|
|
89
|
+
const installed = present.length === group.length;
|
|
90
|
+
const missingFiles = present.length
|
|
91
|
+
? item.targets.filter((file) => !existsSync(path.join(root, file)))
|
|
92
|
+
: [];
|
|
93
|
+
const missingPrerequisites = item.requires.filter((required) => !publicGroups[required].every((capability) => state.installed.includes(capability)));
|
|
94
|
+
return {
|
|
95
|
+
id,
|
|
96
|
+
name: item.name,
|
|
97
|
+
sourceState: present.length
|
|
98
|
+
? installed && !missingFiles.length && !missingPrerequisites.length
|
|
99
|
+
? 'installed'
|
|
100
|
+
: 'incomplete'
|
|
101
|
+
: missingPrerequisites.length
|
|
102
|
+
? 'locked'
|
|
103
|
+
: 'available',
|
|
104
|
+
missingPrerequisites,
|
|
105
|
+
missingFiles,
|
|
106
|
+
activation: 'not verified',
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
const missingFiles = ANHEDRAL_STACK.foundation.targets.filter((file) => !existsSync(path.join(root, file)));
|
|
110
|
+
const foundationReady = !missingFiles.length;
|
|
111
|
+
return {
|
|
112
|
+
root,
|
|
113
|
+
stack: {
|
|
114
|
+
id: ANHEDRAL_STACK.id,
|
|
115
|
+
name: ANHEDRAL_STACK.name,
|
|
116
|
+
foundation: { ...ANHEDRAL_STACK.foundation, missingFiles },
|
|
117
|
+
},
|
|
118
|
+
foundationReady,
|
|
119
|
+
sourceReady: foundationReady && additions.every((item) => item.sourceState !== 'incomplete'),
|
|
120
|
+
additions,
|
|
121
|
+
runtimeAcceptance: 'not evaluated',
|
|
122
|
+
resourcesProvisionedByCli: false,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export async function runCapabilityCommand(command, args, output, run = execFile, scope = 'compatibility') {
|
|
44
126
|
const parsed = commandArguments(command, args);
|
|
127
|
+
if (scope === 'public' && command === 'add') {
|
|
128
|
+
const unsupported = parsed.positional.filter((id) => !PUBLIC_STACK_ADDITIONS.includes(id));
|
|
129
|
+
if (unsupported.length)
|
|
130
|
+
throw commandArgumentError('add', `Choose backend, r2 or stripe for the Anhedral Stack. Broader source recipes are preserved on ${archivedStack}.`);
|
|
131
|
+
}
|
|
45
132
|
let result;
|
|
46
133
|
if (command === 'stack') {
|
|
47
134
|
const [action, ...extra] = parsed.positional;
|
|
48
135
|
if (extra.length || !['list', 'status', 'doctor'].includes(action))
|
|
49
136
|
throw commandArgumentError('stack', 'Use stack list, status or doctor.');
|
|
50
137
|
if (action === 'list')
|
|
51
|
-
result =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
138
|
+
result =
|
|
139
|
+
scope === 'public'
|
|
140
|
+
? { stack: ANHEDRAL_STACK, resourcesProvisionedByCli: false }
|
|
141
|
+
: {
|
|
142
|
+
launchAdditions: {
|
|
143
|
+
backend: ['hono', 'database-auth'],
|
|
144
|
+
r2: ['r2'],
|
|
145
|
+
stripe: ['stripe'],
|
|
146
|
+
},
|
|
147
|
+
capabilities: CAPABILITY_IDS.map((id) => ({ id, ...CAPABILITIES[id] })),
|
|
148
|
+
provisioning: 'Separate from source installation',
|
|
149
|
+
};
|
|
55
150
|
else {
|
|
56
151
|
const root = projectRoot(process.cwd());
|
|
152
|
+
if (scope === 'public')
|
|
153
|
+
assertPublicWorkspace(root, false, 'stack');
|
|
57
154
|
const e = new CapabilityEditor(root, {});
|
|
58
155
|
const state = readState(e);
|
|
59
156
|
const capabilities = CAPABILITY_IDS.map((id) => {
|
|
60
157
|
const missing = CAPABILITIES[id].requires.filter((parent) => !state.installed.includes(parent));
|
|
61
158
|
const installed = state.installed.includes(id);
|
|
62
159
|
const missingFiles = installed
|
|
63
|
-
? CAPABILITIES[id].targets
|
|
160
|
+
? CAPABILITIES[id].targets
|
|
161
|
+
.map((target) => target === 'apps/web/lib/auth-client.ts' &&
|
|
162
|
+
e.json('apps/web/package.json').dependencies?.['@tanstack/react-start']
|
|
163
|
+
? 'apps/web/src/lib/auth-client.ts'
|
|
164
|
+
: target)
|
|
165
|
+
.filter((target) => !existsSync(path.join(root, target)))
|
|
64
166
|
: [];
|
|
65
167
|
return {
|
|
66
168
|
id,
|
|
@@ -79,7 +181,8 @@ export async function runCapabilityCommand(command, args, output, run = execFile
|
|
|
79
181
|
};
|
|
80
182
|
});
|
|
81
183
|
const foundationReady = existsSync(path.join(root, 'apps/web/package.json')) &&
|
|
82
|
-
!!e.json('apps/web/package.json').dependencies?.next
|
|
184
|
+
!!(e.json('apps/web/package.json').dependencies?.next ||
|
|
185
|
+
e.json('apps/web/package.json').dependencies?.['@tanstack/react-start']);
|
|
83
186
|
const sourceReady = foundationReady && capabilities.every((c) => c.sourceState !== 'incomplete');
|
|
84
187
|
result = {
|
|
85
188
|
root,
|
|
@@ -89,28 +192,55 @@ export async function runCapabilityCommand(command, args, output, run = execFile
|
|
|
89
192
|
runtimeAcceptance: 'not evaluated',
|
|
90
193
|
resourcesProvisionedByCli: false,
|
|
91
194
|
};
|
|
92
|
-
if (
|
|
195
|
+
if (scope === 'public')
|
|
196
|
+
result = publicStackState(root, state);
|
|
197
|
+
if (action === 'doctor' && !result.sourceReady)
|
|
93
198
|
process.exitCode = 1;
|
|
94
199
|
}
|
|
95
200
|
}
|
|
96
201
|
else {
|
|
97
202
|
if (!parsed.positional.length || parsed.positional.length > CAPABILITY_IDS.length)
|
|
98
203
|
throw commandArgumentError('add', 'Choose one or more capabilities from anhedral stack list.');
|
|
99
|
-
const root = projectRoot(process.cwd());
|
|
204
|
+
const root = projectRoot(process.cwd(), !parsed.has('--dry-run'));
|
|
205
|
+
if (scope === 'public')
|
|
206
|
+
assertPublicWorkspace(root, !parsed.has('--dry-run'));
|
|
207
|
+
if (!parsed.has('--dry-run') && existsSync(path.join(root, '.anhedral-journal.json')))
|
|
208
|
+
recoverInterruptedTransaction(root);
|
|
100
209
|
const e = new CapabilityEditor(root, {});
|
|
101
210
|
const state = readState(e);
|
|
211
|
+
if (scope === 'public') {
|
|
212
|
+
assertPublicWorkspace(root);
|
|
213
|
+
if (state.installed.some((id) => !['hono', 'database-auth', 'r2', 'stripe'].includes(id)))
|
|
214
|
+
throw publicScopeError();
|
|
215
|
+
}
|
|
102
216
|
Object.assign(e.managed, state.managedFiles);
|
|
103
217
|
const manifest = e.json('package.json');
|
|
104
218
|
if (typeof manifest.name !== 'string' || !manifest.name)
|
|
105
219
|
throw Error('The workspace needs a package name.');
|
|
106
|
-
if (!e.json('apps/web/package.json').dependencies?.next
|
|
107
|
-
|
|
220
|
+
if (!(e.json('apps/web/package.json').dependencies?.next ||
|
|
221
|
+
e.json('apps/web/package.json').dependencies?.['@tanstack/react-start']))
|
|
222
|
+
throw Error('An Anhedral Next.js or TanStack Start foundation is required.');
|
|
108
223
|
for (const id of state.installed)
|
|
109
|
-
for (const
|
|
224
|
+
for (const original of CAPABILITIES[id].targets) {
|
|
225
|
+
const target = original === 'apps/web/lib/auth-client.ts' &&
|
|
226
|
+
e.json('apps/web/package.json').dependencies?.['@tanstack/react-start']
|
|
227
|
+
? 'apps/web/src/lib/auth-client.ts'
|
|
228
|
+
: original;
|
|
110
229
|
if (!existsSync(path.join(root, target)))
|
|
111
230
|
throw Error(`Installed capability is incomplete: ${id} (${target}). Reconcile its source first.`);
|
|
112
|
-
|
|
231
|
+
}
|
|
232
|
+
if (scope === 'public' &&
|
|
233
|
+
!parsed.has('--with-dependencies') &&
|
|
234
|
+
!parsed.positional.includes('backend') &&
|
|
235
|
+
!(state.installed.includes('hono') && state.installed.includes('database-auth')) &&
|
|
236
|
+
parsed.positional.some((id) => id === 'r2' || id === 'stripe'))
|
|
237
|
+
throw commandArgumentError('add', 'Private storage and payments require backend. Run anhedral add backend first, or explicitly use --with-dependencies.');
|
|
238
|
+
const requested = [
|
|
239
|
+
...new Set(parsed.positional.flatMap((id) => (id === 'backend' ? ['hono', 'database-auth'] : [id]))),
|
|
240
|
+
];
|
|
241
|
+
const additions = capabilityOrder(requested, state.installed, parsed.has('--with-dependencies'));
|
|
113
242
|
const installed = [...state.installed, ...additions];
|
|
243
|
+
const composition = composeSourceProvenance(e.json('anhedral.json').composition, installed, additions);
|
|
114
244
|
for (const id of additions)
|
|
115
245
|
addCapabilityRecipe(e, id, manifest.name);
|
|
116
246
|
if (additions.length) {
|
|
@@ -118,6 +248,7 @@ export async function runCapabilityCommand(command, args, output, run = execFile
|
|
|
118
248
|
if (e.read(file) === null)
|
|
119
249
|
e.create(file, source);
|
|
120
250
|
composeCapabilities(e, installed);
|
|
251
|
+
e.set('anhedral.json', ['composition'], composition);
|
|
121
252
|
e.set('anhedral.json', ['capabilities'], {
|
|
122
253
|
schemaVersion: 1,
|
|
123
254
|
installed,
|
|
@@ -128,11 +259,26 @@ export async function runCapabilityCommand(command, args, output, run = execFile
|
|
|
128
259
|
const files = [...e.writes.keys()];
|
|
129
260
|
const plan = {
|
|
130
261
|
root,
|
|
131
|
-
added:
|
|
132
|
-
|
|
133
|
-
|
|
262
|
+
added: scope === 'public'
|
|
263
|
+
? PUBLIC_STACK_ADDITIONS.filter((id) => publicGroups[id].some((capability) => additions.includes(capability)))
|
|
264
|
+
: additions,
|
|
265
|
+
alreadyInstalled: parsed.positional.filter((id) => id === 'backend'
|
|
266
|
+
? state.installed.includes('hono') && state.installed.includes('database-auth')
|
|
267
|
+
: state.installed.includes(id)),
|
|
268
|
+
installed: scope === 'public'
|
|
269
|
+
? PUBLIC_STACK_ADDITIONS.filter((id) => publicGroups[id].every((capability) => installed.includes(capability)))
|
|
270
|
+
: installed,
|
|
134
271
|
files,
|
|
135
|
-
configuration:
|
|
272
|
+
configuration: scope === 'public'
|
|
273
|
+
? PUBLIC_STACK_ADDITIONS.filter((id) => publicGroups[id].some((capability) => additions.includes(capability))).map((id) => ({
|
|
274
|
+
id,
|
|
275
|
+
requirements: [
|
|
276
|
+
...new Set(publicGroups[id].flatMap((capability) => [
|
|
277
|
+
...CAPABILITIES[capability].configuration,
|
|
278
|
+
])),
|
|
279
|
+
],
|
|
280
|
+
}))
|
|
281
|
+
: additions.map((id) => ({ id, requirements: CAPABILITIES[id].configuration })),
|
|
136
282
|
dryRun: parsed.has('--dry-run'),
|
|
137
283
|
resourcesProvisionedByCli: false,
|
|
138
284
|
activation: 'not verified',
|
|
@@ -175,14 +321,19 @@ export async function runCapabilityCommand(command, args, output, run = execFile
|
|
|
175
321
|
dependenciesInstalled: !parsed.has('--dry-run') && !parsed.has('--skip-install'),
|
|
176
322
|
};
|
|
177
323
|
}
|
|
178
|
-
|
|
179
|
-
console.log(JSON.stringify(result, null, 2));
|
|
180
|
-
else if (!output.quiet) {
|
|
324
|
+
const format = () => {
|
|
181
325
|
if (command === 'add')
|
|
182
|
-
|
|
326
|
+
return `${parsed.has('--dry-run') ? 'Plan' : 'Source additions'}: ${result.added.join(', ') || 'already installed'}\n${result.files.map((file) => ' ' + file).join('\n')}\nReview capability configuration and migrations before deployment. No resources were provisioned.`;
|
|
327
|
+
else if (scope === 'public') {
|
|
328
|
+
const rows = parsed.positional[0] === 'list'
|
|
329
|
+
? PUBLIC_STACK_ADDITIONS.map((id) => `${id}\t${ANHEDRAL_STACK.additions[id].name}`)
|
|
330
|
+
: result.additions.map((item) => `${item.id}\t${item.sourceState}`);
|
|
331
|
+
return `${ANHEDRAL_STACK.name}\n${ANHEDRAL_STACK.foundation.name}\n${rows.join('\n')}\nSource state is not live provider activation.`;
|
|
332
|
+
}
|
|
183
333
|
else
|
|
184
|
-
|
|
334
|
+
return (result.capabilities
|
|
185
335
|
.map((item) => `${item.id}\t${item.sourceState ?? item.name}\t${item.requires?.join(', ') ?? ''}`)
|
|
186
336
|
.join('\n') + '\nSource state is not live provider activation.');
|
|
187
|
-
}
|
|
337
|
+
};
|
|
338
|
+
createReporter(output, format).result(result);
|
|
188
339
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from './bounded-file.js';
|
|
1
2
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { existsSync, lstatSync
|
|
3
|
+
import { existsSync, lstatSync } from 'node:fs';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { parse, modify, applyEdits } from 'jsonc-parser';
|
|
5
6
|
export const fingerprint = (source) => createHash('sha256').update(source).digest('hex');
|
|
@@ -38,9 +39,7 @@ export class CapabilityEditor {
|
|
|
38
39
|
if (this.writes.has(relative))
|
|
39
40
|
return this.writes.get(relative);
|
|
40
41
|
if (!this.before.has(relative)) {
|
|
41
|
-
const value = existsSync(file) ?
|
|
42
|
-
if (value && value.length > 2 * 1024 * 1024)
|
|
43
|
-
throw Error(`Configuration exceeds its bound: ${relative}`);
|
|
42
|
+
const value = existsSync(file) ? readBoundedFile(file, MAX_PROJECT_JSON_BYTES) : null;
|
|
44
43
|
this.before.set(relative, value?.toString('utf8') ?? null);
|
|
45
44
|
}
|
|
46
45
|
return this.before.get(relative);
|
|
@@ -89,7 +88,9 @@ export class CapabilityEditor {
|
|
|
89
88
|
verify() {
|
|
90
89
|
for (const [relative, before] of this.before) {
|
|
91
90
|
const file = this.file(relative);
|
|
92
|
-
const current = existsSync(file)
|
|
91
|
+
const current = existsSync(file)
|
|
92
|
+
? readBoundedFile(file, MAX_PROJECT_JSON_BYTES).toString('utf8')
|
|
93
|
+
: null;
|
|
93
94
|
if (before !== current)
|
|
94
95
|
throw Error(`Source changed during addition: ${relative}. Retry after reviewing it.`);
|
|
95
96
|
}
|
|
@@ -4,6 +4,7 @@ import { CapabilityEditor, fingerprint } from './capability-editor.js';
|
|
|
4
4
|
import { CAPABILITY_DEPENDENCIES as P } from './dependencies.js';
|
|
5
5
|
import { STACK_DEPENDENCIES as D } from './dependencies.js';
|
|
6
6
|
import { resourceName } from './render.js';
|
|
7
|
+
import { composeTanstack, addTanstackAuth } from './platforms/tanstack.js';
|
|
7
8
|
import { WEB_API_PROXY } from './platforms/web.js';
|
|
8
9
|
const template = (name) => readFileSync(new URL(`../assets/stack/${name}`, import.meta.url), 'utf8');
|
|
9
10
|
const json = (value) => JSON.stringify(value, null, 2) + '\n';
|
|
@@ -96,8 +97,12 @@ export function addCapabilityRecipe(e, id, name) {
|
|
|
96
97
|
});
|
|
97
98
|
else
|
|
98
99
|
e.set(web, ['services'], [{ binding: 'ANHEDRAL_API', service: resourceName(name, 'api') }]);
|
|
99
|
-
e.
|
|
100
|
-
|
|
100
|
+
const tanstack = !!e.json('apps/web/package.json').dependencies?.['@tanstack/react-start'];
|
|
101
|
+
if (tanstack)
|
|
102
|
+
e.set('apps/api/package.json', ['devDependencies', 'wrangler'], e.json('apps/web/package.json').devDependencies.wrangler);
|
|
103
|
+
e.create(tanstack ? 'apps/web/src/lib/api-proxy.ts' : 'apps/web/lib/api-proxy.ts', WEB_API_PROXY.replace("'idempotency-key'", "'idempotency-key', 'stripe-signature', 'last-event-id'").replace('AbortSignal.timeout(15000)', "AbortSignal.timeout(request.headers.get('accept')?.includes('text/event-stream') ? 35000 : 15000)"));
|
|
104
|
+
if (!tanstack) {
|
|
105
|
+
e.create('apps/web/lib/server-api.ts', `import 'server-only';
|
|
101
106
|
import { getCloudflareContext } from '@opennextjs/cloudflare';
|
|
102
107
|
import { proxyApi,type ApiBinding } from './api-proxy';
|
|
103
108
|
function apiBinding(candidate:unknown):ApiBinding|undefined {
|
|
@@ -111,8 +116,9 @@ export async function apiRequest(request:Request):Promise<Response>{
|
|
|
111
116
|
return proxyApi(request,{development:false,binding:apiBinding(Reflect.get(env,'ANHEDRAL_API'))});
|
|
112
117
|
}
|
|
113
118
|
`);
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
e.create('apps/web/app/api/[[...path]]/route.ts', "import { apiRequest } from '@/lib/server-api';\nexport const dynamic = 'force-dynamic';\nexport const GET = apiRequest;\nexport const POST = apiRequest;\nexport const PUT = apiRequest;\nexport const PATCH = apiRequest;\nexport const DELETE = apiRequest;\nexport const HEAD = apiRequest;\nexport const OPTIONS = apiRequest;\n");
|
|
120
|
+
e.create('apps/web/README.hono.md', '# Hono development\n\nSet this in apps/web/.env.local for local development:\n\n```dotenv\nAPI_INTERNAL_URL=http://127.0.0.1:8787\n```\n\nProduction uses the ANHEDRAL_API service binding.\n');
|
|
121
|
+
}
|
|
116
122
|
break;
|
|
117
123
|
}
|
|
118
124
|
case 'database-auth': {
|
|
@@ -170,8 +176,12 @@ export async function apiRequest(request:Request):Promise<Response>{
|
|
|
170
176
|
e.create('apps/api/src/auth-features.ts', template('auth-features.ts.txt'));
|
|
171
177
|
e.create('apps/api/src/security.ts', template('security.ts.txt'));
|
|
172
178
|
e.create('apps/api/src/features/auth.ts', template('auth-routes.ts.txt'));
|
|
173
|
-
e.
|
|
174
|
-
|
|
179
|
+
if (e.json('apps/web/package.json').dependencies?.['@tanstack/react-start'])
|
|
180
|
+
addTanstackAuth(e);
|
|
181
|
+
else {
|
|
182
|
+
e.create('apps/web/app/sign-in/page.tsx', template('web-sign-in.tsx.txt'));
|
|
183
|
+
e.create('apps/web/lib/auth-client.ts', "'use client';\nimport { createAuthClient } from 'better-auth/react';\nexport const authClient = createAuthClient();\n");
|
|
184
|
+
}
|
|
175
185
|
e.merge('package.json', 'scripts', {
|
|
176
186
|
'db:generate': 'pnpm --dir packages/db db:generate',
|
|
177
187
|
'db:migrate': 'pnpm --dir packages/db db:migrate',
|
|
@@ -209,6 +219,7 @@ export async function apiRequest(request:Request):Promise<Response>{
|
|
|
209
219
|
e.create('packages/db/src/events-schema.ts', template('events-schema.ts.txt'));
|
|
210
220
|
schemaExport(e, 'events-schema');
|
|
211
221
|
e.create('apps/api/src/features/events.ts', template('events.ts.txt'));
|
|
222
|
+
e.create('packages/db/operations/event-retention.sql.example', template('event-retention.sql.txt'));
|
|
212
223
|
break;
|
|
213
224
|
case 'rtc':
|
|
214
225
|
e.create('apps/api/src/features/rtc.ts', template('rtc.ts.txt'));
|
|
@@ -402,7 +413,44 @@ function addDesktop(e) {
|
|
|
402
413
|
e.create('apps/desktop/.gitignore', '/target/\n');
|
|
403
414
|
e.create('apps/desktop/.env.example', '# Desktop binaries run natively, not on Workers.\nANHEDRAL_API_ORIGIN=https://your-app.example\n');
|
|
404
415
|
}
|
|
416
|
+
function taskContract(e, name, patch) {
|
|
417
|
+
const previous = e.json('turbo.json').tasks?.[name] ?? {};
|
|
418
|
+
if (!previous || typeof previous !== 'object' || Array.isArray(previous))
|
|
419
|
+
throw Error(`Preserve invalid task ${name}; reconcile turbo.json first.`);
|
|
420
|
+
const next = { ...previous };
|
|
421
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
422
|
+
if (Array.isArray(value)) {
|
|
423
|
+
const old = previous[key] ?? [];
|
|
424
|
+
if (!Array.isArray(old) || old.some((item) => typeof item !== 'string'))
|
|
425
|
+
throw Error(`Preserve ${name}.${key}; reconcile turbo.json first.`);
|
|
426
|
+
next[key] = [...new Set([...old, ...value])];
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
if (previous[key] !== undefined && previous[key] !== value)
|
|
430
|
+
throw Error(`Preserve ${name}.${key}; reconcile turbo.json first.`);
|
|
431
|
+
next[key] = value;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
e.set('turbo.json', ['tasks', name], next);
|
|
435
|
+
}
|
|
405
436
|
export function composeCapabilities(e, installed) {
|
|
437
|
+
if (e.json('apps/web/package.json').dependencies?.['@tanstack/react-start'])
|
|
438
|
+
composeTanstack(e, installed);
|
|
439
|
+
if (installed.includes('wxt')) {
|
|
440
|
+
taskContract(e, '@workspace/extension#build', {
|
|
441
|
+
outputs: ['.output/**'],
|
|
442
|
+
env: ['WXT_API_ORIGIN'],
|
|
443
|
+
});
|
|
444
|
+
taskContract(e, '@workspace/extension#dev', {
|
|
445
|
+
cache: false,
|
|
446
|
+
persistent: true,
|
|
447
|
+
env: ['WXT_API_ORIGIN'],
|
|
448
|
+
});
|
|
449
|
+
taskContract(e, '@workspace/extension#typecheck', { outputs: ['.wxt/**'] });
|
|
450
|
+
taskContract(e, '@workspace/extension#lint', { outputs: ['.wxt/**'] });
|
|
451
|
+
}
|
|
452
|
+
if (installed.includes('gpui'))
|
|
453
|
+
taskContract(e, '@workspace/desktop#build', { cache: false });
|
|
406
454
|
if (!installed.includes('hono'))
|
|
407
455
|
return;
|
|
408
456
|
if (installed.includes('expo'))
|
package/dist/cli-arguments.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare function globalArguments(input: readonly string[]): {
|
|
|
11
11
|
quiet: boolean;
|
|
12
12
|
verbose: boolean;
|
|
13
13
|
json: boolean;
|
|
14
|
+
human: boolean;
|
|
15
|
+
nonInteractive: boolean;
|
|
14
16
|
};
|
|
15
17
|
export declare function validateCommand(command: string | undefined, args: readonly string[]): void;
|
|
16
18
|
export declare function inlineArguments(command: string | undefined, args: readonly string[]): string[];
|
package/dist/cli-arguments.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { COMMANDS,
|
|
1
|
+
import { COMMANDS, commandDefinition, commandOptions, commandTopic } from './command-schema.js';
|
|
2
2
|
export class CliArgumentError extends Error {
|
|
3
3
|
nextAction;
|
|
4
4
|
code;
|
|
@@ -35,11 +35,14 @@ export function suggest(input, choices) {
|
|
|
35
35
|
export function globalArguments(input) {
|
|
36
36
|
const args = [];
|
|
37
37
|
let cwd;
|
|
38
|
-
let quiet = false;
|
|
39
|
-
let
|
|
40
|
-
let json = false;
|
|
38
|
+
let quiet = false, verbose = false, json = false, human = false, nonInteractive = false;
|
|
39
|
+
let command;
|
|
41
40
|
for (let index = 0; index < input.length; index++) {
|
|
42
41
|
const arg = input[index];
|
|
42
|
+
if (arg === '--') {
|
|
43
|
+
args.push(...input.slice(index));
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
43
46
|
if (arg === '-c' || arg === '--cwd' || arg.startsWith('--cwd=')) {
|
|
44
47
|
const value = arg.startsWith('--cwd=') ? arg.slice(6) : input[++index];
|
|
45
48
|
if (!value || value.startsWith('-') || cwd !== undefined)
|
|
@@ -48,93 +51,141 @@ export function globalArguments(input) {
|
|
|
48
51
|
}
|
|
49
52
|
else if (arg === '--json')
|
|
50
53
|
json = true;
|
|
54
|
+
else if (arg === '--human')
|
|
55
|
+
human = true;
|
|
51
56
|
else if (arg === '--quiet' || arg === '-q')
|
|
52
57
|
quiet = true;
|
|
53
58
|
else if (arg === '--verbose')
|
|
54
59
|
verbose = true;
|
|
55
|
-
else
|
|
60
|
+
else if (arg === '--non-interactive')
|
|
61
|
+
nonInteractive = true;
|
|
62
|
+
else {
|
|
56
63
|
args.push(arg);
|
|
64
|
+
if (!command && !arg.startsWith('-'))
|
|
65
|
+
command = arg;
|
|
66
|
+
const option = commandOptions(command).find((entry) => entry.flag === arg || entry.aliases?.includes(arg));
|
|
67
|
+
if (option?.arity && input[index + 1] !== undefined && !input[index + 1].startsWith('-'))
|
|
68
|
+
args.push(input[++index]);
|
|
69
|
+
}
|
|
57
70
|
}
|
|
58
|
-
|
|
71
|
+
if (json && human)
|
|
72
|
+
throw new CliArgumentError('Choose --json or --human.', 'Run anhedral --help.');
|
|
73
|
+
return { args, cwd, quiet, verbose, json, human, nonInteractive };
|
|
59
74
|
}
|
|
60
|
-
|
|
61
|
-
if (!command || ['--help', '-h', '--version', '-v', 'help'].includes(command))
|
|
62
|
-
return;
|
|
75
|
+
function definitionFor(command) {
|
|
63
76
|
const definition = commandDefinition(command);
|
|
64
77
|
if (!definition) {
|
|
65
78
|
const recommendation = suggest(command, [...Object.keys(COMMANDS), 'help']);
|
|
66
79
|
const name = /^[a-z-]{1,32}$/.test(command) ? `: ${command}` : '';
|
|
67
80
|
throw new CliArgumentError(`Unknown command${name}.${recommendation ? ` Did you mean ${recommendation}?` : ''}`, 'Run anhedral --help.', 'UNKNOWN_COMMAND');
|
|
68
81
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
return definition;
|
|
83
|
+
}
|
|
84
|
+
function collectArguments(command, input) {
|
|
85
|
+
const definitions = commandOptions(command);
|
|
86
|
+
const flags = definitions.flatMap((option) => [option.flag, ...(option.aliases ?? [])]);
|
|
87
|
+
const positional = [];
|
|
88
|
+
const options = new Map();
|
|
89
|
+
let literal = false;
|
|
90
|
+
for (let index = 0; index < input.length; index++) {
|
|
91
|
+
const argument = input[index];
|
|
92
|
+
if (!literal && argument === '--') {
|
|
93
|
+
literal = true;
|
|
75
94
|
continue;
|
|
95
|
+
}
|
|
96
|
+
if (literal || !argument.startsWith('-')) {
|
|
97
|
+
positional.push(argument);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
76
100
|
const separator = argument.indexOf('=');
|
|
77
101
|
const flag = separator < 0 ? argument : argument.slice(0, separator);
|
|
78
|
-
const option =
|
|
102
|
+
const option = definitions.find((entry) => entry.flag === flag || entry.aliases?.includes(flag));
|
|
79
103
|
if (!option) {
|
|
80
104
|
const recommendation = suggest(flag, flags);
|
|
81
105
|
const display = /^--?[a-z-]{1,64}$/.test(flag) ? `: ${flag}` : '';
|
|
82
106
|
throw new CliArgumentError(`Unknown ${command} option${display}.${recommendation ? ` Did you mean ${recommendation}?` : ''}`, `Run anhedral ${command} --help.`);
|
|
83
107
|
}
|
|
84
|
-
if (
|
|
108
|
+
if (options.has(option.flag) && !option.repeatable)
|
|
85
109
|
throw new CliArgumentError(`Specify ${option.flag} once.`, `Run anhedral ${command} --help.`);
|
|
86
|
-
seen.add(option.flag);
|
|
87
110
|
if (separator >= 0 && !option.arity)
|
|
88
111
|
throw new CliArgumentError('This option does not accept an inline value.', `Run anhedral ${command} --help.`);
|
|
112
|
+
const values = options.get(option.flag) ?? [];
|
|
89
113
|
if (option.arity) {
|
|
90
|
-
const value = separator >= 0 ? argument.slice(separator + 1) :
|
|
114
|
+
const value = separator >= 0 ? argument.slice(separator + 1) : input[index + 1];
|
|
91
115
|
if (!value || value.startsWith('-')) {
|
|
92
116
|
if (option.arity === 'required' || separator >= 0)
|
|
93
117
|
throw new CliArgumentError(`Supply a value for ${option.flag}.`, `Run anhedral ${command} --help.`);
|
|
94
118
|
}
|
|
95
|
-
else
|
|
96
|
-
|
|
119
|
+
else {
|
|
120
|
+
if (option.choices && !option.choices.includes(value))
|
|
121
|
+
throw new CliArgumentError(`Choose ${option.choices.join(', ')} for ${option.flag}.`, `Run anhedral ${command} --help.`);
|
|
122
|
+
values.push(value);
|
|
123
|
+
if (separator < 0)
|
|
124
|
+
index++;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
options.set(option.flag, values);
|
|
128
|
+
}
|
|
129
|
+
return { positional, options };
|
|
130
|
+
}
|
|
131
|
+
export function validateCommand(command, args) {
|
|
132
|
+
if (!command || ['--help', '-h', '--version', '-v', 'help'].includes(command))
|
|
133
|
+
return;
|
|
134
|
+
const definition = definitionFor(command);
|
|
135
|
+
const parsed = collectArguments(command, args);
|
|
136
|
+
let topic = [command], selected = definition, positional = parsed.positional;
|
|
137
|
+
while (selected.children) {
|
|
138
|
+
const child = positional[0];
|
|
139
|
+
if (!child || !Object.hasOwn(selected.children, child)) {
|
|
140
|
+
const choices = Object.keys(selected.children), recommendation = child ? suggest(child, choices) : undefined;
|
|
141
|
+
throw new CliArgumentError(`Choose ${topic.join(' ')} ${choices.join(', ')}.${recommendation ? ` Did you mean ${recommendation}?` : ''}`, `Run anhedral ${topic.join(' ')} --help.`);
|
|
97
142
|
}
|
|
143
|
+
topic = [...topic, child];
|
|
144
|
+
selected = commandTopic(topic);
|
|
145
|
+
positional = positional.slice(1);
|
|
146
|
+
}
|
|
147
|
+
const shape = selected.positional;
|
|
148
|
+
if (positional.length < (shape?.min ?? 0) || positional.length > (shape?.max ?? 0))
|
|
149
|
+
throw new CliArgumentError(`Expected ${shape?.name ?? 'no extra arguments'} for ${topic.join(' ')}.`, `Run anhedral ${topic.join(' ')} --help.`);
|
|
150
|
+
if (shape?.choices && positional.some((value) => !shape.choices.includes(value)))
|
|
151
|
+
throw new CliArgumentError(`Choose ${shape.choices.join(', ')} for ${shape.name}.`, `Run anhedral ${topic.join(' ')} --help.`);
|
|
152
|
+
for (const group of [
|
|
153
|
+
...(definition.conflicts ?? []),
|
|
154
|
+
...(selected === definition ? [] : (selected.conflicts ?? [])),
|
|
155
|
+
['--json', '--human'],
|
|
156
|
+
]) {
|
|
157
|
+
const used = group.filter((flag) => parsed.options.has(flag));
|
|
158
|
+
if (used.length > 1)
|
|
159
|
+
throw new CliArgumentError(`Choose one of ${group.join(', ')}.`, `Run anhedral ${topic.join(' ')} --help.`);
|
|
98
160
|
}
|
|
99
161
|
}
|
|
100
162
|
export function inlineArguments(command, args) {
|
|
101
|
-
const
|
|
102
|
-
const flags = new Set(definition?.options
|
|
163
|
+
const flags = new Set(commandOptions(command)
|
|
103
164
|
.filter((option) => option.arity)
|
|
104
|
-
.flatMap((option) => [option.flag, ...(option.aliases ?? [])])
|
|
105
|
-
|
|
165
|
+
.flatMap((option) => [option.flag, ...(option.aliases ?? [])]));
|
|
166
|
+
const result = [];
|
|
167
|
+
for (let index = 0; index < args.length; index++) {
|
|
168
|
+
const argument = args[index];
|
|
169
|
+
if (argument === '--') {
|
|
170
|
+
result.push(...args.slice(index));
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
106
173
|
const separator = argument.indexOf('=');
|
|
107
|
-
if (separator < 0 || !flags.has(argument.slice(0, separator)))
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
174
|
+
if (separator < 0 || !flags.has(argument.slice(0, separator))) {
|
|
175
|
+
result.push(argument);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const flag = argument.slice(0, separator), value = argument.slice(separator + 1);
|
|
111
179
|
if (!value || value.startsWith('-'))
|
|
112
180
|
throw new CliArgumentError(`Supply a value for ${flag}.`, `Run anhedral ${command} --help.`);
|
|
113
|
-
|
|
114
|
-
}
|
|
181
|
+
result.push(flag, value);
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
115
184
|
}
|
|
116
185
|
/** Collect validated options using the same arity and alias metadata as help. */
|
|
117
186
|
export function commandArguments(command, input) {
|
|
118
187
|
validateCommand(command, input);
|
|
119
|
-
const
|
|
120
|
-
const definitions = [...(commandDefinition(command)?.options ?? []), ...GLOBAL_OPTIONS];
|
|
121
|
-
const positional = [];
|
|
122
|
-
const options = new Map();
|
|
123
|
-
for (let index = 0; index < args.length; index++) {
|
|
124
|
-
const argument = args[index];
|
|
125
|
-
const option = definitions.find((entry) => entry.flag === argument || entry.aliases?.includes(argument));
|
|
126
|
-
if (!option) {
|
|
127
|
-
positional.push(argument);
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
const values = options.get(option.flag) ?? [];
|
|
131
|
-
const next = args[index + 1];
|
|
132
|
-
if (option.arity && next && !next.startsWith('-')) {
|
|
133
|
-
values.push(next);
|
|
134
|
-
index++;
|
|
135
|
-
}
|
|
136
|
-
options.set(option.flag, values);
|
|
137
|
-
}
|
|
188
|
+
const { positional, options } = collectArguments(command, input);
|
|
138
189
|
return {
|
|
139
190
|
positional,
|
|
140
191
|
has: (flag) => options.has(flag),
|