codeassembly-agent-logic 0.6.0 → 0.8.0

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.
@@ -1,4 +1,65 @@
1
1
  [
2
+ {
3
+ "version": "0.8.0",
4
+ "date": "2026-11-21",
5
+ "sections": [
6
+ {
7
+ "title": "🎉 Features",
8
+ "audience": "all",
9
+ "items": [
10
+ {
11
+ "description": "Changes the mouse wheel on the statechart canvas from zooming to panning, with Cmd+wheel on macOS, Ctrl+wheel elsewhere, and a trackpad pinch still zooming. (#2303)",
12
+ "hash": "0d95c949fa9683f2ce95d83a2141f3e9619f02b1",
13
+ "entry": 1
14
+ },
15
+ {
16
+ "description": "Names the zoom shortcut in the labels and tooltips of the canvas's Zoom In and Zoom Out buttons: `Cmd+scroll` on macOS and `Ctrl+scroll` elsewhere. (#2303)",
17
+ "hash": "0d95c949fa9683f2ce95d83a2141f3e9619f02b1",
18
+ "entry": 2
19
+ }
20
+ ]
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ "version": "0.7.0",
26
+ "date": "2026-11-21",
27
+ "sections": [
28
+ {
29
+ "title": "🎉 Features",
30
+ "audience": "all",
31
+ "items": [
32
+ {
33
+ "description": "Sets each Markdown heading in `PromptPane` by its level, with its `#` marker muted even when the heading is selected, and adds a `heading` field to `PromptSegment` that records the level and whether the segment is the marker. (#2299)",
34
+ "hash": "86c0f6f48777f7941824ab216f12c85692db470c",
35
+ "entry": 2
36
+ }
37
+ ]
38
+ },
39
+ {
40
+ "title": "🐛 Bug fixes",
41
+ "audience": "all",
42
+ "items": [
43
+ {
44
+ "description": "Fixes the issue that `PromptPane` marked Markdown heading lines, list markers, and front matter as \"Not used\", by adding the `structure` value to the exported `Coverage` union, which `buildPromptSegments` assigns to that syntax and the pane leaves unmarked. (#2299)",
45
+ "hash": "86c0f6f48777f7941824ab216f12c85692db470c",
46
+ "entry": 1
47
+ }
48
+ ]
49
+ },
50
+ {
51
+ "title": "📦 Dependencies",
52
+ "audience": "dev",
53
+ "items": [
54
+ {
55
+ "description": "Upgrades `@testing-library/jest-dom` from 7.0.1 to 8.0.0, whose only breaking change drops support for Vitest versions below 5, which the repository's Vitest 5.1.1 meets. (#2301)",
56
+ "hash": "d2c434179d5faa5b3ec36ba91ef815c299c59b02",
57
+ "entry": 1
58
+ }
59
+ ]
60
+ }
61
+ ]
62
+ },
2
63
  {
3
64
  "version": "0.6.0",
4
65
  "date": "2026-11-19",
package/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 0.8.0 — 2026-11-21
6
+
7
+ ### 🎉 Features
8
+
9
+ - Changes the mouse wheel on the statechart canvas from zooming to panning, with Cmd+wheel on macOS, Ctrl+wheel elsewhere, and a trackpad pinch still zooming. (#2303)
10
+ - Names the zoom shortcut in the labels and tooltips of the canvas's Zoom In and Zoom Out buttons: `Cmd+scroll` on macOS and `Ctrl+scroll` elsewhere. (#2303)
11
+
12
+ ## 0.7.0 — 2026-11-21
13
+
14
+ ### 🎉 Features
15
+
16
+ - Sets each Markdown heading in `PromptPane` by its level, with its `#` marker muted even when the heading is selected, and adds a `heading` field to `PromptSegment` that records the level and whether the segment is the marker. (#2299)
17
+
18
+ ### 🐛 Bug fixes
19
+
20
+ - Fixes the issue that `PromptPane` marked Markdown heading lines, list markers, and front matter as "Not used", by adding the `structure` value to the exported `Coverage` union, which `buildPromptSegments` assigns to that syntax and the pane leaves unmarked. (#2299)
21
+
22
+ ### 📦 Dependencies
23
+
24
+ - Upgrades `@testing-library/jest-dom` from 7.0.1 to 8.0.0, whose only breaking change drops support for Vitest versions below 5, which the repository's Vitest 5.1.1 meets. (#2301)
25
+
5
26
  ## 0.6.0 — 2026-11-19
6
27
 
7
28
  ### 🎉 Features
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  <!-- section:release-notes -->
2
- ## Release notes — v0.6.0 (2026-11-19)
2
+ ## Release notes — v0.8.0 (2026-11-21)
3
3
 
4
4
  ### 🎉 Features
5
5
 
6
- - Adds `PromptPane` and `PromptKey` to `codeassembly-agent-logic/react`, which show the whole prompt with a key and mark ambient, unused, unconverted, and comment text, leaving the text that the chart uses unmarked. (#2297)
7
- - Adds the custom properties `--agent-logic-passage-background`, `--agent-logic-text-subtlest`, and `--agent-logic-unconverted` to `codeassembly-agent-logic/react/styles.css` for theming the pane, and adds `--agent-logic-font-prose`, which replaces the serif face that was hard-coded for a flow's preamble. (#2297)
6
+ - Changes the mouse wheel on the statechart canvas from zooming to panning, with Cmd+wheel on macOS, Ctrl+wheel elsewhere, and a trackpad pinch still zooming. (#2303)
7
+ - Names the zoom shortcut in the labels and tooltips of the canvas's Zoom In and Zoom Out buttons: `Cmd+scroll` on macOS and `Ctrl+scroll` elsewhere. (#2303)
8
8
  <!-- /section:release-notes -->
9
9
 
10
10
  <!-- readme-type: library -->
@@ -117,7 +117,7 @@ if (started.ok) {
117
117
 
118
118
  The package draws the chart and the prompt; the page around them is the app's. The app renders the load controls, the inspector, and the terminal in its own design system, and it renders the canvas's key: `StatechartCanvas` passes the marks that the chart draws to its `renderKey` prop, and `CANVAS_KEY_ENTRIES` gives each mark's name, gloss, and drawing.
119
119
 
120
- `PromptPane` shows the whole prompt with its key, marking the text that the chart does not use and leaving used text unmarked. The app supplies its segments, from `buildPromptSegments`, the selected element, the passages to show, and the handler that receives a clicked passage's path. A line that the app draws from the canvas to the selected passage finds the pane's text by `data-prompt-text` and the passage by `data-passage-for`, whose value is the element's path; `PromptPane`'s doc comment lists its other attributes. `PromptKey` renders the key alone, for an app that places it outside the pane. The app also supplies the URL of the conversions resource to `./client`'s `createConversionClient`.
120
+ `PromptPane` shows the whole prompt with its key, marking the text that the chart does not use and leaving used text unmarked. It sets each Markdown heading by its level, with its `#` muted, and leaves Markdown structure, such as heading lines and list markers, unmarked. The app supplies its segments, from `buildPromptSegments`, the selected element, the passages to show, and the handler that receives a clicked passage's path. A line that the app draws from the canvas to the selected passage finds the pane's text by `data-prompt-text` and the passage by `data-passage-for`, whose value is the element's path; `PromptPane`'s doc comment lists its other attributes. `PromptKey` renders the key alone, for an app that places it outside the pane. The app also supplies the URL of the conversions resource to `./client`'s `createConversionClient`.
121
121
 
122
122
  ## Styling and theming
123
123
 
@@ -1,12 +1,4 @@
1
- import { isFenceCloser, matchFenceOpener } from "../source/fence.js";
2
- import { findCommentSpans } from "../source/find-comment-spans.js";
3
- const BLOCKQUOTE = /^\s*>/;
4
- const HEADING = /^ {0,3}#{1,6}(?:\s|$)/;
5
- const LIST_ITEM = /^\s*(?:[-*+]|\d+[.)])\s+/;
6
- const LONE_TAG = /^\s*<\/?[A-Za-z][\w-]*>\s*$/;
7
- const TABLE_ROW = /^\s*\|/;
8
- const TABLE_SEPARATOR = /^\s*\|?(?:\s*:?-+:?\s*\|)+\s*:?-*:?\s*$/;
9
- const THEMATIC_BREAK = /^ {0,3}(?:-{3,}|\*{3,}|_{3,})\s*$/;
1
+ import { blankComments, classifyLine, findFenceClose, indentOf, skipFrontMatter, splitLines, } from "../source/prompt-lines.js";
10
2
  export function findPromptBlocks(prompt) {
11
3
  const blocks = [];
12
4
  const source = blankComments(prompt);
@@ -78,63 +70,6 @@ export function findPromptBlocks(prompt) {
78
70
  flush();
79
71
  return blocks;
80
72
  }
81
- function blankComments(prompt) {
82
- let result = '';
83
- let from = 0;
84
- for (const { start, end } of findCommentSpans(prompt)) {
85
- result += prompt.slice(from, start) + prompt.slice(start, end).replaceAll(/[^\n]/g, ' ');
86
- from = end;
87
- }
88
- return result + prompt.slice(from);
89
- }
90
- function classifyLine(lines, index) {
91
- const text = lines[index]?.text ?? '';
92
- if (matchFenceOpener(text) !== undefined)
93
- return 'fence';
94
- if (text.trim() === '')
95
- return 'blank';
96
- if (HEADING.test(text) || THEMATIC_BREAK.test(text) || LONE_TAG.test(text))
97
- return 'skip';
98
- if (TABLE_ROW.test(text)) {
99
- const next = lines[index + 1];
100
- const isHeader = next !== undefined && TABLE_SEPARATOR.test(next.text);
101
- return TABLE_SEPARATOR.test(text) || isHeader ? 'skip' : 'row';
102
- }
103
- if (LIST_ITEM.test(text))
104
- return 'item';
105
- if (BLOCKQUOTE.test(text))
106
- return 'quote';
107
- return 'text';
108
- }
109
- function findFenceClose(lines, opening) {
110
- const fence = matchFenceOpener(lines[opening]?.text ?? '');
111
- if (fence === undefined)
112
- return opening;
113
- for (let index = opening + 1; index < lines.length; index++) {
114
- if (isFenceCloser(lines[index]?.text ?? '', fence))
115
- return index;
116
- }
117
- return lines.length - 1;
118
- }
119
- function indentOf(text) {
120
- return text.length - text.trimStart().length;
121
- }
122
73
  function isLeadIn(text) {
123
74
  return !text.includes('\n') && text.trimEnd().endsWith(':');
124
75
  }
125
- function skipFrontMatter(lines) {
126
- if (lines[0]?.text !== '---')
127
- return 0;
128
- const close = lines.findIndex((line, index) => index > 0 && line.text === '---');
129
- return close === -1 ? 0 : close + 1;
130
- }
131
- function splitLines(text) {
132
- const lines = [];
133
- let start = 0;
134
- for (const [index, rawLine] of text.split('\n').entries()) {
135
- const lineText = rawLine.endsWith('\r') ? rawLine.slice(0, -1) : rawLine;
136
- lines.push({ start, end: start + lineText.length, number: index + 1, text: lineText });
137
- start += rawLine.length + 1;
138
- }
139
- return lines;
140
- }
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Background, Controls, EdgeChangeset, getNodesBounds, NodeChangeset, ReactFlow, ReactFlowProvider, useReactFlow, useReactFlowStoreApi, useViewportStore, } from '@xyflow/react';
3
3
  import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
4
4
  import { AmbientSelectionContext } from "./AmbientSelectionContext.js";
5
+ import { buildAriaLabelConfig } from "./build-aria-label-config.js";
5
6
  import { DetailLevelContext } from "./DetailLevelContext.js";
6
7
  import { findElementBox } from "./find-element-box.js";
7
8
  import { findViewCentre, readView } from "./find-view-centre.js";
@@ -20,12 +21,6 @@ const fitViewOptions = {
20
21
  maxZoom: READING_ZOOM,
21
22
  };
22
23
  const MAX_ZOOM = 2;
23
- const STATE_DESCRIPTION = "Press Enter or Space to select. Press Right arrow to move to the state's outgoing transitions, when it has any.";
24
- const ariaLabelConfig = {
25
- 'node.a11yDescription.default': STATE_DESCRIPTION,
26
- 'node.a11yDescription.keyboardDisabled': STATE_DESCRIPTION,
27
- 'edge.a11yDescription.default': 'Press Enter or Space to select. Press Up or Down arrow to move between transitions from the same state, or Left arrow to return to that state.',
28
- };
29
24
  const DRAG_THRESHOLD = 3;
30
25
  export function StatechartCanvas({ elements, renderKey, ...props }) {
31
26
  const marks = useMemo(() => listChartMarks(elements), [elements]);
@@ -97,6 +92,7 @@ function StatechartFlow({ elements, selectedPath, onSelect, onViewportChange })
97
92
  const height = useViewportStore((state) => state.height);
98
93
  const bounds = useMemo(() => getNodesBounds(elements.nodes.filter(({ parentId }) => parentId === undefined)), [elements.nodes]);
99
94
  const fitZoom = findFitZoom(bounds, width, height);
95
+ const ariaLabelConfig = useMemo(() => buildAriaLabelConfig(), []);
100
96
  const detailLevel = useViewportStore((state) => findDetailLevel(state.transform[2]));
101
97
  const isFitted = useRef(true);
102
98
  const markMoved = useCallback(() => {
@@ -160,7 +156,7 @@ function StatechartFlow({ elements, selectedPath, onSelect, onViewportChange })
160
156
  return (_jsx(DetailLevelContext.Provider, { value: detailLevel, children: _jsx(AmbientSelectionContext.Provider, { value: ambientSelection, children: _jsxs(ReactFlow, { className: `statechart-canvas__flow--${detailLevel}`, nodes: shownNodes, edges: shownEdges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesChange: handleNodesChange, onEdgesChange: handleEdgesChange, onNodeClick: handleNodeClick, onMoveStart: (event) => {
161
157
  if (event !== null)
162
158
  markMoved();
163
- }, ...(onViewportChange === undefined ? {} : { onMove: onViewportChange }), nodesDraggable: false, nodesConnectable: false, multiSelectionKeyCode: null, fitView: true, fitViewOptions: fitViewOptions, autoPanOnNodeFocus: false, ariaLabelConfig: ariaLabelConfig, minZoom: fitZoom, maxZoom: MAX_ZOOM, children: [_jsx(Background, {}), _jsx(ArrowheadDefs, {}), _jsx(Controls, { showInteractive: false, fitViewOptions: fitViewOptions, onFitView: () => {
159
+ }, ...(onViewportChange === undefined ? {} : { onMove: onViewportChange }), nodesDraggable: false, nodesConnectable: false, multiSelectionKeyCode: null, panOnScroll: true, fitView: true, fitViewOptions: fitViewOptions, autoPanOnNodeFocus: false, ariaLabelConfig: ariaLabelConfig, minZoom: fitZoom, maxZoom: MAX_ZOOM, children: [_jsx(Background, {}), _jsx(ArrowheadDefs, {}), _jsx(Controls, { showInteractive: false, fitViewOptions: fitViewOptions, onFitView: () => {
164
160
  isFitted.current = true;
165
161
  }, onZoomIn: markMoved, onZoomOut: markMoved }), _jsx(SelectionSync, { selectedPath: selectedPath, reportRef: reportRef, onCentre: markMoved }), _jsx(EdgeDragPan, { onPan: markMoved }), _jsx(FocusNavigation, { onCentre: markMoved }), _jsx(ZoomProperty, {})] }) }) }));
166
162
  }
@@ -0,0 +1,6 @@
1
+ import type { AriaLabelConfig } from '@xyflow/react';
2
+ /**
3
+ * Returns the canvas's labels, naming the zoom shortcut on the zoom buttons. The key is the one that React Flow's
4
+ * default `zoomActivationKeyCode` picks, by the same user-agent test.
5
+ */
6
+ export declare function buildAriaLabelConfig(): Partial<AriaLabelConfig>;
@@ -0,0 +1,14 @@
1
+ const STATE_DESCRIPTION = "Press Enter or Space to select. Press Right arrow to move to the state's outgoing transitions, when it has any.";
2
+ const baseAriaLabelConfig = {
3
+ 'node.a11yDescription.default': STATE_DESCRIPTION,
4
+ 'node.a11yDescription.keyboardDisabled': STATE_DESCRIPTION,
5
+ 'edge.a11yDescription.default': 'Press Enter or Space to select. Press Up or Down arrow to move between transitions from the same state, or Left arrow to return to that state.',
6
+ };
7
+ export function buildAriaLabelConfig() {
8
+ const zoomKey = typeof navigator !== 'undefined' && navigator.userAgent.includes('Mac') ? 'Cmd' : 'Ctrl';
9
+ return {
10
+ ...baseAriaLabelConfig,
11
+ 'controls.zoomIn.ariaLabel': `Zoom In (${zoomKey}+scroll)`,
12
+ 'controls.zoomOut.ariaLabel': `Zoom Out (${zoomKey}+scroll)`,
13
+ };
14
+ }
@@ -11,9 +11,10 @@ export interface PromptPaneProps {
11
11
  onSelect: (path: string) => void;
12
12
  }
13
13
  /**
14
- * The whole prompt with its key, marking the text that the chart does not use, with the selected element's or the
15
- * shown passages highlighted. Its text region has `data-prompt-text`, and each passage `data-coverage`; a selected
16
- * passage has `data-selected`, the first of them `data-passage-for` with the element's path, a shown passage
17
- * `data-shown`, the earliest of them `data-shown-passage`, and a passage that selects an element `data-select-path`.
14
+ * The whole prompt with its key, marking the text that the chart does not use and setting each heading by its level,
15
+ * with the selected element's or the shown passages highlighted. Its text region has `data-prompt-text`, and each
16
+ * passage `data-coverage`; a selected passage has `data-selected`, the first of them `data-passage-for` with the
17
+ * element's path, a shown passage `data-shown`, the earliest of them `data-shown-passage`, and a passage that selects
18
+ * an element `data-select-path`.
18
19
  */
19
20
  export declare function PromptPane({ segments, selected, shownPassages, onSelect }: PromptPaneProps): ReactElement;
@@ -46,8 +46,16 @@ function boldSharedWords(text, words) {
46
46
  .split(/([A-Za-z0-9]+)/)
47
47
  .map((part, index) => (words.has(part.toLowerCase()) ? _jsx("b", { children: part }, index) : part));
48
48
  }
49
- function classifyPassage({ coverage, text }, isHighlighted) {
50
- const isMarked = coverage !== 'unused' || WORD.test(text);
51
- const classes = isMarked ? `prompt-pane__passage prompt-pane__passage--${coverage}` : 'prompt-pane__passage';
52
- return isHighlighted ? `${classes} prompt-pane__passage--highlighted` : classes;
49
+ function classifyPassage({ coverage, heading, text }, isHighlighted) {
50
+ const isMarked = coverage !== 'structure' && (coverage !== 'unused' || WORD.test(text));
51
+ const classes = ['prompt-pane__passage'];
52
+ if (isMarked)
53
+ classes.push(`prompt-pane__passage--${coverage}`);
54
+ if (heading !== undefined)
55
+ classes.push(`prompt-pane__passage--h${heading.level}`);
56
+ if (heading?.isMarker === true)
57
+ classes.push('prompt-pane__passage--heading-marker');
58
+ if (isHighlighted)
59
+ classes.push('prompt-pane__passage--highlighted');
60
+ return classes.join(' ');
53
61
  }
@@ -644,6 +644,45 @@
644
644
  color: var(--_agent-logic-text-subtle);
645
645
  }
646
646
 
647
+ /*
648
+ * A heading's larger text, set on the body text's baseline, would make its line taller; aligning it to the top keeps
649
+ * the line at the pane's line height, so that no line of the prompt moves.
650
+ */
651
+ .prompt-pane__passage--h1,
652
+ .prompt-pane__passage--h2,
653
+ .prompt-pane__passage--h3,
654
+ .prompt-pane__passage--h4,
655
+ .prompt-pane__passage--h5,
656
+ .prompt-pane__passage--h6 {
657
+ vertical-align: top;
658
+ }
659
+
660
+ .prompt-pane__passage--h1 {
661
+ font-size: 22px;
662
+ font-weight: 700;
663
+ }
664
+
665
+ .prompt-pane__passage--h2 {
666
+ font-size: 19px;
667
+ font-weight: 700;
668
+ }
669
+
670
+ .prompt-pane__passage--h3 {
671
+ font-size: 17px;
672
+ font-weight: 600;
673
+ }
674
+
675
+ .prompt-pane__passage--h4,
676
+ .prompt-pane__passage--h5,
677
+ .prompt-pane__passage--h6 {
678
+ font-weight: 600;
679
+ }
680
+
681
+ /* The marker is syntax, so it stays muted when its heading is selected or shown. */
682
+ .prompt-pane__passage.prompt-pane__passage--heading-marker {
683
+ color: var(--_agent-logic-text-subtle);
684
+ }
685
+
647
686
  .prompt-key {
648
687
  display: flex;
649
688
  flex-wrap: wrap;
@@ -0,0 +1,18 @@
1
+ import type { Span } from '../schema/agent-logic-schema.js';
2
+ /** A span of Markdown syntax that structures the prompt rather than instructs. */
3
+ export type StructureSpan = (Span & {
4
+ kind: 'heading';
5
+ level: number;
6
+ markerEnd: number;
7
+ }) | (Span & {
8
+ kind: 'line';
9
+ }) | (Span & {
10
+ kind: 'list-marker';
11
+ });
12
+ /**
13
+ * Finds, in order, the lines that `findPromptBlocks` does not take into any block, a leading YAML front matter as one
14
+ * span, and the marker of each list item. Each span starts with its line's indent, so that the indent is not left
15
+ * marked as unused text. A heading's `markerEnd` is the offset just past its run of `#`. Text inside a fenced block or
16
+ * an HTML comment is never structure.
17
+ */
18
+ export declare function findStructureSpans(prompt: string): StructureSpan[];
@@ -0,0 +1,35 @@
1
+ import { blankComments, classifyLine, findFenceClose, HEADING, indentOf, LIST_MARKER, skipFrontMatter, splitLines, } from "./prompt-lines.js";
2
+ export function findStructureSpans(prompt) {
3
+ const spans = [];
4
+ const lines = splitLines(blankComments(prompt));
5
+ const first = skipFrontMatter(lines);
6
+ const frontMatterEnd = lines[first - 1]?.end;
7
+ if (frontMatterEnd !== undefined)
8
+ spans.push({ kind: 'line', start: 0, end: frontMatterEnd });
9
+ for (let index = first; index < lines.length; index++) {
10
+ const line = lines[index];
11
+ if (line === undefined)
12
+ break;
13
+ const { start } = line;
14
+ const markerStart = start + indentOf(line.text);
15
+ switch (classifyLine(lines, index)) {
16
+ case 'fence':
17
+ index = findFenceClose(lines, index);
18
+ break;
19
+ case 'item': {
20
+ const markerLength = LIST_MARKER.exec(line.text.trimStart())?.[0].length ?? 0;
21
+ spans.push({ kind: 'list-marker', start, end: markerStart + markerLength });
22
+ break;
23
+ }
24
+ case 'skip': {
25
+ const markerLength = HEADING.exec(line.text)?.[1]?.length;
26
+ spans.push(markerLength === undefined
27
+ ? { kind: 'line', start, end: line.end }
28
+ : { kind: 'heading', start, end: line.end, level: markerLength, markerEnd: markerStart + markerLength });
29
+ break;
30
+ }
31
+ default:
32
+ }
33
+ }
34
+ return spans;
35
+ }
@@ -0,0 +1,26 @@
1
+ /** A line of a prompt with its offsets, excluding its newline. */
2
+ export interface Line {
3
+ start: number;
4
+ end: number;
5
+ /** The 1-based line number. */
6
+ number: number;
7
+ text: string;
8
+ }
9
+ export type LineKind = 'blank' | 'fence' | 'item' | 'quote' | 'row' | 'skip' | 'text';
10
+ export declare const HEADING: RegExp;
11
+ export declare const LIST_MARKER: RegExp;
12
+ /** Replaces each HTML comment with spaces, keeping its newlines, so that offsets and line numbers stay the same. */
13
+ export declare function blankComments(prompt: string): string;
14
+ /**
15
+ * Returns what the line at the index is, as far as cutting the prompt into blocks goes. Headings, thematic breaks,
16
+ * table header and separator rows, and lines that hold only an HTML tag are `skip`, because they hold no instruction.
17
+ */
18
+ export declare function classifyLine(lines: Line[], index: number): LineKind;
19
+ /** Returns the index of the line that closes the fence opened at the index, or the last line's when nothing does. */
20
+ export declare function findFenceClose(lines: Line[], opening: number): number;
21
+ /** Returns the number of leading whitespace characters of the line. */
22
+ export declare function indentOf(text: string): number;
23
+ /** Returns the index of the first line after a YAML front matter that opens the prompt, or 0 when it has none. */
24
+ export declare function skipFrontMatter(lines: Line[]): number;
25
+ /** Splits the text into lines with their offsets, excluding each line's newline. */
26
+ export declare function splitLines(text: string): Line[];
@@ -0,0 +1,67 @@
1
+ import { isFenceCloser, matchFenceOpener } from "./fence.js";
2
+ import { findCommentSpans } from "./find-comment-spans.js";
3
+ const BLOCKQUOTE = /^\s*>/;
4
+ export const HEADING = /^ {0,3}(#{1,6})(?:\s|$)/;
5
+ const LIST_ITEM = /^\s*(?:[-*+]|\d+[.)])\s+/;
6
+ export const LIST_MARKER = /^(?:[-*+]|\d+[.)])/;
7
+ const LONE_TAG = /^\s*<\/?[A-Za-z][\w-]*>\s*$/;
8
+ const TABLE_ROW = /^\s*\|/;
9
+ const TABLE_SEPARATOR = /^\s*\|?(?:\s*:?-+:?\s*\|)+\s*:?-*:?\s*$/;
10
+ const THEMATIC_BREAK = /^ {0,3}(?:-{3,}|\*{3,}|_{3,})\s*$/;
11
+ export function blankComments(prompt) {
12
+ let result = '';
13
+ let from = 0;
14
+ for (const { start, end } of findCommentSpans(prompt)) {
15
+ result += prompt.slice(from, start) + prompt.slice(start, end).replaceAll(/[^\n]/g, ' ');
16
+ from = end;
17
+ }
18
+ return result + prompt.slice(from);
19
+ }
20
+ export function classifyLine(lines, index) {
21
+ const text = lines[index]?.text ?? '';
22
+ if (matchFenceOpener(text) !== undefined)
23
+ return 'fence';
24
+ if (text.trim() === '')
25
+ return 'blank';
26
+ if (HEADING.test(text) || THEMATIC_BREAK.test(text) || LONE_TAG.test(text))
27
+ return 'skip';
28
+ if (TABLE_ROW.test(text)) {
29
+ const next = lines[index + 1];
30
+ const isHeader = next !== undefined && TABLE_SEPARATOR.test(next.text);
31
+ return TABLE_SEPARATOR.test(text) || isHeader ? 'skip' : 'row';
32
+ }
33
+ if (LIST_ITEM.test(text))
34
+ return 'item';
35
+ if (BLOCKQUOTE.test(text))
36
+ return 'quote';
37
+ return 'text';
38
+ }
39
+ export function findFenceClose(lines, opening) {
40
+ const fence = matchFenceOpener(lines[opening]?.text ?? '');
41
+ if (fence === undefined)
42
+ return opening;
43
+ for (let index = opening + 1; index < lines.length; index++) {
44
+ if (isFenceCloser(lines[index]?.text ?? '', fence))
45
+ return index;
46
+ }
47
+ return lines.length - 1;
48
+ }
49
+ export function indentOf(text) {
50
+ return text.length - text.trimStart().length;
51
+ }
52
+ export function skipFrontMatter(lines) {
53
+ if (lines[0]?.text !== '---')
54
+ return 0;
55
+ const close = lines.findIndex((line, index) => index > 0 && line.text === '---');
56
+ return close === -1 ? 0 : close + 1;
57
+ }
58
+ export function splitLines(text) {
59
+ const lines = [];
60
+ let start = 0;
61
+ for (const [index, rawLine] of text.split('\n').entries()) {
62
+ const lineText = rawLine.endsWith('\r') ? rawLine.slice(0, -1) : rawLine;
63
+ lines.push({ start, end: start + lineText.length, number: index + 1, text: lineText });
64
+ start += rawLine.length + 1;
65
+ }
66
+ return lines;
67
+ }
@@ -1,6 +1,7 @@
1
1
  import type { ConfigDescription, ElementDescription } from '../layout/describe-config.js';
2
2
  import type { Span, UnconvertedSpan } from '../schema/agent-logic-schema.js';
3
- export type Coverage = 'ambient' | 'comment' | 'used' | 'unused' | 'unconverted';
3
+ /** How the chart uses a run of prompt text; `structure` is Markdown syntax, such as a heading line or a list marker. */
4
+ export type Coverage = 'ambient' | 'comment' | 'structure' | 'used' | 'unused' | 'unconverted';
4
5
  /** A run of prompt text that the same element spans cover. */
5
6
  export interface PromptSegment {
6
7
  start: number;
@@ -9,10 +10,15 @@ export interface PromptSegment {
9
10
  coverage: Coverage;
10
11
  /** Paths of the elements whose spans cover the segment, narrowest span first. */
11
12
  paths: string[];
13
+ /** The level of the Markdown heading whose line contains the segment, and whether the segment is its `#` marker. */
14
+ heading?: {
15
+ level: number;
16
+ isMarker: boolean;
17
+ };
12
18
  }
13
19
  /**
14
- * Cuts the prompt at every span, comment, and shown-span boundary into contiguous segments, each with the elements
15
- * that cover it.
20
+ * Cuts the prompt at every span, comment, structure, and shown-span boundary into contiguous segments, each with the
21
+ * elements that cover it.
16
22
  */
17
23
  export declare function buildPromptSegments(prompt: string, description: ConfigDescription, unconverted: UnconvertedSpan[], shown?: Span[]): PromptSegment[];
18
24
  /** Lists the lowercase words of an element's identifiers and prose, without common function words. */
@@ -1,4 +1,5 @@
1
1
  import { findCommentSpans } from "./find-comment-spans.js";
2
+ import { findStructureSpans } from "./find-structure-spans.js";
2
3
  export function buildPromptSegments(prompt, description, unconverted, shown = []) {
3
4
  const elements = [...description.states.filter(({ parentId }) => parentId !== undefined), ...description.transitions];
4
5
  const elementSpans = [
@@ -14,8 +15,10 @@ export function buildPromptSegments(prompt, description, unconverted, shown = []
14
15
  ];
15
16
  const ambientSpans = description.ambient.map(({ source }) => source);
16
17
  const commentSpans = findCommentSpans(prompt);
17
- const cuts = new Set([0, prompt.length]);
18
- for (const { start, end } of [...elementSpans, ...unconverted, ...commentSpans, ...shown]) {
18
+ const structureSpans = findStructureSpans(prompt);
19
+ const headings = structureSpans.filter((span) => span.kind === 'heading');
20
+ const cuts = new Set([0, prompt.length, ...headings.map(({ markerEnd }) => markerEnd)]);
21
+ for (const { start, end } of [...elementSpans, ...unconverted, ...commentSpans, ...structureSpans, ...shown]) {
19
22
  cuts.add(start);
20
23
  cuts.add(end);
21
24
  }
@@ -26,12 +29,14 @@ export function buildPromptSegments(prompt, description, unconverted, shown = []
26
29
  const end = points[index + 1] ?? prompt.length;
27
30
  const covering = elementSpans.filter((span) => span.start <= start && span.end >= end);
28
31
  const paths = covering.toSorted((a, b) => a.end - a.start - (b.end - b.start)).map(({ path }) => path);
32
+ const heading = headings.find((span) => span.start <= start && span.end >= end);
29
33
  segments.push({
30
34
  start,
31
35
  end,
32
36
  text: prompt.slice(start, end),
33
- coverage: findCoverage(start, end, { unconverted, ambient: ambientSpans, comments: commentSpans }, paths),
37
+ coverage: findCoverage(start, end, { unconverted, ambient: ambientSpans, comments: commentSpans, structure: structureSpans }, paths),
34
38
  paths,
39
+ ...(heading !== undefined && { heading: { level: heading.level, isMarker: end <= heading.markerEnd } }),
35
40
  });
36
41
  }
37
42
  return segments;
@@ -50,14 +55,16 @@ export function splitWords(text) {
50
55
  .split(/[^a-z0-9]+/)
51
56
  .filter((word) => word !== '' && !STOP_WORDS.has(word));
52
57
  }
53
- function findCoverage(start, end, { unconverted, ambient, comments }, paths) {
58
+ function findCoverage(start, end, { unconverted, ambient, comments, structure }, paths) {
54
59
  if (unconverted.some(covers))
55
60
  return 'unconverted';
56
61
  if (ambient.some(covers))
57
62
  return 'ambient';
58
63
  if (paths.length > 0)
59
64
  return 'used';
60
- return comments.some(covers) ? 'comment' : 'unused';
65
+ if (comments.some(covers))
66
+ return 'comment';
67
+ return structure.some(covers) ? 'structure' : 'unused';
61
68
  function covers(span) {
62
69
  return span.start <= start && span.end >= end;
63
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeassembly-agent-logic",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Model of an agent prompt's states and transitions, with React and server entries for the apps that present it",
5
5
  "keywords": [
6
6
  "agents",
@@ -73,9 +73,9 @@
73
73
  "@modelcontextprotocol/client": "2.4.0",
74
74
  "@modelcontextprotocol/server": "2.4.0",
75
75
  "@testing-library/dom": "10.4.2",
76
- "@testing-library/jest-dom": "7.0.1",
76
+ "@testing-library/jest-dom": "8.0.0",
77
77
  "@testing-library/react": "16.3.3",
78
- "@testing-library/user-event": "14.6.12",
78
+ "@testing-library/user-event": "14.6.13",
79
79
  "@types/node": "24.19.2",
80
80
  "@types/react": "19.3.0",
81
81
  "@types/react-dom": "19.3.0",
@@ -84,7 +84,7 @@
84
84
  "@williamthorsen/toolbelt.acp": "0.3.3",
85
85
  "@williamthorsen/toolbelt.llm": "0.2.1",
86
86
  "eslint": "10.15.0",
87
- "eslint-plugin-jest-dom": "5.10.2",
87
+ "eslint-plugin-jest-dom": "5.11.0",
88
88
  "eslint-plugin-react": "7.37.5",
89
89
  "eslint-plugin-react-hooks": "7.1.1",
90
90
  "eslint-plugin-testing-library": "7.16.2",