Skip to content

Commit 46f3e89

Browse files
Lee Seongjooclaude
andcommitted
Capture screenshots in backlog issues; selectable per-issue export to Downloads
- Issue records now store the attached screenshots (BacklogEntry.images, optional for back-compat). The backlog row shows an "첨부 이미지" thumbnail strip so an image-based 해설 issue isn't an empty "입력 —". - Export is selection-based: a checkbox per row + 전체 선택, and 내보내기 exports the checked entries (one or many). - Export writes a timestamped folder in ~/Downloads (single → backlog_<stage>_…, multiple → backlog_export_…) containing a readable backlog_export.json (image bytes replaced by PNG filenames) plus the screenshots as PNG files — so the images are openable for analysis instead of base64 blobs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0371e34 commit 46f3e89

3 files changed

Lines changed: 93 additions & 15 deletions

File tree

‎Sources/App/AppState.swift‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,16 @@ final class AppState: ObservableObject {
192192
}
193193
e = BacklogEntry(id: UUID().uuidString, createdAt: Date(), tags: finalTags, note: note,
194194
stage: "해설", provider: explainProvider.label, model: explainModel,
195-
prompt: explainPrompt, hint: explainHint, input: codeText, output: explanationText)
195+
prompt: explainPrompt, hint: explainHint, input: codeText, output: explanationText,
196+
images: codeImages.isEmpty ? nil : codeImages)
196197
case .script:
197198
guard !scriptText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
198199
statusText = "기록할 대본이 없습니다"; return
199200
}
200201
e = BacklogEntry(id: UUID().uuidString, createdAt: Date(), tags: finalTags, note: note,
201202
stage: "대본", provider: scriptProvider.label, model: scriptModel,
202-
prompt: normalizePrompt, hint: scriptHint, input: inputText, output: scriptText)
203+
prompt: normalizePrompt, hint: scriptHint, input: inputText, output: scriptText,
204+
images: nil)
203205
}
204206
backlogStore.add(e); backlog = backlogStore.entries
205207
statusText = "백로그에 기록됨 (\(stage == .explain ? "해설" : "대본"))"
@@ -208,7 +210,7 @@ final class AppState: ObservableObject {
208210
func updateBacklog(_ e: BacklogEntry) { backlogStore.update(e); backlog = backlogStore.entries }
209211
func deleteBacklog(_ id: String) { backlogStore.delete(id); backlog = backlogStore.entries }
210212
func clearBacklog() { backlogStore.clear(); backlog = backlogStore.entries }
211-
func exportBacklog() -> URL? { backlogStore.export() }
213+
func exportBacklog(_ items: [BacklogEntry]) -> URL? { backlogStore.export(items) }
212214
var backlogTags: [String] { backlogStore.allTags }
213215

214216
private func finish() {

‎Sources/Core/BacklogStore.swift‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct BacklogEntry: Codable, Identifiable, Hashable {
1515
let hint: String // per-run 추가 지시
1616
let input: String // code (해설) or source prose (대본)
1717
let output: String // generated 해설 / 대본
18+
var images: [Data]? // attached screenshots (해설), PNG; optional for back-compat
1819
}
1920

2021
/// Persists flagged cases to backlog.json in Application Support.
@@ -43,16 +44,54 @@ final class BacklogStore {
4344
return out.sorted()
4445
}
4546

46-
/// Write a pretty-printed JSON export and return its URL (for Finder reveal).
47-
func export() -> URL? {
47+
/// Flat record for export: image bytes are written as separate PNG files and
48+
/// referenced by filename here (so the JSON stays readable and the screenshots
49+
/// are openable for analysis, instead of base64 blobs).
50+
private struct ExportEntry: Codable {
51+
let id: String
52+
let createdAt: Date
53+
let tags: [String]
54+
let note, stage, provider, model, prompt, hint, input, output: String
55+
let imageFiles: [String]?
56+
}
57+
58+
/// Export the given entries to a timestamped folder in ~/Downloads: a readable
59+
/// JSON plus the attached screenshots as PNG files. Returns the folder URL.
60+
func export(_ items: [BacklogEntry]) -> URL? {
61+
guard !items.isEmpty else { return nil }
62+
let fm = FileManager.default
63+
let downloads = fm.urls(for: .downloadsDirectory, in: .userDomainMask).first
64+
?? URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Downloads")
65+
let fmt = DateFormatter(); fmt.dateFormat = "yyyyMMdd-HHmmss"
66+
let stamp = fmt.string(from: Date())
67+
let name = items.count == 1 ? "backlog_\(items[0].stage)_\(stamp)" : "backlog_export_\(stamp)"
68+
let dir = downloads.appendingPathComponent(name, isDirectory: true)
69+
guard (try? fm.createDirectory(at: dir, withIntermediateDirectories: true)) != nil else { return nil }
70+
71+
var exported: [ExportEntry] = []
72+
for e in items {
73+
var files: [String]?
74+
if let imgs = e.images, !imgs.isEmpty {
75+
var names: [String] = []
76+
for (i, data) in imgs.enumerated() {
77+
let name = "\(e.id)_\(i + 1).png"
78+
try? data.write(to: dir.appendingPathComponent(name))
79+
names.append(name)
80+
}
81+
files = names
82+
}
83+
exported.append(ExportEntry(id: e.id, createdAt: e.createdAt, tags: e.tags, note: e.note,
84+
stage: e.stage, provider: e.provider, model: e.model,
85+
prompt: e.prompt, hint: e.hint, input: e.input, output: e.output,
86+
imageFiles: files))
87+
}
4888
let enc = JSONEncoder()
4989
enc.outputFormatting = [.prettyPrinted, .withoutEscapingSlashes]
5090
enc.dateEncodingStrategy = .iso8601
51-
guard let data = try? enc.encode(entries) else { return nil }
52-
let out = URL(fileURLWithPath:
53-
(Secrets.appSupportDir as NSString).appendingPathComponent("backlog_export.json"))
54-
try? data.write(to: out)
55-
return out
91+
if let data = try? enc.encode(exported) {
92+
try? data.write(to: dir.appendingPathComponent("backlog_export.json"))
93+
}
94+
return dir
5695
}
5796

5897
private func load() {

‎Sources/UI/BacklogView.swift‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ struct BacklogView: View {
88
@EnvironmentObject var app: AppState
99
@State private var stageFilter = "전체"
1010
@State private var tagFilter = "전체"
11+
@State private var selection: Set<String> = [] // checked entry ids to export
1112

1213
private var filtered: [BacklogEntry] {
1314
app.backlog.filter { e in
1415
(stageFilter == "전체" || e.stage == stageFilter)
1516
&& (tagFilter == "전체" || e.tags.contains(tagFilter))
1617
}
1718
}
19+
private var allSelected: Bool {
20+
!filtered.isEmpty && selection.isSuperset(of: Set(filtered.map { $0.id }))
21+
}
1822

1923
var body: some View {
2024
VStack(alignment: .leading, spacing: 8) {
@@ -29,10 +33,18 @@ struct BacklogView: View {
2933
Spacer()
3034
Text("\(filtered.count)건").font(.caption).foregroundStyle(.secondary)
3135
Button {
32-
if let url = app.exportBacklog() { NSWorkspace.shared.activateFileViewerSelecting([url]) }
33-
} label: { Label("내보내기", systemImage: "square.and.arrow.up") }
34-
.controlSize(.small).disabled(app.backlog.isEmpty)
35-
Button { app.clearBacklog() } label: { Label("전체 삭제", systemImage: "trash") }
36+
let all = Set(filtered.map { $0.id })
37+
selection = selection.isSuperset(of: all) ? [] : all
38+
} label: {
39+
Label(allSelected ? "선택 해제" : "전체 선택", systemImage: "checklist")
40+
}
41+
.controlSize(.small).disabled(filtered.isEmpty)
42+
Button {
43+
let items = filtered.filter { selection.contains($0.id) }
44+
if let url = app.exportBacklog(items) { NSWorkspace.shared.activateFileViewerSelecting([url]) }
45+
} label: { Label("내보내기 (\(selection.count))", systemImage: "square.and.arrow.up") }
46+
.controlSize(.small).disabled(selection.isEmpty)
47+
Button { app.clearBacklog(); selection = [] } label: { Label("전체 삭제", systemImage: "trash") }
3648
.controlSize(.small).disabled(app.backlog.isEmpty)
3749
}
3850

@@ -47,7 +59,7 @@ struct BacklogView: View {
4759
.frame(maxWidth: .infinity, maxHeight: .infinity)
4860
} else {
4961
List(filtered) { entry in
50-
BacklogRow(entry: entry)
62+
BacklogRow(entry: entry, selection: $selection)
5163
}
5264
.listStyle(.inset)
5365
}
@@ -64,6 +76,7 @@ struct BacklogView: View {
6476
private struct BacklogRow: View {
6577
@EnvironmentObject var app: AppState
6678
let entry: BacklogEntry
79+
@Binding var selection: Set<String>
6780
@State private var expanded = false
6881
@State private var note = ""
6982
@State private var tagsText = ""
@@ -72,6 +85,23 @@ private struct BacklogRow: View {
7285
DisclosureGroup(isExpanded: $expanded) {
7386
VStack(alignment: .leading, spacing: 8) {
7487
field("입력", entry.input)
88+
if let imgs = entry.images, !imgs.isEmpty {
89+
VStack(alignment: .leading, spacing: 4) {
90+
Text("첨부 이미지 (\(imgs.count))").font(.caption).foregroundStyle(.secondary)
91+
ScrollView(.horizontal, showsIndicators: false) {
92+
HStack(spacing: 8) {
93+
ForEach(Array(imgs.enumerated()), id: \.offset) { _, data in
94+
if let img = NSImage(data: data) {
95+
Image(nsImage: img).resizable().scaledToFill()
96+
.frame(width: 120, height: 80).clipped()
97+
.clipShape(RoundedRectangle(cornerRadius: 6))
98+
.overlay(RoundedRectangle(cornerRadius: 6).stroke(.quaternary))
99+
}
100+
}
101+
}
102+
}
103+
}
104+
}
75105
field("프롬프트", entry.prompt)
76106
if !entry.hint.isEmpty { field("추가 지시", entry.hint) }
77107
field("출력", entry.output)
@@ -91,6 +121,13 @@ private struct BacklogRow: View {
91121
.onAppear { note = entry.note; tagsText = entry.tags.joined(separator: ", ") }
92122
} label: {
93123
HStack(spacing: 6) {
124+
Button {
125+
if selection.contains(entry.id) { selection.remove(entry.id) } else { selection.insert(entry.id) }
126+
} label: {
127+
Image(systemName: selection.contains(entry.id) ? "checkmark.circle.fill" : "circle")
128+
.foregroundStyle(selection.contains(entry.id) ? Color.accentColor : .secondary)
129+
}
130+
.buttonStyle(.plain).help("내보내기 선택")
94131
Text(entry.stage)
95132
.font(.caption2).padding(.horizontal, 6).padding(.vertical, 2)
96133
.background((entry.stage == "해설" ? Color.blue : Color.purple).opacity(0.15))

0 commit comments

Comments
 (0)