codeassembly-agent-logic 0.6.0 → 0.7.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.
- package/.meta/changelog.json +39 -0
- package/CHANGELOG.md +14 -0
- package/README.md +7 -4
- package/dist/esm/coverage-map/find-prompt-blocks.js +1 -66
- package/dist/esm/react/source/PromptPane.d.ts +5 -4
- package/dist/esm/react/source/PromptPane.js +12 -4
- package/dist/esm/react/styles.css +39 -0
- package/dist/esm/source/find-structure-spans.d.ts +18 -0
- package/dist/esm/source/find-structure-spans.js +35 -0
- package/dist/esm/source/prompt-lines.d.ts +26 -0
- package/dist/esm/source/prompt-lines.js +67 -0
- package/dist/esm/source/prompt-segments.d.ts +9 -3
- package/dist/esm/source/prompt-segments.js +12 -5
- package/package.json +3 -3
package/.meta/changelog.json
CHANGED
|
@@ -1,4 +1,43 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"date": "2026-11-21",
|
|
5
|
+
"sections": [
|
|
6
|
+
{
|
|
7
|
+
"title": "🎉 Features",
|
|
8
|
+
"audience": "all",
|
|
9
|
+
"items": [
|
|
10
|
+
{
|
|
11
|
+
"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)",
|
|
12
|
+
"hash": "86c0f6f48777f7941824ab216f12c85692db470c",
|
|
13
|
+
"entry": 2
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"title": "🐛 Bug fixes",
|
|
19
|
+
"audience": "all",
|
|
20
|
+
"items": [
|
|
21
|
+
{
|
|
22
|
+
"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)",
|
|
23
|
+
"hash": "86c0f6f48777f7941824ab216f12c85692db470c",
|
|
24
|
+
"entry": 1
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"title": "📦 Dependencies",
|
|
30
|
+
"audience": "dev",
|
|
31
|
+
"items": [
|
|
32
|
+
{
|
|
33
|
+
"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)",
|
|
34
|
+
"hash": "d2c434179d5faa5b3ec36ba91ef815c299c59b02",
|
|
35
|
+
"entry": 1
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
},
|
|
2
41
|
{
|
|
3
42
|
"version": "0.6.0",
|
|
4
43
|
"date": "2026-11-19",
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 0.7.0 — 2026-11-21
|
|
6
|
+
|
|
7
|
+
### 🎉 Features
|
|
8
|
+
|
|
9
|
+
- 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)
|
|
10
|
+
|
|
11
|
+
### 🐛 Bug fixes
|
|
12
|
+
|
|
13
|
+
- 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)
|
|
14
|
+
|
|
15
|
+
### 📦 Dependencies
|
|
16
|
+
|
|
17
|
+
- 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)
|
|
18
|
+
|
|
5
19
|
## 0.6.0 — 2026-11-19
|
|
6
20
|
|
|
7
21
|
### 🎉 Features
|
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
<!-- section:release-notes -->
|
|
2
|
-
## Release notes — v0.
|
|
2
|
+
## Release notes — v0.7.0 (2026-11-21)
|
|
3
3
|
|
|
4
4
|
### 🎉 Features
|
|
5
5
|
|
|
6
|
-
-
|
|
7
|
-
|
|
6
|
+
- 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)
|
|
7
|
+
|
|
8
|
+
### 🐛 Bug fixes
|
|
9
|
+
|
|
10
|
+
- 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)
|
|
8
11
|
<!-- /section:release-notes -->
|
|
9
12
|
|
|
10
13
|
<!-- readme-type: library -->
|
|
@@ -117,7 +120,7 @@ if (started.ok) {
|
|
|
117
120
|
|
|
118
121
|
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
122
|
|
|
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`.
|
|
123
|
+
`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
124
|
|
|
122
125
|
## Styling and theming
|
|
123
126
|
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
-
}
|
|
@@ -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
|
|
15
|
-
* shown passages highlighted. Its text region has `data-prompt-text`, and each
|
|
16
|
-
* passage has `data-selected`, the first of them `data-passage-for` with the
|
|
17
|
-
* `data-shown`, the earliest of them `data-shown-passage`, and a passage that selects
|
|
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 =
|
|
52
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
18
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.7.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": "
|
|
76
|
+
"@testing-library/jest-dom": "8.0.0",
|
|
77
77
|
"@testing-library/react": "16.3.3",
|
|
78
|
-
"@testing-library/user-event": "14.6.
|
|
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",
|