@aarwitz/tapp 0.18.1 → 0.18.3
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/.claude-plugin/plugin.json +2 -2
- package/browser/app.css +420 -141
- package/browser/app.js +238 -459
- package/browser/index.html +67 -149
- package/browser/product-contract.js +16 -16
- package/browser/view-model.js +85 -0
- package/docs/BROWSER-PRODUCT.md +64 -70
- package/docs/PRODUCT-ENGINE.md +1 -1
- package/mcp-server/src/browser-product.js +142 -70
- package/mcp-server/src/html-report.js +1 -1
- package/mcp-server/src/index.js +4 -0
- package/package.json +2 -2
package/browser/app.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { customerProductContract } from "./product-contract.js";
|
|
2
|
-
import { operationIsPending,
|
|
2
|
+
import { classifyPrompt, narrate, narrateFinding, operationIsPending, summarize } from "./view-model.js";
|
|
3
3
|
|
|
4
4
|
const API_BASE = String(document.querySelector('meta[name="tapp-api-base"]')?.content || "").replace(/\/$/, "");
|
|
5
5
|
const LOGIN_URL = String(document.querySelector('meta[name="tapp-login-url"]')?.content || "");
|
|
@@ -11,15 +11,16 @@ function apiRoute(route) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const state = {
|
|
14
|
-
csrf: "", session: null, project: null, activeJob: null, activeView: "overview",
|
|
15
|
-
selectedTargetId: "", selectedRunId: "",
|
|
16
|
-
|
|
14
|
+
csrf: "", session: null, project: null, audits: [], explores: [], activeJob: null, activeView: "overview",
|
|
15
|
+
selectedTargetId: "", selectedRunId: "", live: { active:false }, transcript: [], transcriptSource: "", frameTimer: null,
|
|
16
|
+
chatCollapsed: false, shotScreens: new Set(), lastShotAt: 0,
|
|
17
17
|
};
|
|
18
18
|
const $ = (selector) => document.querySelector(selector);
|
|
19
19
|
const $$ = (selector) => [...document.querySelectorAll(selector)];
|
|
20
20
|
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (character) => ({ "&":"&", "<":"<", ">":">", '"':""", "'":"'" }[character]));
|
|
21
21
|
const pretty = (value) => String(value || "").replaceAll("_", " ").replaceAll("-", " ").replace(/\b\w/g, (letter) => letter.toUpperCase());
|
|
22
22
|
const compactDate = (value) => value ? new Intl.DateTimeFormat(undefined, { month:"short", day:"numeric", hour:"numeric", minute:"2-digit" }).format(new Date(value)) : "—";
|
|
23
|
+
const chatTime = (value) => new Intl.DateTimeFormat(undefined, { hour:"numeric", minute:"2-digit" }).format(new Date(value));
|
|
23
24
|
|
|
24
25
|
function toast(message, error = false) {
|
|
25
26
|
const node = $("#toast");
|
|
@@ -50,15 +51,15 @@ function captureId(report) {
|
|
|
50
51
|
}
|
|
51
52
|
return report?.capture?.id || "";
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
return id ? `<a class="button-link" href="${esc(apiRoute(`/evidence/captures/${encodeURIComponent(id)}/report.html`))}" target="_blank" rel="noreferrer">${esc(label)}</a>` : "";
|
|
54
|
+
const captureUrl = (id, file = "report.html") => apiRoute(`/evidence/captures/${encodeURIComponent(id)}/${file}`);
|
|
55
|
+
function evidenceLink(id, label = "Open visual evidence") {
|
|
56
|
+
return id ? `<a class="button-link" href="${esc(captureUrl(id))}" target="_blank" rel="noreferrer">${esc(label)}</a>` : "";
|
|
57
57
|
}
|
|
58
|
+
function reportLink(report, label) { return evidenceLink(captureId(report), label); }
|
|
58
59
|
|
|
59
60
|
function currentTarget() { return (state.project?.targets || []).find((target) => target.id === state.selectedTargetId) || null; }
|
|
60
|
-
|
|
61
61
|
function targetStorageKey() { return `tapp:selected-target:${state.project?.repository?.id || "none"}`; }
|
|
62
|
+
function currentPlatform() { return state.live?.active ? state.live.platform : (currentTarget()?.platform || state.promptPlatform || ""); }
|
|
62
63
|
|
|
63
64
|
function chooseDefaultTarget() {
|
|
64
65
|
const targets = state.project?.targets || [];
|
|
@@ -73,8 +74,6 @@ function operationPayload(extra = {}) {
|
|
|
73
74
|
return {
|
|
74
75
|
...(target ? { target:target.id, platform:target.platform } : {}),
|
|
75
76
|
...(target?.platform === "android" && $("#android-serial")?.value.trim() ? { serial:$("#android-serial").value.trim() } : {}),
|
|
76
|
-
...($("#test-email")?.value ? { testEmail:$("#test-email").value } : {}),
|
|
77
|
-
...($("#test-password")?.value ? { testPassword:$("#test-password").value } : {}),
|
|
78
77
|
...extra,
|
|
79
78
|
};
|
|
80
79
|
}
|
|
@@ -88,43 +87,34 @@ function activateView(view) {
|
|
|
88
87
|
window.scrollTo({ top:0, behavior:"instant" });
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
function
|
|
90
|
+
function showPrompt() {
|
|
92
91
|
$("#source-onboarding").classList.remove("hidden");
|
|
93
92
|
$("#product-shell").classList.add("hidden");
|
|
93
|
+
setTimeout(() => $("#prompt-input")?.focus(), 50);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
function showProduct() {
|
|
97
97
|
$("#source-onboarding").classList.add("hidden");
|
|
98
98
|
$("#product-shell").classList.remove("hidden");
|
|
99
|
-
activateView(location.hash.slice(1) || state.activeView);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function sourceLayer(repository) {
|
|
103
|
-
return repository?.source?.kind === "website" ? "Website" : "Repository";
|
|
104
99
|
}
|
|
105
100
|
|
|
106
101
|
function renderRepositoryChrome() {
|
|
107
102
|
const repositories = state.session?.repositories || [];
|
|
108
103
|
const current = state.project?.repository || state.session?.repository;
|
|
109
104
|
const switcher = $("#repository-switcher");
|
|
110
|
-
switcher.classList.toggle("hidden", repositories.length <
|
|
111
|
-
switcher.innerHTML = repositories.map((repository) => `<option value="${esc(repository.id)}" ${repository.id === current?.id ? "selected" : ""}>${esc(repository.name)}
|
|
105
|
+
switcher.classList.toggle("hidden", repositories.length < 2);
|
|
106
|
+
switcher.innerHTML = repositories.map((repository) => `<option value="${esc(repository.id)}" ${repository.id === current?.id ? "selected" : ""}>${esc(repository.name)}</option>`).join("");
|
|
112
107
|
$("#refresh-project").classList.toggle("hidden", !current);
|
|
113
108
|
if (!current) return;
|
|
114
|
-
const website = sourceLayer(current) === "Website";
|
|
115
109
|
$("#sidebar-project-name").textContent = state.project?.application?.name || current.name;
|
|
116
|
-
$("#sidebar-project-source").textContent =
|
|
110
|
+
$("#sidebar-project-source").textContent = current.source?.label || current.root || "Repository";
|
|
117
111
|
$("#project-avatar").textContent = (state.project?.application?.name || current.name || "T").slice(0, 1).toUpperCase();
|
|
118
|
-
$("#repository-title").textContent = current.source?.label || current.name;
|
|
119
|
-
$("#repository-detail").textContent = current.source?.note || (website ? "Connected website. Tapp can explore, record, and check it; a release verdict needs a source revision." : current.ephemeral ? "This is an isolated working copy. Review and export changes before updating the source repository." : `Direct local checkout · ${current.root}`);
|
|
120
|
-
$("#settings-repository").innerHTML = `<dl class="settings-dl"><div><dt>Layer</dt><dd>${sourceLayer(current)}</dd></div><div><dt>Source</dt><dd>${esc(pretty(current.source?.kind))}</dd></div><div><dt>Location</dt><dd><code>${esc(current.root || current.source?.label || "—")}</code></dd></div><div><dt>Write mode</dt><dd>${website ? "Observation only" : current.ephemeral ? "Isolated review copy" : "Direct checkout"}</dd></div></dl>`;
|
|
121
112
|
}
|
|
122
113
|
|
|
123
|
-
function setCount(id, value
|
|
114
|
+
function setCount(id, value) {
|
|
124
115
|
const node = $(id);
|
|
125
116
|
node.textContent = value;
|
|
126
117
|
node.classList.toggle("zero", !value);
|
|
127
|
-
node.classList.toggle("alert", alert && value > 0);
|
|
128
118
|
}
|
|
129
119
|
|
|
130
120
|
function renderTargets() {
|
|
@@ -138,8 +128,8 @@ function renderTargets() {
|
|
|
138
128
|
const detail = target.platform === "ios" ? `${target.build?.proposedScheme || "scheme unresolved"} · ${target.runtime?.surface || "iOS Simulator"}`
|
|
139
129
|
: target.platform === "android" ? `${target.runtime?.applicationId || "application id unresolved"} · ${target.build?.task || "assembleDebug"}`
|
|
140
130
|
: `${target.runtime?.management || "runtime unresolved"} · ${target.build?.start || target.build?.tool || "web"}`;
|
|
141
|
-
return `<button type="button" class="target-card ${selected ? "selected" : ""}" data-target-id="${esc(target.id)}" aria-pressed="${selected ? "true" : "false"}"><span class="platform-icon ${esc(target.platform)}">${target.platform === "ios" ? "
|
|
142
|
-
}).join("") : '<div class="empty">
|
|
131
|
+
return `<button type="button" class="target-card ${selected ? "selected" : ""}" data-target-id="${esc(target.id)}" aria-pressed="${selected ? "true" : "false"}"><span class="platform-icon ${esc(target.platform)}">${esc(target.platform === "ios" ? "" : target.platform === "android" ? "▲" : "⌁")}</span><span><strong>${esc(target.name)}</strong><small>${esc(pretty(target.platform))} · ${esc(detail)}</small></span><em class="target-state ${esc(target.status || "")}">${esc(pretty(target.status || "detected"))}</em></button>`;
|
|
132
|
+
}).join("") : (state.project?.state?.inspected ? '<div class="empty">No iOS, Android or web target was detected in this repository.</div>' : '<div class="empty">Inspecting the repository for iOS, Android and web targets…</div>');
|
|
143
133
|
const target = currentTarget();
|
|
144
134
|
$("#target-status").textContent = target ? `${pretty(target.platform)} · ${target.name}` : targets.length > 1 ? "Selection required" : "No target selected";
|
|
145
135
|
$("#sidebar-target").textContent = target ? `${pretty(target.platform)} · ${target.name}` : "Select a target";
|
|
@@ -147,39 +137,41 @@ function renderTargets() {
|
|
|
147
137
|
const appId = target?.runtime?.bundleId || target?.runtime?.applicationId || target?.build?.bundleId || "";
|
|
148
138
|
$("#sidebar-app-row").classList.toggle("hidden", !appId);
|
|
149
139
|
$("#sidebar-app-id").textContent = appId;
|
|
150
|
-
renderDeviceChrome(
|
|
140
|
+
renderDeviceChrome();
|
|
151
141
|
$("#runtime-row").classList.toggle("hidden", !targets.length);
|
|
152
142
|
$("#serial-field").classList.toggle("hidden", target?.platform !== "android");
|
|
153
143
|
$("#explore").disabled = !target;
|
|
154
144
|
$("#command-run").disabled = !target || !!state.activeJob;
|
|
145
|
+
$("#run-gate").disabled = !target || !!state.activeJob;
|
|
155
146
|
$("#explore").textContent = target && targets.length > 1 ? `Build & explore ${target.name}` : "Build, launch & explore";
|
|
156
147
|
$("#start-session").disabled = !target || state.live?.active === true;
|
|
157
|
-
$("#explore-help").textContent = !target ? (targets.length > 1 ? `Choose one of the ${targets.length} detected targets. Tapp will not select one for you.` : "
|
|
148
|
+
$("#explore-help").textContent = !target ? (targets.length > 1 ? `Choose one of the ${targets.length} detected targets. Tapp will not select one for you.` : "A runnable target is needed first.")
|
|
158
149
|
: target.platform === "ios" ? "Builds the selected scheme for an iOS simulator, installs it, then explores."
|
|
159
150
|
: target.platform === "android" ? "Builds the selected Gradle application, installs its APK, then explores."
|
|
160
151
|
: "Builds and starts the selected repository web application, then explores it in Chromium.";
|
|
161
152
|
}
|
|
162
153
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
154
|
+
// The device frame takes the platform's real shape: a phone is tall, a browser is wide. The stage
|
|
155
|
+
// gives it every pixel it can, so the frame class drives the aspect ratio and the stage the size.
|
|
156
|
+
function renderDeviceChrome() {
|
|
157
|
+
const platform = currentPlatform();
|
|
158
|
+
const target = currentTarget();
|
|
159
|
+
$("#device-frame").className = `device-frame ${platform || "ios"}`;
|
|
160
|
+
$("#stage").className = `stage ${platform || "ios"}`;
|
|
161
|
+
$("#device-feed-label").textContent = platform === "android" ? "Android" : platform === "web" ? "Chromium" : "iPhone";
|
|
168
162
|
$("#device-meta-device").textContent = platform === "ios" ? (target?.runtime?.surface || "iOS Simulator")
|
|
169
163
|
: platform === "android" ? (target?.runtime?.serial || "Android emulator / device")
|
|
170
|
-
: platform === "web" ? "Chromium" : "—";
|
|
164
|
+
: platform === "web" ? "Local Chromium" : "—";
|
|
171
165
|
}
|
|
172
166
|
|
|
173
167
|
// The device panel shows whichever real surface exists right now: an interactive session's frame,
|
|
174
|
-
// else the newest screenshot the running
|
|
168
|
+
// else the newest screenshot the running operation wrote. Nothing is synthesized.
|
|
175
169
|
function frameSource() {
|
|
176
170
|
if (state.live?.active) return "/api/live-session/frame";
|
|
177
171
|
if (state.activeJob && state.jobHasFrame) return `/api/jobs/${state.activeJob}/frame`;
|
|
178
172
|
return "";
|
|
179
173
|
}
|
|
180
174
|
|
|
181
|
-
// One in-flight capture at a time; the next request waits for the previous image to land so a
|
|
182
|
-
// slow simulator does not pile up frame requests.
|
|
183
175
|
function refreshLiveFrame() {
|
|
184
176
|
clearTimeout(state.frameTimer);
|
|
185
177
|
const source = frameSource();
|
|
@@ -192,31 +184,22 @@ function refreshLiveFrame() {
|
|
|
192
184
|
image.onerror = () => { loading.textContent = "Live frame could not be captured. The semantic controls remain available."; scheduleLiveFrame(); };
|
|
193
185
|
image.src = apiRoute(`${source}?at=${Date.now()}`);
|
|
194
186
|
}
|
|
195
|
-
|
|
196
|
-
function
|
|
197
|
-
clearTimeout(state.frameTimer);
|
|
198
|
-
if (frameSource()) state.frameTimer = setTimeout(refreshLiveFrame, 1500);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function stopLiveFrames() {
|
|
202
|
-
clearTimeout(state.frameTimer);
|
|
203
|
-
state.frameTimer = null;
|
|
204
|
-
}
|
|
187
|
+
function scheduleLiveFrame() { clearTimeout(state.frameTimer); if (frameSource()) state.frameTimer = setTimeout(refreshLiveFrame, 1500); }
|
|
188
|
+
function stopLiveFrames() { clearTimeout(state.frameTimer); state.frameTimer = null; }
|
|
205
189
|
|
|
206
190
|
function renderLiveSession() {
|
|
207
191
|
const live = state.live || { active:false };
|
|
208
192
|
$("#live-session-panel").classList.toggle("hidden", !live.active);
|
|
209
193
|
if (!live.active) {
|
|
210
|
-
// Keep the last real frame on screen after a run; only show the placeholder when nothing was ever captured.
|
|
211
194
|
if (!frameSource()) stopLiveFrames();
|
|
212
195
|
const hasFrame = !!$("#live-frame-image").getAttribute("src");
|
|
213
196
|
$("#live-frame-loading").classList.toggle("hidden", hasFrame || !frameSource());
|
|
214
197
|
$("#device-placeholder").classList.toggle("hidden", hasFrame);
|
|
215
198
|
if (!state.activeJob) $("#live-screen-title").textContent = hasFrame ? $("#live-screen-title").textContent : "—";
|
|
216
|
-
renderDeviceChrome(
|
|
199
|
+
renderDeviceChrome();
|
|
217
200
|
return;
|
|
218
201
|
}
|
|
219
|
-
renderDeviceChrome(
|
|
202
|
+
renderDeviceChrome();
|
|
220
203
|
$("#live-screen-title").textContent = live.screenTitle || live.targetName || "Running target";
|
|
221
204
|
$("#live-platform").textContent = `${pretty(live.platform)} · ${live.targetName || "live target"}`;
|
|
222
205
|
$("#live-recorded-steps").textContent = `${live.recordedSteps || 0} recorded step${live.recordedSteps === 1 ? "" : "s"}`;
|
|
@@ -227,7 +210,7 @@ function renderLiveSession() {
|
|
|
227
210
|
const target = element.id || element.label;
|
|
228
211
|
const input = element.role === "input" || element.secure || /input|textfield|edittext|textarea|secure/i.test(element.type);
|
|
229
212
|
return `<button class="live-control" data-live-control="${index}" data-live-target="${esc(target)}" data-live-input="${input ? "true" : "false"}" ${element.enabled === false || (!element.hittable && !input) ? "disabled" : ""}><span><strong>${esc(element.label || element.id)}</strong><small>${esc(element.id || "No stable identifier")} · ${esc(element.type || element.role || "control")}</small></span><em>${input ? "fill" : element.clickable ? "tap" : "inspect"}</em></button>`;
|
|
230
|
-
}).join("") : '<div class="empty">The current screen exposed no semantic controls. Add accessibility identifiers
|
|
213
|
+
}).join("") : '<div class="empty">The current screen exposed no semantic controls. Add accessibility identifiers to the app to drive it here.</div>';
|
|
231
214
|
refreshLiveFrame();
|
|
232
215
|
}
|
|
233
216
|
|
|
@@ -236,60 +219,6 @@ function renderRequirements() {
|
|
|
236
219
|
$("#requirements").innerHTML = requirements.length ? `<ul class="requirements">${requirements.map((item) => `<li class="${item.severity === "blocking" ? "blocking" : ""}"><span>${item.severity === "blocking" ? "!" : "i"}</span><div><b>${esc(item.message)}</b><small>${esc(item.remediation || "")}</small></div></li>`).join("")}</ul>` : "";
|
|
237
220
|
}
|
|
238
221
|
|
|
239
|
-
function renderMap(map) {
|
|
240
|
-
const nodes = map?.nodes || [];
|
|
241
|
-
const edges = map?.edges || [];
|
|
242
|
-
const controls = nodes.reduce((total, node) => total + (node.controls?.length || 0), 0);
|
|
243
|
-
const covered = nodes.filter((node) => (node.coveredBy?.tasks?.length || 0) + (node.coveredBy?.contracts?.length || 0) > 0).length;
|
|
244
|
-
$("#map-metric").textContent = `${nodes.length} states · ${edges.length} transitions`;
|
|
245
|
-
$("#map-canvas").innerHTML = nodes.length ? nodes.map((node, index) => {
|
|
246
|
-
const tasks = node.coveredBy?.tasks || [], contracts = node.coveredBy?.contracts || [];
|
|
247
|
-
return `<article class="map-node" style="--node-order:${index}"><div class="map-node-title"><span>${String(index + 1).padStart(2, "0")}</span><b>${esc(node.stateLabel || node.name)}</b></div><small>${node.controls?.length || 0} controls · ${esc((node.platforms || []).join("/"))} · ${esc(node.status)}</small><div class="coverage">${tasks.map((item) => `<span class="tag covered">Task: ${esc(item)}</span>`).join("")}${contracts.map((item) => `<span class="tag covered">Contract: ${esc(item)}</span>`).join("")}${!tasks.length && !contracts.length ? '<span class="tag">uncovered</span>' : ""}</div></article>`;
|
|
248
|
-
}).join("") : '<div class="empty">Explore the real product to build its map.</div>';
|
|
249
|
-
$("#coverage-summary").innerHTML = `<p class="eyebrow">MAP COVERAGE</p><dl><div><dt>States</dt><dd>${nodes.length}</dd></div><div><dt>Transitions</dt><dd>${edges.length}</dd></div><div><dt>Controls</dt><dd>${controls}</dd></div><div><dt>Covered states</dt><dd>${covered}/${nodes.length}</dd></div></dl><p class="coverage-honesty">Coverage means observed and contract-linked UI states—not source-line coverage or proof of every possible input.</p>`;
|
|
250
|
-
$("#overview-coverage").innerHTML = `<div><strong>${nodes.length}</strong><small>states observed</small></div><div><strong>${edges.length}</strong><small>transitions</small></div><div><strong>${controls}</strong><small>semantic controls</small></div><div><strong>${nodes.length ? Math.round(covered / nodes.length * 100) : 0}%</strong><small>contract-linked</small></div>`;
|
|
251
|
-
$("#transition-list").innerHTML = edges.length ? `<h3>Observed transitions</h3>${edges.map((edge) => `<div><code>${esc(edge.from)}</code><span>→ ${esc(edge.action?.target || edge.action?.label || edge.action || "action")} →</span><code>${esc(edge.to)}</code><em>${esc(edge.status)}</em></div>`).join("")}` : "";
|
|
252
|
-
$("#screen-list").innerHTML = nodes.length ? `<table><thead><tr><th>Screen / state</th><th>Platform</th><th>Status</th><th>Controls</th><th>Coverage</th></tr></thead><tbody>${nodes.map((node) => `<tr><td><strong>${esc(node.stateLabel || node.name)}</strong><small><code>${esc(node.id)}</code></small></td><td>${esc((node.platforms || []).join(", "))}</td><td>${esc(node.status)}</td><td>${node.controls?.length || 0}</td><td>${(node.coveredBy?.tasks?.length || 0)} Tasks · ${(node.coveredBy?.contracts?.length || 0)} contracts</td></tr>`).join("")}</tbody></table>` : '<div class="empty">No observed screens yet.</div>';
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function decisionValue(value) { return value === "accepted" ? "approved" : value || "pending"; }
|
|
256
|
-
|
|
257
|
-
function planHtml(plan) {
|
|
258
|
-
const items = plan?.items || [];
|
|
259
|
-
return items.length ? items.map((item) => `<article class="plan-item" data-id="${esc(item.id)}" data-criticality="${esc(item.criticality)}" data-original="${esc(decisionValue(item.decision))}"><div><div class="plan-title"><h3>${esc(item.title)}</h3><span class="criticality ${esc(item.criticality)}">${esc(item.criticality)}</span></div><p>${esc(item.businessValue)}</p><small class="risk">${esc(item.risk || item.requiredValidation || "Requires real deterministic validation")}</small><div class="plan-meta"><span class="tag">${esc(item.origin)}</span>${(item.platforms || []).map((platform) => `<span class="tag">${esc(platform)}</span>`).join("")}${(item.actors || []).map((actor) => `<span class="tag">actor: ${esc(actor)}</span>`).join("")}${item.generation ? `<span class="tag ${item.generation.trusted ? "covered" : "warning"}">${esc(item.generation.status)}</span>` : ""}</div></div><select aria-label="Decision for ${esc(item.title)}" ${item.origin === "committed" ? "disabled" : ""}><option value="pending" ${decisionValue(item.decision)==="pending"?"selected":""}>Needs review</option><option value="approved" ${decisionValue(item.decision)==="approved"?"selected":""}>Approve</option><option value="deferred" ${decisionValue(item.decision)==="deferred"?"selected":""}>Defer</option><option value="rejected" ${decisionValue(item.decision)==="rejected"?"selected":""}>Reject</option></select></article>`).join("") : '<div class="empty">Inspect and explore to create a grounded release plan.</div>';
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function renderPlan(plan) {
|
|
263
|
-
const items = plan?.items || [];
|
|
264
|
-
const pending = items.filter((item) => item.decision === "pending").length;
|
|
265
|
-
$("#plan-status").textContent = plan ? `${items.length} proposed · ${pending} pending` : "No plan";
|
|
266
|
-
$("#plan-list").innerHTML = planHtml(plan);
|
|
267
|
-
$("#coverage-plan-list").innerHTML = planHtml(plan);
|
|
268
|
-
setCount("#contract-count", state.project?.model?.artifacts?.contracts?.length || 0);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function renderArtifacts(model, plan) {
|
|
272
|
-
const tasks = model?.artifacts?.tasks || [];
|
|
273
|
-
const contracts = model?.artifacts?.contracts || [];
|
|
274
|
-
const flows = state.project?.flows || [];
|
|
275
|
-
const items = plan?.items || [];
|
|
276
|
-
const generated = items.filter((item) => item.generation?.path);
|
|
277
|
-
const drafts = generated.filter((item) => item.generation.status !== "promoted");
|
|
278
|
-
const validatedDrafts = drafts.filter((item) => item.generation?.trusted === true || item.generation?.status === "validated-draft");
|
|
279
|
-
const promoted = generated.filter((item) => item.generation.status === "promoted");
|
|
280
|
-
$("#validation-status").textContent = validatedDrafts.length ? "Validated drafts available" : drafts.length ? `${drafts.length} untrusted draft(s)` : promoted.length || contracts.length ? "Promoted suite ready" : "Not generated";
|
|
281
|
-
$("#generate").disabled = !items.some((item) => item.decision === "approved" && item.origin !== "committed" && !item.generation?.path);
|
|
282
|
-
$("#validate-drafts").disabled = !drafts.length || !currentTarget();
|
|
283
|
-
$("#promote").disabled = !validatedDrafts.length;
|
|
284
|
-
const artifacts = [
|
|
285
|
-
...contracts.map((item) => ({ kind:"Contract", name:item.name, path:item.path, status:"committed", platforms:item.platforms || [] })),
|
|
286
|
-
...tasks.map((item) => ({ kind:"Task", name:item.name, path:item.path, status:"committed", platforms:item.platforms || Object.keys(item.implementations || {}) })),
|
|
287
|
-
...flows.map((item) => ({ kind:"Flow", name:item.name, path:item.path, status:item.status, platforms:[item.platform], steps:item.steps })),
|
|
288
|
-
...drafts.map((item) => ({ kind:"Draft", name:item.name, path:item.generation.path, status:item.generation.trusted ? "validated" : item.generation.status || "untrusted", platforms:item.platforms || [] })),
|
|
289
|
-
];
|
|
290
|
-
$("#artifact-list").innerHTML = artifacts.length ? artifacts.map((item) => `<div class="artifact"><span><b>${esc(item.kind)}</b> · ${esc(item.name)} <span class="tag ${item.status === "validated" || item.status === "committed" ? "covered" : "warning"}">${esc(item.status)}</span>${item.steps ? ` <small>${item.steps} steps</small>` : ""}</span><span>${(item.platforms || []).map((platform) => `<i>${esc(platform)}</i>`).join("")}<code>${esc(item.path)}</code></span></div>`).join("") : '<div class="empty">No generated or committed Tasks, Flows, or contracts yet.</div>';
|
|
291
|
-
}
|
|
292
|
-
|
|
293
222
|
function latestRun() { return (state.project?.evidence || []).find((run) => run.report) || null; }
|
|
294
223
|
|
|
295
224
|
function renderDecision(run) {
|
|
@@ -299,12 +228,10 @@ function renderDecision(run) {
|
|
|
299
228
|
card.className = "decision-card neutral";
|
|
300
229
|
$("#decision-title").textContent = "Not evaluated";
|
|
301
230
|
$("#decision-detail").textContent = "Run a conclusive release gate to establish evidence.";
|
|
302
|
-
$("#overview-evidence").innerHTML = '<div class="empty">No
|
|
231
|
+
$("#overview-evidence").innerHTML = '<div class="empty">No run yet.</div>';
|
|
303
232
|
return;
|
|
304
233
|
}
|
|
305
234
|
const report = latest.report;
|
|
306
|
-
// The decision reflects the GATE outcome (pass/fail/inconclusive), not a ship verdict — exploration
|
|
307
|
-
// only observes (ADR-0005). Without a gate, it's an observation, not a merge decision.
|
|
308
235
|
const outcome = report.gate?.outcome || (report.gate?.failed === true ? "fail" : report.inconclusive ? "inconclusive" : report.gate ? "pass" : null);
|
|
309
236
|
const cssClass = { pass: "ready", fail: "blocked", inconclusive: "caution" }[outcome] || "caution";
|
|
310
237
|
card.className = `decision-card ${cssClass}`;
|
|
@@ -313,112 +240,158 @@ function renderDecision(run) {
|
|
|
313
240
|
$("#overview-evidence").innerHTML = `<div class="latest-run-line"><span class="verdict-dot ${esc(cssClass)}"></span><div><strong>${esc(report.headline || pretty(cssClass))}</strong><small>${esc(pretty(report.platform || "unknown"))} · ${compactDate(latest.createdAt)} · ${(report.contracts || []).filter((item) => item.passed).length}/${(report.contracts || []).length} contracts passed</small></div></div><p>${esc((report.gate?.reasons || ["No blocking release-gate reason reported."])[0])}</p>${reportLink(report)}`;
|
|
314
241
|
}
|
|
315
242
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const report = latest.report;
|
|
324
|
-
const failed = report.gate?.failed === true;
|
|
325
|
-
$("#latest-evidence").innerHTML = `<article class="evidence-card"><small>Gate</small><strong class="${failed ? "bad" : "good"}">${failed ? "BLOCK" : "PASS"}</strong><small>${esc(report.platform || "unknown")}</small></article><article class="evidence-card"><small>Coverage</small><strong>${report.screensExplored || 0}</strong><small>states · ${report.actionsPerformed || 0} actions</small></article><article class="evidence-card"><small>Contracts</small><strong>${(report.contracts || []).filter((item) => item.passed).length}/${(report.contracts || []).length}</strong><small>deterministic replay</small></article><article class="evidence-card"><small>Findings</small><strong>${report.findingCounts?.total ?? (report.findings || []).length}</strong><small>${report.regression?.new?.length || 0} new vs baseline</small></article><article class="evidence-card wide"><small>Decision rationale</small><h3>${esc(report.headline || "Release gate completed")}</h3><ul class="findings-list">${(report.gate?.reasons || ["No blocking gate reason reported."]).map((item) => `<li>${esc(item)}</li>`).join("")}</ul>${reportLink(report, "Open full report")}</article><article class="evidence-card wide"><small>Known boundary</small><h3>What this run did not prove</h3><ul class="findings-list">${(report.notChecked || ["Only observed and committed journeys are covered."]).slice(0, 5).map((item) => `<li>${esc(item)}</li>`).join("")}</ul></article>`;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function allFindings() {
|
|
329
|
-
return (state.project?.evidence || []).flatMap((run) => (run.report?.findings || []).map((finding, index) => ({ ...finding, __runId:run.id, __createdAt:run.createdAt, __id:`${run.id}:${finding.findingKey || finding.id || index}` })));
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
function findingTitle(finding) { return finding.title || finding.message || finding.type || "Finding"; }
|
|
333
|
-
|
|
334
|
-
function renderFindings() {
|
|
335
|
-
const filter = $("#finding-filter").value;
|
|
336
|
-
const findings = allFindings().filter((finding) => filter === "all" || String(finding.severity).toLowerCase() === filter);
|
|
337
|
-
setCount("#finding-count", allFindings().filter((finding) => ["critical", "high"].includes(String(finding.severity).toLowerCase())).length, { alert:true });
|
|
338
|
-
$("#findings-list").innerHTML = findings.length ? findings.map((finding) => `<button class="finding-row ${finding.__id === state.selectedFindingId ? "selected" : ""}" data-finding-id="${esc(finding.__id)}"><span class="severity ${esc(String(finding.severity || "info").toLowerCase())}"></span><span><strong>${esc(findingTitle(finding))}</strong><small>${esc(finding.screen || finding.category || pretty(finding.type))} · ${compactDate(finding.__createdAt)}</small></span><em>${esc(finding.severity || "info")}</em></button>`).join("") : '<div class="empty">No findings match this view.</div>';
|
|
339
|
-
const selected = findings.find((finding) => finding.__id === state.selectedFindingId) || findings[0];
|
|
340
|
-
if (selected) state.selectedFindingId = selected.__id;
|
|
341
|
-
$("#finding-detail").innerHTML = selected ? `<p class="eyebrow">${esc(selected.severity || "FINDING")}</p><h2>${esc(findingTitle(selected))}</h2><p>${esc(selected.description || selected.detail || "Tapp recorded this behavior during the release run.")}</p><dl class="detail-dl"><div><dt>Screen</dt><dd>${esc(selected.screen || "—")}</dd></div><div><dt>Category</dt><dd>${esc(pretty(selected.category || selected.type || "unknown"))}</dd></div><div><dt>Target</dt><dd>${esc(selected.target || "—")}</dd></div><div><dt>Run</dt><dd><code>${esc(selected.__runId)}</code></dd></div></dl>${selected.evidence ? `<h3>Evidence</h3><pre>${esc(typeof selected.evidence === "string" ? selected.evidence : JSON.stringify(selected.evidence, null, 2))}</pre>` : ""}<p class="honesty">Finding acknowledgement and suppression are not yet shared across browser, CLI, and CI, so this browser does not offer a misleading local-only “ignore” button.</p>` : '<div class="empty">Select a finding to inspect its evidence.</div>';
|
|
243
|
+
// Runs are three kinds in one list: gate runs on the repository, explorations started from the
|
|
244
|
+
// prompt, and read-only website audits. Each opens the report page the engine wrote.
|
|
245
|
+
function allRuns() {
|
|
246
|
+
const gates = (state.project?.evidence || []).map((run) => ({ ...run, kind:"gate" }));
|
|
247
|
+
const explores = (state.explores || []).map((run) => ({ id:run.id, createdAt:run.createdAt, kind:"explore", explore:run }));
|
|
248
|
+
const audits = (state.audits || []).map((audit) => ({ id:audit.id, createdAt:audit.createdAt, kind:"audit", audit }));
|
|
249
|
+
return [...gates, ...explores, ...audits].sort((a, b) => String(b.createdAt || "").localeCompare(String(a.createdAt || "")));
|
|
342
250
|
}
|
|
343
251
|
|
|
344
|
-
function renderRuns(
|
|
252
|
+
function renderRuns() {
|
|
253
|
+
const runs = allRuns();
|
|
345
254
|
setCount("#run-count", runs.length);
|
|
346
255
|
$("#runs-list").innerHTML = runs.length ? runs.map((run) => {
|
|
256
|
+
const selected = run.id === state.selectedRunId ? "selected" : "";
|
|
257
|
+
if (run.kind === "audit") {
|
|
258
|
+
const audit = run.audit;
|
|
259
|
+
const issues = audit.issueCount || 0;
|
|
260
|
+
const host = (() => { try { return new URL(audit.url).host; } catch { return audit.url; } })();
|
|
261
|
+
return `<button class="run-row ${selected}" data-run-id="${esc(run.id)}"><span class="run-status ${issues ? "inconclusive" : "ready"}">${issues ? "!" : "✓"}</span><span><strong>Audit · ${esc(host)}</strong><small>${compactDate(run.createdAt)} · ${audit.pagesAudited || 0} page${audit.pagesAudited === 1 ? "" : "s"} · read-only</small></span><em>${issues ? `${issues} issue${issues === 1 ? "" : "s"}` : "Nothing broken"}</em></button>`;
|
|
262
|
+
}
|
|
263
|
+
if (run.kind === "explore") {
|
|
264
|
+
const e = run.explore;
|
|
265
|
+
const findings = e.report?.findingCounts?.total ?? (e.report?.findings || []).length;
|
|
266
|
+
return `<button class="run-row ${selected}" data-run-id="${esc(run.id)}"><span class="run-status ${e.report?.inconclusive ? "inconclusive" : "completed"}">${e.report?.inconclusive ? "◐" : "✓"}</span><span><strong>Explore · ${esc(e.target || e.platform)}</strong><small>${compactDate(run.createdAt)} · ${esc(pretty(e.platform))}</small></span><em>${findings} finding${findings === 1 ? "" : "s"}</em></button>`;
|
|
267
|
+
}
|
|
347
268
|
const report = run.report;
|
|
348
269
|
const failed = report?.gate?.failed === true;
|
|
349
|
-
// Status reflects the gate outcome (pass/fail/inconclusive), mapped to the existing CSS classes.
|
|
350
270
|
const status = !report ? run.status
|
|
351
271
|
: report.gate?.outcome === "fail" || failed ? "blocked"
|
|
352
272
|
: report.gate?.outcome === "inconclusive" || report.inconclusive ? "inconclusive"
|
|
353
273
|
: report.gate?.outcome === "pass" ? "ready" : "completed";
|
|
354
|
-
return `<button class="run-row ${
|
|
355
|
-
}).join("") : '<div class="empty">No release
|
|
356
|
-
const
|
|
357
|
-
if (
|
|
358
|
-
renderRunDetail(
|
|
274
|
+
return `<button class="run-row ${selected}" data-run-id="${esc(run.id)}"><span class="run-status ${esc(status)}">${failed ? "×" : report ? "✓" : "…"}</span><span><strong>${esc(report?.headline || `Release run ${run.id.slice(-8)}`)}</strong><small>${compactDate(run.createdAt)} · ${esc(pretty(report?.platform || "unknown"))}</small></span><em>${esc(pretty(status))}</em></button>`;
|
|
275
|
+
}).join("") : '<div class="empty">No runs yet. Run a release check, or audit a website above.</div>';
|
|
276
|
+
const chosen = runs.find((run) => run.id === state.selectedRunId) || runs[0];
|
|
277
|
+
if (chosen) state.selectedRunId = chosen.id;
|
|
278
|
+
renderRunDetail(chosen);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function detailLists(report) {
|
|
282
|
+
return `<h3>What Tapp checked</h3><ul class="detail-list">${(report.checkedFor || []).slice(0, 8).map((item) => `<li>${esc(item)}</li>`).join("")}</ul><h3>Not checked</h3><ul class="detail-list boundary">${(report.notChecked || []).slice(0, 8).map((item) => `<li>${esc(item)}</li>`).join("")}</ul>`;
|
|
359
283
|
}
|
|
360
284
|
|
|
361
285
|
function renderRunDetail(run) {
|
|
362
|
-
if (!run
|
|
286
|
+
if (!run) { $("#run-detail").innerHTML = '<div class="empty">Select a run to inspect its evidence.</div>'; return; }
|
|
287
|
+
if (run.kind === "audit") {
|
|
288
|
+
const audit = run.audit;
|
|
289
|
+
const counts = audit.findingCounts || {};
|
|
290
|
+
const issues = audit.issues || [];
|
|
291
|
+
$("#run-detail").innerHTML = `<div class="run-detail-head"><div><p class="eyebrow">READ-ONLY AUDIT</p><h2>${esc(audit.url)}</h2><small><code>${esc(audit.id)}</code> · ${compactDate(audit.createdAt)} · nothing was clicked</small></div>${evidenceLink(audit.id, "Visual report")}</div><div class="run-stats"><div><strong>${audit.pagesAudited || 0}</strong><small>pages</small></div><div><strong>${issues.length}</strong><small>distinct issues</small></div><div><strong>${counts.high || 0}</strong><small>high</small></div><div><strong>${counts.medium || 0}</strong><small>medium</small></div></div><h3>Issues</h3>${issues.length ? `<ul class="detail-list">${issues.slice(0, 40).map((issue) => `<li><b>${esc(issue.severity)}</b> · ${esc(issue.title)}${issue.pages?.length > 1 ? ` <small>(${issue.pages.length} pages)</small>` : ""}</li>`).join("")}</ul>` : '<p class="muted">Nothing broken was observed. This says the pages are served without structural defects, not that the site works.</p>'}${detailLists(audit)}`;
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (run.kind === "explore") {
|
|
295
|
+
const e = run.explore;
|
|
296
|
+
const report = e.report || {};
|
|
297
|
+
$("#run-detail").innerHTML = `<div class="run-detail-head"><div><p class="eyebrow">${esc(report.inconclusive ? "INCONCLUSIVE" : "EXPLORATION")}</p><h2>${esc(report.headline || `Explored ${e.target || e.platform}`)}</h2><small><code>${esc(e.id)}</code> · ${compactDate(e.createdAt)} · an observation, not a release decision</small></div>${evidenceLink(e.id, "Visual report")}</div><div class="run-stats"><div><strong>${report.screensExplored || 0}</strong><small>screens</small></div><div><strong>${report.actionsPerformed || 0}</strong><small>actions</small></div><div><strong>${report.findingCounts?.total ?? (report.findings || []).length}</strong><small>findings</small></div></div><h3>Findings</h3>${(report.findings || []).length ? `<ul class="detail-list">${report.findings.slice(0, 40).map((f) => `<li><b>${esc(f.severity)}</b> · ${esc(f.title)}${f.screen ? ` <small>on ${esc(f.screen)}</small>` : ""}</li>`).join("")}</ul>` : '<p class="muted">No findings surfaced in the exercised surfaces.</p>'}${detailLists(report)}`;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (!run.report) { $("#run-detail").innerHTML = '<div class="empty">Select a completed run to inspect its evidence.</div>'; return; }
|
|
363
301
|
const report = run.report;
|
|
364
302
|
const contracts = report.contracts || [];
|
|
365
|
-
$("#run-detail").innerHTML = `<div class="run-detail-head"><div><p class="eyebrow">${esc(report.gate?.failed ? "BLOCKED" : report.inconclusive ? "INCONCLUSIVE" : "RELEASE RUN")}</p><h2>${esc(report.headline || "Release gate completed")}</h2><small><code>${esc(run.id)}</code> · ${compactDate(run.createdAt)}</small></div>${reportLink(report, "Visual report")}</div><div class="run-stats"><div><strong>${report.screensExplored || 0}</strong><small>states</small></div><div><strong>${report.actionsPerformed || 0}</strong><small>actions</small></div><div><strong>${contracts.filter((item) => item.passed).length}/${contracts.length}</strong><small>contracts</small></div><div><strong>${report.findingCounts?.total ?? (report.findings || []).length}</strong><small>findings</small></div></div><h3>Decision rationale</h3><ul class="detail-list">${(report.gate?.reasons || ["No blocking gate reason reported."]).map((item) => `<li>${esc(item)}</li>`).join("")}</ul><h3>Deterministic contracts</h3>${contracts.length ? contracts.map((contract) => `<div class="contract-result"><span class="${contract.passed ? "pass" : "fail"}">${contract.passed ? "✓" : "×"}</span><div><strong>${esc(contract.title || contract.name || contract.path)}</strong><small>${esc(contract.detail || contract.path || "Deterministic replay")}</small></div></div>`).join("") : '<p class="muted">No committed release contracts applied to this target.</p>'}
|
|
303
|
+
$("#run-detail").innerHTML = `<div class="run-detail-head"><div><p class="eyebrow">${esc(report.gate?.failed ? "BLOCKED" : report.inconclusive ? "INCONCLUSIVE" : "RELEASE RUN")}</p><h2>${esc(report.headline || "Release gate completed")}</h2><small><code>${esc(run.id)}</code> · ${compactDate(run.createdAt)}</small></div>${reportLink(report, "Visual report")}</div><div class="run-stats"><div><strong>${report.screensExplored || 0}</strong><small>states</small></div><div><strong>${report.actionsPerformed || 0}</strong><small>actions</small></div><div><strong>${contracts.filter((item) => item.passed).length}/${contracts.length}</strong><small>contracts</small></div><div><strong>${report.findingCounts?.total ?? (report.findings || []).length}</strong><small>findings</small></div></div><h3>Decision rationale</h3><ul class="detail-list">${(report.gate?.reasons || ["No blocking gate reason reported."]).map((item) => `<li>${esc(item)}</li>`).join("")}</ul><h3>Deterministic contracts</h3>${contracts.length ? contracts.map((contract) => `<div class="contract-result"><span class="${contract.passed ? "pass" : "fail"}">${contract.passed ? "✓" : "×"}</span><div><strong>${esc(contract.title || contract.name || contract.path)}</strong><small>${esc(contract.detail || contract.path || "Deterministic replay")}</small></div></div>`).join("") : '<p class="muted">No committed release contracts applied to this target.</p>'}${detailLists(report)}`;
|
|
366
304
|
}
|
|
367
305
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
306
|
+
// ---- tapp chat: the engine's progress log, rendered as a transcript -------------------------
|
|
307
|
+
function renderChat() {
|
|
308
|
+
const node = $("#chat-transcript");
|
|
309
|
+
const stickToBottom = node.scrollTop + node.clientHeight >= node.scrollHeight - 24;
|
|
310
|
+
const lines = state.transcript.map((entry) => {
|
|
311
|
+
if (entry.kind === "shots") return `<div class="chat-shots">${entry.shots.map((shot) => `<a href="${esc(shot.href)}" target="_blank" rel="noreferrer" title="${esc(shot.caption)}"><img src="${esc(shot.src)}" alt="${esc(shot.caption)}"></a>`).join("")}</div>`;
|
|
312
|
+
if (entry.kind === "attachments") return `<div class="chat-attachments">${entry.items.map((item) => `<a href="${esc(item.href)}" target="_blank" rel="noreferrer"><span>${item.icon}</span>${esc(item.label)}</a>`).join("")}</div>`;
|
|
313
|
+
if (entry.kind === "summary") return `<div class="chat-summary ${esc(entry.tone)}"><span class="chat-pill">${esc(entry.pill)}</span><p>${esc(entry.text)}</p></div>`;
|
|
314
|
+
if (entry.kind === "finding") return `<div class="chat-line finding ${esc(entry.severity)}"><span class="chat-icon">${entry.icon}</span><span>${esc(entry.text)}</span></div>`;
|
|
315
|
+
if (entry.kind === "progress") return "";
|
|
316
|
+
return `<div class="chat-line ${esc(entry.kind || "")}"><span class="chat-icon">${entry.icon || "•"}</span><span>${esc(entry.text)}${entry.detail ? ` <em>— ${esc(entry.detail)}</em>` : ""}</span></div>`;
|
|
317
|
+
}).join("") + (state.activeJob ? '<div class="chat-line typing"><span class="chat-icon">✨</span><span>tapp is working<i>…</i></span></div>' : "");
|
|
318
|
+
node.innerHTML = lines;
|
|
319
|
+
if (stickToBottom) node.scrollTop = node.scrollHeight;
|
|
320
|
+
const progress = [...state.transcript].reverse().find((entry) => entry.kind === "progress");
|
|
321
|
+
$("#chat-status").textContent = state.activeJob ? (progress ? `${progress.current}/${progress.total} actions${progress.states != null ? ` · ${progress.states} screens` : ""}` : "working…") : state.transcript.length > 1 ? "done" : "ready";
|
|
379
322
|
}
|
|
380
323
|
|
|
381
|
-
function
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
$("#
|
|
324
|
+
function setChatCollapsed(collapsed) {
|
|
325
|
+
state.chatCollapsed = collapsed;
|
|
326
|
+
$("#chat-float").classList.toggle("collapsed", collapsed);
|
|
327
|
+
$("#chat-toggle").setAttribute("aria-expanded", String(!collapsed));
|
|
328
|
+
try { localStorage.setItem("tapp:chat-collapsed", collapsed ? "1" : "0"); } catch { /* storage may be unavailable */ }
|
|
385
329
|
}
|
|
386
330
|
|
|
387
|
-
|
|
331
|
+
function pushLine(entry) { state.transcript.push({ at: new Date().toISOString(), ...entry }); }
|
|
388
332
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
333
|
+
// A screenshot the engine wrote during the run, kept as a thumbnail in the transcript. Captured
|
|
334
|
+
// once per screen name the engine reports, and never more often than every few seconds.
|
|
335
|
+
async function keepShot(screen) {
|
|
336
|
+
const key = screen || `t${Math.floor(Date.now() / 4000)}`;
|
|
337
|
+
if (state.shotScreens.has(key) || Date.now() - state.lastShotAt < 2500 || !state.activeJob) return;
|
|
338
|
+
state.shotScreens.add(key);
|
|
339
|
+
state.lastShotAt = Date.now();
|
|
340
|
+
try {
|
|
341
|
+
const response = await fetch(apiRoute(`/api/jobs/${state.activeJob}/frame?at=${Date.now()}`));
|
|
342
|
+
if (!response.ok) return;
|
|
343
|
+
const blob = await response.blob();
|
|
344
|
+
const src = URL.createObjectURL(blob);
|
|
345
|
+
const last = state.transcript.at(-1);
|
|
346
|
+
if (last?.kind === "shots" && last.shots.length < 3) last.shots.push({ src, href: src, caption: screen || "screen" });
|
|
347
|
+
else pushLine({ kind: "shots", shots: [{ src, href: src, caption: screen || "screen" }] });
|
|
348
|
+
renderChat();
|
|
349
|
+
} catch { /* a missed thumbnail is not an error */ }
|
|
395
350
|
}
|
|
396
351
|
|
|
397
|
-
// The transcript is the engine's own progress log, bubble per entry. Phase changes get the
|
|
398
|
-
// `phase` style; everything else is narration of what actually happened.
|
|
399
352
|
function syncTranscriptFromJob(name, job) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
353
|
+
if (state.transcriptSource !== job.id) {
|
|
354
|
+
state.transcript = [{ at: job.createdAt, kind: "phase", icon: "🚀", text: startLine(name, job) }];
|
|
355
|
+
state.transcriptSource = job.id;
|
|
356
|
+
state.shotScreens = new Set();
|
|
357
|
+
state.lastShotAt = 0;
|
|
358
|
+
}
|
|
359
|
+
const seen = state.transcript.filter((entry) => entry.source === "job").length;
|
|
403
360
|
for (const entry of job.progress.slice(seen)) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
if (
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
361
|
+
const line = narrate(entry, { platform: currentPlatform() });
|
|
362
|
+
state.transcript.push({ ...(line || { kind: "step", icon: "•", text: "" }), at: entry.at, source: "job" });
|
|
363
|
+
if (line && line.kind !== "progress") {
|
|
364
|
+
const last = state.transcript.at(-2);
|
|
365
|
+
if (last && last.text === line.text && last.kind !== "shots") state.transcript.splice(-1, 1);
|
|
366
|
+
}
|
|
367
|
+
if (entry.screen) keepShot(entry.screen);
|
|
410
368
|
}
|
|
411
369
|
}
|
|
412
370
|
|
|
413
|
-
function
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
371
|
+
function startLine(name, job) {
|
|
372
|
+
const input = job.input || "";
|
|
373
|
+
return { initialize: "Starting a release check — build, launch and explore the real app", gate: "Running the release gate", audit: `Opening ${input} read-only — nothing will be clicked`, "explore-build": `Exploring ${input} on the booted device`, open: `Opening ${input}`, "session-start": "Opening a live session", "session-act": "Acting in the live session", "session-save-flow": "Saving the journey as a Flow", "session-end": "Ending the live session" }[name] || `${pretty(name)} started`;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async function finishTranscript(name, job) {
|
|
377
|
+
state.transcript = state.transcript.filter((entry) => entry.kind !== "progress" || true);
|
|
378
|
+
if (job.status === "failed") { pushLine({ kind: "warning", icon: "⚠️", text: job.error?.message || `${pretty(name)} failed` }); return; }
|
|
379
|
+
const result = job.result || {};
|
|
380
|
+
// initialize carries its exploration beside the project; the gate carries a report.
|
|
381
|
+
const report = result.exploration || result.report || result;
|
|
382
|
+
for (const finding of (report.findings || result.issues || []).slice(0, 12)) pushLine(narrateFinding(finding));
|
|
383
|
+
const id = result.capture?.id || captureId(report);
|
|
384
|
+
if (id) {
|
|
385
|
+
try {
|
|
386
|
+
const files = await api(`/api/captures/${encodeURIComponent(id)}/files`);
|
|
387
|
+
if (files.shots?.length) pushLine({ kind: "shots", shots: files.shots.slice(0, 3).map((shot) => ({ src: captureUrl(id, shot.src), href: captureUrl(id, shot.src), caption: shot.caption })) });
|
|
388
|
+
const items = [];
|
|
389
|
+
if (files.recording) items.push({ icon: "🎬", label: files.recording, href: captureUrl(id, files.recording) });
|
|
390
|
+
if (files.report) items.push({ icon: "📄", label: "report.html", href: captureUrl(id, files.report) });
|
|
391
|
+
if (items.length) pushLine({ kind: "attachments", items });
|
|
392
|
+
} catch { /* the summary still renders */ }
|
|
419
393
|
}
|
|
420
|
-
|
|
421
|
-
state.transcript.push({ at: job.completedAt || new Date().toISOString(), kind: "summary", text: summary });
|
|
394
|
+
pushLine({ kind: "summary", ...summarize(name, result.exploration ? { ...result, report } : result) });
|
|
422
395
|
}
|
|
423
396
|
|
|
424
397
|
function seedIdleTranscript() {
|
|
@@ -426,8 +399,8 @@ function seedIdleTranscript() {
|
|
|
426
399
|
const latest = latestRun();
|
|
427
400
|
const report = latest?.report;
|
|
428
401
|
state.transcript = report
|
|
429
|
-
? [{ at: latest.createdAt, kind: "summary",
|
|
430
|
-
: [{ at: new Date().toISOString(), kind: "phase", text: state.project?.state?.inspected ? "Ready. Run a release check
|
|
402
|
+
? [{ at: latest.createdAt, kind: "summary", ...summarize("gate", report) }]
|
|
403
|
+
: [{ at: new Date().toISOString(), kind: "phase", icon: "👋", text: state.project?.state?.inspected ? "Ready. Run a release check and I'll narrate what the app does while you watch it." : "Inspecting the project…" }];
|
|
431
404
|
}
|
|
432
405
|
|
|
433
406
|
function renderCommandState(job = null, name = "") {
|
|
@@ -436,6 +409,7 @@ function renderCommandState(job = null, name = "") {
|
|
|
436
409
|
pill.classList.toggle("hidden", !running);
|
|
437
410
|
pill.classList.toggle("running", running);
|
|
438
411
|
$("#command-run").disabled = running || !currentTarget();
|
|
412
|
+
$("#run-gate").disabled = running || !currentTarget();
|
|
439
413
|
$("#run-progress").classList.toggle("hidden", !running);
|
|
440
414
|
$("#idle-badges").classList.toggle("hidden", running);
|
|
441
415
|
if (running) {
|
|
@@ -450,39 +424,30 @@ function renderCommandState(job = null, name = "") {
|
|
|
450
424
|
const target = currentTarget();
|
|
451
425
|
const runner = target ? state.session?.runners?.find((item) => item.platform === target.platform) : null;
|
|
452
426
|
$("#idle-badges").innerHTML = [
|
|
453
|
-
target ? `<span><b>${esc(pretty(target.platform))}</b> · ${esc(target.name)}</span>` : "
|
|
454
|
-
runner ? `<span>${esc(runner.label)}
|
|
455
|
-
`<span>Idle · ${target ? "Ready for next release check" : "Choose a target to run"}</span>`,
|
|
427
|
+
target ? `<span><b>${esc(pretty(target.platform))}</b> · ${esc(target.name)}</span>` : "",
|
|
428
|
+
runner ? `<span>${esc(runner.label)}</span>` : "",
|
|
456
429
|
].filter(Boolean).join("");
|
|
457
430
|
}
|
|
458
431
|
|
|
459
|
-
function renderJourney(status) {
|
|
460
|
-
const flags = productJourneyFlags({ status, hasTarget:!!currentTarget(), hasEvidence:(state.project?.evidence || []).some((run) => run.report) });
|
|
461
|
-
$$(".journey button").forEach((button, index) => button.classList.toggle("done", !!flags[index]));
|
|
462
|
-
}
|
|
463
|
-
|
|
464
432
|
function renderProject() {
|
|
465
433
|
const project = state.project;
|
|
466
434
|
renderRepositoryChrome();
|
|
467
|
-
if (!project?.connected) {
|
|
435
|
+
if (!project?.connected) {
|
|
436
|
+
if ((state.audits.length || state.explores.length) && state.activeView === "runs") { showProduct(); renderRuns(); return; }
|
|
437
|
+
if (state.promptRun) { showProduct(); renderRuns(); renderDeviceChrome(); renderChat(); return; }
|
|
438
|
+
showPrompt();
|
|
439
|
+
renderRuns();
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
468
442
|
showProduct();
|
|
469
443
|
$("#app-name").textContent = project.application?.name || "Unnamed product";
|
|
470
444
|
const platforms = project.application?.platforms?.map(pretty).join(" · ") || "Targets not inspected";
|
|
471
|
-
$("#app-summary").textContent = `${platforms} · ${project.capabilities?.length || 0} known capabilities
|
|
472
|
-
$("#connect-status").textContent = project.state.inspected ? (project.state.explored ? "Observed" : "Inspected") : "Not inspected";
|
|
445
|
+
$("#app-summary").textContent = `${platforms} · ${project.capabilities?.length || 0} known capabilities`;
|
|
473
446
|
renderTargets();
|
|
474
447
|
renderRequirements();
|
|
475
|
-
renderMap(project.map);
|
|
476
|
-
renderPlan(project.plan);
|
|
477
|
-
renderArtifacts(project.model, project.plan);
|
|
478
448
|
renderDecision();
|
|
479
|
-
|
|
480
|
-
renderRuns(project.evidence || []);
|
|
481
|
-
renderFindings();
|
|
482
|
-
renderApplication(project.model);
|
|
483
|
-
renderRunners();
|
|
449
|
+
renderRuns();
|
|
484
450
|
renderLiveSession();
|
|
485
|
-
renderJourney(project.state);
|
|
486
451
|
seedIdleTranscript();
|
|
487
452
|
renderChat();
|
|
488
453
|
renderCommandState();
|
|
@@ -494,40 +459,30 @@ async function refreshSession() {
|
|
|
494
459
|
const local = state.session.mode === "local";
|
|
495
460
|
$("#mode-pill").textContent = local ? "Self-host · this machine" : "Cloud · outbound runner";
|
|
496
461
|
$("#onboarding-mode-pill").textContent = local ? "Self-host · this machine" : "Cloud";
|
|
497
|
-
$("#privacy-note-
|
|
498
|
-
$("#privacy-note-detail").textContent = local ? "Ordinary exploration, replay, and merge decisions are deterministic and require no API key. This machine must stay open while Tapp runs." : "Builds and application runs execute on your connected outbound runner; the hosted control plane keeps the evidence.";
|
|
499
|
-
$("#website-connect-link").classList.toggle("hidden", local);
|
|
500
|
-
$(".local-runner-card").classList.toggle("hidden", local);
|
|
501
|
-
$("#website-source-note").textContent = local
|
|
502
|
-
? "In the local Studio, website checks run from the CLI: npx -y @aarwitz/tapp@latest explore https://example.com --read-only. Website projects live in the hosted Studio."
|
|
503
|
-
: "You confirm you own the site before Tapp observes it. Accounts and backend access are configured privately, never in chat.";
|
|
504
|
-
if (!local) {
|
|
505
|
-
$("#github-source-copy").textContent = "Repository upload works now. GitHub App connection will add selected-repository import without changing the product workflow.";
|
|
506
|
-
$("#github-source-note").textContent = "Use This Mac now; GitHub can be added independently later.";
|
|
507
|
-
const result = await api("/api/repositories/local");
|
|
508
|
-
$("#local-repositories").innerHTML = result.repositories?.length
|
|
509
|
-
? result.repositories.map(repo=>`<button class="primary" data-local-runner="${esc(repo.runnerId)}" data-local-repository="${esc(repo.id)}">Use ${esc(repo.name)} <small>${esc(repo.runnerName)}${repo.branch ? ` · ${esc(repo.branch)}`:""}</small></button>`).join("")
|
|
510
|
-
: '<small>Start the Tapp runner on this Mac to make local checkouts available.</small>';
|
|
511
|
-
}
|
|
462
|
+
$("#privacy-note-detail").textContent = local ? "Everything runs on this machine. Exploration, replay and merge decisions are deterministic and need no API key." : "Your repository stays in your private Tapp workspace.";
|
|
512
463
|
}
|
|
513
464
|
|
|
514
465
|
async function refresh() {
|
|
515
|
-
[
|
|
466
|
+
const [project, live, runs] = await Promise.all([api("/api/project"), api("/api/live-session"), api("/api/audits").catch(() => ({ audits: [], explores: [] }))]);
|
|
467
|
+
state.project = project;
|
|
468
|
+
state.live = live;
|
|
469
|
+
state.audits = runs.audits || [];
|
|
470
|
+
state.explores = runs.explores || [];
|
|
516
471
|
renderProject();
|
|
517
472
|
}
|
|
518
473
|
|
|
519
|
-
async function runOperation(name, body = {}) {
|
|
520
|
-
if (state.activeJob) throw new Error("Another
|
|
474
|
+
async function runOperation(name, body = {}, { input = "" } = {}) {
|
|
475
|
+
if (state.activeJob) throw new Error("Another operation is still running");
|
|
521
476
|
const started = await api(`/api/operations/${name}`, { method:"POST", body:JSON.stringify(body) });
|
|
477
|
+
if (!started.job) return started; // synchronous answers (open a path, a business name)
|
|
522
478
|
state.activeJob = started.job.id;
|
|
523
479
|
const drawer = $("#operation-drawer");
|
|
524
480
|
drawer.classList.remove("hidden");
|
|
525
|
-
$("#operation-title").textContent = pretty(name);
|
|
526
|
-
$("#operation-progress").textContent = "Starting
|
|
481
|
+
$("#operation-title").textContent = name === "audit" ? "Read-only audit" : pretty(name);
|
|
482
|
+
$("#operation-progress").textContent = "Starting";
|
|
527
483
|
$("#operation-progress-bar").style.width = "6%";
|
|
528
|
-
syncTranscriptFromJob(name, started.job);
|
|
529
|
-
renderCommandState(started.job, name);
|
|
530
|
-
renderChat();
|
|
484
|
+
syncTranscriptFromJob(name, { ...started.job, input });
|
|
485
|
+
if (!$("#product-shell").classList.contains("hidden")) { renderCommandState(started.job, name); renderChat(); }
|
|
531
486
|
try {
|
|
532
487
|
while (true) {
|
|
533
488
|
await new Promise((resolve) => setTimeout(resolve, 650));
|
|
@@ -536,22 +491,20 @@ async function runOperation(name, body = {}) {
|
|
|
536
491
|
$("#operation-progress").textContent = progress?.text || "Working…";
|
|
537
492
|
const ratio = progress?.current && progress?.total ? Math.min(92, Math.round(progress.current / progress.total * 100)) : Math.min(88, 8 + job.progress.length * 4);
|
|
538
493
|
$("#operation-progress-bar").style.width = `${ratio}%`;
|
|
539
|
-
syncTranscriptFromJob(name, job);
|
|
540
|
-
renderCommandState(job, name);
|
|
541
|
-
renderChat();
|
|
494
|
+
syncTranscriptFromJob(name, { ...job, input });
|
|
495
|
+
if (!$("#product-shell").classList.contains("hidden")) { renderCommandState(job, name); renderChat(); }
|
|
542
496
|
const screen = [...job.progress].reverse().find((entry) => entry.screen)?.screen;
|
|
543
497
|
if (screen && !state.live?.active) $("#live-screen-title").textContent = screen;
|
|
544
498
|
if (job.frame && !state.jobHasFrame) { state.jobHasFrame = true; refreshLiveFrame(); }
|
|
545
499
|
if (operationIsPending(job.status)) continue;
|
|
546
|
-
finishTranscript(name, job);
|
|
500
|
+
await finishTranscript(name, job);
|
|
547
501
|
if (job.status === "failed") throw new Error(job.error?.message || "Operation failed");
|
|
548
502
|
if (job.status !== "completed") throw new Error(`Operation ended in an unknown '${job.status}' state`);
|
|
549
503
|
$("#operation-progress-bar").style.width = "100%";
|
|
550
|
-
if (name === "ci-preview") { $("#ci-preview").textContent = job.result.workflow; $("#ci-preview").classList.remove("hidden"); }
|
|
551
504
|
if (name === "session-act" && job.result.status !== "ok") toast(job.result.detail || `The action ended with ${job.result.status}`, true);
|
|
552
505
|
else if (name === "session-save-flow") toast(`Saved ${job.result.path} as a reviewable deterministic Flow`);
|
|
553
506
|
else if (name === "gate" && job.result.passed === false) toast("The release gate blocked this revision. Tapp did not soften the result.", true);
|
|
554
|
-
else toast(
|
|
507
|
+
else if (name === "audit") toast(`Audited ${job.result.pagesAudited} page(s) — ${job.result.issueCount} distinct issue(s)`);
|
|
555
508
|
return job.result;
|
|
556
509
|
}
|
|
557
510
|
} finally {
|
|
@@ -561,182 +514,46 @@ async function runOperation(name, body = {}) {
|
|
|
561
514
|
await refreshSession();
|
|
562
515
|
await refresh();
|
|
563
516
|
} finally {
|
|
564
|
-
|
|
565
|
-
// product snapshot/frame has rendered. Hiding this earlier caused stale
|
|
566
|
-
// decisions and black loading frames to flash after successful work.
|
|
517
|
+
renderChat();
|
|
567
518
|
drawer.classList.add("hidden");
|
|
568
519
|
}
|
|
569
520
|
}
|
|
570
521
|
}
|
|
571
522
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
if (
|
|
578
|
-
|
|
523
|
+
// "What should tapp test?" — route by what was typed. The server classifies again and refuses
|
|
524
|
+
// what the mode cannot do (a hosted Studio cannot open a path on your machine).
|
|
525
|
+
async function startFromPrompt(raw) {
|
|
526
|
+
const prompt = classifyPrompt(raw);
|
|
527
|
+
if (prompt.kind === "empty") return;
|
|
528
|
+
if (prompt.kind === "url") {
|
|
529
|
+
state.promptRun = true; state.promptPlatform = "web";
|
|
530
|
+
showProduct(); activateView("overview"); renderDeviceChrome(); renderChat();
|
|
531
|
+
const result = await runOperation("audit", { url: prompt.value }, { input: prompt.value });
|
|
532
|
+
state.selectedRunId = result?.capture?.id || state.selectedRunId;
|
|
579
533
|
return;
|
|
580
534
|
}
|
|
581
|
-
if (
|
|
582
|
-
|
|
535
|
+
if (["bundle", "app", "apk"].includes(prompt.kind)) {
|
|
536
|
+
state.promptRun = true; state.promptPlatform = prompt.kind === "apk" ? "android" : "ios";
|
|
537
|
+
showProduct(); activateView("overview"); renderDeviceChrome(); renderChat();
|
|
538
|
+
const result = await runOperation("explore-build", { input: prompt.value }, { input: prompt.value });
|
|
539
|
+
state.selectedRunId = result?.capture?.id || state.selectedRunId;
|
|
583
540
|
return;
|
|
584
541
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
function normalizeInputFiles(fileList) {
|
|
592
|
-
const files = [...fileList];
|
|
593
|
-
const prefix = files[0]?.webkitRelativePath?.split("/")[0] || "repository";
|
|
594
|
-
return files.flatMap((file) => {
|
|
595
|
-
const raw = file.webkitRelativePath || file.name;
|
|
596
|
-
const parts = raw.split("/");
|
|
597
|
-
if (parts[0] === prefix && parts.length > 1) parts.shift();
|
|
598
|
-
if (!parts.length || parts.some((part) => BLOCKED_UPLOAD_DIRECTORIES.has(part))) return [];
|
|
599
|
-
return [{ file, path:parts.join("/") }];
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
async function entriesFromWebkitEntry(entry, prefix = "") {
|
|
604
|
-
if (entry.isFile) {
|
|
605
|
-
const file = await new Promise((resolve, reject) => entry.file(resolve, reject));
|
|
606
|
-
return [{ file, path:`${prefix}${entry.name}` }];
|
|
607
|
-
}
|
|
608
|
-
if (!entry.isDirectory || BLOCKED_UPLOAD_DIRECTORIES.has(entry.name)) return [];
|
|
609
|
-
const reader = entry.createReader();
|
|
610
|
-
const children = [];
|
|
611
|
-
while (true) {
|
|
612
|
-
const batch = await new Promise((resolve, reject) => reader.readEntries(resolve, reject));
|
|
613
|
-
if (!batch.length) break;
|
|
614
|
-
children.push(...batch);
|
|
615
|
-
}
|
|
616
|
-
const nextPrefix = prefix ? `${prefix}${entry.name}/` : "";
|
|
617
|
-
return (await Promise.all(children.map((child) => entriesFromWebkitEntry(child, nextPrefix)))).flat();
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
async function entriesFromDrop(event) {
|
|
621
|
-
const items = [...event.dataTransfer.items];
|
|
622
|
-
const entries = items.map((item) => item.webkitGetAsEntry?.()).filter(Boolean);
|
|
623
|
-
if (entries.length) {
|
|
624
|
-
const rootName = entries.length === 1 && entries[0].isDirectory ? entries[0].name : "repository";
|
|
625
|
-
const files = (await Promise.all(entries.map((entry) => entriesFromWebkitEntry(entry)))).flat();
|
|
626
|
-
return { name:rootName, entries:files };
|
|
627
|
-
}
|
|
628
|
-
return { name:"repository", entries:[...event.dataTransfer.files].map((file) => ({ file, path:file.name })) };
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
// The webkitdirectory input (and some drop implementations) silently exclude hidden
|
|
632
|
-
// entries, which destroys committed .tapp/ config. The File System Access picker
|
|
633
|
-
// enumerates hidden files, so it is preferred wherever it exists.
|
|
634
|
-
async function entriesFromDirectoryHandle(handle, prefix = "") {
|
|
635
|
-
const entries = [];
|
|
636
|
-
for await (const child of handle.values()) {
|
|
637
|
-
if (BLOCKED_UPLOAD_DIRECTORIES.has(child.name)) continue;
|
|
638
|
-
if (child.kind === "file") entries.push({ file:await child.getFile(), path:`${prefix}${child.name}` });
|
|
639
|
-
else if (child.kind === "directory") entries.push(...await entriesFromDirectoryHandle(child, `${prefix}${child.name}/`));
|
|
640
|
-
}
|
|
641
|
-
return entries;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
async function chooseFolder() {
|
|
645
|
-
if (!window.showDirectoryPicker) { $("#folder-input").click(); return; }
|
|
646
|
-
let handle;
|
|
647
|
-
try {
|
|
648
|
-
handle = await window.showDirectoryPicker({ mode:"read" });
|
|
649
|
-
} catch (error) {
|
|
650
|
-
if (error?.name === "AbortError") return;
|
|
651
|
-
$("#folder-input").click();
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
await uploadRepository(handle.name, await entriesFromDirectoryHandle(handle), { hiddenComplete:true });
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
async function uploadRepository(name, entries, { hiddenComplete = false } = {}) {
|
|
658
|
-
if (!entries.length) throw new Error("The selected folder contained no uploadable source files");
|
|
659
|
-
if (state.activeJob) throw new Error("Another product operation is still running");
|
|
660
|
-
state.activeJob = "repository-upload";
|
|
661
|
-
const drawer = $("#operation-drawer");
|
|
662
|
-
drawer.classList.remove("hidden");
|
|
663
|
-
$("#operation-title").textContent = "Import local repository";
|
|
664
|
-
$("#operation-progress-bar").style.width = "2%";
|
|
665
|
-
let upload;
|
|
666
|
-
try {
|
|
667
|
-
const bytes = entries.reduce((total, entry) => total + entry.file.size, 0);
|
|
668
|
-
upload = await api("/api/repositories/uploads", { method:"POST", body:JSON.stringify({ name, expectedFiles:entries.length, expectedBytes:bytes }) });
|
|
669
|
-
let cursor = 0;
|
|
670
|
-
let completed = 0;
|
|
671
|
-
const worker = async () => {
|
|
672
|
-
while (cursor < entries.length) {
|
|
673
|
-
const entry = entries[cursor++];
|
|
674
|
-
$("#operation-progress").textContent = `Uploading ${entry.path} · ${completed}/${entries.length}`;
|
|
675
|
-
const response = await fetch(apiRoute(`/api/repositories/uploads/${upload.id}/files`), { method:"PUT", headers:{ "content-type":"application/octet-stream", "x-tapp-csrf":state.csrf, "x-tapp-relative-path":encodeURIComponent(entry.path) }, body:entry.file });
|
|
676
|
-
const result = await response.json().catch(() => ({}));
|
|
677
|
-
if (!response.ok) throw new Error(result.error || `Could not upload ${entry.path}`);
|
|
678
|
-
completed += 1;
|
|
679
|
-
$("#operation-progress-bar").style.width = `${Math.max(3, Math.round(completed / entries.length * 94))}%`;
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
await Promise.all(Array.from({ length:Math.min(4, entries.length) }, worker));
|
|
683
|
-
await api(`/api/repositories/uploads/${upload.id}/complete`, { method:"POST", body:"{}" });
|
|
684
|
-
$("#operation-progress-bar").style.width = "100%";
|
|
685
|
-
const hasHiddenEntries = entries.some((entry) => entry.path.split("/").some((part) => part.startsWith(".")));
|
|
686
|
-
if (!hiddenComplete && !hasHiddenEntries) {
|
|
687
|
-
toast("Imported, but no hidden files (like .tapp/) came through — this browser's folder picker skips them. Committed Tapp config was not uploaded.", true);
|
|
688
|
-
} else {
|
|
689
|
-
toast("Repository imported into an isolated Tapp workspace");
|
|
690
|
-
}
|
|
691
|
-
} catch (error) {
|
|
692
|
-
if (upload?.id) await api(`/api/repositories/uploads/${upload.id}`, { method:"DELETE" }).catch(() => {});
|
|
693
|
-
throw error;
|
|
694
|
-
} finally {
|
|
695
|
-
state.activeJob = null;
|
|
696
|
-
drawer.classList.add("hidden");
|
|
697
|
-
await refreshSession();
|
|
698
|
-
await refresh();
|
|
699
|
-
}
|
|
700
|
-
await beginRepositoryJourney();
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
async function openGithubDialog() {
|
|
704
|
-
const dialog = $("#github-dialog");
|
|
705
|
-
dialog.showModal();
|
|
706
|
-
$("#github-repositories").innerHTML = '<div class="empty">Loading authorized repositories…</div>';
|
|
707
|
-
try {
|
|
708
|
-
const result = await api("/api/repositories/github");
|
|
709
|
-
state.githubRepositories = result.repositories || [];
|
|
710
|
-
if (result.unavailable) {
|
|
711
|
-
$("#github-repositories").innerHTML = `<div class="remediation"><strong>GitHub connection is not configured yet</strong><p>${esc(result.unavailable)}</p></div>`;
|
|
712
|
-
} else renderGithubRepositories();
|
|
713
|
-
} catch (error) {
|
|
714
|
-
$("#github-repositories").innerHTML = `<div class="remediation"><strong>GitHub needs attention</strong><p>${esc(error.message)}</p></div>`;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
function renderGithubRepositories() {
|
|
719
|
-
const query = $("#github-search").value.trim().toLowerCase();
|
|
720
|
-
const repositories = state.githubRepositories.filter((repository) => !query || repository.nameWithOwner.toLowerCase().includes(query));
|
|
721
|
-
$("#github-repositories").innerHTML = repositories.length ? repositories.map((repository) => `<button type="button" data-github-repository="${esc(repository.nameWithOwner)}"><span class="repository-icon">${esc(repository.name.slice(0, 1).toUpperCase())}</span><span><strong>${esc(repository.nameWithOwner)}</strong><small>${repository.private ? "Private" : "Public"} · ${esc(repository.permission || "authorized")} · ${esc(repository.defaultBranch || "default branch")}</small></span><em>Connect</em></button>`).join("") : '<div class="empty">No repositories match this search.</div>';
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
async function connectGithub(repository) {
|
|
725
|
-
$("#github-dialog").close();
|
|
726
|
-
await runOperation("connect-github", { repository });
|
|
727
|
-
await beginRepositoryJourney();
|
|
542
|
+
const answer = await runOperation("open", { input: prompt.value }, { input: prompt.value });
|
|
543
|
+
if (answer?.kind === "business") { toast(answer.message, true); return; }
|
|
544
|
+
await refreshSession();
|
|
545
|
+
await refresh();
|
|
546
|
+
state.selectedTargetId = "";
|
|
547
|
+
if (state.project?.connected && !state.project?.state?.inspected) await runOperation("initialize", { write:true });
|
|
728
548
|
}
|
|
729
549
|
|
|
730
|
-
function
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
if (value === "deferred") decisions.defer.push(node.dataset.id);
|
|
738
|
-
});
|
|
739
|
-
return decisions;
|
|
550
|
+
async function auditWebsite(url) {
|
|
551
|
+
const trimmed = String(url || "").trim();
|
|
552
|
+
if (!/^https?:\/\//i.test(trimmed)) { toast("Enter an http(s) URL to audit", true); return; }
|
|
553
|
+
const result = await runOperation("audit", { url: trimmed }, { input: trimmed });
|
|
554
|
+
state.selectedRunId = result?.capture?.id || state.selectedRunId;
|
|
555
|
+
activateView("runs");
|
|
556
|
+
renderRuns();
|
|
740
557
|
}
|
|
741
558
|
|
|
742
559
|
document.addEventListener("click", (event) => {
|
|
@@ -746,89 +563,51 @@ document.addEventListener("click", (event) => {
|
|
|
746
563
|
if (targetButton) {
|
|
747
564
|
state.selectedTargetId = targetButton.dataset.targetId;
|
|
748
565
|
localStorage.setItem(targetStorageKey(), state.selectedTargetId);
|
|
749
|
-
renderTargets();
|
|
566
|
+
renderTargets();
|
|
567
|
+
renderCommandState();
|
|
750
568
|
}
|
|
751
569
|
const runButton = event.target.closest("[data-run-id]");
|
|
752
|
-
if (runButton) { state.selectedRunId = runButton.dataset.runId; renderRuns(
|
|
753
|
-
const
|
|
754
|
-
if (
|
|
755
|
-
const coverageButton = event.target.closest("[data-coverage-tab]");
|
|
756
|
-
if (coverageButton) {
|
|
757
|
-
$$('[data-coverage-tab]').forEach((button) => button.classList.toggle("active", button === coverageButton));
|
|
758
|
-
$$('[data-coverage-panel]').forEach((panel) => panel.classList.toggle("active", panel.dataset.coveragePanel === coverageButton.dataset.coverageTab));
|
|
759
|
-
}
|
|
760
|
-
const githubButton = event.target.closest("[data-github-repository]");
|
|
761
|
-
if (githubButton) connectGithub(githubButton.dataset.githubRepository).catch((error) => toast(error.message, true));
|
|
762
|
-
const jump = event.target.closest("[data-jump]");
|
|
763
|
-
if (jump) {
|
|
764
|
-
const destination = jump.dataset.jump;
|
|
765
|
-
const view = ["map"].includes(destination) ? "coverage" : ["contracts", "validate"].includes(destination) ? "contracts" : destination === "evidence" ? "settings" : "overview";
|
|
766
|
-
activateView(view);
|
|
767
|
-
setTimeout(() => document.getElementById(destination)?.scrollIntoView({ behavior:"smooth", block:"start" }), 20);
|
|
768
|
-
}
|
|
769
|
-
const localButton = event.target.closest("[data-local-repository]");
|
|
770
|
-
if (localButton) api("/api/repositories/local", { method:"POST", body:JSON.stringify({ runnerId:localButton.dataset.localRunner, repositoryId:localButton.dataset.localRepository }) }).then(async () => { state.selectedTargetId = ""; await refreshSession(); await refresh(); }).catch((error) => toast(error.message, true));
|
|
570
|
+
if (runButton) { state.selectedRunId = runButton.dataset.runId; renderRuns(); }
|
|
571
|
+
const suggestion = event.target.closest("[data-prompt]");
|
|
572
|
+
if (suggestion) { const input = $("#prompt-input"); input.value = suggestion.dataset.prompt; input.focus(); input.select(); }
|
|
771
573
|
const liveControl = event.target.closest("[data-live-control]");
|
|
772
574
|
if (liveControl) {
|
|
773
575
|
const target = liveControl.dataset.liveTarget;
|
|
774
576
|
$("#live-action-target").value = target;
|
|
775
|
-
if (liveControl.dataset.liveInput === "true")
|
|
776
|
-
|
|
777
|
-
} else {
|
|
778
|
-
runOperation("session-act", { action:"tap", id:target }).catch((error) => toast(error.message, true));
|
|
779
|
-
}
|
|
577
|
+
if (liveControl.dataset.liveInput === "true") $("#live-action-text").focus();
|
|
578
|
+
else runOperation("session-act", { action:"tap", id:target }).catch((error) => toast(error.message, true));
|
|
780
579
|
}
|
|
781
580
|
});
|
|
782
581
|
|
|
783
|
-
|
|
582
|
+
document.addEventListener("submit", (event) => {
|
|
583
|
+
const audit = event.target.closest("form.audit-form");
|
|
584
|
+
if (audit) { event.preventDefault(); auditWebsite(audit.elements.url.value).catch((error) => toast(error.message, true)); return; }
|
|
585
|
+
const prompt = event.target.closest("#prompt-form");
|
|
586
|
+
if (prompt) { event.preventDefault(); startFromPrompt(prompt.elements.input.value).catch((error) => toast(error.message, true)); }
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
$$("[data-brand-home]").forEach((button) => button.addEventListener("click", () => state.project?.connected ? (showProduct(), activateView("overview")) : showPrompt()));
|
|
784
590
|
$("#command-run").addEventListener("click", () => runOperation("initialize", operationPayload({ explore:true })).catch((error) => toast(error.message, true)));
|
|
785
591
|
$("#refresh-project").addEventListener("click", () => refresh().catch((error) => toast(error.message, true)));
|
|
786
|
-
$("#change-source").addEventListener("click",
|
|
787
|
-
$("#
|
|
788
|
-
$("#browse-folder").addEventListener("click", () => chooseFolder().catch((error) => toast(error.message, true)));
|
|
789
|
-
$("#repository-drop-zone").addEventListener("keydown", (event) => { if (["Enter", " "].includes(event.key)) { event.preventDefault(); chooseFolder().catch((error) => toast(error.message, true)); } });
|
|
790
|
-
$("#folder-input").addEventListener("change", (event) => {
|
|
791
|
-
const entries = normalizeInputFiles(event.target.files);
|
|
792
|
-
const name = event.target.files[0]?.webkitRelativePath?.split("/")[0] || "repository";
|
|
793
|
-
uploadRepository(name, entries).catch((error) => toast(error.message, true));
|
|
794
|
-
event.target.value = "";
|
|
795
|
-
});
|
|
796
|
-
for (const name of ["dragenter", "dragover"]) $("#repository-drop-zone").addEventListener(name, (event) => { event.preventDefault(); $("#repository-drop-zone").classList.add("dragging"); });
|
|
797
|
-
for (const name of ["dragleave", "drop"]) $("#repository-drop-zone").addEventListener(name, (event) => { event.preventDefault(); $("#repository-drop-zone").classList.remove("dragging"); });
|
|
798
|
-
$("#repository-drop-zone").addEventListener("drop", async (event) => { try { const dropped = await entriesFromDrop(event); await uploadRepository(dropped.name, dropped.entries); } catch (error) { toast(error.message, true); } });
|
|
799
|
-
$("#connect-github").addEventListener("click", () => openGithubDialog());
|
|
800
|
-
$("#github-search").addEventListener("input", renderGithubRepositories);
|
|
592
|
+
$("#change-source").addEventListener("click", showPrompt);
|
|
593
|
+
$("#chat-toggle").addEventListener("click", () => setChatCollapsed(!state.chatCollapsed));
|
|
801
594
|
$("#repository-switcher").addEventListener("change", async (event) => {
|
|
802
|
-
if (event.target.value === "__add__") { showSourceOnboarding(); return; }
|
|
803
595
|
try { await api("/api/repositories/select", { method:"POST", body:JSON.stringify({ id:event.target.value }) }); state.selectedTargetId = ""; await refreshSession(); await refresh(); } catch (error) { toast(error.message, true); }
|
|
804
596
|
});
|
|
805
|
-
$("#inspect").addEventListener("click", () => runOperation("initialize", { write:true }).catch((error) => toast(error.message, true)));
|
|
806
597
|
$("#explore").addEventListener("click", () => runOperation("initialize", operationPayload({ explore:true })).catch((error) => toast(error.message, true)));
|
|
807
598
|
$("#start-session").addEventListener("click", () => runOperation("session-start", operationPayload()).catch((error) => toast(error.message, true)));
|
|
808
599
|
$("#refresh-live-session").addEventListener("click", () => runOperation("session-act", { action:"tree" }).catch((error) => toast(error.message, true)));
|
|
809
600
|
$("#end-session").addEventListener("click", () => runOperation("session-end").catch((error) => toast(error.message, true)));
|
|
810
|
-
$("#save-live-flow").addEventListener("click", () => { const name=$("#live-flow-name").value.trim(); if (!name) { toast("Name the Flow before saving it", true); return; } runOperation("session-save-flow",
|
|
601
|
+
$("#save-live-flow").addEventListener("click", () => { const name=$("#live-flow-name").value.trim(); if (!name) { toast("Name the Flow before saving it", true); return; } runOperation("session-save-flow", { name }).catch((error) => toast(error.message, true)); });
|
|
811
602
|
$("#live-tap").addEventListener("click", () => { const id=$("#live-action-target").value.trim(); if (!id) { toast("Choose or enter a semantic target", true); return; } runOperation("session-act", { action:"tap", id }).catch((error) => toast(error.message, true)); });
|
|
812
603
|
$("#live-type").addEventListener("click", () => { const id=$("#live-action-target").value.trim(), text=$("#live-action-text").value; if (!id) { toast("Choose or enter a field", true); return; } runOperation("session-act", { action:"type", id, text }).catch((error) => toast(error.message, true)); });
|
|
813
604
|
$("#live-back").addEventListener("click", () => runOperation("session-act", { action:"back" }).catch((error) => toast(error.message, true)));
|
|
814
605
|
$("#live-swipe").addEventListener("click", () => runOperation("session-act", { action:"swipe", direction:"up" }).catch((error) => toast(error.message, true)));
|
|
815
|
-
$("#approve-high").addEventListener("click", () => $$("#plan-list .plan-item").forEach((node) => { if (["high", "critical"].includes(node.dataset.criticality) && node.querySelector("select").value === "pending") node.querySelector("select").value = "approved"; }));
|
|
816
|
-
$("#defer-rest").addEventListener("click", () => $$("#plan-list .plan-item select").forEach((select) => { if (select.value === "pending") select.value = "deferred"; }));
|
|
817
|
-
$("#save-review").addEventListener("click", () => { const decisions = reviewDecisions(); if (![...decisions.approve, ...decisions.reject, ...decisions.defer].length) { toast("No review decisions changed"); return; } runOperation("review", decisions).catch((error) => toast(error.message, true)); });
|
|
818
|
-
$("#generate").addEventListener("click", () => runOperation("generate").catch((error) => toast(error.message, true)));
|
|
819
|
-
$("#validate-drafts").addEventListener("click", () => runOperation("validate", operationPayload()).catch((error) => toast(error.message, true)));
|
|
820
|
-
$("#promote").addEventListener("click", () => runOperation("promote").catch((error) => toast(error.message, true)));
|
|
821
606
|
$("#run-gate").addEventListener("click", () => runOperation("gate", operationPayload()).catch((error) => toast(error.message, true)));
|
|
822
|
-
$("#create-baseline").addEventListener("click", () => runOperation("baseline", operationPayload({ runId:$("#create-baseline").dataset.runId })).catch((error) => toast(error.message, true)));
|
|
823
|
-
$("#preview-ci").addEventListener("click", () => runOperation("ci-preview").catch((error) => toast(error.message, true)));
|
|
824
|
-
$("#install-ci").addEventListener("click", () => runOperation("ci-install").catch((error) => toast(error.message, true)));
|
|
825
|
-
$("#finding-filter").addEventListener("change", renderFindings);
|
|
826
607
|
|
|
827
608
|
try {
|
|
609
|
+
try { setChatCollapsed(localStorage.getItem("tapp:chat-collapsed") === "1"); } catch { /* storage may be unavailable */ }
|
|
828
610
|
await refreshSession();
|
|
829
611
|
await refresh();
|
|
830
|
-
// A repository supplied by `tapp app /path` should enter the same journey as
|
|
831
|
-
// drag/drop and GitHub: inspect immediately, then stop for an explicit target
|
|
832
|
-
// choice when detection is ambiguous.
|
|
833
612
|
if (state.project?.connected && !state.project?.state?.inspected) await runOperation("initialize", { write:true });
|
|
834
613
|
} catch (error) { toast(error.message, true); }
|