llmist 0.5.1 → 0.6.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.
package/dist/cli.js CHANGED
@@ -1,7 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- createGadget
4
- } from "./chunk-LKIBXQ5I.js";
5
2
  import {
6
3
  AgentBuilder,
7
4
  BaseGadget,
@@ -12,17 +9,20 @@ import {
12
9
  LLMMessageBuilder,
13
10
  LLMist,
14
11
  MODEL_ALIASES,
12
+ createGadget,
15
13
  createLogger,
16
14
  init_builder,
17
15
  init_client,
18
16
  init_constants2 as init_constants,
17
+ init_create_gadget,
19
18
  init_exceptions,
19
+ init_gadget,
20
20
  init_logger,
21
21
  init_messages,
22
22
  init_model_shortcuts,
23
23
  init_registry,
24
24
  resolveModel
25
- } from "./chunk-MH4TQ5AD.js";
25
+ } from "./chunk-KB7LMYC2.js";
26
26
 
27
27
  // src/cli/constants.ts
28
28
  var CLI_NAME = "llmist";
@@ -45,6 +45,7 @@ var OPTION_FLAGS = {
45
45
  parameterFormat: "--parameter-format <format>",
46
46
  logLevel: "--log-level <level>",
47
47
  logFile: "--log-file <path>",
48
+ logReset: "--log-reset",
48
49
  noBuiltins: "--no-builtins",
49
50
  noBuiltinInteraction: "--no-builtin-interaction"
50
51
  };
@@ -58,6 +59,7 @@ var OPTION_DESCRIPTIONS = {
58
59
  parameterFormat: "Format for gadget parameter schemas: 'json', 'yaml', 'toml', or 'auto'.",
59
60
  logLevel: "Log level: silly, trace, debug, info, warn, error, fatal.",
60
61
  logFile: "Path to log file. When set, logs are written to file instead of stderr.",
62
+ logReset: "Reset (truncate) the log file at session start instead of appending.",
61
63
  noBuiltins: "Disable built-in gadgets (AskUser, TellUser).",
62
64
  noBuiltinInteraction: "Disable interactive gadgets (AskUser) while keeping TellUser."
63
65
  };
@@ -69,7 +71,7 @@ import { Command, InvalidArgumentError as InvalidArgumentError3 } from "commande
69
71
  // package.json
70
72
  var package_default = {
71
73
  name: "llmist",
72
- version: "0.5.0",
74
+ version: "0.5.1",
73
75
  description: "Universal TypeScript LLM client with streaming-first agent framework. Works with any model - no structured outputs or native tool calling required. Implements its own flexible grammar for function calling.",
74
76
  type: "module",
75
77
  main: "dist/index.cjs",
@@ -188,8 +190,9 @@ import { createInterface } from "node:readline/promises";
188
190
  import chalk3 from "chalk";
189
191
 
190
192
  // src/cli/builtin-gadgets.ts
191
- import { z } from "zod";
193
+ init_create_gadget();
192
194
  init_exceptions();
195
+ import { z } from "zod";
193
196
  var askUser = createGadget({
194
197
  name: "AskUser",
195
198
  description: "Ask the user a question when you need more information or clarification. The user's response will be provided back to you.",
@@ -255,6 +258,7 @@ var tellUser = createGadget({
255
258
  var builtinGadgets = [askUser, tellUser];
256
259
 
257
260
  // src/cli/gadgets.ts
261
+ init_gadget();
258
262
  import fs from "node:fs";
259
263
  import path from "node:path";
260
264
  import { pathToFileURL } from "node:url";
@@ -999,7 +1003,7 @@ async function promptApproval(env, prompt) {
999
1003
  const rl = createInterface({ input: env.stdin, output: env.stderr });
1000
1004
  try {
1001
1005
  const answer = await rl.question(prompt);
1002
- return answer.toLowerCase().startsWith("y");
1006
+ return answer.trim();
1003
1007
  } finally {
1004
1008
  rl.close();
1005
1009
  }
@@ -1166,16 +1170,19 @@ async function executeAgent(promptArg, options, env) {
1166
1170
  const command = ctx.parameters.command;
1167
1171
  progress.pause();
1168
1172
  env.stderr.write(`
1169
- ${chalk3.yellow("\u{1F512} Execute:")} ${command}
1173
+ \u{1F512} Execute: ${chalk3.cyan(command)}
1170
1174
  `);
1171
- const approved = await promptApproval(env, " Approve? [y/n] ");
1172
- if (!approved) {
1175
+ const response = await promptApproval(env, " \u23CE approve, or type to reject: ");
1176
+ const isApproved = response === "" || response.toLowerCase() === "y";
1177
+ if (!isApproved) {
1173
1178
  env.stderr.write(` ${chalk3.red("\u2717 Denied")}
1174
1179
 
1175
1180
  `);
1176
1181
  return {
1177
1182
  action: "skip",
1178
- syntheticResult: "status=denied\n\nCommand denied by user. Ask what they'd like to do instead."
1183
+ syntheticResult: `status=denied
1184
+
1185
+ Command rejected by user with message: "${response}"`
1179
1186
  };
1180
1187
  }
1181
1188
  env.stderr.write(` ${chalk3.green("\u2713 Approved")}
@@ -1315,7 +1322,7 @@ import { existsSync, readFileSync } from "node:fs";
1315
1322
  import { homedir } from "node:os";
1316
1323
  import { join } from "node:path";
1317
1324
  import { load as parseToml } from "js-toml";
1318
- var GLOBAL_CONFIG_KEYS = /* @__PURE__ */ new Set(["log-level", "log-file"]);
1325
+ var GLOBAL_CONFIG_KEYS = /* @__PURE__ */ new Set(["log-level", "log-file", "log-reset"]);
1319
1326
  var VALID_LOG_LEVELS = ["silly", "trace", "debug", "info", "warn", "error", "fatal"];
1320
1327
  var COMPLETE_CONFIG_KEYS = /* @__PURE__ */ new Set(["model", "system", "temperature", "max-tokens"]);
1321
1328
  var AGENT_CONFIG_KEYS = /* @__PURE__ */ new Set([
@@ -1332,7 +1339,10 @@ var CUSTOM_CONFIG_KEYS = /* @__PURE__ */ new Set([
1332
1339
  ...COMPLETE_CONFIG_KEYS,
1333
1340
  ...AGENT_CONFIG_KEYS,
1334
1341
  "type",
1335
- "description"
1342
+ "description",
1343
+ "log-level",
1344
+ "log-file",
1345
+ "log-reset"
1336
1346
  ]);
1337
1347
  var VALID_PARAMETER_FORMATS = ["json", "yaml", "toml", "auto"];
1338
1348
  function getConfigPath() {
@@ -1422,6 +1432,9 @@ function validateGlobalConfig(raw, section) {
1422
1432
  if ("log-file" in rawObj) {
1423
1433
  result["log-file"] = validateString(rawObj["log-file"], "log-file", section);
1424
1434
  }
1435
+ if ("log-reset" in rawObj) {
1436
+ result["log-reset"] = validateBoolean(rawObj["log-reset"], "log-reset", section);
1437
+ }
1425
1438
  return result;
1426
1439
  }
1427
1440
  function validateCompleteConfig(raw, section) {
@@ -1543,6 +1556,21 @@ function validateCustomConfig(raw, section) {
1543
1556
  min: 1
1544
1557
  });
1545
1558
  }
1559
+ if ("log-level" in rawObj) {
1560
+ const level = validateString(rawObj["log-level"], "log-level", section);
1561
+ if (!VALID_LOG_LEVELS.includes(level)) {
1562
+ throw new ConfigError(
1563
+ `[${section}].log-level must be one of: ${VALID_LOG_LEVELS.join(", ")}`
1564
+ );
1565
+ }
1566
+ result["log-level"] = level;
1567
+ }
1568
+ if ("log-file" in rawObj) {
1569
+ result["log-file"] = validateString(rawObj["log-file"], "log-file", section);
1570
+ }
1571
+ if ("log-reset" in rawObj) {
1572
+ result["log-reset"] = validateBoolean(rawObj["log-reset"], "log-reset", section);
1573
+ }
1546
1574
  return result;
1547
1575
  }
1548
1576
  function validateConfig(raw, configPath) {
@@ -1761,38 +1789,6 @@ function registerModelsCommand(program, env) {
1761
1789
  );
1762
1790
  }
1763
1791
 
1764
- // src/cli/custom-command.ts
1765
- function registerCustomCommand(program, name, config, env) {
1766
- const type = config.type ?? "agent";
1767
- const description = config.description ?? `Custom ${type} command`;
1768
- const cmd = program.command(name).description(description).argument("[prompt]", "Prompt for the command. Falls back to stdin when available.");
1769
- if (type === "complete") {
1770
- addCompleteOptions(cmd, config);
1771
- cmd.action(
1772
- (prompt, cliOptions) => executeAction(async () => {
1773
- const configDefaults = configToCompleteOptions(config);
1774
- const options = {
1775
- ...configDefaults,
1776
- ...cliOptions
1777
- };
1778
- await executeComplete(prompt, options, env);
1779
- }, env)
1780
- );
1781
- } else {
1782
- addAgentOptions(cmd, config);
1783
- cmd.action(
1784
- (prompt, cliOptions) => executeAction(async () => {
1785
- const configDefaults = configToAgentOptions(config);
1786
- const options = {
1787
- ...configDefaults,
1788
- ...cliOptions
1789
- };
1790
- await executeAgent(prompt, options, env);
1791
- }, env)
1792
- );
1793
- }
1794
- }
1795
-
1796
1792
  // src/cli/environment.ts
1797
1793
  init_client();
1798
1794
  init_logger();
@@ -1816,6 +1812,9 @@ function createLoggerFactory(config) {
1816
1812
  options.minLevel = LOG_LEVEL_MAP[level];
1817
1813
  }
1818
1814
  }
1815
+ if (config?.logReset !== void 0) {
1816
+ options.logReset = config.logReset;
1817
+ }
1819
1818
  if (config?.logFile) {
1820
1819
  const originalLogFile = process.env.LLMIST_LOG_FILE;
1821
1820
  process.env.LLMIST_LOG_FILE = config.logFile;
@@ -1875,6 +1874,52 @@ function createDefaultEnvironment(loggerConfig) {
1875
1874
  };
1876
1875
  }
1877
1876
 
1877
+ // src/cli/custom-command.ts
1878
+ function createCommandEnvironment(baseEnv, config) {
1879
+ const hasLoggingConfig = config["log-level"] !== void 0 || config["log-file"] !== void 0 || config["log-reset"] !== void 0;
1880
+ if (!hasLoggingConfig) {
1881
+ return baseEnv;
1882
+ }
1883
+ const loggerConfig = {
1884
+ logLevel: config["log-level"] ?? baseEnv.loggerConfig?.logLevel,
1885
+ logFile: config["log-file"] ?? baseEnv.loggerConfig?.logFile,
1886
+ logReset: config["log-reset"] ?? baseEnv.loggerConfig?.logReset
1887
+ };
1888
+ return createDefaultEnvironment(loggerConfig);
1889
+ }
1890
+ function registerCustomCommand(program, name, config, env) {
1891
+ const type = config.type ?? "agent";
1892
+ const description = config.description ?? `Custom ${type} command`;
1893
+ const cmd = program.command(name).description(description).argument("[prompt]", "Prompt for the command. Falls back to stdin when available.");
1894
+ if (type === "complete") {
1895
+ addCompleteOptions(cmd, config);
1896
+ cmd.action((prompt, cliOptions) => {
1897
+ const cmdEnv = createCommandEnvironment(env, config);
1898
+ return executeAction(async () => {
1899
+ const configDefaults = configToCompleteOptions(config);
1900
+ const options = {
1901
+ ...configDefaults,
1902
+ ...cliOptions
1903
+ };
1904
+ await executeComplete(prompt, options, cmdEnv);
1905
+ }, cmdEnv);
1906
+ });
1907
+ } else {
1908
+ addAgentOptions(cmd, config);
1909
+ cmd.action((prompt, cliOptions) => {
1910
+ const cmdEnv = createCommandEnvironment(env, config);
1911
+ return executeAction(async () => {
1912
+ const configDefaults = configToAgentOptions(config);
1913
+ const options = {
1914
+ ...configDefaults,
1915
+ ...cliOptions
1916
+ };
1917
+ await executeAgent(prompt, options, cmdEnv);
1918
+ }, cmdEnv);
1919
+ });
1920
+ }
1921
+ }
1922
+
1878
1923
  // src/cli/program.ts
1879
1924
  function parseLogLevel(value) {
1880
1925
  const normalized = value.toLowerCase();
@@ -1885,7 +1930,7 @@ function parseLogLevel(value) {
1885
1930
  }
1886
1931
  function createProgram(env, config) {
1887
1932
  const program = new Command();
1888
- program.name(CLI_NAME).description(CLI_DESCRIPTION).version(package_default.version).option(OPTION_FLAGS.logLevel, OPTION_DESCRIPTIONS.logLevel, parseLogLevel).option(OPTION_FLAGS.logFile, OPTION_DESCRIPTIONS.logFile).configureOutput({
1933
+ program.name(CLI_NAME).description(CLI_DESCRIPTION).version(package_default.version).option(OPTION_FLAGS.logLevel, OPTION_DESCRIPTIONS.logLevel, parseLogLevel).option(OPTION_FLAGS.logFile, OPTION_DESCRIPTIONS.logFile).option(OPTION_FLAGS.logReset, OPTION_DESCRIPTIONS.logReset).configureOutput({
1889
1934
  writeOut: (str) => env.stdout.write(str),
1890
1935
  writeErr: (str) => env.stderr.write(str)
1891
1936
  });
@@ -1906,12 +1951,13 @@ async function runCLI(overrides = {}) {
1906
1951
  const config = opts.config !== void 0 ? opts.config : loadConfig();
1907
1952
  const envOverrides = opts.env ?? {};
1908
1953
  const preParser = new Command();
1909
- preParser.option(OPTION_FLAGS.logLevel, OPTION_DESCRIPTIONS.logLevel, parseLogLevel).option(OPTION_FLAGS.logFile, OPTION_DESCRIPTIONS.logFile).allowUnknownOption().allowExcessArguments().helpOption(false);
1954
+ preParser.option(OPTION_FLAGS.logLevel, OPTION_DESCRIPTIONS.logLevel, parseLogLevel).option(OPTION_FLAGS.logFile, OPTION_DESCRIPTIONS.logFile).option(OPTION_FLAGS.logReset, OPTION_DESCRIPTIONS.logReset).allowUnknownOption().allowExcessArguments().helpOption(false);
1910
1955
  preParser.parse(process.argv);
1911
1956
  const globalOpts = preParser.opts();
1912
1957
  const loggerConfig = {
1913
1958
  logLevel: globalOpts.logLevel ?? config.global?.["log-level"],
1914
- logFile: globalOpts.logFile ?? config.global?.["log-file"]
1959
+ logFile: globalOpts.logFile ?? config.global?.["log-file"],
1960
+ logReset: globalOpts.logReset ?? config.global?.["log-reset"]
1915
1961
  };
1916
1962
  const defaultEnv = createDefaultEnvironment(loggerConfig);
1917
1963
  const env = { ...defaultEnv, ...envOverrides };