spequi 0.1.8 → 0.1.9
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/CHANGELOG.md +12 -0
- package/README.md +19 -9
- package/bin/spequi.mjs +5 -14
- package/docs/agent-workflow.md +19 -3
- package/package.json +1 -1
- package/public/app.css +49 -1
- package/public/app.js +68 -23
- package/public/diff.css +31 -4
- package/public/index.html +208 -179
- package/public/requests.js +14 -17
- package/public/review.css +21 -4
- package/public/review.js +85 -50
- package/public/session.js +3 -10
- package/public/studio.css +114 -28
- package/public/workflow.js +37 -4
- package/skills/spequi/SKILL.md +26 -7
- package/src/analytics.mjs +39 -10
- package/src/commands.mjs +4 -41
- package/src/comment-controls.mjs +1 -1
- package/src/comment-view.mjs +6 -5
- package/src/diff-view.mjs +1 -1
- package/src/document-view.mjs +9 -2
- package/src/drafts.mjs +15 -0
- package/src/feedback.mjs +2 -0
- package/src/jobs.mjs +60 -16
- package/src/lifecycle.mjs +11 -8
- package/src/plan-git.mjs +129 -0
- package/src/preview-view.mjs +3 -3
- package/src/previews.mjs +4 -1
- package/src/review-images.mjs +51 -0
- package/src/review-store.mjs +16 -16
- package/src/review-view.mjs +3 -2
- package/src/server.mjs +45 -20
- package/src/source-preview-view.mjs +3 -3
- package/src/spec-context-view.mjs +3 -5
- package/src/studio-view.mjs +44 -20
- package/src/updates.mjs +82 -0
- package/src/verification.mjs +6 -0
- package/src/views.mjs +34 -12
package/src/updates.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { execFile, spawn } from 'node:child_process';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { readJSON, runtime, exists, withLock } from './files.mjs';
|
|
7
|
+
import { listJobs, pendingStatuses } from './jobs.mjs';
|
|
8
|
+
|
|
9
|
+
const exec = promisify(execFile);
|
|
10
|
+
const packageRoot = fileURLToPath(new URL('../', import.meta.url));
|
|
11
|
+
const metadata = JSON.parse(await fs.readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
12
|
+
const release = value => /^\d+\.\d+\.\d+$/.test(value || '');
|
|
13
|
+
const newer = (a, b) => {
|
|
14
|
+
const left = a.split('.').map(Number), right = b.split('.').map(Number);
|
|
15
|
+
for (let i = 0; i < 3; i++) if (left[i] !== right[i]) return left[i] > right[i];
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
async function npmEntry() {
|
|
20
|
+
const candidates = [process.env.npm_execpath, path.join(path.dirname(process.execPath), 'node_modules/npm/bin/npm-cli.js')];
|
|
21
|
+
for (const directory of (process.env.PATH || '').split(path.delimiter).filter(Boolean)) {
|
|
22
|
+
candidates.push(path.join(directory, 'node_modules/npm/bin/npm-cli.js'));
|
|
23
|
+
for (const name of ['npm', 'npm.cmd']) {
|
|
24
|
+
const resolved = await fs.realpath(path.join(directory, name)).catch(() => null);
|
|
25
|
+
if (resolved?.endsWith('npm-cli.js')) candidates.push(resolved);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (const file of candidates) if (file && await fs.stat(file).then(stat => stat.isFile(), () => false)) return file;
|
|
29
|
+
throw new Error('npm could not be found. Install Node.js with npm and retry.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function checkForUpdate(root) {
|
|
33
|
+
const current = metadata.version;
|
|
34
|
+
try {
|
|
35
|
+
const { stdout } = await exec(process.execPath, [await npmEntry(), 'view', `${metadata.name}@latest`, 'version', '--json', '--fetch-retries=0', '--fetch-timeout=2500'], { cwd: root, timeout: 4000, maxBuffer: 4096, windowsHide: true });
|
|
36
|
+
const latest = JSON.parse(stdout);
|
|
37
|
+
if (!release(latest) || !release(current)) throw new Error('Invalid release version');
|
|
38
|
+
return { current, latest, available: newer(latest, current), development: await exists(path.join(packageRoot, '.git')) };
|
|
39
|
+
} catch { return { current, available: false, unavailable: true }; }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function updateRuntime(root) {
|
|
43
|
+
if (await exists(path.join(packageRoot, '.git'))) throw new Error('This runtime is a local source checkout. Update the checkout yourself, then run node bin/spequi.mjs init; published updates will not replace local code.');
|
|
44
|
+
return withLock(runtime(root, 'update.lock'), async () => {
|
|
45
|
+
const connection = await readJSON(runtime(root, 'server.json'));
|
|
46
|
+
if (connection?.pid) {
|
|
47
|
+
let live = false;
|
|
48
|
+
try { process.kill(connection.pid, 0); live = true; } catch (error) { if (error.code === 'EPERM') live = true; }
|
|
49
|
+
if (live) throw new Error('Stop this project’s Spequi server before updating, then restart it and reload the Spequi skill. Requests and project state are retained.');
|
|
50
|
+
}
|
|
51
|
+
if ((await listJobs(root)).some(job => pendingStatuses.includes(job.status) && job.status !== 'queued')) throw new Error('Finish or resolve the active request before updating. Its saved state has been kept.');
|
|
52
|
+
for (const name of ['cli.mjs', 'server.mjs']) {
|
|
53
|
+
const content = await fs.readFile(runtime(root, name), 'utf8').catch(error => { if (error.code === 'ENOENT') return ''; throw error; });
|
|
54
|
+
if (content && !content.startsWith('// Generated by spequi.')) throw new Error(`Custom .spequi/${name} was preserved. Reconcile it with the generated launcher before updating.`);
|
|
55
|
+
}
|
|
56
|
+
const shipped = await fs.readFile(new URL('../skills/spequi/SKILL.md', import.meta.url), 'utf8');
|
|
57
|
+
for (const relative of ['.agents/skills/spequi/SKILL.md', '.gigacode/skills/spequi/SKILL.md']) {
|
|
58
|
+
const content = await fs.readFile(path.join(root, relative), 'utf8').catch(error => { if (error.code === 'ENOENT') return ''; throw error; });
|
|
59
|
+
if (content && content !== shipped) throw new Error(`Local changes in ${relative} were preserved. Use the project’s pinned runtime to update, or reconcile those changes first.`);
|
|
60
|
+
}
|
|
61
|
+
const wrappers = {
|
|
62
|
+
'.claude/commands/spequi.md': '---\nname: spequi\ndescription: Initialize and operate Spequi in the current agent session\n---\n\nRead and follow .agents/skills/spequi/SKILL.md. User arguments: $ARGUMENTS\n',
|
|
63
|
+
'.gigacode/commands/spequi.md': '---\ndescription: Initialize and operate Spequi in the current agent session\n---\n\nRead and follow .gigacode/skills/spequi/SKILL.md. User arguments: {{args}}\n'
|
|
64
|
+
};
|
|
65
|
+
for (const [relative, expected] of Object.entries(wrappers)) {
|
|
66
|
+
const content = await fs.readFile(path.join(root, relative), 'utf8').catch(error => { if (error.code === 'ENOENT') return ''; throw error; });
|
|
67
|
+
if (content && content !== expected) throw new Error(`Custom ${relative} was preserved. Reconcile the command wrapper before updating.`);
|
|
68
|
+
}
|
|
69
|
+
const cli = await npmEntry();
|
|
70
|
+
const latest = await checkForUpdate(root);
|
|
71
|
+
if (latest.unavailable) throw new Error('Could not check the configured npm registry. Your current runtime is unchanged; retry when online or fix the project’s npm registry settings.');
|
|
72
|
+
if (!latest.available && newer(metadata.version, latest.latest)) throw new Error('The configured registry has an older release. Current runtime retained.');
|
|
73
|
+
await new Promise((resolve, reject) => {
|
|
74
|
+
const child = spawn(process.execPath, [cli, 'exec', '--yes', '--prefer-online', `--package=${metadata.name}@${latest.latest}`, '--', metadata.name, 'init', '--root', root], { cwd: root, stdio: 'inherit', shell: false });
|
|
75
|
+
child.once('error', reject);
|
|
76
|
+
child.once('exit', code => code === 0 ? resolve() : reject(new Error('Update failed. Project requests and data were retained; retry the update.')));
|
|
77
|
+
});
|
|
78
|
+
const config = await readJSON(runtime(root, 'config.json'));
|
|
79
|
+
if (config?.viewerVersion !== latest.latest) throw new Error('Could not confirm the new runtime. Re-run initialization with the intended package version.');
|
|
80
|
+
return { version: config.viewerVersion, next: 'Start node .spequi/server.mjs, reload the Spequi skill from disk, and reattach the agent. Existing requests are retained.' };
|
|
81
|
+
}, { waitMs: 0 });
|
|
82
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// A heading or generic completion message is not a verification report.
|
|
2
|
+
export function hasVerificationReport(value) {
|
|
3
|
+
if (typeof value !== 'string') return false;
|
|
4
|
+
const body = value.split(/\r?\n/).filter(line => !/^\s*(?:#{1,6}\s|[-=_]{3,}\s*$)/.test(line)).join('\n').trim();
|
|
5
|
+
return body.length >= 40 && !/^(?:verify|verification)(?:\s+report)?\s*:[^\n]*$|^(?:completed?|done|success)[.!]?$/i.test(body);
|
|
6
|
+
}
|
package/src/views.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isPlanningDraft } from './drafts.mjs';
|
|
2
|
+
import { exists, readJSON, runtime } from './files.mjs';
|
|
1
3
|
import path from 'node:path';
|
|
2
4
|
import { randomUUID } from 'node:crypto';
|
|
3
5
|
import { renderReviewMarkdown, renderReviewSource, renderDocumentDiscussion } from './document-view.mjs';
|
|
@@ -33,6 +35,10 @@ const paths = {
|
|
|
33
35
|
spark: '<path d="m12 3 2.5 6.5L21 12l-6.5 2.5L12 21l-2.5-6.5L3 12l6.5-2.5Z"/>',
|
|
34
36
|
plus: '<path d="M12 5v14M5 12h14"/>',
|
|
35
37
|
download: '<path d="M12 3v12m-4-4 4 4 4-4M4 16v5h16v-5"/>',
|
|
38
|
+
attachment: '<path d="m21 11-8 8a6 6 0 0 1-8.5-8.5l9-9a4 4 0 0 1 5.7 5.7l-9 9a2 2 0 0 1-2.9-2.9l8-8"/>',
|
|
39
|
+
image: '<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8" cy="8" r="1.5"/><path d="m3 17 5-5 4 4 3-3 6 6"/>',
|
|
40
|
+
settings: '<path d="M12.00 4.20 13.35 4.32 15.42 2.60 17.00 3.34 17.01 6.02 17.98 6.99 18.75 8.10 19.33 9.33 21.85 10.26 22.00 12.00 19.68 13.35 19.33 14.67 18.75 15.90 17.98 17.01 18.43 19.66 17.00 20.66 14.67 19.33 13.35 19.68 12.00 19.80 10.65 19.68 8.58 21.40 7.00 20.66 6.99 17.98 6.02 17.01 5.25 15.90 4.67 14.67 2.15 13.74 2.00 12.00 4.32 10.65 4.67 9.33 5.25 8.10 6.02 6.99 5.57 4.34 7.00 3.34 9.33 4.67 10.65 4.32Z"/><circle cx="12" cy="12" r="3"/>',
|
|
41
|
+
privacy: '<path d="M12 3 3 7v5c0 5 9 9 9 9s9-4 9-9V7l-9-4Z"/><path d="m8 12 3 3 5-6"/>',
|
|
36
42
|
bell: '<path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9"/><path d="M10 21h4"/>',
|
|
37
43
|
book: '<path d="M12 5C9 2 4 3 2 4v16c3-2 7-2 10 0 3-2 7-2 10 0V4c-2-1-7-2-10 1Zm0 0v15"/>',
|
|
38
44
|
};
|
|
@@ -41,8 +47,8 @@ function url(params) { const query = new URLSearchParams(Object.entries(params).
|
|
|
41
47
|
function link(label, params, className = '', extra = '') { return `<a href="${e(url(params))}" hx-get="${e(url(params))}" hx-target="#workspace" hx-swap="outerHTML" hx-push-url="true" class="${className}" ${extra}>${label}</a>`; }
|
|
42
48
|
function badge(label, type = '') { return `<span class="badge ${type}">${e(label)}</span>`; }
|
|
43
49
|
function progressBar(progress) { return `<span class="progress-track" aria-label="${progress.done} of ${progress.total} tasks complete"><span style="width:${progress.total ? Math.round(progress.done / progress.total * 100) : 0}%"></span></span>`; }
|
|
44
|
-
export function shell(content, data, csrf, params = {}) {
|
|
45
|
-
return `<!doctype html><html lang="en" data-theme="enterprise"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="csrf-token" content="${csrf}"><title>${e(data.name)} · Spequi</title><link rel="icon" href="/favicon.svg" type="image/svg+xml"><script src="/assets/app.js" defer></script><script src="/assets/review.js" defer></script><script src="/assets/workflow.js" defer></script><script src="/assets/studio.js" defer></script><script src="/assets/session.js" defer></script><script src="/assets/requests.js" defer></script><link rel="stylesheet" href="/assets/fonts.css"><link rel="stylesheet" href="/assets/app.css"><link rel="stylesheet" href="/assets/diff.css"><link rel="stylesheet" href="/assets/review.css"><link rel="stylesheet" href="/assets/studio.css"></head><body><a class="skip-link" href="#document">Skip to document</a><header class="topbar"><div class="topbar-start"><div class="brand">${icon('layers')}<span>Spequi</span><span class="local-pill">LOCAL</span></div></div><div class="topbar-end"><a class="tool-docs-link" href="/docs" target="_blank" rel="noopener noreferrer" aria-label="Spequi docs and landing page (opens in a new tab)" title="Docs and getting started">${icon('book')}<span>Docs</span></a><button type="button" class="button requests-toggle" data-requests-toggle aria-controls="requests-panel" aria-expanded="false"><span class="requests-icon" aria-hidden="true">${icon('clock')}<span class="requests-attention" data-request-count hidden></span></span>Requests</button><button type="button" id="agent-indicator" class="session-indicator" data-session-toggle aria-expanded="false" aria-controls="agent-connections"><span class="session-agent-icon" aria-hidden="true">${icon('agent')}<i></i></span><span data-session-label>Checking agent</span><span class="session-chevron" aria-hidden="true">${icon('chevron')}</span></button><button type="button" class="session-mcp-button" aria-label="MCP connections" data-session-toggle aria-expanded="false" aria-controls="mcp-connections">${icon('plug')}<span id="mcp-count">MCPs</span></button><button type="button" class="notification-toggle icon-button" data-notification-toggle popovertarget="notification-settings" aria-controls="notification-settings" aria-expanded="false" aria-label="Desktop notifications" title="Notifications for completed work and questions">${icon('bell')}</button><button type="button" id="theme-toggle" class="theme-toggle" aria-label="Switch to dark mode" title="Switch to dark mode"><span class="theme-icon-dark">${icon('moon')}</span><span class="theme-icon-light">${icon('sun')}</span></button></div></header><aside id="agent-connections" class="session-panel agent-panel" aria-label="Agent connection" hidden><header><h2>Agent</h2><button type="button" class="icon-button" data-session-close aria-label="Close agent details">${icon('close')}</button></header><div class="agent-summary"><span class="agent-avatar" aria-hidden="true">${icon('agent')}</span><div class="agent-identity"><strong id="session-agent-name">Spequi Agent</strong><p id="session-agent-caption">Checking connection</p></div><span id="session-state" class="agent-state-badge">Checking</span></div><dl class="agent-facts"><div><dt>Last seen</dt><dd><time id="session-last-seen">Not yet</time></dd></div><div><dt>Queue</dt><dd id="session-queue-state">Checking</dd></div></dl><section class="agent-current" data-session-current aria-label="Current request" hidden><div><strong id="session-current-change"></strong><span id="session-current-state"></span></div><p id="session-current-hint"></p></section><section id="session-question" aria-label="Agent question" hidden></section><form id="session-cancel-request" data-lifecycle-form method="post" hidden><p>Cancelling frees the queue and keeps existing files.</p><button type="submit" class="button">Cancel request</button><div data-lifecycle-feedback role="status" aria-live="polite"></div></form><section id="session-recovery" class="agent-guidance" aria-label="Next step" hidden><p id="session-recovery-message"></p><p id="session-recovery-detail" hidden></p></section><footer class="agent-panel-actions"><button type="button" class="button" data-session-refresh>Refresh status</button><button type="button" class="text-button" data-session-open-requests>View requests ${icon('arrow')}</button></footer><p data-session-check-result role="status" aria-live="polite" aria-atomic="true"></p></aside><aside id="mcp-connections" class="session-panel mcp-panel" aria-label="MCP connections" hidden><header><div><h2>MCP connections</h2><span id="mcp-panel-state" class="mcp-panel-state">Not reported</span></div><button type="button" class="icon-button" data-session-close aria-label="Close MCP connections">${icon('close')}</button></header><div class="mcp-panel-body"><p id="mcp-report-summary" hidden></p><div class="mcp-empty" data-mcp-empty><span class="mcp-empty-icon" aria-hidden="true">${icon('plug')}</span><div><h3 id="mcp-empty-title">Waiting for connection details</h3><p id="mcp-empty-description">Your agent hasn’t shared its MCP connections yet.</p></div></div><ul id="session-mcps"></ul></div><footer class="mcp-panel-footer"><button type="button" class="text-button" data-mcp-refresh>Refresh status</button><time id="mcp-report-date">Not reported yet</time></footer></aside><aside id="notification-settings" class="notification-settings" popover="auto" data-dropdown-panel data-dropdown-width="320" aria-labelledby="notification-title"><h2 id="notification-title">Stay in the loop</h2><p>Get a desktop notification when your plan or file diff is ready, your agent needs an answer, or a request fails while you’re in another tab.</p><p class="notification-note">Keep this workspace open to receive alerts.</p><p data-notification-message role="status" aria-live="polite"></p><button type="button" class="button primary" data-enable-notifications hidden>Enable notifications</button></aside><aside id="requests-panel" class="requests-panel" aria-label="Requests" hidden><header><h2>Requests</h2><div class="requests-tools"><select data-request-filter aria-label="Filter requests"><option value="inbox" selected>Inbox</option><option value="all">All history</option><option value="active">Active history</option><option value="completed">Completed</option><option value="failed">Failed</option><option value="cancelled">Cancelled</option></select><button type="button" class="icon-button" data-requests-close aria-label="Close requests">${icon('close')}</button></div></header><div data-requests-feedback role="status" aria-live="polite"></div><div data-request-list></div><footer hidden><span data-request-pagination></span><nav data-request-pages aria-label="Request pages" hidden><button class="icon-button" type="button" data-request-page="previous" aria-label="Previous page" title="Previous page">${icon('chevron')}</button><button class="icon-button" type="button" data-request-page="next" aria-label="Next page" title="Next page">${icon('chevron')}</button></nav></footer></aside><dialog id="request-delete-dialog" aria-labelledby="request-delete-title" aria-describedby="request-delete-description request-delete-retention"><form method="dialog"><h2 id="request-delete-title">Delete this request?</h2><p id="request-delete-description">Remove it from request history.</p><label><input type="checkbox" name="reviewData" checked> Also delete its saved preview and that preview’s comments and exports</label><p id="request-delete-retention">Project files, OpenSpec documents, and applied-file backups are kept.</p><div class="dialog-actions"><button value="cancel" class="button">Keep request</button><button value="confirm" class="button danger-solid">Delete request</button></div></form></dialog><dialog id="draft-delete-dialog" aria-labelledby="draft-delete-title" aria-describedby="draft-delete-description draft-delete-retention"><form method="dialog"><h2 id="draft-delete-title">Delete this draft?</h2><p id="draft-delete-description">The saved idea will be removed.</p><label data-delete-plan-choice><input type="checkbox" name="deletePlan"> Also delete the planning files generated from this draft</label><p id="draft-delete-retention">Cancel active requests before deleting. Application source files are kept.</p><div class="dialog-actions"><button value="cancel" class="button">Keep draft</button><button value="confirm" class="button danger-solid">Delete draft</button></div></form></dialog>${content}<div id="toast" role="status" aria-live="polite" aria-atomic="true"></div><dialog id="apply-dialog"><form method="dialog"><h2>Apply this preview?</h2><p>The reviewed files will be written to your project. If any affected file has changed since the preview, the whole operation will stop.</p><div class="dialog-actions"><button value="cancel">Keep reviewing</button><button value="confirm" class="button primary">Apply reviewed files</button></div></form></dialog></body></html>`;
|
|
50
|
+
export function shell(content, data, csrf, params = {}, consent = {}) {
|
|
51
|
+
return `<!doctype html><html lang="en" data-theme="enterprise"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="csrf-token" content="${csrf}"><title>${e(data.name)} · Spequi</title><link rel="icon" href="/favicon.svg" type="image/svg+xml"><script src="/assets/app.js" defer></script><script src="/assets/review.js" defer></script><script src="/assets/workflow.js" defer></script><script src="/assets/studio.js" defer></script><script src="/assets/session.js" defer></script><script src="/assets/requests.js" defer></script><link rel="stylesheet" href="/assets/fonts.css"><link rel="stylesheet" href="/assets/app.css"><link rel="stylesheet" href="/assets/diff.css"><link rel="stylesheet" href="/assets/review.css"><link rel="stylesheet" href="/assets/studio.css"></head><body><a class="skip-link" href="#document">Skip to document</a><header class="topbar"><div class="topbar-start"><div class="brand">${icon('layers')}<span>Spequi</span><span class="local-pill">LOCAL</span></div></div><div class="topbar-end"><button type="button" class="button requests-toggle" data-requests-toggle aria-controls="requests-panel" aria-expanded="false"><span class="requests-icon" aria-hidden="true">${icon('clock')}<span class="requests-attention" data-request-count hidden></span></span><span>Requests</span><span class="request-answer-marker" data-request-answer hidden></span></button><button type="button" id="agent-indicator" class="session-indicator" data-session-toggle aria-expanded="false" aria-controls="agent-connections"><span class="session-agent-icon" aria-hidden="true">${icon('agent')}<i></i></span><span data-session-label>Checking agent</span><span class="session-chevron" aria-hidden="true">${icon('chevron')}</span></button><button type="button" class="session-mcp-button" aria-label="MCP connections" data-session-toggle aria-expanded="false" aria-controls="mcp-connections">${icon('plug')}<span id="mcp-count">MCPs</span></button><button type="button" class="icon-button settings-toggle" data-privacy-toggle popovertarget="workspace-settings" aria-controls="workspace-settings" aria-expanded="false" aria-label="Settings" title="Settings">${icon('settings')}<span class="privacy-attention-dot" data-privacy-dot ${consent.choice ? 'hidden' : ''} aria-hidden="true"></span></button></div></header><aside id="agent-connections" class="session-panel agent-panel" aria-label="Agent connection" hidden><header><h2>Agent</h2><button type="button" class="icon-button" data-session-close aria-label="Close agent details">${icon('close')}</button></header><div class="agent-summary"><span class="agent-avatar" aria-hidden="true">${icon('agent')}</span><div class="agent-identity"><strong id="session-agent-name">Spequi Agent</strong><p id="session-agent-caption">Checking connection</p></div><span id="session-state" class="agent-state-badge">Checking</span></div><dl class="agent-facts"><div><dt>Last seen</dt><dd><time id="session-last-seen">Not yet</time></dd></div><div><dt>Queue</dt><dd id="session-queue-state">Checking</dd></div></dl><section class="agent-current" data-session-current aria-label="Current request" hidden><div><strong id="session-current-change"></strong><span id="session-current-state"></span></div><p id="session-current-hint"></p></section><section id="session-question" aria-label="Agent question" hidden></section><form id="session-cancel-request" data-lifecycle-form method="post" hidden><p>Cancelling frees the queue and keeps existing files.</p><button type="submit" class="button">Cancel request</button><div data-lifecycle-feedback role="status" aria-live="polite"></div></form><section id="session-recovery" class="agent-guidance" aria-label="Next step" hidden><p id="session-recovery-message"></p><p id="session-recovery-detail" hidden></p></section><footer class="agent-panel-actions"><button type="button" class="button" data-session-refresh>Refresh status</button><button type="button" class="text-button" data-session-open-requests>${icon('clock')} View requests</button></footer><p data-session-check-result role="status" aria-live="polite" aria-atomic="true"></p></aside><aside id="mcp-connections" class="session-panel mcp-panel" aria-label="MCP connections" hidden><header><div><h2>MCP connections</h2><span id="mcp-panel-state" class="mcp-panel-state">Not reported</span></div><button type="button" class="icon-button" data-session-close aria-label="Close MCP connections">${icon('close')}</button></header><div class="mcp-panel-body"><p id="mcp-report-summary" hidden></p><div class="mcp-empty" data-mcp-empty><span class="mcp-empty-icon" aria-hidden="true">${icon('plug')}</span><div><h3 id="mcp-empty-title">Waiting for connection details</h3><p id="mcp-empty-description">Your agent hasn’t shared its MCP connections yet.</p></div></div><ul id="session-mcps"></ul></div><footer class="mcp-panel-footer"><button type="button" class="text-button" data-mcp-refresh>Refresh status</button><time id="mcp-report-date">Not reported yet</time></footer></aside><aside id="workspace-settings" class="settings-panel" popover="auto" data-dropdown-panel data-dropdown-width="360" aria-labelledby="settings-title"><header><h2 id="settings-title">Settings</h2><button type="button" class="icon-button" popovertarget="workspace-settings" popovertargetaction="hide" aria-label="Close settings">${icon('close')}</button></header><a class="settings-link" data-dropdown-choice href="/docs" target="_blank" rel="noopener noreferrer" aria-label="Spequi docs and landing page (opens in a new tab)" title="Docs and getting started">${icon('book')}<span>Docs</span></a><button type="button" id="theme-toggle" class="theme-toggle settings-theme" aria-label="Switch to dark mode" title="Switch to dark mode"><span class="theme-icon-dark">${icon('moon')}</span><span class="theme-icon-light">${icon('sun')}</span><span data-theme-label>Dark mode</span></button><details id="settings-notifications" name="workspace-settings"><summary>${icon('bell')}Notifications${icon('chevron')}</summary><section id="notification-settings" class="notification-settings"><p>Get a desktop notification when your plan or file diff is ready, your agent needs an answer, or a request fails while you’re in another tab.</p><p class="notification-note">Keep this workspace open to receive alerts.</p><p data-notification-message role="status" aria-live="polite"></p><button type="button" class="button primary" data-enable-notifications hidden>Enable notifications</button></section></details><details id="settings-sharing" name="workspace-settings"><summary>${icon('privacy')}Usage sharing${icon('chevron')}</summary><section id="privacy-settings" class="privacy-settings" data-consent-pending="${!consent.choice}"><p>Choose what Spequi may send. Nothing is shared until you choose; your choice applies only to <strong>${e(data.name)}</strong>.</p><form data-consent-form><fieldset><legend>Usage data preference</legend>${[['off', 'Do not share', 'No usage or failure events leave this project.'], ['anonymous', 'Share usage without names', 'Includes action counts, CLI name and a random machine identifier.'], ['identity', 'Share usage with names', 'Also includes this project’s folder name and Git user.name.']].map(([value, label, description]) => `<label><input type="radio" name="choice" value="${value}" required ${consent.choice === value ? 'checked' : ''}><span><strong>${label}</strong><small>${description}</small></span></label>`).join('')}</fieldset><p class="privacy-note">Source code, prompts, comments and credentials are never included. Change this preference here at any time.</p><div data-consent-feedback role="status" aria-live="polite"></div><button type="submit" class="button primary">Save preference</button></form></section></details><p class="settings-update" data-update-note>Running Spequi. Update checks run on startup.</p></aside><aside id="requests-panel" class="requests-panel" aria-label="Requests" hidden><header><h2>Requests</h2><div class="requests-tools"><select data-request-filter aria-label="Filter requests"><option value="inbox" selected>Inbox</option><option value="all">All history</option><option value="active">Active history</option><option value="completed">Completed</option><option value="failed">Failed</option><option value="cancelled">Cancelled</option></select><button type="button" class="icon-button" data-requests-close aria-label="Close requests">${icon('close')}</button></div></header><div data-requests-feedback role="status" aria-live="polite"></div><div data-request-list></div><footer hidden><span data-request-pagination></span><nav data-request-pages aria-label="Request pages" hidden><button class="icon-button" type="button" data-request-page="previous" aria-label="Previous page" title="Previous page">${icon('chevron')}</button><button class="icon-button" type="button" data-request-page="next" aria-label="Next page" title="Next page">${icon('chevron')}</button></nav></footer></aside><dialog id="request-delete-dialog" aria-labelledby="request-delete-title" aria-describedby="request-delete-description request-delete-retention"><form method="dialog"><h2 id="request-delete-title">Delete this request?</h2><p id="request-delete-description">Remove it from request history.</p><label><input type="checkbox" name="reviewData" checked> Also delete its saved preview and that preview’s comments and exports</label><p id="request-delete-retention">Project files, OpenSpec documents, and applied-file backups are kept.</p><div class="dialog-actions"><button value="cancel" class="button">Keep request</button><button value="confirm" class="button danger-solid">Delete request</button></div></form></dialog><dialog id="draft-delete-dialog" aria-labelledby="draft-delete-title" aria-describedby="draft-delete-description draft-delete-retention"><form method="dialog"><h2 id="draft-delete-title">Delete this draft?</h2><p id="draft-delete-description">The saved idea will be removed.</p><label data-delete-plan-choice><input type="checkbox" name="deletePlan"> Also delete the planning files generated from this draft</label><p id="draft-delete-retention">Cancel active requests before deleting. Application source files are kept.</p><div class="dialog-actions"><button value="cancel" class="button">Keep draft</button><button value="confirm" class="button danger-solid">Delete draft</button></div></form></dialog>${content}<div id="toast" role="status" aria-live="polite" aria-atomic="true"></div><dialog id="plan-push-dialog" aria-labelledby="plan-push-title" aria-describedby="plan-push-note"><form method="dialog"><h2 id="plan-push-title">Push spec files?</h2><dl class="plan-push-facts"><div><dt>Branch</dt><dd data-push-branch></dd></div><div data-push-message-row><dt>Commit message</dt><dd data-push-message></dd></div></dl><details data-push-files-section><summary data-push-file-count></summary><ul data-push-files></ul></details><p id="plan-push-note">Earlier commits on this branch will be pushed too. Unrelated staged edits are kept.</p><div class="dialog-actions"><button value="cancel" class="button" autofocus>Keep editing</button><button value="confirm" class="button primary" data-push-confirm>Commit & push</button></div></form></dialog><dialog id="apply-dialog"><form method="dialog"><h2>Apply this preview?</h2><p>The reviewed files will be written to your project. If any affected file has changed since the preview, the whole operation will stop.</p><div class="dialog-actions"><button value="cancel">Keep reviewing</button><button value="confirm" class="button primary">Apply reviewed files</button></div></form></dialog></body></html>`;
|
|
46
52
|
}
|
|
47
53
|
export async function workspace({ root, data, params, jobs, agent, drafts = [], getReadiness, compact = true }) {
|
|
48
54
|
if (params.view === 'studio' && params.stage === 'implement') params = { ...params, view: 'preview', stage: undefined, pane: undefined };
|
|
@@ -62,9 +68,20 @@ export async function workspace({ root, data, params, jobs, agent, drafts = [],
|
|
|
62
68
|
const currentDraft = draft || { id: typeof params.draft === 'string' && /^[a-zA-Z0-9_-]{1,128}$/.test(params.draft) ? params.draft : randomUUID() };
|
|
63
69
|
const draftChanges = new Set(drafts.filter(item => item.creationId).map(item => item.change));
|
|
64
70
|
const archivedTarget = params.change && data.changes.filter(change => change.archived && /^\d{4}-\d{2}-\d{2}-/.test(change.id) && change.id.slice(11) === params.change).sort((a, b) => b.id.localeCompare(a.id))[0];
|
|
65
|
-
const selected = params.view === 'studio' && params.new === '1' ? null : data.changes.find(change => change.id === params.change) || archivedTarget || (!params.doc ? data.changes.find(change => !change.archived) || data.changes[0] : null);
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
const selected = params.doc && data.specs.some(spec => spec.file === params.doc) ? null : params.view === 'studio' && params.new === '1' ? null : data.changes.find(change => change.id === params.change) || archivedTarget || (!params.doc ? data.changes.find(change => !change.archived) || data.changes[0] : null);
|
|
72
|
+
let doc = params.doc && data.files.includes(params.doc) ? params.doc : selected?.files[0] || data.specs[0]?.file;
|
|
73
|
+
let view = ['rendered', 'source', 'specs', 'preview', 'studio', 'workflow'].includes(params.view) ? params.view : 'rendered';
|
|
74
|
+
const building = await isPlanningDraft(root, selected, drafts);
|
|
75
|
+
if (building && !['studio', 'workflow'].includes(view)) {
|
|
76
|
+
view = 'studio';
|
|
77
|
+
params = { ...params, view, stage: 'shape', plan: selected.files.includes(doc) ? doc.split('/').slice(3).join('/') : params.plan };
|
|
78
|
+
}
|
|
79
|
+
if (selected && view === 'studio' && !building) {
|
|
80
|
+
const requested = `openspec/changes/${selected.id}/${params.plan || ''}`;
|
|
81
|
+
doc = selected.files.includes(requested) ? requested : doc;
|
|
82
|
+
view = 'rendered';
|
|
83
|
+
params = { ...params, view, stage: undefined, plan: undefined, created: undefined, creation: undefined, pane: undefined };
|
|
84
|
+
}
|
|
68
85
|
const studioLayout = ['studio', 'workflow'].includes(view);
|
|
69
86
|
const state = changeState(selected);
|
|
70
87
|
const preview = await getPreviewContext(root, params, jobs, selected);
|
|
@@ -111,26 +128,31 @@ export async function workspace({ root, data, params, jobs, agent, drafts = [],
|
|
|
111
128
|
const notes = artifact ? (await listComments(root, artifactReviewID(selected.id))).filter(comment => comment.kind === 'artifact' && comment.file === doc) : [];
|
|
112
129
|
const documentBody = artifact ? `<div data-document-content data-source-hash="${artifact.sourceHash}">${view === 'source' ? renderReviewSource(source, { sourceHash: artifact.sourceHash, comments: notes, icon }) : `<article class="prose document-prose">${renderReviewMarkdown(source, { sourceHash: artifact.sourceHash, comments: notes, icon })}</article>`}</div>${renderDocumentDiscussion({ artifact, change: selected, comments: notes }, { icon })}` : view === 'source' ? `<pre class="source-view"><code>${e(source)}</code></pre>` : `<article class="prose">${markdown(source)}</article>`;
|
|
113
130
|
content = `<div class="file-toolbar"><span>${icon('file')}<span>${e(doc.replace('openspec/', ''))}</span></span><div class="segmented" aria-label="Document view">${link('Preview', { ...base, view: 'rendered' }, view === 'rendered' ? 'active' : '')}${link('Source', { ...base, view: 'source' }, view === 'source' ? 'active' : '')}<a href="/api/raw?file=${encodeURIComponent(doc)}" download="${e(path.basename(doc))}" title="Download Markdown" aria-label="Download Markdown">${icon('download')}</a></div></div>${documentBody}`;
|
|
114
|
-
} else
|
|
131
|
+
} else {
|
|
132
|
+
const configured = (await readJSON(runtime(root, 'config.json')))?.openspecDir || 'openspec';
|
|
133
|
+
const initialized = await exists(path.resolve(root, configured));
|
|
134
|
+
content = empty(initialized ? 'Create your first plan' : 'Set up your specification workspace', initialized ? 'OpenSpec is ready. Describe the change you want to make, then review its proposal, requirements, design and tasks before generating code.' : 'Initialize OpenSpec in this project, then create a plan with your coding agent. Your documents will appear here as you work.', 'layers', initialized ? link(`${icon('plus')}New spec`, { view: 'studio', new: '1' }, 'button primary') : '<p class="empty-setup-command"><code>openspec init</code></p><p class="muted">Run this in your project’s CLI, then refresh this page.</p>');
|
|
135
|
+
}
|
|
115
136
|
if (selected) {
|
|
116
137
|
const groups = ['proposal', 'specs', 'design', 'tasks'].map(name => ({ name, files: selected.files.filter(file => name === 'specs' ? file.includes('/specs/') : !file.includes('/specs/') && path.basename(file) === `${name}.md`) }));
|
|
117
138
|
const known = new Set(groups.flatMap(group => group.files));
|
|
118
139
|
for (const file of selected.files.filter(file => !known.has(file))) groups.push({ name: path.basename(file, '.md'), files: [file] });
|
|
119
140
|
const prefix = `openspec/changes/${selected.archived ? 'archive/' : ''}${selected.id}/`;
|
|
120
141
|
navigation = `<div class="document-tabs" role="navigation" aria-label="Change documents">${groups.map(group => {
|
|
121
|
-
const file = group.files[0], planning =
|
|
122
|
-
const active = planning ? group.files.some(file => file.slice(prefix.length) === params.plan) : group.files.includes(doc) && !['preview', 'specs', 'workflow'].includes(view) || group.name === 'specs' && view === 'specs';
|
|
142
|
+
const file = group.files[0], planning = building;
|
|
143
|
+
const active = planning ? view === 'studio' && group.files.some(file => file.slice(prefix.length) === params.plan) : group.files.includes(doc) && !['preview', 'specs', 'workflow'].includes(view) || group.name === 'specs' && view === 'specs';
|
|
123
144
|
const label = `${icon(group.name === 'tasks' ? 'check' : 'file')}<span>${e(group.name)}</span>${group.name === 'tasks' && file ? `<span class="tab-count">${selected.progress.done}/${selected.progress.total}</span>` : ''}`;
|
|
124
145
|
return file ? link(label, planning ? { change: selected.id, view: 'studio', stage: 'shape', plan: file.slice(prefix.length) } : { change: selected.id, doc: file, view: 'rendered' }, `document-tab ${active ? 'active' : ''}`, active ? 'aria-current="page"' : '') : `<span class="document-tab" aria-disabled="true" title="Create this planning artifact to open it">${label}</span>`;
|
|
125
|
-
}).join('')}${link(`${icon('git')}<span>Files</span><span class="tab-count">${preview.result?.changes.length || 0}</span>`, { change: selected.id, view: 'preview', job: preview.job?.id }, `document-tab ${view === 'preview' ? 'active' : ''}`, 'data-files-tab hx-sync="#workspace:replace"')}${link('Workflow', { change: selected.id, view: 'workflow' }, `document-tab ${view === 'workflow' ? 'active' : ''}`, view === 'workflow' ? 'aria-current="page"' : '')}</div>`;
|
|
146
|
+
}).join('')}${building ? `<span class="document-tab" aria-disabled="true" title="Finish planning before reviewing file changes">${icon('git')}<span>Files</span></span>` : link(`${icon('git')}<span>Files</span><span class="tab-count">${preview.result?.changes.length || 0}</span>`, { change: selected.id, view: 'preview', job: preview.job?.id }, `document-tab ${view === 'preview' ? 'active' : ''}`, 'data-files-tab hx-sync="#workspace:replace"')}${link('Workflow', { change: selected.id, view: 'workflow' }, `document-tab ${view === 'workflow' ? 'active' : ''}`, view === 'workflow' ? 'aria-current="page"' : '')}</div>`;
|
|
126
147
|
}
|
|
127
148
|
const lastPreview = preview.job;
|
|
128
149
|
const reviewContext = compact && selected && !studioLayout ? await renderReviewContext({ root, params, selected, context: preview, jobs, agent, artifact, showImpact: view === 'preview' }, { icon, link, badge }) : '';
|
|
129
|
-
const panel = studioLayout ? '' : `<aside class="inspector" id="review-details" aria-label="Review details">${reviewContext}<section class="inspector-section"><div class="section-title"><h2>Change details</h2>${icon('git')}</div><dl><div><dt>Status</dt><dd>${badge(state.label, state.type)}</dd></div><div><dt>Schema</dt><dd>spec-driven</dd></div><div><dt>Artifacts</dt><dd>${selected?.files.length || 0} files</dd></div></dl>${selected?.progress.total ? `<div class="task-progress"><span>Implementation<strong>${selected.progress.done}<span class="muted"> / ${selected.progress.total}</span></strong></span>${progressBar(selected.progress)}</div>` : ''}</section></aside>`;
|
|
150
|
+
const panel = studioLayout || !selected ? '' : `<aside class="inspector" id="review-details" aria-label="Review details">${reviewContext}<section class="inspector-section"><div class="section-title"><h2>Change details</h2>${icon('git')}</div><dl><div><dt>Status</dt><dd>${badge(state.label, state.type)}</dd></div><div><dt>Schema</dt><dd>spec-driven</dd></div><div><dt>Artifacts</dt><dd>${selected?.files.length || 0} files</dd></div></dl>${selected?.progress.total ? `<div class="task-progress"><span>Implementation<strong>${selected.progress.done}<span class="muted"> / ${selected.progress.total}</span></strong></span>${progressBar(selected.progress)}</div>` : ''}</section></aside>`;
|
|
130
151
|
|
|
131
152
|
const compactBreadcrumbs = `<div class="breadcrumbs"><button class="icon-button mobile-menu" id="navigation-toggle" aria-controls="navigation" aria-label="Toggle project navigation" aria-expanded="false">${icon('menu')}</button><span>${e(data.name)}</span>${icon('chevron')}<span>${selected?.archived ? 'Archive' : 'Changes'}</span>${icon('chevron')}<strong role="heading" aria-level="1" title="${e(title)}">${e(selected?.id || creation?.change || (view === 'studio' ? 'New spec' : ''))}</strong></div>`;
|
|
132
|
-
const compactHeader = `<header class="compact-change-header">${compactBreadcrumbs}${navigation}${studioLayout || view === 'studio' ? studioHeader : ''}${studioLayout ? '' : `<button type="button" class="details-icon-toggle" id="toggle-review-details" data-review-details aria-controls="review-details" aria-expanded="true" aria-label="Hide review details" title="Hide review details">${icon('panel')}</button>`}</header>`;
|
|
153
|
+
const compactHeader = `<header class="compact-change-header">${compactBreadcrumbs}${navigation}${studioLayout || view === 'studio' ? studioHeader : ''}${studioLayout || !selected ? '' : `<button type="button" class="details-icon-toggle" id="toggle-review-details" data-review-details aria-controls="review-details" aria-expanded="true" aria-label="Hide review details" title="Hide review details">${icon('panel')}</button>`}</header>`;
|
|
154
|
+
const simpleHeader = `<div class="breadcrumbs"><button class="icon-button mobile-menu" id="navigation-toggle" aria-controls="navigation" aria-label="Toggle project navigation" aria-expanded="false">${icon('menu')}</button><span>${e(data.name)}</span>${icon('chevron')}<span>Specifications</span>${doc ? `${icon('chevron')}<strong>${e(data.specs.find(spec => spec.file === doc)?.id || path.basename(doc, '.md'))}</strong>` : ''}</div>`;
|
|
133
155
|
const refreshURL = url({ ...params, draft: view === 'studio' && !selected ? currentDraft.id : params.draft, change: selected?.id, view, doc: ['preview', 'studio', 'workflow'].includes(view) ? undefined : doc, job: view === 'preview' ? preview.job?.id : params.job, file: view === 'preview' ? preview.file?.file : params.file });
|
|
134
|
-
return `<div id="workspace" class="workspace ${studioLayout ? 'studio-workspace' : ''} ${view === 'preview' ? 'diff-workspace' : ''} ${compact && selected ? `compact-workspace${studioLayout ? '' : ' review-details-open'}` : ''}" data-creation-complete="${Boolean(created)}" data-artifact-follow-complete="${Boolean(followedArtifact)}" data-request-state="${e(JSON.stringify(jobs.filter(job => !job.hiddenAt && (selected && jobMatchesChange(job, selected) || job.id === params.creation)).map(job => [job.id, job.status])))}" data-change="${e(selected?.id || '')}" data-workspace-mode="${
|
|
156
|
+
return `<div id="workspace" class="workspace ${studioLayout ? 'studio-workspace' : ''} ${view === 'preview' ? 'diff-workspace' : ''} ${compact && selected ? `compact-workspace${studioLayout ? '' : ' review-details-open'}` : !selected && !studioLayout ? 'specification-workspace' : ''}" data-creation-complete="${Boolean(created)}" data-artifact-follow-complete="${Boolean(followedArtifact)}" data-request-state="${e(JSON.stringify(jobs.filter(job => !job.hiddenAt && (selected && jobMatchesChange(job, selected) || job.id === params.creation)).map(job => [job.id, job.status])))}" data-change="${e(selected?.id || '')}" data-workspace-mode="${building ? 'build' : 'review'}" data-view="${e(view)}" ${compact ? `data-refresh-url="${e(refreshURL)}"` : ''}>${sidebar}<main class="main" id="document" tabindex="-1">${!selected && view !== 'studio' ? simpleHeader : (compact && selected) || view === 'studio' ? compactHeader : `<div class="breadcrumbs"><button class="icon-button mobile-menu" id="navigation-toggle" aria-controls="navigation" aria-label="Toggle project navigation" aria-expanded="false">${icon('menu')}</button><span>${e(data.name)}</span>${icon('chevron')}<span>${selected?.archived ? 'Archive' : selected ? 'Changes' : 'Specifications'}</span>${selected ? `${icon('chevron')}<strong>${e(selected.id)}</strong>` : ''}</div><div class="change-header"><div><div class="change-title-line"><h1>${e(title)}</h1>${badge(state.label, state.type)}</div><p>${selected ? e(selected.id) : 'A local workspace for intent, implementation, and review.'}</p></div><div class="header-actions">${view === 'preview' ? `<button type="button" class="button" id="toggle-review-details" data-review-details aria-expanded="false" aria-controls="review-details">${icon('layers')}Details</button>` : `${selected ? link(`${icon('git')} Spec changes`, { ...base, view: 'specs' }, `button ${view === 'specs' ? 'selected-button' : ''}`) : ''}${link(`${icon('git')} Files changed${lastPreview ? '<span class="new-dot"></span>' : ''}`, { ...base, view: 'preview', job: lastPreview?.id }, `button ${view === 'preview' ? 'selected-button' : ''}`)}`}</div></div>${navigation}`}<div class="reader ${view === 'preview' || view === 'specs' ? 'review-reader' : ''}">${content}</div><footer class="workspace-footer"><span>${icon('folder')} ${e(data.name)}<span class="footer-divider">/</span>openspec</span><span>${view === 'preview' ? 'Current files compared with an isolated implementation' : 'Markdown is the source of truth'}</span></footer></main>${panel}</div>`;
|
|
135
157
|
}
|
|
136
158
|
function empty(title, copy, symbol = 'code', extra = '') { return `<div class="empty-state">${icon(symbol)}<h2>${title}</h2><p>${copy}</p>${extra}</div>`; }
|