@noobdemon/noob-cli 1.11.1 → 1.12.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.
@@ -0,0 +1,64 @@
1
+ // Pure utility helpers cho REPL — không bám state, không I/O.
2
+ //
3
+ // Tách khỏi src/repl.js (refactor): cuối file gốc đè đầy các const/function nhỏ
4
+ // (shortCwd, shortPath, relTime, firstLine, truncate, fmtTime, fmtK, preview).
5
+ // Đưa ra module riêng để test được không cần mock toàn REPL.
6
+ import chalk from 'chalk';
7
+
8
+ // Cắt cwd cho prompt — quá dài thì giữ phần đuôi.
9
+ export const shortCwd = () => {
10
+ const p = process.cwd();
11
+ return p.length > 48 ? '…' + p.slice(-47) : p;
12
+ };
13
+
14
+ // Cắt path để hiển thị ngắn (vd trong session list).
15
+ export const shortPath = (p = '') => (p.length > 30 ? '…' + p.slice(-29) : p);
16
+
17
+ // Hiển thị thời gian tương đối tiếng Việt: "vừa xong" / "N phút trước" / "N giờ trước" / "N ngày trước".
18
+ export const relTime = (ts) => {
19
+ const m = Math.round((Date.now() - ts) / 60000);
20
+ if (m < 1) return 'vừa xong';
21
+ if (m < 60) return m + ' phút trước';
22
+ const h = Math.round(m / 60);
23
+ if (h < 24) return h + ' giờ trước';
24
+ return Math.round(h / 24) + ' ngày trước';
25
+ };
26
+
27
+ // Lấy dòng đầu của output tool (clip 100 char) cho status line.
28
+ export const firstLine = (s) => (s.split('\n')[0] || '').slice(0, 100);
29
+
30
+ // Cắt chuỗi dài + thay \n bằng ⏎ (cho hiển thị 1 dòng trong queued/status).
31
+ export const truncate = (s = '', n = 120) =>
32
+ (s.length > n ? s.slice(0, n) + '…' : s).replace(/\n/g, '⏎');
33
+
34
+ // Format ISO time → locale vi-VN. Fallback raw string nếu parse fail.
35
+ export const fmtTime = (iso) => {
36
+ try {
37
+ return new Date(iso).toLocaleString('vi-VN');
38
+ } catch {
39
+ return iso;
40
+ }
41
+ };
42
+
43
+ // Format số: 1234 → "1.2k", 1234567 → "1.2M". Dưới 1000 → string thường.
44
+ export function fmtK(n) {
45
+ return n >= 1000000
46
+ ? (n / 1000000).toFixed(1) + 'M'
47
+ : n >= 1000
48
+ ? (n / 1000).toFixed(1) + 'k'
49
+ : String(n);
50
+ }
51
+
52
+ // Preview generic cho non-diff content (vd run_command output cho permission prompt).
53
+ // Cho file/diff dùng src/diff.js (renderUnifiedDiff / renderNewFilePreview).
54
+ export function preview(content, label) {
55
+ const lines = content.split('\n').slice(0, 12);
56
+ const more = content.split('\n').length - lines.length;
57
+ console.log(
58
+ chalk.gray(' ┌─ ' + (label || '')) +
59
+ '\n' +
60
+ lines.map((l) => chalk.gray(' │ ') + l.slice(0, 110)).join('\n') +
61
+ (more > 0 ? chalk.gray(`\n │ … +${more} dòng nữa`) : '') +
62
+ chalk.gray('\n └─')
63
+ );
64
+ }
@@ -53,6 +53,9 @@ export function workflowHelp({ c, t }) {
53
53
  console.log(' /workflow save <name> <req> lưu prompt template → ~/.noob/workflows/');
54
54
  console.log(' /workflow load <name> xem nội dung (saved hoặc built-in)');
55
55
  console.log(' /workflow run <name> [extra] chạy (built-in HOẶC saved, có thể thêm ngữ cảnh)');
56
+ console.log(' /workflow runs list run journal đã chạy (resume-able)');
57
+ console.log(' /workflow log <id> xem chi tiết 1 run (sub-agent task + kết quả)');
58
+ console.log(' /workflow resume <id> chạy lại run, skip task đã done → tiết kiệm token');
56
59
  console.log(' /workflow delete|rm <name> xoá workflow đã lưu');
57
60
  console.log('');
58
61
  console.log(c.accent(' Nhanh nhất để thử:'));