@sejuneoh/aitop 0.38.1 → 0.40.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/README.md +11 -2
- package/bin/aitop.mjs +2 -0
- package/package.json +1 -1
- package/src/cache.mjs +3 -1
- package/src/help.mjs +24 -3
- package/src/i18n.mjs +68 -0
- package/src/json.mjs +4 -0
- package/src/keys.mjs +94 -1
- package/src/sources/artifact-source.mjs +278 -0
- package/src/sources/artifacts.mjs +94 -0
- package/src/sources/claude-tracker.mjs +108 -3
- package/src/sources/claude.mjs +11 -1
- package/src/tail.mjs +18 -10
- package/src/ui/artifact-view.mjs +634 -0
- package/src/ui/chrome.mjs +4 -0
- package/src/ui/detail.mjs +66 -1
- package/src/ui/draw.mjs +5 -2
- package/src/ui/theme.mjs +26 -0
- package/src/ui.mjs +12 -1
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
**Keys on the live screen**
|
|
73
73
|
|
|
74
74
|
- `↑↓` select · `n` next session to check · `/` search · `s` sort · `g` group
|
|
75
|
-
- `p` pin · `f` changed files · `a` waiting alerts on/off · `?` help · `q` quit
|
|
75
|
+
- `p` pin · `f` changed files · `v` artifacts (Enter views the source) · `a` waiting alerts on/off · `?` help · `q` quit
|
|
76
76
|
|
|
77
77
|
**Config file**
|
|
78
78
|
|
|
@@ -89,10 +89,11 @@
|
|
|
89
89
|
- **Waiting alerts**: blocked sessions jump to the top, with optional bell, desktop notification or hook command.
|
|
90
90
|
- **Tokens and cost** per session and for today / last 7 days, estimated at public API list prices. This is not your bill.
|
|
91
91
|
- **Changed files and diffs** per session and per prompt.
|
|
92
|
+
- **Artifacts** a Claude or Cowork session (or its subagents) published with the Artifact tool, with clickable links.
|
|
92
93
|
- **Read-only**: no network, no ports, no dependencies. It only reads the session logs each CLI already writes.
|
|
93
94
|
|
|
94
95
|
<details>
|
|
95
|
-
<summary>Details: stopped sessions, cache countdown, tool run time, context gauge, tool line</summary>
|
|
96
|
+
<summary>Details: stopped sessions, cache countdown, tool run time, context gauge, artifacts, tool line</summary>
|
|
96
97
|
|
|
97
98
|
**Stopped by an error**
|
|
98
99
|
|
|
@@ -118,6 +119,13 @@
|
|
|
118
119
|
|
|
119
120
|
- `~` marks 60% and up, `!` 85% and up, so the levels show without color. Under `NO_COLOR` the bar is `███░░`, and a gauge that reads 0% has no filled cell.
|
|
120
121
|
|
|
122
|
+
**Artifacts**
|
|
123
|
+
|
|
124
|
+
- The detail panel shows `── Artifacts N ──` when a session published any: `title · v1→v3 · 14:02 · claude.ai/…`, plus `edited in place` for an `edits` publish `org` for an org-shared link and `public` for a public one (nothing for `owner`). The version range comes from the publish sequence number; without one it is left out. When space is short, the latest few and `+N`.
|
|
125
|
+
- Only `https://claude.ai/` addresses become OSC 8 links. Under `NO_COLOR`, in piped output and in terminals not known to support links they are plain text; `FORCE_HYPERLINK=1` or `0` overrides. Only the title, address, publish sequence number, time, audience and whether `edits` was used are read (no file paths or edit contents).
|
|
126
|
+
- `--json` has `artifacts` per session (`title`, `url`, `versionFrom`, `versionTo`, `updatedAt`, `audience`, `viaEdits`); `url` is `null` unless it is a `https://claude.ai/` address.
|
|
127
|
+
- `v` moves into the list, `↑↓` picks and `Enter` shows the source full screen (`↑↓` · `space` · `PgUp/PgDn` · `Home/End` scroll, `[ ]` previous/next, `Esc` back one step). The source is looked up only then: the local file at the published path (a regular file, not a symlink, first 2MB), else the last `Write` of that path in the same session's transcripts (subagents included, marked `may differ from the published version` when an `Edit` or an `edits` publish came after it), else `no source`. HTML is never run: scripts, styles, templates and comments are dropped and headings, paragraphs, lists, tables, code and quotes are shown as text, with `data:` images as `[image 120KB]`. Markdown gets simple headings, lists and code blocks.
|
|
128
|
+
|
|
121
129
|
**Tool line and empty screen**
|
|
122
130
|
|
|
123
131
|
- Tools with no live session and no use for 7 days leave the tool line. Its end tells the two kinds apart: `not installed: codex unused 7d: gemini` (counts when space is short). Turn it off with `"hideIdleTools": false`.
|
|
@@ -554,6 +562,7 @@ Continue a session elsewhere, for example when you cannot jump to its tab, as in
|
|
|
554
562
|
- `cacheExpiresAt`, `toolStartedAt`: [Features](#features).
|
|
555
563
|
- `stalled`, `startedAt`, `lastActivityAt`, `entrypoint`, `auto`, `parentId`: [Subagents](#subagents).
|
|
556
564
|
- `resumeCmd`: [Resume a session elsewhere](#resume-a-session-elsewhere).
|
|
565
|
+
- `artifacts`: [Features](#features).
|
|
557
566
|
- Report output (`month`, `current`, `status`, `paths`, `unpriced`, `waitedMs`): [Daily and monthly reports](#daily-and-monthly-reports), [Session report](#session-report).
|
|
558
567
|
|
|
559
568
|
</details>
|
package/bin/aitop.mjs
CHANGED
package/package.json
CHANGED
package/src/cache.mjs
CHANGED
|
@@ -11,8 +11,10 @@ import { debug, debugIo } from './log.mjs';
|
|
|
11
11
|
|
|
12
12
|
// 캐시 형식이 바뀌면 VERSION 을, 가격표가 바뀌면 PRICE_TAG 가 폴더 이름을 바꿔서 예전 캐시를 버린다.
|
|
13
13
|
// 14: 장부의 하루 합계에 모델별 몫(models)을 더하고, 날짜를 10일이 아니라 30일 남긴다 (#128).
|
|
14
|
+
// 15: 세션 기록 캐시에 Artifact 게시 목록(artifacts, artCalls)을 더한다 (#305). 이미 읽은 부분의 게시를 놓치지 않게 다시 읽는다.
|
|
15
|
+
// 16: 15 의 첫 판(3a1eb62)이 version 을 숫자로 잘못 읽어 남긴 캐시를 버린다. 그대로 두면 업데이트 뒤에도 아티팩트 버전이 null 로 읽힌다.
|
|
14
16
|
// 장부(ledger)만 형식이 바뀔 때는 VERSION 대신 장부의 kind 이름을 바꿔 장부만 다시 센다 (세션 화면 캐시는 그대로).
|
|
15
|
-
const VERSION =
|
|
17
|
+
const VERSION = 16;
|
|
16
18
|
// Windows 는 XDG_CACHE_HOME 이 없으면 %LOCALAPPDATA%\aitop\cache (paths.mjs).
|
|
17
19
|
const ROOT = appDir('cache', { home: homedir() });
|
|
18
20
|
export const CACHE_ROOT = ROOT;
|
package/src/help.mjs
CHANGED
|
@@ -34,6 +34,7 @@ export const VIEWS = {
|
|
|
34
34
|
keys: [
|
|
35
35
|
k('detail.switch', '↑↓ j k', 'switchSession', '↑↓/jk'),
|
|
36
36
|
k('detail.files', 'f Tab', 'files'),
|
|
37
|
+
k('detail.artifacts', 'v', 'artifacts'),
|
|
37
38
|
k('detail.copy', 'y', 'copy'),
|
|
38
39
|
k('detail.close', 'd', 'close'),
|
|
39
40
|
],
|
|
@@ -58,6 +59,26 @@ export const VIEWS = {
|
|
|
58
59
|
k('diff.back', 'Esc h ← f Tab', 'back'),
|
|
59
60
|
],
|
|
60
61
|
},
|
|
62
|
+
artifacts: {
|
|
63
|
+
name: 'artifacts',
|
|
64
|
+
title: ko('view.artifacts'),
|
|
65
|
+
keys: [
|
|
66
|
+
k('artifacts.pick', '↑↓ j k', 'pick', '↑↓/jk'),
|
|
67
|
+
k('artifacts.open', 'Enter l', 'source'),
|
|
68
|
+
k('artifacts.back', 'Esc h v', 'back'),
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
artifact: {
|
|
72
|
+
name: 'artifact',
|
|
73
|
+
title: ko('view.artifact'),
|
|
74
|
+
keys: [
|
|
75
|
+
k('artifact.scroll', '↑↓ j k', 'scroll', '↑↓/jk'),
|
|
76
|
+
k('artifact.page', 'space PgDn PgUp', 'page', 'space'),
|
|
77
|
+
k('artifact.ends', 'Home End', 'ends', 'Home/End'),
|
|
78
|
+
k('artifact.prevNext', '[ ]', 'prevNextArt', '[ ]'),
|
|
79
|
+
k('artifact.back', 'Esc h ←', 'back'),
|
|
80
|
+
],
|
|
81
|
+
},
|
|
61
82
|
filtered: {
|
|
62
83
|
name: 'filtered',
|
|
63
84
|
title: ko('view.filtered'),
|
|
@@ -107,9 +128,9 @@ const OPTION_IDS = [
|
|
|
107
128
|
export const options = (lang = getLang()) => OPTION_IDS.map(([o, d]) => [o.startsWith('hopt.') ? t(o, null, { lang }) : o, t(d, null, { lang })]);
|
|
108
129
|
export const OPTIONS = options('ko');
|
|
109
130
|
|
|
110
|
-
// 지금 보는 화면: 파일 목록·diff
|
|
131
|
+
// 지금 보는 화면: 파일 목록·diff·아티팩트 목록·원본에 들어가 있으면 그 화면, 아니면 세션 표. 검색어는 표에 붙는 것이라 helpSections 가 따로 본다.
|
|
111
132
|
export function helpContext(view) {
|
|
112
|
-
if (
|
|
133
|
+
if (['diff', 'files', 'artifacts', 'artifact'].includes(view.focus)) return view.focus;
|
|
113
134
|
return 'table';
|
|
114
135
|
}
|
|
115
136
|
|
|
@@ -130,7 +151,7 @@ export function viewText(v, lang = getLang()) {
|
|
|
130
151
|
// aitop --help 끝의 키 안내. 지금 언어(bin 이 정한다)로 쓴다.
|
|
131
152
|
export function keysText(lang = getLang()) {
|
|
132
153
|
const title = (n) => t(`view.${n}`, null, { lang });
|
|
133
|
-
return [`${t('help.keys', null, { lang })}: ${keysLine('table', lang)} · ${keysLine('common', lang)}`, ...['detail', 'files', 'diff', 'filtered', 'search'].map((n) => ` ${title(n)}: ${keysLine(n, lang)}`)].join('\n');
|
|
154
|
+
return [`${t('help.keys', null, { lang })}: ${keysLine('table', lang)} · ${keysLine('common', lang)}`, ...['detail', 'files', 'diff', 'artifacts', 'artifact', 'filtered', 'search'].map((n) => ` ${title(n)}: ${keysLine(n, lang)}`)].join('\n');
|
|
134
155
|
}
|
|
135
156
|
|
|
136
157
|
// 지금 설정 값 한 줄 (예: 예산 $50 · 알림 켜짐 · 디버그 꺼짐). settings 가 없으면 null.
|
package/src/i18n.mjs
CHANGED
|
@@ -187,6 +187,8 @@ export const STRINGS = {
|
|
|
187
187
|
'view.detail': '상세 패널',
|
|
188
188
|
'view.files': '변경 파일 목록',
|
|
189
189
|
'view.diff': 'diff',
|
|
190
|
+
'view.artifacts': '아티팩트 목록',
|
|
191
|
+
'view.artifact': '아티팩트 원본',
|
|
190
192
|
'view.filtered': '검색어가 걸린 표',
|
|
191
193
|
'view.search': '검색 입력 중',
|
|
192
194
|
'view.common': '어디서나',
|
|
@@ -211,6 +213,10 @@ export const STRINGS = {
|
|
|
211
213
|
'key.scroll': '스크롤',
|
|
212
214
|
'key.page': '페이지',
|
|
213
215
|
'key.prevNext': '이전·다음 파일',
|
|
216
|
+
'key.artifacts': '아티팩트',
|
|
217
|
+
'key.source': '원본 보기',
|
|
218
|
+
'key.ends': '처음·끝',
|
|
219
|
+
'key.prevNextArt': '이전·다음 아티팩트',
|
|
214
220
|
'key.clearSearch': '검색어 지우기',
|
|
215
221
|
'key.newSearch': '새 검색',
|
|
216
222
|
'key.type': '입력',
|
|
@@ -492,6 +498,10 @@ export const STRINGS = {
|
|
|
492
498
|
'foot.pickFile': '파일 선택',
|
|
493
499
|
'foot.viewDiff': 'diff 보기',
|
|
494
500
|
'foot.toSessions': '세션으로',
|
|
501
|
+
'foot.artifacts': '아티팩트',
|
|
502
|
+
'foot.pickArtifact': '아티팩트 선택',
|
|
503
|
+
'foot.viewSource': '원본 보기',
|
|
504
|
+
'foot.toArtifacts': '목록으로',
|
|
495
505
|
'foot.hideEnded': '종료 숨김',
|
|
496
506
|
'foot.showEnded': '종료 포함',
|
|
497
507
|
'foot.next': '다음',
|
|
@@ -580,6 +590,15 @@ export const STRINGS = {
|
|
|
580
590
|
'hk.diff.page': '한 페이지씩',
|
|
581
591
|
'hk.diff.prevNext': '이전·다음 파일',
|
|
582
592
|
'hk.diff.back': '파일 목록으로',
|
|
593
|
+
'hk.detail.artifacts': '아티팩트 목록으로 (게시한 것이 있을 때)',
|
|
594
|
+
'hk.artifacts.pick': '아티팩트 고르기',
|
|
595
|
+
'hk.artifacts.open': '고른 아티팩트의 원본을 전체 화면으로 (로컬 파일 → 기록의 Write 본문 순으로 찾는다)',
|
|
596
|
+
'hk.artifacts.back': '세션 표로',
|
|
597
|
+
'hk.artifact.scroll': '한 줄씩 스크롤',
|
|
598
|
+
'hk.artifact.page': '한 페이지씩',
|
|
599
|
+
'hk.artifact.ends': '처음·끝으로',
|
|
600
|
+
'hk.artifact.prevNext': '이전·다음 아티팩트',
|
|
601
|
+
'hk.artifact.back': '아티팩트 목록으로',
|
|
583
602
|
'hk.filtered.select': '검색 결과 안에서 세션 선택',
|
|
584
603
|
'hk.filtered.clear': '검색어 지우기 (표 전체로)',
|
|
585
604
|
'hk.filtered.new': '지금 검색어를 지우고 새로 입력',
|
|
@@ -629,6 +648,21 @@ export const STRINGS = {
|
|
|
629
648
|
'detail.noTurn': '지시 기록 없음',
|
|
630
649
|
'detail.editCount': ' 편집 {n}회',
|
|
631
650
|
'detail.request': '요청',
|
|
651
|
+
'detail.artifacts': '아티팩트 {n}',
|
|
652
|
+
'detail.artEdits': '바로 수정',
|
|
653
|
+
'detail.artPublic': '공개',
|
|
654
|
+
'detail.artOrg': '조직 공유',
|
|
655
|
+
'art.srcLocal': '로컬 파일',
|
|
656
|
+
'art.srcRecord': '기록 본문',
|
|
657
|
+
'art.srcNone': '원본 없음',
|
|
658
|
+
'art.srcLoading': '찾는 중…',
|
|
659
|
+
'art.loading': '기록에서 원본을 찾는 중…',
|
|
660
|
+
'art.noneNote': '원본 없음 (임시 파일이 지워졌고 기록에도 본문이 없다)',
|
|
661
|
+
'art.mayDiffer': '게시본과 다를 수 있음',
|
|
662
|
+
'art.cut': '앞 {n}만',
|
|
663
|
+
'art.empty': '(보일 글이 없음)',
|
|
664
|
+
'art.image': '[이미지 {size}]',
|
|
665
|
+
'art.imageAlt': '[이미지: {alt}]',
|
|
632
666
|
'detail.activity': '최근 활동',
|
|
633
667
|
'detail.files': '변경 파일',
|
|
634
668
|
'detail.tabNone': ' · {tab} 0개',
|
|
@@ -684,6 +718,8 @@ export const STRINGS = {
|
|
|
684
718
|
'view.detail': 'Detail panel',
|
|
685
719
|
'view.files': 'Changed files',
|
|
686
720
|
'view.diff': 'diff',
|
|
721
|
+
'view.artifacts': 'Artifact list',
|
|
722
|
+
'view.artifact': 'Artifact source',
|
|
687
723
|
'view.filtered': 'Filtered table',
|
|
688
724
|
'view.search': 'Typing a search',
|
|
689
725
|
'view.common': 'Anywhere',
|
|
@@ -708,6 +744,10 @@ export const STRINGS = {
|
|
|
708
744
|
'key.scroll': 'scroll',
|
|
709
745
|
'key.page': 'page',
|
|
710
746
|
'key.prevNext': 'prev/next file',
|
|
747
|
+
'key.artifacts': 'artifacts',
|
|
748
|
+
'key.source': 'view source',
|
|
749
|
+
'key.ends': 'top/bottom',
|
|
750
|
+
'key.prevNextArt': 'prev/next artifact',
|
|
711
751
|
'key.clearSearch': 'clear search',
|
|
712
752
|
'key.newSearch': 'new search',
|
|
713
753
|
'key.type': 'to search',
|
|
@@ -980,6 +1020,10 @@ export const STRINGS = {
|
|
|
980
1020
|
'foot.pickFile': 'pick file',
|
|
981
1021
|
'foot.viewDiff': 'view diff',
|
|
982
1022
|
'foot.toSessions': 'to sessions',
|
|
1023
|
+
'foot.artifacts': 'artifacts',
|
|
1024
|
+
'foot.pickArtifact': 'pick artifact',
|
|
1025
|
+
'foot.viewSource': 'view source',
|
|
1026
|
+
'foot.toArtifacts': 'to list',
|
|
983
1027
|
'foot.hideEnded': 'hide ended',
|
|
984
1028
|
'foot.showEnded': 'show ended',
|
|
985
1029
|
'foot.next': 'next',
|
|
@@ -1067,6 +1111,15 @@ export const STRINGS = {
|
|
|
1067
1111
|
'hk.diff.page': 'Scroll one page',
|
|
1068
1112
|
'hk.diff.prevNext': 'Previous or next file',
|
|
1069
1113
|
'hk.diff.back': 'Back to the file list',
|
|
1114
|
+
'hk.detail.artifacts': 'Open the artifact list (when something was published)',
|
|
1115
|
+
'hk.artifacts.pick': 'Pick an artifact',
|
|
1116
|
+
'hk.artifacts.open': 'View the source full screen (local file first, then the Write body in the transcript)',
|
|
1117
|
+
'hk.artifacts.back': 'Back to the session table',
|
|
1118
|
+
'hk.artifact.scroll': 'Scroll one line',
|
|
1119
|
+
'hk.artifact.page': 'Scroll one page',
|
|
1120
|
+
'hk.artifact.ends': 'Jump to top or bottom',
|
|
1121
|
+
'hk.artifact.prevNext': 'Previous or next artifact',
|
|
1122
|
+
'hk.artifact.back': 'Back to the artifact list',
|
|
1070
1123
|
'hk.filtered.select': 'Select a session in the results',
|
|
1071
1124
|
'hk.filtered.clear': 'Clear the search (full table)',
|
|
1072
1125
|
'hk.filtered.new': 'Clear the search and type a new one',
|
|
@@ -1114,6 +1167,21 @@ export const STRINGS = {
|
|
|
1114
1167
|
'detail.noTurn': 'No prompt found',
|
|
1115
1168
|
'detail.editCount': { one: ' {n} edit', other: ' {n} edits' },
|
|
1116
1169
|
'detail.request': 'Request',
|
|
1170
|
+
'detail.artifacts': 'Artifacts {n}',
|
|
1171
|
+
'detail.artEdits': 'edited in place',
|
|
1172
|
+
'detail.artPublic': 'public',
|
|
1173
|
+
'detail.artOrg': 'org',
|
|
1174
|
+
'art.srcLocal': 'local file',
|
|
1175
|
+
'art.srcRecord': 'transcript body',
|
|
1176
|
+
'art.srcNone': 'no source',
|
|
1177
|
+
'art.srcLoading': 'searching…',
|
|
1178
|
+
'art.loading': 'Searching the transcript for the source…',
|
|
1179
|
+
'art.noneNote': 'No source (the temp file is gone and the transcript has no body)',
|
|
1180
|
+
'art.mayDiffer': 'may differ from the published version',
|
|
1181
|
+
'art.cut': 'first {n} only',
|
|
1182
|
+
'art.empty': '(nothing to show)',
|
|
1183
|
+
'art.image': '[image {size}]',
|
|
1184
|
+
'art.imageAlt': '[image: {alt}]',
|
|
1117
1185
|
'detail.activity': 'Recent activity',
|
|
1118
1186
|
'detail.files': 'Changed files',
|
|
1119
1187
|
'detail.tabNone': ' · {tab}: none',
|
package/src/json.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { toolsJson } from './doctor.mjs';
|
|
|
3
3
|
import { phaseText } from './i18n.mjs';
|
|
4
4
|
import { resumeCmd } from './resume.mjs';
|
|
5
5
|
import { memberStalled } from './sources/common.mjs';
|
|
6
|
+
import { artifactLink } from './sources/artifacts.mjs';
|
|
6
7
|
|
|
7
8
|
// aitop --json 출력. 다른 스크립트나 AI 가 읽기 쉬운 모양으로 세션 목록과 사용량 합계를 담는다.
|
|
8
9
|
// 텍스트는 수집 단계에서 이미 비밀값 가림이 적용돼 있다.
|
|
@@ -73,6 +74,9 @@ export function toJson(data, version = null, opts = {}) {
|
|
|
73
74
|
context: { used: s.context?.used ?? 0, window: s.context?.window ?? null },
|
|
74
75
|
// 변경 내용(diff)은 넣지 않고 파일별 통계만 넣는다. 줄 수는 편집마다 더한 누적값이다 (git diff 아님).
|
|
75
76
|
files: (s.files ?? []).map((f) => ({ path: f.path, created: Boolean(f.created), edits: f.edits, writtenLines: f.add, deletedLines: f.del, updatedAt: iso(f.at), agents: f.agents ?? [] })),
|
|
77
|
+
// Artifact 도구로 게시한 것 (Claude·Cowork, 서브에이전트 포함, 마지막 게시가 최근인 것부터). url 은 https://claude.ai/ 주소만 두고 나머지는 null, audience 는 기록 값 그대로('owner'·'org' 등).
|
|
78
|
+
// versionFrom·versionTo 는 이 세션에서 본 게시 버전 범위, viaEdits 는 마지막 게시가 edits 로 바로 고친 것인지다.
|
|
79
|
+
artifacts: (s.artifacts ?? []).map((a) => ({ title: a.title ?? null, url: artifactLink(a.url), versionFrom: a.from ?? null, versionTo: a.to ?? null, updatedAt: iso(a.at), audience: a.audience ?? null, viaEdits: Boolean(a.edits) })),
|
|
76
80
|
// startedAt·lastActivityAt 은 세션의 startedAt·updatedAt 과 같은 ISO 시각이다 (모르면 null).
|
|
77
81
|
// stalled 는 화면의 '멈춘 듯' 과 같은 짐작(common.mjs memberStalled)을 data.at 기준으로 본 값이다.
|
|
78
82
|
members: (s.members ?? []).map((m) => ({ ...(m.sdk ? { id: m.id, entrypoint: m.entrypoint ?? null, parentId: m.parentId ?? s.id } : {}), name: m.name, task: m.task ?? null, model: m.model ?? null, status: m.status, phase: koPhase(m.phase), phaseKind: m.phase?.kind ?? null, tokens: m.tokens ?? 0, cost: money(m.cost), startedAt: iso(m.startedAt), lastActivityAt: iso(m.lastActivityAt), stalled: memberStalled(m, data.at ?? Date.now(), s.status) })),
|
package/src/keys.mjs
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
// 키 입력 처리. 화면 상태(view)를 바꾸고, 종료·갱신·세션 이동처럼 밖에서 해야 할 일은 act 로 부른다.
|
|
2
2
|
// view.focus: null(세션 선택) → 'files'(변경 파일 목록) → 'diff'(고른 파일의 변경 내용). Esc 는 한 단계씩 뒤로 가고 종료하지 않는다.
|
|
3
|
+
// 아티팩트(#307): v 로 상세 패널의 아티팩트 목록에 들어가 'artifacts'(목록) → Enter 'artifact'(원본 전체 화면). Esc 로 한 단계씩 돌아온다.
|
|
4
|
+
// view.artifactId: 고른 아티팩트, view.artDoc: 연 원본 (Enter 때만 artifact-source.mjs 가 찾는다), view.artScroll: 원본 스크롤 위치.
|
|
3
5
|
// view.tab: 변경 파일을 보는 지시 탭 ('now' 이번 지시, 지시 번호, 'all' 전체). turns.mjs 참고.
|
|
4
6
|
import { turnTabs, visibleFiles } from './turns.mjs';
|
|
5
7
|
import { detailOpen } from './ui/chrome.mjs';
|
|
6
8
|
import { nextGroup, nextSort, togglePin } from './order.mjs';
|
|
9
|
+
import { openArtifactSource } from './sources/artifact-source.mjs';
|
|
7
10
|
|
|
8
|
-
export const KEY = { up: '\x1b[A', down: '\x1b[B', right: '\x1b[C', left: '\x1b[D', pageUp: '\x1b[5~', pageDown: '\x1b[6~', esc: '\x1b', enter: '\r', tab: '\t', ctrlC: '\x03', backspace: '\x7f' };
|
|
11
|
+
export const KEY = { up: '\x1b[A', down: '\x1b[B', right: '\x1b[C', left: '\x1b[D', pageUp: '\x1b[5~', pageDown: '\x1b[6~', home: '\x1b[H', end: '\x1b[F', esc: '\x1b', enter: '\r', tab: '\t', ctrlC: '\x03', backspace: '\x7f' };
|
|
9
12
|
|
|
10
13
|
const isUp = (k) => k === KEY.up || k === 'k';
|
|
11
14
|
const isDown = (k) => k === KEY.down || k === 'j';
|
|
12
15
|
const isBack = (k) => k === KEY.esc || k === 'h';
|
|
16
|
+
// 터미널마다 Home·End 를 보내는 모양이 다르다.
|
|
17
|
+
const isHome = (k) => k === KEY.home || k === '\x1b[1~' || k === '\x1b[7~' || k === '\x1bOH';
|
|
18
|
+
const isEnd = (k) => k === KEY.end || k === '\x1b[4~' || k === '\x1b[8~' || k === '\x1bOF';
|
|
13
19
|
|
|
14
20
|
export function selectedSession(view) {
|
|
15
21
|
return view.data?.sessions.find((s) => s.id === view.selectedId) ?? null;
|
|
@@ -19,9 +25,23 @@ const hasFiles = (view) => Boolean(selectedSession(view)?.files?.length);
|
|
|
19
25
|
// 지금 탭에 보이는 파일
|
|
20
26
|
const filesOf = (view) => visibleFiles(selectedSession(view), view.tab);
|
|
21
27
|
|
|
28
|
+
const artsOf = (view) => selectedSession(view)?.artifacts ?? [];
|
|
29
|
+
const pickedArtifact = (view) => artsOf(view).find((a) => a.id === view.artifactId) ?? null;
|
|
30
|
+
|
|
22
31
|
// 갱신 뒤에 고른 파일이 탭에서 빠졌거나 세션에 고친 파일이 없어졌으면 포커스를 맞춘다.
|
|
23
32
|
export function fixFocus(view) {
|
|
24
33
|
if (!view.focus) return;
|
|
34
|
+
// 원본 화면은 연 원본(artDoc)이 있는 동안 그대로 둔다. 목록은 아티팩트가 없어지면 닫는다.
|
|
35
|
+
if (view.focus === 'artifact') {
|
|
36
|
+
if (!view.artDoc) view.focus = artsOf(view).length ? 'artifacts' : null;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (view.focus === 'artifacts') {
|
|
40
|
+
const arts = artsOf(view);
|
|
41
|
+
if (!arts.length || !view.showDetail) view.focus = null;
|
|
42
|
+
else if (!pickedArtifact(view)) view.artifactId = arts[0].id;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
25
45
|
if (!hasFiles(view) || !view.showDetail) {
|
|
26
46
|
view.focus = null;
|
|
27
47
|
return;
|
|
@@ -87,6 +107,76 @@ function diffKey(view, key) {
|
|
|
87
107
|
return true;
|
|
88
108
|
}
|
|
89
109
|
|
|
110
|
+
function enterArtifacts(view) {
|
|
111
|
+
const arts = artsOf(view);
|
|
112
|
+
if (!arts.length) return;
|
|
113
|
+
view.showDetail = true;
|
|
114
|
+
view.focus = 'artifacts';
|
|
115
|
+
if (!pickedArtifact(view)) view.artifactId = arts[0].id;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function stepArtifact(view, delta) {
|
|
119
|
+
const arts = artsOf(view);
|
|
120
|
+
const i = Math.max(0, arts.findIndex((a) => a.id === view.artifactId));
|
|
121
|
+
view.artifactId = arts[Math.min(arts.length - 1, Math.max(0, i + delta))]?.id ?? null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 원본은 화면을 열 때만 찾는다 (act.loadArtifact 는 테스트가 바꿔 끼운다).
|
|
125
|
+
// 기억한 위치로 바로 찾지 못하면 '찾는 중…' 을 먼저 보이고, 기록 훑기가 끝나면 바꾼 뒤 act.redraw 로 다시 그린다.
|
|
126
|
+
// 그 사이 다른 원본을 열거나 목록으로 돌아가면(view.artDoc 가 바뀜) 훑기를 그만둔다.
|
|
127
|
+
function openArtifact(view, act) {
|
|
128
|
+
const a = pickedArtifact(view);
|
|
129
|
+
if (!a) return;
|
|
130
|
+
view.focus = 'artifact';
|
|
131
|
+
view.artScroll = 0;
|
|
132
|
+
if (act?.loadArtifact) {
|
|
133
|
+
view.artDoc = act.loadArtifact(selectedSession(view), a);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const wait = { kind: 'loading', path: null, text: '', cut: false, changed: false };
|
|
137
|
+
view.artDoc = wait;
|
|
138
|
+
const doc = openArtifactSource(selectedSession(view), a, {
|
|
139
|
+
cancelled: () => view.artDoc !== wait,
|
|
140
|
+
done: (d) => {
|
|
141
|
+
if (view.artDoc !== wait) return;
|
|
142
|
+
view.artDoc = d;
|
|
143
|
+
act?.redraw?.();
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
if (doc) view.artDoc = doc;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function artifactsKey(view, key, act) {
|
|
150
|
+
if (isUp(key)) stepArtifact(view, -1);
|
|
151
|
+
else if (isDown(key)) stepArtifact(view, 1);
|
|
152
|
+
else if (key === KEY.enter || key === 'l') openArtifact(view, act);
|
|
153
|
+
else if (isBack(key) || key === 'v') view.focus = null;
|
|
154
|
+
else return false;
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 원본 화면은 모달이다: 스크롤·이전/다음·뒤로 말고는 받지 않는다 (? 와 q 는 onKey 가 먼저 본다).
|
|
159
|
+
function artifactKey(view, key, act) {
|
|
160
|
+
const page = view.artPage ?? 10;
|
|
161
|
+
const at = view.artScroll ?? 0;
|
|
162
|
+
if (isUp(key)) view.artScroll = Math.max(0, at - 1);
|
|
163
|
+
else if (isDown(key)) view.artScroll = at + 1;
|
|
164
|
+
else if (key === ' ' || key === KEY.pageDown) view.artScroll = at + page;
|
|
165
|
+
else if (key === KEY.pageUp) view.artScroll = Math.max(0, at - page);
|
|
166
|
+
else if (isHome(key)) view.artScroll = 0;
|
|
167
|
+
// 끝은 그릴 때 본문 길이에 맞춘다 (artifact-view.mjs artifactScreen).
|
|
168
|
+
else if (isEnd(key)) view.artScroll = Infinity;
|
|
169
|
+
else if (key === '[' || key === ']') {
|
|
170
|
+
const before = view.artifactId;
|
|
171
|
+
stepArtifact(view, key === '[' ? -1 : 1);
|
|
172
|
+
if (view.artifactId !== before) openArtifact(view, act);
|
|
173
|
+
} else if (isBack(key) || key === KEY.left) {
|
|
174
|
+
view.focus = 'artifacts';
|
|
175
|
+
view.artDoc = null;
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
90
180
|
// 검색 중에는 글자를 검색어로 받는다. Enter 는 검색어를 남기고 목록으로, Esc 는 검색을 지운다.
|
|
91
181
|
function searchKey(view, key, act) {
|
|
92
182
|
if (key === KEY.enter) view.searching = false;
|
|
@@ -120,6 +210,8 @@ export function onKey(view, key, act) {
|
|
|
120
210
|
return;
|
|
121
211
|
}
|
|
122
212
|
if (key === 'q') return act.quit();
|
|
213
|
+
if (view.focus === 'artifact' && artifactKey(view, key, act)) return;
|
|
214
|
+
if (view.focus === 'artifacts' && artifactsKey(view, key, act)) return;
|
|
123
215
|
if (view.focus === 'diff' && diffKey(view, key)) return;
|
|
124
216
|
if (view.focus === 'files' && filesKey(view, key)) return;
|
|
125
217
|
if (key === KEY.esc) {
|
|
@@ -127,6 +219,7 @@ export function onKey(view, key, act) {
|
|
|
127
219
|
return;
|
|
128
220
|
}
|
|
129
221
|
if (key === 'f' || key === KEY.tab) return enterFiles(view);
|
|
222
|
+
if (key === 'v') return enterArtifacts(view);
|
|
130
223
|
if (key === '/') {
|
|
131
224
|
view.searching = true;
|
|
132
225
|
view.filter = '';
|