@llmist/cli 15.10.0 → 15.12.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
@@ -98,7 +98,7 @@ import { Command, InvalidArgumentError as InvalidArgumentError2 } from "commande
98
98
  // package.json
99
99
  var package_default = {
100
100
  name: "@llmist/cli",
101
- version: "15.10.0",
101
+ version: "15.12.0",
102
102
  description: "CLI for llmist - run LLM agents from the command line",
103
103
  type: "module",
104
104
  main: "dist/cli.js",
@@ -154,7 +154,7 @@ var package_default = {
154
154
  node: ">=22.0.0"
155
155
  },
156
156
  dependencies: {
157
- llmist: "^15.10.0",
157
+ llmist: "^15.12.0",
158
158
  "@unblessed/node": "^1.0.0-alpha.23",
159
159
  chalk: "^5.6.2",
160
160
  commander: "^12.1.0",
@@ -168,7 +168,7 @@ var package_default = {
168
168
  zod: "^4.1.12"
169
169
  },
170
170
  devDependencies: {
171
- "@llmist/testing": "^15.10.0",
171
+ "@llmist/testing": "^15.12.0",
172
172
  "@types/diff": "^8.0.0",
173
173
  "@types/js-yaml": "^4.0.9",
174
174
  "@types/marked-terminal": "^6.1.1",
@@ -180,7 +180,7 @@ var package_default = {
180
180
  };
181
181
 
182
182
  // src/agent-command.ts
183
- import { AgentBuilder, GadgetRegistry, isAbortError, text } from "llmist";
183
+ import { AgentBuilder, GadgetRegistry, HookPresets, isAbortError, text } from "llmist";
184
184
 
185
185
  // src/builtin-gadgets.ts
186
186
  import { createGadget, HumanInputRequiredException, TaskCompletionSignal } from "llmist";
@@ -2800,27 +2800,6 @@ async function loadGadgets(specifiers, cwd, importer = createTypeScriptImporter(
2800
2800
  return gadgets;
2801
2801
  }
2802
2802
 
2803
- // src/llm-logging.ts
2804
- import { mkdir, writeFile as writeFile2 } from "fs/promises";
2805
- import { join as join2 } from "path";
2806
- import { extractMessageText } from "llmist";
2807
- function formatLlmRequest(messages) {
2808
- const lines = [];
2809
- for (const msg of messages) {
2810
- lines.push(`=== ${msg.role.toUpperCase()} ===`);
2811
- lines.push(msg.content ? extractMessageText(msg.content) : "");
2812
- lines.push("");
2813
- }
2814
- return lines.join("\n");
2815
- }
2816
- async function writeLogFile(dir, filename, content) {
2817
- await mkdir(dir, { recursive: true });
2818
- await writeFile2(join2(dir, filename), content, "utf-8");
2819
- }
2820
- function formatCallNumber(n) {
2821
- return n.toString().padStart(4, "0");
2822
- }
2823
-
2824
2803
  // src/utils.ts
2825
2804
  import chalk2 from "chalk";
2826
2805
  import { InvalidArgumentError } from "commander";
@@ -6154,10 +6133,10 @@ var HintsBar = class {
6154
6133
  import { spawnSync as spawnSync2 } from "child_process";
6155
6134
  import { readFileSync as readFileSync4, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
6156
6135
  import { tmpdir } from "os";
6157
- import { join as join3 } from "path";
6136
+ import { join as join2 } from "path";
6158
6137
  function openEditorSync(initialContent = "") {
6159
6138
  const editor = process.env.VISUAL || process.env.EDITOR || "vi";
6160
- const tmpFile = join3(tmpdir(), `llmist-input-${Date.now()}.txt`);
6139
+ const tmpFile = join2(tmpdir(), `llmist-input-${Date.now()}.txt`);
6161
6140
  writeFileSync2(tmpFile, initialContent, "utf-8");
6162
6141
  try {
6163
6142
  const parts = editor.split(/\s+/);
@@ -8561,40 +8540,20 @@ async function executeAgent(promptArg, options, env, commandName) {
8561
8540
  let iterations = 0;
8562
8541
  const llmLogsEnabled = options.logLlmRequests === true;
8563
8542
  const llmLogDir = llmLogsEnabled ? env.session?.logDir : void 0;
8564
- let llmCallCounter = 0;
8565
- const _countGadgetOutputTokens = async (output) => {
8566
- if (!output) return void 0;
8567
- try {
8568
- const messages = [{ role: "assistant", content: output }];
8569
- return await client.countTokens(options.model, messages);
8570
- } catch {
8571
- return void 0;
8572
- }
8573
- };
8574
8543
  const resolvedSubagentConfig = buildSubagentConfigMap(
8575
8544
  options.model,
8576
8545
  options.subagents,
8577
8546
  options.globalSubagents
8578
8547
  );
8579
- const builder = new AgentBuilder(client).withModel(options.model).withSubagentConfig(resolvedSubagentConfig).withLogger(env.createLogger("llmist:cli:agent")).withHooks({
8548
+ const tuiHooks = {
8580
8549
  observers: {
8581
8550
  // onLLMCallStart: Track iteration for status bar label formatting
8582
8551
  onLLMCallStart: async (context) => {
8583
8552
  if (context.subagentContext) return;
8584
- llmCallCounter++;
8585
8553
  if (tui) {
8586
8554
  tui.showLLMCallStart(iterations + 1);
8587
8555
  }
8588
8556
  },
8589
- // onLLMCallReady: Log the exact request being sent to the LLM
8590
- onLLMCallReady: async (context) => {
8591
- if (context.subagentContext) return;
8592
- if (llmLogDir) {
8593
- const filename = `${formatCallNumber(llmCallCounter)}.request`;
8594
- const content = formatLlmRequest(context.options.messages);
8595
- await writeLogFile(llmLogDir, filename, content);
8596
- }
8597
- },
8598
8557
  // onStreamChunk: Update status bar with real-time output token estimate
8599
8558
  onStreamChunk: async (context) => {
8600
8559
  if (context.subagentContext) return;
@@ -8602,15 +8561,11 @@ async function executeAgent(promptArg, options, env, commandName) {
8602
8561
  const estimatedOutputTokens = StatusBar.estimateTokens(context.accumulatedText);
8603
8562
  tui.updateStreamingTokens(estimatedOutputTokens);
8604
8563
  },
8605
- // onLLMCallComplete: Capture metadata for final summary and file logging
8564
+ // onLLMCallComplete: Capture metadata for final summary
8606
8565
  onLLMCallComplete: async (context) => {
8607
8566
  if (context.subagentContext) return;
8608
8567
  _usage = context.usage;
8609
8568
  iterations = Math.max(iterations, context.iteration + 1);
8610
- if (llmLogDir) {
8611
- const filename = `${formatCallNumber(llmCallCounter)}.response`;
8612
- await writeLogFile(llmLogDir, filename, context.rawResponse);
8613
- }
8614
8569
  if (tui) {
8615
8570
  tui.clearRetry();
8616
8571
  }
@@ -8718,7 +8673,9 @@ ${ctx.gadgetName} requires interactive approval. Run in a terminal to approve.`
8718
8673
  };
8719
8674
  }
8720
8675
  }
8721
- });
8676
+ };
8677
+ const finalHooks = llmLogDir ? HookPresets.merge(HookPresets.fileLogging({ directory: llmLogDir }), tuiHooks) : tuiHooks;
8678
+ const builder = new AgentBuilder(client).withModel(options.model).withSubagentConfig(resolvedSubagentConfig).withLogger(env.createLogger("llmist:cli:agent")).withHooks(finalHooks);
8722
8679
  const rateLimitConfig = resolveRateLimitConfig(
8723
8680
  options,
8724
8681
  options.globalRateLimits,
@@ -8905,7 +8862,24 @@ function registerAgentCommand(program, env, config, globalSubagents, globalRateL
8905
8862
  }
8906
8863
 
8907
8864
  // src/complete-command.ts
8908
- import { FALLBACK_CHARS_PER_TOKEN as FALLBACK_CHARS_PER_TOKEN2, LLMMessageBuilder, resolveModel as resolveModel2, text as text2 } from "llmist";
8865
+ import {
8866
+ FALLBACK_CHARS_PER_TOKEN as FALLBACK_CHARS_PER_TOKEN2,
8867
+ formatLlmRequest as formatLlmRequest2,
8868
+ LLMMessageBuilder,
8869
+ resolveModel as resolveModel2,
8870
+ text as text2
8871
+ } from "llmist";
8872
+
8873
+ // src/llm-logging.ts
8874
+ import { mkdir, writeFile as writeFile2 } from "fs/promises";
8875
+ import { join as join3 } from "path";
8876
+ import { formatCallNumber, formatLlmRequest } from "llmist";
8877
+ async function writeLogFile(dir, filename, content) {
8878
+ await mkdir(dir, { recursive: true });
8879
+ await writeFile2(join3(dir, filename), content, "utf-8");
8880
+ }
8881
+
8882
+ // src/complete-command.ts
8909
8883
  async function executeComplete(promptArg, options, env) {
8910
8884
  const prompt = await resolvePrompt(promptArg, env);
8911
8885
  const client = env.createClient();
@@ -8931,7 +8905,7 @@ async function executeComplete(promptArg, options, env) {
8931
8905
  const llmLogDir = llmLogsEnabled ? env.session?.logDir : void 0;
8932
8906
  if (llmLogDir) {
8933
8907
  const filename = "0001.request";
8934
- const content = formatLlmRequest(messages);
8908
+ const content = formatLlmRequest2(messages);
8935
8909
  await writeLogFile(llmLogDir, filename, content);
8936
8910
  }
8937
8911
  const stream = client.stream({