@hongymagic/q 2026.227.1 → 2026.302.0-next.db67a88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/q.js +89 -3
  2. package/package.json +1 -1
package/dist/q.js CHANGED
@@ -14586,12 +14586,62 @@ var init_clipboardy = __esm(() => {
14586
14586
  clipboardy_default = clipboard7;
14587
14587
  });
14588
14588
 
14589
+ // src/ansi.ts
14590
+ var exports_ansi = {};
14591
+ __export(exports_ansi, {
14592
+ stripAnsi: () => stripAnsi2,
14593
+ sanitizeForClipboard: () => sanitizeForClipboard,
14594
+ createAnsiStripper: () => createAnsiStripper2
14595
+ });
14596
+ function stripAnsi2(str) {
14597
+ if (!str)
14598
+ return str;
14599
+ return str.replace(ANSI_REGEX2, "");
14600
+ }
14601
+ function sanitizeForClipboard(str) {
14602
+ if (!str)
14603
+ return str;
14604
+ const stripped = stripAnsi2(str);
14605
+ return stripped.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, (char) => {
14606
+ const hex3 = char.charCodeAt(0).toString(16).padStart(2, "0").toUpperCase();
14607
+ return `\\x${hex3}`;
14608
+ });
14609
+ }
14610
+ function createAnsiStripper2() {
14611
+ let buffer = "";
14612
+ return (chunk) => {
14613
+ buffer += chunk;
14614
+ const lastEscIndex = Math.max(buffer.lastIndexOf("\x1B"), buffer.lastIndexOf("›"));
14615
+ if (lastEscIndex !== -1) {
14616
+ const safePart = buffer.slice(0, lastEscIndex);
14617
+ const remainder = buffer.slice(lastEscIndex);
14618
+ if (ANSI_REGEX2.test(remainder)) {
14619
+ const full = buffer;
14620
+ buffer = "";
14621
+ return stripAnsi2(full);
14622
+ }
14623
+ buffer = remainder;
14624
+ return stripAnsi2(safePart);
14625
+ }
14626
+ const output = stripAnsi2(buffer);
14627
+ buffer = "";
14628
+ return output;
14629
+ };
14630
+ }
14631
+ var ANSI_REGEX2;
14632
+ var init_ansi = __esm(() => {
14633
+ ANSI_REGEX2 = new RegExp([
14634
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
14635
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
14636
+ ].join("|"), "g");
14637
+ });
14638
+
14589
14639
  // src/args.ts
14590
14640
  import { parseArgs } from "node:util";
14591
14641
  // package.json
14592
14642
  var package_default = {
14593
14643
  name: "@hongymagic/q",
14594
- version: "2026.227.1",
14644
+ version: "2026.302.0-next.db67a88",
14595
14645
  description: "Quick AI answers from the command line",
14596
14646
  main: "dist/q.js",
14597
14647
  type: "module",
@@ -67684,6 +67734,38 @@ var _a20;
67684
67734
  _a20 = symbol20;
67685
67735
  var defaultDownload2 = createDownload();
67686
67736
 
67737
+ // src/ansi.ts
67738
+ var ANSI_REGEX = new RegExp([
67739
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
67740
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
67741
+ ].join("|"), "g");
67742
+ function stripAnsi(str) {
67743
+ if (!str)
67744
+ return str;
67745
+ return str.replace(ANSI_REGEX, "");
67746
+ }
67747
+ function createAnsiStripper() {
67748
+ let buffer = "";
67749
+ return (chunk) => {
67750
+ buffer += chunk;
67751
+ const lastEscIndex = Math.max(buffer.lastIndexOf("\x1B"), buffer.lastIndexOf("›"));
67752
+ if (lastEscIndex !== -1) {
67753
+ const safePart = buffer.slice(0, lastEscIndex);
67754
+ const remainder = buffer.slice(lastEscIndex);
67755
+ if (ANSI_REGEX.test(remainder)) {
67756
+ const full = buffer;
67757
+ buffer = "";
67758
+ return stripAnsi(full);
67759
+ }
67760
+ buffer = remainder;
67761
+ return stripAnsi(safePart);
67762
+ }
67763
+ const output = stripAnsi(buffer);
67764
+ buffer = "";
67765
+ return output;
67766
+ };
67767
+ }
67768
+
67687
67769
  // src/prompt.ts
67688
67770
  function buildUserPrompt(query, context2) {
67689
67771
  if (!context2) {
@@ -67708,8 +67790,10 @@ async function runQuery(options) {
67708
67790
  prompt: userPrompt
67709
67791
  });
67710
67792
  let fullText = "";
67793
+ const stripper = createAnsiStripper();
67711
67794
  for await (const textPart of result.textStream) {
67712
- process.stdout.write(textPart);
67795
+ const safeText = stripper(textPart);
67796
+ process.stdout.write(safeText);
67713
67797
  fullText += textPart;
67714
67798
  }
67715
67799
  if (!fullText.endsWith(`
@@ -67835,7 +67919,9 @@ async function main() {
67835
67919
  const shouldCopy = !args.options.noCopy && (args.options.copy || config2.default.copy);
67836
67920
  if (shouldCopy) {
67837
67921
  const { default: clipboard8 } = await Promise.resolve().then(() => (init_clipboardy(), exports_clipboardy));
67838
- await clipboard8.write(result.text);
67922
+ const { sanitizeForClipboard: sanitizeForClipboard2 } = await Promise.resolve().then(() => (init_ansi(), exports_ansi));
67923
+ const safeClipboardText = sanitizeForClipboard2(result.text);
67924
+ await clipboard8.write(safeClipboardText);
67839
67925
  logDebug2("Copied to clipboard", debug);
67840
67926
  }
67841
67927
  process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hongymagic/q",
3
- "version": "2026.227.1",
3
+ "version": "2026.302.0-next.db67a88",
4
4
  "description": "Quick AI answers from the command line",
5
5
  "main": "dist/q.js",
6
6
  "type": "module",