@kurvball/ashlar 0.0.0-stage → 1.3.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/CHANGELOG.md +238 -0
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/dist/affected.d.ts +19 -0
- package/dist/affected.js +78 -0
- package/dist/areas.d.ts +2 -0
- package/dist/areas.js +20 -0
- package/dist/baseline.d.ts +27 -0
- package/dist/baseline.js +109 -0
- package/dist/beside.d.ts +1 -0
- package/dist/beside.js +4 -0
- package/dist/check.d.ts +39 -0
- package/dist/check.js +109 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +211 -0
- package/dist/config.d.ts +84 -0
- package/dist/config.js +98 -0
- package/dist/configCheck.d.ts +2 -0
- package/dist/configCheck.js +204 -0
- package/dist/css.d.ts +13 -0
- package/dist/css.js +66 -0
- package/dist/drive.d.ts +77 -0
- package/dist/drive.js +188 -0
- package/dist/features.d.ts +32 -0
- package/dist/features.js +156 -0
- package/dist/git.d.ts +18 -0
- package/dist/git.js +140 -0
- package/dist/glob.d.ts +5 -0
- package/dist/glob.js +49 -0
- package/dist/graph.d.ts +16 -0
- package/dist/graph.js +83 -0
- package/dist/identity.d.ts +1 -0
- package/dist/identity.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +18 -0
- package/dist/jsonc.d.ts +1 -0
- package/dist/jsonc.js +66 -0
- package/dist/knowledge/areas.d.ts +25 -0
- package/dist/knowledge/areas.js +86 -0
- package/dist/knowledge/decisions.d.ts +14 -0
- package/dist/knowledge/decisions.js +53 -0
- package/dist/knowledge/guards.d.ts +4 -0
- package/dist/knowledge/guards.js +60 -0
- package/dist/knowledge/rules.d.ts +12 -0
- package/dist/knowledge/rules.js +100 -0
- package/dist/knowledge/secrets.d.ts +6 -0
- package/dist/knowledge/secrets.js +58 -0
- package/dist/layout.d.ts +61 -0
- package/dist/layout.js +120 -0
- package/dist/ledger.d.ts +28 -0
- package/dist/ledger.js +44 -0
- package/dist/lint.d.ts +11 -0
- package/dist/lint.js +109 -0
- package/dist/map.d.ts +25 -0
- package/dist/map.js +37 -0
- package/dist/move.d.ts +18 -0
- package/dist/move.js +94 -0
- package/dist/onboard/applies.d.ts +11 -0
- package/dist/onboard/applies.js +28 -0
- package/dist/onboard/brief.d.ts +40 -0
- package/dist/onboard/brief.js +126 -0
- package/dist/onboard/guide.d.ts +7 -0
- package/dist/onboard/guide.js +150 -0
- package/dist/onboard/model.d.ts +15 -0
- package/dist/onboard/model.js +57 -0
- package/dist/onboard/onboard.d.ts +28 -0
- package/dist/onboard/onboard.js +86 -0
- package/dist/onboard/questions.d.ts +15 -0
- package/dist/onboard/questions.js +90 -0
- package/dist/onboard/snapshot.d.ts +28 -0
- package/dist/onboard/snapshot.js +58 -0
- package/dist/order.d.ts +1 -0
- package/dist/order.js +1 -0
- package/dist/origins.d.ts +6 -0
- package/dist/origins.js +51 -0
- package/dist/plugin/boundaries.d.ts +5 -0
- package/dist/plugin/boundaries.js +174 -0
- package/dist/plugin/exports.d.ts +2 -0
- package/dist/plugin/exports.js +41 -0
- package/dist/plugin/features.d.ts +4 -0
- package/dist/plugin/features.js +34 -0
- package/dist/plugin/here.d.ts +13 -0
- package/dist/plugin/here.js +69 -0
- package/dist/plugin/imports.d.ts +12 -0
- package/dist/plugin/imports.js +103 -0
- package/dist/plugin/index.d.ts +14 -0
- package/dist/plugin/index.js +19 -0
- package/dist/plugin/messages.d.ts +20 -0
- package/dist/plugin/messages.js +36 -0
- package/dist/plugin/names.d.ts +3 -0
- package/dist/plugin/names.js +68 -0
- package/dist/plugin/references.d.ts +5 -0
- package/dist/plugin/references.js +52 -0
- package/dist/plugin/text.d.ts +7 -0
- package/dist/plugin/text.js +87 -0
- package/dist/plugin/types.d.ts +87 -0
- package/dist/plugin/types.js +1 -0
- package/dist/reach.d.ts +82 -0
- package/dist/reach.js +163 -0
- package/dist/reachDrive.d.ts +31 -0
- package/dist/reachDrive.js +200 -0
- package/dist/reachReader.d.ts +1 -0
- package/dist/reachReader.js +31 -0
- package/dist/rehearse/dependents.d.ts +9 -0
- package/dist/rehearse/dependents.js +38 -0
- package/dist/rehearse/fill.d.ts +28 -0
- package/dist/rehearse/fill.js +44 -0
- package/dist/report.d.ts +6 -0
- package/dist/report.js +91 -0
- package/dist/resolve.d.ts +3 -0
- package/dist/resolve.js +114 -0
- package/dist/runner.d.ts +6 -0
- package/dist/runner.js +29 -0
- package/dist/skill.d.ts +23 -0
- package/dist/skill.js +235 -0
- package/dist/usage.d.ts +1 -0
- package/dist/usage.js +53 -0
- package/dist/workspace.d.ts +16 -0
- package/dist/workspace.js +125 -0
- package/ledger.json +201 -0
- package/package.json +73 -3
- package/schema/affected.v1.json +58 -0
- package/schema/brief.v1.json +205 -0
- package/schema/check.v1.json +151 -0
- package/schema/dependents.v1.json +30 -0
- package/schema/drive.v1.json +55 -0
- package/schema/ledger.v1.json +61 -0
- package/schema/map.v1.json +62 -0
- package/schema/move.v1.json +61 -0
- package/schema/onboard.v1.json +186 -0
- package/schema/rehearse.v1.json +91 -0
- package/schema/snapshot.v1.json +101 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { STACKS } from './layout.js';
|
|
2
|
+
import { RULES } from './plugin/messages.js';
|
|
3
|
+
const TOP = {
|
|
4
|
+
include: 'strings',
|
|
5
|
+
ignore: 'strings',
|
|
6
|
+
apps: 'list',
|
|
7
|
+
setups: 'list',
|
|
8
|
+
tests: 'strings',
|
|
9
|
+
maxLines: 'number',
|
|
10
|
+
baseline: 'string',
|
|
11
|
+
drive: 'string',
|
|
12
|
+
confined: 'list',
|
|
13
|
+
rules: 'record',
|
|
14
|
+
messages: 'record',
|
|
15
|
+
skills: 'record',
|
|
16
|
+
onboard: 'record',
|
|
17
|
+
};
|
|
18
|
+
const ONBOARD = {
|
|
19
|
+
out: 'string',
|
|
20
|
+
decisions: 'string',
|
|
21
|
+
rules: 'string',
|
|
22
|
+
owner: 'string',
|
|
23
|
+
owners: 'record',
|
|
24
|
+
areas: 'strings',
|
|
25
|
+
documents: 'strings',
|
|
26
|
+
dataRules: 'strings',
|
|
27
|
+
guards: 'strings',
|
|
28
|
+
};
|
|
29
|
+
const HANDLE = /^@[A-Za-z0-9][\w.-]*$/;
|
|
30
|
+
function onboardOf(value, problems) {
|
|
31
|
+
if (!isRecord(value))
|
|
32
|
+
return;
|
|
33
|
+
keysOf(value, ONBOARD, 'onboard', problems);
|
|
34
|
+
if (typeof value.out === 'string') {
|
|
35
|
+
const out = value.out.trim().replace(/\/+$/, '');
|
|
36
|
+
if (out === '' || out === '.' || out === '..' || out.startsWith('../') || out.startsWith('/')) {
|
|
37
|
+
problems.push('`onboard.out` is a folder inside the project, such as docs/onboarding.');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(value.areas)) {
|
|
41
|
+
for (const area of value.areas) {
|
|
42
|
+
if (typeof area === 'string' && /[*?{[]/.test(area.replace(/\/\*$/, ''))) {
|
|
43
|
+
problems.push(`\`onboard.areas\` takes folders, or a folder's subfolders as \`folder/*\`: ${area} is neither.`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (typeof value.owner === 'string' && !HANDLE.test(value.owner.trim())) {
|
|
48
|
+
problems.push('`onboard.owner` is a handle, such as @robin.');
|
|
49
|
+
}
|
|
50
|
+
if (isRecord(value.owners)) {
|
|
51
|
+
for (const [folder, owner] of Object.entries(value.owners)) {
|
|
52
|
+
if (typeof owner !== 'string' || !HANDLE.test(owner.trim())) {
|
|
53
|
+
problems.push(`\`onboard.owners.${folder}\` is a handle, such as @robin.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const APP = {
|
|
59
|
+
root: 'string',
|
|
60
|
+
stack: 'string',
|
|
61
|
+
main: 'strings',
|
|
62
|
+
renderer: 'strings',
|
|
63
|
+
shared: 'strings',
|
|
64
|
+
features: 'strings',
|
|
65
|
+
client: 'strings',
|
|
66
|
+
primitives: 'strings',
|
|
67
|
+
areas: 'strings',
|
|
68
|
+
bridge: 'record',
|
|
69
|
+
builds: 'list',
|
|
70
|
+
setups: 'list',
|
|
71
|
+
};
|
|
72
|
+
const BRIDGE = { global: 'string', modules: 'strings', packages: 'strings' };
|
|
73
|
+
const BUILD = { tests: 'strings', reach: 'strings' };
|
|
74
|
+
const SETUP = { files: 'strings', tests: 'strings', exclude: 'strings' };
|
|
75
|
+
const CONFINED = {
|
|
76
|
+
words: 'strings',
|
|
77
|
+
only: 'strings',
|
|
78
|
+
within: 'strings',
|
|
79
|
+
message: 'string',
|
|
80
|
+
};
|
|
81
|
+
const SKILLS = { verify: 'record' };
|
|
82
|
+
const VERIFY = { attach: 'string' };
|
|
83
|
+
const SAYS = {
|
|
84
|
+
strings: 'a list of strings',
|
|
85
|
+
string: 'a string',
|
|
86
|
+
number: 'a whole number above 0',
|
|
87
|
+
list: 'a list',
|
|
88
|
+
record: 'an object',
|
|
89
|
+
};
|
|
90
|
+
const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
91
|
+
function fits(value, shape) {
|
|
92
|
+
switch (shape) {
|
|
93
|
+
case 'strings':
|
|
94
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === 'string');
|
|
95
|
+
case 'string':
|
|
96
|
+
return typeof value === 'string';
|
|
97
|
+
case 'number':
|
|
98
|
+
return typeof value === 'number' && Number.isInteger(value) && value > 0;
|
|
99
|
+
case 'list':
|
|
100
|
+
return Array.isArray(value);
|
|
101
|
+
case 'record':
|
|
102
|
+
return isRecord(value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function keysOf(value, shapes, at, problems) {
|
|
106
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
107
|
+
const shape = shapes[key];
|
|
108
|
+
const path = at ? `${at}.${key}` : key;
|
|
109
|
+
if (shape === undefined) {
|
|
110
|
+
problems.push(`\`${path}\` isn't a key Ashlar reads: ${Object.keys(shapes).join(', ')}.`);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (entry !== undefined && !fits(entry, shape))
|
|
114
|
+
problems.push(`\`${path}\` is ${SAYS[shape]}.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function listOf(value, shapes, at, problems, required = []) {
|
|
118
|
+
if (!Array.isArray(value))
|
|
119
|
+
return [];
|
|
120
|
+
const records = [];
|
|
121
|
+
value.forEach((entry, i) => {
|
|
122
|
+
if (!isRecord(entry)) {
|
|
123
|
+
problems.push(`\`${at}[${i}]\` is an object.`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
keysOf(entry, shapes, `${at}[${i}]`, problems);
|
|
127
|
+
for (const key of required) {
|
|
128
|
+
if (entry[key] === undefined)
|
|
129
|
+
problems.push(`\`${at}[${i}].${key}\` is missing: give it ${SAYS[shapes[key]]}.`);
|
|
130
|
+
}
|
|
131
|
+
records.push(entry);
|
|
132
|
+
});
|
|
133
|
+
return records;
|
|
134
|
+
}
|
|
135
|
+
const RULE_NAMES = RULES.join(', ');
|
|
136
|
+
function rulesOf(value, problems) {
|
|
137
|
+
if (!isRecord(value))
|
|
138
|
+
return;
|
|
139
|
+
for (const [rule, switched] of Object.entries(value)) {
|
|
140
|
+
if (!RULES.includes(rule)) {
|
|
141
|
+
problems.push(`\`rules.${rule}\` names no rule: ${RULE_NAMES}.`);
|
|
142
|
+
}
|
|
143
|
+
else if (switched !== 'on' && switched !== 'off') {
|
|
144
|
+
problems.push(`\`rules.${rule}\` is 'on' or 'off'.`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function messagesOf(value, problems) {
|
|
149
|
+
if (!isRecord(value))
|
|
150
|
+
return;
|
|
151
|
+
for (const [rule, message] of Object.entries(value)) {
|
|
152
|
+
if (rule === 'named-only-in') {
|
|
153
|
+
problems.push('`messages.named-only-in` lives in each `confined` entry, as its `message`.');
|
|
154
|
+
}
|
|
155
|
+
else if (!RULES.includes(rule)) {
|
|
156
|
+
problems.push(`\`messages.${rule}\` names no rule: ${RULE_NAMES}.`);
|
|
157
|
+
}
|
|
158
|
+
else if (typeof message !== 'string' || !message.trim()) {
|
|
159
|
+
problems.push(`\`messages.${rule}\` is the words agents read: a string.`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export function checkConfig(config) {
|
|
164
|
+
const problems = [];
|
|
165
|
+
if (!isRecord(config))
|
|
166
|
+
return ['Its default export is an object: `export default defineConfig({ ... })`.'];
|
|
167
|
+
keysOf(config, TOP, '', problems);
|
|
168
|
+
if (config.include === undefined || (Array.isArray(config.include) && config.include.length === 0)) {
|
|
169
|
+
problems.push('`include` names the folders to check: give it at least one.');
|
|
170
|
+
}
|
|
171
|
+
const apps = listOf(config.apps, APP, 'apps', problems, ['root']);
|
|
172
|
+
apps.forEach((app, i) => {
|
|
173
|
+
if (typeof app.stack !== 'string' || !Object.hasOwn(STACKS, app.stack)) {
|
|
174
|
+
problems.push(`\`apps[${i}].stack\` is one of ${Object.keys(STACKS).join(', ')}.`);
|
|
175
|
+
}
|
|
176
|
+
if (isRecord(app.bridge))
|
|
177
|
+
keysOf(app.bridge, BRIDGE, `apps[${i}].bridge`, problems);
|
|
178
|
+
listOf(app.builds, BUILD, `apps[${i}].builds`, problems, ['tests', 'reach']);
|
|
179
|
+
listOf(app.setups, SETUP, `apps[${i}].setups`, problems, ['files', 'tests']);
|
|
180
|
+
});
|
|
181
|
+
listOf(config.setups, SETUP, 'setups', problems, ['files', 'tests']);
|
|
182
|
+
listOf(config.confined, CONFINED, 'confined', problems, ['words', 'message']);
|
|
183
|
+
rulesOf(config.rules, problems);
|
|
184
|
+
messagesOf(config.messages, problems);
|
|
185
|
+
if (isRecord(config.skills)) {
|
|
186
|
+
keysOf(config.skills, SKILLS, 'skills', problems);
|
|
187
|
+
if (isRecord(config.skills.verify))
|
|
188
|
+
keysOf(config.skills.verify, VERIFY, 'skills.verify', problems);
|
|
189
|
+
}
|
|
190
|
+
onboardOf(config.onboard, problems);
|
|
191
|
+
return problems;
|
|
192
|
+
}
|
|
193
|
+
const keys = (prefix, shapes) => Object.keys(shapes).map((key) => `${prefix}${key}`);
|
|
194
|
+
export const CONFIG_KEYS = [
|
|
195
|
+
...keys('', TOP),
|
|
196
|
+
...keys('apps[].', APP),
|
|
197
|
+
...keys('apps[].bridge.', BRIDGE),
|
|
198
|
+
...keys('apps[].builds[].', BUILD),
|
|
199
|
+
...keys('apps[].setups[].', SETUP),
|
|
200
|
+
...keys('setups[].', SETUP),
|
|
201
|
+
...keys('confined[].', CONFINED),
|
|
202
|
+
...keys('skills.verify.', VERIFY),
|
|
203
|
+
...keys('onboard.', ONBOARD),
|
|
204
|
+
];
|
package/dist/css.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Matcher } from './glob.ts';
|
|
2
|
+
import type { Resolve } from './resolve.ts';
|
|
3
|
+
export interface Source {
|
|
4
|
+
css: string;
|
|
5
|
+
holds: Matcher;
|
|
6
|
+
}
|
|
7
|
+
export interface CssGraph {
|
|
8
|
+
files: string[];
|
|
9
|
+
edges: Map<string, string[]>;
|
|
10
|
+
sources: Source[];
|
|
11
|
+
}
|
|
12
|
+
export declare function cssFiles(root: string, include: string[], ignore: string[]): string[];
|
|
13
|
+
export declare function cssGraph(root: string, files: string[], resolve: Resolve): CssGraph;
|
package/dist/css.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, posix } from 'node:path';
|
|
3
|
+
import { matcherOf } from './glob.js';
|
|
4
|
+
import { tidy } from './layout.js';
|
|
5
|
+
import { walkFolders } from './workspace.js';
|
|
6
|
+
const TOKEN = /\/\*[\s\S]*?(?:\*\/|$)|'(?:\\[\s\S]|[^'\\])*'|"(?:\\[\s\S]|[^"\\])*"/g;
|
|
7
|
+
const AT_RULE = /@(import|reference|plugin|config|source)\s+([^;]+);/g;
|
|
8
|
+
const QUOTED = /^(['"])(.*?)\1/;
|
|
9
|
+
const URL = /^url\(\s*(?:(['"])(.*?)\1|([^)'"\s]+))\s*\)/;
|
|
10
|
+
function uncommented(text) {
|
|
11
|
+
return text.replace(TOKEN, (token) => (token.startsWith('/*') ? ' ' : token));
|
|
12
|
+
}
|
|
13
|
+
function target(argument) {
|
|
14
|
+
const url = URL.exec(argument);
|
|
15
|
+
if (url)
|
|
16
|
+
return url[2] ?? url[3] ?? null;
|
|
17
|
+
return QUOTED.exec(argument)?.[2] ?? null;
|
|
18
|
+
}
|
|
19
|
+
export function cssFiles(root, include, ignore) {
|
|
20
|
+
const found = [];
|
|
21
|
+
walkFolders(root, include, new Set(ignore), (file) => {
|
|
22
|
+
if (file.endsWith('.css'))
|
|
23
|
+
found.push(file);
|
|
24
|
+
});
|
|
25
|
+
return found.sort();
|
|
26
|
+
}
|
|
27
|
+
function sourceOf(css, argument) {
|
|
28
|
+
if (/^(?:not|inline)\b/.test(argument))
|
|
29
|
+
return null;
|
|
30
|
+
const path = target(argument);
|
|
31
|
+
if (path === null)
|
|
32
|
+
return null;
|
|
33
|
+
const at = tidy(posix.join(posix.dirname(css), path));
|
|
34
|
+
return at.startsWith('..') ? null : { css, holds: matcherOf(at) };
|
|
35
|
+
}
|
|
36
|
+
function importOf(css, argument, resolve) {
|
|
37
|
+
const specifier = target(argument);
|
|
38
|
+
if (specifier === null || /^[a-z]+:/i.test(specifier))
|
|
39
|
+
return null;
|
|
40
|
+
const found = resolve(css, specifier);
|
|
41
|
+
if (found || /^[./]/.test(specifier))
|
|
42
|
+
return found;
|
|
43
|
+
return resolve(css, `./${specifier}`);
|
|
44
|
+
}
|
|
45
|
+
export function cssGraph(root, files, resolve) {
|
|
46
|
+
const edges = new Map();
|
|
47
|
+
const sources = [];
|
|
48
|
+
for (const css of files) {
|
|
49
|
+
const text = uncommented(readFileSync(join(root, css), 'utf8'));
|
|
50
|
+
const out = [];
|
|
51
|
+
for (const [, rule, raw] of text.matchAll(AT_RULE)) {
|
|
52
|
+
const argument = raw.trim();
|
|
53
|
+
if (rule === 'source') {
|
|
54
|
+
const source = sourceOf(css, argument);
|
|
55
|
+
if (source)
|
|
56
|
+
sources.push(source);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const found = importOf(css, argument, resolve);
|
|
60
|
+
if (found && found !== css)
|
|
61
|
+
out.push(found);
|
|
62
|
+
}
|
|
63
|
+
edges.set(css, out);
|
|
64
|
+
}
|
|
65
|
+
return { files, edges, sources };
|
|
66
|
+
}
|
package/dist/drive.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type DriveRole, type ReachStep } from './reach.ts';
|
|
2
|
+
export declare const DRIVE_COMMANDS: readonly ['click', 'type', 'key', 'snapshot', 'screenshot', 'record', 'stop'];
|
|
3
|
+
export type DriveVerb = (typeof DRIVE_COMMANDS)[number];
|
|
4
|
+
export declare const isDriveVerb: (v: unknown) => v is DriveVerb;
|
|
5
|
+
export type DriveCommand = {
|
|
6
|
+
command: 'click';
|
|
7
|
+
name: string;
|
|
8
|
+
role: DriveRole | null;
|
|
9
|
+
} | {
|
|
10
|
+
command: 'type';
|
|
11
|
+
text: string;
|
|
12
|
+
} | {
|
|
13
|
+
command: 'key';
|
|
14
|
+
key: string;
|
|
15
|
+
} | {
|
|
16
|
+
command: 'snapshot';
|
|
17
|
+
name: string | null;
|
|
18
|
+
role: DriveRole | null;
|
|
19
|
+
} | {
|
|
20
|
+
command: 'screenshot';
|
|
21
|
+
file: string;
|
|
22
|
+
} | {
|
|
23
|
+
command: 'record';
|
|
24
|
+
file: string;
|
|
25
|
+
} | {
|
|
26
|
+
command: 'stop';
|
|
27
|
+
};
|
|
28
|
+
export declare const DRIVE_FILES: {
|
|
29
|
+
readonly screenshot: '.png';
|
|
30
|
+
readonly record: '.webm';
|
|
31
|
+
};
|
|
32
|
+
export declare const DRIVE_USAGE = "Usage:\n drive click --name <name> [--role <role>]\n Clicks the one element with that accessible name, of that role if given.\n drive type <text>\n Types the text into what has focus.\n drive key <key>\n Presses a key, named as Playwright does: Enter, Escape, Meta+k, or ControlOrMeta+j for \u2318 on a Mac and Ctrl elsewhere.\n drive snapshot [--name <name> [--role <role>]]\n Prints the accessibility tree, or the subtree of the one element with that name.\n With --name it fails when no element has that name.\n drive screenshot <file.png>\n Saves the window as it is now.\n drive record <file.webm>\n Records what follows into the file, which stop saves.\n drive stop\n Saves any recording and ends the app.\nEach command takes --json, and then prints its result as one JSON object.\nThe first command starts the app on a scratch home; it stays up until stop.\nEach command reads DRIVE_SCHEME=light|dark, and the app shows that colour scheme from then on.\n";
|
|
33
|
+
export declare const SCHEME_VARIABLE = "DRIVE_SCHEME";
|
|
34
|
+
export declare const DRIVE_USAGE_REFUSALS: readonly ['no_command', 'unknown_command', 'unknown_flag', 'flag_value', 'no_name', 'role_without_name', 'bad_role', 'no_text', 'no_key', 'bad_key', 'no_file', 'bad_file', 'extra'];
|
|
35
|
+
export type DriveUsageRefusal = (typeof DRIVE_USAGE_REFUSALS)[number];
|
|
36
|
+
export type DriveParse = {
|
|
37
|
+
ok: true;
|
|
38
|
+
command: DriveCommand;
|
|
39
|
+
json: boolean;
|
|
40
|
+
} | {
|
|
41
|
+
ok: false;
|
|
42
|
+
refusal: DriveUsageRefusal;
|
|
43
|
+
says: string;
|
|
44
|
+
};
|
|
45
|
+
export declare const DRIVE_USAGE_WORDS: {
|
|
46
|
+
readonly [R in DriveUsageRefusal]: (said: string) => string;
|
|
47
|
+
};
|
|
48
|
+
export declare function parseDrive(argv: readonly string[]): DriveParse;
|
|
49
|
+
export declare function driveArgv(c: DriveCommand): string[];
|
|
50
|
+
export declare function stepCommand(step: ReachStep): DriveCommand;
|
|
51
|
+
export declare const DRIVE_FAILURES: readonly ['usage', 'not_found', 'ambiguous', 'not_running', 'timed_out', 'crashed'];
|
|
52
|
+
export type DriveFailure = (typeof DRIVE_FAILURES)[number];
|
|
53
|
+
export interface DriveDone {
|
|
54
|
+
ok: true;
|
|
55
|
+
command: DriveVerb;
|
|
56
|
+
ms: number;
|
|
57
|
+
file: string | null;
|
|
58
|
+
tree: string | null;
|
|
59
|
+
}
|
|
60
|
+
export interface DriveFailed {
|
|
61
|
+
ok: false;
|
|
62
|
+
command: DriveVerb | null;
|
|
63
|
+
ms: number;
|
|
64
|
+
failure: DriveFailure;
|
|
65
|
+
says: string;
|
|
66
|
+
}
|
|
67
|
+
export type DriveResult = DriveDone | DriveFailed;
|
|
68
|
+
export declare const DRIVE_EXIT: {
|
|
69
|
+
readonly done: 0;
|
|
70
|
+
readonly failed: 1;
|
|
71
|
+
readonly usage: 2;
|
|
72
|
+
};
|
|
73
|
+
export declare const exitOf: (r: DriveResult) => number;
|
|
74
|
+
export declare const DRIVE_FAILURE_WORDS: {
|
|
75
|
+
readonly [F in Exclude<DriveFailure, 'usage'>]: (name: string | null) => string;
|
|
76
|
+
};
|
|
77
|
+
export declare function driveResultText(r: DriveResult): string;
|
package/dist/drive.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { isDriveKey, isDriveRole } from './reach.js';
|
|
2
|
+
export const DRIVE_COMMANDS = ['click', 'type', 'key', 'snapshot', 'screenshot', 'record', 'stop'];
|
|
3
|
+
export const isDriveVerb = (v) => typeof v === 'string' && DRIVE_COMMANDS.includes(v);
|
|
4
|
+
export const DRIVE_FILES = { screenshot: '.png', record: '.webm' };
|
|
5
|
+
export const DRIVE_USAGE = `Usage:
|
|
6
|
+
drive click --name <name> [--role <role>]
|
|
7
|
+
Clicks the one element with that accessible name, of that role if given.
|
|
8
|
+
drive type <text>
|
|
9
|
+
Types the text into what has focus.
|
|
10
|
+
drive key <key>
|
|
11
|
+
Presses a key, named as Playwright does: Enter, Escape, Meta+k, or ControlOrMeta+j for ⌘ on a Mac and Ctrl elsewhere.
|
|
12
|
+
drive snapshot [--name <name> [--role <role>]]
|
|
13
|
+
Prints the accessibility tree, or the subtree of the one element with that name.
|
|
14
|
+
With --name it fails when no element has that name.
|
|
15
|
+
drive screenshot <file.png>
|
|
16
|
+
Saves the window as it is now.
|
|
17
|
+
drive record <file.webm>
|
|
18
|
+
Records what follows into the file, which stop saves.
|
|
19
|
+
drive stop
|
|
20
|
+
Saves any recording and ends the app.
|
|
21
|
+
Each command takes --json, and then prints its result as one JSON object.
|
|
22
|
+
The first command starts the app on a scratch home; it stays up until stop.
|
|
23
|
+
Each command reads DRIVE_SCHEME=light|dark, and the app shows that colour scheme from then on.
|
|
24
|
+
`;
|
|
25
|
+
export const SCHEME_VARIABLE = 'DRIVE_SCHEME';
|
|
26
|
+
export const DRIVE_USAGE_REFUSALS = [
|
|
27
|
+
'no_command',
|
|
28
|
+
'unknown_command',
|
|
29
|
+
'unknown_flag',
|
|
30
|
+
'flag_value',
|
|
31
|
+
'no_name',
|
|
32
|
+
'role_without_name',
|
|
33
|
+
'bad_role',
|
|
34
|
+
'no_text',
|
|
35
|
+
'no_key',
|
|
36
|
+
'bad_key',
|
|
37
|
+
'no_file',
|
|
38
|
+
'bad_file',
|
|
39
|
+
'extra',
|
|
40
|
+
];
|
|
41
|
+
export const DRIVE_USAGE_WORDS = {
|
|
42
|
+
no_command: () => `Name a drive command: ${DRIVE_COMMANDS.join(', ')}.`,
|
|
43
|
+
unknown_command: (said) => `Drive has no ${said} command: ${DRIVE_COMMANDS.join(', ')}.`,
|
|
44
|
+
unknown_flag: (said) => `Drive's ${said} takes no such flag.`,
|
|
45
|
+
flag_value: (said) => `Give \`--${said}\` a value.`,
|
|
46
|
+
no_name: () => 'Give `click` the element’s accessible name: `--name "Delete path…"`.',
|
|
47
|
+
role_without_name: () => '`--role` narrows `--name`: give the name too.',
|
|
48
|
+
bad_role: (said) => `Drive knows no ${said} role.`,
|
|
49
|
+
no_text: () => 'Give `type` its text.',
|
|
50
|
+
no_key: () => 'Give `key` the key to press.',
|
|
51
|
+
bad_key: (said) => `Drive can't press ${said}: name it as Playwright does, such as Enter or Meta+k.`,
|
|
52
|
+
no_file: (said) => `Give \`${said}\` its file.`,
|
|
53
|
+
bad_file: (said) => `\`${said}\` saves a ${DRIVE_FILES[said] ?? ''} file: name it so.`,
|
|
54
|
+
extra: (said) => `Drive's ${said} takes nothing more.`,
|
|
55
|
+
};
|
|
56
|
+
const FLAGS = {
|
|
57
|
+
click: ['name', 'role'],
|
|
58
|
+
type: [],
|
|
59
|
+
key: [],
|
|
60
|
+
snapshot: ['name', 'role'],
|
|
61
|
+
screenshot: [],
|
|
62
|
+
record: [],
|
|
63
|
+
stop: [],
|
|
64
|
+
};
|
|
65
|
+
const no = (refusal, said = '') => ({
|
|
66
|
+
ok: false,
|
|
67
|
+
refusal,
|
|
68
|
+
says: DRIVE_USAGE_WORDS[refusal](said),
|
|
69
|
+
});
|
|
70
|
+
function commandOf(verb, positional, values) {
|
|
71
|
+
const name = values.get('name') ?? null;
|
|
72
|
+
const roleSaid = values.get('role');
|
|
73
|
+
if (roleSaid !== undefined && !isDriveRole(roleSaid))
|
|
74
|
+
return no('bad_role', roleSaid);
|
|
75
|
+
const role = roleSaid ?? null;
|
|
76
|
+
if (role && !name)
|
|
77
|
+
return no('role_without_name');
|
|
78
|
+
const one = positional.length === 1 ? positional[0] : null;
|
|
79
|
+
if (positional.length > 1 || (positional.length === 1 && ['click', 'snapshot', 'stop'].includes(verb)))
|
|
80
|
+
return no('extra', verb);
|
|
81
|
+
switch (verb) {
|
|
82
|
+
case 'click':
|
|
83
|
+
return name ? { command: 'click', name, role } : no('no_name');
|
|
84
|
+
case 'snapshot':
|
|
85
|
+
return { command: 'snapshot', name, role };
|
|
86
|
+
case 'type':
|
|
87
|
+
return one ? { command: 'type', text: one } : no('no_text');
|
|
88
|
+
case 'key':
|
|
89
|
+
if (!one)
|
|
90
|
+
return no('no_key');
|
|
91
|
+
return isDriveKey(one) ? { command: 'key', key: one } : no('bad_key', one);
|
|
92
|
+
case 'screenshot':
|
|
93
|
+
case 'record':
|
|
94
|
+
if (!one)
|
|
95
|
+
return no('no_file', verb);
|
|
96
|
+
return one.toLowerCase().endsWith(DRIVE_FILES[verb]) && one.length > DRIVE_FILES[verb].length
|
|
97
|
+
? { command: verb, file: one }
|
|
98
|
+
: no('bad_file', verb);
|
|
99
|
+
case 'stop':
|
|
100
|
+
return { command: 'stop' };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export function parseDrive(argv) {
|
|
104
|
+
const [verb, ...rest] = argv;
|
|
105
|
+
if (verb === undefined || verb.startsWith('--'))
|
|
106
|
+
return no('no_command');
|
|
107
|
+
if (!isDriveVerb(verb))
|
|
108
|
+
return no('unknown_command', verb);
|
|
109
|
+
const positional = [];
|
|
110
|
+
const values = new Map();
|
|
111
|
+
let json = false;
|
|
112
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
113
|
+
const arg = rest[i];
|
|
114
|
+
if (!arg.startsWith('--')) {
|
|
115
|
+
positional.push(arg);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const equals = arg.indexOf('=');
|
|
119
|
+
const flag = arg.slice(2, equals === -1 ? undefined : equals);
|
|
120
|
+
if (flag === 'json' && equals === -1) {
|
|
121
|
+
json = true;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (!FLAGS[verb].includes(flag))
|
|
125
|
+
return no('unknown_flag', `${verb} --${flag}`);
|
|
126
|
+
if (equals === -1)
|
|
127
|
+
i += 1;
|
|
128
|
+
const value = (equals === -1 ? rest[i] : arg.slice(equals + 1))?.trim();
|
|
129
|
+
if (!value || value.startsWith('--'))
|
|
130
|
+
return no('flag_value', flag);
|
|
131
|
+
values.set(flag, value);
|
|
132
|
+
}
|
|
133
|
+
const command = commandOf(verb, positional, values);
|
|
134
|
+
return 'ok' in command ? command : { ok: true, command, json };
|
|
135
|
+
}
|
|
136
|
+
export function driveArgv(c) {
|
|
137
|
+
const role = (r) => (r ? ['--role', r] : []);
|
|
138
|
+
switch (c.command) {
|
|
139
|
+
case 'click':
|
|
140
|
+
return ['click', '--name', c.name, ...role(c.role)];
|
|
141
|
+
case 'snapshot':
|
|
142
|
+
return ['snapshot', ...(c.name ? ['--name', c.name] : []), ...role(c.role)];
|
|
143
|
+
case 'type':
|
|
144
|
+
return ['type', c.text];
|
|
145
|
+
case 'key':
|
|
146
|
+
return ['key', c.key];
|
|
147
|
+
case 'screenshot':
|
|
148
|
+
case 'record':
|
|
149
|
+
return [c.command, c.file];
|
|
150
|
+
case 'stop':
|
|
151
|
+
return ['stop'];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
export function stepCommand(step) {
|
|
155
|
+
if (step.click !== undefined)
|
|
156
|
+
return { command: 'click', name: step.click, role: step.role ?? null };
|
|
157
|
+
if (step.type !== undefined)
|
|
158
|
+
return { command: 'type', text: step.type };
|
|
159
|
+
if (step.key !== undefined)
|
|
160
|
+
return { command: 'key', key: step.key };
|
|
161
|
+
return { command: 'snapshot', name: step.snapshot, role: step.role ?? null };
|
|
162
|
+
}
|
|
163
|
+
export const DRIVE_FAILURES = [
|
|
164
|
+
'usage',
|
|
165
|
+
'not_found',
|
|
166
|
+
'ambiguous',
|
|
167
|
+
'not_running',
|
|
168
|
+
'timed_out',
|
|
169
|
+
'crashed',
|
|
170
|
+
];
|
|
171
|
+
export const DRIVE_EXIT = { done: 0, failed: 1, usage: 2 };
|
|
172
|
+
export const exitOf = (r) => r.ok ? DRIVE_EXIT.done : r.failure === 'usage' ? DRIVE_EXIT.usage : DRIVE_EXIT.failed;
|
|
173
|
+
export const DRIVE_FAILURE_WORDS = {
|
|
174
|
+
not_found: (name) => `Nothing on screen is named ${name ? `“${name}”` : 'that'}.`,
|
|
175
|
+
ambiguous: (name) => `More than one element is named ${name ? `“${name}”` : 'that'}: give \`--role\` to say which.`,
|
|
176
|
+
not_running: () => 'The app isn’t running: drive starts it with its first command.',
|
|
177
|
+
timed_out: (name) => `${name ? `“${name}”` : 'It'} didn’t answer in time.`,
|
|
178
|
+
crashed: () => 'The app stopped while drive was using it.',
|
|
179
|
+
};
|
|
180
|
+
export function driveResultText(r) {
|
|
181
|
+
if (!r.ok)
|
|
182
|
+
return `${r.says}\n`;
|
|
183
|
+
if (r.tree !== null)
|
|
184
|
+
return r.tree.endsWith('\n') ? r.tree : `${r.tree}\n`;
|
|
185
|
+
if (r.file !== null)
|
|
186
|
+
return `Saved ${r.file}.\n`;
|
|
187
|
+
return '';
|
|
188
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import type { Loaded } from './config.ts';
|
|
3
|
+
import { type FeatureMap } from './map.ts';
|
|
4
|
+
import type { FileFindings } from './plugin/types.ts';
|
|
5
|
+
import { type ReachScript } from './reach.ts';
|
|
6
|
+
export type ReachLoad = {
|
|
7
|
+
ok: true;
|
|
8
|
+
script: ReachScript;
|
|
9
|
+
} | {
|
|
10
|
+
ok: false;
|
|
11
|
+
says: string;
|
|
12
|
+
};
|
|
13
|
+
export interface Feature {
|
|
14
|
+
name: string;
|
|
15
|
+
folder: string;
|
|
16
|
+
reach: ReachLoad | null;
|
|
17
|
+
}
|
|
18
|
+
export declare const READ_MS = 30000;
|
|
19
|
+
export declare function featureFolders(config: Loaded): string[];
|
|
20
|
+
export declare function proofsOf(config: Loaded, folder: string): string[];
|
|
21
|
+
export declare const READ_WORDS: {
|
|
22
|
+
readonly timedOut: (file: string, seconds?: number) => string;
|
|
23
|
+
readonly noNode: (file: string, why: string) => string;
|
|
24
|
+
readonly stopped: (file: string, said: string) => string;
|
|
25
|
+
readonly sameName: (name: string, folder: string) => string;
|
|
26
|
+
};
|
|
27
|
+
export declare function unread(run: Pick<ReturnType<typeof spawnSync>, 'error' | 'stderr'>, file: string, readMs?: number): string;
|
|
28
|
+
export declare function readReaches(config: Loaded, folders: readonly string[], readMs?: number): Map<string, ReachLoad | null>;
|
|
29
|
+
export declare function featuresOf(config: Loaded): Feature[];
|
|
30
|
+
export declare function unreadText(features: readonly Feature[]): string;
|
|
31
|
+
export declare function buildMap(config: Loaded, features?: readonly Feature[]): FeatureMap;
|
|
32
|
+
export declare function withReachBreaks(config: Loaded, files: Record<string, FileFindings>, features?: readonly Feature[]): Record<string, FileFindings>;
|