@glbgpt/cli 0.1.0-test.1

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 (173) hide show
  1. package/README.md +111 -0
  2. package/dist/src/auth/authClient.d.ts +32 -0
  3. package/dist/src/auth/authClient.js +88 -0
  4. package/dist/src/auth/authClient.js.map +1 -0
  5. package/dist/src/auth/credentialStore.d.ts +22 -0
  6. package/dist/src/auth/credentialStore.js +51 -0
  7. package/dist/src/auth/credentialStore.js.map +1 -0
  8. package/dist/src/auth/loginFlow.d.ts +30 -0
  9. package/dist/src/auth/loginFlow.js +43 -0
  10. package/dist/src/auth/loginFlow.js.map +1 -0
  11. package/dist/src/auth/loopbackServer.d.ts +41 -0
  12. package/dist/src/auth/loopbackServer.js +141 -0
  13. package/dist/src/auth/loopbackServer.js.map +1 -0
  14. package/dist/src/auth/token.d.ts +8 -0
  15. package/dist/src/auth/token.js +15 -0
  16. package/dist/src/auth/token.js.map +1 -0
  17. package/dist/src/commands/accountCommand.d.ts +2 -0
  18. package/dist/src/commands/accountCommand.js +56 -0
  19. package/dist/src/commands/accountCommand.js.map +1 -0
  20. package/dist/src/commands/configCommand.d.ts +4 -0
  21. package/dist/src/commands/configCommand.js +53 -0
  22. package/dist/src/commands/configCommand.js.map +1 -0
  23. package/dist/src/commands/execCommand.d.ts +32 -0
  24. package/dist/src/commands/execCommand.js +122 -0
  25. package/dist/src/commands/execCommand.js.map +1 -0
  26. package/dist/src/commands/loginCommand.d.ts +11 -0
  27. package/dist/src/commands/loginCommand.js +96 -0
  28. package/dist/src/commands/loginCommand.js.map +1 -0
  29. package/dist/src/commands/mediaCommand.d.ts +41 -0
  30. package/dist/src/commands/mediaCommand.js +277 -0
  31. package/dist/src/commands/mediaCommand.js.map +1 -0
  32. package/dist/src/config/configFile.d.ts +30 -0
  33. package/dist/src/config/configFile.js +54 -0
  34. package/dist/src/config/configFile.js.map +1 -0
  35. package/dist/src/config/env.d.ts +6 -0
  36. package/dist/src/config/env.js +24 -0
  37. package/dist/src/config/env.js.map +1 -0
  38. package/dist/src/config/paths.d.ts +6 -0
  39. package/dist/src/config/paths.js +16 -0
  40. package/dist/src/config/paths.js.map +1 -0
  41. package/dist/src/core/catalog.d.ts +49 -0
  42. package/dist/src/core/catalog.js +96 -0
  43. package/dist/src/core/catalog.js.map +1 -0
  44. package/dist/src/core/httpChatBackend.d.ts +31 -0
  45. package/dist/src/core/httpChatBackend.js +134 -0
  46. package/dist/src/core/httpChatBackend.js.map +1 -0
  47. package/dist/src/core/id.d.ts +2 -0
  48. package/dist/src/core/id.js +5 -0
  49. package/dist/src/core/id.js.map +1 -0
  50. package/dist/src/core/runChat.d.ts +28 -0
  51. package/dist/src/core/runChat.js +49 -0
  52. package/dist/src/core/runChat.js.map +1 -0
  53. package/dist/src/core/session.d.ts +44 -0
  54. package/dist/src/core/session.js +70 -0
  55. package/dist/src/core/session.js.map +1 -0
  56. package/dist/src/core/sessionStore.d.ts +39 -0
  57. package/dist/src/core/sessionStore.js +106 -0
  58. package/dist/src/core/sessionStore.js.map +1 -0
  59. package/dist/src/core/toolRegistry.d.ts +19 -0
  60. package/dist/src/core/toolRegistry.js +53 -0
  61. package/dist/src/core/toolRegistry.js.map +1 -0
  62. package/dist/src/core/tools/generateImage.d.ts +10 -0
  63. package/dist/src/core/tools/generateImage.js +34 -0
  64. package/dist/src/core/tools/generateImage.js.map +1 -0
  65. package/dist/src/core/turnLoop.d.ts +31 -0
  66. package/dist/src/core/turnLoop.js +155 -0
  67. package/dist/src/core/turnLoop.js.map +1 -0
  68. package/dist/src/core/types.d.ts +137 -0
  69. package/dist/src/core/types.js +9 -0
  70. package/dist/src/core/types.js.map +1 -0
  71. package/dist/src/exec/input.d.ts +35 -0
  72. package/dist/src/exec/input.js +85 -0
  73. package/dist/src/exec/input.js.map +1 -0
  74. package/dist/src/exec/output.d.ts +39 -0
  75. package/dist/src/exec/output.js +84 -0
  76. package/dist/src/exec/output.js.map +1 -0
  77. package/dist/src/index.d.ts +2 -0
  78. package/dist/src/index.js +253 -0
  79. package/dist/src/index.js.map +1 -0
  80. package/dist/src/mcp/server.d.ts +38 -0
  81. package/dist/src/mcp/server.js +99 -0
  82. package/dist/src/mcp/server.js.map +1 -0
  83. package/dist/src/media/aiApiClient.d.ts +53 -0
  84. package/dist/src/media/aiApiClient.js +97 -0
  85. package/dist/src/media/aiApiClient.js.map +1 -0
  86. package/dist/src/media/errors.d.ts +7 -0
  87. package/dist/src/media/errors.js +70 -0
  88. package/dist/src/media/errors.js.map +1 -0
  89. package/dist/src/media/executor.d.ts +50 -0
  90. package/dist/src/media/executor.js +55 -0
  91. package/dist/src/media/executor.js.map +1 -0
  92. package/dist/src/media/generateImageTool.d.ts +19 -0
  93. package/dist/src/media/generateImageTool.js +120 -0
  94. package/dist/src/media/generateImageTool.js.map +1 -0
  95. package/dist/src/media/manifest.d.ts +23 -0
  96. package/dist/src/media/manifest.js +558 -0
  97. package/dist/src/media/manifest.js.map +1 -0
  98. package/dist/src/media/resolution.d.ts +13 -0
  99. package/dist/src/media/resolution.js +42 -0
  100. package/dist/src/media/resolution.js.map +1 -0
  101. package/dist/src/media/taskLedger.d.ts +17 -0
  102. package/dist/src/media/taskLedger.js +44 -0
  103. package/dist/src/media/taskLedger.js.map +1 -0
  104. package/dist/src/media/taskManager.d.ts +52 -0
  105. package/dist/src/media/taskManager.js +130 -0
  106. package/dist/src/media/taskManager.js.map +1 -0
  107. package/dist/src/media/types.d.ts +80 -0
  108. package/dist/src/media/types.js +15 -0
  109. package/dist/src/media/types.js.map +1 -0
  110. package/dist/src/tui/App.d.ts +34 -0
  111. package/dist/src/tui/App.js +540 -0
  112. package/dist/src/tui/App.js.map +1 -0
  113. package/dist/src/tui/MultilineInput.d.ts +36 -0
  114. package/dist/src/tui/MultilineInput.js +221 -0
  115. package/dist/src/tui/MultilineInput.js.map +1 -0
  116. package/dist/src/tui/atPopup.d.ts +21 -0
  117. package/dist/src/tui/atPopup.js +55 -0
  118. package/dist/src/tui/atPopup.js.map +1 -0
  119. package/dist/src/tui/attachments.d.ts +24 -0
  120. package/dist/src/tui/attachments.js +91 -0
  121. package/dist/src/tui/attachments.js.map +1 -0
  122. package/dist/src/tui/branding.d.ts +22 -0
  123. package/dist/src/tui/branding.js +119 -0
  124. package/dist/src/tui/branding.js.map +1 -0
  125. package/dist/src/tui/chatController.d.ts +188 -0
  126. package/dist/src/tui/chatController.js +614 -0
  127. package/dist/src/tui/chatController.js.map +1 -0
  128. package/dist/src/tui/commands.d.ts +13 -0
  129. package/dist/src/tui/commands.js +22 -0
  130. package/dist/src/tui/commands.js.map +1 -0
  131. package/dist/src/tui/confirmationBridge.d.ts +23 -0
  132. package/dist/src/tui/confirmationBridge.js +47 -0
  133. package/dist/src/tui/confirmationBridge.js.map +1 -0
  134. package/dist/src/tui/inputHistory.d.ts +7 -0
  135. package/dist/src/tui/inputHistory.js +64 -0
  136. package/dist/src/tui/inputHistory.js.map +1 -0
  137. package/dist/src/tui/markdown.d.ts +1 -0
  138. package/dist/src/tui/markdown.js +143 -0
  139. package/dist/src/tui/markdown.js.map +1 -0
  140. package/dist/src/tui/models.d.ts +30 -0
  141. package/dist/src/tui/models.js +54 -0
  142. package/dist/src/tui/models.js.map +1 -0
  143. package/dist/src/tui/run.d.ts +29 -0
  144. package/dist/src/tui/run.js +212 -0
  145. package/dist/src/tui/run.js.map +1 -0
  146. package/dist/src/tui/slashMedia.d.ts +36 -0
  147. package/dist/src/tui/slashMedia.js +86 -0
  148. package/dist/src/tui/slashMedia.js.map +1 -0
  149. package/dist/src/tui/visualLines.d.ts +38 -0
  150. package/dist/src/tui/visualLines.js +110 -0
  151. package/dist/src/tui/visualLines.js.map +1 -0
  152. package/dist/src/util/clipboardImage.d.ts +6 -0
  153. package/dist/src/util/clipboardImage.js +69 -0
  154. package/dist/src/util/clipboardImage.js.map +1 -0
  155. package/dist/src/util/hyperlink.d.ts +10 -0
  156. package/dist/src/util/hyperlink.js +33 -0
  157. package/dist/src/util/hyperlink.js.map +1 -0
  158. package/dist/src/util/imageRef.d.ts +15 -0
  159. package/dist/src/util/imageRef.js +46 -0
  160. package/dist/src/util/imageRef.js.map +1 -0
  161. package/dist/src/util/inlineImage.d.ts +13 -0
  162. package/dist/src/util/inlineImage.js +56 -0
  163. package/dist/src/util/inlineImage.js.map +1 -0
  164. package/dist/src/util/openBrowser.d.ts +5 -0
  165. package/dist/src/util/openBrowser.js +23 -0
  166. package/dist/src/util/openBrowser.js.map +1 -0
  167. package/dist/src/util/retry.d.ts +43 -0
  168. package/dist/src/util/retry.js +116 -0
  169. package/dist/src/util/retry.js.map +1 -0
  170. package/dist/src/version.d.ts +6 -0
  171. package/dist/src/version.js +16 -0
  172. package/dist/src/version.js.map +1 -0
  173. package/package.json +45 -0
@@ -0,0 +1,188 @@
1
+ import type { ChatMessage, ClientTool, ToolResult } from '../core/types.js';
2
+ import { type AttachmentContext } from './attachments.js';
3
+ import { Session } from '../core/session.js';
4
+ import type { TurnLoop } from '../core/turnLoop.js';
5
+ import type { TaskEvent } from '../media/taskManager.js';
6
+ /** One rendered entry in the conversation timeline. */
7
+ export type TimelineItem = {
8
+ kind: 'user';
9
+ text: string;
10
+ } | {
11
+ kind: 'assistant';
12
+ text: string;
13
+ } | {
14
+ kind: 'tool';
15
+ id: string;
16
+ name: string;
17
+ status: 'running' | 'done';
18
+ args?: Record<string, unknown>;
19
+ result?: ToolResult;
20
+ } | {
21
+ kind: 'note';
22
+ text: string;
23
+ } | {
24
+ kind: 'media';
25
+ taskId: string;
26
+ status: 'done' | 'failed';
27
+ localPath?: string;
28
+ reason?: string;
29
+ } | {
30
+ kind: 'error';
31
+ text: string;
32
+ };
33
+ export interface ViewState {
34
+ model: string;
35
+ items: TimelineItem[];
36
+ /** True while a turn is in flight (input disabled, spinner shown). */
37
+ busy: boolean;
38
+ /** Generation tasks currently polling in the background (drives the task summary bar). */
39
+ runningTasks: RunningTask[];
40
+ /** Messages typed while busy — attachments already resolved (snapshot at Enter time);
41
+ * sent automatically, in order, when the turn ends. */
42
+ queued: QueuedMessage[];
43
+ /** Cumulative session usage (chat tokens are informational; billing is server-side). */
44
+ sessionUsage: SessionUsage;
45
+ }
46
+ /** A message resolved at Enter time and waiting for the current turn to finish. */
47
+ export interface QueuedMessage {
48
+ content: string | import('../core/types.js').ContentPart[];
49
+ display: string;
50
+ }
51
+ export interface SessionUsage {
52
+ promptTokens: number;
53
+ completionTokens: number;
54
+ turns: number;
55
+ /** Sum of estimated credits for media tasks submitted this session (estimates, not the bill). */
56
+ mediaCreditsEstimated: number;
57
+ mediaSubmits: number;
58
+ }
59
+ /** A background generation task still in flight. */
60
+ export interface RunningTask {
61
+ taskId: string;
62
+ status: string;
63
+ elapsedMs: number;
64
+ }
65
+ /** Optional capabilities wired in by run.tsx; each slash command degrades gracefully without one. */
66
+ export interface ControllerExtras {
67
+ /** The same media tool instances the model uses (shared confirmation/ledger/polling path). */
68
+ mediaTools?: {
69
+ image?: ClientTool;
70
+ video?: ClientTool;
71
+ };
72
+ /** Recent task records for `/tasks` (e.g. TaskLedger.list). */
73
+ listRecentTasks?: () => Promise<Array<{
74
+ taskId: string;
75
+ model: string;
76
+ prompt: string;
77
+ }>>;
78
+ /** One extra status line for `/status` (e.g. plan/balance from the account API). */
79
+ fetchAccountLine?: () => Promise<string | null>;
80
+ /** Full multi-line account summary for `/account` (email · plan · balance). */
81
+ fetchAccount?: () => Promise<string>;
82
+ /** Recent spend lines for `/transactions` (authoritative billing). */
83
+ fetchTransactions?: () => Promise<string>;
84
+ /** Re-authenticate in place (`/login`), hot-swapping the token everywhere; returns a status line. */
85
+ reauth?: (mode: 'browser' | 'no-browser') => Promise<string>;
86
+ /** Sign out (`/logout`): clear stored credentials; returns a status line. */
87
+ logout?: () => Promise<string>;
88
+ /** Injectable attachment IO overrides (tests). */
89
+ attachmentIO?: Pick<AttachmentContext, 'readFile' | 'readClipboard'>;
90
+ }
91
+ /**
92
+ * Headless controller for the chat TUI: owns the view state and maps the engine's
93
+ * EngineEvent stream into a renderable timeline. Contains no Ink/React so it can be
94
+ * unit-tested deterministically; the Ink view is a thin layer over it.
95
+ */
96
+ export declare class ChatController {
97
+ private session;
98
+ private readonly turnLoop;
99
+ private readonly extras;
100
+ private state;
101
+ private readonly subscribers;
102
+ /** Index of the assistant item currently collecting deltas, or -1 if none is open. */
103
+ private openAssistant;
104
+ /** Abort controller for the in-flight turn (null when idle). */
105
+ private turnAbort;
106
+ /** Serializes busy-time enqueues so rapid submits keep keystroke order. */
107
+ private enqueueChain;
108
+ /** Output URL of the most recently completed generation (for `@image` attachments). */
109
+ private lastMediaUrl;
110
+ /** Session start (for the exit summary). */
111
+ readonly startedAt: number;
112
+ constructor(session: Session, turnLoop: TurnLoop, extras?: ControllerExtras);
113
+ getState(): ViewState;
114
+ /**
115
+ * Timeline items safe to persist: a tool row still 'running' mid-turn has no outcome —
116
+ * persisting it would resurrect as a forever-spinning zombie on resume. The settled row
117
+ * re-persists when the turn ends.
118
+ */
119
+ getPersistableItems(): TimelineItem[];
120
+ /** The session currently being edited (swapped by `/new`); used for persistence. */
121
+ getSession(): Session;
122
+ /**
123
+ * Restore the visible timeline on `resume`. Prefers the PERSISTED transcript (stored
124
+ * alongside the messages, Codex-rollout style); falls back to deriving it from the
125
+ * model messages for sessions saved before transcripts were persisted.
126
+ */
127
+ hydrateFromSession(persisted?: unknown[]): void;
128
+ /** Subscribe to state changes. Returns an unsubscribe function. */
129
+ subscribe(cb: (state: ViewState) => void): () => void;
130
+ switchModel(model: string): void;
131
+ /** Start a fresh conversation (a new session id), keeping the current model. */
132
+ reset(): void;
133
+ showHelp(): void;
134
+ /** Track background generation tasks: progress updates the summary bar; completion hits the timeline. */
135
+ handleTaskEvent(e: TaskEvent): void;
136
+ /**
137
+ * `/image` / `/video`: run the same client tool the model uses, so the confirmation gate,
138
+ * ledger, background polling, and error mapping are identical to the natural-language path.
139
+ * `rest` accepts the CLI's flag syntax (`a cat --ar 16:9 --res 2K -m nano-banana-2 ...`).
140
+ */
141
+ runMedia(kind: 'image' | 'video', rest: string): Promise<void>;
142
+ /** `/tasks`: running tasks plus recent history. */
143
+ showTasks(): Promise<void>;
144
+ /** `/status`: session/model basics immediately, account line when it arrives. */
145
+ showStatus(): Promise<void>;
146
+ /** `/models`: list chat + image/video models available (server-driven catalog applied). */
147
+ showModels(): void;
148
+ /** `/account`: full account summary (email · plan · balance). */
149
+ showAccount(): Promise<void>;
150
+ /** `/transactions`: authoritative recent spend. */
151
+ showTransactions(): Promise<void>;
152
+ /** `/login`: re-authenticate in place, hot-swapping the token everywhere. */
153
+ reauth(mode: 'browser' | 'no-browser'): Promise<void>;
154
+ /** `/logout`: clear stored credentials. */
155
+ logout(): Promise<void>;
156
+ /** `/resume`: swap in a previously saved session and rebuild the timeline. */
157
+ replaceSession(session: Session, persistedTimeline?: unknown[]): void;
158
+ note(text: string): void;
159
+ /**
160
+ * Submit a user message and run one turn to completion, updating the timeline as events
161
+ * arrive. `displayText` (when given) is what the transcript shows — e.g. "[Image #1]"
162
+ * placeholders — while `text` carries the expanded form for attachment resolution.
163
+ *
164
+ * Attachments resolve at ENTER time (snapshot semantics — @clipboard reads the clipboard
165
+ * now, not minutes later when a queued message flushes), and the queue stores the RESOLVED
166
+ * content so pasted images survive queueing.
167
+ */
168
+ submit(text: string, displayText?: string): Promise<void>;
169
+ /** Resolve `@…` attachments into a queueable message; null → error already noted. */
170
+ private resolveForSubmit;
171
+ /** Run one turn whose attachments are already resolved. Caller owns the busy flag. */
172
+ private runResolvedTurn;
173
+ /** Send the next queued (already-resolved) message, if any (runs after each turn settles). */
174
+ private flushQueued;
175
+ /** Accumulate the estimated cost of a submitted media task (estimates only, not the bill). */
176
+ private recordMediaSubmit;
177
+ /** `/cost`: session usage breakdown. Authoritative spend lives in `glbgpt account transactions`. */
178
+ showCost(): void;
179
+ /** Interrupt the in-flight turn (Esc). Partial output is kept; no-op when idle. */
180
+ interrupt(): void;
181
+ private onEvent;
182
+ private addItem;
183
+ private replaceItem;
184
+ private setState;
185
+ private emit;
186
+ }
187
+ /** Convert a stored message history into renderable timeline items (for resume). */
188
+ export declare function timelineFromMessages(messages: ChatMessage[]): TimelineItem[];