anhedral 0.15.0 → 0.16.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 +29 -38
- package/assets/stack/ai-schema.ts.txt +5 -0
- package/assets/stack/ai.ts.txt +30 -0
- package/assets/stack/api-index.ts.txt +15 -0
- package/assets/stack/auth-features.ts.txt +4 -0
- package/assets/stack/auth-journal.json.txt +13 -0
- package/assets/stack/auth-migration.sql.txt +53 -0
- package/assets/stack/auth-routes.ts.txt +11 -0
- package/assets/stack/auth-schema.ts.txt +64 -0
- package/assets/stack/auth-snapshot.json.txt +346 -0
- package/assets/stack/auth.ts.txt +32 -0
- package/assets/stack/billing-mode.ts.txt +8 -0
- package/assets/stack/billing-schema.ts.txt +11 -0
- package/assets/stack/desktop.rs.txt +21 -0
- package/assets/stack/entitlement-guard.ts.txt +32 -0
- package/assets/stack/entitlements.ts.txt +8 -0
- package/assets/stack/events-schema.ts.txt +12 -0
- package/assets/stack/events.ts.txt +59 -0
- package/assets/stack/mobile-auth.ts.txt +25 -0
- package/assets/stack/mobile-billing.tsx.txt +63 -0
- package/assets/stack/mobile-session.tsx.txt +83 -0
- package/assets/stack/native-button.tsx.txt +108 -0
- package/assets/stack/native-global.css.txt +4 -0
- package/assets/stack/native-lib-utils.ts.txt +5 -0
- package/assets/stack/native-metro.config.js.txt +6 -0
- package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
- package/assets/stack/native-tailwind.config.js.txt +73 -0
- package/assets/stack/native-text.tsx.txt +89 -0
- package/assets/stack/purchases.ts.txt +65 -0
- package/assets/stack/revenuecat.ts.txt +88 -0
- package/assets/stack/rtc-schema.ts.txt +10 -0
- package/assets/stack/rtc.ts.txt +122 -0
- package/assets/stack/security.ts.txt +31 -0
- package/assets/stack/storage.ts.txt +36 -0
- package/assets/stack/stripe.ts.txt +126 -0
- package/assets/stack/web-sign-in.tsx.txt +51 -0
- package/assets/ui/LICENSE.react-native-reusables +21 -0
- package/assets/ui/UPSTREAM.json +7 -1
- package/assets/ui/catalog.json +891 -0
- package/assets/ui/extensions/registry.json +6 -0
- package/assets/ui/native/_controls.tsx +521 -0
- package/assets/ui/native/_core.tsx +118 -0
- package/assets/ui/native/_data.tsx +200 -0
- package/assets/ui/native/_display.tsx +453 -0
- package/assets/ui/native/_feedback.tsx +242 -0
- package/assets/ui/native/_legacy-dialog.tsx +38 -0
- package/assets/ui/native/_motion.tsx +520 -0
- package/assets/ui/native/_overlay.tsx +402 -0
- package/assets/ui/native/_selection.tsx +366 -0
- package/assets/ui/native/accordion.tsx +1 -0
- package/assets/ui/native/alert-dialog.tsx +11 -0
- package/assets/ui/native/alert.tsx +1 -0
- package/assets/ui/native/aspect-ratio.tsx +1 -0
- package/assets/ui/native/attachment.tsx +8 -0
- package/assets/ui/native/avatar.tsx +8 -0
- package/assets/ui/native/badge.tsx +1 -0
- package/assets/ui/native/breadcrumb.tsx +9 -0
- package/assets/ui/native/bubble.tsx +1 -0
- package/assets/ui/native/button-group.tsx +1 -0
- package/assets/ui/native/button.tsx +2 -1
- package/assets/ui/native/calendar.tsx +170 -0
- package/assets/ui/native/card.tsx +16 -5
- package/assets/ui/native/carousel.tsx +1 -0
- package/assets/ui/native/chart.tsx +193 -0
- package/assets/ui/native/checkbox.tsx +1 -0
- package/assets/ui/native/code-block.tsx +137 -0
- package/assets/ui/native/collapsible.tsx +1 -0
- package/assets/ui/native/combobox.tsx +1 -0
- package/assets/ui/native/command.tsx +11 -0
- package/assets/ui/native/context-menu.tsx +16 -0
- package/assets/ui/native/data-table.tsx +1 -0
- package/assets/ui/native/date-picker.tsx +43 -0
- package/assets/ui/native/dialog.tsx +14 -74
- package/assets/ui/native/direction.tsx +1 -0
- package/assets/ui/native/drawer.tsx +10 -0
- package/assets/ui/native/dropdown-menu.tsx +16 -0
- package/assets/ui/native/empty.tsx +8 -0
- package/assets/ui/native/field.tsx +13 -0
- package/assets/ui/native/hover-card.tsx +1 -0
- package/assets/ui/native/input-group.tsx +8 -0
- package/assets/ui/native/input-otp.tsx +1 -0
- package/assets/ui/native/input.tsx +2 -1
- package/assets/ui/native/item.tsx +12 -0
- package/assets/ui/native/kbd.tsx +1 -0
- package/assets/ui/native/marker.tsx +1 -0
- package/assets/ui/native/menubar.tsx +17 -0
- package/assets/ui/native/message-scroller.tsx +6 -0
- package/assets/ui/native/message.tsx +10 -0
- package/assets/ui/native/native-select.tsx +1 -0
- package/assets/ui/native/navigation-menu.tsx +10 -0
- package/assets/ui/native/pagination.tsx +9 -0
- package/assets/ui/native/popover.tsx +1 -0
- package/assets/ui/native/progress.tsx +1 -0
- package/assets/ui/native/questionnaire.tsx +130 -0
- package/assets/ui/native/radio-group.tsx +1 -0
- package/assets/ui/native/registry.json +1103 -0
- package/assets/ui/native/resizable.tsx +1 -0
- package/assets/ui/native/scroll-area.tsx +1 -0
- package/assets/ui/native/select.tsx +11 -0
- package/assets/ui/native/separator.tsx +1 -0
- package/assets/ui/native/sheet.tsx +10 -0
- package/assets/ui/native/sidebar.tsx +22 -0
- package/assets/ui/native/skeleton.tsx +1 -0
- package/assets/ui/native/slider.tsx +1 -0
- package/assets/ui/native/spinner.tsx +1 -0
- package/assets/ui/native/switch.tsx +1 -0
- package/assets/ui/native/table.tsx +10 -0
- package/assets/ui/native/tabs.tsx +1 -0
- package/assets/ui/native/textarea.tsx +1 -0
- package/assets/ui/native/toast.tsx +11 -0
- package/assets/ui/native/toggle-group.tsx +1 -0
- package/assets/ui/native/toggle.tsx +1 -0
- package/assets/ui/native/tooltip.tsx +1 -0
- package/assets/ui/native/trace.tsx +20 -0
- package/assets/ui/native/typography.tsx +15 -0
- package/dist/bin.js +7 -12
- package/dist/capabilities.d.ts +4 -33
- package/dist/capabilities.js +2 -66
- package/dist/capability-catalog.d.ts +83 -0
- package/dist/capability-catalog.js +121 -0
- package/dist/capability-command.d.ts +3 -0
- package/dist/capability-command.js +188 -0
- package/dist/capability-editor.d.ts +17 -0
- package/dist/capability-editor.js +97 -0
- package/dist/capability-recipes.d.ts +4 -0
- package/dist/capability-recipes.js +520 -0
- package/dist/capability-references.d.ts +4 -0
- package/dist/capability-references.js +7 -0
- package/dist/cli-commands.d.ts +1 -2
- package/dist/cli-commands.js +10 -104
- package/dist/cli-output.d.ts +1 -2
- package/dist/cli-output.js +6 -251
- package/dist/command-schema.js +39 -322
- package/dist/dependencies.d.ts +29 -6
- package/dist/dependencies.js +61 -14
- package/dist/index.d.ts +1 -42
- package/dist/index.js +1 -27
- package/dist/platforms/mobile.js +1 -20
- package/dist/platforms/web.d.ts +1 -1
- package/dist/platforms/web.js +27 -75
- package/dist/project-config.d.ts +2 -13
- package/dist/project-config.js +10 -82
- package/dist/registry/options.js +1 -5
- package/dist/registry/resolve.d.ts +1 -1
- package/dist/registry/resolve.js +2 -10
- package/dist/registry/usage.js +3 -9
- package/dist/scaffold/backend.js +0 -3
- package/dist/scaffold/database.js +2 -1
- package/dist/scaffold/documentation.js +82 -20
- package/dist/scaffold/expo-runtime.js +3 -4
- package/dist/scaffold/native-ui.js +12 -7
- package/dist/scaffold/stack-documentation.js +1 -1
- package/dist/scaffold/storage.d.ts +2 -0
- package/dist/scaffold/storage.js +21 -0
- package/dist/scaffold/workspace.js +26 -21
- package/dist/stack-registry.d.ts +2 -8
- package/dist/stack-registry.js +11 -87
- package/dist/standard.js +1 -11
- package/dist/ui-catalog.d.ts +26 -0
- package/dist/ui-catalog.js +31 -0
- package/dist/ui-command.d.ts +3 -0
- package/dist/ui-command.js +219 -0
- package/dist/ui-project.d.ts +22 -0
- package/dist/ui-project.js +110 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +4 -20
- package/docs/capabilities.md +110 -0
- package/docs/native-ui.md +102 -0
- package/docs/software-factory.md +16 -44
- package/docs/stack-standard.md +11 -60
- package/docs/ui.md +33 -0
- package/docs/verification.md +191 -0
- package/package.json +19 -18
- package/dist/access.d.ts +0 -10
- package/dist/access.js +0 -93
- package/dist/auth-schema-snapshot.d.ts +0 -346
- package/dist/auth-schema-snapshot.js +0 -347
- package/dist/auth-schema.d.ts +0 -1
- package/dist/auth-schema.js +0 -57
- package/dist/capability-contract.d.ts +0 -47
- package/dist/capability-contract.js +0 -129
- package/dist/catalog-model.d.ts +0 -24
- package/dist/catalog-model.js +0 -1
- package/dist/catalog-registration.d.ts +0 -16
- package/dist/catalog-registration.js +0 -22
- package/dist/catalog-snapshot.d.ts +0 -5
- package/dist/catalog-snapshot.js +0 -97
- package/dist/cli-delivery.d.ts +0 -3
- package/dist/cli-delivery.js +0 -112
- package/dist/cloudflare.d.ts +0 -25
- package/dist/cloudflare.js +0 -226
- package/dist/delivery-evidence.d.ts +0 -62
- package/dist/delivery-evidence.js +0 -157
- package/dist/delivery.d.ts +0 -82
- package/dist/delivery.js +0 -489
- package/dist/inspector-model.d.ts +0 -123
- package/dist/inspector-model.js +0 -1
- package/dist/integration-service-readers.d.ts +0 -12
- package/dist/integration-service-readers.js +0 -92
- package/dist/lifecycle-model.d.ts +0 -15
- package/dist/lifecycle-model.js +0 -20
- package/dist/lifecycle.d.ts +0 -11
- package/dist/lifecycle.js +0 -91
- package/dist/management.d.ts +0 -3
- package/dist/management.js +0 -47
- package/dist/mobile-delivery.d.ts +0 -77
- package/dist/mobile-delivery.js +0 -370
- package/dist/project-catalog.d.ts +0 -41
- package/dist/project-catalog.js +0 -288
- package/dist/project-inspector.d.ts +0 -4
- package/dist/project-inspector.js +0 -671
- package/dist/project-lifecycle.d.ts +0 -25
- package/dist/project-lifecycle.js +0 -57
- package/dist/project-state.d.ts +0 -47
- package/dist/project-state.js +0 -480
- package/dist/provider-auth.d.ts +0 -41
- package/dist/provider-auth.js +0 -180
- package/dist/provider-readiness.d.ts +0 -30
- package/dist/provider-readiness.js +0 -85
- package/dist/providers/adapters.d.ts +0 -17
- package/dist/providers/adapters.js +0 -103
- package/dist/providers/api.d.ts +0 -29
- package/dist/providers/api.js +0 -253
- package/dist/providers/config.d.ts +0 -15
- package/dist/providers/config.js +0 -136
- package/dist/providers/definitions.d.ts +0 -115
- package/dist/providers/definitions.js +0 -42
- package/dist/providers/provision.d.ts +0 -24
- package/dist/providers/provision.js +0 -76
- package/dist/providers/receipts.d.ts +0 -20
- package/dist/providers/receipts.js +0 -56
- package/dist/providers/recovery-verification.d.ts +0 -7
- package/dist/providers/recovery-verification.js +0 -52
- package/dist/providers/recovery.d.ts +0 -30
- package/dist/providers/recovery.js +0 -34
- package/dist/providers/runtime.d.ts +0 -10
- package/dist/providers/runtime.js +0 -234
- package/dist/providers/schema.d.ts +0 -28
- package/dist/providers/schema.js +0 -49
- package/dist/providers/state.d.ts +0 -55
- package/dist/providers/state.js +0 -283
- package/dist/provision.d.ts +0 -47
- package/dist/provision.js +0 -208
- package/dist/r2-service-data.d.ts +0 -2
- package/dist/r2-service-data.js +0 -136
- package/dist/readiness.d.ts +0 -23
- package/dist/readiness.js +0 -117
- package/dist/registry/add.d.ts +0 -24
- package/dist/registry/add.js +0 -210
- package/dist/registry/bootstrap.d.ts +0 -3
- package/dist/registry/bootstrap.js +0 -5
- package/dist/registry/commands.d.ts +0 -3
- package/dist/registry/commands.js +0 -83
- package/dist/registry/preview.d.ts +0 -11
- package/dist/registry/preview.js +0 -91
- package/dist/registry/receipt.d.ts +0 -3
- package/dist/registry/receipt.js +0 -68
- package/dist/repository.d.ts +0 -24
- package/dist/repository.js +0 -96
- package/dist/scaffold/auth.d.ts +0 -2
- package/dist/scaffold/auth.js +0 -76
- package/dist/scaffold/billing-config.d.ts +0 -1
- package/dist/scaffold/billing-config.js +0 -73
- package/dist/scaffold/billing-contracts.d.ts +0 -2
- package/dist/scaffold/billing-contracts.js +0 -48
- package/dist/scaffold/billing-providers.d.ts +0 -1
- package/dist/scaffold/billing-providers.js +0 -249
- package/dist/scaffold/billing-schema.d.ts +0 -1
- package/dist/scaffold/billing-schema.js +0 -34
- package/dist/scaffold/billing-security.d.ts +0 -1
- package/dist/scaffold/billing-security.js +0 -46
- package/dist/scaffold/billing-server.d.ts +0 -1
- package/dist/scaffold/billing-server.js +0 -139
- package/dist/scaffold/billing-store.d.ts +0 -1
- package/dist/scaffold/billing-store.js +0 -72
- package/dist/scaffold/billing.d.ts +0 -2
- package/dist/scaffold/billing.js +0 -208
- package/dist/scaffold/expo-auth.d.ts +0 -3
- package/dist/scaffold/expo-auth.js +0 -203
- package/dist/scaffold/expo-billing.d.ts +0 -3
- package/dist/scaffold/expo-billing.js +0 -257
- package/dist/scaffold/integrations.d.ts +0 -2
- package/dist/scaffold/integrations.js +0 -11
- package/dist/scaffold/managed-email.d.ts +0 -3
- package/dist/scaffold/managed-email.js +0 -47
- package/dist/scaffold/password-reset.d.ts +0 -1
- package/dist/scaffold/password-reset.js +0 -99
- package/dist/scaffold/private-files.d.ts +0 -2
- package/dist/scaffold/private-files.js +0 -78
- package/dist/scaffold/web-billing.d.ts +0 -2
- package/dist/scaffold/web-billing.js +0 -48
- package/dist/service-deletion.d.ts +0 -29
- package/dist/service-deletion.js +0 -195
- package/dist/service-descriptor.d.ts +0 -10
- package/dist/service-descriptor.js +0 -71
- package/dist/service-model.d.ts +0 -49
- package/dist/service-model.js +0 -8
- package/dist/service-operations.d.ts +0 -29
- package/dist/service-operations.js +0 -48
- package/dist/service-readers.d.ts +0 -8
- package/dist/service-readers.js +0 -216
- package/dist/services-command.d.ts +0 -39
- package/dist/services-command.js +0 -96
- package/dist/ship.d.ts +0 -35
- package/dist/ship.js +0 -107
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { existsSync, realpathSync, statSync, chmodSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { commandArguments, commandArgumentError } from './cli-arguments.js';
|
|
4
|
+
import { CAPABILITIES, CAPABILITY_IDS, capabilityOrder, } from './capability-catalog.js';
|
|
5
|
+
import { CapabilityEditor } from './capability-editor.js';
|
|
6
|
+
import { addCapabilityRecipe, composeCapabilities } from './capability-recipes.js';
|
|
7
|
+
import { PostCommitError, runStagedTransaction } from './transaction.js';
|
|
8
|
+
import { put } from './scaffold/files.js';
|
|
9
|
+
import { execFile } from './util.js';
|
|
10
|
+
import { capabilityReferences } from './capability-references.js';
|
|
11
|
+
import { configureDependencyPatches } from './dependency-patches.js';
|
|
12
|
+
function projectRoot(cwd) {
|
|
13
|
+
let root = realpathSync(cwd);
|
|
14
|
+
for (;;) {
|
|
15
|
+
if (existsSync(path.join(root, 'anhedral.json')))
|
|
16
|
+
return root;
|
|
17
|
+
if (existsSync(path.join(root, '.git')))
|
|
18
|
+
break;
|
|
19
|
+
const parent = path.dirname(root);
|
|
20
|
+
if (parent === root)
|
|
21
|
+
break;
|
|
22
|
+
root = parent;
|
|
23
|
+
}
|
|
24
|
+
throw Error('No Anhedral workspace found. Select a generated project with --cwd.');
|
|
25
|
+
}
|
|
26
|
+
function readState(e) {
|
|
27
|
+
const project = e.json('anhedral.json');
|
|
28
|
+
const state = project.capabilities ?? { schemaVersion: 1, installed: [], managedFiles: {} };
|
|
29
|
+
if (state.schemaVersion !== 1 ||
|
|
30
|
+
!Array.isArray(state.installed) ||
|
|
31
|
+
state.installed.some((id) => typeof id !== 'string' || !Object.hasOwn(CAPABILITIES, id)) ||
|
|
32
|
+
!state.managedFiles ||
|
|
33
|
+
typeof state.managedFiles !== 'object' ||
|
|
34
|
+
Array.isArray(state.managedFiles))
|
|
35
|
+
throw Error('Invalid capability state; preserve and reconcile anhedral.json.');
|
|
36
|
+
const installed = [...new Set(state.installed)];
|
|
37
|
+
for (const id of installed)
|
|
38
|
+
for (const parent of CAPABILITIES[id].requires)
|
|
39
|
+
if (!installed.includes(parent))
|
|
40
|
+
throw Error(`Invalid capability state: ${id} requires ${parent}.`);
|
|
41
|
+
return { installed, managedFiles: state.managedFiles };
|
|
42
|
+
}
|
|
43
|
+
export async function runCapabilityCommand(command, args, output, run = execFile) {
|
|
44
|
+
const parsed = commandArguments(command, args);
|
|
45
|
+
let result;
|
|
46
|
+
if (command === 'stack') {
|
|
47
|
+
const [action, ...extra] = parsed.positional;
|
|
48
|
+
if (extra.length || !['list', 'status', 'doctor'].includes(action))
|
|
49
|
+
throw commandArgumentError('stack', 'Use stack list, status or doctor.');
|
|
50
|
+
if (action === 'list')
|
|
51
|
+
result = {
|
|
52
|
+
capabilities: CAPABILITY_IDS.map((id) => ({ id, ...CAPABILITIES[id] })),
|
|
53
|
+
provisioning: 'Separate from source installation',
|
|
54
|
+
};
|
|
55
|
+
else {
|
|
56
|
+
const root = projectRoot(process.cwd());
|
|
57
|
+
const e = new CapabilityEditor(root, {});
|
|
58
|
+
const state = readState(e);
|
|
59
|
+
const capabilities = CAPABILITY_IDS.map((id) => {
|
|
60
|
+
const missing = CAPABILITIES[id].requires.filter((parent) => !state.installed.includes(parent));
|
|
61
|
+
const installed = state.installed.includes(id);
|
|
62
|
+
const missingFiles = installed
|
|
63
|
+
? CAPABILITIES[id].targets.filter((target) => !existsSync(path.join(root, target)))
|
|
64
|
+
: [];
|
|
65
|
+
return {
|
|
66
|
+
id,
|
|
67
|
+
name: CAPABILITIES[id].name,
|
|
68
|
+
sourceState: installed
|
|
69
|
+
? missingFiles.length
|
|
70
|
+
? 'incomplete'
|
|
71
|
+
: 'installed'
|
|
72
|
+
: missing.length
|
|
73
|
+
? 'locked'
|
|
74
|
+
: 'available',
|
|
75
|
+
missingPrerequisites: missing,
|
|
76
|
+
missingFiles,
|
|
77
|
+
configuration: installed ? CAPABILITIES[id].configuration : [],
|
|
78
|
+
activation: 'not verified',
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
const foundationReady = existsSync(path.join(root, 'apps/web/package.json')) &&
|
|
82
|
+
!!e.json('apps/web/package.json').dependencies?.next;
|
|
83
|
+
const sourceReady = foundationReady && capabilities.every((c) => c.sourceState !== 'incomplete');
|
|
84
|
+
result = {
|
|
85
|
+
root,
|
|
86
|
+
foundationReady,
|
|
87
|
+
sourceReady,
|
|
88
|
+
capabilities,
|
|
89
|
+
runtimeAcceptance: 'not evaluated',
|
|
90
|
+
resourcesProvisionedByCli: false,
|
|
91
|
+
};
|
|
92
|
+
if (action === 'doctor' && !sourceReady)
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
if (!parsed.positional.length || parsed.positional.length > CAPABILITY_IDS.length)
|
|
98
|
+
throw commandArgumentError('add', 'Choose one or more capabilities from anhedral stack list.');
|
|
99
|
+
const root = projectRoot(process.cwd());
|
|
100
|
+
const e = new CapabilityEditor(root, {});
|
|
101
|
+
const state = readState(e);
|
|
102
|
+
Object.assign(e.managed, state.managedFiles);
|
|
103
|
+
const manifest = e.json('package.json');
|
|
104
|
+
if (typeof manifest.name !== 'string' || !manifest.name)
|
|
105
|
+
throw Error('The workspace needs a package name.');
|
|
106
|
+
if (!e.json('apps/web/package.json').dependencies?.next)
|
|
107
|
+
throw Error('A Next.js foundation is required.');
|
|
108
|
+
for (const id of state.installed)
|
|
109
|
+
for (const target of CAPABILITIES[id].targets)
|
|
110
|
+
if (!existsSync(path.join(root, target)))
|
|
111
|
+
throw Error(`Installed capability is incomplete: ${id} (${target}). Reconcile its source first.`);
|
|
112
|
+
const additions = capabilityOrder(parsed.positional, state.installed, parsed.has('--with-dependencies'));
|
|
113
|
+
const installed = [...state.installed, ...additions];
|
|
114
|
+
for (const id of additions)
|
|
115
|
+
addCapabilityRecipe(e, id, manifest.name);
|
|
116
|
+
if (additions.length) {
|
|
117
|
+
for (const [file, source] of Object.entries(capabilityReferences()))
|
|
118
|
+
if (e.read(file) === null)
|
|
119
|
+
e.create(file, source);
|
|
120
|
+
composeCapabilities(e, installed);
|
|
121
|
+
e.set('anhedral.json', ['capabilities'], {
|
|
122
|
+
schemaVersion: 1,
|
|
123
|
+
installed,
|
|
124
|
+
managedFiles: e.managed,
|
|
125
|
+
resourcesProvisionedByCli: false,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const files = [...e.writes.keys()];
|
|
129
|
+
const plan = {
|
|
130
|
+
root,
|
|
131
|
+
added: additions,
|
|
132
|
+
alreadyInstalled: parsed.positional.filter((id) => state.installed.includes(id)),
|
|
133
|
+
installed,
|
|
134
|
+
files,
|
|
135
|
+
configuration: additions.map((id) => ({ id, requirements: CAPABILITIES[id].configuration })),
|
|
136
|
+
dryRun: parsed.has('--dry-run'),
|
|
137
|
+
resourcesProvisionedByCli: false,
|
|
138
|
+
activation: 'not verified',
|
|
139
|
+
};
|
|
140
|
+
const installDependencies = () => {
|
|
141
|
+
if (parsed.has('--skip-install'))
|
|
142
|
+
return;
|
|
143
|
+
run('pnpm', ['install', '--lockfile-only', '--no-frozen-lockfile'], root);
|
|
144
|
+
if (configureDependencyPatches(root))
|
|
145
|
+
run('pnpm', ['install', '--lockfile-only', '--no-frozen-lockfile'], root);
|
|
146
|
+
run('pnpm', ['install', '--frozen-lockfile'], root);
|
|
147
|
+
};
|
|
148
|
+
if (!parsed.has('--dry-run') && files.length) {
|
|
149
|
+
await runStagedTransaction(root, {
|
|
150
|
+
commitPaths: files,
|
|
151
|
+
prepare: () => e.verify(),
|
|
152
|
+
build: async (stage) => {
|
|
153
|
+
for (const [file, source] of e.writes) {
|
|
154
|
+
put(stage, file, source);
|
|
155
|
+
if (e.before.get(file) !== null)
|
|
156
|
+
chmodSync(path.join(stage, file), statSync(path.join(root, file)).mode & 0o777);
|
|
157
|
+
}
|
|
158
|
+
e.verify();
|
|
159
|
+
},
|
|
160
|
+
afterCommit: installDependencies,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (!parsed.has('--dry-run') && !files.length) {
|
|
164
|
+
e.verify();
|
|
165
|
+
try {
|
|
166
|
+
installDependencies();
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
throw new PostCommitError([], error);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
result = {
|
|
173
|
+
...plan,
|
|
174
|
+
sourceInstalled: !parsed.has('--dry-run'),
|
|
175
|
+
dependenciesInstalled: !parsed.has('--dry-run') && !parsed.has('--skip-install'),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (output.json)
|
|
179
|
+
console.log(JSON.stringify(result, null, 2));
|
|
180
|
+
else if (!output.quiet) {
|
|
181
|
+
if (command === 'add')
|
|
182
|
+
console.log(`${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.`);
|
|
183
|
+
else
|
|
184
|
+
console.log(result.capabilities
|
|
185
|
+
.map((item) => `${item.id}\t${item.sourceState ?? item.name}\t${item.requires?.join(', ') ?? ''}`)
|
|
186
|
+
.join('\n') + '\nSource state is not live provider activation.');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const fingerprint: (source: string | Buffer) => string;
|
|
2
|
+
/** A bounded, read-only overlay until every capability has passed preflight. */
|
|
3
|
+
export declare class CapabilityEditor {
|
|
4
|
+
readonly root: string;
|
|
5
|
+
readonly managed: Record<string, string>;
|
|
6
|
+
readonly writes: Map<string, string>;
|
|
7
|
+
readonly before: Map<string, string | null>;
|
|
8
|
+
constructor(root: string, managed: Record<string, string>);
|
|
9
|
+
private file;
|
|
10
|
+
read(relative: string): string | null;
|
|
11
|
+
json(relative: string): Record<string, any>;
|
|
12
|
+
create(relative: string, source: string): void;
|
|
13
|
+
owned(relative: string, source: string): void;
|
|
14
|
+
set(relative: string, keys: (string | number)[], value: unknown): void;
|
|
15
|
+
merge(relative: string, section: string, values: Record<string, unknown>): void;
|
|
16
|
+
verify(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, lstatSync, readFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { parse, modify, applyEdits } from 'jsonc-parser';
|
|
5
|
+
export const fingerprint = (source) => createHash('sha256').update(source).digest('hex');
|
|
6
|
+
/** A bounded, read-only overlay until every capability has passed preflight. */
|
|
7
|
+
export class CapabilityEditor {
|
|
8
|
+
root;
|
|
9
|
+
managed;
|
|
10
|
+
writes = new Map();
|
|
11
|
+
before = new Map();
|
|
12
|
+
constructor(root, managed) {
|
|
13
|
+
this.root = root;
|
|
14
|
+
this.managed = managed;
|
|
15
|
+
}
|
|
16
|
+
file(relative) {
|
|
17
|
+
if (!relative ||
|
|
18
|
+
path.isAbsolute(relative) ||
|
|
19
|
+
relative.includes('\\') ||
|
|
20
|
+
relative.split('/').some((p) => !p || p === '.' || p === '..'))
|
|
21
|
+
throw Error(`Unsafe addition path: ${relative}`);
|
|
22
|
+
let current = this.root;
|
|
23
|
+
for (const part of relative.split('/')) {
|
|
24
|
+
current = path.join(current, part);
|
|
25
|
+
try {
|
|
26
|
+
if (lstatSync(current).isSymbolicLink())
|
|
27
|
+
throw Error(`Refusing a symlink in ${relative}.`);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error.code !== 'ENOENT')
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return current;
|
|
35
|
+
}
|
|
36
|
+
read(relative) {
|
|
37
|
+
const file = this.file(relative);
|
|
38
|
+
if (this.writes.has(relative))
|
|
39
|
+
return this.writes.get(relative);
|
|
40
|
+
if (!this.before.has(relative)) {
|
|
41
|
+
const value = existsSync(file) ? readFileSync(file) : null;
|
|
42
|
+
if (value && value.length > 2 * 1024 * 1024)
|
|
43
|
+
throw Error(`Configuration exceeds its bound: ${relative}`);
|
|
44
|
+
this.before.set(relative, value?.toString('utf8') ?? null);
|
|
45
|
+
}
|
|
46
|
+
return this.before.get(relative);
|
|
47
|
+
}
|
|
48
|
+
json(relative) {
|
|
49
|
+
const source = this.read(relative);
|
|
50
|
+
if (source === null)
|
|
51
|
+
throw Error(`Missing ${relative}.`);
|
|
52
|
+
const errors = [];
|
|
53
|
+
const value = parse(source, errors, { allowTrailingComma: true });
|
|
54
|
+
if (errors.length || !value || typeof value !== 'object' || Array.isArray(value))
|
|
55
|
+
throw Error(`Invalid JSON/JSONC in ${relative}.`);
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
create(relative, source) {
|
|
59
|
+
if (this.read(relative) !== null)
|
|
60
|
+
throw Error(`Addition conflicts with existing source: ${relative}. No files were changed.`);
|
|
61
|
+
this.writes.set(relative, source);
|
|
62
|
+
}
|
|
63
|
+
owned(relative, source) {
|
|
64
|
+
const current = this.read(relative);
|
|
65
|
+
if (current !== null &&
|
|
66
|
+
!this.writes.has(relative) &&
|
|
67
|
+
this.managed[relative] !== fingerprint(current))
|
|
68
|
+
throw Error(`Preserve edited generated source: ${relative}. Reconcile it before adding capabilities. No files were changed.`);
|
|
69
|
+
this.writes.set(relative, source);
|
|
70
|
+
this.managed[relative] = fingerprint(source);
|
|
71
|
+
}
|
|
72
|
+
set(relative, keys, value) {
|
|
73
|
+
const source = this.read(relative);
|
|
74
|
+
if (source === null)
|
|
75
|
+
throw Error(`Missing configuration: ${relative}`);
|
|
76
|
+
this.json(relative);
|
|
77
|
+
this.writes.set(relative, applyEdits(source, modify(source, keys, value, { formattingOptions: { insertSpaces: true, tabSize: 2 } })));
|
|
78
|
+
}
|
|
79
|
+
merge(relative, section, values) {
|
|
80
|
+
const current = this.json(relative)[section] ?? {};
|
|
81
|
+
if (!current || typeof current !== 'object' || Array.isArray(current))
|
|
82
|
+
throw Error(`Expected ${section} object in ${relative}.`);
|
|
83
|
+
for (const [key, value] of Object.entries(values)) {
|
|
84
|
+
if (Object.hasOwn(current, key) && JSON.stringify(current[key]) !== JSON.stringify(value))
|
|
85
|
+
throw Error(`Configuration conflict: ${relative} ${section}.${key}. Preserve and reconcile the existing value.`);
|
|
86
|
+
this.set(relative, [section, key], value);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
verify() {
|
|
90
|
+
for (const [relative, before] of this.before) {
|
|
91
|
+
const file = this.file(relative);
|
|
92
|
+
const current = existsSync(file) ? readFileSync(file, 'utf8') : null;
|
|
93
|
+
if (before !== current)
|
|
94
|
+
throw Error(`Source changed during addition: ${relative}. Retry after reviewing it.`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CapabilityEditor } from './capability-editor.js';
|
|
2
|
+
import type { Capability } from './capability-catalog.js';
|
|
3
|
+
export declare function addCapabilityRecipe(e: CapabilityEditor, id: Capability, name: string): void;
|
|
4
|
+
export declare function composeCapabilities(e: CapabilityEditor, installed: Capability[]): void;
|