spequi 0.1.2 → 0.1.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/package.json +1 -1
- package/public/app.js +6 -5
- package/public/studio.css +8 -0
- package/public/studio.js +11 -4
- package/src/analytics.mjs +8 -6
- package/src/diff-view.mjs +1 -1
- package/src/jobs.mjs +2 -2
- package/src/preview-view.mjs +2 -2
- package/src/previews.mjs +1 -1
- package/src/server.mjs +2 -2
- package/src/studio-view.mjs +37 -6
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
detail.open = false;
|
|
7
7
|
if (restoreFocus && detail.contains(document.activeElement)) detail.querySelector('summary')?.focus();
|
|
8
8
|
}
|
|
9
|
-
for (const panel of document.querySelectorAll('.session-panel:not([hidden]), #requests-panel:not([hidden]), [data-dropdown-panel]
|
|
9
|
+
for (const panel of document.querySelectorAll('.session-panel:not([hidden]), #requests-panel:not([hidden]), [data-dropdown-panel][data-open="true"]')) {
|
|
10
10
|
const triggers = dropdownTriggers(panel);
|
|
11
11
|
if (target && (panel.contains(target) || triggers.some(button => button.contains(target)))) continue;
|
|
12
12
|
if (restoreFocus && panel.contains(document.activeElement)) triggers[0]?.focus();
|
|
@@ -30,14 +30,15 @@
|
|
|
30
30
|
document.addEventListener('beforetoggle', event => {
|
|
31
31
|
if (!event.target.matches('[data-dropdown-panel]')) return;
|
|
32
32
|
const open = event.newState === 'open';
|
|
33
|
+
event.target.dataset.open = String(open);
|
|
33
34
|
for (const trigger of dropdownTriggers(event.target)) trigger.setAttribute('aria-expanded', String(open));
|
|
34
35
|
if (open) { closeDropdowns(event.target); positionDropdown(event.target); }
|
|
35
36
|
}, true);
|
|
36
37
|
document.addEventListener('click', event => {
|
|
37
38
|
const panel = event.target.closest('[data-dropdown-choice]')?.closest('[data-dropdown-panel]');
|
|
38
|
-
if (panel?.
|
|
39
|
+
if (panel?.dataset.open === 'true') panel.hidePopover();
|
|
39
40
|
}, true);
|
|
40
|
-
window.addEventListener('resize', () => { for (const panel of document.querySelectorAll('[data-dropdown-panel]
|
|
41
|
+
window.addEventListener('resize', () => { for (const panel of document.querySelectorAll('[data-dropdown-panel][data-open="true"]')) positionDropdown(panel); });
|
|
41
42
|
let analyticsDay;
|
|
42
43
|
const viewedPreviews = new Set();
|
|
43
44
|
function recordUsage() {
|
|
@@ -55,8 +56,8 @@
|
|
|
55
56
|
try { if (sessionStorage.getItem(key)) return; sessionStorage.setItem(key, '1'); } catch {}
|
|
56
57
|
send({ event: 'file_diff_viewed', preview_id: preview, changed_file_count: Number(diff.dataset.diffCount), layout: diff.dataset.diffLayout });
|
|
57
58
|
}
|
|
58
|
-
for (const event of ['htmx:afterSettle', 'visibilitychange', 'click', 'keydown']) document.addEventListener(event, () => requestAnimationFrame(recordUsage));
|
|
59
|
-
requestAnimationFrame(recordUsage);
|
|
59
|
+
for (const event of ['htmx:afterSettle', 'visibilitychange', 'click', 'keydown']) document.addEventListener(event, () => globalThis.requestAnimationFrame?.(recordUsage));
|
|
60
|
+
globalThis.requestAnimationFrame?.(recordUsage);
|
|
60
61
|
const themeToggle = document.getElementById('theme-toggle');
|
|
61
62
|
function applyTheme(theme) {
|
|
62
63
|
const dark = theme === 'dark' || theme === 'developer';
|
package/public/studio.css
CHANGED
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
.studio-artifact-file-menu .selected small{color:inherit;opacity:.85}
|
|
55
55
|
.studio-artifact-choice-state{display:flex;align-items:center;justify-content:center;width:16px;flex-shrink:0;color:var(--accent-text)}
|
|
56
56
|
.studio-artifact-choice-state>svg{width:15px;height:15px}
|
|
57
|
+
.studio-artifact-file-help{position:sticky;bottom:-5px;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;overflow:hidden;margin:6px -5px -5px;padding:10px 12px;border-top:1px solid var(--line);background:var(--surface);color:var(--muted);font-size:10px;line-height:1.6}
|
|
57
58
|
@media(pointer:coarse){.studio-artifact-file-picker>button{min-height:44px}.studio-artifact-file-menu>a{min-height:44px}}
|
|
58
59
|
.studio-canvas-body{padding:24px 28px 36px;overflow:auto;min-height:0;flex:1;overflow-wrap:anywhere}
|
|
59
60
|
.studio-document.prose{padding:0;max-width:74ch;margin:0 auto;font-size:14px;line-height:1.8}
|
|
@@ -147,6 +148,12 @@
|
|
|
147
148
|
.studio-diff-panel .diff-file-path{display:block;font-size:10px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;line-height:1.5}
|
|
148
149
|
.studio[data-stage=implement] .studio-more{flex-shrink:0;max-height:50%;overflow:auto;margin:0;padding:10px 16px;border-top:1px solid var(--line)}
|
|
149
150
|
.studio[data-stage=implement] .studio-empty{flex:1;min-height:0;overflow:auto;padding:28px 24px}
|
|
151
|
+
.studio[data-stage=implement] .studio-implementation-empty{display:flex;flex-direction:column;align-items:flex-start;justify-content:center;max-width:none;padding:32px clamp(24px,4vw,56px)}
|
|
152
|
+
.studio-implementation-empty>svg{width:28px;height:28px;margin-bottom:18px;color:var(--accent-text);flex-shrink:0}
|
|
153
|
+
.studio-implementation-empty>h1{font-size:23px;max-width:30ch}
|
|
154
|
+
.studio-implementation-empty>p{max-width:52ch;margin:0;font-size:13px;line-height:1.75}
|
|
155
|
+
.studio-empty-actions{display:flex;flex-wrap:wrap;gap:10px;margin-top:20px}
|
|
156
|
+
.studio-implementation-empty>.studio-empty-hint{margin-top:12px;font-size:11px}
|
|
150
157
|
@container studio-code (max-width:700px){.studio-diff-panel .diff-file-tools{width:100%;justify-content:space-between;gap:6px}.studio-diff-panel .syntax-language{display:none}.studio-diff-panel .diff-file-paging{margin-left:auto}.studio-diff-panel .diff-file-identity{width:100%}}
|
|
151
158
|
@container studio-code (max-width:400px){.studio[data-stage=implement] .studio-picker>label{display:none}.studio-files-button{padding-inline:8px}.studio-diff-panel .diff-file-toolbar{padding-inline:12px;gap:8px}.studio-diff-panel .diff-file-tools{flex-wrap:wrap}.studio-diff-panel .diff-file-paging{padding-inline-start:4px}}
|
|
152
159
|
@media(pointer:coarse){.studio-changed-files .changed-file-link{min-height:44px}.studio-diff-panel .diff-icon-button{width:44px;height:44px;min-width:44px;min-height:44px}.studio-diff-panel .segmented a,.studio-diff-panel .diff-wrap{min-height:44px;display:inline-flex;align-items:center}}
|
|
@@ -204,6 +211,7 @@
|
|
|
204
211
|
.studio-progress-indicator[data-working]{border-top-color:var(--accent);animation:studio-working 1s linear infinite}
|
|
205
212
|
.studio-history>summary{display:flex;align-items:baseline;justify-content:space-between;gap:12px;cursor:pointer;padding:10px 0;border-bottom:1px solid var(--line);font-size:12px}
|
|
206
213
|
.studio-history>summary>span{font-size:10px;color:var(--muted)}.studio-history[open]>summary{margin-bottom:14px}
|
|
214
|
+
.studio-exchange:focus{outline:2px solid var(--accent);outline-offset:6px;border-radius:4px}
|
|
207
215
|
.session-indicator[data-session-state=working]{color:var(--accent-text)}
|
|
208
216
|
.session-indicator[data-session-state=working] i{width:6px;height:6px;background:none;border:1px solid var(--line);border-top-color:var(--accent);animation:studio-working 1s linear infinite}
|
|
209
217
|
.session-indicator[data-session-state=unresponsive]{color:var(--muted)}.session-indicator[data-session-state=unresponsive]:hover{background:var(--rail);color:var(--text)}
|
package/public/studio.js
CHANGED
|
@@ -161,12 +161,19 @@
|
|
|
161
161
|
remember();
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
const requestJump = event.target.closest('[data-studio-conversation-jump]');
|
|
165
|
+
if (requestJump && studio) {
|
|
166
|
+
studio.dataset.pane = 'conversation'; state().conversationExpanded = true;
|
|
167
|
+
synchronizeExpansion(); synchronizePane();
|
|
166
168
|
const thread = document.getElementById('studio-thread');
|
|
167
|
-
|
|
168
|
-
|
|
169
|
+
const request = requestJump.dataset.studioRequest ? document.getElementById(`studio-job-${requestJump.dataset.studioRequest}`) : studio.querySelector('.studio-progress')?.closest('.studio-exchange') || thread?.querySelector('.studio-exchange:last-of-type');
|
|
170
|
+
request?.querySelector('.studio-history')?.setAttribute('open', '');
|
|
171
|
+
const requestBox = request?.getBoundingClientRect?.(), threadBox = thread?.getBoundingClientRect?.();
|
|
172
|
+
if (thread) thread.scrollTop = requestBox && threadBox ? thread.scrollTop + requestBox.top - threadBox.top - 18 : thread.scrollHeight;
|
|
173
|
+
const target = request || thread;
|
|
174
|
+
target?.setAttribute('tabindex', '-1'); target?.focus({ preventScroll: true });
|
|
169
175
|
remember();
|
|
176
|
+
return;
|
|
170
177
|
}
|
|
171
178
|
if (event.target.closest('[data-studio-question-jump]') && studio) {
|
|
172
179
|
studio.dataset.pane = 'conversation'; synchronizePane();
|
package/src/analytics.mjs
CHANGED
|
@@ -10,14 +10,15 @@ const projects = new Map();
|
|
|
10
10
|
const diffFailures = new Set();
|
|
11
11
|
const run = promisify(execFile);
|
|
12
12
|
|
|
13
|
-
export function trackDiffFailure(root, previewId, reason) {
|
|
13
|
+
export async function trackDiffFailure(root, previewId, reason) {
|
|
14
14
|
const key = `${root}:${previewId}:${reason}`;
|
|
15
15
|
if (diffFailures.has(key)) return;
|
|
16
16
|
diffFailures.add(key);
|
|
17
|
-
trackEvent(root, 'file_diff_failed', { preview_id: previewId, reason });
|
|
17
|
+
await trackEvent(root, 'file_diff_failed', { preview_id: previewId, reason });
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function initializeAnalytics(root) {
|
|
21
|
+
if (process.env.SPEQUI_ANALYTICS_DISABLED === '1') return Promise.resolve(null);
|
|
21
22
|
if (!projects.has(root)) projects.set(root, (async () => {
|
|
22
23
|
const identityFile = path.join(os.homedir(), '.spequi', 'identity.json');
|
|
23
24
|
const identity = await withLock(`${identityFile}.lock`, async () => {
|
|
@@ -40,9 +41,10 @@ export function initializeAnalytics(root) {
|
|
|
40
41
|
return projects.get(root);
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
export function trackEvent(root, event, properties = {}) {
|
|
44
|
+
export async function trackEvent(root, event, properties = {}) {
|
|
45
|
+
if (process.env.SPEQUI_ANALYTICS_DISABLED === '1') return;
|
|
44
46
|
if (!['project_used', 'spec_created', 'file_diff_viewed', 'request_failed', 'file_diff_failed'].includes(event)) return;
|
|
45
|
-
|
|
47
|
+
try {
|
|
46
48
|
const metadata = await initializeAnalytics(root);
|
|
47
49
|
if (!metadata) return;
|
|
48
50
|
const occurred_at = new Date().toISOString();
|
|
@@ -57,7 +59,7 @@ export function trackEvent(root, event, properties = {}) {
|
|
|
57
59
|
if (!firstUse) return;
|
|
58
60
|
}
|
|
59
61
|
const payload = { event, user_id: metadata.user_id, project_name: path.basename(root), git_user_name: metadata.git_user_name, occurred_at, ...properties };
|
|
60
|
-
//
|
|
62
|
+
// Finish local bookkeeping before returning; network delivery is one non-blocking attempt.
|
|
61
63
|
void fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), signal: AbortSignal.timeout(5000) }).then(response => response.body?.cancel()).catch(() => {});
|
|
62
|
-
}
|
|
64
|
+
} catch {}
|
|
63
65
|
}
|
package/src/diff-view.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { trackDiffFailure } from './analytics.mjs';
|
|
|
10
10
|
export async function renderFileDiff(options, helpers) {
|
|
11
11
|
try { return await fileDiff(options, helpers); }
|
|
12
12
|
catch (error) {
|
|
13
|
-
trackDiffFailure(options.root, options.job.id, 'render_failed');
|
|
13
|
+
await trackDiffFailure(options.root, options.job.id, 'render_failed');
|
|
14
14
|
throw error;
|
|
15
15
|
}
|
|
16
16
|
}
|
package/src/jobs.mjs
CHANGED
|
@@ -34,7 +34,7 @@ export async function writeJob(root, job) {
|
|
|
34
34
|
const previous = job.status === 'failed' ? await readJSON(jobPath(root, job.id)).catch(() => null) : null;
|
|
35
35
|
await writeJSON(jobPath(root, job.id), job);
|
|
36
36
|
if (job.status === 'failed' && previous?.status !== 'failed') {
|
|
37
|
-
trackEvent(root, 'request_failed', { request_id: job.id, action: job.action, source: job.origin || 'agent', failure_stage: previous?.preparing ? 'preparation' : 'execution' });
|
|
37
|
+
await trackEvent(root, 'request_failed', { request_id: job.id, action: job.action, source: job.origin || 'agent', failure_stage: previous?.preparing ? 'preparation' : 'execution' });
|
|
38
38
|
}
|
|
39
39
|
changes.emit(await fs.realpath(root), job.id);
|
|
40
40
|
}
|
|
@@ -263,7 +263,7 @@ export async function updateJob(root, id, token, operation, message) {
|
|
|
263
263
|
job.logs.push({ at: job.updatedAt, message: String(message || operation).slice(0, 12000) });
|
|
264
264
|
job.logs = job.logs.slice(-200);
|
|
265
265
|
await writeJob(root, job);
|
|
266
|
-
if (operation === 'finish' && job.action === 'start-plan') trackEvent(root, 'spec_created', { spec_id: job.id });
|
|
266
|
+
if (operation === 'finish' && job.action === 'start-plan') await trackEvent(root, 'spec_created', { spec_id: job.id });
|
|
267
267
|
return job;
|
|
268
268
|
});
|
|
269
269
|
}
|
package/src/preview-view.mjs
CHANGED
|
@@ -13,12 +13,12 @@ export async function getPreviewContext(root, params, jobs, selected) {
|
|
|
13
13
|
let result = null;
|
|
14
14
|
try { result = job ? await previewResult(root, job.id) : null; }
|
|
15
15
|
catch (error) {
|
|
16
|
-
if (job && diffRequested) trackDiffFailure(root, job.id, 'unreadable_result');
|
|
16
|
+
if (job && diffRequested) await trackDiffFailure(root, job.id, 'unreadable_result');
|
|
17
17
|
throw error;
|
|
18
18
|
}
|
|
19
19
|
if (job && diffRequested) {
|
|
20
20
|
const reason = !result ? 'missing_result' : !Array.isArray(result.changes) ? 'invalid_result' : !result.changes.length && result.unsupported?.length ? 'unsupported_files' : !result.changes.length && !changeState(selected).complete ? 'empty_result' : null;
|
|
21
|
-
if (reason) trackDiffFailure(root, job.id, reason);
|
|
21
|
+
if (reason) await trackDiffFailure(root, job.id, reason);
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
24
|
previews, job, result, comments: job && result ? await listComments(root, job.id) : [],
|
package/src/previews.mjs
CHANGED
|
@@ -63,7 +63,7 @@ export async function previewContents(root, id, file) {
|
|
|
63
63
|
if (!change) throw new Error('File is not part of this preview');
|
|
64
64
|
const dir = basePath(root, id);
|
|
65
65
|
const before = await getBuffer(path.join(dir, 'baseline'), file), after = await getBuffer(path.join(dir, 'proposed'), file);
|
|
66
|
-
if (change.beforeHash && before === null || change.afterHash && after === null) trackDiffFailure(root, id, 'missing_snapshot');
|
|
66
|
+
if (change.beforeHash && before === null || change.afterHash && after === null) await trackDiffFailure(root, id, 'missing_snapshot');
|
|
67
67
|
return { before: before?.toString('utf8') || '', after: after?.toString('utf8') || '' };
|
|
68
68
|
}
|
|
69
69
|
export async function applyPreview(root, id) {
|
package/src/server.mjs
CHANGED
|
@@ -164,9 +164,9 @@ export async function startServer({ root = process.cwd(), port, quiet = false, r
|
|
|
164
164
|
if (![origin, `http://localhost:${server.address().port}`].includes(request.headers.origin) || !tokenMatches(request.headers['x-csrf-token'], csrf)) return send(response, 403, '<p class="error-message">Local session verification failed. Reload the viewer and retry.</p>');
|
|
165
165
|
const payload = await body(request, url.pathname.startsWith('/api/source-preview/') ? 2 * 1024 * 1024 : 100000);
|
|
166
166
|
if (url.pathname === '/api/analytics') {
|
|
167
|
-
if (payload.event === 'project_used') trackEvent(root, 'project_used');
|
|
167
|
+
if (payload.event === 'project_used') await trackEvent(root, 'project_used');
|
|
168
168
|
else if (payload.event === 'file_diff_viewed' && /^[a-zA-Z0-9_-]{1,100}$/.test(payload.preview_id || '') && Number.isInteger(payload.changed_file_count) && payload.changed_file_count > 0 && ['unified', 'split'].includes(payload.layout)) {
|
|
169
|
-
trackEvent(root, 'file_diff_viewed', { preview_id: payload.preview_id, changed_file_count: payload.changed_file_count, layout: payload.layout });
|
|
169
|
+
await trackEvent(root, 'file_diff_viewed', { preview_id: payload.preview_id, changed_file_count: payload.changed_file_count, layout: payload.layout });
|
|
170
170
|
} else return send(response, 400, '', 'application/json');
|
|
171
171
|
return send(response, 204, '');
|
|
172
172
|
}
|
package/src/studio-view.mjs
CHANGED
|
@@ -28,7 +28,7 @@ function question(job, item) {
|
|
|
28
28
|
|
|
29
29
|
export function conversation(jobs, agent = {}) {
|
|
30
30
|
const visible = jobs.filter(job => !job.hiddenAt);
|
|
31
|
-
const active = visible.find(job => ['running', 'awaiting-input'].includes(job.status));
|
|
31
|
+
const active = visible.find(job => ['running', 'awaiting-input'].includes(job.status)) || visible.find(job => job.status === 'queued');
|
|
32
32
|
jobs = visible.slice(0, 20);
|
|
33
33
|
if (active && !jobs.includes(active)) jobs = [...jobs.slice(0, 19), active];
|
|
34
34
|
const historyLink = visible.length > jobs.length ? '<p class="studio-conversation-empty">Showing recent requests. <button type="button" class="button" data-requests-toggle>View all requests</button></p>' : '';
|
|
@@ -73,9 +73,10 @@ export async function renderStudio({ root, selected, jobs, agent, params = {}, c
|
|
|
73
73
|
return available.length ? stageLink(e(item.id.replaceAll('-', ' ')), { plan: available.includes(file) ? file : available[0], created: params.created }, `studio-artifact-tab ${available.includes(file) ? 'selected' : ''}`, available.includes(file) ? 'aria-current="page"' : '') : `<span class="studio-artifact-tab" aria-disabled="true" title="${e(item.status === 'ready' ? 'Create this artifact next' : 'Complete its planning dependencies first')}">${e(item.id.replaceAll('-', ' '))}<small>Pending</small></span>`;
|
|
74
74
|
}).join('') || '';
|
|
75
75
|
const files = artifactTabs ? artifactDocuments : documents;
|
|
76
|
+
const fileHint = files.every(name => name.startsWith('specs/')) ? 'OpenSpec stores each capability in specs/<capability>/spec.md. Select one to review its requirement changes and scenarios.' : 'OpenSpec separates proposals, design, tasks, and capability specs. Select a document to review that part of the plan.';
|
|
76
77
|
const fileLabel = name => name.replace(/^specs\//, '').replace(/\/spec\.md$/, '').replace(/\.md$/, '');
|
|
77
78
|
const displayLabel = name => fileLabel(name).replace(/[-_]/g, ' ').replace(/^./, letter => letter.toUpperCase());
|
|
78
|
-
const filePicker = files.length > 1 ? `<div class="studio-artifact-file-picker"><button type="button" id="studio-plan-file" popovertarget="studio-plan-files" aria-controls="studio-plan-files" aria-expanded="false" aria-label="Choose planning document" title="${e(file)}">${icon('file')}<span>${e(displayLabel(file))}</span>${icon('down')}</button><nav id="studio-plan-files" class="studio-artifact-file-menu" popover="auto" data-dropdown-panel aria-label="Planning documents">${files.map(name => stageLink(`<span class="studio-artifact-option-copy"><strong class="studio-artifact-option-heading"><span class="studio-artifact-folder">${e(name.slice(0, name.lastIndexOf('/') + 1))}</span><span class="studio-artifact-filename">${e(name.split('/').at(-1))}</span></strong><small>${e(documentDescription(current[name] ?? previous[name]))}</small></span><span class="studio-artifact-choice-state">${name === file ? icon('check') : ''}</span>`, { plan: name, compare: params.compare }, name === file ? 'selected' : '', `aria-label="${e(name)}" data-dropdown-choice hx-sync="#workspace:replace"${name === file ? ' aria-current="page"' : ''}`)).join('')}</nav></div>` : '';
|
|
79
|
+
const filePicker = files.length > 1 ? `<div class="studio-artifact-file-picker"><button type="button" id="studio-plan-file" popovertarget="studio-plan-files" aria-controls="studio-plan-files" aria-expanded="false" aria-label="Choose planning document" aria-describedby="studio-plan-files-help" title="${e(file)}">${icon('file')}<span>${e(displayLabel(file))}</span>${icon('down')}</button><nav id="studio-plan-files" class="studio-artifact-file-menu" popover="auto" data-dropdown-panel aria-label="Planning documents">${files.map(name => stageLink(`<span class="studio-artifact-option-copy"><strong class="studio-artifact-option-heading"><span class="studio-artifact-folder">${e(name.slice(0, name.lastIndexOf('/') + 1))}</span><span class="studio-artifact-filename">${e(name.split('/').at(-1))}</span></strong><small>${e(documentDescription(current[name] ?? previous[name]))}</small></span><span class="studio-artifact-choice-state">${name === file ? icon('check') : ''}</span>`, { plan: name, compare: params.compare }, name === file ? 'selected' : '', `aria-label="${e(name)}" data-dropdown-choice hx-sync="#workspace:replace"${name === file ? ' aria-current="page"' : ''}`)).join('')}<p class="studio-artifact-file-help" id="studio-plan-files-help">${e(fileHint)}</p></nav></div>` : '';
|
|
79
80
|
toolbar = artifactTabs || filePicker ? `<div class="studio-artifact-navigation">${artifactTabs ? `<nav class="studio-artifact-tabs" aria-label="Planning artifacts">${artifactTabs}</nav>` : ''}${filePicker}</div>` : '';
|
|
80
81
|
const summary = changes.length ? `<details class="studio-change-summary" id="studio-change-summary"><summary>${changes.length} ${changes.length === 1 ? 'document changed' : 'documents changed'} in this revision</summary><ul>${changes.map(item => `<li>${stageLink(e(item.file), { stage: 'shape', plan: item.file, compare: params.compare })}<span>${e(item.type)} · +${item.additions} −${item.deletions}</span></li>`).join('')}</ul><p>Highlights mark changed sections.</p><button type="button" class="text-button" data-studio-change-jump>Show first changed section</button></details>` : '';
|
|
81
82
|
const notice = versions.pending ? '<p class="studio-notice">The agent is updating the plan. The last retained version remains visible until the request finishes.</p>' : versions.failed ? '<p class="studio-notice studio-error">The last planning request failed. Current files may include unfinished edits; review them before continuing.</p>' : '';
|
|
@@ -87,11 +88,41 @@ export async function renderStudio({ root, selected, jobs, agent, params = {}, c
|
|
|
87
88
|
const preview = await getPreviewContext(root, params, jobs, selected);
|
|
88
89
|
const { job, result, file } = preview;
|
|
89
90
|
const diffLink = (label, values, ...rest) => stageLink(label, { ...values, view: 'studio', stage: 'implement', pane: 'document' }, rest[0], `${rest[1] || ''} hx-sync="#workspace:replace"`);
|
|
90
|
-
toolbar = `<button type="button" class="button studio-files-button" id="studio-browse-files" data-studio-files aria-controls="navigation" aria-label="Browse changed files">${icon('folder')}Files <span class="tab-count">${result?.changes.length || 0}</span></button><form class="studio-picker" action="/" hx-get="/" hx-target="#workspace" hx-swap="outerHTML" hx-push-url="true" hx-trigger="change"><input type="hidden" name="change" value="${e(selected.id)}"><input type="hidden" name="view" value="studio"><input type="hidden" name="stage" value="implement"><input type="hidden" name="q" value="${e(params.q || '')}"><input type="hidden" name="pane" value="${base.pane}"><label for="studio-preview-picker">Preview</label><select name="job" id="studio-preview-picker" ${job ? '' : 'disabled'}>${preview.previews.map((item, index) => `<option value="${item.id}" ${item.id === job?.id ? 'selected' : ''}>${index === 0 ? 'Latest preview' : e(new Date(item.updatedAt).toLocaleString())}</option>`).join('')}</select>${file ? `<input type="hidden" name="file" value="${e(file.file)}">` : ''}<input type="hidden" name="mode" value="${params.mode === 'split' ? 'split' : 'unified'}"><input type="hidden" name="wrap" value="${params.wrap === '0' ? '0' : '1'}"></form
|
|
91
|
+
toolbar = job ? `<button type="button" class="button studio-files-button" id="studio-browse-files" data-studio-files aria-controls="navigation" aria-label="Browse changed files">${icon('folder')}Files <span class="tab-count">${result?.changes.length || 0}</span></button><form class="studio-picker" action="/" hx-get="/" hx-target="#workspace" hx-swap="outerHTML" hx-push-url="true" hx-trigger="change"><input type="hidden" name="change" value="${e(selected.id)}"><input type="hidden" name="view" value="studio"><input type="hidden" name="stage" value="implement"><input type="hidden" name="q" value="${e(params.q || '')}"><input type="hidden" name="pane" value="${base.pane}"><label for="studio-preview-picker">Preview</label><select name="job" id="studio-preview-picker" ${job ? '' : 'disabled'}>${preview.previews.map((item, index) => `<option value="${item.id}" ${item.id === job?.id ? 'selected' : ''}>${index === 0 ? 'Latest preview' : e(new Date(item.updatedAt).toLocaleString())}</option>`).join('')}</select>${file ? `<input type="hidden" name="file" value="${e(file.file)}">` : ''}<input type="hidden" name="mode" value="${params.mode === 'split' ? 'split' : 'unified'}"><input type="hidden" name="wrap" value="${params.wrap === '0' ? '0' : '1'}"></form>` : '';
|
|
91
92
|
const stale = job && result ? await previewPlanChanged(root, selected, job, result) : false;
|
|
92
|
-
|
|
93
|
+
let emptyTitle = 'Ready to implement', emptyDescription = 'Generate an implementation in an isolated copy, then review the file diff before applying it.';
|
|
94
|
+
let emptyAction = action('preview', agent.connected ? 'Generate implementation' : 'Queue implementation', true, 'empty-preview');
|
|
95
|
+
let emptyHint = !agent.connected ? 'Resume the Spequi skill in your coding session to process queued requests.' : '';
|
|
96
|
+
const conversationAction = (label, question = false) => `<button type="button" class="button" ${question ? 'data-studio-question-jump' : 'data-studio-conversation-jump'} data-studio-request="${e(state.pending?.id || job?.id || preview.failure?.id || '')}">${label}${icon('arrow')}</button>`;
|
|
97
|
+
if (selected.archived) {
|
|
98
|
+
emptyTitle = result ? 'No file changes in this preview' : 'No preview saved for this archived change'; emptyDescription = 'The archived planning documents remain available to review.';
|
|
99
|
+
emptyAction = stageLink('Review plan', { stage: 'shape' }, 'button'); emptyHint = '';
|
|
100
|
+
} else if (state.pending) {
|
|
101
|
+
const pending = state.pending, implementation = pending.action === 'preview';
|
|
102
|
+
emptyTitle = pending.status === 'awaiting-input' ? 'Your answer is needed' : pending.status === 'queued' && !agent.connected ? 'Waiting for your agent' : implementation ? pending.status === 'queued' ? 'Implementation queued' : 'Preparing the implementation' : 'Finish the current request';
|
|
103
|
+
emptyDescription = pending.status === 'awaiting-input' ? 'Reply to your agent in the conversation to continue.' : pending.status === 'queued' ? `${labels[pending.action] || 'Your request'} is queued. ${agent.connected ? 'Your agent will pick it up when ready.' : 'Resume the Spequi skill in your coding session to continue.'}${implementation ? ' Its file diff will appear here when ready.' : ' Generate the implementation after this request finishes.'}` : implementation ? 'Proposed changes are being prepared in an isolated copy. The file diff will appear here when ready.' : `${labels[pending.action] || 'The current request'} is in progress. Generate the implementation after it finishes.`;
|
|
104
|
+
emptyAction = conversationAction(pending.status === 'awaiting-input' ? 'Answer question' : 'View request', pending.status === 'awaiting-input'); emptyHint = '';
|
|
105
|
+
} else if (state.error || !state.readiness) {
|
|
106
|
+
emptyTitle = state.error ? 'Could not check the plan' : 'Checking the plan'; emptyDescription = state.error || 'Checking whether the required planning documents are ready for implementation.';
|
|
107
|
+
emptyAction = action('refresh', 'Refresh readiness', true, 'empty-readiness'); emptyHint = '';
|
|
108
|
+
} else if (!state.readiness.planningComplete) {
|
|
109
|
+
emptyTitle = 'Finish planning first'; emptyDescription = 'Complete the required planning documents before generating an implementation.';
|
|
110
|
+
emptyAction = stageLink('Continue planning', { stage: 'shape' }, 'button primary'); emptyHint = '';
|
|
111
|
+
} else if (result) {
|
|
112
|
+
emptyTitle = 'No file changes in this preview'; emptyDescription = 'This preview completed without producing a reviewable file diff. Read the agent result in the conversation.';
|
|
113
|
+
emptyAction = conversationAction('View agent result'); emptyHint = '';
|
|
114
|
+
} else if (job) {
|
|
115
|
+
emptyTitle = 'Preview files unavailable'; emptyDescription = 'The saved preview files are missing. Generate a fresh implementation preview to review its diff.';
|
|
116
|
+
} else if (preview.failure) {
|
|
117
|
+
emptyTitle = 'Implementation preview failed'; emptyDescription = preview.failure.result || 'The previous attempt could not produce a preview. Try again with your agent attached.';
|
|
118
|
+
} else if (!state.actions.preview?.enabled) {
|
|
119
|
+
emptyTitle = 'No implementation preview saved'; emptyDescription = state.actions.preview?.reason || 'Review the plan before requesting an implementation.';
|
|
120
|
+
emptyAction = stageLink('Review plan', { stage: 'shape' }, 'button'); emptyHint = '';
|
|
121
|
+
}
|
|
122
|
+
const emptyPreview = `<div class="studio-empty studio-implementation-empty">${icon(state.pending ? 'clock' : 'code')}<h1>${e(emptyTitle)}</h1><p>${e(emptyDescription)}</p><div class="studio-empty-actions">${emptyAction}</div>${emptyHint ? `<p class="studio-empty-hint">${e(emptyHint)}</p>` : ''}</div>`;
|
|
123
|
+
canvas = `${stale ? '<p class="studio-notice studio-error">The spec changed after this preview. Generate a fresh preview before applying.</p>' : ''}${file && preview.pending ? '<p class="studio-notice">An implementation preview is being prepared in a separate copy. Your project has not changed.</p>' : ''}${result?.unsupported.length ? `<p class="studio-notice studio-error">Unsupported files prevent application: ${e(result.unsupported.join(', '))}</p>` : ''}${file ? `<section class="diff-panel studio-diff-panel">${await renderFileDiff({ root, job, file, result, selected, params, compact: false, pathLabel: true }, { ...helpers, link: diffLink })}</section>` : emptyPreview}`;
|
|
93
124
|
const canApply = result && !selected.archived && !state.pending && !stale && !result.applied && result.changes.length && !result.unsupported.length;
|
|
94
|
-
footer = result?.applied ? stageLink(`Continue to validation ${icon('arrow')}`, { stage: 'finish' }, 'button primary') : job && result && !stale ? `<div class="studio-action"><form data-apply-form hx-post="/api/previews/${job.id}/apply" hx-target="#studio-action-feedback"><button class="button primary" type="submit" ${canApply ? '' : 'disabled'}>Apply reviewed preview</button></form>${!canApply ? `<p class="studio-blocker">${e(selected.archived ? 'This change is archived.' : state.pending ? 'Finish the current request first.' : 'No supported file changes are available to apply.')}</p>` : ''}</div>` : action('preview', 'Generate preview', true);
|
|
125
|
+
footer = !file ? '' : result?.applied ? stageLink(`Continue to validation ${icon('arrow')}`, { stage: 'finish' }, 'button primary') : job && result && !stale ? `<div class="studio-action"><form data-apply-form hx-post="/api/previews/${job.id}/apply" hx-target="#studio-action-feedback"><button class="button primary" type="submit" ${canApply ? '' : 'disabled'}>Apply reviewed preview</button></form>${!canApply ? `<p class="studio-blocker">${e(selected.archived ? 'This change is archived.' : state.pending ? 'Finish the current request first.' : 'No supported file changes are available to apply.')}</p>` : ''}</div>` : action('preview', 'Generate preview', true);
|
|
95
126
|
canvas += `<details class="studio-more" id="studio-offline-tools"><summary>Offline analysis and preview tools</summary>${await renderSourcePreviewTools(root, selected, Boolean(result), state.pending, icon)}</details>`;
|
|
96
127
|
} else {
|
|
97
128
|
const validation = state.validation;
|
|
@@ -104,5 +135,5 @@ export async function renderStudio({ root, selected, jobs, agent, params = {}, c
|
|
|
104
135
|
const revisionAction = selected.files.length ? 'revise-plan' : 'plan-next';
|
|
105
136
|
const composer = `<form ${state.pending || selected.archived ? 'hidden' : ''} class="studio-composer" data-lifecycle-form data-studio-composer id="studio-composer" action="/api/lifecycle/actions" method="post">${fields(revisionAction, selected.id)}<label for="studio-message">Describe a revision or ask about this change</label><div class="studio-message-box"><textarea name="message" id="studio-message" rows="2" maxlength="12000" required ${selected.archived || state.pending ? 'disabled' : ''} placeholder="Describe what should change, or type / for commands…"></textarea><div class="studio-composer-end"><fieldset ${selected.archived || state.pending ? 'disabled' : ''}><legend>Conversation intent</legend><label><input type="radio" name="intent" value="${revisionAction}" checked><span>${icon('file')}Revise spec</span></label><label><input type="radio" name="intent" value="explore"><span>${icon('comment')}Ask a question</span></label></fieldset><button type="submit" class="button primary" ${selected.archived || state.pending || state.error ? 'disabled' : ''}>Send ${icon('arrow')}</button></div></div>${state.error || selected.archived || state.pending ? `<p class="studio-blocker">${e(state.error || (selected.archived ? 'This change is archived and read-only.' : 'Answer or finish the current request before sending another message.'))}</p>` : ''}${feedback}</form>`;
|
|
106
137
|
const header = `<nav class="studio-stages" aria-label="Build stages">${stages.map(([id, name], index) => stageLink(`<span class="studio-stage-number">${index + 1}</span>${e(name)}`, { stage: id }, `studio-stage ${stage === id ? 'selected' : ''}`, `id="studio-stage-${id}" data-studio-stage="${id}" ${stage === id ? 'aria-current="step"' : ''}`)).join('')}</nav><div class="studio-flow-controls">${renderCommandPicker(state, { icon })}${draft?.creationId ? `<button type="button" class="button danger" data-draft-delete="${e(draft.id)}" data-has-plan="true">Delete draft</button>` : ''}</div>`;
|
|
107
|
-
return { header, content: `<section class="studio" id="studio" data-studio data-readiness-pending="${!selected.archived && !state.readiness && !state.error}" data-awaiting-input="${latestQuestion}" data-stage="${stage}" data-pane="${base.pane}"><nav class="studio-mobile-panes" aria-label="Studio panes"><button type="button" data-studio-pane="document" aria-pressed="${base.pane === 'document'}">Document</button><button type="button" data-studio-pane="conversation" aria-pressed="${base.pane === 'conversation'}">Conversation${latestQuestion ? ' · Answer needed' : ''}</button></nav><div class="studio-body" id="studio-body"><section class="studio-canvas" aria-label="${e(stages.find(([id]) => id === stage)[1])} canvas">${toolbar ? `<div class="studio-canvas-toolbar">${toolbar}</div>` : ''}<div class="studio-canvas-body" id="studio-canvas-body">${canvas}</div></section><aside class="studio-conversation" aria-label="Change conversation"><header><div><h2>Conversation</h2><span data-lifecycle-agent-caption>${latestQuestion ? 'Your answer is needed' : agent.connected ? 'Same agent session' : 'Requests wait for your agent'}</span></div><button type="button" class="button studio-expand" data-studio-expand aria-expanded="false" aria-controls="studio-body">${icon('panel')}<span data-studio-expand-label>Expand conversation</span></button></header><div class="studio-thread" id="studio-thread">${conversation(state.jobs, agent)}</div>${composer}</aside></div><footer class="studio-footer"><div><strong>${latestQuestion ? 'Reply in the conversation to continue' : stage === 'shape' ? 'Review the plan, then preview code' : stage === 'implement' ? 'Review the exact changes before applying' : selected.archived ? 'This change is archived' : 'Read the checks before archiving'}</strong><span ${latestQuestion ? 'hidden' : ''}>${state.pending ? 'The current request and its progress stay in the conversation.' : stage === 'shape' ? 'Spec revisions update documents; code generation is a separate step.' : stage === 'implement' ? 'Application uses the reviewed files and checks for conflicts.' : 'All finish actions use the existing workflow checks.'}</span></div>${latestQuestion ? '<button type="button" class="button primary" data-studio-question-jump>Answer question</button>' : footer}<div class="studio-footer-feedback" id="studio-action-feedback" role="status" aria-live="polite"></div></footer></section>` };
|
|
138
|
+
return { header, content: `<section class="studio" id="studio" data-studio data-readiness-pending="${!selected.archived && !state.readiness && !state.error}" data-awaiting-input="${latestQuestion}" data-stage="${stage}" data-pane="${base.pane}"><nav class="studio-mobile-panes" aria-label="Studio panes"><button type="button" data-studio-pane="document" aria-pressed="${base.pane === 'document'}">Document</button><button type="button" data-studio-pane="conversation" aria-pressed="${base.pane === 'conversation'}">Conversation${latestQuestion ? ' · Answer needed' : ''}</button></nav><div class="studio-body" id="studio-body"><section class="studio-canvas" aria-label="${e(stages.find(([id]) => id === stage)[1])} canvas">${toolbar ? `<div class="studio-canvas-toolbar">${toolbar}</div>` : ''}<div class="studio-canvas-body" id="studio-canvas-body">${canvas}</div></section><aside class="studio-conversation" aria-label="Change conversation"><header><div><h2>Conversation</h2><span data-lifecycle-agent-caption>${latestQuestion ? 'Your answer is needed' : agent.connected ? 'Same agent session' : 'Requests wait for your agent'}</span></div><button type="button" class="button studio-expand" data-studio-expand aria-expanded="false" aria-controls="studio-body">${icon('panel')}<span data-studio-expand-label>Expand conversation</span></button></header><div class="studio-thread" id="studio-thread">${conversation(state.jobs, agent)}</div>${composer}</aside></div><footer class="studio-footer"><div><strong>${latestQuestion ? 'Reply in the conversation to continue' : stage === 'shape' ? 'Review the plan, then preview code' : stage === 'implement' ? state.result?.changes.length ? 'Review the exact changes before applying' : 'Generate a preview to review the implementation' : selected.archived ? 'This change is archived' : 'Read the checks before archiving'}</strong><span ${latestQuestion ? 'hidden' : ''}>${state.pending ? 'The current request and its progress stay in the conversation.' : stage === 'shape' ? 'Spec revisions update documents; code generation is a separate step.' : stage === 'implement' ? state.result?.changes.length ? 'Application uses the reviewed files and checks for conflicts.' : 'Review the proposed file diff before applying changes.' : 'All finish actions use the existing workflow checks.'}</span></div>${latestQuestion ? '<button type="button" class="button primary" data-studio-question-jump>Answer question</button>' : footer}<div class="studio-footer-feedback" id="studio-action-feedback" role="status" aria-live="polite"></div></footer></section>` };
|
|
108
139
|
}
|