Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions commands/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,21 @@ Every file is on disk, so every question below refines something that already ex

The spec content is now final for this run, so render the human-facing review page. This step is unconditional — every run produces the page — but its failure is never fatal: if `node` is missing (`command -v node`) or the script errors, report that the render was skipped and why, and continue to the report; the markdown remains canonical.

1. Author the **view-model** — the re-shaped, human-friendly representation of what this session learned. Write it as JSON to a temporary file outside the project, following the schema documented at the top of the renderer script. Resolve the temp paths once, with a fallback for an unset `TMPDIR`, and reuse those exact paths for every write, render, and cleanup below:
1. Author the **view-model** — the re-shaped, human-friendly representation of what this session learned. Write it as JSON to a temporary file outside the project, following the schema documented at the top of the renderer script. Create one private temp directory for this run, with a fallback for an unset `TMPDIR`, and keep both temp files inside it:

```bash
view_model_path="${TMPDIR:-/tmp}/spec-view-[index].json"
artifact_path="${TMPDIR:-/tmp}/spec-artifact-[index].html"
spec_tmp_dir="$(mktemp -d "${TMPDIR:-/tmp}/spec-view.XXXXXX")"
view_model_path="$spec_tmp_dir/view-model.json"
artifact_path="$spec_tmp_dir/artifact.html"
echo "$spec_tmp_dir"
```

Run `mktemp` once and reuse the directory it printed for every write, render, and cleanup below — a second call creates a different directory. The directory is readable only by the current user and its name is not predictable, so a parallel run on the same spec index or another local user cannot reach the view-model.

Its content, all in the spec's non-technical register:
- `at_a_glance` — the feature in about five plain sentences.
- `decisions` — every judgment call made in this spec (the things a reviewer might challenge): the decision, the choice, why, and its sources (`interview` / `code` / `web` / `kb`). Facts the user supplied in the prompt or in Steps 8 and 9 count as `interview`.
- `findings` — per research lane, what was discovered and what it changed in the spec (`impact`, with an `anchor` like `#r21` pointing at the requirement it shaped). A lane that did not run gets an explanatory note, not silence.
- `findings` — per research lane, what was discovered and what it changed in the spec (`impact`, with an `anchor` like `#r21` pointing at the requirement it shaped; a two-digit item keeps a dash, `#rN-M`, so requirement 1.12 is `#r1-12`). A lane that did not run gets an explanatory note, not silence.
- `requirements` — per requirement (matched by its number, e.g. `"2.1"`): a one-line plain-language statement, source badges, and a short scannable name for each acceptance criterion, in order.
- `diagram` (optional) — when the behavior is stateful or flow-heavy, a small declarative diagram: box/arrow/text items with user-language labels, following the schema in the renderer header. The renderer draws the SVG itself — it never accepts raw markup. Include a note that the criteria remain the contract.

Expand All @@ -219,7 +223,7 @@ The spec content is now final for this run, so render the human-facing review pa
node ".awos/scripts/render-spec.mjs" "context/spec/[index]-[short-name]" "$view_model_path"
```

The script extracts all requirement prose and acceptance criteria verbatim from `functional-spec.md` — the view-model only adds the human layer on top, never replacement text. Keep the temp view-model file until the publish offer below is resolved, then delete it — it never lands in the project.
The script extracts all requirement prose and acceptance criteria verbatim from `functional-spec.md` — the view-model only adds the human layer on top, never replacement text. Keep the temp directory until the publish offer below is resolved, then delete it — the view-model never lands in the project.

3. Offer to publish the review page as a Claude artifact — a link is easier to share with reviewers than a file. Make the offer only when both hold: the render succeeded, and the `Artifact` tool is available in your toolset (introspection — when it is absent, skip this step silently rather than mentioning an option that cannot work). Ask via `AskUserQuestion`: publish as a private artifact, or skip. Publishing sends the spec's content to an external service, so this is a consent gate, not a preference: an unanswered or dismissed question means **no** — never publish by default, and never publish in an unattended run. This deliberately inverts this command's usual unanswered-question rule; outward-facing actions default to withheld consent. If the user opts in:

Expand All @@ -230,10 +234,10 @@ The spec content is now final for this run, so render the human-facing review pa

Publish only a fragment this run produced: if that command fails or writes no file, report that the artifact render failed and publish nothing. Otherwise publish the fragment file with the `Artifact` tool (favicon `📋`) and report the artifact URL — it starts private, and the user shares it from claude.ai when ready.

4. Delete the temp files, whatever the publish decision was:
4. Delete the temp directory, whatever the publish decision was:

```bash
rm -f "$view_model_path" "$artifact_path"
rm -rf "$spec_tmp_dir"
```

This runs on every path — offer declined, `Artifact` tool absent, unattended run, render failed, or published. The view-model holds the spec's content; it does not belong in shared temporary storage once the run is done.
Expand Down
64 changes: 56 additions & 8 deletions scripts/render-spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
* },
* "requirements": [{ "match": "2.1", "one_liner", "sources": [...], "criteria_names": ["...", ...] }]
* }
*
* A finding's anchor is the requirement card id: "r" + section + item for a
* one-digit item ("2.1" -> "#r21"), with a dash before a two-digit item
* ("1.12" -> "#r1-12") so that 1.12 and 11.2 never share an id.
*/

import fs from 'node:fs';
Expand Down Expand Up @@ -85,7 +89,10 @@ function badge(src) {

function anchorFor(heading) {
const num = heading.match(/^(\d+)\.(\d+)/);
if (num) return `r${num[1]}${num[2]}`;
// "2.1" -> "r21". A two-digit item keeps a separator ("1.12" -> "r1-12"):
// plain concatenation would give 1.12 and 11.2 the same id.
if (num)
return num[2].length > 1 ? `r${num[1]}-${num[2]}` : `r${num[1]}${num[2]}`;
return (
'r-' +
heading
Expand Down Expand Up @@ -233,6 +240,25 @@ function parseBody(body) {
continue;
}

// An indented bullet that is not a checkbox is requirement prose too
// (a detail under a top-level bullet); only the acceptance label is not.
const nested = line.match(/^\s+- (.+)$/);
if (nested) {
let text = nested[1];
i++;
while (i < body.length) {
const next = body[i];
if (!next.trim()) break;
if (/^\s*- /.test(next) || /^#{1,6} /.test(next)) break;
text += ' ' + next.trim();
i++;
}
if (!/^\*\*Acceptance Criteria:?\*\*/i.test(text.trim())) {
pushText(text);
}
continue;
}

// Tables are checked before the paragraph branch below: their rows are
// neither bullets nor a bare rule, so that branch would otherwise fold the
// whole table — pipes, dashes and all — into one run-on paragraph.
Expand Down Expand Up @@ -275,6 +301,7 @@ function splitFlatRequirements(section) {
if (!parseBody(section.body).criteria.length) return [];

const groups = [];
const lead = [];
for (const line of section.body) {
const top = line.match(/^- (.+)$/);
const isCheckbox = /^- \[( |x|X)\]/.test(line);
Expand All @@ -284,12 +311,19 @@ function splitFlatRequirements(section) {
groups.push([line]);
} else if (groups.length) {
groups[groups.length - 1].push(line);
} else {
lead.push(line);
}
}

return groups
.map((body, idx) => ({ title: `${sectionNumber}.${idx + 1}`, body }))
.filter((sub) => parseBody(sub.body).criteria.length > 0);
// A requirement without criteria still renders, as it does in the
// subsection shape. Text before the first requirement rides on the first
// unit as `lead` and renders above its card.
return groups.map((body, idx) => ({
title: `${sectionNumber}.${idx + 1}`,
body,
...(idx === 0 ? { lead } : {}),
}));
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -356,6 +390,17 @@ function renderBlocks(blocks, textTag, textClass) {
.join('\n');
}

// Text a requirements section carries before its first requirement. It rides
// on the first unit and renders above that card; a checkbox written there is
// shown too, because the status bar counts it.
function renderLead(lines) {
const parsed = parseBody(lines || []);
const parts = [renderBlocks(parsed.blocks, 'p', 'prose')];
if (parsed.criteria.length) parts.push(renderCriteria(parsed, null));
const html = parts.filter(Boolean).join('\n');
return html ? `${html}\n` : '';
}

function renderRequirement(sub, vm) {
const parsed = parseBody(sub.body);
const vmReq = findVmRequirement(vm, sub.title);
Expand All @@ -368,7 +413,7 @@ function renderRequirement(sub, vm) {
? `<p class="oneliner">${inline(vmReq.one_liner)}</p>`
: '';
const prose = renderBlocks(parsed.blocks, 'p', 'prose');
return `<section class="req" id="${id}">
return `${renderLead(sub.lead)}<section class="req" id="${id}">
<h3><span>${inline(sub.title)}</span><span class="provrow">${badges}</span></h3>
${oneLiner}
${prose}
Expand Down Expand Up @@ -412,7 +457,8 @@ function renderScope(section) {
})
.join('\n');
if (!cols) return renderGenericSection(section);
return `<h2 id="scope">${inline(section.title)}</h2>\n<div class="cols">${cols}</div>`;
const lead = renderBlocks(parseBody(section.body).blocks, 'p', '');
return `<h2 id="scope">${inline(section.title)}</h2>\n${lead}\n<div class="cols">${cols}</div>`;
}

function renderDecisions(vm) {
Expand Down Expand Up @@ -639,7 +685,7 @@ const CSS = `
.d-head { fill: var(--muted); }
.tabs { margin-top: 12px; }
.tabbar { display: flex; gap: 4px; border-bottom: 2px solid var(--line); }
.tabbar button { appearance: none; border: none; background: none; color: var(--muted); font: 600 14px/1.4 inherit; padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabbar button { appearance: none; border: none; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: 14px; line-height: 1.4; padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabbar button.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabbar button .count { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.tabpanel { display: none; padding: 6px 2px 0; }
Expand Down Expand Up @@ -731,7 +777,9 @@ function render(md, rawVm) {
// yields a unit, the section still renders generically below: showing it
// unenriched beats dropping it.
const subs = section.subs.length
? section.subs
? section.subs.map((sub, idx) =>
idx === 0 ? { ...sub, lead: section.body } : sub
)
: splitFlatRequirements(section);
if (subs.length) requirementSubs.push(...subs);
else genericSections.push(section);
Expand Down
12 changes: 10 additions & 2 deletions tests/lint-prompts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2286,8 +2286,16 @@ test('commands/spec.md keeps the research-backed spec contracts (fan-out, unatte
'the scope boundary must be drafted and marked rather than asked — Step 7 runs before the spec file exists',
],
[
'view_model_path="${TMPDIR:-/tmp}/spec-view-[index].json"',
'the temp paths must be resolved once with a TMPDIR fallback and reused — re-interpolating a bare $TMPDIR per step lets the file written and the file rendered diverge, and makes the cleanup rm a path that was never created',
'spec_tmp_dir="$(mktemp -d "${TMPDIR:-/tmp}/spec-view.XXXXXX")"',
"the temp files must live in one mktemp -d directory per run, with a TMPDIR fallback — a predictable name in shared temp storage can be pre-created by another local user, and two runs on the same spec index overwrite and delete each other's file",
],
[
'rm -rf "$spec_tmp_dir"',
'the cleanup must remove the per-run temp directory itself — the view-model holds the spec content and must not outlive the run',
],
[
'`#rN-M`',
'the anchor guidance must name the two-digit form — the renderer gives requirement 1.12 the id r1-12, so an anchor written as #r112 would point at 11.2 or at nothing',
],
[
'MANUAL SOURCES ONLY',
Expand Down
Loading