mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 16:37:32 +00:00
fix(cli): a catalog gap report hands back a line only when every shell reads the query as text (#8373)
* test(cli): a catalog gap report never carries a query a shell would run * fix(cli): a catalog gap report hands back a line only when every shell reads the query as text * test(cli): type the envelope's query and expect sh double quotes around an apostrophe
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// fallow-ignore-file code-duplication
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, onTestFinished, vi } from "vitest";
|
||||
import { runCommand, type CommandDef } from "citty";
|
||||
|
||||
import type { RegistryItem } from "@hyperframes/core";
|
||||
import { catalogRow, countUnindexed, pickByName, searchMissCommand } from "./catalog.js";
|
||||
import { catalogRow, countUnindexed, pickByName, searchMissReport } from "./catalog.js";
|
||||
|
||||
/** The whole registry, which is what "in this registry" has to be measured against. */
|
||||
const registryNames = new Set(["fade-through", "whip-pan", "count-up"]);
|
||||
@@ -205,6 +205,7 @@ const component = (name: string): { name: string; type: string } => ({
|
||||
});
|
||||
|
||||
interface Envelope {
|
||||
query: string;
|
||||
tier: string;
|
||||
dropped: number;
|
||||
unindexed: number;
|
||||
@@ -536,6 +537,21 @@ describe("catalog --json meaning search", () => {
|
||||
);
|
||||
});
|
||||
|
||||
// fails without the fix: on Windows the envelope carried a bash-escaped line that runs "$(calc)" in PowerShell.
|
||||
it("on Windows, hands back how to report the gap, not a line that would run the query", async () => {
|
||||
const platform = Object.getOwnPropertyDescriptor(process, "platform")!;
|
||||
Object.defineProperty(process, "platform", { value: "win32" });
|
||||
onTestFinished(() => {
|
||||
Object.defineProperty(process, "platform", platform);
|
||||
});
|
||||
|
||||
const envelope = await runEnvelope({ query: "count up $(calc)" });
|
||||
|
||||
expect(envelope.query).toBe("count up $(calc)");
|
||||
expect(envelope.report_gap).not.toContain("$(calc)");
|
||||
expect(envelope.report_gap).toContain("--search-miss");
|
||||
});
|
||||
|
||||
it("names the tier that actually answered in the gap-report command", async () => {
|
||||
state.modelStatus = "declined";
|
||||
state.ranking = null;
|
||||
@@ -676,19 +692,51 @@ describe("a zero-result search", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("searchMissCommand", () => {
|
||||
it("keeps a non-ASCII query intact", () => {
|
||||
// Each one keeps a shell meaning in PowerShell or cmd.exe however it is double-quoted.
|
||||
const WINDOWS_LIVE_QUERIES = [
|
||||
"$(calc)",
|
||||
"a`b",
|
||||
"o'neil $x",
|
||||
"x\u201D;calc;\u201Dy",
|
||||
"x\u2019;calc;\u2018 $y",
|
||||
"$(calc)&calc",
|
||||
"\u201Cquoted\u201D",
|
||||
"%USERPROFILE%",
|
||||
"50% off, 20% more",
|
||||
"Hello!",
|
||||
"a!b",
|
||||
'say "hi" & calc',
|
||||
];
|
||||
|
||||
describe("searchMissReport", () => {
|
||||
it("keeps a non-ASCII query intact, on Windows and elsewhere", () => {
|
||||
// Half of the gap reports received so far were CJK. A query mangled on the
|
||||
// way into the command is a report nobody can act on.
|
||||
expect(searchMissCommand("実写写真のみ 9:16 生活ハック", "on-device")).toContain(
|
||||
'--search-miss "実写写真のみ 9:16 生活ハック"',
|
||||
);
|
||||
for (const platform of ["win32", "linux"] as const) {
|
||||
expect(searchMissReport("実写写真のみ 9:16 生活ハック", "on-device", platform)).toBe(
|
||||
'npx hyperframes feedback --search-miss "実写写真のみ 9:16 生活ハック" ' +
|
||||
'--wanted "<the move you needed>" --tier on-device',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("escapes shell metacharacters so the printed line is safe to paste", () => {
|
||||
const cmd = searchMissCommand('a "quoted" $VAR `sub` \\ thing', "words");
|
||||
// fails without the fix: the query was put in a bash-escaped line on every platform, where a backslash escapes
|
||||
// nothing in PowerShell or cmd.exe, so running the line ran part of the query.
|
||||
it("never puts a query PowerShell or cmd.exe would read as code into a line on Windows", () => {
|
||||
for (const query of WINDOWS_LIVE_QUERIES) {
|
||||
const report = searchMissReport(query, "words", "win32");
|
||||
expect(report, query).not.toContain(query);
|
||||
expect(report, query).not.toMatch(/^npx /);
|
||||
expect(report, query).toContain("--tier words");
|
||||
}
|
||||
});
|
||||
|
||||
expect(cmd).toContain('--search-miss "a \\"quoted\\" \\$VAR \\`sub\\` \\\\ thing"');
|
||||
it("quotes a query with shell syntax as one literal word for sh, bash and zsh", () => {
|
||||
expect(searchMissReport('a "quoted" $VAR `sub` \\ thing!', "words", "linux")).toBe(
|
||||
"npx hyperframes feedback --search-miss 'a \"quoted\" $VAR `sub` \\ thing!' " +
|
||||
'--wanted "<the move you needed>" --tier words',
|
||||
);
|
||||
expect(searchMissReport("o'neil", "words", "darwin")).toContain(`--search-miss "o'neil"`);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import { relative, resolve } from "node:path";
|
||||
import { CliUsageError, finishCommand } from "../utils/commandResult.js";
|
||||
import { printFailureLine } from "../utils/jsonError.js";
|
||||
import { isUnattended } from "../utils/attendedTerminal.js";
|
||||
import { shellArg } from "../utils/shellArg.js";
|
||||
import { runAdd } from "./add.js";
|
||||
import { hasNoSearchableTokens, searchByWords } from "../registry/localSearch.js";
|
||||
import {
|
||||
@@ -342,9 +343,7 @@ export default defineCommand({
|
||||
// Withheld when the query never parsed: the catalog has not been
|
||||
// shown to be missing anything, so inviting a gap report here
|
||||
// would file noise against a search that never ran.
|
||||
...(unsearchable
|
||||
? {}
|
||||
: { report_gap: searchMissCommand(query, tierToken(searched)) }),
|
||||
...(unsearchable ? {} : { report_gap: searchMissReport(query, tierToken(searched)) }),
|
||||
results: [],
|
||||
},
|
||||
null,
|
||||
@@ -379,7 +378,7 @@ export default defineCommand({
|
||||
if (query) {
|
||||
console.log("");
|
||||
console.log(c.dim(" Nothing in the catalog does this? Report the gap:"));
|
||||
console.log(c.dim(` ${searchMissHint(query, tierToken(searched))}`));
|
||||
console.log(c.dim(` ${searchMissReport(query, tierToken(searched))}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,7 +416,7 @@ export default defineCommand({
|
||||
// plausible items and none of them did the thing — a judgement
|
||||
// only the reader can make, so the command has to already be in
|
||||
// the envelope by the time they make it.
|
||||
report_gap: searchMissCommand(query, tierToken(searched)),
|
||||
report_gap: searchMissReport(query, tierToken(searched)),
|
||||
results: output,
|
||||
},
|
||||
null,
|
||||
@@ -471,7 +470,9 @@ export default defineCommand({
|
||||
// in. Every catalog gap reported to date came from the word tier. The
|
||||
// tier rides along in the command so a vocabulary miss stays
|
||||
// distinguishable from a meaning miss when the reports are read.
|
||||
console.log(c.dim(` None of these do it? ${searchMissHint(query, tierToken(searched))}`));
|
||||
console.log(
|
||||
c.dim(` None of these do it? ${searchMissReport(query, tierToken(searched))}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -699,7 +700,8 @@ function tierDetail(searched: { localMode: LocalMode } | null): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* The command that turns a fruitless search into a catalog gap report.
|
||||
* The command that turns a fruitless search into a catalog gap report, or how
|
||||
* to send one when no line would carry the query as typed in the user's shell.
|
||||
*
|
||||
* A search that returns nothing usable is the only moment anyone knows what
|
||||
* the catalog is missing, and it was also the one moment we said nothing:
|
||||
@@ -712,23 +714,21 @@ function tierDetail(searched: { localMode: LocalMode } | null): string {
|
||||
* so plain `catalog --query` keeps its promise that the query text never
|
||||
* leaves the machine.
|
||||
*/
|
||||
export function searchMissCommand(query: string, tier: "on-device" | "words"): string {
|
||||
// Double quotes with the shell metacharacters escaped: the queries that
|
||||
// matter are plain-language phrases, and half the real ones so far were
|
||||
// CJK, which single-quoting renders no more safely and reads worse.
|
||||
const quoted = query.replace(/(["\\$`])/g, "\\$1");
|
||||
export function searchMissReport(
|
||||
query: string,
|
||||
tier: "on-device" | "words",
|
||||
platform: NodeJS.Platform = process.platform,
|
||||
): string {
|
||||
const searched = shellArg(query, platform);
|
||||
if (searched === null) {
|
||||
return `Run hyperframes feedback with your query as --search-miss, the move you needed as --wanted, and --tier ${tier}.`;
|
||||
}
|
||||
return (
|
||||
`npx hyperframes feedback --search-miss "${quoted}" ` +
|
||||
`npx hyperframes feedback --search-miss ${searched} ` +
|
||||
`--wanted "<the move you needed>" --tier ${tier}`
|
||||
);
|
||||
}
|
||||
|
||||
function searchMissHint(query: string, tier: "on-device" | "words"): string {
|
||||
const command = searchMissCommand(query, tier);
|
||||
if (terminalText(command) === command) return command;
|
||||
return `Run hyperframes feedback with your query as --search-miss, the move you needed as --wanted, and --tier ${tier}.`;
|
||||
}
|
||||
|
||||
type LocalMode = "local-model" | "words";
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"files": 14
|
||||
},
|
||||
"hyperframes-registry": {
|
||||
"hash": "25e0d7a72fe285a0",
|
||||
"hash": "763e9fc772b54dbe",
|
||||
"files": 13
|
||||
},
|
||||
"media-use": {
|
||||
|
||||
@@ -23,7 +23,7 @@ npx hyperframes add <name> --json # prints the written files and the moun
|
||||
- Query in English even when the video is not: the catalog is indexed in English, and another script returns `No searchable words in query`, which is not a gap.
|
||||
- Search is local and sends nothing. The default `words` tier only finds items that reuse your words; `--on-device` ranks by meaning after a one-time ~33 MB download. Offer that download and let the person decide; never enable it silently. The `--json` envelope names the tier that answered.
|
||||
- Narrow with `--type block|component` and `--tag <tag>`. `add <tag>` installs every block with that tag; dependencies install first. `add` needs the network even for an item installed before; search works offline from the cached manifest.
|
||||
- Nothing fits: report it before you hand-build, on either tier. `catalog --query` prints the line pre-filled (`report_gap` in `--json`): `npx hyperframes feedback --search-miss "<query>" --wanted "<the move you needed>" --tier <tier>`. Describe the effect, not an item name you imagined.
|
||||
- Nothing fits: report it before you hand-build, on either tier. `catalog --query` prints the line pre-filled (`report_gap` in `--json`): `npx hyperframes feedback --search-miss "<query>" --wanted "<the move you needed>" --tier <tier>`. When the query holds text your shell would run, `report_gap` is a sentence instead: build the line from `query` and `tier`, quoted for your shell. Describe the effect, not an item name you imagined.
|
||||
|
||||
Tiers, `dropped` and `unindexed`, stale indexes, offline behaviour: `references/search.md`.
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ When the search comes back and nothing in it does the job, say so before you han
|
||||
npx hyperframes feedback --search-miss "<the query you ran>" --wanted "<the move you needed>" --tier <the tier that answered>
|
||||
```
|
||||
|
||||
`catalog --query` prints this line for you, pre-filled, and `--json` carries it as `report_gap` — so it is already in hand at the moment you decide nothing fits.
|
||||
`catalog --query` prints this line for you, pre-filled, and `--json` carries it as `report_gap` — so it is already in hand at the moment you decide nothing fits. When the query holds characters your shell would read as code (on Windows, `$(`, `"`, a backtick, `!` or `%NAME%`), no line is pre-filled: `report_gap` says how to report instead, and you pass the envelope's `query` and `tier` as separate arguments, quoted for your own shell.
|
||||
|
||||
**Report whenever nothing in the results does the job, on either tier.** Do not wait for the on-device tier to have answered: it needs a consented 33 MB download, so an agent run is on `words` unless it explicitly opted in, and gating on `on-device` would silence almost every report. The `--tier` value rides along so a vocabulary miss stays distinguishable from a meaning miss when these are read. Describe the effect you wanted, not the item name you imagined: what comes back is a list of moves worth building, and a report naming a non-existent item teaches nothing. This is the only path that sends a query anywhere, which is exactly why it is a separate deliberate command rather than something the search does on its own. It carries no rating and never lands in the rating metric.
|
||||
|
||||
@@ -63,5 +63,5 @@ See [discovery.md](./discovery.md) for details on filtering by type and tags.
|
||||
- **Query in English even when the video is not.** Both tiers index an English catalog, so a query in another script produces no searchable terms and returns nothing. Describe the move in English; the on-screen copy stays in whatever language the video needs. `No searchable words in query` means exactly this and is not a missing component, so do not report it as a catalog gap.
|
||||
- **Read which tier answered; never infer it from results appearing.** With `--json` the envelope carries `query`, `tier` (`on-device` or `words`), `tier_detail`, `dropped`, `unindexed`, `shown`, `total` and `results`, plus `top_score` when the answering tier produces one and `warnings` when a tier was asked for and could not run, or when a search returned nothing and a better tier is still waiting on someone's consent. A weak result on `words` is expected; the same result on `on-device` is a bug. `top_score` is on-device only and has no threshold behind it: the ranker returns the whole catalog in some order for every query, so read it as evidence rather than as a pass or fail.
|
||||
- **`dropped` and `unindexed` are opposite skews between the registry and the on-device index, and rewording the query fixes neither.** `dropped` counts ranked names this registry cannot install, so the strongest matches are the ones being lost. `unindexed` counts registry moves the index cannot see at all, which no query can ever return. Refreshing the registry is not the answer to either: its manifest carries a 24h TTL and heals itself, while the vectors are a separately published artifact fetched into `~/.hyperframes/catalog/`. Re-running with `--on-device` refetches that index when `unindexed` is above zero, so that is the remedy to hand the user. A pure over-coverage skew (`dropped` above zero while `unindexed` is zero) does not trigger the refetch; clearing `~/.hyperframes/catalog/` is the only way out of that one. Both counts are of names rather than of results, so either can exceed `total`.
|
||||
- **When a search comes back with nothing worth installing, say so.** `npx hyperframes feedback --search-miss "<the query you ran>" --wanted "<the move you needed>" --tier <the tier that answered>`. You do not have to assemble that line: `catalog --query` prints it pre-filled, and every `--json` search envelope carries it as `report_gap` with the query and tier already correct — fill in `--wanted` and send. This is the only path that sends a query anywhere, and it is a separate deliberate command precisely so plain `catalog --query` keeps its promise of sending nothing. **Report on either tier**, whenever the results do not do the thing; do not hold out for the on-device tier, which needs a consented 33 MB download and is therefore off in most agent runs — waiting for it means never reporting at all. The tier rides along in the report, so a vocabulary miss stays distinguishable from a meaning miss without you having to judge which one you hit. What comes back is a list of moves the catalog does not have yet, read directly rather than guessed from install counts, so the phrasing that matters is the effect you wanted, not the item name you imagined. It carries no rating and never lands in the rating metric.
|
||||
- **When a search comes back with nothing worth installing, say so.** `npx hyperframes feedback --search-miss "<the query you ran>" --wanted "<the move you needed>" --tier <the tier that answered>`. You do not have to assemble that line: `catalog --query` prints it pre-filled, and every `--json` search envelope carries it as `report_gap` with the query and tier already correct — fill in `--wanted` and send. When `report_gap` is a sentence rather than a line, build the line yourself from `query` and `tier`, quoted for your shell. This is the only path that sends a query anywhere, and it is a separate deliberate command precisely so plain `catalog --query` keeps its promise of sending nothing. **Report on either tier**, whenever the results do not do the thing; do not hold out for the on-device tier, which needs a consented 33 MB download and is therefore off in most agent runs — waiting for it means never reporting at all. The tier rides along in the report, so a vocabulary miss stays distinguishable from a meaning miss without you having to judge which one you hit. What comes back is a list of moves the catalog does not have yet, read directly rather than guessed from install counts, so the phrasing that matters is the effect you wanted, not the item name you imagined. It carries no rating and never lands in the rating metric.
|
||||
- **Offer the offline tier; never enable it silently.** A one-time ~33 MB download (a quantized ONNX build of `bge-small-en-v1.5` plus its tokenizer, pinned to a fixed revision) and the catalog vectors from the registry, both cached under `~/.hyperframes/`, neither added to the project or any package. Once cached it ranks by meaning with nothing sent. Say the size out loud and let the person decide, then pass `--on-device` (with `-y` to skip the prompt) once they agree. The interactive offer only fires on a TTY. Under `--json` there is no prompt, but a search that found nothing puts the same ask in `warnings`, so read that array and put the decision to the user yourself. When the person asks what the download is, why this model, or what leaves the machine, point them to https://hyperframes.heygen.com/developers/catalog-search.
|
||||
|
||||
Reference in New Issue
Block a user