@hongymagic/q 0.4.0 → 0.5.0

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 +135 -9
  2. package/package.json +1 -1
package/dist/q.js CHANGED
@@ -13301,6 +13301,73 @@ var clipboardy_default = clipboard7;
13301
13301
 
13302
13302
  // src/args.ts
13303
13303
  import { parseArgs } from "node:util";
13304
+ // package.json
13305
+ var package_default = {
13306
+ name: "@hongymagic/q",
13307
+ version: "0.5.0",
13308
+ description: "Quick AI answers from the command line",
13309
+ main: "dist/q.js",
13310
+ type: "module",
13311
+ bin: {
13312
+ q: "dist/q.js"
13313
+ },
13314
+ files: [
13315
+ "dist"
13316
+ ],
13317
+ repository: {
13318
+ type: "git",
13319
+ url: "git+https://github.com/hongymagic/q.git"
13320
+ },
13321
+ homepage: "https://github.com/hongymagic/q#readme",
13322
+ bugs: {
13323
+ url: "https://github.com/hongymagic/q/issues"
13324
+ },
13325
+ keywords: [
13326
+ "cli",
13327
+ "ai",
13328
+ "llm",
13329
+ "terminal",
13330
+ "assistant"
13331
+ ],
13332
+ author: "hongymagic <packages@hon.gy>",
13333
+ license: "MIT",
13334
+ engines: {
13335
+ node: ">=24"
13336
+ },
13337
+ scripts: {
13338
+ start: "bun run src/cli.ts",
13339
+ test: "vitest run",
13340
+ "test:watch": "vitest",
13341
+ typecheck: "tsc --noEmit",
13342
+ lint: "biome check .",
13343
+ fix: "biome check --write --unsafe .",
13344
+ build: "bun build --compile --minify --sourcemap ./src/cli.ts --outfile dist/q",
13345
+ "build:npm": "bun build ./src/cli.ts --outfile dist/q.js --target node",
13346
+ "build:all": "bun run build:darwin-arm64 && bun run build:darwin-x64 && bun run build:linux-x64 && bun run build:linux-arm64 && bun run build:windows-x64",
13347
+ "build:darwin-arm64": "bun build --compile --minify --target=bun-darwin-arm64 ./src/cli.ts --outfile dist/q-darwin-arm64",
13348
+ "build:darwin-x64": "bun build --compile --minify --target=bun-darwin-x64 ./src/cli.ts --outfile dist/q-darwin-x64",
13349
+ "build:linux-x64": "bun build --compile --minify --target=bun-linux-x64 ./src/cli.ts --outfile dist/q-linux-x64",
13350
+ "build:linux-arm64": "bun build --compile --minify --target=bun-linux-arm64 ./src/cli.ts --outfile dist/q-linux-arm64",
13351
+ "build:windows-x64": "bun build --compile --minify --target=bun-windows-x64 ./src/cli.ts --outfile dist/q-windows-x64.exe"
13352
+ },
13353
+ dependencies: {
13354
+ ai: "^6.0.97",
13355
+ "@ai-sdk/openai": "^3.0.31",
13356
+ "@ai-sdk/anthropic": "^3.0.46",
13357
+ "@ai-sdk/openai-compatible": "^2.0.30",
13358
+ "ollama-ai-provider-v2": "^3.3.1",
13359
+ zod: "^4.3.6",
13360
+ clipboardy: "^5.3.0",
13361
+ "@t3-oss/env-core": "^0.13.10"
13362
+ },
13363
+ devDependencies: {
13364
+ "@biomejs/biome": "^2.4.4",
13365
+ "@types/bun": "latest",
13366
+ lefthook: "^2.1.1",
13367
+ typescript: "^5.9.3",
13368
+ vitest: "^4.0.18"
13369
+ }
13370
+ };
13304
13371
 
13305
13372
  // src/errors.ts
13306
13373
  class QError extends Error {
@@ -13416,7 +13483,7 @@ EXAMPLES:
13416
13483
  q -p openai --model gpt-4o what is recursion
13417
13484
  q config init
13418
13485
  `;
13419
- var VERSION = "0.4.0";
13486
+ var VERSION = package_default.version;
13420
13487
  function parseCliArgs(argv = Bun.argv.slice(2)) {
13421
13488
  const { values, positionals } = parseArgs({
13422
13489
  args: argv,
@@ -53693,14 +53760,28 @@ var _a20;
53693
53760
  _a20 = symbol20;
53694
53761
  var defaultDownload2 = createDownload();
53695
53762
 
53763
+ // src/prompt.ts
53764
+ function buildUserPrompt(query, context2) {
53765
+ if (!context2) {
53766
+ return query;
53767
+ }
53768
+ return `Context:
53769
+ \`\`\`
53770
+ ${context2}
53771
+ \`\`\`
53772
+
53773
+ Question: ${query}`;
53774
+ }
53775
+
53696
53776
  // src/run.ts
53697
53777
  async function runQuery(options) {
53698
- const { model, query, systemPrompt } = options;
53778
+ const { model, query, systemPrompt, context: context2 } = options;
53779
+ const userPrompt = buildUserPrompt(query, context2);
53699
53780
  try {
53700
53781
  const result = streamText({
53701
53782
  model,
53702
53783
  system: systemPrompt,
53703
- prompt: query
53784
+ prompt: userPrompt
53704
53785
  });
53705
53786
  let fullText = "";
53706
53787
  for await (const textPart of result.textStream) {
@@ -53719,16 +53800,52 @@ async function runQuery(options) {
53719
53800
  }
53720
53801
  }
53721
53802
 
53803
+ // src/stdin.ts
53804
+ var MAX_QUERY_LENGTH = 5000;
53805
+ var MAX_CONTEXT_LENGTH = 50000;
53806
+ async function readStdin() {
53807
+ if (process.stdin.isTTY) {
53808
+ return { content: null, hasInput: false };
53809
+ }
53810
+ const chunks = [];
53811
+ const decoder = new TextDecoder;
53812
+ for await (const chunk of Bun.stdin.stream()) {
53813
+ chunks.push(decoder.decode(chunk));
53814
+ }
53815
+ const content = chunks.join("").trim();
53816
+ return {
53817
+ content: content || null,
53818
+ hasInput: content.length > 0
53819
+ };
53820
+ }
53821
+ function resolveInput(stdinInput, argsQuery) {
53822
+ if (stdinInput.hasInput && argsQuery.length > 0) {
53823
+ return {
53824
+ mode: "context",
53825
+ query: argsQuery.join(" "),
53826
+ context: stdinInput.content
53827
+ };
53828
+ }
53829
+ if (stdinInput.hasInput && stdinInput.content) {
53830
+ return {
53831
+ mode: "stdin",
53832
+ query: stdinInput.content,
53833
+ context: null
53834
+ };
53835
+ }
53836
+ return {
53837
+ mode: "args",
53838
+ query: argsQuery.join(" "),
53839
+ context: null
53840
+ };
53841
+ }
53842
+
53722
53843
  // src/cli.ts
53723
53844
  async function main() {
53724
53845
  let debug = false;
53725
53846
  try {
53726
53847
  const args = parseCliArgs();
53727
53848
  debug = args.options.debug;
53728
- if (args.options.help) {
53729
- console.log(getHelpText());
53730
- process.exit(0);
53731
- }
53732
53849
  if (args.options.version) {
53733
53850
  console.log(getVersion());
53734
53851
  process.exit(0);
@@ -53749,11 +53866,19 @@ async function main() {
53749
53866
  console.log(listProviders(config3));
53750
53867
  process.exit(0);
53751
53868
  }
53752
- const query = args.query.join(" ");
53753
- const MAX_QUERY_LENGTH = 5000;
53869
+ const stdinInput = await readStdin();
53870
+ if (args.options.help && !stdinInput.hasInput && args.query.length === 0) {
53871
+ console.log(getHelpText());
53872
+ process.exit(0);
53873
+ }
53874
+ const { mode, query, context: context2 } = resolveInput(stdinInput, args.query);
53875
+ logDebug2(`Mode: ${mode}`, debug);
53754
53876
  if (query.length > MAX_QUERY_LENGTH) {
53755
53877
  throw new UsageError2(`Query too long (${query.length} characters). Maximum is ${MAX_QUERY_LENGTH}.`);
53756
53878
  }
53879
+ if (context2 && context2.length > MAX_CONTEXT_LENGTH) {
53880
+ throw new UsageError2(`Context too long (${context2.length} characters). Maximum is ${MAX_CONTEXT_LENGTH}.`);
53881
+ }
53757
53882
  logDebug2("Loading config...", debug);
53758
53883
  const config2 = await loadConfig();
53759
53884
  logDebug2(`Resolving provider: ${args.options.provider ?? config2.default.provider}`, debug);
@@ -53765,6 +53890,7 @@ async function main() {
53765
53890
  const result = await runQuery({
53766
53891
  model,
53767
53892
  query,
53893
+ context: context2,
53768
53894
  systemPrompt: buildSystemPrompt(envInfo)
53769
53895
  });
53770
53896
  if (args.options.copy) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hongymagic/q",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Quick AI answers from the command line",
5
5
  "main": "dist/q.js",
6
6
  "type": "module",