@cam5/baby-bird 0.1.1 → 0.1.2

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/index.d.ts CHANGED
@@ -218,6 +218,13 @@ type LlmKind = 'plain' | 'claude';
218
218
  interface LlmPreset {
219
219
  /** argv; when promptVia is "arg", any "{prompt}" token is replaced with the prompt. */
220
220
  command: string[];
221
+ /**
222
+ * argv for `bb ask`: an interactive chat about a tour. Tokens: "{context-file}" is the path of a
223
+ * file holding the tour context (a system prompt), "{context}" is that text inline, and
224
+ * "{message}" is the user's opening message (argv entries that are only "{message}" are dropped
225
+ * when there is none).
226
+ */
227
+ chatCommand?: string[];
221
228
  promptVia?: PromptVia;
222
229
  /**
223
230
  * "claude": the Claude Code CLI; streaming flags and --json-schema are added
@@ -233,6 +240,7 @@ declare const ConfigSchema: z.ZodObject<{
233
240
  preset: z.ZodString;
234
241
  presets: z.ZodRecord<z.ZodString, z.ZodObject<{
235
242
  command: z.ZodArray<z.ZodString>;
243
+ chatCommand: z.ZodOptional<z.ZodArray<z.ZodString>>;
236
244
  promptVia: z.ZodOptional<z.ZodEnum<{
237
245
  stdin: "stdin";
238
246
  arg: "arg";
@@ -245,6 +253,7 @@ declare const ConfigSchema: z.ZodObject<{
245
253
  }, z.core.$strip>>;
246
254
  args: z.ZodArray<z.ZodString>;
247
255
  command: z.ZodNullable<z.ZodArray<z.ZodString>>;
256
+ chatCommand: z.ZodNullable<z.ZodArray<z.ZodString>>;
248
257
  promptVia: z.ZodNullable<z.ZodEnum<{
249
258
  stdin: "stdin";
250
259
  arg: "arg";
@@ -286,10 +295,6 @@ declare const ConfigSchema: z.ZodObject<{
286
295
  auto: "auto";
287
296
  always: "always";
288
297
  }>;
289
- theme: z.ZodEnum<{
290
- dark: "dark";
291
- light: "light";
292
- }>;
293
298
  }, z.core.$strip>;
294
299
  cache: z.ZodObject<{
295
300
  enabled: z.ZodBoolean;
@@ -302,6 +307,7 @@ declare const PartialConfigSchema: z.ZodObject<{
302
307
  preset: z.ZodOptional<z.ZodString>;
303
308
  presets: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
304
309
  command: z.ZodArray<z.ZodString>;
310
+ chatCommand: z.ZodOptional<z.ZodArray<z.ZodString>>;
305
311
  promptVia: z.ZodOptional<z.ZodEnum<{
306
312
  stdin: "stdin";
307
313
  arg: "arg";
@@ -314,6 +320,7 @@ declare const PartialConfigSchema: z.ZodObject<{
314
320
  }, z.core.$strip>>>;
315
321
  args: z.ZodOptional<z.ZodArray<z.ZodString>>;
316
322
  command: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
323
+ chatCommand: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
317
324
  promptVia: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
318
325
  stdin: "stdin";
319
326
  arg: "arg";
@@ -355,10 +362,6 @@ declare const PartialConfigSchema: z.ZodObject<{
355
362
  auto: "auto";
356
363
  always: "always";
357
364
  }>>;
358
- theme: z.ZodOptional<z.ZodEnum<{
359
- dark: "dark";
360
- light: "light";
361
- }>>;
362
365
  }, z.core.$strip>>;
363
366
  cache: z.ZodOptional<z.ZodObject<{
364
367
  enabled: z.ZodOptional<z.ZodBoolean>;
@@ -410,6 +413,15 @@ interface ResolvedLlm {
410
413
  }
411
414
  declare function allPresets(config: Config): Record<string, LlmPreset>;
412
415
  declare function resolveLlm(config: Config): ResolvedLlm;
416
+ interface ResolvedChat {
417
+ /** argv template; see LlmPreset.chatCommand for the tokens. */
418
+ command: string[];
419
+ /** Preset name the command came from, or null for llm.chatCommand / a custom command. */
420
+ preset: string | null;
421
+ env: Record<string, string>;
422
+ }
423
+ /** The interactive command `bb ask` runs. Errors when neither the preset nor llm.chatCommand provides one. */
424
+ declare function resolveChat(config: Config): ResolvedChat;
413
425
  /** Minimal POSIX-ish shell splitting: whitespace separated, single/double quotes, backslash escapes. */
414
426
  declare function shellSplit(input: string): string[];
415
427
 
@@ -498,12 +510,15 @@ declare function materializeTour(input: MaterializeInput): Tour;
498
510
  */
499
511
  declare function sliceHunk(hunk: Hunk, range: [number, number] | undefined, maxLines: number): HunkLine[];
500
512
 
501
- interface PromptInput {
513
+ /** The change as gathered from git and the code host. */
514
+ interface ChangeInput {
502
515
  source: TourSource;
503
516
  branch: string | null;
504
517
  diff: ParsedDiff;
505
518
  commits: CommitInfo[];
506
519
  pullRequest?: PullRequestInfo;
520
+ }
521
+ interface PromptInput extends ChangeInput {
507
522
  /** Soft budget for the whole prompt, in bytes. */
508
523
  maxBytes: number;
509
524
  /** The runner enforces the JSON schema itself (e.g. claude --json-schema); adjusts the output instruction. */
@@ -520,6 +535,14 @@ interface BuiltPrompt {
520
535
  truncation: TruncationReport;
521
536
  }
522
537
  declare function buildPrompt(input: PromptInput): BuiltPrompt;
538
+ /**
539
+ * The change itself: source, PR text, commit subjects, the file table, and the diff with every
540
+ * hunk labeled by id. Diffs are shortened biggest-file-first to fit `maxBytes`.
541
+ */
542
+ declare function renderChange(input: ChangeInput, maxBytes: number): {
543
+ text: string;
544
+ truncation: TruncationReport;
545
+ };
523
546
  declare function describeSource(source: TourSource, branch: string | null): string;
524
547
 
525
548
  /** Bump whenever the prompt text or its assembly changes materially; it is part of the cache key. */
@@ -747,6 +770,23 @@ interface TourResult {
747
770
  declare function prepareTour(opts: TourOptions): Promise<PreparedTour>;
748
771
  declare function generateTour(opts: TourOptions, prepared?: PreparedTour): Promise<TourResult>;
749
772
 
773
+ interface ChatContextInput {
774
+ tour: Tour;
775
+ /** The change the tour was built from, as gathered by prepareTour. */
776
+ change: ChangeInput;
777
+ /** Soft budget for the whole context, in bytes; the tour is always kept and the diff is shortened to fit. */
778
+ maxBytes: number;
779
+ /** Where the tour JSON lives on disk, when cached, so a tool-using assistant can open it. */
780
+ tourPath?: string | null;
781
+ }
782
+ interface ChatContext {
783
+ /** Markdown meant for a system prompt: framing, the tour, then the change and its diff. */
784
+ text: string;
785
+ truncation: TruncationReport;
786
+ }
787
+ /** The text `bb ask` hands to the chat command as context. */
788
+ declare function buildChatContext(input: ChatContextInput): ChatContext;
789
+
750
790
  interface CollectOptions {
751
791
  cwd: string;
752
792
  exclude: string[];
@@ -773,6 +813,44 @@ declare function diffStats(diff: ParsedDiff): {
773
813
  deletions: number;
774
814
  };
775
815
 
816
+ interface ChatArgvInput {
817
+ command: string[];
818
+ contextFile: string;
819
+ context: string;
820
+ message?: string;
821
+ }
822
+ /** Fill the tokens in a chat command. Entries that are exactly "{message}" are dropped when there is no message. */
823
+ declare function chatArgv(input: ChatArgvInput): string[];
824
+ /** Which tokens a chat command uses, so the caller can warn about a message or context that would go nowhere. */
825
+ declare function chatSlots(command: string[]): {
826
+ context: boolean;
827
+ message: boolean;
828
+ };
829
+ interface LaunchChatOptions {
830
+ /** argv template; see chatArgv for the tokens. */
831
+ command: string[];
832
+ /** The system-prompt-like context, written to a temp file for "{context-file}". */
833
+ context: string;
834
+ /** Opening message, if any. */
835
+ message?: string;
836
+ cwd: string;
837
+ env?: Record<string, string>;
838
+ debug?: (msg: string) => void;
839
+ /** Defaults to the terminal ("inherit"); tests use "ignore". */
840
+ stdio?: 'inherit' | 'ignore';
841
+ }
842
+ interface ChatOutcome {
843
+ /** The command's exit code, or 128 + signal number when a signal ended it. */
844
+ exitCode: number;
845
+ signal: NodeJS.Signals | null;
846
+ }
847
+ /**
848
+ * Run an interactive chat command in the foreground, attached to this terminal, and resolve when it
849
+ * exits. Ctrl+C reaches the child through the terminal, so bb ignores SIGINT itself while the chat
850
+ * runs; SIGTERM and SIGHUP are forwarded.
851
+ */
852
+ declare function launchChat(opts: LaunchChatOptions): Promise<ChatOutcome>;
853
+
776
854
  /**
777
855
  * JSON Schema for the model's answer, handed to `claude --json-schema` so the
778
856
  * CLI enforces the shape itself. Kept deliberately simple (no tuples, no
@@ -855,10 +933,8 @@ interface RenderOptions {
855
933
  section?: number;
856
934
  /** Whether the tour came from the cache, for the header note. */
857
935
  fromCache?: boolean;
858
- /** Language-aware token colors in excerpts, layered under add/del background tints. Needs color. */
936
+ /** Language-aware token colors in excerpts. Needs color. */
859
937
  highlight?: boolean;
860
- /** Which background tints to use for added/removed lines. */
861
- theme?: 'dark' | 'light';
862
938
  }
863
939
  interface Renderer {
864
940
  render(tour: Tour, opts: RenderOptions): string;
@@ -880,4 +956,4 @@ interface PagerOptions {
880
956
  /** Write output to stdout, through $PAGER (default `less -RFX`) when it would not fit the screen. */
881
957
  declare function writeMaybePaged(output: string, opts: PagerOptions): Promise<void>;
882
958
 
883
- export { BUILTIN_PRESETS, BadLlmOutputError, BbError, type BuiltPrompt, type CacheEntry, ClaudeStreamParser, CliRenderer, type CodeHost, type CommandKind, CommandProvider, type CommitInfo, type CompleteOptions, type Config, ConfigError, type ConfigLayer, ConfigSchema, DEFAULT_CONFIG, type DiffFile, type Excerpt, type FileStatus, GhCodeHost, GitError, type Hunk, type HunkLine, type LineType, type LlmEvent, LlmFailedError, type LlmKind, type LlmPreset, type LlmProvider, type LlmTourOutput, LlmTourOutputSchema, type LoadedConfig, NoChangesError, NoCodeHost, NotARepoError, OTHER_CHANGES_TITLE, PROMPT_VERSION, type ParsedDiff, type PartialConfig, PartialConfigSchema, type PreparedTour, type ProgressSink, type PromptInput, type PullRequestInfo, type RangeRequest, type RangeResolvedBy, type RenderOptions, type Renderer, type ResolveOptions, type ResolvedLlm, type ResolvedRange, type Section, TOUR_JSON_SCHEMA, type Tour, TourCache, type TourContext, type TourGenerator, type TourOptions, type TourResult, TourSchema, type TourSource, type TourStats, type TruncationReport, UsageError, type WorkingResolvedBy, allPresets, buildPrompt, collectCommits, collectDiff, createCodeHost, createProvider, currentBranch, deepMerge, defaultCacheDir, describeSource, detectDefaultBranch, diffStats, extractJson, formatIssues, generateTour, gitRoot, loadConfig, materializeTour, noProgress, parseDiff, prepareTour, projectConfigPath, promptHeader, relativeTime, resolveLlm, resolveRange, revParse, shellSplit, sliceHunk, userConfigPath, wrap, writeMaybePaged };
959
+ export { BUILTIN_PRESETS, BadLlmOutputError, BbError, type BuiltPrompt, type CacheEntry, type ChangeInput, type ChatContext, type ChatContextInput, type ChatOutcome, ClaudeStreamParser, CliRenderer, type CodeHost, type CommandKind, CommandProvider, type CommitInfo, type CompleteOptions, type Config, ConfigError, type ConfigLayer, ConfigSchema, DEFAULT_CONFIG, type DiffFile, type Excerpt, type FileStatus, GhCodeHost, GitError, type Hunk, type HunkLine, type LaunchChatOptions, type LineType, type LlmEvent, LlmFailedError, type LlmKind, type LlmPreset, type LlmProvider, type LlmTourOutput, LlmTourOutputSchema, type LoadedConfig, NoChangesError, NoCodeHost, NotARepoError, OTHER_CHANGES_TITLE, PROMPT_VERSION, type ParsedDiff, type PartialConfig, PartialConfigSchema, type PreparedTour, type ProgressSink, type PromptInput, type PullRequestInfo, type RangeRequest, type RangeResolvedBy, type RenderOptions, type Renderer, type ResolveOptions, type ResolvedChat, type ResolvedLlm, type ResolvedRange, type Section, TOUR_JSON_SCHEMA, type Tour, TourCache, type TourContext, type TourGenerator, type TourOptions, type TourResult, TourSchema, type TourSource, type TourStats, type TruncationReport, UsageError, type WorkingResolvedBy, allPresets, buildChatContext, buildPrompt, chatArgv, chatSlots, collectCommits, collectDiff, createCodeHost, createProvider, currentBranch, deepMerge, defaultCacheDir, describeSource, detectDefaultBranch, diffStats, extractJson, formatIssues, generateTour, gitRoot, launchChat, loadConfig, materializeTour, noProgress, parseDiff, prepareTour, projectConfigPath, promptHeader, relativeTime, renderChange, resolveChat, resolveLlm, resolveRange, revParse, shellSplit, sliceHunk, userConfigPath, wrap, writeMaybePaged };
package/dist/index.js CHANGED
@@ -23,7 +23,10 @@ import {
23
23
  TourSchema,
24
24
  UsageError,
25
25
  allPresets,
26
+ buildChatContext,
26
27
  buildPrompt,
28
+ chatArgv,
29
+ chatSlots,
27
30
  collectCommits,
28
31
  collectDiff,
29
32
  createCodeHost,
@@ -38,6 +41,7 @@ import {
38
41
  formatIssues,
39
42
  generateTour,
40
43
  gitRoot,
44
+ launchChat,
41
45
  loadConfig,
42
46
  materializeTour,
43
47
  noProgress,
@@ -46,6 +50,8 @@ import {
46
50
  projectConfigPath,
47
51
  promptHeader,
48
52
  relativeTime,
53
+ renderChange,
54
+ resolveChat,
49
55
  resolveLlm,
50
56
  resolveRange,
51
57
  revParse,
@@ -54,7 +60,7 @@ import {
54
60
  userConfigPath,
55
61
  wrap,
56
62
  writeMaybePaged
57
- } from "./chunk-7ALXKEST.js";
63
+ } from "./chunk-YI2UL4IC.js";
58
64
  export {
59
65
  BUILTIN_PRESETS,
60
66
  BadLlmOutputError,
@@ -80,7 +86,10 @@ export {
80
86
  TourSchema,
81
87
  UsageError,
82
88
  allPresets,
89
+ buildChatContext,
83
90
  buildPrompt,
91
+ chatArgv,
92
+ chatSlots,
84
93
  collectCommits,
85
94
  collectDiff,
86
95
  createCodeHost,
@@ -95,6 +104,7 @@ export {
95
104
  formatIssues,
96
105
  generateTour,
97
106
  gitRoot,
107
+ launchChat,
98
108
  loadConfig,
99
109
  materializeTour,
100
110
  noProgress,
@@ -103,6 +113,8 @@ export {
103
113
  projectConfigPath,
104
114
  promptHeader,
105
115
  relativeTime,
116
+ renderChange,
117
+ resolveChat,
106
118
  resolveLlm,
107
119
  resolveRange,
108
120
  revParse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cam5/baby-bird",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Guided code tours for git changes, on the command line.",
5
5
  "license": "MIT",
6
6
  "type": "module",