@soleur/opencode 3.357.10 → 3.357.12
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/agents/product/design/ux-design-lead.md +5 -5
- package/package.json +1 -1
- package/skills/brainstorm/references/brainstorm-brand-workshop.md +3 -3
- package/skills/brainstorm-techniques/references/technical-ruling-delegation.md +3 -1
- package/skills/pencil-setup/SKILL.md +5 -1
- package/skills/pencil-setup/scripts/check_deps.sh +35 -3
- package/skills/pencil-setup/scripts/copy_adapter.sh +11 -5
- package/skills/pencil-setup/scripts/engine-contract-probe.sh +187 -0
- package/skills/pencil-setup/scripts/pencil-error-enrichment.mjs +20 -0
- package/skills/pencil-setup/scripts/pencil-mcp-adapter.mjs +507 -305
- package/skills/pencil-setup/scripts/pencil-repl-surface.mjs +136 -0
- package/skills/pencil-setup/scripts/pencil-response-classify.mjs +3 -0
- package/skills/pencil-setup/scripts/pencil-save-gate.mjs +164 -1
|
@@ -54,8 +54,8 @@ Use the **AskUserQuestion tool** to clarify the design scope:
|
|
|
54
54
|
|
|
55
55
|
**KISS — design for the least loaded screen that still does the job (apply throughout this step).** The default bias is *fewer* elements, not more. Before adding any element to a frame, require it to earn its place by carrying either information the user needs or an action the user takes — decorative glyphs (status dots, accent flourishes), redundant labels (a single-letter monogram next to the icon it abbreviates), and duplicate affordances (two controls that do the same thing) are clutter and must be cut. Prefer one clear path over several; prefer an icon-with-tooltip over an icon-plus-label-plus-badge; collapse adjacent rows that say the same thing. When two layouts satisfy the brief, ship the simpler one. Persistent chrome (sidebars, top bars, rails) is where clutter compounds across every session, so hold it to the strictest version of this bar. This is the design-time complement to the `real-estate`/`comprehension` audit rubric below — catch the load before it ships, not only in audit.
|
|
56
56
|
|
|
57
|
-
1. Call `get_style_guide_tags` then `get_style_guide(tags)` for design inspiration. If brand tokens were extracted in Step 1, use those as primary constraints.
|
|
58
|
-
2. Call `get_guidelines(
|
|
57
|
+
1. Call `get_style_guide_tags` then `get_style_guide(tags)` for design inspiration (Pencil Desktop/IDE). The headless adapter (`@pencil.dev/cli` 0.2.9) has no style-guide tools: they answer `Unknown tool: …` with an `[adapter hint]` ("not available in the headless CLI"); skip them and continue with the brand tokens. If brand tokens were extracted in Step 1, use those as primary constraints.
|
|
58
|
+
2. Call `get_guidelines()` with no arguments to list the guides, then `get_guidelines({ category: "guide", name })` for the relevant design type (headless guide names: `Landing Page`, `Design System`, `Table`, `Web App`, `Mobile App`, `Slides`, `Code`, `Tailwind`; Desktop/IDE keep the older `topic` argument). Before the first `batch_design`, call `get_editor_state({ include_schema: true })` once: it returns the operation grammar that the adapter's `operations` field takes.
|
|
59
59
|
3. Use `open_document` to create a new .pen file or open an existing one.
|
|
60
60
|
|
|
61
61
|
**Pre-open snapshot + post-open collapse gate (HARD GATE).** When `open_document`
|
|
@@ -67,7 +67,7 @@ Use the **AskUserQuestion tool** to clarify the design scope:
|
|
|
67
67
|
- Record a pre-open snapshot of the existing file's size and sha256 checksum (`stat -c %s <path>` plus `sha256sum <path>`) **before** calling `open_document`. Note both values.
|
|
68
68
|
- Call `open_document`.
|
|
69
69
|
- **After** the call, immediately re-`stat -c %s <path>`. **Collapse gate:** if the
|
|
70
|
-
post-open size is `< 50%` of the pre-open size **OR** post-open size `≤
|
|
70
|
+
post-open size is `< 50%` of the pre-open size **OR** post-open size `≤ 128 bytes` (the empty document is 96 bytes)
|
|
71
71
|
while the pre-open was larger, treat the open as a **destructive wipe / parse
|
|
72
72
|
failure** — do NOT proceed with iteration. Halt, surface the pre-open vs post-open
|
|
73
73
|
sizes and the pre-open checksum verbatim, and recover the source from git
|
|
@@ -76,7 +76,7 @@ Use the **AskUserQuestion tool** to clarify the design scope:
|
|
|
76
76
|
gate at Step 3 item 2; cross-reference the two.
|
|
77
77
|
- **New-file exemption:** when `open_document` creates a brand-new document there is
|
|
78
78
|
no pre-existing file to snapshot, and the collapse gate does not apply (a new doc
|
|
79
|
-
legitimately starts at ~41 bytes). The gate fires only when opening a pre-existing
|
|
79
|
+
legitimately starts at ~41-96 bytes). The gate fires only when opening a pre-existing
|
|
80
80
|
non-empty `.pen`.
|
|
81
81
|
4. Iterative design loop:
|
|
82
82
|
- Use `batch_design` to build frames, components, and content
|
|
@@ -87,7 +87,7 @@ Use the **AskUserQuestion tool** to clarify the design scope:
|
|
|
87
87
|
### Step 3: Deliver
|
|
88
88
|
|
|
89
89
|
1. Save the .pen file to `knowledge-base/product/design/{domain}/{descriptive-name}.pen` (e.g., `design/brand/landing-page.pen`, `design/onboarding/signup-flow.pen`). **The `product/` segment is mandatory — the pre-#566 top-level design directory was removed in the domain restructure and writing there produces a placeholder that no automated audit catches.**
|
|
90
|
-
2. **Post-save size verification (HARD GATE).** Before announcing completion, `stat -c %s <saved-file>` and assert the result is
|
|
90
|
+
2. **Post-save size verification (HARD GATE).** Before announcing completion, `stat -c %s <saved-file>` and assert the result is larger than 128 bytes (a 96-byte file is an empty `{"children": []}` document, which `> 0` wrongly accepts). The headless adapter's `open_document` also reports `N top-level node(s) loaded`; after reopening, `N` must be at least 1 (a new, untracked `.pen` cannot be reopened under this repo's `pencil-open-guard.sh`: commit it first, or verify with `batch_get()` plus `stat` instead). The adapter refuses (`REFUSED save:`) to write an empty document over a file that holds nodes: surface that text verbatim. If the file is 0 bytes, the preceding Pencil MCP calls silently dropped (typically an auth or schema error the adapter returned as `isError: true`). **Read the actual adapter error text and surface it verbatim — do NOT fabricate a "headless stub" or "dropped ops" narrative.** The adapter has no stub code path; a 0-byte file always corresponds to a real `isError` response the caller can inspect. See the "Silent-drop diagnosis" Sharp Edge (`ex-cq-pencil-mcp-silent-drop-diagnosis-checklist`) in `plugins/soleur/skills/pencil-setup/SKILL.md` and the learning `knowledge-base/project/learnings/bug-fixes/2026-04-19-ux-design-lead-headless-stub-fabrication.md`.
|
|
91
91
|
3. **Export high-resolution screenshots.** Use `export_nodes` with `scale: 3` and `format: "png"` to export all top-level frames as **direct children** of the `screenshots/` subdirectory next to the .pen file (e.g., `knowledge-base/product/design/billing/screenshots/`). **Do NOT create a nested per-feature subfolder** — `.gitignore` rule `!knowledge-base/product/design/**/screenshots/*.png` only unignores PNGs that are direct children of `screenshots/`; nested paths like `screenshots/<feature>/05-foo.png` stay gitignored and silently fail to commit. Verify with `git check-ignore -v <png>` before announcing completion. Do NOT use `get_screenshot` for final deliverables — it produces low-resolution 512px images. `export_nodes` with `scale: 3` produces ~4K images suitable for review.
|
|
92
92
|
4. **Rename screenshots to human-readable names.** `export_nodes` saves files as `{nodeId}.png`. After export, rename each file to a feature-prefixed kebab-case name continuing the existing `NN-` numbering already in the `screenshots/` folder (e.g., if `01-04` exist, the new feature starts at `05-`; rename `bBxvQ.png` → `05-upgrade-modal-at-capacity-solo.png`). Then remove the raw `{nodeId}.png` exports left behind by `export_nodes` so they don't appear as untracked siblings.
|
|
93
93
|
5. **Open the screenshots folder** for founder review: `xdg-open <screenshots-directory>`. This step is not optional — the founder must visually review wireframes before proceeding. The interactive **approve / request-changes** pause lives in the *orchestrator* (brainstorm Phase 3.55b / plan Phase 2.5 step 4b), NOT in this agent — a Task subagent cannot pause for operator input (`2026-05-12-task-subagent-prompt-text-only.md`), so this agent's job ends at opening the folder and returning. Do not re-add an `AskUserQuestion` pause here.
|
package/package.json
CHANGED
|
@@ -85,15 +85,15 @@ a.1. **Commit the `.pen` source immediately after first save (recover-from-wipe
|
|
|
85
85
|
onward) — so an iteration-cycle wipe (#3274: `open_document` silently
|
|
86
86
|
overwriting the source with empty state) is recoverable via
|
|
87
87
|
`git checkout -- <path>`. **Gate the commit on a non-collapsed save first**:
|
|
88
|
-
`stat -c %s <pen>` must be `>
|
|
88
|
+
`stat -c %s <pen>` must be `> 128 bytes` (the 41- to 96-byte empty `{"version": …, "children": []}`
|
|
89
89
|
shell is a failed/empty save, not a baseline worth committing — committing it
|
|
90
|
-
defeats the recover-from-wipe purpose). If the `.pen` is `≤
|
|
90
|
+
defeats the recover-from-wipe purpose). If the `.pen` is `≤ 128 bytes`, halt and
|
|
91
91
|
surface the save failure instead of committing.
|
|
92
92
|
|
|
93
93
|
```bash
|
|
94
94
|
pen=knowledge-base/product/design/brand/<topic>-<YYYY-MM-DD>/<topic>.pen
|
|
95
95
|
sz=$(stat -c %s "$pen")
|
|
96
|
-
if [[ "$sz" -le
|
|
96
|
+
if [[ "$sz" -le 128 ]]; then
|
|
97
97
|
echo "BLOCKED: $pen is only ${sz}B — first save did not produce a real document; not committing a wiped baseline." >&2
|
|
98
98
|
else
|
|
99
99
|
git add "$pen"
|
|
@@ -116,7 +116,9 @@ per persisted decision, whatever shape the free-form body uses. Columns: `Item |
|
|
|
116
116
|
gets an `operator (scope)` row naming that override, so the operator sees it. A CLO ruling on legal posture is recorded
|
|
117
117
|
with Class `operator (legal-risk)` and a `Ruled by CLO agent, <date>: ...` Ruling; `technical (legal)` is not a valid Class.
|
|
118
118
|
- **Ruling, technical row:** `Ruled by CTO agent, <date>: <decision> - <rationale>` (`CLO` for legal; and `Dissent: <line>` when
|
|
119
|
-
present).
|
|
119
|
+
present). Write the cell only AFTER the agent's reply is in context, copying its decision: the gate checks the cell's
|
|
120
|
+
shape and cannot tell whether the consultation happened. **Why:** #10552 — three rows were pre-written with a CTO/CLO
|
|
121
|
+
name before either was asked; a fix-round seat caught it, and the CLO's real answer amended one row. If the ruling differs from what a headless subagent assumed and built, re-enter `work` for the item.
|
|
120
122
|
- **Ruling, operator row:** the ACTION being authorised, citing the sibling technical row's item id when split. For a
|
|
121
123
|
production-mutating act covered by a Standing Delegation the Ruling cell reads exactly
|
|
122
124
|
`Authorized by delegation <comment-url>, envelope <path>[, ran <ISO>]` and is valid only on
|
|
@@ -196,6 +196,10 @@ The hook fires **PostToolUse** on `mcp__pencil__open_document`. When the on-disk
|
|
|
196
196
|
- **pencil CLI collision**: The `pencil` binary name collides with evolus/pencil. The check_deps.sh script guards against this by verifying the version string contains "pencil.dev" or checking for the `mcp-server` subcommand.
|
|
197
197
|
- **Headless CLI interactive mode is not MCP**: The Pencil npm headless CLI's `pencil interactive` command speaks a custom REPL format (`tool_name({ key: value })`), not MCP protocol. An adapter wrapper is needed to bridge it to Claude Code's MCP framework. The headless CLI also lacks the `mcp-server` subcommand that the Desktop-installed CLI exposes, and its version string (`pencil 0.2.3`) doesn't match existing detection patterns.
|
|
198
198
|
- **Headless CLI has programmatic save**: Unlike Desktop/IDE modes, `pencil interactive --out` supports a `save()` command that writes to disk without manual Ctrl+S.
|
|
199
|
+
- **Headless engine contract (#11143)**: the adapter targets `@pencil.dev/cli` **0.2.9**, pinned in `check_deps.sh`. Its `batch_design` takes `{ input }` (the adapter maps its `operations` field onto it); an unknown key is dropped by the engine and answered `OK`, so every REPL line goes through `formatReplCommand` in `pencil-repl-surface.mjs`, which throws on a tool or key not in that table. Short aliases `I()`/`U()`/`C()` work through a per-call `var` preamble. `set_variables`, `find_empty_space_on_canvas`, `get_style_guide`, `get_style_guide_tags`, `search_all_unique_properties` and `replace_all_matching_properties` do not exist in 0.2.9: they return `Unknown tool:` plus a replacement hint and never save.
|
|
200
|
+
- **`open_document` loads the existing file**: the adapter passes `--in <file>` when the target exists and is non-empty, so reopening resumes the design; a respawn after a crash reloads the saved file, never a template `inputPath`. It reports `N top-level node(s) loaded` and fails (refusing every tool until the next successful `open_document`) when the file it loaded from holds nodes that did not load, or is not a recognizable `.pen` document at all (the engine loads such a file as EMPTY without an error). Targets must be plain `.pen` files: a wrong extension or a symlink is refused, and `inputPath` (a template) is refused when `filePath` already holds a document, because the first save would replace it.
|
|
201
|
+
- **Save sentinel**: every save (auto-save and the explicit `save` tool) is one exclusive job that reads the file, probes the in-memory document and refuses (`REFUSED save:`) an empty document over a file that still holds nodes, and anything over a file that exists but is not a recognizable `.pen` document. The in-memory node count is read from the untruncated `batch_get()` reply (a capped reply is not valid JSON, and would refuse every save of a design above 64 KB). To start a design over, open a new file path; do not delete the file to bypass it. This is the only protection on a customer machine, where this repo's open/collapse hooks do not exist.
|
|
202
|
+
- **Bumping the CLI pin**: run `doppler run -p soleur -c dev -- bash "${CLAUDE_PLUGIN_ROOT}/skills/pencil-setup/scripts/engine-contract-probe.sh"` first. It diffs the CLI's `--help` signatures against the adapter's table and does a real round trip (exit 3 without `PENCIL_CLI_KEY`). The migration to `@pen.dev/cli` is tracked in #11156.
|
|
199
203
|
- **Adapter child process Node version**: The pencil CLI uses `#!/usr/bin/env node`, so the resolved Node depends on PATH, not on the binary that launched the adapter. The adapter's `buildPencilEnv()` must prepend `dirname(process.execPath)` to PATH to ensure child processes inherit the correct Node version (22+).
|
|
200
204
|
- **Text nodes do not support `padding`**: Passing `padding` to a `batch_design` operation on a text node produces "Invalid properties: /padding unexpected property". The adapter enriches this error with a hint, but the fix is to wrap the text in a frame and apply padding to the frame instead (see #1107 workaround).
|
|
201
|
-
- **Silent-drop diagnosis**: When a Pencil MCP op appears to "silently drop" or produces a 0-byte `.pen`, verify in order: (a) `claude mcp get pencil` env has `PENCIL_CLI_KEY` matching Doppler `soleur/dev`, (b) `bash "${CLAUDE_PLUGIN_ROOT}/skills/pencil-setup/scripts/check_deps.sh" --check-adapter-drift` prints `OK`, (c) saved file `stat -c %s`
|
|
205
|
+
- **Silent-drop diagnosis**: When a Pencil MCP op appears to "silently drop" or produces a 0-byte `.pen`, verify in order: (a) `claude mcp get pencil` env has `PENCIL_CLI_KEY` matching Doppler `soleur/dev`, (b) `bash "${CLAUDE_PLUGIN_ROOT}/skills/pencil-setup/scripts/check_deps.sh" --check-adapter-drift` prints `OK`, (c) saved file `stat -c %s` is larger than the 96-byte empty document (a bare `> 0` accepts an empty document). "Headless stub" is NOT a known failure mode — the adapter has no stub code path. (`ex-cq-pencil-mcp-silent-drop-diagnosis-checklist`; #2630; `knowledge-base/project/learnings/bug-fixes/2026-04-19-ux-design-lead-headless-stub-fabrication.md`)
|
|
@@ -4,6 +4,15 @@
|
|
|
4
4
|
# No set -euo pipefail: soft dependency checks and install failures
|
|
5
5
|
# must not abort the script. Each check uses explicit if/then.
|
|
6
6
|
|
|
7
|
+
case "$-" in
|
|
8
|
+
*x*)
|
|
9
|
+
if [ -n "${PENCIL_CLI_KEY:+x}" ]; then
|
|
10
|
+
printf '[FATAL] refusing to trace with a live credential set (see #7797)\n' >&2
|
|
11
|
+
exit 78
|
|
12
|
+
fi
|
|
13
|
+
;;
|
|
14
|
+
esac
|
|
15
|
+
|
|
7
16
|
AUTO_INSTALL=false
|
|
8
17
|
CHECK_ADAPTER_DRIFT=false
|
|
9
18
|
for arg in "$@"; do
|
|
@@ -48,7 +57,27 @@ if [[ "$CHECK_ADAPTER_DRIFT" == "true" ]]; then
|
|
|
48
57
|
installed_sha=$(sha256sum -- "$installed_adapter" | awk '{print $1}')
|
|
49
58
|
repo_sha=$(sha256sum -- "$repo_adapter" | awk '{print $1}')
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
# Compare EVERY runtime module copy_adapter.sh installs, not only the main
|
|
61
|
+
# file: a stale sibling (the save sentinel, the REPL surface table) next to a
|
|
62
|
+
# fresh adapter is exactly the state this check exists to catch. The list is
|
|
63
|
+
# read from copy_adapter.sh so the two cannot disagree. (A while-read loop, not
|
|
64
|
+
# mapfile: this script also runs on macOS bash 3.2.)
|
|
65
|
+
drifted=""
|
|
66
|
+
compared=0
|
|
67
|
+
while IFS= read -r module; do
|
|
68
|
+
[[ -n "$module" ]] || continue
|
|
69
|
+
compared=$((compared + 1))
|
|
70
|
+
if [[ ! -f "$install_dir/$module" ]] || ! cmp -s -- "$script_dir/$module" "$install_dir/$module"; then
|
|
71
|
+
drifted="$drifted $module"
|
|
72
|
+
fi
|
|
73
|
+
done < <(sed -n '/^ADAPTER_FILES=(/,/^)/p' "$script_dir/copy_adapter.sh" | grep -o '"[^"]*\.mjs"' | tr -d '"')
|
|
74
|
+
if [[ "$compared" -eq 0 ]]; then
|
|
75
|
+
# An unreadable module list must not read as "no drift": it would compare nothing.
|
|
76
|
+
echo "ERROR: no adapter modules parsed from $script_dir/copy_adapter.sh ADAPTER_FILES" >&2
|
|
77
|
+
exit 2
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
if [[ -z "$drifted" ]]; then
|
|
52
81
|
echo "OK: installed adapter matches repo (sha ${repo_sha:0:12})"
|
|
53
82
|
exit 0
|
|
54
83
|
fi
|
|
@@ -69,7 +98,7 @@ if [[ "$CHECK_ADAPTER_DRIFT" == "true" ]]; then
|
|
|
69
98
|
fi
|
|
70
99
|
fi
|
|
71
100
|
|
|
72
|
-
echo "DRIFT: installed ${installed_sha:0:12} != repo ${repo_sha:0:12}"
|
|
101
|
+
echo "DRIFT: installed ${installed_sha:0:12} != repo ${repo_sha:0:12}; differing or missing:${drifted}"
|
|
73
102
|
echo " Run: bash $(basename "${BASH_SOURCE[0]}") --check-adapter-drift --auto"
|
|
74
103
|
echo " Or re-run /soleur:pencil-setup to refresh the installed adapter."
|
|
75
104
|
exit 3
|
|
@@ -438,7 +467,10 @@ attempt_headless_install() {
|
|
|
438
467
|
# Package name is @pencil.dev/cli (not @anthropic-ai/pencil-cli — that 404s).
|
|
439
468
|
# The detect_headless_cli function on line 182 already expects @pencil.dev/cli
|
|
440
469
|
# in the symlink target; the previous install command was inconsistent.
|
|
441
|
-
|
|
470
|
+
# Pinned to 0.2.9: the adapter's REPL surface table (pencil-repl-surface.mjs)
|
|
471
|
+
# is that version's signature list. Bumping this pin requires running
|
|
472
|
+
# engine-contract-probe.sh first (see #11143; migration tracked in #11156).
|
|
473
|
+
if "$npm_bin" install --prefix "$HOME/.local" @pencil.dev/cli@0.2.9 2>&1; then
|
|
442
474
|
detect_headless_cli && return 0
|
|
443
475
|
echo " [FAILED] Install succeeded but binary not found"
|
|
444
476
|
else
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#
|
|
10
10
|
# Exit codes:
|
|
11
11
|
# 0 copy succeeded (or repo already matches install)
|
|
12
|
-
# 1 repo adapter missing (should never happen inside the plugin)
|
|
12
|
+
# 1 repo adapter or one of its sibling modules missing (should never happen inside the plugin)
|
|
13
13
|
# 2 install directory not writable
|
|
14
14
|
|
|
15
15
|
set -euo pipefail
|
|
@@ -26,6 +26,7 @@ ADAPTER_FILES=(
|
|
|
26
26
|
"sanitize-filename.mjs"
|
|
27
27
|
"pencil-response-classify.mjs"
|
|
28
28
|
"pencil-save-gate.mjs"
|
|
29
|
+
"pencil-repl-surface.mjs"
|
|
29
30
|
"package.json"
|
|
30
31
|
"package-lock.json"
|
|
31
32
|
)
|
|
@@ -35,6 +36,15 @@ if [[ ! -f "$REPO_ADAPTER_DIR/pencil-mcp-adapter.mjs" ]]; then
|
|
|
35
36
|
exit 1
|
|
36
37
|
fi
|
|
37
38
|
|
|
39
|
+
# Validate EVERY source before copying ANY: a hard error mid-loop would leave a
|
|
40
|
+
# mixed-version install (new adapter, old guards) that fails far from the cause.
|
|
41
|
+
for file in "${ADAPTER_FILES[@]}"; do
|
|
42
|
+
if [[ ! -f "$REPO_ADAPTER_DIR/$file" ]]; then
|
|
43
|
+
echo "ERROR: missing repo file $REPO_ADAPTER_DIR/$file — refusing a partial install" >&2
|
|
44
|
+
exit 1
|
|
45
|
+
fi
|
|
46
|
+
done
|
|
47
|
+
|
|
38
48
|
mkdir -p "$INSTALL_DIR" || {
|
|
39
49
|
echo "ERROR: cannot create install dir $INSTALL_DIR" >&2
|
|
40
50
|
exit 2
|
|
@@ -44,10 +54,6 @@ copied=0
|
|
|
44
54
|
for file in "${ADAPTER_FILES[@]}"; do
|
|
45
55
|
src="$REPO_ADAPTER_DIR/$file"
|
|
46
56
|
dst="$INSTALL_DIR/$file"
|
|
47
|
-
if [[ ! -f "$src" ]]; then
|
|
48
|
-
echo "WARN: missing repo file $src — skipping" >&2
|
|
49
|
-
continue
|
|
50
|
-
fi
|
|
51
57
|
if [[ -f "$dst" ]] && ! [[ -L "$dst" ]] && cmp -s -- "$src" "$dst"; then
|
|
52
58
|
continue
|
|
53
59
|
fi
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# engine-contract-probe.sh — run the pencil-setup adapter against the REAL
|
|
3
|
+
# @pencil.dev/cli engine and check the contract the unit/stub tests only assume.
|
|
4
|
+
#
|
|
5
|
+
# This is the one test that touches the real engine. The stub integration test
|
|
6
|
+
# (test/pencil-adapter-stub-repl.test.ts) encodes our BELIEF about the REPL,
|
|
7
|
+
# which is how #11143 passed review; only this probe confirms it. Run it by
|
|
8
|
+
# hand whenever the @pencil.dev/cli pin in check_deps.sh is bumped (see #11156).
|
|
9
|
+
# It is deliberately not a *.test.sh: it needs PENCIL_CLI_KEY, so it must never
|
|
10
|
+
# be a required CI job or an auto-registered suite.
|
|
11
|
+
#
|
|
12
|
+
# Checks:
|
|
13
|
+
# 1. `pencil interactive --help` signatures == REPL_SURFACE (minus `save`)
|
|
14
|
+
# 2. open a new file, batch_design with the I(...) alias twice, save
|
|
15
|
+
# 3. a fresh adapter session reopens the file: top-level nodes loaded, file
|
|
16
|
+
# larger than the 96-byte empty document
|
|
17
|
+
# 4. batch_get() returns the JSON shape the save sentinel parses
|
|
18
|
+
#
|
|
19
|
+
# Exit codes: 0 all checks passed; 1 a contract check failed;
|
|
20
|
+
# 3 UNRESOLVED (PENCIL_CLI_KEY unset or tooling missing): nothing was asserted.
|
|
21
|
+
|
|
22
|
+
set -uo pipefail
|
|
23
|
+
|
|
24
|
+
case "$-" in
|
|
25
|
+
*x*)
|
|
26
|
+
if [ -n "${PENCIL_CLI_KEY:+x}" ]; then
|
|
27
|
+
printf '[FATAL] refusing to trace with a live credential set (see #7797)\n' >&2
|
|
28
|
+
exit 78
|
|
29
|
+
fi
|
|
30
|
+
;;
|
|
31
|
+
esac
|
|
32
|
+
|
|
33
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
34
|
+
|
|
35
|
+
if [[ -z "${PENCIL_CLI_KEY:-}" ]]; then
|
|
36
|
+
echo "UNRESOLVED: PENCIL_CLI_KEY is not set, so this probe asserted nothing." >&2
|
|
37
|
+
echo " Run: doppler run -p soleur -c dev -- bash $0" >&2
|
|
38
|
+
exit 3
|
|
39
|
+
fi
|
|
40
|
+
for tool in node npm; do
|
|
41
|
+
command -v "$tool" >/dev/null 2>&1 || { echo "UNRESOLVED: $tool not on PATH" >&2; exit 3; }
|
|
42
|
+
done
|
|
43
|
+
|
|
44
|
+
PENCIL_BIN="${PENCIL_BINARY:-$HOME/.local/node_modules/.bin/pencil}"
|
|
45
|
+
if [[ ! -e "$PENCIL_BIN" ]]; then
|
|
46
|
+
echo "UNRESOLVED: pencil binary not found at $PENCIL_BIN (set PENCIL_BINARY)" >&2
|
|
47
|
+
exit 3
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
work="$(mktemp -d -t pencil-contract-probe.XXXXXXXX)"
|
|
51
|
+
[[ "$work" == /* ]] || { echo "FATAL: work dir not absolute: $work" >&2; exit 2; }
|
|
52
|
+
trap 'rm -rf -- "$work"' EXIT
|
|
53
|
+
|
|
54
|
+
cat > "$work/probe.mjs" <<'NODE'
|
|
55
|
+
import { spawnSync } from "node:child_process";
|
|
56
|
+
import { readFileSync, statSync, writeFileSync } from "node:fs";
|
|
57
|
+
import { join } from "node:path";
|
|
58
|
+
import { pathToFileURL } from "node:url";
|
|
59
|
+
|
|
60
|
+
const [scriptsDir, testLib, workDir, pencilBin] = process.argv.slice(2);
|
|
61
|
+
const { REPL_SURFACE } = await import(pathToFileURL(join(scriptsDir, "pencil-repl-surface.mjs")).href);
|
|
62
|
+
const { installAdapter, connectAdapter } = await import(pathToFileURL(join(testLib, "pencil-adapter-roundtrip.mjs")).href);
|
|
63
|
+
const { memoryTopLevelCount } = await import(pathToFileURL(join(scriptsDir, "pencil-save-gate.mjs")).href);
|
|
64
|
+
|
|
65
|
+
let failures = 0;
|
|
66
|
+
const check = (ok, label, detail = "") => {
|
|
67
|
+
// never print the credential, even inside engine output echoed on a failure
|
|
68
|
+
const safe = String(detail).split(process.env.PENCIL_CLI_KEY).join("<redacted>").slice(0, 400);
|
|
69
|
+
console.log(`${ok ? "PASS" : "FAIL"} ${label}${ok || !safe ? "" : `: ${safe}`}`);
|
|
70
|
+
if (!ok) failures++;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// 1. signature diff against `pencil interactive --help`
|
|
74
|
+
const help = spawnSync(process.execPath, [pencilBin, "interactive", "--help"], {
|
|
75
|
+
encoding: "utf8",
|
|
76
|
+
env: { PATH: process.env.PATH, HOME: process.env.HOME },
|
|
77
|
+
});
|
|
78
|
+
const text = `${help.stdout}\n${help.stderr}`.replace(/\x1b\[[0-9;]*m/g, "");
|
|
79
|
+
const live = {};
|
|
80
|
+
for (const m of text.matchAll(/^# ([a-z_]+)\(\{?\s*([^})]*?)\s*\}?\)\s*$/gm)) {
|
|
81
|
+
live[m[1]] = m[2].split(",").map((k) => k.trim().replace(/\?$/, "")).filter(Boolean).sort();
|
|
82
|
+
}
|
|
83
|
+
const table = Object.fromEntries(
|
|
84
|
+
Object.entries(REPL_SURFACE).filter(([t]) => t !== "save").map(([t, k]) => [t, [...k].sort()])
|
|
85
|
+
);
|
|
86
|
+
check(Object.keys(live).length > 0, "parsed tool signatures from --help", text.slice(0, 200));
|
|
87
|
+
check(
|
|
88
|
+
JSON.stringify(Object.entries(live).sort()) === JSON.stringify(Object.entries(table).sort()),
|
|
89
|
+
"REPL_SURFACE matches the installed CLI",
|
|
90
|
+
`live=${JSON.stringify(live)} table=${JSON.stringify(table)}`
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// 2-4. round trip through the INSTALLED adapter copy against the real engine
|
|
94
|
+
const installDir = installAdapter(join(workDir, "install"));
|
|
95
|
+
const pen = join(workDir, "probe.pen");
|
|
96
|
+
let a = await connectAdapter({ installDir, binary: pencilBin, key: process.env.PENCIL_CLI_KEY });
|
|
97
|
+
try {
|
|
98
|
+
const o = await a.call("open_document", { filePath: pen });
|
|
99
|
+
check(!o.isError, "open_document on a new path", o.text);
|
|
100
|
+
const b1 = await a.call("batch_design", {
|
|
101
|
+
operations: 'f=I(document,{type:"frame",width:200,height:100,fill:"#FFFFFF"})\nt=I(f,{type:"text",content:"probe"})',
|
|
102
|
+
});
|
|
103
|
+
check(!b1.isError, "batch_design with I(...) aliases", b1.text);
|
|
104
|
+
const b2 = await a.call("batch_design", { operations: 'g=I(document,{type:"frame",width:50,height:50})' });
|
|
105
|
+
check(!b2.isError, "second consecutive batch_design", b2.text);
|
|
106
|
+
const g = await a.call("batch_get", {});
|
|
107
|
+
// the parser the save sentinel itself uses, not a re-implementation of it
|
|
108
|
+
const shape = memoryTopLevelCount(g.text);
|
|
109
|
+
check(shape !== null && shape >= 2, "batch_get() returns a parseable top-level node list", g.text.slice(0, 200));
|
|
110
|
+
const sv = await a.call("save");
|
|
111
|
+
check(!sv.isError, "explicit save", sv.text);
|
|
112
|
+
} finally {
|
|
113
|
+
await a.close();
|
|
114
|
+
}
|
|
115
|
+
let size = 0;
|
|
116
|
+
try { size = statSync(pen).size; } catch {}
|
|
117
|
+
check(size > 96, "saved file is larger than the 96-byte empty document", `size=${size}`);
|
|
118
|
+
|
|
119
|
+
a = await connectAdapter({ installDir, binary: pencilBin, key: process.env.PENCIL_CLI_KEY });
|
|
120
|
+
try {
|
|
121
|
+
const o = await a.call("open_document", { filePath: pen });
|
|
122
|
+
check(!o.isError, "reopen in a fresh session", o.text);
|
|
123
|
+
const n = /\((\d+) top-level node/.exec(o.text);
|
|
124
|
+
check(n && Number(n[1]) >= 2, "reopen loaded the saved top-level nodes", o.text);
|
|
125
|
+
// the sentinel must refuse an empty document over this non-empty file only
|
|
126
|
+
const g = await a.call("batch_get", {});
|
|
127
|
+
check(!g.isError && g.text.length > 20, "batch_get after reopen has content", g.text.slice(0, 200));
|
|
128
|
+
} finally {
|
|
129
|
+
await a.close();
|
|
130
|
+
}
|
|
131
|
+
const doc = JSON.parse(readFileSync(pen, "utf8"));
|
|
132
|
+
check(Array.isArray(doc.children) && doc.children.length >= 2, "on-disk document keeps its children", JSON.stringify(doc).slice(0, 200));
|
|
133
|
+
|
|
134
|
+
// 5. A design whose batch_get() reply exceeds 64 KiB must still save and reopen:
|
|
135
|
+
// the sentinel parses the UNtruncated reply (a capped reply is not valid JSON).
|
|
136
|
+
const big = join(workDir, "big.pen");
|
|
137
|
+
a = await connectAdapter({ installDir, binary: pencilBin, key: process.env.PENCIL_CLI_KEY });
|
|
138
|
+
try {
|
|
139
|
+
const o = await a.call("open_document", { filePath: big });
|
|
140
|
+
check(!o.isError, "open_document on a new path (large design)", o.text);
|
|
141
|
+
const pad = "x".repeat(500);
|
|
142
|
+
const ops = Array.from({ length: 140 }, (_, i) => `n${i}=I(document,{type:"frame",name:"${pad}${i}",width:10,height:10})`).join("\n");
|
|
143
|
+
const r = await a.call("batch_design", { operations: ops });
|
|
144
|
+
check(!r.isError, "batch_design inserting 140 frames with long names", r.text);
|
|
145
|
+
const g = await a.call("batch_design", { operations: 'extra=I(document,{type:"frame",width:5,height:5})' });
|
|
146
|
+
check(!g.isError, "a second edit over a non-empty file is allowed by the sentinel", g.text);
|
|
147
|
+
} finally {
|
|
148
|
+
await a.close();
|
|
149
|
+
}
|
|
150
|
+
let bigSize = 0;
|
|
151
|
+
try { bigSize = statSync(big).size; } catch {}
|
|
152
|
+
check(bigSize > 60000, "the large design reached disk", `size=${bigSize}`);
|
|
153
|
+
a = await connectAdapter({ installDir, binary: pencilBin, key: process.env.PENCIL_CLI_KEY });
|
|
154
|
+
try {
|
|
155
|
+
const o = await a.call("open_document", { filePath: big });
|
|
156
|
+
const n = /\((\d+) top-level node/.exec(o.text);
|
|
157
|
+
check(!o.isError && n && Number(n[1]) >= 140, "the large design reopens with its nodes", o.text);
|
|
158
|
+
} finally {
|
|
159
|
+
await a.close();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 6. The sentinel against the REAL engine: content appears behind the session's
|
|
163
|
+
// back while the session's document is empty. A save must be refused.
|
|
164
|
+
const guarded = join(workDir, "guarded.pen");
|
|
165
|
+
a = await connectAdapter({ installDir, binary: pencilBin, key: process.env.PENCIL_CLI_KEY });
|
|
166
|
+
try {
|
|
167
|
+
const o = await a.call("open_document", { filePath: guarded });
|
|
168
|
+
check(!o.isError, "open_document on a new path (sentinel check)", o.text);
|
|
169
|
+
writeFileSync(guarded, readFileSync(pen));
|
|
170
|
+
const before = readFileSync(guarded, "utf8");
|
|
171
|
+
const sv = await a.call("save");
|
|
172
|
+
check(sv.isError && /REFUSED save:/.test(sv.text), "an empty document is refused over a non-empty file", sv.text);
|
|
173
|
+
check(readFileSync(guarded, "utf8") === before, "the refused save left the file byte-identical");
|
|
174
|
+
writeFileSync(guarded, "# not a pen document\n");
|
|
175
|
+
const garbage = await a.call("batch_design", { operations: 'z=I(document,{type:"frame",width:5,height:5})' });
|
|
176
|
+
check(garbage.isError && /not a recognizable/.test(garbage.text), "an unrecognizable file is never overwritten", garbage.text);
|
|
177
|
+
} finally {
|
|
178
|
+
await a.close();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
console.log(failures === 0 ? "PROBE OK" : `PROBE FAILED (${failures})`);
|
|
182
|
+
process.exit(failures === 0 ? 0 : 1);
|
|
183
|
+
NODE
|
|
184
|
+
|
|
185
|
+
node "$work/probe.mjs" "$SCRIPT_DIR" "$SCRIPT_DIR/../../../test/lib" "$work" "$PENCIL_BIN"
|
|
186
|
+
rc=$?
|
|
187
|
+
exit "$rc"
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
// Pure function: enriches known Pencil API error messages with actionable hints.
|
|
2
2
|
// Extracted for testability — no external dependencies.
|
|
3
3
|
|
|
4
|
+
// Tools @pencil.dev/cli 0.2.9 removed (#11143). Retire with #11156.
|
|
5
|
+
const REMOVED_TOOL_HINTS = {
|
|
6
|
+
set_variables:
|
|
7
|
+
"set_variables is not available in the headless CLI. Set variables with SetVariables(...) inside batch_design (syntax: get_editor_state({ include_schema: true })).",
|
|
8
|
+
find_empty_space_on_canvas:
|
|
9
|
+
"find_empty_space_on_canvas is not available in the headless CLI. Use FindEmptySpace(...) inside batch_design (syntax: get_editor_state({ include_schema: true })).",
|
|
10
|
+
get_style_guide:
|
|
11
|
+
"get_style_guide is not available in the headless CLI. Call get_guidelines() with no arguments to list the available guides, or continue with brand tokens.",
|
|
12
|
+
get_style_guide_tags:
|
|
13
|
+
"get_style_guide_tags is not available in the headless CLI. Call get_guidelines() with no arguments to list the available guides, or continue with brand tokens.",
|
|
14
|
+
search_all_unique_properties:
|
|
15
|
+
"search_all_unique_properties has no headless equivalent in this CLI version. Read nodes with batch_get and inspect them.",
|
|
16
|
+
replace_all_matching_properties:
|
|
17
|
+
"replace_all_matching_properties has no headless equivalent in this CLI version. Apply the change with Update(...) calls inside batch_design.",
|
|
18
|
+
};
|
|
19
|
+
|
|
4
20
|
export function enrichErrorMessage(text) {
|
|
5
21
|
if (text.includes("alignSelf") && text.includes("unexpected property")) {
|
|
6
22
|
return text + "\n\n[adapter hint] alignSelf is not supported on frames. " +
|
|
@@ -17,5 +33,9 @@ export function enrichErrorMessage(text) {
|
|
|
17
33
|
"M(nodeId, parent, index) to reorder after insertion. Discover the target " +
|
|
18
34
|
"index with batch_get on the parent. See #1117.";
|
|
19
35
|
}
|
|
36
|
+
const removed = text.match(/^Unknown tool: ([a-z_]+)/m);
|
|
37
|
+
if (removed && Object.hasOwn(REMOVED_TOOL_HINTS, removed[1])) {
|
|
38
|
+
return text + "\n\n[adapter hint] " + REMOVED_TOOL_HINTS[removed[1]];
|
|
39
|
+
}
|
|
20
40
|
return text;
|
|
21
41
|
}
|