@scrylog/cli 0.3.0 → 0.3.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.
Files changed (195) hide show
  1. package/dist/assets/highlights-eq9cgrbb.scm +604 -0
  2. package/dist/assets/highlights-ghv9g403.scm +205 -0
  3. package/dist/assets/highlights-hk7bwhj4.scm +284 -0
  4. package/dist/assets/highlights-r812a2qc.scm +150 -0
  5. package/dist/assets/highlights-x6tmsnaa.scm +115 -0
  6. package/dist/assets/injections-73j83es3.scm +27 -0
  7. package/dist/assets/parser.worker-xyhf83rf.js +4563 -0
  8. package/dist/assets/tree-sitter-3jzf13jk.wasm +0 -0
  9. package/dist/assets/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
  10. package/dist/assets/tree-sitter-markdown-411r6y9b.wasm +0 -0
  11. package/dist/assets/tree-sitter-markdown_inline-j5349f42.wasm +0 -0
  12. package/dist/assets/tree-sitter-typescript-zxjzwt75.wasm +0 -0
  13. package/dist/assets/tree-sitter-zig-e78zbjpm.wasm +0 -0
  14. package/dist/cli/index.js +499 -0
  15. package/dist/cli/index.js.map +61 -0
  16. package/dist/daemon/index.js +670 -0
  17. package/dist/daemon/index.js.map +1475 -0
  18. package/dist/hooks/claude.js +6 -0
  19. package/dist/hooks/claude.js.map +11 -0
  20. package/dist/hooks/codex.js +10 -0
  21. package/dist/hooks/codex.js.map +11 -0
  22. package/dist/mcp/index.js +100 -0
  23. package/dist/mcp/index.js.map +231 -0
  24. package/dist/oc/index.js +21 -0
  25. package/dist/oc/index.js.map +10 -0
  26. package/package.json +16 -13
  27. package/src/api/docs/sessions.keys.ts +0 -6
  28. package/src/api/docs/sessions.ts +0 -82
  29. package/src/api/docs/system.keys.ts +0 -5
  30. package/src/api/docs/system.ts +0 -69
  31. package/src/api/docs/usage.keys.ts +0 -3
  32. package/src/api/docs/usage.ts +0 -24
  33. package/src/api/docs/webhooks.keys.ts +0 -5
  34. package/src/api/docs/webhooks.ts +0 -78
  35. package/src/api/index.ts +0 -18
  36. package/src/api/lib/auth.ts +0 -43
  37. package/src/api/lib/errors.ts +0 -28
  38. package/src/api/lib/route.ts +0 -18
  39. package/src/api/models/claude.ts +0 -4
  40. package/src/api/models/codex.ts +0 -4
  41. package/src/api/models/opencode.ts +0 -11
  42. package/src/api/routes/sessions.ts +0 -51
  43. package/src/api/routes/system.ts +0 -106
  44. package/src/api/routes/usage.ts +0 -15
  45. package/src/api/routes/webhooks/claude.ts +0 -149
  46. package/src/api/routes/webhooks/codex.ts +0 -175
  47. package/src/api/routes/webhooks/opencode.ts +0 -112
  48. package/src/api/routes.ts +0 -93
  49. package/src/api/schemas/common.ts +0 -29
  50. package/src/api/schemas/sessions.ts +0 -86
  51. package/src/api/schemas/usage.ts +0 -51
  52. package/src/api/schemas/webhooks/claude.ts +0 -32
  53. package/src/api/schemas/webhooks/codex.ts +0 -34
  54. package/src/api/schemas/webhooks/opencode.ts +0 -29
  55. package/src/api/services/claude-session.ts +0 -9
  56. package/src/api/services/codex-session.ts +0 -8
  57. package/src/api/services/opencode-session.ts +0 -73
  58. package/src/classifier.ts +0 -206
  59. package/src/cli/commands.ts +0 -714
  60. package/src/cli/index.ts +0 -18
  61. package/src/cli/program.ts +0 -175
  62. package/src/cli/prompt.ts +0 -44
  63. package/src/daemon/cli.ts +0 -27
  64. package/src/daemon/collectors/claude/README.md +0 -108
  65. package/src/daemon/collectors/claude/collector.ts +0 -423
  66. package/src/daemon/collectors/claude/discovery.ts +0 -127
  67. package/src/daemon/collectors/claude/hooks.ts +0 -181
  68. package/src/daemon/collectors/claude/index.ts +0 -8
  69. package/src/daemon/collectors/claude/jsonl.ts +0 -85
  70. package/src/daemon/collectors/claude/transcript.ts +0 -246
  71. package/src/daemon/collectors/codex/README.md +0 -147
  72. package/src/daemon/collectors/codex/collector.ts +0 -661
  73. package/src/daemon/collectors/codex/discovery.ts +0 -104
  74. package/src/daemon/collectors/codex/hooks.ts +0 -179
  75. package/src/daemon/collectors/codex/index.ts +0 -7
  76. package/src/daemon/collectors/codex/jsonl.ts +0 -108
  77. package/src/daemon/collectors/codex/transcript.ts +0 -299
  78. package/src/daemon/collectors/git.ts +0 -353
  79. package/src/daemon/collectors/herdr/collector.ts +0 -128
  80. package/src/daemon/collectors/herdr/index.ts +0 -2
  81. package/src/daemon/collectors/herdr/normalization.ts +0 -111
  82. package/src/daemon/collectors/opencode/README.md +0 -106
  83. package/src/daemon/collectors/opencode/collector.ts +0 -545
  84. package/src/daemon/collectors/opencode/discovery.ts +0 -257
  85. package/src/daemon/collectors/opencode/index.ts +0 -5
  86. package/src/daemon/collectors/opencode/session-builder.ts +0 -59
  87. package/src/daemon/collectors/opencode-db.ts +0 -294
  88. package/src/daemon/collectors/process.ts +0 -201
  89. package/src/daemon/collectors/tmux/README.md +0 -128
  90. package/src/daemon/collectors/tmux/collector.ts +0 -492
  91. package/src/daemon/collectors/tmux/enrichment.ts +0 -242
  92. package/src/daemon/collectors/tmux/index.ts +0 -4
  93. package/src/daemon/collectors/tmux/parse.ts +0 -128
  94. package/src/daemon/collectors/usage.ts +0 -259
  95. package/src/daemon/index.ts +0 -209
  96. package/src/daemon/scheduler.ts +0 -86
  97. package/src/daemon/store.ts +0 -630
  98. package/src/detect.ts +0 -143
  99. package/src/hooks/claude.ts +0 -596
  100. package/src/hooks/codex.ts +0 -517
  101. package/src/legacy/classifier.ts +0 -215
  102. package/src/legacy/detect.ts +0 -143
  103. package/src/mcp/client-server.ts +0 -21
  104. package/src/mcp/http-handler.ts +0 -126
  105. package/src/mcp/index.ts +0 -61
  106. package/src/mcp/resources/config-current.ts +0 -19
  107. package/src/mcp/resources/index.ts +0 -11
  108. package/src/mcp/resources/sessions-active.ts +0 -19
  109. package/src/mcp/resources/sessions-all.ts +0 -19
  110. package/src/mcp/schemas/sessions.ts +0 -3
  111. package/src/mcp/server.ts +0 -17
  112. package/src/mcp/services/api-adapter.ts +0 -48
  113. package/src/mcp/services/data-source.ts +0 -22
  114. package/src/mcp/services/store-adapter.ts +0 -40
  115. package/src/mcp/tools/get-active-sessions.ts +0 -16
  116. package/src/mcp/tools/get-session-children.ts +0 -24
  117. package/src/mcp/tools/get-session-messages.ts +0 -24
  118. package/src/mcp/tools/get-session.ts +0 -23
  119. package/src/mcp/tools/index.ts +0 -15
  120. package/src/mcp/tools/list-sessions.ts +0 -16
  121. package/src/oc/index.ts +0 -302
  122. package/src/service/manager.ts +0 -284
  123. package/src/shared/config.ts +0 -511
  124. package/src/shared/ipc.ts +0 -80
  125. package/src/shared/logger.ts +0 -248
  126. package/src/shared/paths.ts +0 -73
  127. package/src/shared/platform.ts +0 -110
  128. package/src/shared/session-exclusions.ts +0 -5
  129. package/src/shared/session-view.ts +0 -302
  130. package/src/shared/terminal-capabilities.ts +0 -130
  131. package/src/shared/types.ts +0 -330
  132. package/src/shared/utils.ts +0 -339
  133. package/src/shared/version.ts +0 -44
  134. package/src/tui/App.tsx +0 -240
  135. package/src/tui/client.ts +0 -163
  136. package/src/tui/components/BindingsModal.tsx +0 -82
  137. package/src/tui/components/DashboardHeader.tsx +0 -256
  138. package/src/tui/components/KeyBar.tsx +0 -67
  139. package/src/tui/components/SessionDetailModal.tsx +0 -169
  140. package/src/tui/components/SessionsView.tsx +0 -184
  141. package/src/tui/components/TabBar.tsx +0 -40
  142. package/src/tui/components/UsageSummaryPane.tsx +0 -272
  143. package/src/tui/components/UsageView.tsx +0 -242
  144. package/src/tui/components/tool-icons.ts +0 -24
  145. package/src/tui/index.tsx +0 -106
  146. package/src/tui/keybindings.ts +0 -49
  147. package/src/tui/model.ts +0 -295
  148. package/src/tui/state.ts +0 -77
  149. package/src/tui/theme.ts +0 -110
  150. package/src/types.ts +0 -113
  151. package/src/usage/README.md +0 -323
  152. package/src/usage/api.ts +0 -99
  153. package/src/usage/client.ts +0 -3
  154. package/src/usage/clients/anthropic-oauth-usage.ts +0 -258
  155. package/src/usage/clients/anthropic-web-usage.ts +0 -329
  156. package/src/usage/clients/claude-cli-probe.ts +0 -513
  157. package/src/usage/clients/codex-app-server.ts +0 -354
  158. package/src/usage/clients/codex-oauth-usage.ts +0 -240
  159. package/src/usage/clients/opencode-go-api.ts +0 -100
  160. package/src/usage/clients/opencode-go-usage.ts +0 -577
  161. package/src/usage/errors.ts +0 -33
  162. package/src/usage/index.ts +0 -20
  163. package/src/usage/local/opencode-go-local.ts +0 -194
  164. package/src/usage/mappers.ts +0 -282
  165. package/src/usage/planner.ts +0 -118
  166. package/src/usage/providers/claude.ts +0 -233
  167. package/src/usage/providers/codex.ts +0 -115
  168. package/src/usage/providers/opencode-go.ts +0 -115
  169. package/src/usage/resolver.ts +0 -4
  170. package/src/usage/resolvers/browser-cookies.ts +0 -808
  171. package/src/usage/resolvers/claude-auth.ts +0 -208
  172. package/src/usage/resolvers/claude-cli.ts +0 -24
  173. package/src/usage/resolvers/claude-desktop-auth.ts +0 -170
  174. package/src/usage/resolvers/claude-web.ts +0 -82
  175. package/src/usage/resolvers/codex-auth.ts +0 -174
  176. package/src/usage/resolvers/keychain-coordinator.ts +0 -397
  177. package/src/usage/resolvers/opencode-go-web.ts +0 -55
  178. package/src/usage/types.ts +0 -225
  179. package/src/usage/web-session-cache.ts +0 -37
  180. /package/{src/tui → dist/cli}/assets/providers/SOURCES.md +0 -0
  181. /package/{src/tui → dist/cli}/assets/providers/claude-terminal.png +0 -0
  182. /package/{src/tui → dist/cli}/assets/providers/claude-terminal.svg +0 -0
  183. /package/{src/tui → dist/cli}/assets/providers/claude.png +0 -0
  184. /package/{src/tui → dist/cli}/assets/providers/copilot.png +0 -0
  185. /package/{src/tui → dist/cli}/assets/providers/copilot.svg +0 -0
  186. /package/{src/tui → dist/cli}/assets/providers/openai-terminal.png +0 -0
  187. /package/{src/tui → dist/cli}/assets/providers/openai-terminal.svg +0 -0
  188. /package/{src/tui → dist/cli}/assets/providers/openai.png +0 -0
  189. /package/{src/tui → dist/cli}/assets/providers/opencode-terminal.png +0 -0
  190. /package/{src/tui → dist/cli}/assets/providers/opencode-terminal.svg +0 -0
  191. /package/{src/tui → dist/cli}/assets/providers/opencode.png +0 -0
  192. /package/{src/tui → dist/cli}/assets/providers/shell.png +0 -0
  193. /package/{src/tui → dist/cli}/assets/providers/shell.svg +0 -0
  194. /package/{src/tui → dist/cli}/assets/providers/unknown.png +0 -0
  195. /package/{src/tui → dist/cli}/assets/providers/unknown.svg +0 -0
@@ -1,330 +0,0 @@
1
- // ── Legacy types (preserved for backward compat with collectors/classifier) ────
2
-
3
- export type ToolKind = "opencode" | "claude" | "codex" | "copilotcli" | "shell" | "unknown";
4
-
5
- export type PaneState = "working" | "idle" | "waiting-input" | "shell" | "unknown";
6
-
7
- export interface SessionInfo {
8
- name: string;
9
- attached: boolean;
10
- windows: number;
11
- }
12
-
13
- export interface TmuxPaneRecord {
14
- sessionName: string;
15
- windowIndex: number;
16
- windowName: string;
17
- paneIndex: number;
18
- paneId: string;
19
- panePid: number;
20
- currentCommand: string;
21
- currentPath: string;
22
- active: boolean;
23
- tty: string;
24
- title: string;
25
- width: number;
26
- height: number;
27
- /** OpenCode session ID written by the scrylog plugin via @opencode-session pane option. */
28
- opencodeSession?: string;
29
- /** Claude session ID written by the scrylog hook via @claude-session pane option. */
30
- claudeSession?: string;
31
- /** Codex session ID written by the scrylog hook via @codex-session pane option. */
32
- codexSession?: string;
33
- }
34
-
35
- export interface ProjectInfo {
36
- displayName: string;
37
- compactLabel: string;
38
- sourcePath: string;
39
- isGitRepository: boolean;
40
- gitRootPath?: string;
41
- repositoryIdentityPath?: string;
42
- branch?: string;
43
- isWorktree?: boolean;
44
- remoteName?: string;
45
- remoteUrl?: string;
46
- }
47
-
48
- export interface EnrichedPaneRecord extends TmuxPaneRecord {
49
- project: ProjectInfo;
50
- }
51
-
52
- export interface ProcessInfo {
53
- pid: number;
54
- ppid: number;
55
- state: string;
56
- elapsed: string;
57
- command: string;
58
- comm: string;
59
- }
60
-
61
- export interface DetectionReason {
62
- label: string;
63
- detail: string;
64
- }
65
-
66
- export interface PaneSample {
67
- paneId: string;
68
- lines: string[];
69
- preview: string;
70
- }
71
-
72
- export interface PaneModel extends EnrichedPaneRecord {
73
- processTree: ProcessInfo[];
74
- processChain: string[];
75
- sample: PaneSample | null;
76
- tool: ToolKind;
77
- state: PaneState;
78
- toolReasons: DetectionReason[];
79
- stateReasons: DetectionReason[];
80
- summary: string;
81
- lastChangedAt: number;
82
- stableForMs: number;
83
- hasAttention: boolean;
84
- }
85
-
86
- export interface SnapshotError {
87
- source: string;
88
- message: string;
89
- }
90
-
91
- export interface DashboardSnapshot {
92
- sessions: SessionInfo[];
93
- panes: PaneModel[];
94
- generatedAt: number;
95
- errors: SnapshotError[];
96
- }
97
-
98
- export interface FilterOptions {
99
- query: string;
100
- actionableOnly: boolean;
101
- tool: ToolKind | "all";
102
- state: PaneState | "all";
103
- }
104
-
105
- // Re-export usage types so consumers can import from shared/types
106
- export type {
107
- UsageState,
108
- UsageProviderEntry,
109
- UsageWindow,
110
- ProviderCostSnapshot,
111
- } from "../usage/types";
112
-
113
- export interface SnapshotHistory {
114
- tool: ToolKind;
115
- state: PaneState;
116
- lastFingerprint: string;
117
- lastChangedAt: number;
118
- stableCount: number;
119
- }
120
-
121
- export interface CollectorOptions {
122
- previewLines: number;
123
- detailLines: number;
124
- refreshMs: number;
125
- }
126
-
127
- export interface AppOptions extends CollectorOptions {
128
- selectedPaneId?: string;
129
- }
130
-
131
- // ── New unified session model ─────────────────────────────────────────────────
132
-
133
- /** How the agent session was detected */
134
- export type SessionSource = "tmux" | "herdr" | "standalone";
135
-
136
- /** The tool type — extended with "claude" and "error" variants */
137
- export type SessionTool = "opencode" | "claude" | "codex" | "copilotcli" | "shell" | "unknown";
138
-
139
- /** The current state of the session */
140
- export type SessionState = "working" | "idle" | "waiting-input" | "error" | "shell" | "unknown";
141
-
142
- /** OpenCode-specific session metadata */
143
- export interface OpenCodeSessionMeta {
144
- sessionId: string;
145
- instanceUrl: string;
146
- /** Number of pending permission/question prompts not yet replied to */
147
- pendingAttentionCount?: number;
148
- }
149
-
150
- /** Claude-specific session metadata */
151
- export interface ClaudeSessionMeta {
152
- sessionId: string;
153
- transcriptPath: string;
154
- hookEventType?: string;
155
- hookEventTime?: number;
156
- hookSeq?: number;
157
- permissionMode?: string;
158
- startSource?: string;
159
- endReason?: string;
160
- errorType?: string;
161
- attentionKind?: "permission" | "question" | "turn" | "none";
162
- toolName?: string;
163
- toolInputSummary?: string;
164
- toolResultStatus?: "started" | "completed" | "error" | "blocked" | "denied" | "unknown";
165
- agentId?: string;
166
- agentType?: string;
167
- }
168
-
169
- /** Codex-specific session metadata */
170
- export interface CodexSessionMeta {
171
- sessionId: string;
172
- transcriptPath: string;
173
- hookEventType?: string;
174
- hookEventTime?: number;
175
- hookSeq?: number;
176
- permissionMode?: string;
177
- model?: string;
178
- startSource?: string;
179
- endReason?: string;
180
- attentionKind?: "permission" | "question" | "turn" | "none";
181
- toolName?: string;
182
- toolInputSummary?: string;
183
- toolResultStatus?: "started" | "completed" | "error" | "blocked" | "denied" | "unknown";
184
- turnId?: string;
185
- agentId?: string;
186
- agentType?: string;
187
- agentNickname?: string;
188
- agentRole?: string;
189
- parentSessionId?: string;
190
- forkedFromId?: string;
191
- }
192
-
193
- /** Herdr pane and agent metadata */
194
- export interface HerdrSessionMeta {
195
- paneId: string;
196
- terminalId?: string;
197
- workspaceId?: string;
198
- workspace?: string;
199
- tabId?: string;
200
- tab?: string;
201
- /** Explicit pane name — undefined when herdr only derived it from the agent name */
202
- name?: string;
203
- focused?: boolean;
204
- providerSource: "socket" | "cli";
205
- agent?: string;
206
- agentStatus?: string;
207
- agentSessionId?: string;
208
- }
209
-
210
- /** Unified session model used throughout daemon, API, MCP, and TUI */
211
- export interface SessionModel {
212
- id: string;
213
- source: SessionSource;
214
- tool: SessionTool;
215
- state: SessionState;
216
- project?: ProjectInfo;
217
- tmux?: {
218
- session: string;
219
- window: string;
220
- pane: string;
221
- /** tmux window (tab) name, used as display-name fallback */
222
- windowName?: string;
223
- };
224
- summary: string;
225
- lastActivity: number;
226
- stateChangedAt?: number;
227
- activeTool?: string;
228
- /** Populated when detected via OpenCode SDK */
229
- opencode?: OpenCodeSessionMeta;
230
- /** Populated when detected via Claude JSONL transcript */
231
- claude?: ClaudeSessionMeta;
232
- /** Populated when detected via Codex JSONL transcript or hooks */
233
- codex?: CodexSessionMeta;
234
- /** Populated for panes discovered through herdr */
235
- herdr?: HerdrSessionMeta;
236
- /** Populated when detected via legacy heuristics */
237
- legacyPaneId?: string;
238
- /** Data source description for UI display */
239
- detectionSource?: "opencode-sdk" | "opencode-hook" | "claude-transcript" | "claude-hook" | "codex-transcript" | "codex-hook" | "fallback-detection" | "opencode-db" | "herdr";
240
- /** ID of the parent session when this is a sub-agent session spawned by another session */
241
- parentSessionId?: string;
242
- /** IDs of direct child sessions spawned by this session (populated on parent sessions) */
243
- childSessionIds?: string[];
244
- /** Timestamp when the session first entered "working" state in the current work stretch.
245
- * Preserved across brief idle→working transitions (grace period). */
246
- lastWorkingChangedAt?: number;
247
- /** Timestamp when the last child session transitioned away from "working" or "waiting-input".
248
- * Used to apply a grace period for parent sessions that briefly go idle between sub-agent turns. */
249
- lastChildActiveAt?: number;
250
-
251
- // ── Extended fields (populated by tmux collector / enrichment) ────────────
252
- /** Full process tree rooted at the pane PID */
253
- processTree?: ProcessInfo[];
254
- /** Compact process chain (comm names) */
255
- processChain?: string[];
256
- /** Captured pane output sample */
257
- sample?: PaneSample | null;
258
- /** Reasons for tool detection classification */
259
- toolReasons?: DetectionReason[];
260
- /** Reasons for state detection classification */
261
- stateReasons?: DetectionReason[];
262
- /** Milliseconds the session has been in the current state */
263
- stableForMs?: number;
264
- /** Whether the session needs user attention */
265
- hasAttention?: boolean;
266
- /** Current command running in the pane */
267
- currentCommand?: string;
268
- /** Current working directory of the pane */
269
- currentPath?: string;
270
- /** PID of the tmux pane shell process */
271
- panePid?: number;
272
- /** TTY device path */
273
- tty?: string;
274
- /** Pane title set by the running program */
275
- paneTitle?: string;
276
- }
277
-
278
- /**
279
- * Minimal session summary used in the API tree response (children arrays).
280
- * Contains only the fields needed to understand a sub-session at a glance.
281
- */
282
- export interface SessionSummary {
283
- id: string;
284
- tool: SessionTool;
285
- state: SessionState;
286
- summary: string;
287
- lastActivity: number;
288
- parentSessionId?: string;
289
- }
290
-
291
- // ── Daemon state ──────────────────────────────────────────────────────────────
292
-
293
- export interface DaemonState {
294
- tmuxSessions: SessionInfo[];
295
- sessions: SessionModel[];
296
- collectorStatus: Record<string, CollectorStatus>;
297
- usage: import("../usage/types").UsageState;
298
- startedAt: number;
299
- refreshedAt: number;
300
- }
301
-
302
- export interface HealthResponse {
303
- ok: true;
304
- version: string;
305
- startedAt: number;
306
- refreshedAt: number;
307
- collectors: Record<string, CollectorStatus>;
308
- }
309
-
310
- export type DaemonHealth = Pick<HealthResponse, "ok"> & Partial<Omit<HealthResponse, "ok">>;
311
-
312
- export interface CollectorStatus {
313
- name: string;
314
- running: boolean;
315
- lastRunAt: number;
316
- lastDurationMs?: number;
317
- skippedPolls?: number;
318
- errorCount?: number;
319
- lastError?: string;
320
- }
321
-
322
- // ── Store events ──────────────────────────────────────────────────────────────
323
-
324
- export type StoreEvent =
325
- | { type: "session:added"; session: SessionModel }
326
- | { type: "session:updated"; session: SessionModel }
327
- | { type: "session:removed"; sessionId: string }
328
- | { type: "state:refreshed"; timestamp: number }
329
- | { type: "error"; source: string; message: string }
330
- | { type: "usage:updated"; usage: import("../usage/types").UsageState };
@@ -1,339 +0,0 @@
1
- import { basename } from "node:path";
2
-
3
- export interface CommandOptions {
4
- cwd?: string;
5
- timeoutMs?: number;
6
- }
7
-
8
- export function runCommand(command: string[], timeoutMs?: number): string {
9
- return runCommandInDirectory(command, { timeoutMs });
10
- }
11
-
12
- export function runCommandInDirectory(command: string[], options: CommandOptions = {}): string {
13
- const proc = Bun.spawnSync(command, {
14
- cwd: options.cwd,
15
- stdout: "pipe",
16
- stderr: "pipe",
17
- ...(options.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
18
- });
19
-
20
- if (proc.exitCode !== 0) {
21
- const error = Buffer.from(proc.stderr).toString("utf8").trim() || `Command failed: ${command.join(" ")}`;
22
- throw new Error(error);
23
- }
24
-
25
- return Buffer.from(proc.stdout).toString("utf8");
26
- }
27
-
28
- export function maybeRunCommand(command: string[], timeoutMs?: number): { ok: true; output: string } | { ok: false; error: string } {
29
- return maybeRunCommandInDirectory(command, { timeoutMs });
30
- }
31
-
32
- export function maybeRunCommandInDirectory(command: string[], options: CommandOptions = {}): { ok: true; output: string } | { ok: false; error: string } {
33
- try {
34
- return { ok: true, output: runCommandInDirectory(command, options) };
35
- } catch (error) {
36
- return { ok: false, error: error instanceof Error ? error.message : String(error) };
37
- }
38
- }
39
-
40
- export function parseIntSafe(value: string, fallback = 0): number {
41
- const parsed = Number.parseInt(value, 10);
42
- return Number.isNaN(parsed) ? fallback : parsed;
43
- }
44
-
45
- export function safeBasename(pathname: string): string {
46
- if (!pathname) {
47
- return "-";
48
- }
49
-
50
- const base = basename(pathname);
51
- return base || pathname;
52
- }
53
-
54
- export function truncate(value: string, length: number): string {
55
- if (value.length <= length) {
56
- return value;
57
- }
58
-
59
- if (length <= 1) {
60
- return value.slice(0, length);
61
- }
62
-
63
- return `${value.slice(0, length - 1)}...`;
64
- }
65
-
66
- export function compactWhitespace(value: string): string {
67
- return value.replace(/\s+/g, " ").trim();
68
- }
69
-
70
- export function cleanSummaryText(value: string): string {
71
- return compactWhitespace(stripAnsiAndUi(value))
72
- .replace(/^[•\-\*]+\s*/, "")
73
- .replace(/^>\s+/, "")
74
- .trim();
75
- }
76
-
77
- export function stripAnsiAndUi(value: string): string {
78
- return value
79
- .replace(/\u001b\[[0-9;]*m/g, "")
80
- .replace(/[│┃╭╮╰╯╹▀─]+/g, " ")
81
- .replace(/[›]/g, ">")
82
- .trim();
83
- }
84
-
85
- export function isMostlyUiNoise(value: string): boolean {
86
- const cleaned = cleanSummaryText(value);
87
- if (!cleaned) {
88
- return true;
89
- }
90
-
91
- return /(ctrl\+t variants|tab agents|ctrl\+p commands|100% context left|Tip: Use \/feedback|\? for shortcuts|↑↓ select|enter submit|esc dismiss)/i.test(cleaned)
92
- || isOpencodeFooterLine(cleaned);
93
- }
94
-
95
- export function isLowValueSummaryLine(value: string): boolean {
96
- const cleaned = cleanSummaryText(value);
97
- if (!cleaned) {
98
- return true;
99
- }
100
-
101
- return (
102
- isMostlyUiNoise(cleaned)
103
- || /^>\s*implement\s*\{feature\}/i.test(cleaned)
104
- || /^\d+\.\s/.test(cleaned)
105
- || /^[.·•\u2800-\u28ff\s]{4,}$/u.test(cleaned)
106
- || /^\$\s/.test(cleaned)
107
- || /^▣\s+(build|plan)\b/i.test(cleaned)
108
- || /^(model:|directory:)/i.test(cleaned)
109
- || /^(working\s*\(|build\b|plan\b|asked\s+\d+\s+question)/i.test(cleaned)
110
- || /^gpt-[\w.-]+.*% left/i.test(cleaned)
111
- || /^(build|plan)\s+.*(github copilot|openai)$/i.test(cleaned)
112
- || /^(yes, continue|no, quit|press enter to continue)$/i.test(cleaned)
113
- );
114
- }
115
-
116
- export function isSuggestionStyleText(value: string): boolean {
117
- const cleaned = cleanSummaryText(value);
118
- if (!cleaned) {
119
- return false;
120
- }
121
-
122
- return (
123
- /^(next steps?|siguientes? pasos?|siguiente paso natural|recommended next step|next step natural|natural next step)/i.test(cleaned)
124
- || /recommended by default|recomendado por defecto/i.test(cleaned)
125
- || /^(si quieres|if you want|you can|puedes)\b/i.test(cleaned)
126
- || /^\d+\.\s/.test(cleaned)
127
- );
128
- }
129
-
130
- export function isOpencodeFooterLine(value: string): boolean {
131
- const cleaned = cleanSummaryText(value);
132
- if (!cleaned) {
133
- return false;
134
- }
135
-
136
- return /(esc|escape)(?:\s+to)?\s+(interrupt|cancel|stop)\b|(interrupt|cancel|stop)\b.*\b(esc|escape)\b/i.test(cleaned);
137
- }
138
-
139
- export function pickMeaningfulTail(lines: string[], fallback = ""): string {
140
- for (let index = lines.length - 1; index >= 0; index -= 1) {
141
- const cleaned = cleanSummaryText(lines[index] ?? "");
142
- if (!cleaned) {
143
- continue;
144
- }
145
- if (isMostlyUiNoise(cleaned)) {
146
- continue;
147
- }
148
- return cleaned;
149
- }
150
-
151
- return fallback;
152
- }
153
-
154
- export function pickSummaryTail(lines: string[], fallback = ""): string {
155
- const normalized = lines.map((line) => cleanSummaryText(line));
156
-
157
- const preferred = pickPreferredSummaryLine(normalized);
158
- if (preferred) {
159
- return preferred;
160
- }
161
-
162
- for (let index = normalized.length - 1; index >= 0; index -= 1) {
163
- const current = normalized[index] ?? "";
164
- if (!current || isLowValueSummaryLine(current)) {
165
- continue;
166
- }
167
- if (isOptionDescription(normalized, index)) {
168
- continue;
169
- }
170
-
171
- const block: string[] = [current];
172
- for (let lookback = index - 1; lookback >= 0; lookback -= 1) {
173
- const previous = normalized[lookback] ?? "";
174
- if (!previous || isLowValueSummaryLine(previous) || isOptionDescription(normalized, lookback)) {
175
- break;
176
- }
177
- if (/^[•\-]/.test(previous) || /^[•\-]/.test(current) || previous.endsWith(":") || current.length < 100) {
178
- block.unshift(previous);
179
- if (block.length >= 2) {
180
- break;
181
- }
182
- } else {
183
- break;
184
- }
185
- }
186
-
187
- return cleanSummaryText(block.join(" "));
188
- }
189
-
190
- return pickMeaningfulTail(lines, fallback);
191
- }
192
-
193
- export function pickQuestionTail(lines: string[], fallback = ""): string {
194
- const normalized = lines.map((line) => cleanSummaryText(line));
195
-
196
- for (let index = normalized.length - 1; index >= 0; index -= 1) {
197
- const line = normalized[index] ?? "";
198
- if (!line || isLowValueSummaryLine(line) || isOptionDescription(normalized, index)) {
199
- continue;
200
- }
201
-
202
- if (isSuggestionStyleText(line)) {
203
- continue;
204
- }
205
-
206
- if (/[¿?]/.test(line) || /^(confirmas|what|which|que|qué|cual|cuál|do you|can you|would you|elige|escoge|selecciona|resp[oó]ndeme)/i.test(line)) {
207
- const previous = normalized[index - 1] ?? "";
208
- if (/[¿?]/.test(line)) {
209
- if (previous && !isLowValueSummaryLine(previous) && !isOptionDescription(normalized, index - 1) && previous.length < 90 && /^[a-záéíóúñ]/i.test(line)) {
210
- return cleanSummaryText(`${previous} ${line}`);
211
- }
212
- return line;
213
- }
214
- if (previous && !isLowValueSummaryLine(previous) && !isOptionDescription(normalized, index - 1) && !/[¿?]/.test(previous) && previous.length < 90) {
215
- return cleanSummaryText(`${previous} ${line}`);
216
- }
217
- return line;
218
- }
219
- }
220
-
221
- return pickSummaryTail(lines, fallback);
222
- }
223
-
224
- export function pickCompletionTail(lines: string[], fallback = ""): string {
225
- const normalized = lines.map((line) => cleanSummaryText(line));
226
-
227
- for (let index = normalized.length - 1; index >= 0; index -= 1) {
228
- const line = normalized[index] ?? "";
229
- if (!line || isLowValueSummaryLine(line) || isOptionDescription(normalized, index)) {
230
- continue;
231
- }
232
-
233
- if (/^(se cre[oó]|cada archivo contiene|all done|completed|finished|done\b)/i.test(line)) {
234
- const previousIndex = findPreviousMeaningfulIndex(normalized, index - 1);
235
- const previous = previousIndex >= 0 ? normalized[previousIndex] ?? "" : "";
236
- if (previous && !isLowValueSummaryLine(previous) && !isOptionDescription(normalized, previousIndex) && /^(se cre[oó]|all done|completed|finished|done\b)/i.test(previous)) {
237
- return firstUsefulSentence(cleanSummaryText(`${previous} ${line}`));
238
- }
239
- return firstUsefulSentence(line);
240
- }
241
- }
242
-
243
- return pickSummaryTail(lines, fallback);
244
- }
245
-
246
- function pickPreferredSummaryLine(lines: string[]): string | null {
247
- for (let index = lines.length - 1; index >= 0; index -= 1) {
248
- const line = lines[index] ?? "";
249
- if (!line || isLowValueSummaryLine(line) || isOptionDescription(lines, index)) {
250
- continue;
251
- }
252
-
253
- if (isSuggestionStyleText(line)) {
254
- continue;
255
- }
256
-
257
- if (/^[•\-]\s/.test(line) && !/waited for background terminal|working\s*\(/i.test(line)) {
258
- return cleanSummaryText(line);
259
- }
260
-
261
- if (/[¿?]/.test(line) || /^(resp[oó]ndeme|creado archivo \d+|va en orden|carpeta creada|listo\.|voy a |el proceso ya|el lote|s[ií]:|se cre[oó]|cada archivo contiene)/i.test(line)) {
262
- const previous = lines[index - 1] ?? "";
263
- if (previous && !isLowValueSummaryLine(previous) && !isOptionDescription(lines, index - 1) && previous.length < 120 && line.length < 120 && !/^(creado archivo \d+)/i.test(line)) {
264
- return firstUsefulSentence(cleanSummaryText(`${previous} ${line}`));
265
- }
266
- return firstUsefulSentence(cleanSummaryText(line));
267
- }
268
- }
269
-
270
- return null;
271
- }
272
-
273
- function isOptionDescription(lines: string[], index: number): boolean {
274
- const current = lines[index] ?? "";
275
- if (!current) {
276
- return false;
277
- }
278
-
279
- const previous = lines[index - 1] ?? "";
280
- return /^\d+\.\s/.test(previous) || /^(una sola|una respuesta|varias opciones)/i.test(current);
281
- }
282
-
283
- function findPreviousMeaningfulIndex(lines: string[], startIndex: number): number {
284
- for (let index = startIndex; index >= 0; index -= 1) {
285
- if (lines[index]?.trim()) {
286
- return index;
287
- }
288
- }
289
-
290
- return -1;
291
- }
292
-
293
- function firstUsefulSentence(value: string): string {
294
- const normalized = cleanSummaryText(value);
295
- const sentences = normalized.match(/.*?[.!?](?:\s|$)|.+$/g)?.map((part) => cleanSummaryText(part)).filter(Boolean) ?? [];
296
- if (sentences.length === 0) {
297
- return normalized;
298
- }
299
-
300
- const first = sentences[0] ?? normalized;
301
- if (/^(listo|hecho)[.!?]?$/i.test(first) && sentences[1]) {
302
- return sentences[1];
303
- }
304
-
305
- return first;
306
- }
307
-
308
- export function formatDuration(ms: number): string {
309
- if (ms < 1000) {
310
- return "0s";
311
- }
312
-
313
- const totalSeconds = Math.floor(ms / 1000);
314
- const hours = Math.floor(totalSeconds / 3600);
315
- const minutes = Math.floor((totalSeconds % 3600) / 60);
316
- const seconds = totalSeconds % 60;
317
-
318
- if (hours > 0) {
319
- return `${hours}h${minutes}m`;
320
- }
321
-
322
- if (minutes > 0) {
323
- return `${minutes}m${seconds}s`;
324
- }
325
-
326
- return `${seconds}s`;
327
- }
328
-
329
- export function joinLines(lines: string[]): string {
330
- return compactWhitespace(lines.join(" "));
331
- }
332
-
333
- export function normalizeCommandName(command: string): string {
334
- return compactWhitespace(command).split(" ")[0] ?? "";
335
- }
336
-
337
- export function isInsideTmux(): boolean {
338
- return Boolean(process.env.TMUX);
339
- }
@@ -1,44 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
-
4
- export interface DaemonVersionMismatch {
5
- cliVersion: string;
6
- daemonVersion?: string;
7
- }
8
-
9
- function readInstalledVersion(): string {
10
- try {
11
- const pkg = JSON.parse(readFileSync(join(import.meta.dir, "..", "..", "package.json"), "utf8")) as { version?: unknown };
12
- return typeof pkg.version === "string" && pkg.version.length > 0 ? pkg.version : "unknown";
13
- } catch {
14
- return "unknown";
15
- }
16
- }
17
-
18
- const INSTALLED_VERSION = readInstalledVersion();
19
-
20
- export function getInstalledVersion(): string {
21
- return INSTALLED_VERSION;
22
- }
23
-
24
- export function getDaemonVersionMismatch(cliVersion: string, daemonVersion?: string): DaemonVersionMismatch | undefined {
25
- if (cliVersion === "unknown") return undefined;
26
- if (!daemonVersion || daemonVersion === "unknown") return { cliVersion };
27
- if (daemonVersion === cliVersion) return undefined;
28
- return { cliVersion, daemonVersion };
29
- }
30
-
31
- export function formatVersionDiagnostics(cliVersion: string, daemonVersion?: string): string {
32
- const normalizedDaemonVersion = daemonVersion && daemonVersion !== "unknown" ? daemonVersion : "unknown";
33
- const mismatch = getDaemonVersionMismatch(cliVersion, daemonVersion);
34
- const lines = [
35
- `CLI version: ${cliVersion}`,
36
- `Daemon version: ${normalizedDaemonVersion}`,
37
- `Version match: ${mismatch ? "false" : "true"}`,
38
- ];
39
- if (mismatch) {
40
- lines.push("Action: scrylog daemon restart");
41
- lines.push("Fallback: stop the running daemon and run scrylogd");
42
- }
43
- return `${lines.join("\n")}\n`;
44
- }