@phnx-labs/artifacts-cli 0.3.2 → 0.3.4
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 +82 -0
- package/README.md +41 -2
- package/dist/cli.js +11 -40
- package/dist/cli.js.map +1 -1
- package/dist/commands/answers.d.ts +6 -0
- package/dist/commands/answers.js +90 -0
- package/dist/commands/answers.js.map +1 -0
- package/dist/commands/new.d.ts +9 -0
- package/dist/commands/new.js +62 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/lib/charts.d.ts +16 -0
- package/dist/lib/charts.js +76 -0
- package/dist/lib/charts.js.map +1 -0
- package/dist/lib/embedded-html.d.ts +1 -1
- package/dist/lib/embedded-html.js +15 -0
- package/dist/lib/embedded-html.js.map +1 -1
- package/dist/lib/highlights.d.ts +1 -0
- package/dist/lib/highlights.js +129 -0
- package/dist/lib/highlights.js.map +1 -0
- package/dist/lib/html.d.ts +8 -0
- package/dist/lib/html.js +18 -0
- package/dist/lib/html.js.map +1 -0
- package/dist/lib/icons.d.ts +11 -4
- package/dist/lib/icons.js +10 -8
- package/dist/lib/icons.js.map +1 -1
- package/dist/lib/links.d.ts +28 -0
- package/dist/lib/links.js +150 -0
- package/dist/lib/links.js.map +1 -1
- package/dist/lib/render.js +335 -30
- package/dist/lib/render.js.map +1 -1
- package/dist/lib/templates.d.ts +2 -1
- package/dist/lib/templates.js +17 -0
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/validate.js +122 -8
- package/dist/lib/validate.js.map +1 -1
- package/dist/lib/worksheet.d.ts +94 -0
- package/dist/lib/worksheet.js +364 -0
- package/dist/lib/worksheet.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,87 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.3.4 — 2026-08-15
|
|
6
|
+
|
|
7
|
+
- **A `worksheet` artifact kind takes input back.** A fourth kind renders a
|
|
8
|
+
fillable Q&A page instead of a read-only document. Agents author questions as
|
|
9
|
+
declarative `field` and `fields` fenced blocks — never form HTML — and the
|
|
10
|
+
renderer emits the textareas, as-you-type `localStorage` autosave, per-field
|
|
11
|
+
chips (`draft` when a field carries a value, `needs you` when it does not, and `answered` after merge), and a
|
|
12
|
+
toolbar (Save · Export answers · Copy answers as Markdown · Print / PDF · Reset
|
|
13
|
+
drafts). A required `worksheet_id` frontmatter key (8-hex, generated by
|
|
14
|
+
`artifacts new worksheet`) keys the autosave blob so `file://` worksheets do not
|
|
15
|
+
collide. The `input`/`textarea`/`button` sanitizer carve-out is scoped to this
|
|
16
|
+
kind; every other kind still strips them.
|
|
17
|
+
- **`artifacts answers` closes the round-trip.** The user fills the rendered page
|
|
18
|
+
and clicks Export answers to download `<basename>.<worksheet_id>.answers.json`;
|
|
19
|
+
`artifacts answers <ws.md> --from <file.json>` merges it back into the `.md` by
|
|
20
|
+
field id — only user-touched (`dirty`) fields land (so an agent's revised draft
|
|
21
|
+
survives), merged fields gain an `answered: YYYY-MM-DD` stamp, and a
|
|
22
|
+
`worksheet_id` mismatch or a three-way conflict aborts the whole write with a
|
|
23
|
+
per-field report. With no `--from`, the command prints a filled/pending table (or
|
|
24
|
+
`--json` a `id → {label, value, state}` map) so any later session reads the
|
|
25
|
+
user's answers straight from the `.md`; a directory argument scans for worksheets
|
|
26
|
+
and lists per-file pending counts. The `.md` is the only durable answer store.
|
|
27
|
+
- Kept `bar-chart` validation and rendering on one exact fence-name check, counted
|
|
28
|
+
forbidden embedded tags separately by tag name, and documented that a valid
|
|
29
|
+
chart data table satisfies an internal plan's visual-figure gate. Escaped pipes
|
|
30
|
+
in chart labels now render as literal pipes.
|
|
31
|
+
|
|
32
|
+
## 0.3.3 — 2026-08-15
|
|
33
|
+
|
|
34
|
+
- **Theme-aware figures and data-driven bar charts.** Rendered pages expose
|
|
35
|
+
`--artifact-fg`, `--artifact-muted`, and `--artifact-accent` for inline SVG;
|
|
36
|
+
the always-dark diagram surface now scopes those colors so its caption stays
|
|
37
|
+
readable in light and dark themes. A fenced `bar-chart` component accepts a
|
|
38
|
+
two-column Markdown table and emits accessible, automatically scaled SVG with
|
|
39
|
+
no author-supplied coordinates or hex colors.
|
|
40
|
+
- **Authoring diagnostics are shorter and more actionable.** Repeated embedded
|
|
41
|
+
HTML violations collapse by root cause with occurrence counts, unsupported
|
|
42
|
+
SVG classes point to `fill=`, `font-size=`, and `font-family=`, and
|
|
43
|
+
`stroke-dashoffset` is accepted as an SVG animation target. Frontmatter
|
|
44
|
+
summaries render safe inline Markdown, including code spans, and
|
|
45
|
+
`artifacts new <kind> --blank --stdout` prints a required-section skeleton
|
|
46
|
+
without writing a file.
|
|
47
|
+
|
|
48
|
+
- **Reader highlights persist in each browser.** Selecting text in a rendered
|
|
49
|
+
artifact saves a stable section-and-block-relative range under the artifact's
|
|
50
|
+
existing URL-and-title identity. Highlights return after a reload or reopened
|
|
51
|
+
tab, support overlaps without changing the document text, and disappear when
|
|
52
|
+
clicked. Storage failures stay silent, and the themed mark color remains
|
|
53
|
+
readable in light and dark mode without adding an authored script/style surface.
|
|
54
|
+
- **Body links render as link pills.** Every outbound `http(s)` link an agent writes
|
|
55
|
+
as plain Markdown — `[text](url)` or a pasted bare URL — now renders with the
|
|
56
|
+
source's brand mark (GitHub, Linear, Jira, Notion, GitLab, Bitbucket, Asana,
|
|
57
|
+
Trello, Slack, Figma) or its favicon, in a bordered, clickable pill, so sources
|
|
58
|
+
are identifiable at a glance without an agent hand-writing any HTML. A bare URL
|
|
59
|
+
is labelled `PR #1914` / `RUSH-2513` / the host instead of printed in full, using
|
|
60
|
+
the same short form as the frontmatter `links` chips. Links in headings, `code`,
|
|
61
|
+
and `<pre>`, in-page anchors, `mailto:`/`tel:`, relative paths, and image links
|
|
62
|
+
stay plain anchors. The pass runs after the body sanitizer, so its generated
|
|
63
|
+
markup survives the tag and class allowlist.
|
|
64
|
+
- **A `References` appendix is generated automatically.** Every outbound link in
|
|
65
|
+
the body is collected into a numbered section at the end — deduped, in order of
|
|
66
|
+
first appearance, each row carrying the source's mark, label, and host, reusing
|
|
67
|
+
the same short label as the pill. An author-written `References` / `Sources` /
|
|
68
|
+
`Bibliography` / `Citations` heading suppresses it.
|
|
69
|
+
- **The table of contents is now a contents rail.** It lists subsections as well
|
|
70
|
+
as sections, and above 1380px becomes a fixed side rail that tracks the section
|
|
71
|
+
being read. Heading ids and the rail are now produced by one pass over the
|
|
72
|
+
rendered HTML, which fixes three bugs: two subsections sharing a title used to
|
|
73
|
+
get one shared id (so the rail's second entry jumped to the first heading and
|
|
74
|
+
scroll-spy could never select it), a heading containing a link or an `&`
|
|
75
|
+
slugified differently in the rail than in its own id, and a `##` line inside a
|
|
76
|
+
fenced code block was treated as a heading. A heading inside an embedded panel
|
|
77
|
+
or figure still gets an id but is excluded from the rail.
|
|
78
|
+
- **Artifacts keep a local read count**, shown in the document header, stored per
|
|
79
|
+
browser in `localStorage` and scoped to the artifact's own URL and title.
|
|
80
|
+
- **`summary` and `links` are soft-required.** Their absence is now a warning, not
|
|
81
|
+
an error: the artifact still compiles, but the author is reminded that a TL;DR
|
|
82
|
+
and the related tickets/PRs/docs are what give a reader context. An overlong
|
|
83
|
+
summary is flagged too.
|
|
84
|
+
|
|
3
85
|
## 0.3.2 — 2026-08-10
|
|
4
86
|
|
|
5
87
|
- `artifacts --version` now reads the version from `package.json` at runtime instead
|
package/README.md
CHANGED
|
@@ -75,13 +75,14 @@ offline brand mark; other hosts try a remote favicon and drop it if load fails.
|
|
|
75
75
|
|
|
76
76
|
## Commands
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
Five commands. Everything else is a flag on one of them.
|
|
79
79
|
|
|
80
80
|
| Command | Purpose |
|
|
81
81
|
| --- | --- |
|
|
82
|
-
| `artifacts new <plan\|report\|visual\|design> [--out file] [--blank]` | Scaffolds an artifact and pre-fills detectable provenance. `--blank` leaves every field empty; `design` writes a starter `DESIGN.md`. |
|
|
82
|
+
| `artifacts new <plan\|report\|visual\|worksheet\|design> [--out file] [--blank] [--stdout]` | Scaffolds an artifact and pre-fills detectable provenance. `--blank` leaves every field empty; `--stdout` prints the skeleton without writing; `design` writes a starter `DESIGN.md`; `worksheet` generates a `worksheet_id`. |
|
|
83
83
|
| `artifacts check file.md` | Validates frontmatter metadata, required sections, asset paths, and embedded HTML/SVG safety. |
|
|
84
84
|
| `artifacts render file.md [--out file] [--open]` | Renders Markdown to self-contained HTML next to the source. `--open` shows it in your default browser. Embeds the Markdown source for recovery. |
|
|
85
|
+
| `artifacts answers <ws.md> [--from file.json] [--json] [--pending]` | Reads or merges a `worksheet`'s answers. No flag prints a filled/pending table; `--json` emits `id → {label, value, state}`; `--pending` filters to pending fields or worksheets; `--from` merges an exported answers file back into the `.md` (id-matched, dirty-only, atomic). A directory scans for worksheets and lists per-file pending counts. |
|
|
85
86
|
| `artifacts share file.md` | Renders Markdown when needed and publishes through the configured R2/Worker endpoint. |
|
|
86
87
|
|
|
87
88
|
### Internal commands
|
|
@@ -184,6 +185,44 @@ The committed [representative plan](examples/plan.md) measures:
|
|
|
184
185
|
|
|
185
186
|
That example is an **82.1% authoring-token reduction** when the alternative is having the agent emit the same self-contained HTML. It includes complete metadata, ordinary Markdown, a table, embedded layout HTML, inline SVG, theme CSS, responsive rules, print rules, and the theme toggle. Run `artifacts estimate examples/plan.md` to reproduce it — the command is absent from `--help` but still runs.
|
|
186
187
|
|
|
188
|
+
## Links
|
|
189
|
+
|
|
190
|
+
Write links as ordinary Markdown. Every outbound `http(s)` link in the body renders as a **link pill**: the source's brand mark (GitHub, Linear, Jira, Notion, GitLab, Bitbucket, Asana, Trello, Slack, Figma) or its favicon, followed by the link text, in a bordered, clickable container. No HTML to hand-write.
|
|
191
|
+
|
|
192
|
+
```markdown
|
|
193
|
+
See [the merge guard](https://github.com/phnx-labs/agents-cli/pull/1914) for context.
|
|
194
|
+
Ticket: [RUSH-2513](https://linear.app/phnx/issue/RUSH-2513/version-drift)
|
|
195
|
+
https://github.com/phnx-labs/artifacts-cli
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
A pasted bare URL is labelled instead of printed in full — `PR #1914`, `RUSH-2513`, or the host — the same short form the frontmatter `links` chips use.
|
|
199
|
+
|
|
200
|
+
These stay plain anchors, because a pill would fight the surrounding element or misrepresent the link:
|
|
201
|
+
|
|
202
|
+
| Link | Why it stays plain |
|
|
203
|
+
| --- | --- |
|
|
204
|
+
| In a heading, `code`, or a `<pre>` block | The pill would break the type. |
|
|
205
|
+
| In-page anchor (`#section`) | Not an outbound source. |
|
|
206
|
+
| `mailto:` and `tel:` | Not a web source. |
|
|
207
|
+
| Relative path (`./notes.html`) | Not an outbound source. |
|
|
208
|
+
| An image wrapped in a link | The image is the content, not a citation. |
|
|
209
|
+
|
|
210
|
+
Brand marks are bundled, so a known host needs no network. Unknown hosts fall back to a remote favicon that removes itself if it cannot load.
|
|
211
|
+
|
|
212
|
+
## Reading Surfaces
|
|
213
|
+
|
|
214
|
+
Four reader affordances are generated from the artifact itself. An agent writes nothing extra for any of them.
|
|
215
|
+
|
|
216
|
+
**References appendix.** Every outbound link in the body is collected into a numbered `References` section at the end — deduped, in order of first appearance, each row carrying the source's mark, its label, and its host. A bare URL lists under its short label (`PR #1914`), not the raw address. Writing your own `References`, `Sources`, `Bibliography`, or `Citations` heading suppresses the generated one.
|
|
217
|
+
|
|
218
|
+
**Contents rail.** The table of contents lists sections and their subsections. At viewports wider than 1380px it becomes a fixed side rail that tracks the section you are reading; below that it stays inline at the top with subsections hidden. Heading ids are unique even when two subsections share a title, so every rail entry addresses its own heading. A heading inside an embedded panel or figure is that block's caption and is deliberately left out of the rail.
|
|
219
|
+
|
|
220
|
+
**Read count.** Each artifact keeps a per-browser read count in `localStorage`, shown in the document header (`first read`, then `2 reads`). It is scoped to the artifact's own URL and title, so two artifacts published under the same title do not share a counter. Nothing is sent anywhere.
|
|
221
|
+
|
|
222
|
+
**Highlights.** Select text in the artifact body to save a highlight in this browser. Highlights survive reloads and reopening the page; click any highlighted text to remove that selection. They use the same URL-and-title artifact identity as the read count, stay on the reader's device, and need no server or account.
|
|
223
|
+
|
|
224
|
+
Themes already follow the reader's system preference and switch live when the OS theme changes, unless the reader picks one explicitly with the in-page toggle.
|
|
225
|
+
|
|
187
226
|
## Embedded HTML And SVG
|
|
188
227
|
|
|
189
228
|
Use Markdown for prose, lists, tables, and code. When Markdown cannot express a figure or comparison, write semantic HTML directly in the Markdown file. The renderer sanitizes it, applies the active `DESIGN.md` theme, and keeps the output responsive.
|
package/dist/cli.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { dirname, join, resolve } from 'node:path';
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
import { Command, Option } from 'commander';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
|
+
import { addNewCommand } from './commands/new.js';
|
|
8
9
|
import { exportPdf, parsePdfLayout } from './lib/pdf.js';
|
|
9
10
|
import { compileArtifact, decompileHtml } from './lib/render.js';
|
|
10
11
|
import { estimateArtifactTokens } from './lib/tokens.js';
|
|
11
|
-
import { detectArtifactContext, STARTER_DESIGN, templateFor } from './lib/templates.js';
|
|
12
12
|
import { validateMarkdown } from './lib/validate.js';
|
|
13
13
|
import { shareAnalytics, shareDelete, shareJoin, sharePublish, shareSetup, shareStatus } from './commands/share.js';
|
|
14
|
+
import { answersCommand } from './commands/answers.js';
|
|
14
15
|
const { version } = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '../package.json'), 'utf-8'));
|
|
15
16
|
const program = new Command();
|
|
16
17
|
function printDiagnostics(diagnostics) {
|
|
@@ -46,45 +47,15 @@ Happy path:
|
|
|
46
47
|
|
|
47
48
|
Run artifacts <command> --help for details.
|
|
48
49
|
`);
|
|
50
|
+
addNewCommand(program);
|
|
49
51
|
program
|
|
50
|
-
.command('
|
|
51
|
-
.description('
|
|
52
|
-
.argument('<
|
|
53
|
-
.option('--
|
|
54
|
-
.option('--
|
|
55
|
-
.option('--
|
|
56
|
-
.
|
|
57
|
-
Examples:
|
|
58
|
-
$ artifacts new plan --out plan.md # provenance filled from git and the agent env
|
|
59
|
-
$ artifacts new plan --blank # plan.template.md, every field left empty
|
|
60
|
-
$ artifacts new design # DESIGN.md, project-wide branding
|
|
61
|
-
`)
|
|
62
|
-
.action((kind, opts) => {
|
|
63
|
-
// A defaulted filename is a guess, so it must never clobber authored work.
|
|
64
|
-
// An explicit --out is the caller naming the target, which stays as-is.
|
|
65
|
-
const writeArtifact = (out, content, defaulted) => {
|
|
66
|
-
if (defaulted && !opts.force && existsSync(out)) {
|
|
67
|
-
throw new Error(`${out} already exists; pass --out <file> to write elsewhere, or --force to overwrite.`);
|
|
68
|
-
}
|
|
69
|
-
writeFileSync(out, content);
|
|
70
|
-
console.log(`${chalk.bold('wrote')} ${out}`);
|
|
71
|
-
};
|
|
72
|
-
// design is a different file shape entirely — its own frontmatter, no
|
|
73
|
-
// required sections — so it never goes through templateFor().
|
|
74
|
-
if (kind === 'design') {
|
|
75
|
-
if (opts.blank)
|
|
76
|
-
throw new Error('--blank does not apply to design; DESIGN.md has no context-filled variant.');
|
|
77
|
-
writeArtifact(opts.out || 'DESIGN.md', STARTER_DESIGN, !opts.out);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (!['plan', 'report', 'visual'].includes(kind)) {
|
|
81
|
-
throw new Error(`Unknown artifact kind: ${kind}; use plan, report, visual, or design.`);
|
|
82
|
-
}
|
|
83
|
-
const artifactKind = kind;
|
|
84
|
-
const out = opts.out || (opts.blank ? `${artifactKind}.template.md` : `${artifactKind}.md`);
|
|
85
|
-
const content = opts.blank ? templateFor(artifactKind) : templateFor(artifactKind, detectArtifactContext());
|
|
86
|
-
writeArtifact(out, content, !opts.out);
|
|
87
|
-
});
|
|
52
|
+
.command('answers')
|
|
53
|
+
.description('Read worksheet answers or merge an artifacts.answers.v1 export into Markdown.')
|
|
54
|
+
.argument('<worksheet.md|directory>')
|
|
55
|
+
.option('--from <export.json>', 'merge an exported answers file into the worksheet')
|
|
56
|
+
.option('--json', 'emit machine-readable JSON')
|
|
57
|
+
.option('--pending', 'show only pending fields or worksheets')
|
|
58
|
+
.action(answersCommand);
|
|
88
59
|
program
|
|
89
60
|
.command('check')
|
|
90
61
|
.alias('validate')
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAkB,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EA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AAgB,CAAC;KAC3C,MAAM,CAAC,iBAAiB,EAAE,8CAA8C,CAAC;KACzE,MAAM,CAAC,2BAA2B,EAAE,gCAAgC,CAAC;KACrE,MAAM,CAAC,UAAU,CAAC,CAAC;AACtB,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,iCAAiC,CAAC;KACjE,QAAQ,CAAC,WAAW,CAAC;KACrB,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC;KACxC,MAAM,CAAC,SAAS,CAAC,CAAC;AACrB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,iCAAiC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC3F,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC,+CAA+C,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AAC/G,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,4CAA4C,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAE5H,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC5C,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACjG,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import matter from 'gray-matter';
|
|
4
|
+
import { applyAnswers, fieldState, parseAnswersExport, parseWorksheet } from '../lib/worksheet.js';
|
|
5
|
+
function worksheetSource(path) {
|
|
6
|
+
const raw = readFileSync(path, 'utf8');
|
|
7
|
+
const parsed = matter(raw);
|
|
8
|
+
if (parsed.data.kind !== 'worksheet')
|
|
9
|
+
throw new Error(`${path} is not a worksheet (frontmatter kind must be worksheet).`);
|
|
10
|
+
const worksheet = parseWorksheet(parsed.content);
|
|
11
|
+
if (worksheet.issues.length)
|
|
12
|
+
throw new Error(`${path} has worksheet errors: ${worksheet.issues[0].message}`);
|
|
13
|
+
return { raw, data: parsed.data, worksheet };
|
|
14
|
+
}
|
|
15
|
+
function answerMap(path, pendingOnly) {
|
|
16
|
+
const { worksheet } = worksheetSource(path);
|
|
17
|
+
return Object.fromEntries(worksheet.fields
|
|
18
|
+
.filter((field) => !pendingOnly || fieldState(field) === 'pending')
|
|
19
|
+
.map((field) => [field.id, {
|
|
20
|
+
label: field.label,
|
|
21
|
+
value: field.value,
|
|
22
|
+
state: fieldState(field),
|
|
23
|
+
...(field.answered ? { answered: field.answered } : {}),
|
|
24
|
+
}]));
|
|
25
|
+
}
|
|
26
|
+
function preview(value) {
|
|
27
|
+
const oneLine = value.replace(/\s+/g, ' ').trim();
|
|
28
|
+
return oneLine.length > 54 ? `${oneLine.slice(0, 51)}...` : oneLine;
|
|
29
|
+
}
|
|
30
|
+
function showFile(path, options) {
|
|
31
|
+
const answers = answerMap(path, Boolean(options.pending));
|
|
32
|
+
if (options.json) {
|
|
33
|
+
console.log(JSON.stringify(answers, null, 2));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.log('id\tstate\tlabel\tvalue');
|
|
37
|
+
for (const [id, answer] of Object.entries(answers)) {
|
|
38
|
+
console.log(`${id}\t${answer.state}\t${answer.label}\t${preview(answer.value) || '—'}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function scanDirectory(path, options) {
|
|
42
|
+
const rows = readdirSync(path)
|
|
43
|
+
.filter((name) => name.endsWith('.md'))
|
|
44
|
+
.map((name) => join(path, name))
|
|
45
|
+
.flatMap((file) => {
|
|
46
|
+
try {
|
|
47
|
+
const { worksheet } = worksheetSource(file);
|
|
48
|
+
const pending = worksheet.fields.filter((field) => fieldState(field) === 'pending').length;
|
|
49
|
+
return options.pending && pending === 0 ? [] : [{ file, fields: worksheet.fields.length, pending }];
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (options.json)
|
|
56
|
+
console.log(JSON.stringify(rows, null, 2));
|
|
57
|
+
else {
|
|
58
|
+
console.log('file\tfields\tpending');
|
|
59
|
+
for (const row of rows)
|
|
60
|
+
console.log(`${row.file}\t${row.fields}\t${row.pending}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function answersCommand(target, options) {
|
|
64
|
+
const path = resolve(target);
|
|
65
|
+
if (statSync(path).isDirectory()) {
|
|
66
|
+
if (options.from)
|
|
67
|
+
throw new Error('--from requires a worksheet Markdown file, not a directory.');
|
|
68
|
+
scanDirectory(path, options);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!options.from) {
|
|
72
|
+
showFile(path, options);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const { raw, data, worksheet } = worksheetSource(path);
|
|
76
|
+
const exported = parseAnswersExport(readFileSync(resolve(options.from), 'utf8'));
|
|
77
|
+
if (exported.worksheet_id !== data.worksheet_id) {
|
|
78
|
+
throw new Error(`Worksheet id mismatch: source is ${String(data.worksheet_id || '(missing)')}, export is ${exported.worksheet_id}.`);
|
|
79
|
+
}
|
|
80
|
+
const result = applyAnswers(raw, exported, new Date().toISOString().slice(0, 10));
|
|
81
|
+
if (result.conflicts.length) {
|
|
82
|
+
const details = result.conflicts.map((item) => `${item.id}: baseline=${JSON.stringify(item.baseline)} yours=${JSON.stringify(item.yours)} current=${JSON.stringify(item.current)}`).join('\n');
|
|
83
|
+
throw new Error(`Answers merge aborted with ${result.conflicts.length} conflict(s); no changes written.\n${details}`);
|
|
84
|
+
}
|
|
85
|
+
writeFileSync(path, result.merged);
|
|
86
|
+
console.log(`merged ${result.mergedIds.length}/${worksheet.fields.length} · ${result.pending.length} still pending · ${result.orphans.length} orphans · 0 conflicts`);
|
|
87
|
+
for (const orphan of result.orphans)
|
|
88
|
+
console.log(`orphan ${orphan.id}: ${orphan.value}`);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=answers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answers.js","sourceRoot":"","sources":["../../src/commands/answers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQnG,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,2DAA2D,CAAC,CAAC;IAC1H,MAAM,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,0BAA0B,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC7G,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,C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EAAE,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAClF,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/L,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,CAAC,SAAS,CAAC,MAAM,sCAAsC,OAAO,EAAE,CAAC,CAAC;IACxH,CAAC;IACD,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACnC,OAAO,CAAC,GAAG,CAAC,UAAU,MAAM,CAAC,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,oBAAoB,MAAM,CAAC,OAAO,CAAC,MAAM,wBAAwB,CAAC,CAAC;IACtK,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,CAAC,GAAG,CAAC,UAAU,MAAM,CAAC,EAAE,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
export type NewOptions = {
|
|
3
|
+
out?: string;
|
|
4
|
+
blank?: boolean;
|
|
5
|
+
force?: boolean;
|
|
6
|
+
stdout?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function runNewCommand(kind: string, opts: NewOptions): void;
|
|
9
|
+
export declare function addNewCommand(program: Command): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { existsSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { detectArtifactContext, STARTER_DESIGN, templateFor } from '../lib/templates.js';
|
|
4
|
+
export function runNewCommand(kind, opts) {
|
|
5
|
+
if (opts.stdout && !opts.blank)
|
|
6
|
+
throw new Error('--stdout requires --blank.');
|
|
7
|
+
if (opts.stdout && opts.out)
|
|
8
|
+
throw new Error('--stdout cannot be combined with --out.');
|
|
9
|
+
if (opts.stdout && opts.force)
|
|
10
|
+
throw new Error('--stdout cannot be combined with --force.');
|
|
11
|
+
// A defaulted filename is a guess, so it must never clobber authored work.
|
|
12
|
+
// An explicit --out is the caller naming the target, which stays as-is.
|
|
13
|
+
const writeArtifact = (out, content, defaulted) => {
|
|
14
|
+
if (defaulted && !opts.force && existsSync(out)) {
|
|
15
|
+
throw new Error(`${out} already exists; pass --out <file> to write elsewhere, or --force to overwrite.`);
|
|
16
|
+
}
|
|
17
|
+
writeFileSync(out, content);
|
|
18
|
+
console.log(`${chalk.bold('wrote')} ${out}`);
|
|
19
|
+
};
|
|
20
|
+
// design is a different file shape entirely: its own frontmatter, no
|
|
21
|
+
// required sections, so it never goes through templateFor().
|
|
22
|
+
if (kind === 'design') {
|
|
23
|
+
if (opts.blank)
|
|
24
|
+
throw new Error('--blank does not apply to design; DESIGN.md has no context-filled variant.');
|
|
25
|
+
if (opts.stdout) {
|
|
26
|
+
process.stdout.write(STARTER_DESIGN);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
writeArtifact(opts.out || 'DESIGN.md', STARTER_DESIGN, !opts.out);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!['plan', 'report', 'visual', 'worksheet'].includes(kind)) {
|
|
33
|
+
throw new Error(`Unknown artifact kind: ${kind}; use plan, report, visual, worksheet, or design.`);
|
|
34
|
+
}
|
|
35
|
+
const artifactKind = kind;
|
|
36
|
+
const content = opts.blank ? templateFor(artifactKind) : templateFor(artifactKind, detectArtifactContext());
|
|
37
|
+
if (opts.stdout) {
|
|
38
|
+
process.stdout.write(content);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const out = opts.out || (opts.blank ? `${artifactKind}.template.md` : `${artifactKind}.md`);
|
|
42
|
+
writeArtifact(out, content, !opts.out);
|
|
43
|
+
}
|
|
44
|
+
export function addNewCommand(program) {
|
|
45
|
+
program
|
|
46
|
+
.command('new')
|
|
47
|
+
.description('Scaffold a Markdown artifact: plan, report, visual, worksheet, or design.')
|
|
48
|
+
.argument('<kind>', 'plan, report, visual, worksheet, or design')
|
|
49
|
+
.option('--out <file>', 'output file')
|
|
50
|
+
.option('--blank', 'write an unfilled template instead of a context-filled artifact')
|
|
51
|
+
.option('--stdout', 'print the artifact to stdout without writing a file')
|
|
52
|
+
.option('--force', 'overwrite the default output file if it already exists')
|
|
53
|
+
.addHelpText('after', `
|
|
54
|
+
Examples:
|
|
55
|
+
$ artifacts new plan --out plan.md # provenance filled from git and the agent env
|
|
56
|
+
$ artifacts new plan --blank # plan.template.md, every field left empty
|
|
57
|
+
$ artifacts new plan --blank --stdout # print the required section skeleton
|
|
58
|
+
$ artifacts new design # DESIGN.md, project-wide branding
|
|
59
|
+
`)
|
|
60
|
+
.action(runNewCommand);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=new.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.js","sourceRoot":"","sources":["../../src/commands/new.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,WAAW,EAAqB,MAAM,qBAAqB,CAAC;AAS5G,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE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
4
|
+
displayValue: string;
|
|
5
|
+
}
|
|
6
|
+
export interface BarChartData {
|
|
7
|
+
labelHeading: string;
|
|
8
|
+
valueHeading: string;
|
|
9
|
+
rows: BarChartDatum[];
|
|
10
|
+
}
|
|
11
|
+
/** Keep chart fence recognition identical anywhere Markdown tokens are consumed. */
|
|
12
|
+
export declare function isBarChartFence(info: string): boolean;
|
|
13
|
+
/** Parse a two-column Markdown table supplied by a `bar-chart` fence. */
|
|
14
|
+
export declare function parseBarChartTable(source: string): BarChartData | undefined;
|
|
15
|
+
/** Render a fenced Markdown data table as a theme-aware horizontal bar chart. */
|
|
16
|
+
export declare function renderBarChart(source: string): string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { escapeHtml } from './html.js';
|
|
2
|
+
const CHART_WIDTH = 720;
|
|
3
|
+
const LABEL_WIDTH = 180;
|
|
4
|
+
const VALUE_WIDTH = 88;
|
|
5
|
+
const PLOT_X = 196;
|
|
6
|
+
const PLOT_WIDTH = CHART_WIDTH - PLOT_X - VALUE_WIDTH;
|
|
7
|
+
const ROW_HEIGHT = 42;
|
|
8
|
+
const CHART_TOP = 42;
|
|
9
|
+
const CHART_BOTTOM = 18;
|
|
10
|
+
/** Keep chart fence recognition identical anywhere Markdown tokens are consumed. */
|
|
11
|
+
export function isBarChartFence(info) {
|
|
12
|
+
return info.trim().split(/\s+/)[0] === 'bar-chart';
|
|
13
|
+
}
|
|
14
|
+
function tableCells(line) {
|
|
15
|
+
const trimmed = line.trim().replace(/^\|/, '').replace(/\|$/, '');
|
|
16
|
+
const escapedPipe = '\uE002';
|
|
17
|
+
return trimmed
|
|
18
|
+
.replace(/\\\|/g, escapedPipe)
|
|
19
|
+
.split('|')
|
|
20
|
+
.map((cell) => cell.replaceAll(escapedPipe, '|').trim());
|
|
21
|
+
}
|
|
22
|
+
function isDivider(cells) {
|
|
23
|
+
return cells.length >= 2 && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
|
|
24
|
+
}
|
|
25
|
+
function numericValue(value) {
|
|
26
|
+
const normalized = value.replace(/,/g, '').replace(/^[$£€¥]/, '').replace(/%$/, '').trim();
|
|
27
|
+
if (!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(normalized))
|
|
28
|
+
return undefined;
|
|
29
|
+
const parsed = Number(normalized);
|
|
30
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Parse a two-column Markdown table supplied by a `bar-chart` fence. */
|
|
33
|
+
export function parseBarChartTable(source) {
|
|
34
|
+
const lines = source.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
35
|
+
if (lines.length < 3)
|
|
36
|
+
return undefined;
|
|
37
|
+
const header = tableCells(lines[0]);
|
|
38
|
+
const divider = tableCells(lines[1]);
|
|
39
|
+
if (header.length !== 2 || divider.length !== 2 || !isDivider(divider) || header.some((cell) => !cell)) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const rows = [];
|
|
43
|
+
for (const line of lines.slice(2)) {
|
|
44
|
+
const cells = tableCells(line);
|
|
45
|
+
if (cells.length !== 2 || !cells[0] || !cells[1])
|
|
46
|
+
return undefined;
|
|
47
|
+
const value = numericValue(cells[1]);
|
|
48
|
+
if (value === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
rows.push({ label: cells[0], value, displayValue: cells[1] });
|
|
51
|
+
}
|
|
52
|
+
if (rows.length === 0)
|
|
53
|
+
return undefined;
|
|
54
|
+
return { labelHeading: header[0], valueHeading: header[1], rows };
|
|
55
|
+
}
|
|
56
|
+
/** Render a fenced Markdown data table as a theme-aware horizontal bar chart. */
|
|
57
|
+
export function renderBarChart(source) {
|
|
58
|
+
const chart = parseBarChartTable(source);
|
|
59
|
+
if (!chart)
|
|
60
|
+
return `<pre><code class="language-bar-chart">${escapeHtml(source)}</code></pre>`;
|
|
61
|
+
const height = CHART_TOP + chart.rows.length * ROW_HEIGHT + CHART_BOTTOM;
|
|
62
|
+
const maximum = Math.max(...chart.rows.map((row) => row.value));
|
|
63
|
+
const title = `${chart.valueHeading} by ${chart.labelHeading}`;
|
|
64
|
+
const rows = chart.rows.map((row, index) => {
|
|
65
|
+
const y = CHART_TOP + index * ROW_HEIGHT;
|
|
66
|
+
const barWidth = maximum === 0 ? 0 : (row.value / maximum) * PLOT_WIDTH;
|
|
67
|
+
return [
|
|
68
|
+
`<text x="${LABEL_WIDTH}" y="${y + 22}" text-anchor="end" fill="var(--artifact-fg)">${escapeHtml(row.label)}</text>`,
|
|
69
|
+
`<line x1="${PLOT_X}" y1="${y + 30}" x2="${PLOT_X + PLOT_WIDTH}" y2="${y + 30}" stroke="var(--artifact-muted)" stroke-opacity="0.22" />`,
|
|
70
|
+
`<rect x="${PLOT_X}" y="${y + 8}" width="${barWidth}" height="22" rx="4" fill="var(--artifact-accent)" />`,
|
|
71
|
+
`<text x="${CHART_WIDTH - 8}" y="${y + 24}" text-anchor="end" fill="var(--artifact-fg)" font-weight="600">${escapeHtml(row.displayValue)}</text>`,
|
|
72
|
+
].join('');
|
|
73
|
+
}).join('');
|
|
74
|
+
return `<figure class="artifact-figure"><svg class="artifact-diagram" viewBox="0 0 ${CHART_WIDTH} ${height}" role="img" aria-label="${escapeHtml(title)}" xmlns="http://www.w3.org/2000/svg"><title>${escapeHtml(title)}</title><text x="${LABEL_WIDTH}" y="22" text-anchor="end" fill="var(--artifact-muted)" font-size="12" font-weight="600">${escapeHtml(chart.labelHeading)}</text><text x="${CHART_WIDTH - 8}" y="22" text-anchor="end" fill="var(--artifact-muted)" font-size="12" font-weight="600">${escapeHtml(chart.valueHeading)}</text>${rows}</svg></figure>`;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=charts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charts.js","sourceRoot":"","sources":["../../src/lib/charts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAcvC,MAAM,WAAW,GAAG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C;QACzC,MAAM,QAAQ,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,UAAU,CAAC;QACxE,OAAO;YACL,YAAY,WAAW,QAAQ,CAAC,GAAG,EAAE,iDAAiD,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS;YACpH,aAAa,MAAM,SAAS,CAAC,GAAG,EAAE,SAAS,MAAM,GAAG,UAAU,SAAS,CAAC,GAAG,EAAE,2DAA2D;YACxI,YAAY,MAAM,QAAQ,CAAC,GAAG,CAAC,YAAY,QAAQ,uDAAuD;YAC1G,YAAY,WAAW,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,mEAAmE,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS;SAClJ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACb,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEZ,OAAO,8EAA8E,WAAW,IAAI,MAAM,4BAA4B,UAAU,CAAC,KAAK,CAAC,+CAA+C,UAAU,CAAC,KAAK,CAAC,oBAAoB,WAAW,4FAA4F,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,mBAAmB,WAAW,GAAG,CAAC,4FAA4F,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,IAAI,iBAAiB,CAAC;AAC9iB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const EMBEDDED_ARTIFACT_CLASSES: readonly ["artifact-behavior", "artifact-behavior-panel", "artifact-callout", "artifact-callout-danger", "artifact-callout-warn", "artifact-diagram", "artifact-figure", "artifact-figure-diagram", "artifact-figure-tall", "artifact-figure-wide", "artifact-grid", "artifact-grid-2", "artifact-grid-3", "artifact-image", "artifact-legend", "artifact-panel", "artifact-stat", "artifact-stat-label", "artifact-stat-value", "artifact-tag", "artifact-tag-accent", "code-diff", "code-diff-file", "code-diff-pre", "cd-line", "cd-sign", "cd-code", "cd-add", "cd-del", "cd-ctx", "cd-hunk", "cd-meta", "checklist", "checklist-head", "checklist-items", "cl-item", "cl-done", "cl-doing", "cl-todo", "cl-box", "cl-text"];
|
|
1
|
+
export declare const EMBEDDED_ARTIFACT_CLASSES: readonly ["artifact-behavior", "artifact-behavior-panel", "artifact-callout", "artifact-callout-danger", "artifact-callout-warn", "artifact-diagram", "artifact-figure", "artifact-figure-diagram", "artifact-figure-tall", "artifact-figure-wide", "artifact-grid", "artifact-grid-2", "artifact-grid-3", "artifact-image", "artifact-legend", "artifact-panel", "artifact-stat", "artifact-stat-label", "artifact-stat-value", "artifact-tag", "artifact-tag-accent", "code-diff", "code-diff-file", "code-diff-pre", "cd-line", "cd-sign", "cd-code", "cd-add", "cd-del", "cd-ctx", "cd-hunk", "cd-meta", "checklist", "checklist-head", "checklist-items", "cl-item", "cl-done", "cl-doing", "cl-todo", "cl-box", "cl-text", "wq-card", "wq-head", "wq-label", "wq-hint", "wq-chip", "wq-chip-draft", "wq-chip-you", "wq-chip-answered", "wq-chip-edited", "wq-copy", "wq-textarea", "wq-input", "wq-group", "wq-row", "wq-row-label"];
|
|
2
2
|
export interface EmbeddedHtmlIssue {
|
|
3
3
|
index: number;
|
|
4
4
|
message: string;
|
|
@@ -41,6 +41,21 @@ export const EMBEDDED_ARTIFACT_CLASSES = [
|
|
|
41
41
|
'cl-todo',
|
|
42
42
|
'cl-box',
|
|
43
43
|
'cl-text',
|
|
44
|
+
'wq-card',
|
|
45
|
+
'wq-head',
|
|
46
|
+
'wq-label',
|
|
47
|
+
'wq-hint',
|
|
48
|
+
'wq-chip',
|
|
49
|
+
'wq-chip-draft',
|
|
50
|
+
'wq-chip-you',
|
|
51
|
+
'wq-chip-answered',
|
|
52
|
+
'wq-chip-edited',
|
|
53
|
+
'wq-copy',
|
|
54
|
+
'wq-textarea',
|
|
55
|
+
'wq-input',
|
|
56
|
+
'wq-group',
|
|
57
|
+
'wq-row',
|
|
58
|
+
'wq-row-label',
|
|
44
59
|
];
|
|
45
60
|
export const EMBEDDED_BLOCK_TAGS = ['svg', 'figure', 'section', 'article', 'aside', 'div', 'details'];
|
|
46
61
|
export const EMBEDDED_BLOCK_PATTERN = new RegExp(`<(?:${EMBEDDED_BLOCK_TAGS.join('|')})\\b`, 'i');
|