@allpepper/task-orchestrator-tui 1.1.0 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allpepper/task-orchestrator-tui",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Terminal UI for task orchestration - Kanban boards, tree views, and task management",
5
5
  "type": "module",
6
6
  "bin": {
@@ -45,7 +45,7 @@
45
45
  "prepublishOnly": "bun test"
46
46
  },
47
47
  "dependencies": {
48
- "@allpepper/task-orchestrator": "^1.1.0",
48
+ "@allpepper/task-orchestrator": "^1.1.1",
49
49
  "@inkjs/ui": "^2.0.0",
50
50
  "ink": "^6.6.0",
51
51
  "react": "^19.2.4"
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
2
2
  import { Box, Text, useInput } from 'ink';
3
3
  import type { Section } from '@allpepper/task-orchestrator';
4
4
  import { useTheme } from '../../ui/context/theme-context';
5
+ import { MarkdownText } from '../../ui/lib/markdown';
5
6
 
6
7
  export interface SectionListProps {
7
8
  sections: Section[];
@@ -83,8 +84,8 @@ export function SectionList({
83
84
  </Text>
84
85
  </Box>
85
86
  )}
86
- <Box>
87
- <Text>{section.content}</Text>
87
+ <Box flexDirection="column">
88
+ <MarkdownText>{section.content}</MarkdownText>
88
89
  </Box>
89
90
  </Box>
90
91
  )}
@@ -0,0 +1,181 @@
1
+ import React from 'react';
2
+ import { Text, Box } from 'ink';
3
+
4
+ /**
5
+ * Detect if content looks like markdown
6
+ * Checks for common patterns LLMs use
7
+ */
8
+ export function looksLikeMarkdown(content: string): boolean {
9
+ // Check for literal \n (escaped newlines that should be actual newlines)
10
+ if (content.includes('\\n')) return true;
11
+
12
+ // Check for markdown headers (## Header)
13
+ if (/^#{1,6}\s/m.test(content)) return true;
14
+
15
+ // Check for bullet points (- item or * item)
16
+ if (/^\s*[-*]\s/m.test(content)) return true;
17
+
18
+ // Check for inline code (`code`)
19
+ if (/`[^`]+`/.test(content)) return true;
20
+
21
+ // Check for bold (**text**)
22
+ if (/\*\*[^*]+\*\*/.test(content)) return true;
23
+
24
+ return false;
25
+ }
26
+
27
+ interface MarkdownTextProps {
28
+ children: string;
29
+ }
30
+
31
+ /**
32
+ * Render markdown content with Ink styling
33
+ * Handles common markdown patterns used by LLMs
34
+ */
35
+ export function MarkdownText({ children }: MarkdownTextProps) {
36
+ if (!looksLikeMarkdown(children)) {
37
+ return <Text>{children}</Text>;
38
+ }
39
+
40
+ // First, convert literal \n to actual newlines
41
+ const normalized = children.replace(/\\n/g, '\n');
42
+
43
+ // Split into lines for processing
44
+ const lines = normalized.split('\n');
45
+
46
+ return (
47
+ <Box flexDirection="column">
48
+ {lines.map((line, lineIndex) => (
49
+ <MarkdownLine key={lineIndex} line={line} />
50
+ ))}
51
+ </Box>
52
+ );
53
+ }
54
+
55
+ interface MarkdownLineProps {
56
+ line: string;
57
+ }
58
+
59
+ function MarkdownLine({ line }: MarkdownLineProps) {
60
+ // Empty line
61
+ if (!line.trim()) {
62
+ return <Text> </Text>;
63
+ }
64
+
65
+ // Header (## Header)
66
+ const headerMatch = line.match(/^(#{1,6})\s+(.*)$/);
67
+ if (headerMatch) {
68
+ const level = headerMatch[1].length;
69
+ const text = headerMatch[2];
70
+ return (
71
+ <Box marginTop={level === 1 ? 1 : 0}>
72
+ <Text bold color={level <= 2 ? 'cyan' : undefined}>
73
+ {text}
74
+ </Text>
75
+ </Box>
76
+ );
77
+ }
78
+
79
+ // Bullet point (- item or * item)
80
+ const bulletMatch = line.match(/^(\s*)([-*])\s+(.*)$/);
81
+ if (bulletMatch) {
82
+ const indent = bulletMatch[1].length;
83
+ const content = bulletMatch[3];
84
+ return (
85
+ <Box marginLeft={indent}>
86
+ <Text>
87
+ <Text dimColor>• </Text>
88
+ <InlineMarkdown text={content} />
89
+ </Text>
90
+ </Box>
91
+ );
92
+ }
93
+
94
+ // Regular line with inline formatting
95
+ return (
96
+ <Text>
97
+ <InlineMarkdown text={line} />
98
+ </Text>
99
+ );
100
+ }
101
+
102
+ interface InlineMarkdownProps {
103
+ text: string;
104
+ }
105
+
106
+ /**
107
+ * Handle inline markdown: `code`, **bold**
108
+ */
109
+ function InlineMarkdown({ text }: InlineMarkdownProps) {
110
+ const parts: React.ReactNode[] = [];
111
+ let remaining = text;
112
+ let key = 0;
113
+
114
+ while (remaining.length > 0) {
115
+ // Check for inline code `code`
116
+ const codeMatch = remaining.match(/^(.*?)`([^`]+)`(.*)$/);
117
+ if (codeMatch) {
118
+ if (codeMatch[1]) {
119
+ parts.push(<BoldMarkdown key={key++} text={codeMatch[1]} />);
120
+ }
121
+ parts.push(
122
+ <Text key={key++} color="yellow">
123
+ {codeMatch[2]}
124
+ </Text>
125
+ );
126
+ remaining = codeMatch[3];
127
+ continue;
128
+ }
129
+
130
+ // Check for bold **text**
131
+ const boldMatch = remaining.match(/^(.*?)\*\*([^*]+)\*\*(.*)$/);
132
+ if (boldMatch) {
133
+ if (boldMatch[1]) {
134
+ parts.push(<Text key={key++}>{boldMatch[1]}</Text>);
135
+ }
136
+ parts.push(
137
+ <Text key={key++} bold>
138
+ {boldMatch[2]}
139
+ </Text>
140
+ );
141
+ remaining = boldMatch[3];
142
+ continue;
143
+ }
144
+
145
+ // No more patterns, add remaining text
146
+ parts.push(<Text key={key++}>{remaining}</Text>);
147
+ break;
148
+ }
149
+
150
+ return <>{parts}</>;
151
+ }
152
+
153
+ /**
154
+ * Handle bold within text that might have already had code extracted
155
+ */
156
+ function BoldMarkdown({ text }: { text: string }) {
157
+ const parts: React.ReactNode[] = [];
158
+ let remaining = text;
159
+ let key = 0;
160
+
161
+ while (remaining.length > 0) {
162
+ const boldMatch = remaining.match(/^(.*?)\*\*([^*]+)\*\*(.*)$/);
163
+ if (boldMatch) {
164
+ if (boldMatch[1]) {
165
+ parts.push(<Text key={key++}>{boldMatch[1]}</Text>);
166
+ }
167
+ parts.push(
168
+ <Text key={key++} bold>
169
+ {boldMatch[2]}
170
+ </Text>
171
+ );
172
+ remaining = boldMatch[3];
173
+ continue;
174
+ }
175
+
176
+ parts.push(<Text key={key++}>{remaining}</Text>);
177
+ break;
178
+ }
179
+
180
+ return <>{parts}</>;
181
+ }