spequi 0.1.0 → 0.1.1
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 +8 -0
- package/README.md +25 -23
- package/bin/spequi.mjs +51 -18
- package/docs/agent-workflow.md +24 -35
- package/package.json +14 -5
- package/public/app.css +114 -5
- package/public/app.js +119 -19
- package/public/diff.css +1 -1
- package/public/requests.js +328 -0
- package/public/review.css +27 -13
- package/public/review.js +5 -2
- package/public/session.js +134 -23
- package/public/studio.css +120 -22
- package/public/studio.js +2 -11
- package/public/{lifecycle.js → workflow.js} +30 -9
- package/skills/spequi/SKILL.md +11 -6
- package/src/agent-client.mjs +17 -0
- package/src/agent-session.mjs +3 -2
- package/src/analytics.mjs +63 -0
- package/src/commands.mjs +35 -11
- package/src/comment-view.mjs +3 -2
- package/src/creation-view.mjs +7 -7
- package/src/diff-view.mjs +11 -2
- package/src/direct-preview.mjs +4 -3
- package/src/drafts.mjs +83 -0
- package/src/files.mjs +79 -6
- package/src/job-dialogue.mjs +2 -2
- package/src/jobs.mjs +138 -43
- package/src/lifecycle.mjs +18 -23
- package/src/openspec-cli.mjs +5 -5
- package/src/preview-view.mjs +20 -7
- package/src/previews.mjs +6 -2
- package/src/project.mjs +2 -0
- package/src/requests.mjs +80 -0
- package/src/server.mjs +151 -21
- package/src/studio-view.mjs +31 -16
- package/src/views.mjs +39 -23
- package/src/workspace-state.mjs +48 -0
- package/public/lifecycle.css +0 -93
- package/src/lifecycle-view.mjs +0 -58
package/src/lifecycle-view.mjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { escape as e, readArtifact, markdown } from './specs.mjs';
|
|
3
|
-
import { lifecycleState, lifecycleJourney } from './lifecycle.mjs';
|
|
4
|
-
import { renderSourcePreviewTools } from './source-preview-view.mjs';
|
|
5
|
-
|
|
6
|
-
const labels = { 'create-change': 'Create change', explore: 'Explore', 'plan-next': 'Create next document', propose: 'Create full plan', preview: 'Preview code changes', verify: 'Check implementation', archive: 'Archive', 'sync-specs': 'Sync specifications', 'revise-plan': 'Update spec', 'update-specs': 'Update spec from comments', impact: 'File impact' };
|
|
7
|
-
const statusText = status => ({ 'awaiting-input': 'Needs your answer', queued: 'Waiting for agent', running: 'Working', completed: 'Completed', failed: 'Failed', cancelled: 'Cancelled' }[status] || status);
|
|
8
|
-
|
|
9
|
-
export async function renderLifecycle({ root, selected, jobs, agent, params = {} }, { icon, link, badge }) {
|
|
10
|
-
const state = await lifecycleState(root, selected?.id || '', { jobs });
|
|
11
|
-
const target = selected?.id || '';
|
|
12
|
-
const fields = (action, change = target) => `<input type="hidden" name="action" value="${e(action)}"><input type="hidden" name="change" value="${e(change)}">`;
|
|
13
|
-
const feedback = '<div data-lifecycle-feedback role="status" aria-live="polite"></div>';
|
|
14
|
-
const actionForm = (action, { primary = false, label, id = `lc-action-${action}` } = {}) => {
|
|
15
|
-
const option = state.actions[action] || { enabled: action === 'refresh', reason: '' };
|
|
16
|
-
return `<div class="lc-action"><form data-lifecycle-form id="${id}" action="/api/lifecycle/actions" method="post">${fields(action)}<button type="submit" class="button ${primary ? 'primary' : ''}" ${option.enabled ? '' : 'disabled'}>${icon(action === 'validate' ? 'check' : 'arrow')}${e(label || option.label)}</button>${feedback}</form>${option.reason ? `<p class="lc-blocker">${e(option.reason)}</p>` : ''}</div>`;
|
|
17
|
-
};
|
|
18
|
-
const questionHTML = (job, question) => {
|
|
19
|
-
const waiting = job.status === 'awaiting-input' && !question.answeredAt && job.questions.at(-1).id === question.id;
|
|
20
|
-
return `<section class="lc-question"><p class="lc-question-text">${e(question.message)}</p>${question.answeredAt ? `<div class="lc-answer"><strong>Your answer</strong><p>${e(question.answer)}</p></div>` : waiting ? `<form data-lifecycle-form id="lc-reply-${question.id}" action="/api/lifecycle/jobs/${job.id}/reply" method="post"><input type="hidden" name="questionId" value="${question.id}">${question.options.map(option => `<label class="lc-choice"><input type="radio" name="choice" value="${e(option)}"><span>${e(option)}</span></label>`).join('')}<label class="lc-field-label" for="lc-answer-${question.id}">Your answer${question.options.length ? ' or additional context' : ''}</label><textarea id="lc-answer-${question.id}" name="answer" rows="3" maxlength="6000" ${question.options.length ? '' : 'required'} placeholder="Reply to continue…"></textarea><button class="button primary" type="submit">${icon('arrow')}Reply & continue</button>${feedback}</form>` : '<p class="lc-muted">This request is no longer waiting for a reply.</p>'}</section>`;
|
|
21
|
-
};
|
|
22
|
-
const jobBody = job => `<div class="lc-job-body">${job.message ? `<p class="lc-request">${e(job.message)}</p>` : ''}${(job.questions || []).map(question => questionHTML(job, question)).join('')}${job.result ? `<p class="lc-result ${job.status === 'failed' ? 'error-message' : ''}">${e(job.result)}</p>` : ''}${job.status === 'completed' && job.action === 'create-change' ? link('Continue with this change', { change: job.change, view: 'lifecycle' }, 'button primary') : ''}<details id="lc-log-${job.id}"><summary>Activity log</summary><ol>${job.logs.slice(-30).map(log => `<li><time>${e(new Date(log.at).toLocaleString())}</time><span>${e(log.message)}</span></li>`).join('')}</ol></details>${['queued', 'awaiting-input'].includes(job.status) ? `<form data-lifecycle-form id="lc-cancel-${job.id}" action="/api/jobs/${job.id}/cancel" method="post"><button class="button" type="submit">Cancel request</button>${feedback}</form>` : ''}</div>`;
|
|
23
|
-
const renderJob = (job, open = false) => `<details class="lc-job" id="lc-job-${job.id}" ${job.status === 'awaiting-input' ? 'data-lifecycle-waiting' : job.status === 'failed' ? 'data-lifecycle-failed' : ''} ${open ? 'open' : ''}><summary><span>${e(labels[job.action] || job.action)}${!selected && job.change ? ` · ${e(job.change)}` : ''}</span>${badge(statusText(job.status), job.status === 'completed' ? 'success' : '')}</summary>${jobBody(job)}</details>`;
|
|
24
|
-
const history = excluded => `<details class="lc-history" id="lc-history"><summary>Previous requests <span class="lc-muted">${state.jobs.filter(job => job.id !== excluded).length}</span></summary><div class="lc-conversation">${state.jobs.filter(job => job.id !== excluded).slice(0, 20).map(job => renderJob(job)).join('') || '<p class="lc-muted">No previous requests.</p>'}</div></details>`;
|
|
25
|
-
const connection = `<p class="lc-agent-note">${icon('comment')}<span data-lifecycle-agent-note>${agent.connected ? `${e(agent.agent || 'Agent')} is attached. Ready to update the spec and preview code.` : 'No agent attached. Run the spequi skill in your coding agent to process requests.'}</span></p>`;
|
|
26
|
-
if (!selected) {
|
|
27
|
-
const latest = state.jobs[0];
|
|
28
|
-
return `<section class="lifecycle-page"><header class="lc-heading"><h1>What do you want to change?</h1></header>${connection}<section class="lc-start"><form data-lifecycle-form id="lc-create" action="/api/lifecycle/actions" method="post"><input type="hidden" name="action" value="create-change"><label class="lc-field-label" for="lc-goal">Describe your idea</label><textarea id="lc-goal" name="message" rows="4" required maxlength="12000" placeholder="For example: let users reset a forgotten password by email."></textarea><label class="lc-field-label" for="lc-name">Short name</label><input id="lc-name" name="change" required pattern="[a-z][a-z0-9]*(?:-[a-z0-9]+)*" maxlength="80" placeholder="password-reset"><p class="lc-muted">Start the change, build its spec, then preview and apply the code.</p><button class="button primary" type="submit">${icon('plus')}Start change</button>${feedback}</form></section>${latest ? `<section class="lc-current"><h2>${latest.status === 'awaiting-input' ? 'Your answer is needed' : 'Latest request'}</h2>${renderJob(latest, true)}</section>` : ''}<details class="lc-more" id="lc-explore-project"><summary>Explore an idea first</summary><form data-lifecycle-form id="lc-explore-project-form" action="/api/lifecycle/actions" method="post">${fields('explore', '')}<label class="lc-field-label" for="lc-idea">What would you like to investigate?</label><textarea id="lc-idea" name="message" rows="3" required maxlength="12000"></textarea><button class="button" type="submit">Explore idea</button>${feedback}</form></details>${history(latest?.id)}</section>`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const journey = lifecycleJourney(state), ready = state.readiness, preview = state.preview, result = state.result;
|
|
32
|
-
const current = state.pending || state.jobs[0];
|
|
33
|
-
const currentHTML = current ? `<section class="lc-current"><div class="lc-section-heading"><h2>${current.status === 'awaiting-input' ? 'Your answer is needed' : state.pending ? 'Current request' : 'Latest result'}</h2><span class="lc-muted" data-lifecycle-agent-caption>${agent.connected ? 'Same agent session' : 'Requests wait for your agent'}</span></div>${renderJob(current, true)}</section>` : '';
|
|
34
|
-
const documentLabel = file => file.includes('/specs/') ? file.split('/specs/')[1] : path.basename(file, '.md');
|
|
35
|
-
const reviewFile = selected.files.includes(params.plan) ? params.plan : selected.files.find(file => file.includes('/specs/')) || selected.files[0];
|
|
36
|
-
const updatedPlan = current?.status === 'completed' && ['revise-plan', 'update-specs', 'plan-next', 'propose'].includes(current.action) && (!preview || current.updatedAt > preview.createdAt);
|
|
37
|
-
const planReview = reviewFile ? `<details class="lc-plan-review" id="lc-plan-review-${current?.id || 'current'}" data-lifecycle-spec-review ${updatedPlan || params.plan ? 'open' : ''}><summary>Review ${updatedPlan ? 'updated ' : ''}spec <span class="lc-muted">${selected.files.length} documents</span></summary><nav class="lc-plan-documents" aria-label="Spec documents">${selected.files.map(file => link(e(documentLabel(file)), { change: target, view: 'lifecycle', plan: file }, `button ${file === reviewFile ? 'selected-button' : ''}`)).join('')}</nav><article class="prose lc-plan-document">${markdown(await readArtifact(root, reviewFile))}</article></details>` : '';
|
|
38
|
-
const editAction = selected.files.length ? 'revise-plan' : 'plan-next', editOption = state.actions[editAction];
|
|
39
|
-
const composer = selected.archived ? '' : `<section class="lc-spec-editor"><form data-lifecycle-form id="lc-revise" action="/api/lifecycle/actions" method="post">${fields(editAction)}<label class="lc-field-label" for="lc-revision">What should the spec say?</label><textarea id="lc-revision" name="message" rows="3" maxlength="12000" required placeholder="Describe a change, for example: reset links should expire after 30 minutes."></textarea><div class="lc-composer-actions"><button class="button" type="submit" ${editOption.enabled ? '' : 'disabled'}>${icon('comment')}${selected.files.length ? 'Update spec' : 'Create spec'}</button><span class="lc-muted">${state.pending ? 'Wait for the current request to finish, or answer its question above.' : 'Updates planning documents. Code changes come in the next step.'}</span></div>${!editOption.enabled ? `<p class="lc-blocker">${e(editOption.reason)}</p>` : ''}${feedback}</form></section>`;
|
|
40
|
-
let primary = '';
|
|
41
|
-
if (journey.action === 'review') primary = link(`${icon('git')}${e(journey.label)}`, { change: target, view: 'preview', job: preview.id }, 'button primary');
|
|
42
|
-
else if (journey.action) primary = actionForm(journey.action, { primary: true, label: journey.label, id: `lc-next-${journey.action}` });
|
|
43
|
-
const next = `<section class="lc-next" aria-labelledby="lc-next-heading"><div><h2 id="lc-next-heading">${e(journey.title)}</h2><p>${e(journey.description)}</p></div>${primary}</section>`;
|
|
44
|
-
const stages = [
|
|
45
|
-
['Spec', selected.archived ? 'Archived documents' : state.error ? 'Readiness unavailable' : ready?.planningComplete ? 'Ready to review' : 'In progress'],
|
|
46
|
-
['Code preview', preview ? state.previewStale ? 'Needs refresh' : 'Preview saved' : 'Not generated'],
|
|
47
|
-
['Review & apply', result?.applied ? 'Applied' : result?.changes.length ? 'Review needed' : 'Not applied'],
|
|
48
|
-
['Finish', selected.archived ? 'Archived' : 'Check, then archive']
|
|
49
|
-
];
|
|
50
|
-
const board = `<ol class="lc-board" aria-label="Change progress">${stages.map(([name, detail], index) => `<li class="lc-stage ${index === journey.stage ? 'current' : ''}" ${index === journey.stage ? 'aria-current="step"' : ''}><strong>${e(name)}</strong><span>${e(detail)}</span></li>`).join('')}</ol>`;
|
|
51
|
-
const artifactRows = ready?.artifacts.map(artifact => `<li><span>${e(artifact.id)}</span>${badge(artifact.status, artifact.status === 'done' ? 'success' : '')}</li>`).join('') || '<li>Readiness unavailable.</li>';
|
|
52
|
-
const validation = state.validation;
|
|
53
|
-
const validationHTML = validation ? `<div class="lc-validation"><div class="row">${badge(validation.stale ? 'Spec changed since check' : validation.valid ? 'Specification valid' : 'Validation findings', validation.valid && !validation.stale ? 'success' : '')}<time>${e(new Date(validation.checkedAt).toLocaleString())}</time></div><ul>${validation.issues.map(issue => `<li><strong>${e(issue.level || issue.severity || 'Finding')}</strong> ${e(issue.path || '')} ${e(issue.message || '')}</li>`).join('')}</ul><p class="lc-muted">Checks the spec, not the implementation.</p></div>` : '<p class="lc-muted">No spec validation result saved yet.</p>';
|
|
54
|
-
const apply = state.actions.apply;
|
|
55
|
-
const applyForm = preview ? `<div class="lc-action"><form data-apply-form action="/api/previews/${preview.id}/apply" hx-post="/api/previews/${preview.id}/apply" hx-target="#apply-feedback"><button class="button" type="submit" ${apply.enabled ? '' : 'disabled'}>${icon('check')}${e(apply.label)}</button></form>${apply.reason ? `<p class="lc-blocker">${e(apply.reason)}</p>` : ''}</div>` : '';
|
|
56
|
-
const more = `<details class="lc-more" id="lc-more"><summary>More actions & details</summary><p class="lc-muted">Use individual OpenSpec actions when you need more control.</p><div class="lc-tools"><section><h2>Planning</h2><ul class="lc-artifacts">${artifactRows}</ul>${actionForm('plan-next')}${actionForm('propose')}<form data-lifecycle-form id="lc-explore-change" action="/api/lifecycle/actions" method="post">${fields('explore')}<label class="lc-field-label" for="lc-explore-message">Investigate a question</label><textarea id="lc-explore-message" name="message" rows="3" required maxlength="12000"></textarea><button class="button" type="submit" ${state.actions.explore.enabled ? '' : 'disabled'}>Explore</button>${state.actions.explore.reason ? `<p class="lc-blocker">${e(state.actions.explore.reason)}</p>` : ''}${feedback}</form></section><section><h2>Code & checks</h2>${actionForm('preview')}${applyForm}<div id="apply-feedback" role="status" aria-live="polite"></div>${actionForm('verify')}${actionForm('validate')}${validationHTML}</section><section><h2>Finish this change</h2>${actionForm('sync-specs')}<p class="lc-muted">Sync updates the project's main specs and keeps this change active.</p>${actionForm('archive')}${state.actions['archive-override'].enabled ? `<details id="lc-archive-exception"><summary>Archive incomplete work…</summary><p class="lc-muted">The workflow will check outstanding work and ask for confirmation.</p>${actionForm('archive-override')}</details>` : ''}<h2 class="lc-detail-heading">Change details</h2><dl><div><dt>Schema</dt><dd>${e(ready?.schema || 'Unavailable')}</dd></div><div><dt>Tasks checked</dt><dd>${ready ? `${ready.tasks.done} / ${ready.tasks.total}` : 'Unavailable'}</dd></div></dl>${actionForm('refresh', { label: 'Refresh readiness' })}</section></div>${await renderSourcePreviewTools(root, selected, Boolean(result), state.pending, icon)}</details>`;
|
|
57
|
-
return `<section class="lifecycle-page"><header class="lc-heading"><div><h1>Lifecycle</h1><p>Update the spec. Review the code. Apply when ready.</p></div>${badge(selected.archived ? 'Archived' : state.pending ? statusText(state.pending.status) : ready?.planningComplete ? 'Spec ready' : 'Planning')}</header>${board}${connection}${next}${state.pending ? currentHTML : ''}${composer}${planReview}${!state.pending ? currentHTML : ''}${history(current?.id)}${more}</section>`;
|
|
58
|
-
}
|