codsh-cli 0.2.0 → 0.4.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.
@@ -1,75 +0,0 @@
1
- /**
2
- * Terminal styling and display metrics: SGR sequences that degrade to plain
3
- * text off a TTY, and the display-column width a rendered string occupies.
4
- * @module codsh-cli/src/theme
5
- */
6
- /** Style roles the renderer asks for, resolved to SGR codes by {@link createTheme}. */
7
- export interface Theme {
8
- /** Whether this theme emits SGR sequences at all. */
9
- readonly colored: boolean;
10
- dim(text: string): string;
11
- bold(text: string): string;
12
- /** Failures, denied approvals, and removed diff lines. */
13
- error(text: string): string;
14
- /** Completed work and added diff lines. */
15
- success(text: string): string;
16
- /** Pending state and approval prompts. */
17
- pending(text: string): string;
18
- /** Tool names and card titles. */
19
- tool(text: string): string;
20
- /** File paths and locations. */
21
- path(text: string): string;
22
- /** The user's own echoed input. */
23
- user(text: string): string;
24
- /** Roles used inside a fenced code block. */
25
- readonly syntax: SyntaxTheme;
26
- }
27
- /** Styling for the token classes a code block is coloured by. */
28
- export interface SyntaxTheme {
29
- keyword(text: string): string;
30
- string(text: string): string;
31
- number(text: string): string;
32
- comment(text: string): string;
33
- }
34
- /**
35
- * Build the theme for one surface.
36
- *
37
- * Color is suppressed off a TTY and whenever `NO_COLOR` is set to any value,
38
- * following the `no-color.org` convention: a redirected transcript stays
39
- * greppable, and a pipe never receives sequences a reader would have to strip.
40
- *
41
- * Secondary text uses a palette gray on a 256-color terminal rather than the
42
- * `dim` attribute: several terminals render `dim` at full brightness, and a
43
- * hierarchy nobody can see is no hierarchy — the placeholder, the menu details,
44
- * and the status row must sit visibly behind what the person typed.
45
- * @param isTty - whether the output stream is a terminal.
46
- * @param env - the environment to read `NO_COLOR` and the color depth from.
47
- * @returns the styling functions for this surface.
48
- */
49
- export declare function createTheme(isTty: boolean, env: Record<string, string | undefined>): Theme;
50
- /**
51
- * Display columns a string occupies once printed, ignoring styling sequences.
52
- *
53
- * Measured by `string-width` — the width authority cli-table3, ink, and every
54
- * maintained terminal renderer sit on — so East Asian Wide, emoji presentation
55
- * (`⚡` included), combining marks, and ZWJ sequences all match what a
56
- * terminal's cursor actually does. A hand-kept range table here mis-sized `⚡`
57
- * and sheared a real table's columns; widths are exactly the kind of data
58
- * nobody should maintain by hand.
59
- * @param text - the string to measure, possibly carrying SGR sequences.
60
- * @returns the number of display columns.
61
- */
62
- export declare function displayWidth(text: string): number;
63
- /**
64
- * Shorten a string to at most `columns` display columns, marking the cut with
65
- * an ellipsis when anything was dropped.
66
- *
67
- * Styling survives: sequences cost no columns and travel with the text they
68
- * style, and a cut that kept any styling closes it with a reset before the
69
- * ellipsis so nothing leaks onto the next row. A string that already fits is
70
- * returned exactly as it came — a fit is not a licence to restyle it.
71
- * @param text - the string to shorten, possibly carrying SGR sequences.
72
- * @param columns - the display-column budget; a budget under 2 yields the empty string.
73
- * @returns the string, unchanged when it already fits.
74
- */
75
- export declare function truncate(text: string, columns: number): string;
@@ -1,129 +0,0 @@
1
- /**
2
- * Session log to terminal lines. One appended {@link SessionEvent} renders to
3
- * zero or more finished lines; the surface never rewrites a line it has
4
- * printed, so the transcript scrolls like a shell history.
5
- *
6
- * Tool cards come from the registered presenters rather than from tool names:
7
- * a tool declares its own render intent, and this module switches on the
8
- * resulting `card` tag.
9
- * @module codsh-cli/src/transcript
10
- */
11
- import type { SessionEvent } from '@deepseek-ai/dsh-session';
12
- import type { ToolCallView, ToolResult, ToolResultView } from '@deepseek-ai/dsh-tools';
13
- import type { Theme } from './theme.ts';
14
- /** The registered presenters, resolved against the agent's scope by the caller. */
15
- export interface ToolPresenters {
16
- /**
17
- * Render intent for a pending call.
18
- * @param name - the tool the model called.
19
- * @param args - the parsed call arguments.
20
- * @returns the declared view, or undefined for the generic fallback.
21
- */
22
- call(name: string, args: unknown): ToolCallView | undefined;
23
- /**
24
- * Render intent for a completed call.
25
- * @param name - the tool the model called.
26
- * @param args - the parsed call arguments.
27
- * @param result - the completed outcome.
28
- * @returns the declared view, or undefined for the generic fallback.
29
- */
30
- result(name: string, args: unknown, result: ToolResult): ToolResultView | undefined;
31
- }
32
- /** What the renderer needs to know about the surface it writes to. */
33
- export interface TranscriptOptions {
34
- theme: Theme;
35
- /** Display columns available for one line. */
36
- columns: number;
37
- /** Session workspace, stripped from absolute paths so cards stay short. */
38
- cwd: string;
39
- }
40
- /** Renders one session's appended events as terminal lines. */
41
- export declare class Transcript {
42
- private readonly options;
43
- private readonly presenters;
44
- private readonly calls;
45
- /** The full form of the event just rendered, when its body was collapsed. */
46
- private fold;
47
- constructor(options: TranscriptOptions, presenters: ToolPresenters);
48
- /**
49
- * Shorten an absolute path inside the workspace to a workspace-relative one.
50
- * @param path - the model-facing path a card carries.
51
- * @returns the display path.
52
- */
53
- private relative;
54
- /**
55
- * Shorten every workspace path a presenter embedded in free text.
56
- *
57
- * A title is prose the tool composed (`Write /abs/path`), so the path inside
58
- * it needs the same shortening as a structured `locations` entry.
59
- * @param text - the presenter-supplied line.
60
- * @returns the line with workspace-rooted paths made relative.
61
- */
62
- private relativizeIn;
63
- /**
64
- * Paths worth appending to a title that may already name them.
65
- * @param title - the presenter's title, already relativized.
66
- * @param paths - the relativized paths the card covers.
67
- * @returns the paths the title does not mention, joined for display.
68
- */
69
- private extraPaths;
70
- /**
71
- * Render one appended event.
72
- * @param event - the event exactly as recorded.
73
- * @returns the lines to append to the transcript, empty when the event shows nothing.
74
- */
75
- render(event: SessionEvent): string[];
76
- /**
77
- * Render a pending call as its declared card.
78
- * @param callId - correlation id, remembered until the result pairs with it.
79
- * @param name - the tool the model called.
80
- * @param rawArguments - the unparsed arguments JSON the model produced.
81
- * @returns the pending card's lines.
82
- */
83
- private renderCall;
84
- /**
85
- * Render a completed call, pairing it with the call this transcript recorded.
86
- * @param data - the `tool/result` payload.
87
- * @returns the completed card's lines.
88
- */
89
- private renderResult;
90
- /**
91
- * The expanded form of the lines {@link render} just returned, when that
92
- * event's body was collapsed — the whole event re-rendered without its cap,
93
- * because a fold swaps entire blocks, not just the clipped tail. The full
94
- * body is kept from the render itself: what a tool truncated before
95
- * returning is upstream of the log and unrecoverable everywhere.
96
- * @returns the full lines, or undefined when nothing was collapsed.
97
- */
98
- takeFold(): string[] | undefined;
99
- /**
100
- * Render one completed call's status suffix and body from its declared view.
101
- * @param view - the result view, absent when no presenter answered.
102
- * @param block - the model-facing result block, used by the generic fallback.
103
- * @returns the suffix, the (possibly capped) body, and — when the cap dropped
104
- * lines, or a bodiless card withheld content — the full body for Ctrl-O.
105
- */
106
- private outcome;
107
- /**
108
- * Flatten a result's content blocks to displayable text.
109
- * @param content - the result content blocks.
110
- * @returns the joined text.
111
- */
112
- private resultText;
113
- /**
114
- * Ask a call presenter for its view, absorbing a throwing presenter.
115
- * @param name - the tool the model called.
116
- * @param args - the parsed call arguments.
117
- * @returns the view, or undefined to fall back to the generic line.
118
- */
119
- private safeCall;
120
- /**
121
- * Ask a result presenter for its view, absorbing a throwing presenter.
122
- * @param pending - the recorded call this result pairs with.
123
- * @param content - the model-facing result content.
124
- * @param isError - whether the executor reported a failure.
125
- * @param meta - the tool's private presentation payload, when it attached one.
126
- * @returns the view, or undefined to fall back to the generic card.
127
- */
128
- private safeResult;
129
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * Display-width wrapping for styled text.
3
- *
4
- * Inside the alternate screen the terminal no longer wraps for us: a transcript
5
- * line longer than the viewport must be broken into rows before it is painted,
6
- * or it would overwrite the row below. The lines being broken are already
7
- * styled, so a naive split would cut an escape sequence in half and leak
8
- * gibberish — and a continuation row would lose the colour its first half set.
9
- * @module codsh/src/wrap
10
- */
11
- /**
12
- * Break one styled line into rows no wider than `columns` display columns.
13
- *
14
- * Styles carry across the break: each continuation row re-opens whatever was
15
- * active where the cut fell, and every row that opened a style closes it.
16
- * @param text - the styled line, without a terminator.
17
- * @param columns - display columns available per row.
18
- * @returns the rows, at least one (an empty line yields one empty row).
19
- */
20
- export declare function wrapStyled(text: string, columns: number): string[];
21
- /**
22
- * Wrap many lines, keeping their order.
23
- * @param lines - styled lines.
24
- * @param columns - display columns per row.
25
- * @returns the physical rows they occupy.
26
- */
27
- export declare function wrapAll(lines: readonly string[], columns: number): string[];