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
package/dist/cli-commands.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type OutputOptions } from './cli-output.js';
|
|
2
2
|
export declare function runCommand(command: string, args: string[], output: OutputOptions): Promise<void>;
|
package/dist/cli-commands.js
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
|
+
import { runPlatformCommand } from './platform-command.js';
|
|
1
2
|
import { runCapabilityCommand } from './capability-command.js';
|
|
2
|
-
import {
|
|
3
|
+
import { runAnhedralUiCommand } from './ui-command.js';
|
|
3
4
|
import { commandArgumentError } from './cli-arguments.js';
|
|
4
|
-
import {
|
|
5
|
+
import { createReporter } from './cli-output.js';
|
|
6
|
+
import { scaffoldLaunchProject, parseAnhedralStackOptions } from './launch.js';
|
|
7
|
+
import { completionScript } from './completion.js';
|
|
8
|
+
import { commandArguments } from './cli-arguments.js';
|
|
5
9
|
export async function runCommand(command, args, output) {
|
|
10
|
+
if (command === 'completion') {
|
|
11
|
+
const parsed = commandArguments(command, args);
|
|
12
|
+
const shell = parsed.positional[0];
|
|
13
|
+
const script = completionScript(shell);
|
|
14
|
+
createReporter(output, () => script.trimEnd()).result({ shell, script });
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if ([
|
|
18
|
+
'login',
|
|
19
|
+
'logout',
|
|
20
|
+
'whoami',
|
|
21
|
+
'link',
|
|
22
|
+
'unlink',
|
|
23
|
+
'source',
|
|
24
|
+
'deploy',
|
|
25
|
+
'env',
|
|
26
|
+
'staging',
|
|
27
|
+
'logs',
|
|
28
|
+
].includes(command))
|
|
29
|
+
return runPlatformCommand(command, args, output);
|
|
6
30
|
if (command === 'add' || command === 'stack')
|
|
7
|
-
return runCapabilityCommand(command, args, output);
|
|
31
|
+
return runCapabilityCommand(command, args, output, undefined, 'public');
|
|
8
32
|
if (command === 'ui')
|
|
9
|
-
return
|
|
33
|
+
return runAnhedralUiCommand(args, output);
|
|
10
34
|
if (command !== 'init')
|
|
11
35
|
throw commandArgumentError(command, 'Use init, add, stack or ui. Run anhedral --help.');
|
|
12
36
|
let options;
|
|
13
37
|
try {
|
|
14
|
-
options =
|
|
38
|
+
options = parseAnhedralStackOptions(args);
|
|
15
39
|
}
|
|
16
40
|
catch (error) {
|
|
17
41
|
throw commandArgumentError('init', error instanceof Error ? error.message : String(error));
|
|
18
42
|
}
|
|
19
|
-
await
|
|
43
|
+
await scaffoldLaunchProject(options, undefined, output);
|
|
20
44
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type FailureCategory = 'usage' | 'auth' | 'permission' | 'network' | 'conflict' | 'context' | 'post_commit' | 'internal';
|
|
2
|
+
export declare class CliFailure extends Error {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly nextAction: string;
|
|
5
|
+
readonly category: FailureCategory;
|
|
6
|
+
readonly retryable: boolean;
|
|
7
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
8
|
+
constructor(message: string, code: string, nextAction: string, category: FailureCategory, retryable?: boolean, details?: Record<string, unknown> | undefined);
|
|
9
|
+
}
|
|
10
|
+
/** Preserve existing error fields and exit status; attach actionable safe detail. */
|
|
11
|
+
export declare function describeFailure(error: unknown, command?: string): {
|
|
12
|
+
details?: Record<string, unknown> | undefined;
|
|
13
|
+
error: string;
|
|
14
|
+
code: string;
|
|
15
|
+
nextAction: string;
|
|
16
|
+
category: FailureCategory;
|
|
17
|
+
retryable: boolean;
|
|
18
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CliArgumentError } from './cli-arguments.js';
|
|
2
|
+
import { PostCommitError } from './transaction.js';
|
|
3
|
+
export class CliFailure extends Error {
|
|
4
|
+
code;
|
|
5
|
+
nextAction;
|
|
6
|
+
category;
|
|
7
|
+
retryable;
|
|
8
|
+
details;
|
|
9
|
+
constructor(message, code, nextAction, category, retryable = false, details) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.nextAction = nextAction;
|
|
13
|
+
this.category = category;
|
|
14
|
+
this.retryable = retryable;
|
|
15
|
+
this.details = details;
|
|
16
|
+
this.name = 'CliFailure';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Preserve existing error fields and exit status; attach actionable safe detail. */
|
|
20
|
+
export function describeFailure(error, command) {
|
|
21
|
+
if (error instanceof CliArgumentError)
|
|
22
|
+
return {
|
|
23
|
+
error: error.message,
|
|
24
|
+
code: error.code,
|
|
25
|
+
nextAction: error.nextAction,
|
|
26
|
+
category: 'usage',
|
|
27
|
+
retryable: false,
|
|
28
|
+
};
|
|
29
|
+
if (error instanceof CliFailure)
|
|
30
|
+
return {
|
|
31
|
+
error: error.message,
|
|
32
|
+
code: error.code,
|
|
33
|
+
nextAction: error.nextAction,
|
|
34
|
+
category: error.category,
|
|
35
|
+
retryable: error.retryable,
|
|
36
|
+
...(error.details ? { details: error.details } : {}),
|
|
37
|
+
};
|
|
38
|
+
if (error instanceof PostCommitError)
|
|
39
|
+
return {
|
|
40
|
+
error: error.message,
|
|
41
|
+
code: 'POST_COMMIT_FAILED',
|
|
42
|
+
nextAction: 'The files were kept. Resolve the reported follow-up failure and rerun only that operation in the project directory; do not regenerate the project.',
|
|
43
|
+
category: 'post_commit',
|
|
44
|
+
retryable: false,
|
|
45
|
+
details: { committedPaths: [...error.committedPaths] },
|
|
46
|
+
};
|
|
47
|
+
const code = command === 'init'
|
|
48
|
+
? 'GENERATION_FAILED'
|
|
49
|
+
: command === 'add' || command === 'stack'
|
|
50
|
+
? 'CAPABILITY_COMMAND_FAILED'
|
|
51
|
+
: command === 'ui'
|
|
52
|
+
? 'UI_COMMAND_FAILED'
|
|
53
|
+
: ['login', 'logout', 'whoami', 'link', 'unlink', 'source', 'deploy'].includes(command ?? '')
|
|
54
|
+
? 'PLATFORM_COMMAND_FAILED'
|
|
55
|
+
: 'INTERNAL_ERROR';
|
|
56
|
+
return {
|
|
57
|
+
error: error instanceof Error ? error.message : String(error),
|
|
58
|
+
code,
|
|
59
|
+
nextAction: `Run anhedral ${command && /^[a-z-]+$/.test(command) ? command + ' ' : ''}--help.`,
|
|
60
|
+
category: 'internal',
|
|
61
|
+
retryable: false,
|
|
62
|
+
};
|
|
63
|
+
}
|
package/dist/cli-output.d.ts
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
|
+
export interface CliIO {
|
|
2
|
+
out: {
|
|
3
|
+
write(text: string): unknown;
|
|
4
|
+
};
|
|
5
|
+
err: {
|
|
6
|
+
write(text: string): unknown;
|
|
7
|
+
};
|
|
8
|
+
stdinTTY: boolean;
|
|
9
|
+
stdoutTTY: boolean;
|
|
10
|
+
stderrTTY: boolean;
|
|
11
|
+
ci?: boolean;
|
|
12
|
+
}
|
|
1
13
|
export interface OutputOptions {
|
|
2
14
|
json?: boolean;
|
|
3
15
|
quiet?: boolean;
|
|
16
|
+
human?: boolean;
|
|
17
|
+
nonInteractive?: boolean;
|
|
18
|
+
io?: CliIO;
|
|
4
19
|
}
|
|
20
|
+
/** One output policy for terminal, redirected, and machine consumers. */
|
|
21
|
+
export declare function createReporter(options?: OutputOptions, humanFormatter?: (value: unknown) => string, defaultJson?: boolean): {
|
|
22
|
+
canPrompt: boolean;
|
|
23
|
+
result(value: unknown): void;
|
|
24
|
+
diagnostic(message: string): void;
|
|
25
|
+
progress(message: string): void;
|
|
26
|
+
};
|
|
5
27
|
export declare function formatResult(_command: string, value: unknown): string;
|
|
6
28
|
export declare function printResult(command: string, value: unknown, options?: OutputOptions): void;
|
|
7
29
|
export declare function printProgress(message: string, options?: OutputOptions): void;
|
package/dist/cli-output.js
CHANGED
|
@@ -1,17 +1,52 @@
|
|
|
1
|
+
/** One output policy for terminal, redirected, and machine consumers. */
|
|
2
|
+
export function createReporter(options = {}, humanFormatter = (value) => String(value), defaultJson = false) {
|
|
3
|
+
const json = options.json || (defaultJson && !options.human);
|
|
4
|
+
const ci = options.io?.ci ?? !!(process.env.CI && process.env.CI !== '0' && process.env.CI !== 'false');
|
|
5
|
+
const line = (stream, value) => {
|
|
6
|
+
if (options.io)
|
|
7
|
+
options.io[stream].write(value + '\n');
|
|
8
|
+
else if (stream === 'out')
|
|
9
|
+
console.log(value);
|
|
10
|
+
else
|
|
11
|
+
console.error(value);
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
canPrompt: !options.json &&
|
|
15
|
+
!options.quiet &&
|
|
16
|
+
!options.nonInteractive &&
|
|
17
|
+
!ci &&
|
|
18
|
+
(options.io?.stdinTTY ?? !!process.stdin.isTTY) &&
|
|
19
|
+
(options.io?.stdoutTTY ?? !!process.stdout.isTTY),
|
|
20
|
+
result(value) {
|
|
21
|
+
// Quiet suppresses implicit output, while explicitly requested JSON survives.
|
|
22
|
+
if (options.quiet && !options.json)
|
|
23
|
+
return;
|
|
24
|
+
line('out', json ? JSON.stringify(value, null, defaultJson ? undefined : 2) : humanFormatter(value));
|
|
25
|
+
},
|
|
26
|
+
diagnostic(message) {
|
|
27
|
+
if (!options.json && !options.quiet)
|
|
28
|
+
line('err', message);
|
|
29
|
+
},
|
|
30
|
+
progress(message) {
|
|
31
|
+
if (!json && !options.quiet && (options.io?.stderrTTY ?? !!process.stderr.isTTY))
|
|
32
|
+
line('err', message);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
1
36
|
export function formatResult(_command, value) {
|
|
2
37
|
const data = value;
|
|
3
|
-
|
|
38
|
+
if (data.stack === 'anhedral-stack' && !data.generated)
|
|
39
|
+
return `Foundation preview for ${data.root}.\nStack: Anhedral Stack.\nNo files were written or resources provisioned.`;
|
|
40
|
+
if (data.stack === 'anhedral-stack' && data.generated)
|
|
41
|
+
return `Created ${data.root}.\nStack: Anhedral Stack.\n${data.dependenciesInstalled ? 'Run pnpm dev' : 'Run pnpm install, then pnpm dev'} in the project directory.\nAdd services when needed: anhedral add backend, then anhedral add r2 or anhedral add stripe.\nReview README.md for configuration and deployment.`;
|
|
42
|
+
return (`${data.generated ? 'Created' : 'Foundation preview for'} ${data.root}.\nComponents: ${data.products.join(', ')}.\n` +
|
|
4
43
|
(data.generated
|
|
5
44
|
? 'Review README.md, then run pnpm dev in the project directory. You own development, integrations and hosting.'
|
|
6
45
|
: 'No files were written or resources provisioned.'));
|
|
7
46
|
}
|
|
8
47
|
export function printResult(command, value, options = {}) {
|
|
9
|
-
|
|
10
|
-
console.log(JSON.stringify(value, null, 2));
|
|
11
|
-
else if (!options.quiet)
|
|
12
|
-
console.log(formatResult(command, value));
|
|
48
|
+
createReporter(options, (data) => formatResult(command, data)).result(value);
|
|
13
49
|
}
|
|
14
50
|
export function printProgress(message, options = {}) {
|
|
15
|
-
|
|
16
|
-
console.error(message);
|
|
51
|
+
createReporter(options).progress(message);
|
|
17
52
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Internal synchronous-runner companion. Owns only its spawned command tree.
|
|
2
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
+
import { writeFileSync } from 'node:fs';
|
|
4
|
+
import { readBoundedFile } from './bounded-file.js';
|
|
5
|
+
const [configuration, resultFile] = process.argv.slice(2);
|
|
6
|
+
if (!configuration || !resultFile)
|
|
7
|
+
throw Error('Command runner requires private input and result files.');
|
|
8
|
+
const input = JSON.parse(readBoundedFile(configuration, 1024 * 1024).toString('utf8'));
|
|
9
|
+
if (typeof input.command !== 'string' ||
|
|
10
|
+
!Array.isArray(input.args) ||
|
|
11
|
+
input.args.some((value) => typeof value !== 'string') ||
|
|
12
|
+
typeof input.cwd !== 'string' ||
|
|
13
|
+
!Number.isInteger(input.timeout) ||
|
|
14
|
+
input.timeout < 1 ||
|
|
15
|
+
input.timeout > 1200000 ||
|
|
16
|
+
!Number.isInteger(input.maximum) ||
|
|
17
|
+
input.maximum < 1024 ||
|
|
18
|
+
input.maximum > 16 * 1024 * 1024)
|
|
19
|
+
throw Error('Invalid command runner configuration.');
|
|
20
|
+
const child = spawn(input.command, input.args, {
|
|
21
|
+
cwd: input.cwd,
|
|
22
|
+
shell: false,
|
|
23
|
+
detached: process.platform !== 'win32',
|
|
24
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
25
|
+
windowsHide: true,
|
|
26
|
+
});
|
|
27
|
+
let stdout = Buffer.alloc(0), stderr = Buffer.alloc(0), total = 0, error, completed = false;
|
|
28
|
+
const tail = (previous, chunk) => Buffer.concat([previous, chunk]).subarray(-128 * 1024);
|
|
29
|
+
function stopTree() {
|
|
30
|
+
if (!child.pid)
|
|
31
|
+
return;
|
|
32
|
+
if (process.platform === 'win32')
|
|
33
|
+
spawnSync('taskkill', ['/pid', String(child.pid), '/T', '/F'], {
|
|
34
|
+
shell: false,
|
|
35
|
+
stdio: 'ignore',
|
|
36
|
+
windowsHide: true,
|
|
37
|
+
timeout: 5000,
|
|
38
|
+
});
|
|
39
|
+
else
|
|
40
|
+
try {
|
|
41
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
child.kill('SIGKILL');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const timer = setTimeout(() => {
|
|
48
|
+
error = 'ETIMEDOUT';
|
|
49
|
+
stopTree();
|
|
50
|
+
}, input.timeout);
|
|
51
|
+
function finish(status) {
|
|
52
|
+
if (completed)
|
|
53
|
+
return;
|
|
54
|
+
completed = true;
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
writeFileSync(resultFile, JSON.stringify({
|
|
57
|
+
status,
|
|
58
|
+
error,
|
|
59
|
+
stdout: stdout.toString('base64'),
|
|
60
|
+
stderr: stderr.toString('base64'),
|
|
61
|
+
}), { flag: 'wx', mode: 0o600 });
|
|
62
|
+
}
|
|
63
|
+
for (const [stream, name] of [
|
|
64
|
+
[child.stdout, 'stdout'],
|
|
65
|
+
[child.stderr, 'stderr'],
|
|
66
|
+
])
|
|
67
|
+
stream.on('data', (chunk) => {
|
|
68
|
+
total += chunk.length;
|
|
69
|
+
if (name === 'stdout')
|
|
70
|
+
stdout = tail(stdout, chunk);
|
|
71
|
+
else
|
|
72
|
+
stderr = tail(stderr, chunk);
|
|
73
|
+
if (input.verbose)
|
|
74
|
+
process[name].write(chunk);
|
|
75
|
+
if (total > input.maximum && !error) {
|
|
76
|
+
error = 'ENOBUFS';
|
|
77
|
+
stopTree();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
child.on('error', () => {
|
|
81
|
+
error = 'SPAWN_FAILED';
|
|
82
|
+
stopTree();
|
|
83
|
+
finish(null);
|
|
84
|
+
});
|
|
85
|
+
// A parent can exit while its children keep pipes open. Kill its group on exit,
|
|
86
|
+
// not only after close, so pipe-holding descendants cannot strand the caller.
|
|
87
|
+
child.on('exit', () => stopTree());
|
|
88
|
+
child.on('close', (status) => finish(status));
|
package/dist/command-schema.d.ts
CHANGED
|
@@ -7,6 +7,15 @@ export interface CommandOption {
|
|
|
7
7
|
arity?: 'required' | 'optional';
|
|
8
8
|
repeatable?: boolean;
|
|
9
9
|
hidden?: boolean;
|
|
10
|
+
kind?: 'file' | 'directory' | 'value';
|
|
11
|
+
choices?: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
export interface CommandPositional {
|
|
14
|
+
name: string;
|
|
15
|
+
min: number;
|
|
16
|
+
max: number;
|
|
17
|
+
kind?: 'directory' | 'file' | 'capability' | 'component' | 'value';
|
|
18
|
+
choices?: readonly string[];
|
|
10
19
|
}
|
|
11
20
|
export interface CommandDefinition {
|
|
12
21
|
description: string;
|
|
@@ -14,8 +23,15 @@ export interface CommandDefinition {
|
|
|
14
23
|
options: readonly CommandOption[];
|
|
15
24
|
examples: readonly string[];
|
|
16
25
|
note?: string;
|
|
26
|
+
children?: Readonly<Record<string, CommandDefinition>>;
|
|
27
|
+
positional?: CommandPositional;
|
|
28
|
+
conflicts?: readonly (readonly string[])[];
|
|
17
29
|
}
|
|
18
30
|
export declare const GLOBAL_OPTIONS: readonly CommandOption[];
|
|
19
31
|
export declare function optionHelp(option: CommandOption): string;
|
|
20
32
|
export declare function commandDefinition(command: string | undefined): CommandDefinition | undefined;
|
|
21
33
|
export declare const COMMANDS: Readonly<Record<string, CommandDefinition>>;
|
|
34
|
+
/** Complete topic lookup; leaf options are contextual while parser acceptance stays compatible. */
|
|
35
|
+
export declare function commandTopic(topic: readonly string[]): CommandDefinition | undefined;
|
|
36
|
+
/** Family options remain accepted before/after a child for existing scripts. */
|
|
37
|
+
export declare function commandOptions(command: string | undefined): readonly CommandOption[];
|