Skip to content

Commit 6dd0f00

Browse files
committed
feat: fix precommit
1 parent 208299f commit 6dd0f00

6 files changed

Lines changed: 86 additions & 18 deletions

File tree

.mise.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,21 @@ run = "bash scripts/release.sh"
109109
description = "Start opal-server with Erlang distribution"
110110
dir = "opal"
111111
run = "elixir --sname opal -S mix run --no-halt"
112+
113+
114+
# ── CI Preflight ─────────────────────────────────────────────
115+
116+
[tasks."codegen:check"]
117+
description = "Verify codegen is up-to-date"
118+
dir = "opal"
119+
run = "mix run ../scripts/codegen_ts.exs --check"
120+
121+
[tasks.precommit]
122+
description = "Run everything CI checks: deps, codegen, lint, build, test"
123+
depends = ["deps"]
124+
run = [
125+
"mise run codegen:check",
126+
"mise run lint",
127+
"mise run build",
128+
"mise run test",
129+
]

cli/src/sdk/cli-history.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function historyPath(): string {
2929
function readRaw(): Record<string, unknown> {
3030
try {
3131
const data = readFileSync(historyPath(), "utf-8");
32-
const parsed = JSON.parse(data);
33-
return typeof parsed === "object" && parsed !== null ? parsed : {};
32+
const parsed: unknown = JSON.parse(data);
33+
return typeof parsed === "object" && parsed !== null ? (parsed as Record<string, unknown>) : {};
3434
} catch {
3535
return {};
3636
}
@@ -51,8 +51,11 @@ export function readHistory(): HistoryEntry[] {
5151

5252
if (!Array.isArray(history)) return [];
5353
return history.filter(
54-
(e): e is HistoryEntry =>
55-
typeof e === "object" && e !== null && typeof e.text === "string" && typeof e.timestamp === "string",
54+
(e: unknown): e is HistoryEntry =>
55+
typeof e === "object" &&
56+
e !== null &&
57+
typeof (e as HistoryEntry).text === "string" &&
58+
typeof (e as HistoryEntry).timestamp === "string",
5659
);
5760
}
5861

cli/src/sdk/cli-state.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ function statePath(): string {
4444
function readRaw(): StoredState {
4545
try {
4646
const data = readFileSync(statePath(), "utf-8");
47-
const parsed = JSON.parse(data);
48-
return typeof parsed === "object" && parsed !== null ? parsed : {};
47+
const parsed: unknown = JSON.parse(data);
48+
return typeof parsed === "object" && parsed !== null ? (parsed as StoredState) : {};
4949
} catch {
5050
return {};
5151
}
@@ -65,9 +65,7 @@ export function readCliState(): CliState {
6565
lastModel: raw.last_model ?? null,
6666
preferences: {
6767
...DEFAULT_PREFERENCES,
68-
...(typeof raw.preferences === "object" && raw.preferences !== null
69-
? (raw.preferences as Record<string, unknown>)
70-
: {}),
68+
...(typeof raw.preferences === "object" && raw.preferences !== null ? raw.preferences : {}),
7169
},
7270
version: VERSION,
7371
};

cli/src/state/cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export interface CliStateSlice {
3636
/** Load CLI state and command history from local files. */
3737
loadCliState: () => void;
3838
/** Update CLI state to local files. */
39-
updateCliState: (updates: { lastModel?: Record<string, unknown> | null; preferences?: Record<string, unknown> }) => void;
39+
updateCliState: (updates: {
40+
lastModel?: Record<string, unknown> | null;
41+
preferences?: Record<string, unknown>;
42+
}) => void;
4043
/** Add a command to history (persisted to disk). */
4144
addToHistory: (command: string) => void;
4245

cli/src/views/opal-view.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { type FC } from "react";
2-
import { Box } from "ink";
2+
import { Box, Static } from "ink";
33
import { Welcome } from "../components/welcome.js";
44
import { useOpalStore } from "../state/index.js";
55
import { selectFocusedAgent } from "../state/selectors.js";
@@ -38,13 +38,27 @@ export const OpalView: FC = () => {
3838

3939
return (
4040
<Box flexDirection="column">
41-
<Welcome
42-
dimmed={hasEntries}
43-
workingDir={workingDir}
44-
contextFiles={contextFiles}
45-
skills={skills}
46-
distributionNode={distributionNode}
47-
/>
41+
{hasEntries ? (
42+
<Static items={["welcome"] as const} style={{ width: "100%" }}>
43+
{() => (
44+
<Welcome
45+
key="welcome"
46+
dimmed
47+
workingDir={workingDir}
48+
contextFiles={contextFiles}
49+
skills={skills}
50+
distributionNode={distributionNode}
51+
/>
52+
)}
53+
</Static>
54+
) : (
55+
<Welcome
56+
workingDir={workingDir}
57+
contextFiles={contextFiles}
58+
skills={skills}
59+
distributionNode={distributionNode}
60+
/>
61+
)}
4862
<Timeline />
4963
{debugVisible && <DebugPanel />}
5064
<QueuedMessages messages={queuedMessages} />

opal/lib/opal/application.ex

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ defmodule Opal.Application do
77

88
@impl true
99
def start(_type, _args) do
10+
setup_file_logger()
11+
1012
children = [
1113
{Registry, keys: :unique, name: Opal.Registry},
1214
{Registry, keys: :duplicate, name: Opal.Events.Registry},
@@ -79,6 +81,36 @@ defmodule Opal.Application do
7981
|> String.to_atom()
8082
end
8183

84+
defp setup_file_logger do
85+
data_dir =
86+
Application.get_env(:opal, :data_dir) ||
87+
Opal.Config.default_data_dir()
88+
89+
logs_dir = Path.join(Path.expand(data_dir), "logs")
90+
log_file = Path.join(logs_dir, "server.log")
91+
92+
with :ok <- File.mkdir_p(logs_dir),
93+
:ok <-
94+
:logger.add_handler(:file_log, :logger_std_h, %{
95+
config: %{
96+
file: String.to_charlist(log_file),
97+
max_no_bytes: 5_000_000,
98+
max_no_files: 3
99+
},
100+
formatter:
101+
{:logger_formatter,
102+
%{
103+
single_line: true,
104+
template: [:time, " [", :level, "] ", :msg, "\n"]
105+
}}
106+
}) do
107+
:ok
108+
else
109+
{:error, reason} ->
110+
Logger.warning("Could not set up file logging: #{inspect(reason)}")
111+
end
112+
end
113+
82114
defp distribution_cookie do
83115
case Application.get_env(:opal, :distribution_cookie, :random) do
84116
:random -> generate_cookie()

0 commit comments

Comments
 (0)