@cfbender/cesium 0.4.0 → 0.5.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 +94 -0
- package/README.md +2 -5
- package/package.json +3 -2
- package/src/cli/commands/serve.ts +18 -2
- package/src/index.ts +4 -1
- package/src/prompt/field-reference.ts +94 -0
- package/src/prompt/system-fragment.md +56 -65
- package/src/render/blocks/catalog.ts +39 -0
- package/src/render/blocks/escape.ts +27 -0
- package/src/render/blocks/highlight.ts +188 -0
- package/src/render/blocks/index.ts +6 -0
- package/src/render/blocks/markdown.ts +217 -0
- package/src/render/blocks/render.ts +104 -0
- package/src/render/blocks/renderers/callout.ts +38 -0
- package/src/render/blocks/renderers/code.ts +46 -0
- package/src/render/blocks/renderers/compare-table.ts +56 -0
- package/src/render/blocks/renderers/diagram.ts +48 -0
- package/src/render/blocks/renderers/divider.ts +31 -0
- package/src/render/blocks/renderers/hero.ts +66 -0
- package/src/render/blocks/renderers/kv.ts +45 -0
- package/src/render/blocks/renderers/list.ts +51 -0
- package/src/render/blocks/renderers/pill-row.ts +45 -0
- package/src/render/blocks/renderers/prose.ts +29 -0
- package/src/render/blocks/renderers/raw-html.ts +32 -0
- package/src/render/blocks/renderers/risk-table.ts +76 -0
- package/src/render/blocks/renderers/section.ts +97 -0
- package/src/render/blocks/renderers/timeline.ts +58 -0
- package/src/render/blocks/renderers/tldr.ts +30 -0
- package/src/render/blocks/themes/claret-dark.ts +206 -0
- package/src/render/blocks/themes/claret-light.ts +227 -0
- package/src/render/blocks/types.ts +127 -0
- package/src/render/blocks/validate-block.ts +202 -0
- package/src/render/critique.ts +410 -10
- package/src/render/fallback.ts +18 -0
- package/src/render/theme.ts +154 -0
- package/src/render/validate.ts +282 -17
- package/src/render/wrap.ts +7 -7
- package/src/server/lifecycle.ts +190 -3
- package/src/storage/assets.ts +66 -0
- package/src/storage/index-cache.ts +1 -0
- package/src/storage/index-gen.ts +13 -14
- package/src/tools/ask.ts +7 -5
- package/src/tools/critique.ts +41 -6
- package/src/tools/publish.ts +43 -14
- package/src/tools/styleguide.ts +118 -9
package/src/tools/styleguide.ts
CHANGED
|
@@ -1,15 +1,124 @@
|
|
|
1
|
-
// Tool handler for cesium_styleguide — returns
|
|
1
|
+
// Tool handler for cesium_styleguide — returns a markdown reference generated from the block catalog.
|
|
2
2
|
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
3
|
import { tool } from "@opencode-ai/plugin";
|
|
7
4
|
import type { PluginInput } from "@opencode-ai/plugin";
|
|
5
|
+
import { blockCatalog, blockTypes } from "../render/blocks/catalog.ts";
|
|
6
|
+
import { renderBlock } from "../render/blocks/render.ts";
|
|
7
|
+
import type { RenderCtx, SectionCounter } from "../render/blocks/render.ts";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
9
|
+
function makeCtx(): RenderCtx {
|
|
10
|
+
const counter: SectionCounter = { value: 1 };
|
|
11
|
+
return { sectionCounter: counter, depth: 0, path: "blocks[0]", highlightTheme: "claret-dark" };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Escape a string for safe insertion inside a markdown fenced code block. */
|
|
15
|
+
function escapeForCodeFence(s: string): string {
|
|
16
|
+
// Prevent accidental fence closing — replace ``` with ` `` ` (rare in practice)
|
|
17
|
+
return s.replace(/```/g, "` `` `");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Generate the full markdown reference from the catalog. Deterministic — same catalog → same output. */
|
|
21
|
+
export async function generateStyleguideMarkdown(): Promise<string> {
|
|
22
|
+
const lines: string[] = [];
|
|
23
|
+
|
|
24
|
+
lines.push("# Cesium publishing reference");
|
|
25
|
+
lines.push("");
|
|
26
|
+
lines.push("## Two input modes");
|
|
27
|
+
lines.push("");
|
|
28
|
+
lines.push(
|
|
29
|
+
"`cesium_publish` accepts either `blocks: Block[]` (preferred) or `html: string`" +
|
|
30
|
+
" (escape valve). Provide exactly one.",
|
|
31
|
+
);
|
|
32
|
+
lines.push("");
|
|
33
|
+
lines.push(
|
|
34
|
+
"Prefer `blocks` for plans, reviews, reports, explainers, comparisons, audits, design docs." +
|
|
35
|
+
" Use `html` only for whole-document bespoke layouts (custom hero, non-standard grid," +
|
|
36
|
+
" experimental visual essay). For isolated bespoke regions, stay in `blocks` and use" +
|
|
37
|
+
" `raw_html` or `diagram`.",
|
|
38
|
+
);
|
|
39
|
+
lines.push("");
|
|
40
|
+
lines.push("## Block reference");
|
|
41
|
+
lines.push("");
|
|
42
|
+
|
|
43
|
+
// Pre-render all examples in parallel (order preserved via index)
|
|
44
|
+
const renderedExamples = await Promise.all(
|
|
45
|
+
blockTypes.map(async (blockType) => {
|
|
46
|
+
const entry = blockCatalog[blockType];
|
|
47
|
+
if (entry.renderedExample !== undefined) {
|
|
48
|
+
return entry.renderedExample;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return await renderBlock(entry.example, makeCtx());
|
|
52
|
+
} catch {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < blockTypes.length; i++) {
|
|
59
|
+
const blockType = blockTypes[i];
|
|
60
|
+
if (blockType === undefined) continue;
|
|
61
|
+
const entry = blockCatalog[blockType];
|
|
62
|
+
const rendered = renderedExamples[i] ?? "";
|
|
63
|
+
|
|
64
|
+
lines.push(`### \`${entry.type}\``);
|
|
65
|
+
lines.push("");
|
|
66
|
+
lines.push(entry.description);
|
|
67
|
+
lines.push("");
|
|
68
|
+
|
|
69
|
+
// Schema as JSON
|
|
70
|
+
lines.push("```json");
|
|
71
|
+
lines.push(escapeForCodeFence(JSON.stringify(entry.schema, null, 2)));
|
|
72
|
+
lines.push("```");
|
|
73
|
+
lines.push("");
|
|
74
|
+
|
|
75
|
+
// Canonical example
|
|
76
|
+
lines.push("Example:");
|
|
77
|
+
lines.push("");
|
|
78
|
+
lines.push("```json");
|
|
79
|
+
lines.push(escapeForCodeFence(JSON.stringify(entry.example, null, 2)));
|
|
80
|
+
lines.push("```");
|
|
81
|
+
lines.push("");
|
|
82
|
+
|
|
83
|
+
if (rendered !== "") {
|
|
84
|
+
lines.push("Renders to:");
|
|
85
|
+
lines.push("");
|
|
86
|
+
lines.push("```html");
|
|
87
|
+
lines.push(escapeForCodeFence(rendered));
|
|
88
|
+
lines.push("```");
|
|
89
|
+
lines.push("");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
lines.push(
|
|
94
|
+
"## Markdown subset (inside `prose`, `tldr`, `callout.markdown`, list items, table cells)",
|
|
95
|
+
);
|
|
96
|
+
lines.push("");
|
|
97
|
+
lines.push(
|
|
98
|
+
"- Block: paragraph, `-` lists, `1.` lists, `>` blockquote, `---` rule, hard break (two-space EOL).",
|
|
99
|
+
);
|
|
100
|
+
lines.push(
|
|
101
|
+
"- Inline: `**bold**`, `*italic*`, `` `code` ``, `[text](href)` (relative or anchor only).",
|
|
102
|
+
);
|
|
103
|
+
lines.push(
|
|
104
|
+
"- HTML safelist: `<kbd>`, `<span class=\"pill\">`, `<span class=\"tag\">`. Anything else is escaped.",
|
|
105
|
+
);
|
|
106
|
+
lines.push("");
|
|
107
|
+
lines.push("## When to reach for raw_html / diagram");
|
|
108
|
+
lines.push("");
|
|
109
|
+
lines.push(
|
|
110
|
+
"- `diagram` — inline SVG visualizations or bespoke composed HTML diagrams.",
|
|
111
|
+
);
|
|
112
|
+
lines.push(
|
|
113
|
+
"- `raw_html` — anything genuinely creative that doesn't fit a known block type." +
|
|
114
|
+
" Include a `purpose` string describing what you're building.",
|
|
115
|
+
);
|
|
116
|
+
lines.push(
|
|
117
|
+
"- Critique flags raw_html overuse (>2 blocks or >30% of body characters).",
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
return lines.join("\n");
|
|
121
|
+
}
|
|
13
122
|
|
|
14
123
|
export function createStyleguideTool(_ctx: PluginInput): ReturnType<typeof tool> {
|
|
15
124
|
return tool({
|
|
@@ -17,7 +126,7 @@ export function createStyleguideTool(_ctx: PluginInput): ReturnType<typeof tool>
|
|
|
17
126
|
"Returns the cesium HTML design system reference page (CSS classes with example usage). Call this once at the start of writing a complex artifact to internalize the available components.",
|
|
18
127
|
args: {},
|
|
19
128
|
async execute(_args, _context) {
|
|
20
|
-
return await
|
|
129
|
+
return await generateStyleguideMarkdown();
|
|
21
130
|
},
|
|
22
131
|
});
|
|
23
132
|
}
|