reslop 0.2.7 → 0.3.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 (158) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/README.md +16 -14
  3. package/bin/reslop.js +8 -5
  4. package/lib/agents/agents.js +573 -0
  5. package/lib/agents/allow.js +71 -0
  6. package/lib/agents/allow.json +17 -0
  7. package/lib/agents/models.js +467 -0
  8. package/lib/api.js +15 -12
  9. package/lib/cli.js +43 -68
  10. package/lib/{files.js → common/files.js} +48 -55
  11. package/lib/{find.js → common/find.js} +1 -1
  12. package/lib/common/format.js +101 -0
  13. package/lib/{utilities.js → common/process.js} +7 -95
  14. package/lib/common/tasks.json +27 -0
  15. package/lib/common/utilities.js +112 -0
  16. package/lib/dashboard/git.js +9 -16
  17. package/lib/dashboard/model.js +90 -49
  18. package/lib/dashboard/npm.js +17 -13
  19. package/lib/dashboard/tree.js +27 -30
  20. package/lib/{session → dashboard}/watch.js +36 -31
  21. package/lib/{workspace.js → dashboard/workspace.js} +23 -38
  22. package/lib/{deps.js → deps/deps.js} +31 -45
  23. package/lib/{deps-diff.js → deps/diff.js} +35 -25
  24. package/lib/{manifest.js → deps/manifest.js} +47 -30
  25. package/lib/diff/align.js +1 -2
  26. package/lib/diff/diff.js +2 -2
  27. package/lib/diff/display.js +29 -5
  28. package/lib/diff/inline.js +10 -14
  29. package/lib/diff/items.js +6 -4
  30. package/lib/diff/patch.js +39 -3
  31. package/lib/diff/unit.js +45 -16
  32. package/lib/{git-branches.js → git/branches.js} +53 -48
  33. package/lib/{git-deps.js → git/deps.js} +151 -95
  34. package/lib/git/git.js +71 -0
  35. package/lib/git/worktree.js +504 -0
  36. package/lib/highlight/bash.js +1 -2
  37. package/lib/highlight/csv.js +1 -2
  38. package/lib/highlight/dot.js +1 -2
  39. package/lib/{highlight.js → highlight/highlight.js} +42 -11
  40. package/lib/highlight/html.js +20 -18
  41. package/lib/highlight/json.js +1 -2
  42. package/lib/highlight/log.js +1 -2
  43. package/lib/highlight/txt.js +1 -2
  44. package/lib/{session → input}/actions.js +114 -48
  45. package/lib/{editor.js → input/editor.js} +16 -8
  46. package/lib/{keys.js → input/keys.js} +24 -45
  47. package/lib/input/line-edit.js +78 -0
  48. package/lib/input/menu-pick.js +70 -0
  49. package/lib/render/agents.js +642 -0
  50. package/lib/render/branches.js +4 -5
  51. package/lib/render/commits.js +54 -64
  52. package/lib/render/{dash-activity.js → dashboard/activity.js} +25 -40
  53. package/lib/render/{dash-blocks.js → dashboard/blocks.js} +131 -137
  54. package/lib/render/{dashboard.js → dashboard/dashboard.js} +25 -22
  55. package/lib/render/diff.js +166 -45
  56. package/lib/render/field.js +131 -0
  57. package/lib/render/files.js +9 -14
  58. package/lib/render/footer.js +385 -0
  59. package/lib/render/frame.js +123 -25
  60. package/lib/render/header.js +176 -0
  61. package/lib/render/log.js +320 -0
  62. package/lib/render/menu.js +60 -0
  63. package/lib/render/notes.js +16 -11
  64. package/lib/render/npm.js +322 -196
  65. package/lib/render/packages.js +9 -13
  66. package/lib/render/primitives.js +101 -15
  67. package/lib/render/render.js +7 -11
  68. package/lib/render/repos.js +13 -25
  69. package/lib/render/status.js +370 -0
  70. package/lib/render/status.json +85 -0
  71. package/lib/render/{dash-table.js → table.js} +13 -60
  72. package/lib/render/tiles.js +109 -48
  73. package/lib/render/unit.js +32 -13
  74. package/lib/{report-model.js → report/model.js} +4 -6
  75. package/lib/{report-parse.js → report/parse.js} +9 -14
  76. package/lib/{report-render.js → report/render.js} +48 -19
  77. package/lib/{report-run.js → report/run.js} +42 -30
  78. package/lib/{report-test.js → report/test.js} +56 -55
  79. package/lib/{report-tools.js → report/tools.js} +24 -33
  80. package/lib/review/agent-instructions.md +14 -0
  81. package/lib/review/format.js +420 -0
  82. package/lib/{review-merge.js → review/merge.js} +9 -8
  83. package/lib/review/review.js +190 -0
  84. package/lib/review/store.js +281 -0
  85. package/lib/review/templates.js +83 -0
  86. package/lib/runs/commands.js +14 -0
  87. package/lib/runs/logs.js +299 -0
  88. package/lib/runs/output.js +174 -0
  89. package/lib/runs/process.js +113 -0
  90. package/lib/{runs.js → runs/runs.js} +84 -36
  91. package/lib/runs/scripts.js +150 -0
  92. package/lib/session/agents/agents.js +976 -0
  93. package/lib/session/agents/job.js +320 -0
  94. package/lib/session/agents/jobs.js +355 -0
  95. package/lib/session/agents/options.js +153 -0
  96. package/lib/session/agents/plans.js +83 -0
  97. package/lib/session/branches.js +33 -40
  98. package/lib/session/change-actions.js +34 -100
  99. package/lib/session/commit.js +91 -52
  100. package/lib/session/compose.js +189 -147
  101. package/lib/session/dashboard.js +23 -22
  102. package/lib/session/dispatch.js +86 -21
  103. package/lib/session/files-pane.js +47 -26
  104. package/lib/session/find.js +16 -29
  105. package/lib/session/import.js +93 -0
  106. package/lib/session/items.js +8 -17
  107. package/lib/session/lifecycle.js +78 -72
  108. package/lib/session/load.js +2 -4
  109. package/lib/session/navigation.js +6 -3
  110. package/lib/session/npm/history.js +250 -0
  111. package/lib/session/npm/npm.js +836 -0
  112. package/lib/session/{packages.js → npm/packages.js} +21 -14
  113. package/lib/session/ops.js +125 -34
  114. package/lib/session/pointer.js +202 -10
  115. package/lib/session/prefs.js +112 -0
  116. package/lib/session/reads.js +109 -0
  117. package/lib/session/review.js +28 -10
  118. package/lib/session/run-panel.js +40 -0
  119. package/lib/{session.js → session/session.js} +158 -63
  120. package/lib/session/tasks.js +321 -66
  121. package/lib/session/templates.js +1 -1
  122. package/lib/session/terminal.js +94 -12
  123. package/lib/session/unit.js +35 -30
  124. package/lib/session/update.js +194 -6
  125. package/lib/session/view.js +65 -65
  126. package/lib/session/workspace.js +39 -78
  127. package/lib/{capabilities.js → source/capabilities.js} +3 -12
  128. package/lib/{github.js → source/github.js} +102 -32
  129. package/lib/{gitlab.js → source/gitlab.js} +87 -10
  130. package/lib/{remote.js → source/remote.js} +144 -40
  131. package/lib/source/review-threads.graphql +20 -0
  132. package/lib/source/source.js +74 -0
  133. package/lib/term/ansi.js +396 -0
  134. package/lib/{clipboard.js → term/clipboard.js} +3 -6
  135. package/lib/{select.js → term/select.js} +4 -3
  136. package/lib/term/themes/dark.json +122 -0
  137. package/lib/term/themes/light.json +122 -0
  138. package/lib/term/wide.txt +21 -0
  139. package/lib/{wrap.js → term/wrap.js} +4 -4
  140. package/package.json +2 -2
  141. package/lib/ansi.js +0 -545
  142. package/lib/detect.js +0 -34
  143. package/lib/diff/edit.js +0 -33
  144. package/lib/git-worktree.js +0 -455
  145. package/lib/git.js +0 -79
  146. package/lib/npm-commands.js +0 -522
  147. package/lib/render/chrome.js +0 -806
  148. package/lib/render/present.js +0 -19
  149. package/lib/render/report.js +0 -43
  150. package/lib/render/search.js +0 -25
  151. package/lib/review.js +0 -745
  152. package/lib/session/accessors.js +0 -26
  153. package/lib/session/edit-click.js +0 -57
  154. package/lib/session/npm.js +0 -452
  155. package/lib/session/progress.js +0 -41
  156. package/lib/source.js +0 -36
  157. package/lib/update.js +0 -192
  158. /package/lib/{git-reword-todo.js → git/reword-todo.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const ansi = require('./ansi.js');
4
- const { graphemes, graphemeWidth, visibleWidth } = ansi;
3
+ const { clamp } = require('../common/utilities.js');
4
+ const { graphemes, graphemeWidth, visibleWidth } = require('./ansi.js');
5
5
 
6
6
  const wrapPlain = (text, width) => {
7
7
  if (width <= 0) return [''];
@@ -51,7 +51,7 @@ const wrapMultiline = (text, width) =>
51
51
 
52
52
  const cursorInWrap = (text, cursor, width) => {
53
53
  const rows = wrapDoc(text, width);
54
- const clamped = Math.max(0, Math.min(cursor, text.length));
54
+ const clamped = clamp(cursor, 0, text.length);
55
55
  let row = rows.length - 1;
56
56
  for (let i = 0; i < rows.length - 1; i++) {
57
57
  if (clamped < rows[i + 1].start) {
@@ -60,7 +60,7 @@ const cursorInWrap = (text, cursor, width) => {
60
60
  }
61
61
  }
62
62
  const line = rows[row];
63
- const take = Math.min(Math.max(0, clamped - line.start), line.text.length);
63
+ const take = clamp(clamped - line.start, 0, line.text.length);
64
64
  return { row, col: visibleWidth(line.text.slice(0, take)) };
65
65
  };
66
66
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reslop",
3
- "version": "0.2.7",
3
+ "version": "0.3.1",
4
4
  "description": "Interactive code review and repair planning for AI-assisted changes",
5
5
  "keywords": [
6
6
  "code-review",
@@ -59,7 +59,7 @@
59
59
  "eslint": "^9.39.4",
60
60
  "eslint-config-metarhia": "^9.1.9",
61
61
  "metaskills": "^1.0.5",
62
- "prettier": "^3.9.9"
62
+ "prettier": "^3.9.10"
63
63
  },
64
64
  "dependencies": {
65
65
  "metautil": "^5.5.2"
package/lib/ansi.js DELETED
@@ -1,545 +0,0 @@
1
- 'use strict';
2
-
3
- const SEGMENTER = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
4
-
5
- const ESC = String.fromCodePoint(0x1b);
6
- const ANSI_RE = new RegExp(`${ESC}\\[[0-9;?]*[ -/]*[@-~]`, 'g');
7
- const RESET = `${ESC}[0m`;
8
- const BOLD = `${ESC}[1m`;
9
- const EL = `${ESC}[K`;
10
-
11
- const WIDE_CP = [
12
- 0x1100, 0x115f, 0x231a, 0x231b, 0x2329, 0x232a, 0x23e9, 0x23ec, 0x23f0,
13
- 0x23f0, 0x23f3, 0x23f3, 0x25fd, 0x25fe, 0x2614, 0x2615, 0x2630, 0x2637,
14
- 0x2648, 0x2653, 0x267f, 0x267f, 0x268a, 0x268f, 0x2693, 0x2693, 0x26a1,
15
- 0x26a1, 0x26aa, 0x26ab, 0x26bd, 0x26be, 0x26c4, 0x26c5, 0x26ce, 0x26ce,
16
- 0x26d4, 0x26d4, 0x26ea, 0x26ea, 0x26f2, 0x26f3, 0x26f5, 0x26f5, 0x26fa,
17
- 0x26fa, 0x26fd, 0x26fd, 0x2705, 0x2705, 0x270a, 0x270b, 0x2728, 0x2728,
18
- 0x274c, 0x274c, 0x274e, 0x274e, 0x2753, 0x2755, 0x2757, 0x2757, 0x2795,
19
- 0x2797, 0x27b0, 0x27b0, 0x27bf, 0x27bf, 0x2b1b, 0x2b1c, 0x2b50, 0x2b50,
20
- 0x2b55, 0x2b55, 0x2e80, 0x2e99, 0x2e9b, 0x2ef3, 0x2f00, 0x2fd5, 0x2ff0,
21
- 0x303e, 0x3041, 0x3096, 0x3099, 0x30ff, 0x3105, 0x312f, 0x3131, 0x318e,
22
- 0x3190, 0x31e5, 0x31ef, 0x321e, 0x3220, 0x3247, 0x3250, 0xa48c, 0xa490,
23
- 0xa4c6, 0xa960, 0xa97c, 0xac00, 0xd7a3, 0xf900, 0xfaff, 0xfe10, 0xfe19,
24
- 0xfe30, 0xfe52, 0xfe54, 0xfe66, 0xfe68, 0xfe6b, 0xff01, 0xff60, 0xffe0,
25
- 0xffe6, 0x16fe0, 0x16fe4, 0x16ff0, 0x16ff1, 0x17000, 0x187f7, 0x18800,
26
- 0x18cd5, 0x18cff, 0x18d08, 0x1aff0, 0x1aff3, 0x1aff5, 0x1affb, 0x1affd,
27
- 0x1affe, 0x1b000, 0x1b122, 0x1b132, 0x1b132, 0x1b150, 0x1b152, 0x1b155,
28
- 0x1b155, 0x1b164, 0x1b167, 0x1b170, 0x1b2fb, 0x1d300, 0x1d356, 0x1d360,
29
- 0x1d376, 0x1f004, 0x1f004, 0x1f0cf, 0x1f0cf, 0x1f18e, 0x1f18e, 0x1f191,
30
- 0x1f19a, 0x1f200, 0x1f202, 0x1f210, 0x1f23b, 0x1f240, 0x1f248, 0x1f250,
31
- 0x1f251, 0x1f260, 0x1f265, 0x1f300, 0x1f320, 0x1f32d, 0x1f335, 0x1f337,
32
- 0x1f37c, 0x1f37e, 0x1f393, 0x1f3a0, 0x1f3ca, 0x1f3cf, 0x1f3d3, 0x1f3e0,
33
- 0x1f3f0, 0x1f3f4, 0x1f3f4, 0x1f3f8, 0x1f43e, 0x1f440, 0x1f440, 0x1f442,
34
- 0x1f4fc, 0x1f4ff, 0x1f53d, 0x1f54b, 0x1f54e, 0x1f550, 0x1f567, 0x1f57a,
35
- 0x1f57a, 0x1f595, 0x1f596, 0x1f5a4, 0x1f5a4, 0x1f5fb, 0x1f64f, 0x1f680,
36
- 0x1f6c5, 0x1f6cc, 0x1f6cc, 0x1f6d0, 0x1f6d2, 0x1f6d5, 0x1f6d7, 0x1f6dc,
37
- 0x1f6df, 0x1f6eb, 0x1f6ec, 0x1f6f4, 0x1f6fc, 0x1f7e0, 0x1f7eb, 0x1f7f0,
38
- 0x1f7f0, 0x1f90c, 0x1f93a, 0x1f93c, 0x1f945, 0x1f947, 0x1f9ff, 0x1fa70,
39
- 0x1fa7c, 0x1fa80, 0x1fa89, 0x1fa8f, 0x1fac6, 0x1face, 0x1fadc, 0x1fadf,
40
- 0x1fae9, 0x1faf0, 0x1faf8, 0x20000, 0x2fffd, 0x30000, 0x3fffd,
41
- ];
42
-
43
- const DARK_UI = {
44
- delLineFg: [0xcc, 0x7a, 0x7a],
45
- delLineBg: [0x3a, 0x1a, 0x1a],
46
- delCharFg: [0xff, 0xff, 0xff],
47
- delCharBg: [0x75, 0x22, 0x22],
48
- addLineFg: [0x7a, 0xcc, 0x8a],
49
- addLineBg: [0x14, 0x28, 0x14],
50
- addCharFg: [0xff, 0xff, 0xff],
51
- addCharBg: [0x1a, 0x4c, 0x26],
52
- ctxFg: [0x8a, 0x8a, 0x8a],
53
- ctxBg: [0x12, 0x12, 0x18],
54
- splitGutterFg: [0x18, 0x18, 0x24],
55
- splitGutterBg: [0x18, 0x18, 0x24],
56
- headerFg: [0x3a, 0x3a, 0x3a],
57
- headerBg: [0xe6, 0xe6, 0xee],
58
- headerChromeFg: [0x5a, 0x5a, 0x5a],
59
- headerRepoFg: [0x3a, 0x3a, 0x3a],
60
- headerDirFg: [0x6e, 0x6e, 0x6e],
61
- headerSlashFg: [0x8a, 0x8a, 0x8a],
62
- headerFileFg: [0x4e, 0x4e, 0x4e],
63
- chromeFg: [0xd0, 0xd0, 0xe0],
64
- chromeBg: [0x18, 0x18, 0x24],
65
- noteBg: [0x24, 0x24, 0x36],
66
- buttonFg: [0x6a, 0x6a, 0x7e],
67
- buttonBg: [0x2a, 0x2a, 0x40],
68
- buttonHotFg: [0xff, 0xff, 0xff],
69
- currentBg: [0xa8, 0xcc, 0xb4],
70
- checkFg: [0xf4, 0xf4, 0xfc],
71
- checkBg: [0x52, 0x52, 0x74],
72
- checkDoneFg: [0xf0, 0xff, 0xf4],
73
- checkDoneBg: [0x22, 0x58, 0x34],
74
- errorFg: [0xff, 0x80, 0x80],
75
- warnFg: [0xe8, 0xc8, 0x4a],
76
- mutedFg: [0x7a, 0x7a, 0x8a],
77
- shaFg: [0x56, 0x9c, 0xd6],
78
- pkgDepFg: [0xaf, 0xe0, 0xb9],
79
- pkgDevFg: [0x9a, 0xc4, 0xe6],
80
- pkgFg: [0xc8, 0xc8, 0xd2],
81
- pkgChainFg: [0x55, 0x55, 0x62],
82
- shaDarkFg: [0x15, 0x4a, 0x8c],
83
- stagedDelLineFg: [0xa0, 0xa0, 0xa8],
84
- stagedDelLineBg: [0x20, 0x20, 0x26],
85
- stagedDelCharFg: [0xf0, 0xf0, 0xf4],
86
- stagedDelCharBg: [0x44, 0x44, 0x4e],
87
- stagedAddLineFg: [0xb0, 0xb0, 0xb8],
88
- stagedAddLineBg: [0x26, 0x26, 0x2e],
89
- stagedAddCharFg: [0xff, 0xff, 0xff],
90
- stagedAddCharBg: [0x4e, 0x4e, 0x58],
91
- dashBg: [0x00, 0x00, 0x00],
92
- dashTileBg: [0x26, 0x26, 0x2a],
93
- dashRowBg: [0x1c, 0x1c, 0x1f],
94
- dashHeadBg: [0x70, 0x70, 0x7c],
95
- dashDimHeadBg: [0x30, 0x30, 0x38],
96
- dashDimTileBg: [0x12, 0x12, 0x14],
97
- dashDimRowBg: [0x0c, 0x0c, 0x0e],
98
- dashHeadMuted: [0xf2, 0xf2, 0xfa],
99
- dashDelFg: [0xff, 0xd2, 0xd2],
100
- heatTrack: [0x3a, 0x3c, 0x48],
101
- heat1: [0x1c, 0x3a, 0x32],
102
- heat2: [0x2a, 0x5a, 0x38],
103
- heat3: [0x8a, 0x6a, 0x18],
104
- heat4: [0xa0, 0x3a, 0x28],
105
- heatFg: [0xf4, 0xf4, 0xf8],
106
- heatBlink: [0xf2, 0xe2, 0x8a],
107
- heatBlinkFg: [0x1a, 0x16, 0x08],
108
- dashKeyFg: [0xff, 0xff, 0xff],
109
- taskHeadFg: [0xff, 0xff, 0xff],
110
- taskHeadBg: [0x3c, 0x3c, 0x48],
111
- searchFg: [0x1a, 0x16, 0x08],
112
- searchBg: [0x8a, 0x6a, 0x18],
113
- searchOnFg: [0x1a, 0x16, 0x08],
114
- searchOnBg: [0xf2, 0xe2, 0x8a],
115
- };
116
-
117
- const DARK_CODE = {
118
- keyword: [197, 134, 192],
119
- control: [197, 134, 192],
120
- storage: [86, 156, 214],
121
- literal: [86, 156, 214],
122
- string: [206, 145, 120],
123
- template: [206, 145, 120],
124
- escape: [209, 105, 105],
125
- interpolation: [156, 220, 254],
126
- number: [181, 206, 168],
127
- comment: [106, 153, 85],
128
- function: [220, 220, 170],
129
- method: [220, 220, 170],
130
- className: [78, 201, 176],
131
- type: [78, 201, 176],
132
- interface: [78, 201, 176],
133
- property: [156, 220, 254],
134
- variable: [156, 220, 254],
135
- parameter: [156, 220, 254],
136
- constant: [79, 193, 255],
137
- operator: [212, 212, 212],
138
- punct: [212, 212, 212],
139
- regex: [209, 105, 105],
140
- decorator: [220, 220, 170],
141
- tag: [86, 156, 214],
142
- attr: [156, 220, 254],
143
- plain: [212, 212, 212],
144
- punctDim: [128, 128, 128],
145
- logDate: [210, 210, 220],
146
- logError: [230, 90, 90],
147
- logWarn: [230, 180, 80],
148
- logInfo: [100, 170, 230],
149
- logDebug: [140, 160, 180],
150
- };
151
-
152
- const DARK_LOG_COLS = [
153
- [210, 210, 220],
154
- [120, 180, 220],
155
- [180, 160, 220],
156
- [140, 200, 160],
157
- [220, 180, 120],
158
- [220, 140, 160],
159
- [160, 200, 200],
160
- [200, 170, 140],
161
- ];
162
-
163
- const LIGHT_UI = {
164
- delLineFg: [0xb3, 0x1d, 0x28],
165
- delLineBg: [0xff, 0xeb, 0xe9],
166
- delCharFg: [0x1f, 0x23, 0x28],
167
- delCharBg: [0xff, 0xc1, 0xc0],
168
- addLineFg: [0x1a, 0x7f, 0x37],
169
- addLineBg: [0xe6, 0xff, 0xec],
170
- addCharFg: [0x1f, 0x23, 0x28],
171
- addCharBg: [0xab, 0xf2, 0xbc],
172
- ctxFg: [0x57, 0x60, 0x6a],
173
- ctxBg: [0xff, 0xff, 0xff],
174
- splitGutterFg: [0xea, 0xee, 0xf2],
175
- splitGutterBg: [0xea, 0xee, 0xf2],
176
- headerFg: [0x24, 0x29, 0x2f],
177
- headerBg: [0xd8, 0xde, 0xe4],
178
- headerChromeFg: [0x42, 0x4a, 0x53],
179
- headerRepoFg: [0x24, 0x29, 0x2f],
180
- headerDirFg: [0x57, 0x60, 0x6a],
181
- headerSlashFg: [0x8c, 0x95, 0x9f],
182
- headerFileFg: [0x1f, 0x23, 0x28],
183
- chromeFg: [0x24, 0x29, 0x2f],
184
- chromeBg: [0xf0, 0xf2, 0xf5],
185
- noteBg: [0xe8, 0xf0, 0xfe],
186
- buttonFg: [0x57, 0x60, 0x6a],
187
- buttonBg: [0xe1, 0xe5, 0xea],
188
- buttonHotFg: [0x0f, 0x14, 0x19],
189
- currentBg: [0xac, 0xe1, 0xc2],
190
- checkFg: [0x1f, 0x23, 0x28],
191
- checkBg: [0xc8, 0xcf, 0xd8],
192
- checkDoneFg: [0x0f, 0x3d, 0x1f],
193
- checkDoneBg: [0xab, 0xf2, 0xbc],
194
- errorFg: [0xcf, 0x22, 0x2e],
195
- warnFg: [0x9a, 0x67, 0x00],
196
- mutedFg: [0x6e, 0x77, 0x81],
197
- shaFg: [0x05, 0x50, 0xae],
198
- pkgDepFg: [0x3c, 0xa8, 0x5a],
199
- pkgDevFg: [0x3d, 0x7e, 0xc8],
200
- pkgFg: [0x9a, 0xa2, 0xac],
201
- pkgChainFg: [0x3a, 0x42, 0x4c],
202
- shaDarkFg: [0x0b, 0x3d, 0x70],
203
- stagedDelLineFg: [0x57, 0x60, 0x6a],
204
- stagedDelLineBg: [0xf3, 0xf4, 0xf6],
205
- stagedDelCharFg: [0x1f, 0x23, 0x28],
206
- stagedDelCharBg: [0xd8, 0xdc, 0xe1],
207
- stagedAddLineFg: [0x42, 0x4a, 0x53],
208
- stagedAddLineBg: [0xea, 0xec, 0xef],
209
- stagedAddCharFg: [0x0f, 0x14, 0x19],
210
- stagedAddCharBg: [0xcc, 0xd1, 0xd7],
211
- dashBg: [0xff, 0xff, 0xff],
212
- dashTileBg: [0xe4, 0xe7, 0xeb],
213
- dashRowBg: [0xd9, 0xdc, 0xe1],
214
- dashHeadBg: [0xe8, 0xeb, 0xef],
215
- dashDimHeadBg: [0xb0, 0xb6, 0xbe],
216
- dashDimTileBg: [0xc4, 0xc8, 0xce],
217
- dashDimRowBg: [0xb0, 0xb4, 0xba],
218
- dashHeadMuted: [0x3e, 0x46, 0x52],
219
- dashDelFg: [0xd0, 0x3a, 0x44],
220
- heatTrack: [0xc5, 0xca, 0xd3],
221
- heat1: [0xc8, 0xe6, 0xd4],
222
- heat2: [0x7d, 0xc8, 0x96],
223
- heat3: [0xe6, 0xb4, 0x3c],
224
- heat4: [0xe0, 0x78, 0x68],
225
- heatFg: [0x1f, 0x23, 0x28],
226
- heatBlink: [0xff, 0xf3, 0xb0],
227
- heatBlinkFg: [0x1a, 0x16, 0x08],
228
- dashKeyFg: [0x00, 0x00, 0x00],
229
- taskHeadFg: [0xff, 0xff, 0xff],
230
- taskHeadBg: [0x6e, 0x77, 0x81],
231
- searchFg: [0x1a, 0x16, 0x08],
232
- searchBg: [0xf0, 0xc8, 0x6a],
233
- searchOnFg: [0x1a, 0x16, 0x08],
234
- searchOnBg: [0xff, 0xe1, 0x4a],
235
- };
236
-
237
- const LIGHT_CODE = {
238
- keyword: [175, 0, 219],
239
- control: [175, 0, 219],
240
- storage: [0, 0, 255],
241
- literal: [0, 0, 255],
242
- string: [163, 21, 21],
243
- template: [163, 21, 21],
244
- escape: [238, 0, 0],
245
- interpolation: [0, 16, 128],
246
- number: [9, 134, 88],
247
- comment: [0, 128, 0],
248
- function: [121, 94, 38],
249
- method: [121, 94, 38],
250
- className: [38, 127, 153],
251
- type: [38, 127, 153],
252
- interface: [38, 127, 153],
253
- property: [0, 16, 128],
254
- variable: [0, 16, 128],
255
- parameter: [0, 16, 128],
256
- constant: [0, 112, 193],
257
- operator: [60, 60, 60],
258
- punct: [60, 60, 60],
259
- regex: [129, 31, 63],
260
- decorator: [121, 94, 38],
261
- tag: [128, 0, 0],
262
- attr: [229, 0, 0],
263
- plain: [31, 31, 31],
264
- punctDim: [140, 140, 140],
265
- logDate: [60, 60, 70],
266
- logError: [205, 49, 49],
267
- logWarn: [160, 110, 0],
268
- logInfo: [0, 90, 180],
269
- logDebug: [100, 110, 125],
270
- };
271
-
272
- const LIGHT_LOG_COLS = [
273
- [60, 60, 70],
274
- [0, 95, 150],
275
- [110, 70, 170],
276
- [30, 120, 60],
277
- [150, 95, 20],
278
- [170, 50, 90],
279
- [20, 120, 120],
280
- [130, 90, 50],
281
- ];
282
-
283
- const PALETTES = {
284
- dark: { ui: DARK_UI, code: DARK_CODE, logCols: DARK_LOG_COLS },
285
- light: { ui: LIGHT_UI, code: LIGHT_CODE, logCols: LIGHT_LOG_COLS },
286
- };
287
- const THEME_NAMES = Object.keys(PALETTES);
288
-
289
- const applyColors = (into, from) => {
290
- for (const key of Object.keys(from)) {
291
- const src = from[key];
292
- const dst = into[key];
293
- dst[0] = src[0];
294
- dst[1] = src[1];
295
- dst[2] = src[2];
296
- }
297
- };
298
-
299
- const THEME = structuredClone(DARK_UI);
300
- const CODE_FG = structuredClone(DARK_CODE);
301
- const LOG_COL_FG = structuredClone(DARK_LOG_COLS);
302
- let currentTheme = 'dark';
303
-
304
- const setTheme = (name) => {
305
- if (!Object.hasOwn(PALETTES, name)) {
306
- throw new Error(`unknown theme ${name}`);
307
- }
308
- const palette = PALETTES[name];
309
- applyColors(THEME, palette.ui);
310
- applyColors(CODE_FG, palette.code);
311
- applyColors(LOG_COL_FG, palette.logCols);
312
- currentTheme = name;
313
- };
314
-
315
- const themeName = () => currentTheme;
316
-
317
- const codeFg = (style) => {
318
- if (typeof style !== 'string') return CODE_FG.plain;
319
- if (Object.hasOwn(CODE_FG, style)) return CODE_FG[style];
320
- if (style.startsWith('logCol')) {
321
- const i = parseInt(style.slice(6), 10);
322
- return LOG_COL_FG[i % LOG_COL_FG.length];
323
- }
324
- return CODE_FG.plain;
325
- };
326
-
327
- const channels = (rgb) => {
328
- if (typeof rgb === 'number') return `${rgb};${rgb};${rgb}`;
329
- return `${rgb[0]};${rgb[1]};${rgb[2]}`;
330
- };
331
-
332
- const fg = (rgb) => `${ESC}[38;2;${channels(rgb)}m`;
333
-
334
- const bg = (rgb) => `${ESC}[48;2;${channels(rgb)}m`;
335
-
336
- const seq = (fgRgb, bgRgb) => `${fg(fgRgb)}${bg(bgRgb)}`;
337
-
338
- const paint = (text, fgRgb, bgRgb, color, bold) => {
339
- if (!color || text === '') return text;
340
- const mark = bold ? BOLD : '';
341
- return `${mark}${seq(fgRgb, bgRgb)}${text}${RESET}`;
342
- };
343
-
344
- const stripAnsi = (text) => text.replace(ANSI_RE, '');
345
-
346
- const graphemes = (text) => {
347
- const parts = new Array(text.length);
348
- let n = 0;
349
- for (const { segment } of SEGMENTER.segment(text)) parts[n++] = segment;
350
- parts.length = n;
351
- return parts;
352
- };
353
-
354
- const isWide = (cp) => {
355
- let lo = 0;
356
- let hi = WIDE_CP.length >> 1;
357
- while (lo < hi) {
358
- const mid = (lo + hi) >> 1;
359
- const start = WIDE_CP[mid << 1];
360
- const end = WIDE_CP[(mid << 1) + 1];
361
- if (cp < start) hi = mid;
362
- else if (cp > end) lo = mid + 1;
363
- else return true;
364
- }
365
- return false;
366
- };
367
-
368
- const graphemeWidth = (ch, col) => {
369
- if (ch === '\t') return 8 - (col % 8);
370
- if (ch === '\n' || ch === '\r') return 0;
371
- const cp = ch.codePointAt(0);
372
- if (cp <= 0x1f || cp === 0x7f) return 0;
373
- if (cp === 0x200d) return 0;
374
- if (cp >= 0xfe00 && cp <= 0xfe0f) return 0;
375
- if (isWide(cp)) return 2;
376
- return 1;
377
- };
378
-
379
- const visibleWidth = (text) => {
380
- const plain = stripAnsi(text);
381
- let width = 0;
382
- for (const ch of graphemes(plain)) {
383
- width += graphemeWidth(ch, width);
384
- }
385
- return width;
386
- };
387
-
388
- const truncateVisible = (text, width, mark = '') => {
389
- if (width <= 0) return '';
390
- const plain = stripAnsi(text);
391
- if (visibleWidth(plain) <= width) return text;
392
- const markW = mark ? visibleWidth(mark) : 0;
393
- const fits = markW > 0 && markW <= width;
394
- const limit = fits ? width - markW : width;
395
- const parts = graphemes(plain);
396
- let used = 0;
397
- let out = '';
398
- for (const ch of parts) {
399
- const w = graphemeWidth(ch, used);
400
- if (used + w > limit) break;
401
- out += ch;
402
- used += w;
403
- }
404
- return fits ? `${out}${mark}` : out;
405
- };
406
-
407
- const trimVisible = (text, width) => truncateVisible(text, width, '…');
408
-
409
- const csiLength = (text, index) => {
410
- if (text[index] !== ESC || text[index + 1] !== '[') return 0;
411
- let at = index + 2;
412
- while (at < text.length) {
413
- const code = text.charCodeAt(at);
414
- at += 1;
415
- if (code >= 64 && code <= 126) return at - index;
416
- }
417
- return 0;
418
- };
419
-
420
- const firstGrapheme = (text) => {
421
- const next = SEGMENTER.segment(text)[Symbol.iterator]().next();
422
- if (next.done || !next.value) return '';
423
- return next.value.segment;
424
- };
425
-
426
- const clipAnsi = (text, width) => {
427
- const raw = `${text ?? ''}`;
428
- if (width <= 0) return '';
429
- if (visibleWidth(raw) <= width) return raw;
430
- let used = 0;
431
- let out = '';
432
- let index = 0;
433
- while (index < raw.length && used < width) {
434
- const csi = csiLength(raw, index);
435
- if (csi) {
436
- out += raw.slice(index, index + csi);
437
- index += csi;
438
- continue;
439
- }
440
- const ch = firstGrapheme(raw.slice(index));
441
- if (!ch) break;
442
- const w = graphemeWidth(ch, used);
443
- if (used + w > width) break;
444
- out += ch;
445
- used += w;
446
- index += ch.length;
447
- }
448
- if (stripAnsi(out) !== stripAnsi(raw)) out += RESET;
449
- return out;
450
- };
451
-
452
- const sgrParams = (seq) => {
453
- const inner = seq.slice(2, -1);
454
- if (!inner) return [0];
455
- return inner.split(';').map((part) => (part === '' ? 0 : Number(part)));
456
- };
457
-
458
- const colorSpan = (params, index) => {
459
- const mode = params[index + 1];
460
- if (mode === 5) return 2;
461
- if (mode === 2) return 4;
462
- return 0;
463
- };
464
-
465
- const keepFgParams = (params) => {
466
- const kept = [];
467
- for (let i = 0; i < params.length; i++) {
468
- const code = params[i];
469
- if (code === 38 || code === 48) {
470
- const extra = colorSpan(params, i);
471
- if (code === 38 && extra) {
472
- kept.push(code, ...params.slice(i + 1, i + 1 + extra));
473
- }
474
- i += extra;
475
- continue;
476
- }
477
- if (code >= 40 && code <= 49) continue;
478
- if (code >= 100 && code <= 107) continue;
479
- if (code === 7 || code === 27) continue;
480
- kept.push(code);
481
- }
482
- return kept;
483
- };
484
-
485
- const foregroundOn = (text, bgRgb) => {
486
- const raw = `${text ?? ''}`;
487
- const ground = bg(bgRgb);
488
- let out = '';
489
- let index = 0;
490
- while (index < raw.length) {
491
- if (raw[index] !== ESC) {
492
- const next = raw.indexOf(ESC, index);
493
- const end = next < 0 ? raw.length : next;
494
- out += raw.slice(index, end);
495
- index = end;
496
- continue;
497
- }
498
- const csi = csiLength(raw, index);
499
- if (!csi) {
500
- out += raw[index];
501
- index += 1;
502
- continue;
503
- }
504
- const seq = raw.slice(index, index + csi);
505
- index += csi;
506
- if (!seq.endsWith('m')) {
507
- out += seq;
508
- continue;
509
- }
510
- const kept = keepFgParams(sgrParams(seq));
511
- const reset = kept.includes(0);
512
- const rest = kept.filter((code) => code !== 0);
513
- if (reset) out += RESET;
514
- out += ground;
515
- if (rest.length) out += `${ESC}[${rest.join(';')}m`;
516
- }
517
- return out;
518
- };
519
-
520
- module.exports = {
521
- ESC,
522
- RESET,
523
- BOLD,
524
- EL,
525
- THEME,
526
- CODE_FG,
527
- PALETTES,
528
- THEME_NAMES,
529
- setTheme,
530
- themeName,
531
- codeFg,
532
- fg,
533
- bg,
534
- seq,
535
- paint,
536
- stripAnsi,
537
- graphemes,
538
- graphemeWidth,
539
- visibleWidth,
540
- truncateVisible,
541
- trimVisible,
542
- firstGrapheme,
543
- clipAnsi,
544
- foregroundOn,
545
- };
package/lib/detect.js DELETED
@@ -1,34 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('node:path');
4
- const metautil = require('metautil');
5
- const { fileExt } = metautil;
6
-
7
- const highlight = require('./highlight.js');
8
- const { mapLang } = highlight;
9
-
10
- const PROSE_BASENAMES = [
11
- 'license',
12
- 'licence',
13
- 'copying',
14
- 'authors',
15
- 'notice',
16
- 'copyright',
17
- ];
18
-
19
- const isProse = (base) => {
20
- const stem = base.replace(/\.(txt|text|md|markdown)$/, '');
21
- return PROSE_BASENAMES.includes(stem);
22
- };
23
-
24
- const detectLang = (filePath) => {
25
- const base = path.basename(filePath || '').toLowerCase();
26
- if (base.endsWith('.d.ts')) return 'dts';
27
- if (isProse(base)) return 'md';
28
- if (base.endsWith('.log')) return 'log';
29
- if (base.startsWith('.') || !base.includes('.')) return 'dot';
30
- const ext = fileExt(base);
31
- return ext ? mapLang(ext) : 'dot';
32
- };
33
-
34
- module.exports = { detectLang };
package/lib/diff/edit.js DELETED
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- const addBlockRange = (hunk, blockId) => {
4
- let newLine = hunk.newStart;
5
- let start = 0;
6
- let count = 0;
7
- for (const line of hunk.lines) {
8
- if (line.type === 'del') {
9
- if (line.blockId === blockId && start === 0) start = newLine;
10
- continue;
11
- }
12
- if (line.type === 'add' && line.blockId === blockId) {
13
- if (count === 0) start = newLine;
14
- count += 1;
15
- }
16
- newLine += 1;
17
- }
18
- if (start === 0) start = hunk.newStart;
19
- return { start, count };
20
- };
21
-
22
- const replaceBlockAdds = (content, hunk, blockId, text) => {
23
- const range = addBlockRange(hunk, blockId);
24
- const ended = content.endsWith('\n');
25
- const body = ended ? content.slice(0, -1) : content;
26
- const lines = content === '' ? [] : body.split('\n');
27
- const from = Math.min(lines.length, Math.max(0, range.start - 1));
28
- const added = text === '' ? [] : text.split('\n');
29
- lines.splice(from, range.count, ...added);
30
- return lines.join('\n') + (ended ? '\n' : '');
31
- };
32
-
33
- module.exports = { addBlockRange, replaceBlockAdds };