chore: fix biome lint errors and tune overrides

- Remove duplicate 'prepare' key in package.json
- Allow default exports in rslib.config.ts
- Relax noExplicitAny and noNonNullAssertion in test files
- Auto-fix 17 files (imports, formatting)

小橘 🍊(NEKO Team)
This commit is contained in:
2026-04-24 12:36:57 +00:00
parent 48c81c2e19
commit 7cb7112ed6
19 changed files with 81 additions and 57 deletions
+14 -1
View File
@@ -19,7 +19,7 @@
},
"overrides": [
{
"include": ["tsup.config.ts"],
"include": ["tsup.config.ts", "*/rslib.config.ts"],
"linter": {
"rules": {
"style": {
@@ -27,6 +27,19 @@
}
}
}
},
{
"include": ["**/__tests__/**"],
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "off"
},
"style": {
"noNonNullAssertion": "off"
}
}
}
}
],
"linter": {
+1 -2
View File
@@ -8,8 +8,7 @@
"prepare": "husky",
"build": "pnpm -r run build",
"check": "biome check .",
"format": "biome format --write .",
"prepare": "husky"
"format": "biome format --write ."
},
"devDependencies": {
"@biomejs/biome": "^1.9.0",
+2 -2
View File
@@ -234,7 +234,7 @@ describe("logsCommand negative offset", () => {
it("exits with code 1 and writes to stderr when offset is negative", async () => {
await expect(
logsCommand.run!({
logsCommand.run?.({
args: { n: "50", offset: "-5", follow: false },
rawArgs: [],
cmd: logsCommand as never,
@@ -247,7 +247,7 @@ describe("logsCommand negative offset", () => {
it("exits with code 1 for offset=-1", async () => {
await expect(
logsCommand.run!({
logsCommand.run?.({
args: { n: "10", offset: "-1", follow: false },
rawArgs: [],
cmd: logsCommand as never,
+1 -1
View File
@@ -15,6 +15,7 @@ import { join } from "node:path";
import { createLogStore } from "@uncaged/nerve-store";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import type { LogStore, ThreadRoundRow, WorkflowRun } from "@uncaged/nerve-store";
import {
DEFAULT_THREAD_BUDGET_CHARS,
buildInspectOutput,
@@ -28,7 +29,6 @@ import {
statusIcon,
} from "../commands/workflow.js";
import { triggerWorkflowViaDaemon } from "../daemon-client.js";
import type { LogStore, ThreadRoundRow, WorkflowRun } from "@uncaged/nerve-store";
// ---------------------------------------------------------------------------
// Test helpers
+1 -1
View File
@@ -85,7 +85,7 @@ export function buildLogFooter(slice: LogSlice, nArg: number, logPath: string):
let footer = `\n📄 ${rangeStr} | ${logPath}\n`;
if (slice.nextOffset !== null) {
footer += `⏩ Earlier lines available. Fetch previous page:\n`;
footer += "⏩ Earlier lines available. Fetch previous page:\n";
footer += ` nerve logs --offset ${slice.nextOffset} -n ${nArg}\n`;
}
+1 -2
View File
@@ -1,13 +1,12 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { DatabaseSync } from "node:sqlite";
import type { DatabaseSync } from "node:sqlite";
import { type SenseInfo, isPlainRecord, parseNerveConfig } from "@uncaged/nerve-core";
import { defineCommand } from "citty";
import { listSensesViaDaemon, triggerSenseViaDaemon } from "../daemon-client.js";
import {
assertSenseDbExists,
defaultPreviewSql,
formatRowsAsAlignedTable,
listTableSqlStatements,
+8 -20
View File
@@ -5,8 +5,8 @@ import { isPlainRecord } from "@uncaged/nerve-core";
import { defineCommand } from "citty";
import { stringify } from "yaml";
import { triggerWorkflowViaDaemon } from "../daemon-client.js";
import type { LogStore, ThreadRoundRow, WorkflowRun } from "@uncaged/nerve-store";
import { triggerWorkflowViaDaemon } from "../daemon-client.js";
import { loadDaemonModule } from "../workspace-daemon.js";
import { getNerveRoot, getSocketPath, isRunning } from "../workspace.js";
@@ -218,13 +218,7 @@ export function formatThreadRoundBlock(row: ThreadRoundRow): string {
const { roleStr, contentBody, meta } = partitionWorkflowMessage(row.message);
const yamlBlock =
Object.keys(meta).length === 0 ? "{}\n" : `${stringify(meta, { lineWidth: 100 })}\n`;
return (
`[#${row.round} ${roleStr}] ${formatTs(row.ts)}\n` +
`---\n` +
yamlBlock +
`---\n` +
`${contentBody}\n\n`
);
return `[#${row.round} ${roleStr}] ${formatTs(row.ts)}\n---\n${yamlBlock}---\n${contentBody}\n\n`;
}
export type ThreadCommandOutput = {
@@ -260,14 +254,13 @@ export function buildThreadCommandOutput(
const { roleStr, contentBody, meta } = partitionWorkflowMessage(row.message);
const yamlBlock =
Object.keys(meta).length === 0 ? "{}\n" : `${stringify(meta, { lineWidth: 100 })}\n`;
const header =
`[#${row.round} ${roleStr}] ${formatTs(row.ts)}\n` + `---\n` + yamlBlock + `---\n`;
const maxBody = Math.max(0, remaining - header.length - `[truncated]\n`.length);
const header = `[#${row.round} ${roleStr}] ${formatTs(row.ts)}\n---\n${yamlBlock}---\n`;
const maxBody = Math.max(0, remaining - header.length - "[truncated]\n".length);
const truncated =
maxBody > 0 && contentBody.length > maxBody
? `${contentBody.slice(0, maxBody)}\n[truncated]\n`
: `${contentBody}\n[truncated]\n`;
const single = header + truncated + "\n";
const single = `${header + truncated}\n`;
const hintRound = row.round;
return {
lines: [...prefixLines, single],
@@ -284,9 +277,7 @@ export function buildThreadCommandOutput(
const shownMinRound = picked.length === 0 ? null : Math.min(...picked.map((r) => r.round));
let paginationHint: string | null = null;
if (shownMinRound !== null && shownMinRound > 1) {
paginationHint =
`\n⏩ Older rounds not shown. Fetch with:\n` +
` nerve workflow thread ${runId} --before ${String(shownMinRound)}${budgetFlag}\n`;
paginationHint = `\n⏩ Older rounds not shown. Fetch with:\n nerve workflow thread ${runId} --before ${String(shownMinRound)}${budgetFlag}\n`;
}
return { lines: [...prefixLines, ...blocksAsc], paginationHint };
@@ -455,10 +446,7 @@ const workflowThreadCommand = defineCommand({
const totalRoleRounds = store.getThreadRoundCount(args.runId);
if (totalRoleRounds === 0) {
process.stdout.write(
`🧵 Workflow thread: ${run.runId}\n` +
` workflow: ${run.workflow}\n` +
` status: ${run.status}\n\n` +
`📭 No role rounds recorded for this run.\n`,
`🧵 Workflow thread: ${run.runId}\n workflow: ${run.workflow}\n status: ${run.status}\n\n📭 No role rounds recorded for this run.\n`,
);
return;
}
@@ -469,7 +457,7 @@ const workflowThreadCommand = defineCommand({
});
const prefixLines = [
`🧵 Role rounds (workflow thread)\n`,
"🧵 Role rounds (workflow thread)\n",
` runId: ${run.runId}\n`,
` workflow: ${run.workflow}\n`,
` status: ${run.status}\n`,
+8 -2
View File
@@ -24,5 +24,11 @@ export { ok, err } from "./result.js";
export { parseNerveConfig } from "./config.js";
export { isPlainRecord } from "./is-plain-record.js";
export type { ParsedSenseWorkflowDirective, SenseComputeRoute } from "./sense-workflow-directive.js";
export { parseSenseWorkflowDirective, routeSenseComputeOutput } from "./sense-workflow-directive.js";
export type {
ParsedSenseWorkflowDirective,
SenseComputeRoute,
} from "./sense-workflow-directive.js";
export {
parseSenseWorkflowDirective,
routeSenseComputeOutput,
} from "./sense-workflow-directive.js";
@@ -158,7 +158,10 @@ describe("daemon-ipc — trigger-sense", () => {
expect(resp).toEqual({ ok: true });
expect(triggerSense).not.toHaveBeenCalled();
expect(wfManager.startWorkflow).toHaveBeenCalledWith("my-workflow", { prompt: "test prompt", maxRounds: 10 });
expect(wfManager.startWorkflow).toHaveBeenCalledWith("my-workflow", {
prompt: "test prompt",
maxRounds: 10,
});
});
it("responds ok:false for completely unknown request type", async () => {
@@ -304,7 +304,7 @@ describe("Kernel — workflow hot reload via file-watcher (Phase 3)", () => {
senses: {},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
kernel.reloadConfig(newConfig);
@@ -181,7 +181,7 @@ describe("kernel — reloadConfig", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
});
expect(kernel.groups.has("network")).toBe(true);
@@ -198,7 +198,7 @@ describe("kernel — reloadConfig", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
const kernel = createKernel(config, "/tmp/nerve-test");
@@ -213,7 +213,7 @@ describe("kernel — reloadConfig", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
});
expect(kernel.groups.has("network")).toBe(false);
@@ -236,7 +236,7 @@ describe("kernel — reloadConfig", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
});
expect(kernel.getHealth().activeSenses).toBe(2);
@@ -298,7 +298,7 @@ describe("kernel + workflowManager integration", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
});
const kernel = createKernel(initialConfig, "/tmp/nerve-test", {
@@ -366,7 +366,7 @@ describe("kernel + workflowManager integration", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
kernel.reloadConfig(newConfig);
+1 -1
View File
@@ -201,7 +201,7 @@ describe("kernel — groupForSense mapping", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
const kernel = createKernel(config, "/tmp/nerve-test");
@@ -30,7 +30,7 @@ describe("LogStore + ReflexScheduler integration", () => {
},
reflexes: [{ kind: "sense", sense: "cpu-usage", interval: null, on: ["cpu-usage"] }],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
const bus = createSignalBus();
const triggered: string[] = [];
@@ -58,7 +58,7 @@ describe("LogStore + ReflexScheduler integration", () => {
},
reflexes: [{ kind: "sense", sense: "cpu-usage", interval: 1000, on: null }],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
const bus = createSignalBus();
const ref: { scheduler: ReturnType<typeof createReflexScheduler> | null } = { scheduler: null };
@@ -89,7 +89,7 @@ describe("LogStore + ReflexScheduler integration", () => {
},
reflexes: [{ kind: "sense", sense: "cpu-usage", interval: null, on: ["cpu-usage"] }],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
const bus = createSignalBus();
const triggered: string[] = [];
@@ -137,7 +137,7 @@ describe("phase6 — reloadConfig", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
kernel.reloadConfig(newConfig);
@@ -157,7 +157,7 @@ describe("phase6 — reloadConfig", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
kernel = createKernel(config, "/tmp/nerve-phase6-test", {
workerScript: MOCK_WORKER,
@@ -172,7 +172,7 @@ describe("phase6 — reloadConfig", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
kernel.reloadConfig(newConfig);
@@ -203,7 +203,7 @@ describe("phase6 — error isolation", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
kernel = createKernel(config, "/tmp/nerve-phase6-test", {
@@ -307,7 +307,7 @@ describe("phase6 — getHealth", () => {
},
reflexes: [],
workflows: null,
maxRounds: 10,
maxRounds: 10,
};
kernel.reloadConfig(newConfig);
+10 -2
View File
@@ -59,7 +59,12 @@ function parseRequest(line: string): DaemonRequest | null {
if (typeof req.workflow !== "string" || req.workflow.length === 0) return null;
if (typeof req.prompt !== "string") return null;
if (typeof req.maxRounds !== "number") return null;
return { type: "trigger-workflow", workflow: req.workflow, prompt: req.prompt, maxRounds: req.maxRounds };
return {
type: "trigger-workflow",
workflow: req.workflow,
prompt: req.prompt,
maxRounds: req.maxRounds,
};
}
if (req.type === "trigger-sense") {
if (typeof req.sense !== "string" || req.sense.length === 0) return null;
@@ -106,7 +111,10 @@ export function createDaemonIpcServer(
try {
if (req.type === "trigger-workflow") {
workflowManager.startWorkflow(req.workflow, { prompt: req.prompt, maxRounds: req.maxRounds });
workflowManager.startWorkflow(req.workflow, {
prompt: req.prompt,
maxRounds: req.maxRounds,
});
const resp: DaemonResponse = { ok: true };
socket.write(`${JSON.stringify(resp)}\n`);
} else if (req.type === "trigger-sense") {
+3 -1
View File
@@ -296,7 +296,9 @@ const WORKER_MSG_TYPES = new Set([
"thread-workflow-message",
]);
function parseThreadWorkflowMessageMsg(obj: Record<string, unknown>): Result<WorkerToParentMessage> {
function parseThreadWorkflowMessageMsg(
obj: Record<string, unknown>,
): Result<WorkerToParentMessage> {
if (typeof obj.runId !== "string") {
return err(new Error("Worker 'thread-workflow-message' missing string 'runId' field"));
}
+3 -3
View File
@@ -110,9 +110,9 @@ export function runMigrations(sqlite: DatabaseSync, migrationsDir: string): Resu
const migrationRows = sqlite.prepare("SELECT name FROM _migrations").all();
const applied = new Set<string>(
migrationRows.filter((r): r is { name: string } => isPlainRecord(r) && typeof r.name === "string").map(
(r) => r.name,
),
migrationRows
.filter((r): r is { name: string } => isPlainRecord(r) && typeof r.name === "string")
.map((r) => r.name),
);
for (const file of filesResult.value) {
+9 -3
View File
@@ -14,6 +14,7 @@ import { fileURLToPath } from "node:url";
import type { NerveConfig, WorkflowConfig, WorkflowMessage } from "@uncaged/nerve-core";
import { START, isPlainRecord } from "@uncaged/nerve-core";
import type { LogStore, WorkflowRunStatus } from "@uncaged/nerve-store";
import type {
ResumeThreadMessage,
ShutdownMessage,
@@ -21,7 +22,6 @@ import type {
ThreadEventMessage,
} from "./ipc.js";
import { parseWorkerMessage } from "./ipc.js";
import type { LogStore, WorkflowRunStatus } from "@uncaged/nerve-store";
import {
formatCapturedStderrTail,
formatChildExitSummary,
@@ -307,7 +307,10 @@ export function createWorkflowManager(
function recoverQueuedRun(workflowName: string, runId: string, state: WorkflowState): void {
if (state.queue.some((q) => q.runId === runId)) return;
const launch = readLaunchFromTriggerPayload(logStore.getTriggerPayload(runId), config.maxRounds);
const launch = readLaunchFromTriggerPayload(
logStore.getTriggerPayload(runId),
config.maxRounds,
);
state.queue.push({ runId, prompt: launch.prompt, maxRounds: launch.maxRounds });
process.stderr.write(
`[workflow-manager] crash-recovery: re-queued thread "${runId}" for "${workflowName}"\n`,
@@ -322,7 +325,10 @@ export function createWorkflowManager(
): void {
if (state.active.has(runId)) return;
const rawMessages = logStore.getThreadMessages(runId);
const launch = readLaunchFromTriggerPayload(logStore.getTriggerPayload(runId), config.maxRounds);
const launch = readLaunchFromTriggerPayload(
logStore.getTriggerPayload(runId),
config.maxRounds,
);
const messages = ensureThreadMessagesWithStart(rawMessages, launch.prompt, launch.maxRounds);
state.active.add(runId);
const msg: ResumeThreadMessage = {