@x-otto/plugin-feedback 0.1.0-alpha.1 → 0.3.0-beta.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.
@@ -0,0 +1,1182 @@
1
+ import { uiPositionKey } from "@x-otto/kernel";
2
+ import { getLocale, registerBundle, tIn } from "@x-otto/i18n";
3
+ import { Fragment, createElement, useEffect, useRef, useState } from "react";
4
+ import { Box, Text } from "ink";
5
+ import { TextInput, fullDialogWidth } from "@x-otto/tui";
6
+ import { Dialog, SPACING, Select, dialogTotalRows, resolveFigures, truncateByDisplayWidth, useLayoutTokens, useNavigation, usePanelExpand, useTerminalSize, useTheme, wrapProse } from "@x-otto/tui-plugin";
7
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
+
9
+ //#region src/constants.ts
10
+ const FEEDBACK_OWNER = "feedback";
11
+ const FEEDBACK_PLUGIN_ID = "feedback";
12
+ const FEEDBACK_PLUGIN_VERSION = "0.1.0";
13
+ const FEEDBACK_PANEL_PATH = "/panel/feedback";
14
+ const FEEDBACK_POSITION_ID = "feedback";
15
+ const MERGE_WINDOW_MS = 1e3;
16
+ const MAX_BUNDLE_BYTES = 4 * 1024 * 1024;
17
+ const SURFACE_BYTES_LIMIT = 64 * 1024;
18
+ const SURFACE_TEXT_LIMIT = 2e3;
19
+ const DIAGNOSTICS_BYTES_LIMIT = 512 * 1024;
20
+ const FEEDBACK_HOME_DIRECTORY = "feedback";
21
+ const STAGING_DIRECTORY = "staging";
22
+ const OUTBOX_DIRECTORY = "outbox";
23
+ const SETTING_KEYS = {
24
+ operationLogSize: "feedback.operationLogSize",
25
+ includeDiagnostics: "feedback.includeDiagnostics",
26
+ includeWorkspaceName: "feedback.includeWorkspaceName",
27
+ maxBundleBytes: "feedback.maxBundleBytes",
28
+ publisher: "feedback.publisher",
29
+ serviceUrl: "feedback.service.url",
30
+ serviceAuthProvider: "feedback.service.authProvider"
31
+ };
32
+ const SETTING_ENV = {
33
+ operationLogSize: "OTTO_FEEDBACK_LOG_SIZE",
34
+ serviceUrl: "OTTO_FEEDBACK_SERVICE_URL"
35
+ };
36
+ const FEEDBACK_SERVICE_HOSTS_ENV = "OTTO_FEEDBACK_SERVICE_HOSTS";
37
+ const FEEDBACK_SERVICE_ALLOW_HTTP_ENV = "OTTO_FEEDBACK_SERVICE_ALLOW_HTTP";
38
+ const PUBLISHER_OUTBOX = "outbox";
39
+ const PUBLISHER_SERVICE = "service";
40
+ const LEGACY_PUBLISHER_CODING = "coding";
41
+ const DEFAULT_AUTH_PROVIDER = "uipaas";
42
+ const PUBLIC_URL_HOSTS = ["github.com", "gitlab.com"];
43
+
44
+ //#endregion
45
+ //#region src/scope.ts
46
+ function includesSessionExcerpt(category) {
47
+ return category !== "idea";
48
+ }
49
+
50
+ //#endregion
51
+ //#region src/locales/en.ts
52
+ const en = {
53
+ "feedback::command.summary": "Send feedback with recent operations and environment",
54
+ "feedback::panel.title": "Feedback",
55
+ "feedback::section.consent": "Consent",
56
+ "feedback::section.describe": "Describe",
57
+ "feedback::section.submit": "Submit",
58
+ "feedback::desc.title": "One line summary; Tab moves to the next field",
59
+ "feedback::desc.notes": "Steps, expected vs actual, anything that helps reproduce",
60
+ "feedback::consent.lines": [
61
+ "Packaged: this session excerpt (skipped for an Idea or when no session is open), the most recent operations within the configured window, environment (versions, build id, model, provider and permission mode), diagnostics from this window, and your notes.",
62
+ "Tool output bodies are excluded; arguments keep only key names. The operation log lives in memory and is cleared on restart. Nothing is sent until you confirm the preview.",
63
+ "Known secrets become «redacted» and paths become <workspace>. Check the preview before sending."
64
+ ],
65
+ "feedback::consent.row": "I have read this and agree to build and submit the content described above",
66
+ "feedback::consent.idea": "For an Idea the session excerpt is skipped: only the last operations, environment and diagnostics are packaged.",
67
+ "feedback::consent.noSession": "No session is open: this report will not include a session excerpt.",
68
+ "feedback::field.category": "Type",
69
+ "feedback::field.title": "Title",
70
+ "feedback::field.titlePlaceholder": "one line summary",
71
+ "feedback::field.description": "What happened?",
72
+ "feedback::field.descriptionPlaceholder": "steps, expected vs actual, anything that helps",
73
+ "feedback::field.workspace": "Include the workspace directory name",
74
+ "feedback::action.build": "Build preview",
75
+ "feedback::action.inspect": "View files",
76
+ "feedback::action.publish": "Save locally",
77
+ "feedback::action.issue": "Submit as issue",
78
+ "feedback::desc.previewLocal": "Saves the bundle to ~/.otto/feedback/outbox only; nothing is sent. Switch the channel to Feedback service in Preferences → Feedback to open an issue.",
79
+ "feedback::desc.previewRemote": "Sends the redacted report bundle to the feedback service with your otto login; the service opens the issue. No coding token is needed here.",
80
+ "feedback::desc.previewInspect": "Reads the redacted report, operations and other packaged files",
81
+ "feedback::desc.previewBack": "Returns to the form and discards this preview",
82
+ "feedback::desc.previewDiscard": "Closes the dialog and discards this preview",
83
+ "feedback::action.back": "Back",
84
+ "feedback::action.discard": "Discard preview",
85
+ "feedback::category.bug": "Bug",
86
+ "feedback::category.idea": "Idea",
87
+ "feedback::category.question": "Question",
88
+ "feedback::phase.building": "Building the preview…",
89
+ "feedback::value.on": "on",
90
+ "feedback::value.off": "off",
91
+ "feedback::error.lookupUnknown": "The result is unknown (the request may have reached the service); retrying reconciles first and will not create a duplicate",
92
+ "feedback::phase.cancelHint": "Press Esc again to cancel publishing",
93
+ "feedback::phase.publishing": "Sending… press Esc twice to cancel",
94
+ "feedback::phase.done.local": "Saved locally to",
95
+ "feedback::phase.done.localNote": "Not sent to anyone.",
96
+ "feedback::phase.done.issue": "Issue created",
97
+ "feedback::preview.heading": "Preview",
98
+ "feedback::preview.files": "files",
99
+ "feedback::preview.redactions": "Redactions",
100
+ "feedback::preview.missing": "Missing",
101
+ "feedback::preview.none": "none",
102
+ "feedback::viewer.hint": "Esc back",
103
+ "feedback::hint.next": "next",
104
+ "feedback::hint.select": "select",
105
+ "feedback::hint.open": "open",
106
+ "feedback::hint.save": "save",
107
+ "feedback::hint.toggle": "toggle",
108
+ "feedback::hint.build": "build preview",
109
+ "feedback::hint.run": "run",
110
+ "feedback::hint.discard": "close preview",
111
+ "feedback::hint.nextFile": "next file",
112
+ "feedback::hint.scroll": "scroll",
113
+ "feedback::hint.back": "back",
114
+ "feedback::hint.retry": "retry",
115
+ "feedback::hint.close": "close",
116
+ "feedback::hint.cancel": "Cancel",
117
+ "feedback::error.consentMissing": "Tick the consent box first (Space on the consent row)",
118
+ "feedback::error.titleMissing": "Enter a title first (Enter on the Title row)",
119
+ "feedback::error.bundleTooLarge": "The bundle is over the size limit; turn diagnostics off or trim the notes",
120
+ "feedback::error.buildCancelled": "Building was cancelled",
121
+ "feedback::error.publishCancelled": "Publishing was cancelled before anything was sent",
122
+ "feedback::error.bundleIntegrity": "The bundle failed its integrity check; nothing was kept",
123
+ "feedback::error.publisherUnavailable": "The feedback service is not configured; set the Service URL in Preferences → Feedback",
124
+ "feedback::error.serviceUrlInvalid": "The feedback service URL must be an https address without credentials, query, fragment or path prefix",
125
+ "feedback::error.loginRequired": "Sign in to otto before submitting feedback",
126
+ "feedback::error.unauthorized": "Your otto login has expired; sign in again and retry",
127
+ "feedback::error.idConflict": "This bundle id was already submitted with different content; build a new bundle",
128
+ "feedback::error.rateLimited": "Too many submissions for now; try again later",
129
+ "feedback::error.serviceRejected": "The feedback service rejected the request",
130
+ "feedback::error.serviceBusy": "This feedback is still being submitted; retry in a moment",
131
+ "feedback::error.outboxExists": "A bundle with this id already exists in the outbox",
132
+ "feedback::error.outboxUnwritable": "The outbox directory is not writable",
133
+ "feedback::error.diskFull": "There is no space left to write the bundle",
134
+ "feedback::error.failed": "Could not complete the request",
135
+ "feedback::error.publishFailed": "Could not submit the report",
136
+ "feedback::phase.unknownResult": "The result is unknown: the issue may already exist. Retrying reconciles first and will not create a duplicate."
137
+ };
138
+
139
+ //#endregion
140
+ //#region src/locales/zh.ts
141
+ const zh = {
142
+ "feedback::command.summary": "提交反馈:附带最近操作与环境",
143
+ "feedback::panel.title": "反馈",
144
+ "feedback::section.consent": "同意",
145
+ "feedback::section.describe": "描述",
146
+ "feedback::section.submit": "提交",
147
+ "feedback::desc.title": "一句话概括;Tab 跳到下一个字段",
148
+ "feedback::desc.notes": "复现步骤、期望与实际、任何有助于定位的信息",
149
+ "feedback::consent.lines": [
150
+ "打包内容:本会话摘录(类型为“建议”或没有打开的会话时不含)、配置窗口内的最近操作、环境(版本、构建 ID、模型、provider 与权限模式)、本窗口诊断,以及你填写的说明。",
151
+ "工具输出正文不含,参数只保留键名;操作日志只在内存、重启清空。确认预览前不会发送任何内容。",
152
+ "已知密钥替换为 «redacted»,路径替换为 <workspace>。发送前请在预览里检查。"
153
+ ],
154
+ "feedback::consent.row": "我已阅读并同意按上述范围生成并提交这些内容",
155
+ "feedback::consent.idea": "选择“建议”时不打包会话摘录:只打包最近的操作、环境与诊断。",
156
+ "feedback::consent.noSession": "当前没有打开的会话:本次反馈不包含会话摘录。",
157
+ "feedback::field.category": "类型",
158
+ "feedback::field.title": "标题",
159
+ "feedback::field.titlePlaceholder": "一句话概括",
160
+ "feedback::field.description": "发生了什么?",
161
+ "feedback::field.descriptionPlaceholder": "复现步骤、期望与实际、任何有帮助的信息",
162
+ "feedback::field.workspace": "发送工作区目录名",
163
+ "feedback::action.build": "生成预览",
164
+ "feedback::action.inspect": "查看内容",
165
+ "feedback::action.publish": "保存到本地",
166
+ "feedback::action.issue": "提交为 Issue",
167
+ "feedback::desc.previewLocal": "只把包保存到 ~/.otto/feedback/outbox,不发送任何内容。要在 Preferences → Feedback 把通道改成“反馈服务”才会提交。",
168
+ "feedback::desc.previewRemote": "用当前 otto 登录把脱敏报告包发给反馈服务,由服务创建 Issue;本地无需 coding token。",
169
+ "feedback::desc.previewInspect": "只读查看脱敏后的报告、操作日志与其它打包文件",
170
+ "feedback::desc.previewBack": "返回表单并丢弃本次预览",
171
+ "feedback::desc.previewDiscard": "关闭对话框并丢弃本次预览",
172
+ "feedback::action.back": "返回",
173
+ "feedback::action.discard": "丢弃预览",
174
+ "feedback::category.bug": "问题",
175
+ "feedback::category.idea": "建议",
176
+ "feedback::category.question": "咨询",
177
+ "feedback::phase.building": "正在生成预览…",
178
+ "feedback::value.on": "开",
179
+ "feedback::value.off": "关",
180
+ "feedback::error.lookupUnknown": "结果未知(请求可能已到达反馈服务);重试会先对账,不会重复建单",
181
+ "feedback::phase.cancelHint": "再按一次 Esc 取消发布",
182
+ "feedback::phase.publishing": "正在发送… 按两次 Esc 取消",
183
+ "feedback::phase.done.local": "已保存到本机",
184
+ "feedback::phase.done.localNote": "尚未发送给任何人。",
185
+ "feedback::phase.done.issue": "Issue 已创建",
186
+ "feedback::preview.heading": "预览",
187
+ "feedback::preview.files": "个文件",
188
+ "feedback::preview.redactions": "脱敏命中",
189
+ "feedback::preview.missing": "缺失字段",
190
+ "feedback::preview.none": "无",
191
+ "feedback::viewer.hint": "Esc 返回",
192
+ "feedback::hint.next": "下一个",
193
+ "feedback::hint.select": "选择",
194
+ "feedback::hint.open": "打开",
195
+ "feedback::hint.save": "保存",
196
+ "feedback::hint.toggle": "切换",
197
+ "feedback::hint.build": "生成预览",
198
+ "feedback::hint.run": "执行",
199
+ "feedback::hint.discard": "关闭预览",
200
+ "feedback::hint.nextFile": "下一个文件",
201
+ "feedback::hint.scroll": "滚动",
202
+ "feedback::hint.back": "返回",
203
+ "feedback::hint.retry": "重试",
204
+ "feedback::hint.close": "关闭",
205
+ "feedback::hint.cancel": "取消",
206
+ "feedback::error.consentMissing": "请先勾选同意(在同意行按 Space)",
207
+ "feedback::error.titleMissing": "请先填写标题(在 Title 行按 Enter)",
208
+ "feedback::error.bundleTooLarge": "包超过大小上限:关闭诊断或精简说明后重试",
209
+ "feedback::error.buildCancelled": "构建已取消",
210
+ "feedback::error.publishCancelled": "发布已取消,尚未发送任何内容",
211
+ "feedback::error.bundleIntegrity": "包完整性校验失败,未保留任何内容",
212
+ "feedback::error.publisherUnavailable": "反馈服务未配置;请在 Preferences → Feedback 填写服务地址",
213
+ "feedback::error.serviceUrlInvalid": "反馈服务地址必须是 https,且不能带账号、查询串、锚点或路径前缀",
214
+ "feedback::error.loginRequired": "请先登录 otto 再提交反馈",
215
+ "feedback::error.unauthorized": "otto 登录已过期,请重新登录后重试",
216
+ "feedback::error.idConflict": "这个包 ID 已用不同内容提交过,请重新生成包",
217
+ "feedback::error.rateLimited": "提交过于频繁,请稍后再试",
218
+ "feedback::error.serviceRejected": "反馈服务拒绝了这次请求",
219
+ "feedback::error.serviceBusy": "这份反馈还在提交中,请稍后重试",
220
+ "feedback::error.outboxExists": "outbox 里已有同名包",
221
+ "feedback::error.outboxUnwritable": "outbox 目录不可写",
222
+ "feedback::error.diskFull": "磁盘空间不足,无法写入包",
223
+ "feedback::error.failed": "请求未能完成",
224
+ "feedback::error.publishFailed": "未能提交反馈",
225
+ "feedback::phase.unknownResult": "结果未知:远端可能已建单。重试会先对账,不会重复创建。"
226
+ };
227
+
228
+ //#endregion
229
+ //#region src/locales/index.ts
230
+ const FEEDBACK_BUNDLE_OWNER = "feedback";
231
+ function stringsOf(source) {
232
+ const out = {};
233
+ for (const [key, value] of Object.entries(source)) if (typeof value === "string") out[key] = value;
234
+ return out;
235
+ }
236
+ const feedbackLocales = {
237
+ en: stringsOf(en),
238
+ zh: stringsOf(zh)
239
+ };
240
+ registerBundle(FEEDBACK_BUNDLE_OWNER, feedbackLocales);
241
+ function messagesOf(locale) {
242
+ return locale === "zh" ? zh : en;
243
+ }
244
+ function textOf(key) {
245
+ const value = tIn(getLocale(), key);
246
+ if (value !== key) return value;
247
+ return feedbackLocales.en[key] ?? key;
248
+ }
249
+ function linesOf(messages, key) {
250
+ const value = messages[key];
251
+ return Array.isArray(value) ? value : [];
252
+ }
253
+
254
+ //#endregion
255
+ //#region src/ui/FeedbackDialog/limits.ts
256
+ const MaxDescriptionChars = 4e3;
257
+
258
+ //#endregion
259
+ //#region src/ui/FeedbackDialog/errors.ts
260
+ const MESSAGES = {
261
+ FEEDBACK_CONSENT_REQUIRED: "feedback::error.consentMissing",
262
+ FEEDBACK_CONSENT_SCOPE_MISMATCH: "feedback::error.consentMissing",
263
+ FEEDBACK_TITLE_REQUIRED: "feedback::error.titleMissing",
264
+ FEEDBACK_BUNDLE_TOO_LARGE: "feedback::error.bundleTooLarge",
265
+ FEEDBACK_BUILD_CANCELLED: "feedback::error.buildCancelled",
266
+ FEEDBACK_PUBLISH_CANCELLED: "feedback::error.publishCancelled",
267
+ FEEDBACK_BUNDLE_INTEGRITY: "feedback::error.bundleIntegrity",
268
+ FEEDBACK_ISSUE_LOOKUP_UNKNOWN: "feedback::error.lookupUnknown",
269
+ FEEDBACK_ISSUE_NETWORK: "feedback::error.lookupUnknown",
270
+ FEEDBACK_ISSUE_RECEIPT_UNREADABLE: "feedback::error.lookupUnknown",
271
+ FEEDBACK_ISSUE_URL_MISSING: "feedback::error.lookupUnknown",
272
+ FEEDBACK_ISSUE_RECEIPT_UNWRITABLE: "feedback::error.lookupUnknown",
273
+ FEEDBACK_ARCHIVE_UNREADABLE: "feedback::error.publishFailed",
274
+ FEEDBACK_PUBLISH_FAILED: "feedback::error.publishFailed",
275
+ FEEDBACK_ZIP_ENTRY_INVALID: "feedback::error.failed",
276
+ FEEDBACK_UPLOAD_NETWORK: "feedback::error.lookupUnknown",
277
+ FEEDBACK_PUBLISHER_UNAVAILABLE: "feedback::error.publisherUnavailable",
278
+ FEEDBACK_SERVICE_NOT_CONFIGURED: "feedback::error.publisherUnavailable",
279
+ FEEDBACK_SERVICE_URL_INVALID: "feedback::error.serviceUrlInvalid",
280
+ FEEDBACK_SERVICE_LOGIN_REQUIRED: "feedback::error.loginRequired",
281
+ FEEDBACK_SERVICE_UNAUTHORIZED: "feedback::error.unauthorized",
282
+ FEEDBACK_SERVICE_ID_CONFLICT: "feedback::error.idConflict",
283
+ FEEDBACK_SERVICE_RATE_LIMITED: "feedback::error.rateLimited",
284
+ FEEDBACK_SERVICE_TOO_LARGE: "feedback::error.bundleTooLarge",
285
+ FEEDBACK_SERVICE_BAD_REQUEST: "feedback::error.serviceRejected",
286
+ FEEDBACK_SERVICE_UNSUPPORTED: "feedback::error.serviceRejected",
287
+ FEEDBACK_SERVICE_UPSTREAM_REJECTED: "feedback::error.serviceRejected",
288
+ FEEDBACK_SERVICE_UNKNOWN: "feedback::error.lookupUnknown",
289
+ FEEDBACK_SERVICE_IN_FLIGHT: "feedback::error.serviceBusy",
290
+ FEEDBACK_OUTBOX_EXISTS: "feedback::error.outboxExists",
291
+ FEEDBACK_OUTBOX_UNWRITABLE: "feedback::error.outboxUnwritable",
292
+ FEEDBACK_DISK_FULL: "feedback::error.diskFull"
293
+ };
294
+ function errorMessageOf(code) {
295
+ if (code === void 0) return void 0;
296
+ const key = MESSAGES[code];
297
+ return key === void 0 ? void 0 : textOf(key);
298
+ }
299
+
300
+ //#endregion
301
+ //#region src/ui/BundleList/index.tsx
302
+ function BundleList({ files, redactions, missing, labels, maxFileRows }) {
303
+ const fileBudget = maxFileRows === void 0 ? files.length : Math.max(0, Math.min(files.length, maxFileRows));
304
+ const visibleFiles = files.slice(0, fileBudget);
305
+ const hiddenFileCount = files.length - visibleFiles.length;
306
+ const redactionKeys = Object.keys(redactions).sort();
307
+ const redactionLine = redactionKeys.length === 0 ? labels.none : redactionKeys.map((key) => `${key}=${redactions[key] ?? 0}`).join(" · ");
308
+ return /* @__PURE__ */ jsxs(Box, {
309
+ flexDirection: "column",
310
+ children: [
311
+ /* @__PURE__ */ jsx(Text, {
312
+ bold: true,
313
+ children: `${labels.heading} · ${files.length} ${labels.files}`
314
+ }),
315
+ visibleFiles.map((file) => /* @__PURE__ */ jsx(Text, { children: ` ${file.path} (${file.bytes} B)` }, file.path)),
316
+ hiddenFileCount === 0 ? null : /* @__PURE__ */ jsx(Text, {
317
+ dimColor: true,
318
+ children: ` … +${hiddenFileCount} ${labels.files}`
319
+ }),
320
+ /* @__PURE__ */ jsx(Text, {
321
+ dimColor: true,
322
+ children: `${labels.redactions}: ${redactionLine}`
323
+ }),
324
+ /* @__PURE__ */ jsx(Text, {
325
+ dimColor: true,
326
+ children: `${labels.missing}: ${missing.length === 0 ? labels.none : missing.join(", ")}`
327
+ })
328
+ ]
329
+ });
330
+ }
331
+
332
+ //#endregion
333
+ //#region src/ui/ContentViewer/index.tsx
334
+ function ContentViewer({ path, text, height, scroll, hint }) {
335
+ const lines = text.split("\n");
336
+ const start = Math.max(0, Math.min(scroll, Math.max(0, lines.length - 1)));
337
+ const visible = lines.slice(start, start + Math.max(1, height));
338
+ return /* @__PURE__ */ jsxs(Box, {
339
+ flexDirection: "column",
340
+ children: [
341
+ /* @__PURE__ */ jsx(Text, {
342
+ bold: true,
343
+ children: `${path} · ${start + 1}-${start + visible.length}/${lines.length}`
344
+ }),
345
+ visible.map((line, index) => /* @__PURE__ */ jsx(Text, {
346
+ wrap: "truncate-end",
347
+ children: line === "" ? " " : line
348
+ }, `${start}-${index}`)),
349
+ /* @__PURE__ */ jsx(Text, {
350
+ dimColor: true,
351
+ children: hint
352
+ })
353
+ ]
354
+ });
355
+ }
356
+
357
+ //#endregion
358
+ //#region src/types.ts
359
+ const CONSENT_POLICY_VERSION = "feedback-consent-v1";
360
+
361
+ //#endregion
362
+ //#region src/ui/FeedbackDialog/state.ts
363
+ const EDIT_ROWS = [
364
+ "consent",
365
+ "category",
366
+ "title",
367
+ "notes",
368
+ "build",
369
+ "workspace"
370
+ ];
371
+ const PREVIEW_ACTIONS = [
372
+ "publish",
373
+ "inspect",
374
+ "back",
375
+ "close"
376
+ ];
377
+ function nextRow(rows, current, direction) {
378
+ const index = rows.indexOf(current);
379
+ if (index === -1) return rows[0] ?? current;
380
+ return rows[(index + direction + rows.length) % rows.length] ?? current;
381
+ }
382
+ function nextAction(current, direction) {
383
+ return PREVIEW_ACTIONS[(PREVIEW_ACTIONS.indexOf(current) + direction + PREVIEW_ACTIONS.length) % PREVIEW_ACTIONS.length] ?? current;
384
+ }
385
+ function consentScope(input) {
386
+ return [
387
+ ...includesSessionExcerpt(input.category) ? ["session"] : [],
388
+ "operations",
389
+ "environment",
390
+ ...input.diagnostics ? ["diagnostics"] : [],
391
+ ...input.workspaceName ? ["workspace-name"] : []
392
+ ];
393
+ }
394
+ function acceptedConsent(acceptedAt, scope) {
395
+ return {
396
+ accepted: true,
397
+ policy: CONSENT_POLICY_VERSION,
398
+ acceptedAt,
399
+ scope
400
+ };
401
+ }
402
+ function canBuild(draft) {
403
+ return draft.consent.accepted === true && draft.consent.policy === "feedback-consent-v1" && draft.consent.acceptedAt >= draft.openedAt && draft.title.trim().length > 0;
404
+ }
405
+ function draftOf(input) {
406
+ return {
407
+ openId: input.openId,
408
+ openedAt: input.openedAt,
409
+ category: input.category,
410
+ title: input.title,
411
+ description: input.description,
412
+ consent: input.consent,
413
+ includeWorkspaceName: input.includeWorkspaceName,
414
+ ...input.sessionId === void 0 ? {} : { sessionId: input.sessionId }
415
+ };
416
+ }
417
+ function errorCodeOf(error) {
418
+ const message = error instanceof Error ? error.message : String(error);
419
+ const match = /^FEEDBACK_[A-Z_]+/.exec(message);
420
+ return match === null ? "FEEDBACK_BUILD_FAILED" : match[0];
421
+ }
422
+
423
+ //#endregion
424
+ //#region src/ui/FeedbackDialog/index.tsx
425
+ const CATEGORIES = [
426
+ {
427
+ id: "bug",
428
+ key: "feedback::category.bug"
429
+ },
430
+ {
431
+ id: "idea",
432
+ key: "feedback::category.idea"
433
+ },
434
+ {
435
+ id: "question",
436
+ key: "feedback::category.question"
437
+ }
438
+ ];
439
+ const FALLBACK_CATEGORY = {
440
+ id: "bug",
441
+ key: "feedback::category.bug"
442
+ };
443
+ const CONSENT_TOGGLE_DEBOUNCE_MS = 150;
444
+ const VIEWER_PAGE = 6;
445
+ function FeedbackDialog({ ports }) {
446
+ const messages = messagesOf(ports.locale());
447
+ const message = (key) => textOf(key);
448
+ const tokens = useLayoutTokens();
449
+ const { colors } = useTheme();
450
+ const fig = resolveFigures();
451
+ const { rows, columns } = useTerminalSize();
452
+ const { maxRows } = usePanelExpand(rows, "panelRows", void 0, { cap: "roomy" });
453
+ const { goBack } = useNavigation();
454
+ const openedRef = useRef({
455
+ id: `feedback-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`,
456
+ at: Date.now()
457
+ });
458
+ const mountedRef = useRef(true);
459
+ const buildControllerRef = useRef(void 0);
460
+ const publishRunRef = useRef(0);
461
+ const buildActiveRef = useRef(false);
462
+ const publishActiveRef = useRef(false);
463
+ const publishControllerRef = useRef(void 0);
464
+ const cancelArmedRef = useRef(0);
465
+ const lastToggleRef = useRef(0);
466
+ const consentRef = useRef(false);
467
+ const [phase, setPhase] = useState("editing");
468
+ const [focus, setFocus] = useState("title");
469
+ const [action, setAction] = useState("publish");
470
+ const [categoryIndex, setCategoryIndex] = useState(0);
471
+ const [title, setTitle] = useState("");
472
+ const [notes, setNotes] = useState("");
473
+ const [consent, setConsent] = useState(false);
474
+ const [consentAcceptedAt, setConsentAcceptedAt] = useState(void 0);
475
+ const [includeWorkspace, setIncludeWorkspace] = useState(ports.includeWorkspaceName());
476
+ const [bundle, setBundle] = useState(void 0);
477
+ const [errorCode, setErrorCode] = useState(void 0);
478
+ const [notice, setNotice] = useState(void 0);
479
+ const [doneKind, setDoneKind] = useState("stored");
480
+ const [viewerIndex, setViewerIndex] = useState(0);
481
+ const [subPage, setSubPage] = useState(void 0);
482
+ const [scroll, setScroll] = useState(0);
483
+ const selectedCategory = CATEGORIES[categoryIndex] ?? FALLBACK_CATEGORY;
484
+ useEffect(() => {
485
+ mountedRef.current = true;
486
+ return () => {
487
+ mountedRef.current = false;
488
+ buildControllerRef.current?.abort();
489
+ };
490
+ }, []);
491
+ const currentConsent = consentAcceptedAt === void 0 ? { accepted: false } : acceptedConsent(consentAcceptedAt, consentScope({
492
+ category: selectedCategory.id,
493
+ diagnostics: ports.includeDiagnostics(),
494
+ workspaceName: includeWorkspace
495
+ }));
496
+ const currentDraft = () => draftOf({
497
+ openId: openedRef.current.id,
498
+ openedAt: openedRef.current.at,
499
+ category: selectedCategory.id,
500
+ title,
501
+ description: notes,
502
+ consent: currentConsent,
503
+ includeWorkspaceName: includeWorkspace,
504
+ ...ports.sessionId() === void 0 ? {} : { sessionId: ports.sessionId() }
505
+ });
506
+ const discardBundle = (next = "editing") => {
507
+ const existing = bundle;
508
+ setBundle(void 0);
509
+ setPhase(next);
510
+ if (existing !== void 0) ports.discard(existing);
511
+ };
512
+ const invalidate = () => {
513
+ if (phase === "editing") return;
514
+ discardBundle("editing");
515
+ };
516
+ const invalidateConsent = () => {
517
+ consentRef.current = false;
518
+ setConsent(false);
519
+ setConsentAcceptedAt(void 0);
520
+ };
521
+ const toggleConsent = () => {
522
+ const now = Date.now();
523
+ if (now - lastToggleRef.current < CONSENT_TOGGLE_DEBOUNCE_MS) return;
524
+ lastToggleRef.current = now;
525
+ consentRef.current = !consentRef.current;
526
+ setConsent(consentRef.current);
527
+ setConsentAcceptedAt(consentRef.current ? now : void 0);
528
+ invalidate();
529
+ };
530
+ const build = () => {
531
+ if (buildActiveRef.current) return;
532
+ const draft = currentDraft();
533
+ if (!canBuild(draft)) {
534
+ if (draft.consent.accepted !== true || draft.consent.acceptedAt < draft.openedAt) {
535
+ setErrorCode("FEEDBACK_CONSENT_REQUIRED");
536
+ setFocus("consent");
537
+ return;
538
+ }
539
+ setErrorCode("FEEDBACK_TITLE_REQUIRED");
540
+ setFocus("title");
541
+ return;
542
+ }
543
+ setErrorCode(void 0);
544
+ setNotice(void 0);
545
+ setPhase("building");
546
+ buildActiveRef.current = true;
547
+ const controller = new AbortController();
548
+ buildControllerRef.current = controller;
549
+ ports.build(draft, controller.signal).then((next) => {
550
+ buildActiveRef.current = false;
551
+ if (!mountedRef.current || controller.signal.aborted) {
552
+ ports.discard(next);
553
+ return;
554
+ }
555
+ setBundle(next);
556
+ setAction("publish");
557
+ setPhase("preview");
558
+ }).catch((error) => {
559
+ buildActiveRef.current = false;
560
+ if (!mountedRef.current || controller.signal.aborted) return;
561
+ setErrorCode(errorCodeOf(error));
562
+ setPhase("failed");
563
+ });
564
+ };
565
+ const publish = () => {
566
+ if (bundle === void 0 || publishActiveRef.current) return;
567
+ const run = publishRunRef.current + 1;
568
+ publishRunRef.current = run;
569
+ setPhase("publishing");
570
+ publishActiveRef.current = true;
571
+ cancelArmedRef.current = 0;
572
+ const controller = new AbortController();
573
+ publishControllerRef.current = controller;
574
+ setNotice(message("feedback::phase.publishing"));
575
+ const draft = currentDraft();
576
+ ports.publish(bundle, draft, controller.signal).then((outcome) => {
577
+ publishActiveRef.current = false;
578
+ publishControllerRef.current = void 0;
579
+ if (!mountedRef.current || publishRunRef.current !== run) return;
580
+ if (controller.signal.aborted && outcome.kind === "failed" && outcome.code !== "FEEDBACK_PUBLISH_CANCELLED") {
581
+ setErrorCode(outcome.code);
582
+ setNotice(outcome.message);
583
+ setPhase("failed");
584
+ return;
585
+ }
586
+ if (controller.signal.aborted && outcome.kind !== "unknown" && outcome.kind !== "issue") {
587
+ setErrorCode("FEEDBACK_PUBLISH_CANCELLED");
588
+ setPhase("failed");
589
+ return;
590
+ }
591
+ if (outcome.kind === "stored") {
592
+ setDoneKind("stored");
593
+ setNotice(outcome.path);
594
+ setPhase("done");
595
+ return;
596
+ }
597
+ if (outcome.kind === "issue") {
598
+ setDoneKind("issue");
599
+ setNotice(outcome.url);
600
+ setPhase("done");
601
+ return;
602
+ }
603
+ setErrorCode(outcome.code);
604
+ setNotice(outcome.kind === "unknown" ? `${message("feedback::phase.unknownResult")} ${outcome.message}` : outcome.message);
605
+ setPhase("failed");
606
+ }).catch((error) => {
607
+ publishActiveRef.current = false;
608
+ publishControllerRef.current = void 0;
609
+ if (!mountedRef.current || publishRunRef.current !== run) return;
610
+ if (controller.signal.aborted) {
611
+ setErrorCode("FEEDBACK_PUBLISH_CANCELLED");
612
+ setPhase("failed");
613
+ return;
614
+ }
615
+ const code = errorCodeOf(error);
616
+ setErrorCode(code === "FEEDBACK_BUILD_FAILED" ? "FEEDBACK_PUBLISH_FAILED" : code);
617
+ setPhase("failed");
618
+ });
619
+ };
620
+ const close = () => {
621
+ if (bundle !== void 0) ports.discard(bundle);
622
+ goBack();
623
+ };
624
+ const draftValue = subPage === "title" ? title : notes;
625
+ const draftLimit = subPage === "title" ? 120 : MaxDescriptionChars;
626
+ const setDraftValue = (value) => {
627
+ if (subPage === "title") setTitle(value);
628
+ else setNotes(value);
629
+ invalidate();
630
+ };
631
+ const handlePanelKeys = (event) => {
632
+ if (subPage !== void 0) {
633
+ if (event.key.escape) {
634
+ setSubPage(void 0);
635
+ return true;
636
+ }
637
+ return;
638
+ }
639
+ if (phase === "building") {
640
+ if (event.key.escape) {
641
+ buildControllerRef.current?.abort();
642
+ buildActiveRef.current = false;
643
+ setErrorCode("FEEDBACK_BUILD_CANCELLED");
644
+ setPhase("editing");
645
+ return true;
646
+ }
647
+ return;
648
+ }
649
+ if (phase === "publishing") {
650
+ if (event.key.escape) {
651
+ const now = Date.now();
652
+ if (now - cancelArmedRef.current < 3e3) {
653
+ cancelArmedRef.current = 0;
654
+ publishControllerRef.current?.abort();
655
+ return true;
656
+ }
657
+ cancelArmedRef.current = now;
658
+ setNotice(message("feedback::phase.cancelHint"));
659
+ return true;
660
+ }
661
+ return;
662
+ }
663
+ if (event.key.escape) {
664
+ if (phase === "inspecting") {
665
+ setPhase("preview");
666
+ return true;
667
+ }
668
+ if (phase === "preview") {
669
+ discardBundle("editing");
670
+ return true;
671
+ }
672
+ close();
673
+ return true;
674
+ }
675
+ if (phase === "inspecting") {
676
+ if (event.key.tab) {
677
+ const files = inspectableFiles(bundle);
678
+ if (files.length > 0) setViewerIndex((viewerIndex + 1) % files.length);
679
+ setScroll(0);
680
+ return true;
681
+ }
682
+ if (event.key.upArrow) {
683
+ setScroll(Math.max(0, scroll - 1));
684
+ return true;
685
+ }
686
+ if (event.key.downArrow) {
687
+ setScroll(scroll + 1);
688
+ return true;
689
+ }
690
+ if (event.key.pageUp) {
691
+ setScroll(Math.max(0, scroll - VIEWER_PAGE));
692
+ return true;
693
+ }
694
+ if (event.key.pageDown) {
695
+ setScroll(scroll + VIEWER_PAGE);
696
+ return true;
697
+ }
698
+ return;
699
+ }
700
+ if (phase === "preview") {
701
+ if (event.key.tab) {
702
+ setAction(nextAction(action, event.key.shift ? -1 : 1));
703
+ return true;
704
+ }
705
+ if (event.key.upArrow || event.key.downArrow) {
706
+ setAction(nextAction(action, event.key.upArrow ? -1 : 1));
707
+ return true;
708
+ }
709
+ if (event.key.return) {
710
+ runPreviewAction(action);
711
+ return true;
712
+ }
713
+ return;
714
+ }
715
+ if (phase === "done") {
716
+ if (event.key.return) {
717
+ close();
718
+ return true;
719
+ }
720
+ return;
721
+ }
722
+ if (phase === "failed") {
723
+ if (event.key.return) {
724
+ if (bundle === void 0) build();
725
+ else publish();
726
+ return true;
727
+ }
728
+ return;
729
+ }
730
+ if (event.key.tab) {
731
+ setFocus(nextRow(EDIT_ROWS, focus, event.key.shift ? -1 : 1));
732
+ return true;
733
+ }
734
+ if (event.key.upArrow || event.key.downArrow) {
735
+ setFocus(nextRow(EDIT_ROWS, focus, event.key.upArrow ? -1 : 1));
736
+ return true;
737
+ }
738
+ if (event.key.leftArrow || event.key.rightArrow) {
739
+ if (focus === "category") {
740
+ setCategoryIndex((categoryIndex + (event.key.leftArrow ? -1 : 1) + CATEGORIES.length) % CATEGORIES.length);
741
+ invalidateConsent();
742
+ invalidate();
743
+ return true;
744
+ }
745
+ return;
746
+ }
747
+ if (event.key.ctrl === true && event.input === "w") {
748
+ setIncludeWorkspace((previous) => !previous);
749
+ invalidateConsent();
750
+ invalidate();
751
+ return true;
752
+ }
753
+ if (event.input === " ") {
754
+ if (focus === "consent") {
755
+ toggleConsent();
756
+ return true;
757
+ }
758
+ if (focus === "category") {
759
+ setCategoryIndex((categoryIndex + 1) % CATEGORIES.length);
760
+ invalidateConsent();
761
+ invalidate();
762
+ return true;
763
+ }
764
+ if (focus === "workspace") {
765
+ setIncludeWorkspace((previous) => !previous);
766
+ invalidateConsent();
767
+ invalidate();
768
+ return true;
769
+ }
770
+ return;
771
+ }
772
+ if (event.key.return) {
773
+ if (focus === "build") {
774
+ build();
775
+ return true;
776
+ }
777
+ if (focus === "title" || focus === "notes") {
778
+ setSubPage(focus);
779
+ return true;
780
+ }
781
+ if (focus === "workspace") {
782
+ setIncludeWorkspace((previous) => !previous);
783
+ invalidateConsent();
784
+ invalidate();
785
+ return true;
786
+ }
787
+ return;
788
+ }
789
+ };
790
+ const rowOpensOnEnter = focus === "title" || focus === "notes" || focus === "build";
791
+ const rowTogglesOnSpace = focus === "consent" || focus === "category" || focus === "workspace";
792
+ const width = Math.min(columns, Math.max(tokens.layout.gateDialogMinWidth, fullDialogWidth(columns)));
793
+ const consentLines = linesOf(messages, "feedback::consent.lines").slice(0, 3);
794
+ const consentNotice = includesSessionExcerpt(selectedCategory.id) ? ports.sessionId() === void 0 ? message("feedback::consent.noSession") : void 0 : message("feedback::consent.idea");
795
+ const viewerFile = inspectableFiles(bundle)[viewerIndex];
796
+ const inspectRows = Math.max(4, Math.min(rows - 8, 14));
797
+ const innerColumns = Math.max(1, width - 4);
798
+ const textRows = (text) => Math.max(1, wrapProse(text, innerColumns).length);
799
+ const indentedRows = (text) => wrapProse(text, Math.max(1, innerColumns - 2)).map((row) => ` ${row}`);
800
+ const categoryLabel = message(selectedCategory.key);
801
+ const rowPrefix = (active) => `${active ? fig.pointer : " "} `;
802
+ const previewOptions = [
803
+ {
804
+ name: ports.publisherMode() === "outbox" ? message("feedback::action.publish") : message("feedback::action.issue"),
805
+ value: "publish"
806
+ },
807
+ {
808
+ name: message("feedback::action.inspect"),
809
+ value: "inspect"
810
+ },
811
+ {
812
+ name: message("feedback::action.back"),
813
+ value: "back"
814
+ },
815
+ {
816
+ name: message("feedback::action.discard"),
817
+ value: "close"
818
+ }
819
+ ];
820
+ const actionOf = (option) => option.value ?? "publish";
821
+ const previewDescription = (value) => value === "publish" ? ports.publisherMode() === "outbox" ? message("feedback::desc.previewLocal") : message("feedback::desc.previewRemote") : value === "inspect" ? message("feedback::desc.previewInspect") : value === "back" ? message("feedback::desc.previewBack") : message("feedback::desc.previewDiscard");
822
+ const runPreviewAction = (value) => {
823
+ if (value === "publish") publish();
824
+ else if (value === "inspect") {
825
+ setViewerIndex(0);
826
+ setScroll(0);
827
+ setPhase("inspecting");
828
+ } else if (value === "back") discardBundle("editing");
829
+ else close();
830
+ };
831
+ const editingBlocks = [
832
+ {
833
+ key: "consent-header",
834
+ node: /* @__PURE__ */ jsx(Text, {
835
+ color: colors.muted,
836
+ children: message("feedback::section.consent").toUpperCase()
837
+ })
838
+ },
839
+ ...consentLines.flatMap((line, index) => indentedRows(line).map((row, rowIndex) => ({
840
+ key: `consent-line-${index}-${rowIndex}`,
841
+ node: /* @__PURE__ */ jsx(Text, {
842
+ color: colors.muted,
843
+ wrap: "truncate-end",
844
+ children: row
845
+ })
846
+ }))),
847
+ ...consentNotice === void 0 ? [] : indentedRows(consentNotice).map((row, rowIndex) => ({
848
+ key: `consent-notice-${rowIndex}`,
849
+ node: /* @__PURE__ */ jsx(Text, {
850
+ color: colors.muted,
851
+ wrap: "truncate-end",
852
+ children: row
853
+ })
854
+ })),
855
+ {
856
+ key: "consent-row",
857
+ focus: "consent",
858
+ rows: textRows(`${rowPrefix(focus === "consent")}[ ] ${message("feedback::consent.row")}`),
859
+ node: /* @__PURE__ */ jsx(Text, {
860
+ color: focus === "consent" ? colors.selectedText : void 0,
861
+ bold: focus === "consent",
862
+ children: `${rowPrefix(focus === "consent")}[${consent ? "x" : " "}] ${message("feedback::consent.row")}`
863
+ })
864
+ },
865
+ ...errorCode === void 0 ? [] : [{
866
+ key: "consent-error",
867
+ rows: textRows(`${errorMessageOf(errorCode) ?? message("feedback::error.failed")} (${errorCode})`),
868
+ node: /* @__PURE__ */ jsx(Text, {
869
+ color: colors.error,
870
+ children: `${errorMessageOf(errorCode) ?? message("feedback::error.failed")} (${errorCode})`
871
+ })
872
+ }],
873
+ {
874
+ key: "describe-gap",
875
+ node: /* @__PURE__ */ jsx(Box, { height: SPACING.tight })
876
+ },
877
+ {
878
+ key: "describe-header",
879
+ node: /* @__PURE__ */ jsx(Text, {
880
+ color: colors.muted,
881
+ children: message("feedback::section.describe").toUpperCase()
882
+ })
883
+ },
884
+ {
885
+ key: "category-row",
886
+ focus: "category",
887
+ node: /* @__PURE__ */ jsx(Text, {
888
+ color: focus === "category" ? colors.selectedText : void 0,
889
+ bold: focus === "category",
890
+ children: `${rowPrefix(focus === "category")}${message("feedback::field.category")}: ${fig.triangleLeft} ${categoryLabel} ${fig.triangleRight}`
891
+ })
892
+ },
893
+ {
894
+ key: "title-row",
895
+ focus: "title",
896
+ node: /* @__PURE__ */ jsx(Text, {
897
+ color: focus === "title" ? colors.selectedText : void 0,
898
+ bold: focus === "title",
899
+ children: `${rowPrefix(focus === "title")}${message("feedback::field.title")} ${truncateByDisplayWidth(title === "" ? message("feedback::field.titlePlaceholder") : title, Math.max(8, columns - 24))}`
900
+ })
901
+ },
902
+ {
903
+ key: "notes-row",
904
+ focus: "notes",
905
+ node: /* @__PURE__ */ jsx(Text, {
906
+ color: focus === "notes" ? colors.selectedText : void 0,
907
+ bold: focus === "notes",
908
+ children: `${rowPrefix(focus === "notes")}${message("feedback::field.description")}`
909
+ })
910
+ },
911
+ {
912
+ key: "notes-preview",
913
+ node: /* @__PURE__ */ jsx(Text, {
914
+ color: colors.muted,
915
+ children: ` ${truncateByDisplayWidth(notes.trim() === "" ? message("feedback::field.descriptionPlaceholder") : notes.split("\n")[0] ?? "", Math.max(8, columns - 24))}`
916
+ })
917
+ },
918
+ {
919
+ key: "submit-gap",
920
+ node: /* @__PURE__ */ jsx(Box, { height: SPACING.tight })
921
+ },
922
+ {
923
+ key: "submit-header",
924
+ node: /* @__PURE__ */ jsx(Text, {
925
+ color: colors.muted,
926
+ children: message("feedback::section.submit").toUpperCase()
927
+ })
928
+ },
929
+ {
930
+ key: "build-row",
931
+ focus: "build",
932
+ node: /* @__PURE__ */ jsx(Text, {
933
+ color: focus === "build" ? colors.selectedText : void 0,
934
+ bold: focus === "build",
935
+ children: `${rowPrefix(focus === "build")}[ ${message("feedback::action.build")} ]`
936
+ })
937
+ },
938
+ {
939
+ key: "workspace-row",
940
+ focus: "workspace",
941
+ node: /* @__PURE__ */ jsx(Text, {
942
+ color: focus === "workspace" ? colors.selectedText : void 0,
943
+ bold: focus === "workspace",
944
+ children: `${rowPrefix(focus === "workspace")}${message("feedback::field.workspace")}: ${includeWorkspace ? message("feedback::value.on") : message("feedback::value.off")} (^W)`
945
+ })
946
+ }
947
+ ];
948
+ const editingRows = editingBlocks.map((block) => block.node);
949
+ const editingViewportRows = Math.max(4, maxRows - tokens.layout.dialogChromeRows);
950
+ const editingFocusIndex = Math.max(0, editingBlocks.findIndex((block) => block.focus !== void 0 && block.focus === focus));
951
+ const editingWindowStart = Math.max(0, Math.min(editingRows.length - editingViewportRows, editingFocusIndex - Math.floor(editingViewportRows / 2)));
952
+ const previewFileRows = Math.max(1, maxRows - tokens.layout.dialogChromeRows - 9);
953
+ const bodyRowsOf = () => {
954
+ if (phase === "editing" && subPage !== void 0) {
955
+ const hint = subPage === "title" ? message("feedback::desc.title") : message("feedback::desc.notes");
956
+ return 1 + SPACING.tight + textRows(hint);
957
+ }
958
+ if (phase === "editing") return editingBlocks.slice(editingWindowStart, editingWindowStart + editingViewportRows).reduce((sum, block) => sum + (block.rows ?? 1), 0);
959
+ if (phase === "preview" && bundle !== void 0) {
960
+ const visibleFiles = Math.min(bundle.files.length, previewFileRows);
961
+ const hiddenRows = visibleFiles < bundle.files.length ? 1 : 0;
962
+ const redactionText = Object.keys(bundle.redactions).map((key) => `${key}=${bundle.redactions[key] ?? 0}`).join(" · ");
963
+ const redactionRows = textRows(`${message("feedback::preview.redactions")}: ${redactionText || message("feedback::preview.none")}`);
964
+ const missingRows = textRows(`${message("feedback::preview.missing")}: ${bundle.missing.join(", ") || message("feedback::preview.none")}`);
965
+ const descriptionRows = textRows(previewDescription(action));
966
+ return 1 + visibleFiles + hiddenRows + redactionRows + missingRows + SPACING.tight + previewOptions.length + SPACING.tight + descriptionRows;
967
+ }
968
+ if (phase === "inspecting" && viewerFile !== void 0) {
969
+ const lineCount = (viewerFile.text ?? "").split("\n").length;
970
+ return 2 + Math.min(lineCount, inspectRows);
971
+ }
972
+ if (phase === "publishing") return 1 + (notice === void 0 ? 0 : textRows(notice));
973
+ if (phase === "done") {
974
+ const noteRows = doneKind === "stored" ? textRows(message("feedback::phase.done.localNote")) : 0;
975
+ return 1 + textRows(notice ?? "") + noteRows;
976
+ }
977
+ if (phase === "failed") {
978
+ const failure = `${errorMessageOf(errorCode) ?? message("feedback::error.failed")} (${errorCode ?? "unknown"})`;
979
+ const hint = `${message("feedback::hint.retry")} · Esc ${message("feedback::hint.close")}`;
980
+ return textRows(failure) + (notice === void 0 ? 0 : textRows(notice)) + textRows(hint);
981
+ }
982
+ return 1;
983
+ };
984
+ const bodyRows = bodyRowsOf();
985
+ const footerItems = subPage !== void 0 ? [{
986
+ key: "⏎",
987
+ label: message("feedback::hint.save")
988
+ }, {
989
+ key: "Esc",
990
+ label: message("feedback::hint.back")
991
+ }] : phase === "editing" ? [
992
+ {
993
+ key: `${fig.arrowUp}${fig.arrowDown}`,
994
+ label: message("feedback::hint.select")
995
+ },
996
+ ...rowOpensOnEnter ? [{
997
+ key: "⏎",
998
+ label: focus === "build" ? message("feedback::hint.build") : message("feedback::hint.open")
999
+ }] : [],
1000
+ ...rowTogglesOnSpace ? [{
1001
+ key: "Space",
1002
+ label: message("feedback::hint.toggle")
1003
+ }] : [],
1004
+ {
1005
+ key: "Esc",
1006
+ label: message("feedback::hint.close")
1007
+ }
1008
+ ] : phase === "preview" ? [
1009
+ {
1010
+ key: "⇥",
1011
+ label: message("feedback::hint.next")
1012
+ },
1013
+ {
1014
+ key: "⏎",
1015
+ label: message("feedback::hint.run")
1016
+ },
1017
+ {
1018
+ key: "Esc",
1019
+ label: message("feedback::hint.discard")
1020
+ }
1021
+ ] : phase === "inspecting" ? [
1022
+ {
1023
+ key: "⇥",
1024
+ label: message("feedback::hint.nextFile")
1025
+ },
1026
+ {
1027
+ key: `${fig.arrowUp}${fig.arrowDown}`,
1028
+ label: message("feedback::hint.scroll")
1029
+ },
1030
+ {
1031
+ key: "Esc",
1032
+ label: message("feedback::hint.back")
1033
+ }
1034
+ ] : phase === "failed" ? [{
1035
+ key: "⏎",
1036
+ label: message("feedback::hint.retry")
1037
+ }, {
1038
+ key: "Esc",
1039
+ label: message("feedback::hint.close")
1040
+ }] : phase === "building" || phase === "publishing" ? [{
1041
+ key: "Esc",
1042
+ label: message("feedback::hint.cancel")
1043
+ }] : [{
1044
+ key: "Esc",
1045
+ label: message("feedback::hint.close")
1046
+ }];
1047
+ return /* @__PURE__ */ jsx(Dialog.Root, {
1048
+ defaultOpen: true,
1049
+ closeOnEscape: false,
1050
+ children: /* @__PURE__ */ jsx(Dialog.Content, {
1051
+ title: subPage === void 0 ? message("feedback::panel.title") : `${message("feedback::panel.title")} / ${subPage === "title" ? message("feedback::field.title") : message("feedback::field.description")}`,
1052
+ width,
1053
+ maxHeight: maxRows,
1054
+ declaredRows: dialogTotalRows(bodyRows, maxRows, void 0, tokens),
1055
+ footer: footerItems,
1056
+ keyHandler: handlePanelKeys,
1057
+ children: /* @__PURE__ */ jsxs(Box, {
1058
+ flexDirection: "column",
1059
+ children: [
1060
+ phase === "editing" && subPage !== void 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
1061
+ /* @__PURE__ */ jsx(TextInput, {
1062
+ multiline: false,
1063
+ value: draftValue,
1064
+ prefix: ">",
1065
+ maxLength: draftLimit,
1066
+ width: Math.max(20, width - 4),
1067
+ focused: true,
1068
+ autoFocus: true,
1069
+ placeholder: subPage === "title" ? message("feedback::field.titlePlaceholder") : message("feedback::field.descriptionPlaceholder"),
1070
+ onInput: (value) => setDraftValue(value),
1071
+ onKeyDown: (_input, key) => {
1072
+ if (key.escape || key.return) {
1073
+ setSubPage(void 0);
1074
+ return true;
1075
+ }
1076
+ return false;
1077
+ }
1078
+ }),
1079
+ /* @__PURE__ */ jsx(Box, { height: SPACING.tight }),
1080
+ /* @__PURE__ */ jsx(Text, {
1081
+ color: colors.muted,
1082
+ children: subPage === "title" ? message("feedback::desc.title") : message("feedback::desc.notes")
1083
+ })
1084
+ ] }) : null,
1085
+ phase === "editing" && subPage === void 0 ? editingRows.slice(editingWindowStart, editingWindowStart + editingViewportRows).map((node, index) => /* @__PURE__ */ jsx(Fragment, { children: node }, editingWindowStart + index)) : null,
1086
+ phase === "building" ? /* @__PURE__ */ jsx(Text, { children: message("feedback::phase.building") }) : null,
1087
+ phase === "preview" && bundle !== void 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
1088
+ /* @__PURE__ */ jsx(BundleList, {
1089
+ maxFileRows: previewFileRows,
1090
+ files: bundle.files,
1091
+ redactions: bundle.redactions,
1092
+ missing: bundle.missing,
1093
+ labels: {
1094
+ heading: message("feedback::preview.heading"),
1095
+ files: message("feedback::preview.files"),
1096
+ redactions: message("feedback::preview.redactions"),
1097
+ missing: message("feedback::preview.missing"),
1098
+ none: message("feedback::preview.none")
1099
+ }
1100
+ }),
1101
+ /* @__PURE__ */ jsx(Box, { height: SPACING.tight }),
1102
+ /* @__PURE__ */ jsx(Select, {
1103
+ options: previewOptions,
1104
+ selectedIndex: Math.max(0, PREVIEW_ACTIONS.indexOf(action)),
1105
+ activeDescendant: true,
1106
+ focused: true,
1107
+ descriptionOf: (option) => previewDescription(actionOf(option)),
1108
+ onSelectionChange: (_index, option) => {
1109
+ if (option !== null) setAction(actionOf(option));
1110
+ },
1111
+ onSelect: (_index, option) => runPreviewAction(actionOf(option))
1112
+ })
1113
+ ] }) : null,
1114
+ phase === "inspecting" && viewerFile !== void 0 ? /* @__PURE__ */ jsx(ContentViewer, {
1115
+ path: viewerFile.path,
1116
+ text: viewerFile.text ?? "",
1117
+ height: inspectRows,
1118
+ scroll,
1119
+ hint: message("feedback::viewer.hint")
1120
+ }) : null,
1121
+ phase === "publishing" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Text, { children: message("feedback::phase.publishing") }), notice === void 0 ? null : /* @__PURE__ */ jsx(Text, {
1122
+ color: colors.muted,
1123
+ children: notice
1124
+ })] }) : null,
1125
+ phase === "done" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
1126
+ /* @__PURE__ */ jsx(Text, {
1127
+ bold: true,
1128
+ children: doneKind === "stored" ? message("feedback::phase.done.local") : message("feedback::phase.done.issue")
1129
+ }),
1130
+ /* @__PURE__ */ jsx(Text, { children: notice ?? "" }),
1131
+ doneKind === "stored" ? /* @__PURE__ */ jsx(Text, {
1132
+ dimColor: true,
1133
+ children: message("feedback::phase.done.localNote")
1134
+ }) : null
1135
+ ] }) : null,
1136
+ phase === "failed" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
1137
+ /* @__PURE__ */ jsx(Text, {
1138
+ color: colors.error,
1139
+ children: `${errorMessageOf(errorCode) ?? message("feedback::error.failed")} (${errorCode ?? "unknown"})`
1140
+ }),
1141
+ notice === void 0 ? null : /* @__PURE__ */ jsx(Text, {
1142
+ color: colors.muted,
1143
+ children: notice
1144
+ }),
1145
+ /* @__PURE__ */ jsx(Text, {
1146
+ color: colors.muted,
1147
+ children: `${message("feedback::hint.retry")} · Esc ${message("feedback::hint.close")}`
1148
+ })
1149
+ ] }) : null
1150
+ ]
1151
+ })
1152
+ })
1153
+ });
1154
+ }
1155
+ function inspectableFiles(bundle) {
1156
+ if (bundle === void 0) return [];
1157
+ return bundle.files.filter((file) => file.text !== void 0);
1158
+ }
1159
+
1160
+ //#endregion
1161
+ //#region src/ui/position.ts
1162
+ function feedbackPositionKey() {
1163
+ return uiPositionKey(FEEDBACK_OWNER, FEEDBACK_POSITION_ID);
1164
+ }
1165
+ function feedbackPosition(ports) {
1166
+ return {
1167
+ owner: FEEDBACK_OWNER,
1168
+ id: FEEDBACK_POSITION_ID,
1169
+ kind: "overlay",
1170
+ path: FEEDBACK_PANEL_PATH,
1171
+ order: 70,
1172
+ priority: 0,
1173
+ label: {
1174
+ key: "position.overlay.feedback",
1175
+ fallback: "Send feedback"
1176
+ },
1177
+ element: createElement(FeedbackDialog, { ports })
1178
+ };
1179
+ }
1180
+
1181
+ //#endregion
1182
+ export { PUBLISHER_SERVICE as C, SURFACE_BYTES_LIMIT as D, STAGING_DIRECTORY as E, SURFACE_TEXT_LIMIT as O, PUBLISHER_OUTBOX as S, SETTING_KEYS as T, LEGACY_PUBLISHER_CODING as _, messagesOf as a, OUTBOX_DIRECTORY as b, DEFAULT_AUTH_PROVIDER as c, FEEDBACK_OWNER as d, FEEDBACK_PANEL_PATH as f, FEEDBACK_SERVICE_HOSTS_ENV as g, FEEDBACK_SERVICE_ALLOW_HTTP_ENV as h, linesOf as i, DIAGNOSTICS_BYTES_LIMIT as l, FEEDBACK_PLUGIN_VERSION as m, feedbackPositionKey as n, textOf as o, FEEDBACK_PLUGIN_ID as p, feedbackLocales as r, includesSessionExcerpt as s, feedbackPosition as t, FEEDBACK_HOME_DIRECTORY as u, MAX_BUNDLE_BYTES as v, SETTING_ENV as w, PUBLIC_URL_HOSTS as x, MERGE_WINDOW_MS as y };