mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
recipe.mjs and prefs.mjs printed recipe.json and preferences.json values raw: names, workflows, approval dates, brief values, confirmed-in project names, and the known-recipe list in an unknown-name error. Both files travel with a project, so an escape sequence in them could rewrite or hide earlier output, set the window title or write the clipboard in terminals that allow it. The SFX provider's empty-search line repeats the intent, and its Openverse fallback line repeats a network error. Each of those lines now goes through terminalText, like the resolve and adopt lines beside them. --json output is unchanged. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Remembered defaults CLI — the lightweight tier of HyperFrames user memory.
|
|
*
|
|
* node prefs.mjs get --hyperframes . [--json]
|
|
* Print the merged view (project `.media/preferences.json` over user
|
|
* `~/.media/preferences.json`), each key with its source and the receipt
|
|
* material (confirmed_in, updated_at).
|
|
*
|
|
* node prefs.mjs record --hyperframes . --key destination --value x-feed [--workflow <w>]
|
|
* Record one confirmed brief answer into the project tier; the same value
|
|
* confirmed in two different projects promotes the key to the user tier.
|
|
*
|
|
* Consumption rule (references/memory.md): a remembered value becomes the
|
|
* recommended option with a receipt — it never skips a question.
|
|
*/
|
|
import { parseArgs } from "node:util";
|
|
import { mergedPreferences, recordPreference } from "./lib/prefs-store.mjs";
|
|
import { terminalText } from "./lib/terminal-text.mjs";
|
|
|
|
const { values: args, positionals } = parseArgs({
|
|
options: {
|
|
hyperframes: { type: "string", default: "." },
|
|
key: { type: "string" },
|
|
value: { type: "string" },
|
|
workflow: { type: "string" },
|
|
json: { type: "boolean", default: false },
|
|
},
|
|
allowPositionals: true,
|
|
});
|
|
|
|
const verb = positionals[0];
|
|
|
|
function fail(message) {
|
|
console.error(terminalText(message));
|
|
process.exit(1);
|
|
}
|
|
|
|
if (verb === "get") {
|
|
const merged = mergedPreferences(args.hyperframes);
|
|
if (args.json) {
|
|
console.log(JSON.stringify(merged, null, 2));
|
|
} else if (Object.keys(merged).length === 0) {
|
|
console.log("no remembered preferences yet");
|
|
} else {
|
|
for (const [key, entry] of Object.entries(merged)) {
|
|
console.log(
|
|
terminalText(
|
|
`${key} = ${entry.value} (${entry.source}; confirmed in ${entry.confirmed_in.join(", ")})`,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
} else if (verb === "record") {
|
|
if (!args.key || !args.value) fail("record needs --key and --value");
|
|
try {
|
|
const result = recordPreference({
|
|
projectDir: args.hyperframes,
|
|
key: args.key,
|
|
value: args.value,
|
|
workflow: args.workflow,
|
|
});
|
|
const promotion = result.promoted ? "; promoted to user tier" : "";
|
|
console.log(terminalText(`recorded ${result.key} = ${result.value} (project${promotion})`));
|
|
} catch (err) {
|
|
fail(err instanceof Error ? err.message : String(err));
|
|
}
|
|
} else {
|
|
fail(
|
|
"usage: prefs.mjs <get|record> --hyperframes . [--key <k> --value <v> --workflow <w>] [--json]",
|
|
);
|
|
}
|