-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
70 lines (66 loc) · 2 KB
/
index.ts
File metadata and controls
70 lines (66 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bun
import { Command, ValidationError } from "@effect/cli";
import { BunContext, BunRuntime } from "@effect/platform-bun";
import { Clock, Effect, Layer } from "effect";
import { app } from "./src/cli/app.js";
import pkg from "./package.json" with { type: "json" };
import { logErrorEvent } from "./src/cli/logging.js";
import { CliOutput } from "./src/cli/output.js";
import { exitCodeFor, exitCodeFromExit } from "./src/cli/exit-codes.js";
import {
errorDetails,
errorCode,
errorSuggestion,
errorType,
formatErrorEnvelope,
formatErrorMessage,
getAgentPayload,
jsonErrorsEnabled,
makeErrorEnvelope
} from "./src/cli/error-envelope.js";
import { relocateGlobalOptions } from "./src/cli/argv.js";
const cli = Command.run(app, {
name: "skygent",
version: pkg.version
});
const program = cli(relocateGlobalOptions(process.argv)).pipe(
Effect.tapError((error) => {
const agentPayload = getAgentPayload(error);
const code = exitCodeFor(error);
if (jsonErrorsEnabled()) {
const envelope = makeErrorEnvelope(error, code, agentPayload);
return Effect.flatMap(CliOutput, (output) =>
output.writeStderr(formatErrorEnvelope(envelope))
);
}
if (ValidationError.isValidationError(error)) {
return Effect.void;
}
return logErrorEvent(formatErrorMessage(error, agentPayload), {
code,
errorCode: errorCode(error, agentPayload),
type: errorType(error, agentPayload),
suggestion: errorSuggestion(error, agentPayload),
...errorDetails(error, agentPayload)
});
}),
Effect.provide(
Layer.mergeAll(
BunContext.layer,
CliOutput.layer,
Layer.succeed(Clock.Clock, Clock.make())
)
)
);
const runnable = program as Effect.Effect<void, unknown>;
BunRuntime.runMain({
disableErrorReporting: true,
disablePrettyLogger: true,
teardown: (exit, onExit) => {
const code = exitCodeFromExit(exit);
onExit(code);
if (typeof process !== "undefined") {
process.exit(code);
}
}
})(runnable);