54a4ca81f9
Bare `omp --list-models` (or any other stale/typoed --flag) was silently consumed by `parseArgs` and the agent went on to start a real session, connect to the configured MCP servers, and hang waiting on the model. Any positional after the unknown flag was reinterpreted as the initial prompt, so a documentation drift turned into an unintended LLM invocation. `parseArgs` now tracks flag-shaped tokens that did not match any built-in or extension-registered flag in a new `unrecognizedFlags: string[]` field, and `reportUnrecognizedFlags` prints a clean `Error: unknown flag(s): …` line plus the `--help` hint. `runRootCommand` invokes the helper right after the post-extension reparse and `process.exit(2)`s before any session, MCP, or initial-message work runs. The validation is gated on the extension-aware reparse, so extension flags (`--spawn-peer`, `--headless`, `--plan`, …) still pass through the same way `applyExtensionFlags` already handles them. `-` (stdin marker) and `--` (POSIX separator) are deliberately allowed through. Fixes #2459
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import type { ImageContent } from "@oh-my-pi/pi-ai";
|
|
import type { Args } from "@oh-my-pi/pi-coding-agent/cli/args";
|
|
import { buildInitialMessage } from "@oh-my-pi/pi-coding-agent/cli/initial-message";
|
|
|
|
function createArgs(messages: string[]): Args {
|
|
return {
|
|
messages,
|
|
fileArgs: [],
|
|
unknownFlags: new Map(),
|
|
unrecognizedFlags: [],
|
|
};
|
|
}
|
|
|
|
describe("buildInitialMessage", () => {
|
|
it("combines stdin, file text, and the first CLI message", () => {
|
|
const parsed = createArgs(["first", "second"]);
|
|
const images: ImageContent[] = [{ type: "image", data: "abc123", mimeType: "image/png" }];
|
|
|
|
const result = buildInitialMessage({
|
|
parsed,
|
|
stdinContent: "stdin",
|
|
fileText: "file-",
|
|
fileImages: images,
|
|
});
|
|
|
|
expect(result.initialMessage).toBe("stdin\nfile-first");
|
|
expect(result.initialImages).toEqual(images);
|
|
expect(parsed.messages).toEqual(["second"]);
|
|
});
|
|
|
|
it("leaves plain CLI messages untouched when there is no initial file or stdin input", () => {
|
|
const parsed = createArgs(["first", "second"]);
|
|
|
|
const result = buildInitialMessage({ parsed });
|
|
|
|
expect(result.initialMessage).toBeUndefined();
|
|
expect(result.initialImages).toBeUndefined();
|
|
expect(parsed.messages).toEqual(["first", "second"]);
|
|
});
|
|
});
|