@uipath/skills 1.206.0 → 1.206.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/CODEOWNERS +34 -7
- package/README.md +2 -2
- package/package.json +2 -2
- package/skills/uipath-genome/SKILL.md +35 -88
- package/skills/uipath-genome/references/build-guide.md +61 -0
- package/skills/uipath-genome/references/completion-report-guide.md +93 -0
- package/skills/uipath-genome/references/composite-interactions-guide.md +39 -0
- package/skills/uipath-genome/references/configuration-questions-guide.md +68 -0
- package/skills/uipath-genome/references/execution-guide.md +45 -166
- package/skills/uipath-genome/references/execution-parts-guide.md +84 -17
- package/skills/uipath-genome/references/genome-reading-guide.md +153 -0
- package/skills/uipath-genome/references/live-application-guide.md +23 -9
- package/skills/uipath-genome/references/offline-definition-workarounds-guide.md +4 -4
- package/skills/uipath-genome/references/open-items-guide.md +3 -3
- package/skills/uipath-genome/references/package-doc-errata-guide.md +8 -0
- package/skills/uipath-genome/references/refactor-guide.md +38 -39
- package/skills/uipath-genome/references/selector-matching-guide.md +59 -0
- package/skills/uipath-genome/references/selector-translation-guide.md +13 -66
- package/skills/uipath-genome/references/selector-translation-sap-guide.md +7 -5
- package/skills/uipath-genome/references/selector-translation-web-guide.md +2 -2
- package/skills/uipath-genome/references/source-frameworks-guide.md +21 -0
- package/skills/uipath-genome/references/source-migration-guide.md +48 -19
- package/skills/uipath-genome/references/test-execution-guide.md +8 -7
- package/skills/uipath-genome/references/transactional-execution-guide.md +41 -13
- package/skills/uipath-genome/references/ui-target-migration-guide.md +12 -49
- package/skills/uipath-genome/references/ui-verification-guide.md +9 -1
- package/skills/uipath-maestro-case/SKILL.md +7 -7
- package/skills/uipath-maestro-case/references/evals/evals.json +5 -5
- package/skills/uipath-maestro-case/references/planning.md +5 -5
- package/skills/uipath-maestro-case/references/plugins/conditions/task-entry-conditions/planning.md +2 -2
- package/skills/uipath-maestro-case/references/plugins/sla/planning.md +1 -1
- package/skills/uipath-maestro-case/references/registry-discovery.md +3 -3
- package/skills/uipath-planner/SKILL.md +80 -199
- package/skills/uipath-planner/assets/templates/agent-sdd-template.md +17 -17
- package/skills/uipath-planner/assets/templates/api-workflow-sdd-template.md +15 -13
- package/skills/uipath-planner/assets/templates/bpmn-sdd-template.md +19 -19
- package/skills/uipath-planner/assets/templates/case-sdd-task-details-template.md +173 -0
- package/skills/uipath-planner/assets/templates/{case/case-sdd-template.md → case-sdd-template.md} +51 -229
- package/skills/uipath-planner/assets/templates/coded-app-sdd-template.md +16 -14
- package/skills/{uipath-genome → uipath-planner}/assets/templates/component-genome-template.md +9 -5
- package/skills/uipath-planner/assets/templates/flow-sdd-template.md +17 -15
- package/skills/{uipath-genome → uipath-planner}/assets/templates/process-genome-template.md +11 -7
- package/skills/uipath-planner/assets/templates/rpa-sdd-template.md +50 -73
- package/skills/uipath-planner/references/author/author-guide.md +119 -0
- package/skills/uipath-planner/references/author/genome-from-sdd-guide.md +36 -0
- package/skills/uipath-planner/references/author/scenario-proposal-guide.md +30 -0
- package/skills/uipath-planner/references/decompose/decompose-guide.md +223 -0
- package/skills/uipath-planner/references/{asdd-crosswalk-guide.md → design/asdd-crosswalk-guide.md} +6 -4
- package/skills/uipath-planner/references/{business-rules-guide.md → design/business-rules-guide.md} +3 -3
- package/skills/uipath-planner/references/design/caller-request-guide.md +92 -0
- package/skills/uipath-planner/references/design/case-data-and-time-guide.md +292 -0
- package/skills/uipath-planner/references/design/case-product-guide.md +243 -0
- package/skills/uipath-planner/references/design/case-review-and-conformance-guide.md +166 -0
- package/skills/uipath-planner/references/design/design-guide.md +296 -0
- package/skills/uipath-planner/references/{package-selection-guide.md → design/package-selection-guide.md} +16 -13
- package/skills/uipath-planner/references/{rpa-product-guide.md → design/rpa-product-guide.md} +23 -53
- package/skills/uipath-planner/references/design/scope-recommendation-guide.md +134 -0
- package/skills/uipath-planner/references/design/sdd-writing-guide.md +235 -0
- package/skills/uipath-planner/references/design/solution-composition-guide.md +153 -0
- package/skills/uipath-planner/references/edit/edit-guide.md +66 -0
- package/skills/uipath-planner/references/extract/extract-guide.md +230 -0
- package/skills/uipath-planner/references/extract/source-frameworks-guide.md +22 -0
- package/skills/uipath-planner/references/extract/uipath-non-rpa-signals-guide.md +121 -0
- package/skills/uipath-planner/references/extract/uipath-rpa-signals-guide.md +88 -0
- package/skills/uipath-planner/references/extract/uipath-source-guide.md +193 -0
- package/skills/uipath-planner/references/shared/component-placement-guide.md +99 -0
- package/skills/{uipath-genome/references → uipath-planner/references/shared}/defect-verification-guide.md +4 -4
- package/skills/{uipath-genome/references → uipath-planner/references/shared}/extracted-genome-guide.md +15 -14
- package/skills/uipath-planner/references/shared/extraction-parts-guide.md +66 -0
- package/skills/{uipath-genome/references → uipath-planner/references/shared}/genome-format-guide.md +63 -34
- package/skills/uipath-planner/references/{multi-skill-patterns-guide.md → shared/multi-skill-patterns-guide.md} +28 -27
- package/skills/uipath-planner/references/{pdd-analysis-guide.md → shared/pdd-analysis-guide.md} +27 -72
- package/skills/uipath-planner/references/{plan-and-tasks-format.md → shared/plan-and-tasks-format.md} +43 -67
- package/skills/uipath-planner/references/{platform-availability-guide.md → shared/platform-availability-guide.md} +56 -1
- package/skills/uipath-planner/references/shared/product-selection-guide.md +202 -0
- package/skills/{uipath-genome/references → uipath-planner/references/shared}/skill-mapping-guide.md +24 -4
- package/skills/uipath-planner/references/{tenant-library-search-guide.md → shared/tenant-library-search-guide.md} +10 -8
- package/skills/{uipath-genome/references → uipath-planner/references/shared}/transactional-shape-guide.md +39 -8
- package/skills/uipath-planner/scripts/check-genome.mjs +801 -0
- package/skills/uipath-planner/scripts/sdd-fingerprint.mjs +71 -0
- package/skills/uipath-planner/scripts/sdd-to-docx.mjs +87 -0
- package/skills/uipath-test/SKILL.md +3 -3
- package/version-manifest.json +1 -1
- package/skills/uipath-genome/CLAUDE.md +0 -85
- package/skills/uipath-genome/assets/examples/artemis-2-mission-monitor-genome.md +0 -126
- package/skills/uipath-genome/assets/examples/classify-document-and-create-validation-genome.md +0 -117
- package/skills/uipath-genome/assets/examples/invoice-processing-genome/exception-triage-agent-genome.md +0 -96
- package/skills/uipath-genome/assets/examples/invoice-processing-genome/invoice-extraction-genome.md +0 -128
- package/skills/uipath-genome/assets/examples/invoice-processing-genome/invoice-orchestration-genome.md +0 -115
- package/skills/uipath-genome/assets/examples/invoice-processing-genome.md +0 -136
- package/skills/uipath-genome/assets/examples/purchase-requisition-entry-genome.md +0 -224
- package/skills/uipath-genome/assets/examples/salesforce-accounts-and-contacts-genome.md +0 -151
- package/skills/uipath-genome/references/authoring-guide.md +0 -98
- package/skills/uipath-genome/references/editing-guide.md +0 -57
- package/skills/uipath-genome/references/extraction-guide.md +0 -166
- package/skills/uipath-genome/references/extraction-parts-guide.md +0 -45
- package/skills/uipath-genome/references/parts-guide.md +0 -22
- package/skills/uipath-genome/references/uipath-source-guide.md +0 -404
- package/skills/uipath-genome/scripts/check-genome.py +0 -670
- package/skills/uipath-planner/assets/templates/case/sdd-viewer.html +0 -1530
- package/skills/uipath-planner/references/case/case-design-lane-guide.md +0 -327
- package/skills/uipath-planner/references/case/case-design-layers-guide.md +0 -503
- package/skills/uipath-planner/references/case/case-sdd-conformance-checklist.md +0 -123
- package/skills/uipath-planner/references/non-pdd-lane-guide.md +0 -196
- package/skills/uipath-planner/references/pdd-driven-lane-guide.md +0 -210
- package/skills/uipath-planner/references/product-selection-guide.md +0 -673
- package/skills/uipath-planner/references/sdd-generation-guide.md +0 -613
- package/skills/uipath-planner/scripts/docx-extract.ps1 +0 -59
- package/skills/uipath-planner/scripts/docx-extract.sh +0 -54
- package/skills/uipath-planner/scripts/sdd-to-docx.ps1 +0 -74
- package/skills/uipath-planner/scripts/sdd-to-docx.sh +0 -76
- /package/skills/uipath-planner/references/{attended-reauth-pattern-guide.md → design/attended-reauth-pattern-guide.md} +0 -0
|
@@ -0,0 +1,801 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Checks a genome, and its Source Map's step tables against the source export. Node >= 20, built-ins only.
|
|
3
|
+
//
|
|
4
|
+
// Usage:
|
|
5
|
+
// check-genome.mjs component <genome.md> [--profile core|strict] [--expect TOKEN ...] [--source-map TOKEN ...]
|
|
6
|
+
// check-genome.mjs process <genome.md> [--profile core|strict] [--skills SKILL ...] [--expect TOKEN ...]
|
|
7
|
+
// check-genome.mjs tokens <pattern> --expect TOKEN ... [--min FRACTION] [--files N]
|
|
8
|
+
// check-genome.mjs skills JSON of the skill names a genome may cite: build and operate
|
|
9
|
+
// check-genome.mjs -h | --help
|
|
10
|
+
// component and process also take: [--shape transactional|stub [--flows N] [--unit TOKEN ...]]
|
|
11
|
+
// [--shape-checks gate|advisory] advisory: Transactional Shape findings
|
|
12
|
+
// are graded by the strict profile only (a task that tests something else)
|
|
13
|
+
// [--processes <inventory.json> --recordsets <recordsets.json>]
|
|
14
|
+
//
|
|
15
|
+
// uipath-planner runs it with --profile strict after `author`, `extract` and `edit`, and for `check`. An
|
|
16
|
+
// extraction through the framework migration pack adds the two files the pack's `data` command writes. The
|
|
17
|
+
// genome tasks grade with this file.
|
|
18
|
+
//
|
|
19
|
+
// Profiles:
|
|
20
|
+
// core the genome contract a smoke test gates on: level and preamble, every section, valid skill names,
|
|
21
|
+
// steps and criteria present, a Transactional Shape that is the stub or has flows that each name their
|
|
22
|
+
// unit of work, Source Map tokens, expected facts; in an extracted genome (one with a Source Map), a
|
|
23
|
+
// `### Steps` table with exactly one row per Workflow step.
|
|
24
|
+
// strict core plus every mechanical rule of the genome format, the transactional shape and the extracted
|
|
25
|
+
// genome's Source Map: behavioural wording (no code-level tokens), configuration question kind
|
|
26
|
+
// and default, bold step names, numbered acceptance criteria, the As-is table, exactly the outcome
|
|
27
|
+
// rows the transactional shape allows, split options named by letter with only their Requires and Changes cells,
|
|
28
|
+
// complete for every unit and alternative unit, a `Decided:` project chain on option B only and naming two
|
|
29
|
+
// or more projects, retry and consecutive-failure stop; step table cells
|
|
30
|
+
// holding references only; no H2 heading twice; no component genome linked twice; the `Source framework`
|
|
31
|
+
// row in the Source Map of a process or standalone component genome; a `Designed in:` line carrying its
|
|
32
|
+
// `sdd-sha256` fingerprint, linking an SDD that can be read (a solution root with every child SDD it
|
|
33
|
+
// lists) and still has that fingerprint.
|
|
34
|
+
//
|
|
35
|
+
// Export check (--processes and --recordsets, both required together):
|
|
36
|
+
// --processes a list of {"id", "name", "recordset" (name or null), "calls": [{"calleeId", "recordset"}]}
|
|
37
|
+
// --recordsets a list of {"id", "name"}; an entry with "drives": false is provenance, never a data set
|
|
38
|
+
// In every step table: each source object is `Name` (id) with the id a process of that name, each data set
|
|
39
|
+
// `Name` (id) with the id a data set of that name, and every row names at least one source object. A library
|
|
40
|
+
// step's process that no built root reaches while a same-named copy is reachable is the wrong copy; a library
|
|
41
|
+
// workflow nothing in the genome calls is a NOTE. The check reads no prose and derives nothing.
|
|
42
|
+
//
|
|
43
|
+
// <genome.md> and <pattern> may be a quoted glob ("*-genome.md"): the file name is the agent's choice, only the
|
|
44
|
+
// -genome.md suffix is a contract. component and process need exactly one match; tokens searches every match,
|
|
45
|
+
// case-sensitively, like a file_contains criterion.
|
|
46
|
+
//
|
|
47
|
+
// Options take `--flag value` or `--flag=value`. Input files are read as strict UTF-8; a missing, unreadable or
|
|
48
|
+
// invalid input file is a FAIL line.
|
|
49
|
+
//
|
|
50
|
+
// Exit 0 when every check passes; exit 1 with one line per failure; exit 2 on a usage error.
|
|
51
|
+
|
|
52
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
53
|
+
import { dirname, join, resolve as resolvePath } from "node:path";
|
|
54
|
+
import { pathToFileURL } from "node:url";
|
|
55
|
+
import { sddFingerprint } from "./sdd-fingerprint.mjs";
|
|
56
|
+
|
|
57
|
+
export const VALID_SKILLS = new Set([
|
|
58
|
+
"uipath-rpa", "uipath-maestro-flow", "uipath-maestro-bpmn", "uipath-maestro-case",
|
|
59
|
+
"uipath-agents", "uipath-functions", "uipath-api-workflow", "uipath-coded-apps",
|
|
60
|
+
"uipath-connector-builder", "uipath-ixp", "uipath-process-mining", "uipath-mcp-servers",
|
|
61
|
+
"uipath-solution", "uipath-human-in-the-loop", "uipath-rules",
|
|
62
|
+
]);
|
|
63
|
+
export const OPERATE_SKILLS = new Set([ // allowed in Platform Dependencies / Deployment, never in Build With or Components
|
|
64
|
+
"uipath-platform", "uipath-tasks", "uipath-test", "uipath-admin", "uipath-insights",
|
|
65
|
+
"uipath-troubleshoot", "uipath-governance", "uipath-review", "uipath-planner", "uipath-aops",
|
|
66
|
+
"uipath-automationhub", "uipath-feedback",
|
|
67
|
+
"uipath-activity-migrator", "uipath-knowledge-bundles", "uipath-vertical-solutions",
|
|
68
|
+
]);
|
|
69
|
+
const RETIRED_SKILLS = ["uipath-rpa-workflows", "uipath-coded-workflows", "uipath-coded-agents"];
|
|
70
|
+
// the skill a genome's preamble routes its build to
|
|
71
|
+
export const BUILDER = "uipath-genome";
|
|
72
|
+
const routesToBuilder = (s) => /\buipath-genome(?![\w-])/.test(s);
|
|
73
|
+
|
|
74
|
+
export const COMPONENT_SECTIONS = [
|
|
75
|
+
"Overview", "Target Applications", "Build With", "Platform Dependencies", "Interface",
|
|
76
|
+
"Configuration Questions", "Workflow", "Business Rules", "Error Handling",
|
|
77
|
+
"Transactional Shape", "Acceptance Criteria", "Complexity", "Tags",
|
|
78
|
+
];
|
|
79
|
+
export const PROCESS_SECTIONS = [
|
|
80
|
+
"Overview", "Actors and Systems", "Components", "Process Map", "Handoffs",
|
|
81
|
+
"Platform Dependencies", "Configuration Questions", "Business Rules",
|
|
82
|
+
"Error Handling and Recovery", "Transactional Shape", "Acceptance Criteria", "Deployment",
|
|
83
|
+
"Complexity", "Tags",
|
|
84
|
+
];
|
|
85
|
+
// Code-level tokens that must not appear in the genome body (Source Map excluded).
|
|
86
|
+
const BANNED_BODY_TOKENS = [
|
|
87
|
+
"InvokeWorkflowFile", "RetryScope", "TryCatch", "ReadRange", "AppendRange", "WriteRange",
|
|
88
|
+
"GetIMAPMailMessages", "SaveAttachments", "AddQueueItem", "ReadPDFText", "LogMessage",
|
|
89
|
+
"AndAlso", "OrElse", "dt_", "in_", "out_", ".xaml", "core.action", "core.logic",
|
|
90
|
+
"uipath.core.", "activityType", "JsInvoke",
|
|
91
|
+
];
|
|
92
|
+
export const OUTCOME_ROWS = new Set(["Success", "Business exception", "System exception", "Postponed"]);
|
|
93
|
+
// the genome format's minimum Workflow steps and Acceptance Criteria per complexity.
|
|
94
|
+
// core gates only on the floor every genome meets (the simple minimum); the per-complexity minimum is strict.
|
|
95
|
+
const CORE_FLOOR = 3;
|
|
96
|
+
const MIN_STEPS_BY_COMPLEXITY = { simple: 3, medium: 5, complex: 8 };
|
|
97
|
+
const MIN_CRITERIA_BY_COMPLEXITY = { simple: 3, medium: 5, complex: 7 };
|
|
98
|
+
const SPLIT_OPTIONS = ["A", "B", "C"];
|
|
99
|
+
export const SPLIT_COLUMNS = ["unit of work", "option", "requires", "changes against as-is"];
|
|
100
|
+
export const STUB = "Not transactional";
|
|
101
|
+
// a flow with one side outside the genome names it instead of the table
|
|
102
|
+
const EXTERNAL_SIDE = /Split options:(?:\*\*)? none\s*[—–-]+\s*the (consumer|producer) is outside this genome/i;
|
|
103
|
+
// an extracted genome's Source Map step table
|
|
104
|
+
export const STEPS_COLUMNS = ["step", "source objects", "data sets", "captures", "notes"];
|
|
105
|
+
const REFERENCE = /^`([^`]+)`(?:\s*\(((?:[^()`]|`[^`]*`)*)\))?$/; // `Name`, `Name` (id), `Name` (id, locator)
|
|
106
|
+
// The `{…}` placeholders of the genome templates' Transactional Shape sections, a one-word one with the word before it (`with {result}`, `retried {n}`). A genome's own
|
|
107
|
+
// braces — a value built from parts, such as `{item}_{date}` or `INV-{n}` — are content, not a placeholder left
|
|
108
|
+
// unfilled. tests/tasks/uipath-planner/_shared/test_genome_contract.py keeps this list equal to the templates.
|
|
109
|
+
export const TEMPLATE_PLACEHOLDERS = [
|
|
110
|
+
"— {unit}",
|
|
111
|
+
"{a–b}",
|
|
112
|
+
"{c–d}",
|
|
113
|
+
"{unit of work}",
|
|
114
|
+
": {producer}",
|
|
115
|
+
"→ {consumer}",
|
|
116
|
+
"{producer | consumer | consumer of Flow {M}",
|
|
117
|
+
"{one sentence}",
|
|
118
|
+
"one {item}",
|
|
119
|
+
"{identifying field(s)}",
|
|
120
|
+
"{volume and cadence}",
|
|
121
|
+
"{items fail, retry and are reported independently at this level; the reference exists; the retry cost is acceptable}",
|
|
122
|
+
"{other item}",
|
|
123
|
+
"when {condition}",
|
|
124
|
+
"{steps that create items; how often; one source or several; guarded by a lock or ledger?}",
|
|
125
|
+
"{steps that take items; one robot or several; how items are picked; order}",
|
|
126
|
+
"{queue / table / in-memory list / folder}",
|
|
127
|
+
"{status, tags, fields, output}",
|
|
128
|
+
"{parent items, ledgers, locks, tag joins — what each is for; \"none\"}",
|
|
129
|
+
"{one kind, or several routed inside the consumer — what differs}",
|
|
130
|
+
"steps {n}",
|
|
131
|
+
"{p–q}",
|
|
132
|
+
"steps {r}",
|
|
133
|
+
"with {result}",
|
|
134
|
+
"rules: {names}",
|
|
135
|
+
"handlers: {names}",
|
|
136
|
+
"retried {n}",
|
|
137
|
+
"after {m}",
|
|
138
|
+
"{what takes the items}",
|
|
139
|
+
"| {unit}",
|
|
140
|
+
"{what this flow needs for one job to hold both roles — or \"excluded: {the fact that rules it out}",
|
|
141
|
+
"{projects and schedules, where per-item state is visible, retry granularity, end-of-parent work}",
|
|
142
|
+
"{alternative unit}",
|
|
143
|
+
"{facts only — robots, schedules, sources, applications per item kind, whether items survive a run today}",
|
|
144
|
+
"{only when the SDD, the request or the refactor answers already chose the split: option and unit — source; for B, `: <Project> → <Project>[ → …]` when the source names the projects (transactional shape guide rule 8)}",
|
|
145
|
+
"{a, b}",
|
|
146
|
+
"{c, d}",
|
|
147
|
+
"{per-item record and where it lands; screenshot on system exception; run summary}",
|
|
148
|
+
"{reason — the run is one unit of work; one item's work started per item by {caller}",
|
|
149
|
+
"component {p}",
|
|
150
|
+
"component {c}",
|
|
151
|
+
"row {n}",
|
|
152
|
+
"component {d}",
|
|
153
|
+
"row {m}",
|
|
154
|
+
"{component # and steps that create items; how often; one source or several; guarded by a lock or ledger?}",
|
|
155
|
+
"{component # and steps that take items; one robot or several; how items are picked; order}",
|
|
156
|
+
"run: {steps}",
|
|
157
|
+
"item: {steps}",
|
|
158
|
+
"end: {steps}",
|
|
159
|
+
"{component #}",
|
|
160
|
+
"{per-item record and where it lands; the upstream reference a chained item carries; screenshot on system exception; run summary; which component reports on them}",
|
|
161
|
+
"{same block}",
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
const DEFAULTS = {
|
|
165
|
+
profile: "core", expect: [], sourceMap: [], skills: [], shape: null, shapeChecks: "gate", flows: null,
|
|
166
|
+
unit: [], minSteps: 5, minCriteria: 5, min: 1.0, files: null, processes: null, recordsets: null,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/** Collects findings; a strict finding is dropped under the core profile. */
|
|
170
|
+
class Report {
|
|
171
|
+
constructor(profile, shapeGates = true) {
|
|
172
|
+
this.profile = profile;
|
|
173
|
+
this.shapeGates = shapeGates; // --shape-checks advisory: Transactional Shape findings count as strict
|
|
174
|
+
this.errors = [];
|
|
175
|
+
}
|
|
176
|
+
shape(message) { (this.shapeGates ? this.core : this.strict).call(this, message); }
|
|
177
|
+
core(message) { this.errors.push(message); }
|
|
178
|
+
strict(message) { if (this.profile === "strict") this.errors.push(message); }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// --- markdown helpers --------------------------------------------------------------------------
|
|
182
|
+
|
|
183
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
184
|
+
const lines = (s) => s.split("\n");
|
|
185
|
+
const repr = (list) => `[${list.map((x) => `'${x}'`).join(", ")}]`; // a list as the findings have always printed it
|
|
186
|
+
/** A file the checker cannot read: missing, unreadable or not UTF-8. Printed as a FAIL line, never a stack trace. */
|
|
187
|
+
class InputError extends Error {}
|
|
188
|
+
const UTF8 = new TextDecoder("utf-8", { fatal: true });
|
|
189
|
+
/** [bytes, text] of a file, decoded as strict UTF-8. */
|
|
190
|
+
function decode(path) {
|
|
191
|
+
let raw;
|
|
192
|
+
try { raw = readFileSync(path); } catch (e) { throw new InputError(`${posix(String(path))}: cannot be read (${e.code ?? e.message})`); }
|
|
193
|
+
try { return [raw, UTF8.decode(raw)]; } catch { throw new InputError(`${posix(String(path))}: not valid UTF-8`); }
|
|
194
|
+
}
|
|
195
|
+
const read = (path) => decode(path)[1].replace(/\r\n?/g, "\n");
|
|
196
|
+
const posix = (p) => p.replace(/\\/g, "/");
|
|
197
|
+
|
|
198
|
+
function h2Positions(text) {
|
|
199
|
+
const pos = new Map();
|
|
200
|
+
for (const m of text.matchAll(/^## (.+)$/gm)) pos.set(m[1].trim(), m.index);
|
|
201
|
+
return pos;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Position of the first heading that starts with name, any case ('Error Handling and Recovery'
|
|
205
|
+
* counts as 'Error Handling'). The exact heading is a format rule, graded by strict. */
|
|
206
|
+
function sectionPos(pos, name) {
|
|
207
|
+
for (const [h, p] of pos) if (h.toLowerCase().startsWith(name.toLowerCase())) return p;
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function sectionBody(text, heading) {
|
|
212
|
+
const m = text.match(new RegExp(`^## ${esc(heading)}\\b[^\\n]*$([\\s\\S]*?)(?=^## |(?![\\s\\S]))`, "mi"));
|
|
213
|
+
return m ? m[1] : "";
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function complexityOf(text) {
|
|
217
|
+
const m = sectionBody(text, "Complexity").match(/\b(simple|medium|complex)\b/i);
|
|
218
|
+
return m ? m[1].toLowerCase() : null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** strict: a process or standalone component genome's Source Map (one holding a table) has a `Source framework`
|
|
222
|
+
* row in any of its tables (`| Row |` in a component, `| Component |` in a process); a part inherits it. */
|
|
223
|
+
function checkSourceFramework(text, r) {
|
|
224
|
+
const rows = lines(sectionBody(text, "Source Map")).filter((l) => l.trim().startsWith("|")).map(cells);
|
|
225
|
+
const hasFrameworkRow = rows.some((c) => c.length > 1 && c[0].replace(/\*/g, "").trim().toLowerCase() === "source framework");
|
|
226
|
+
if (rows.length && !hasFrameworkRow) r.strict("Source Map has no 'Source framework' row");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const bodyWithoutSourceMap = (text) => text.split(/^## Source Map\s*$/m)[0];
|
|
230
|
+
|
|
231
|
+
const cells = (row) => row.trim().replace(/^\|+|\|+$/g, "").split("|").map((c) => c.trim());
|
|
232
|
+
|
|
233
|
+
/** Data rows of the first markdown table in block whose header row starts with headerStart. */
|
|
234
|
+
export function tableRows(block, headerStart) {
|
|
235
|
+
const ls = lines(block);
|
|
236
|
+
for (let i = 0; i < ls.length; i++) {
|
|
237
|
+
if (!ls[i].trim().startsWith(headerStart)) continue;
|
|
238
|
+
const rows = [];
|
|
239
|
+
for (const row of ls.slice(i + 2)) {
|
|
240
|
+
if (!row.trim().startsWith("|")) break;
|
|
241
|
+
rows.push(cells(row));
|
|
242
|
+
}
|
|
243
|
+
return rows;
|
|
244
|
+
}
|
|
245
|
+
return [];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** [name, body] per '### Flow N' block of the Transactional Shape. */
|
|
249
|
+
function flowBlocks(ts) {
|
|
250
|
+
const parts = ts.split(/^(### Flow\b.*)$/m);
|
|
251
|
+
const out = [];
|
|
252
|
+
for (let i = 1; i < parts.length - 1; i += 2) out.push([parts[i].replace(/^[# ]+/, "").split(":")[0].trim(), parts[i + 1]]);
|
|
253
|
+
return out;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** The numbers of the Workflow's top-level steps, in order. */
|
|
257
|
+
export const workflowSteps = (text) => [...sectionBody(text, "Workflow").matchAll(/^(\d+)\.\s/gm)].map((m) => m[1]);
|
|
258
|
+
|
|
259
|
+
/** [header cells, rows] of the Source Map's `### Steps` table; null when the Source Map has none. */
|
|
260
|
+
function stepsTable(text) {
|
|
261
|
+
const m = sectionBody(text, "Source Map").match(/^### Steps\s*$([\s\S]*?)(?=^#{2,3} |(?![\s\S]))/m);
|
|
262
|
+
if (!m) return null;
|
|
263
|
+
const header = lines(m[1]).find((l) => l.trim().startsWith("|")) ?? "";
|
|
264
|
+
return [cells(header).map((c) => c.toLowerCase()), header ? tableRows(m[1], header.trim()) : []];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The parts of a step table cell, split on '; ' outside backticks and parentheses. */
|
|
268
|
+
function splitReferences(cell) {
|
|
269
|
+
const parts = [];
|
|
270
|
+
let part = "", tick = false, depth = 0;
|
|
271
|
+
for (const ch of cell) {
|
|
272
|
+
if (ch === "`") tick = !tick;
|
|
273
|
+
else if (!tick && (ch === "(" || ch === ")")) depth = ch === "(" ? depth + 1 : Math.max(0, depth - 1);
|
|
274
|
+
if (ch === ";" && !tick && depth === 0) { parts.push(part); part = ""; } else part += ch;
|
|
275
|
+
}
|
|
276
|
+
return [...parts, part].map((p) => p.trim()).filter(Boolean);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** [[name, id or null] per reference, the parts that are no reference] of a step table cell; `none` is empty. */
|
|
280
|
+
function references(cell) {
|
|
281
|
+
if (cell.trim().toLowerCase() === "none") return [[], []];
|
|
282
|
+
const refs = [], prose = [];
|
|
283
|
+
for (const part of splitReferences(cell)) {
|
|
284
|
+
const m = part.match(REFERENCE);
|
|
285
|
+
if (!m) { prose.push(part); continue; }
|
|
286
|
+
const ident = (m[2] ?? "").split(",")[0].trim();
|
|
287
|
+
refs.push([m[1], ident || null]);
|
|
288
|
+
}
|
|
289
|
+
return [refs, prose];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const skillNames = (body) => [...new Set([...body.matchAll(/`(uipath-[a-z-]+)`/g)].map((m) => m[1]))].sort();
|
|
293
|
+
|
|
294
|
+
// --- checks shared by both levels ---------------------------------------------------------------
|
|
295
|
+
|
|
296
|
+
function checkCommon(path, text, level, sections, r, minCriteria) {
|
|
297
|
+
if (!new RegExp(`UIPATH-AUTOMATION-GENOME:\\s*${level}`, "i").test(text)) r.core(`missing preamble comment 'UIPATH-AUTOMATION-GENOME: ${level}'`);
|
|
298
|
+
else if (!text.includes(`UIPATH-AUTOMATION-GENOME: ${level}`)) r.strict(`preamble comment not written exactly 'UIPATH-AUTOMATION-GENOME: ${level}'`);
|
|
299
|
+
if (!/UiPath automation blueprint/i.test(text)) r.core("missing blueprint blockquote");
|
|
300
|
+
else if (!text.includes("This is a UiPath automation blueprint")) r.strict("blueprint blockquote not written as the template words it");
|
|
301
|
+
// the preamble routes the agent to the skill that builds the genome, not to the Build With skills
|
|
302
|
+
const comment = text.match(/<!--\s*UIPATH-AUTOMATION-GENOME[\s\S]*?-->/i);
|
|
303
|
+
if (comment && !routesToBuilder(comment[0])) r.strict(`preamble comment does not name ${BUILDER} as the skill that builds the genome`);
|
|
304
|
+
const blockquote = text.match(/^>.*UiPath automation blueprint.*$/im);
|
|
305
|
+
if (blockquote && !routesToBuilder(blockquote[0])) r.strict(`blueprint blockquote does not name ${BUILDER} as the skill that builds the genome`);
|
|
306
|
+
const designedIn = text.match(/^>\s*Designed in:[^\n]*/m);
|
|
307
|
+
if (designedIn && !/\bsdd-sha256\s+[0-9a-f]{64}\b/.test(designedIn[0])) r.strict("Designed in: line has no sdd-sha256 fingerprint");
|
|
308
|
+
checkDesignedIn(path, text, r);
|
|
309
|
+
const pos = h2Positions(text);
|
|
310
|
+
const headings = [...text.matchAll(/^## (.+)$/gm)].map((m) => m[1].trim());
|
|
311
|
+
for (const h of new Set(headings.filter((h, i) => headings.indexOf(h) !== i))) r.strict(`heading '## ${h}' appears more than once`);
|
|
312
|
+
for (const s of sections) {
|
|
313
|
+
if (sectionPos(pos, s) === null) r.core(`missing section '## ${s}'`);
|
|
314
|
+
else if (!pos.has(s)) r.strict(`section '## ${s}' present under a longer or differently cased heading`);
|
|
315
|
+
}
|
|
316
|
+
for (const name of [...RETIRED_SKILLS].sort()) if (text.includes(name)) r.core(`retired skill name '${name}' present`);
|
|
317
|
+
// skill names are read where a genome names skills; elsewhere `uipath-…` is also an Integration
|
|
318
|
+
// Service connector key (`uipath-slack`, `uipath-salesforce-sfdc`), not a skill
|
|
319
|
+
for (const heading of ["Build With", "Components"]) {
|
|
320
|
+
for (const name of skillNames(sectionBody(text, heading))) {
|
|
321
|
+
if (!VALID_SKILLS.has(name) && !OPERATE_SKILLS.has(name) && name !== BUILDER) r.core(`unknown skill name '${name}' in ${heading}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
for (const heading of ["Build With", "Components"]) {
|
|
325
|
+
for (const name of skillNames(sectionBody(text, heading))) {
|
|
326
|
+
// advisory: a platform row in Build With does no harm — the
|
|
327
|
+
// resources still reach the target through the solution and the open-items files
|
|
328
|
+
if (OPERATE_SKILLS.has(name)) r.strict(`operate-only skill '${name}' in ${heading}; it belongs under Platform Dependencies`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
// a criterion is a list item in any form: '- ', '- [ ] ', '* ' or '1. '; the genome format numbers them
|
|
332
|
+
const criteria = lines(sectionBody(text, "Acceptance Criteria")).filter((l) => /^(?:[-*]|\d+\.) \S/.test(l));
|
|
333
|
+
if (criteria.length < CORE_FLOOR) r.core(`acceptance criteria: ${criteria.length} found, expected >= ${CORE_FLOOR}`);
|
|
334
|
+
else if (criteria.length < minCriteria) r.strict(`acceptance criteria: ${criteria.length} found, expected >= ${minCriteria} for the stated complexity`);
|
|
335
|
+
if (criteria.some((l) => !/^\d+\. /.test(l))) r.strict("acceptance criteria are not numbered ('1. …'), so a report cannot cite them by number");
|
|
336
|
+
for (const line of criteria) if (/completes successfully|handles errors properly/i.test(line)) r.core(`generic acceptance criterion: ${line.trim()}`);
|
|
337
|
+
|
|
338
|
+
const body = bodyWithoutSourceMap(text);
|
|
339
|
+
for (const tok of BANNED_BODY_TOKENS) {
|
|
340
|
+
// a prefix token counts at the start of a word only: `in_Folder`, never "login_page" or "layout_name"
|
|
341
|
+
if (tok.endsWith("_") ? new RegExp(`\\b${esc(tok)}\\w`).test(body) : body.includes(tok)) r.strict(`code-level token '${tok}' in the genome body (outside Source Map)`);
|
|
342
|
+
}
|
|
343
|
+
for (const [, num, question] of sectionBody(text, "Configuration Questions").matchAll(/^(\d+)\. (.*)$/gm)) {
|
|
344
|
+
const pointer = !question.includes("?") && /Configuration Question \d+/.test(question); // a question the process genome asks
|
|
345
|
+
if (!pointer && !/\((setting|constant); default:/.test(question)) r.strict(`configuration question ${num} does not name its kind and default as '(setting; default: …)' or '(constant; default: …)'`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** strict: the SDD a `Designed in:` line links still has the fingerprint the line records. */
|
|
350
|
+
function checkDesignedIn(path, text, r) {
|
|
351
|
+
const m = text.match(DESIGNED_IN);
|
|
352
|
+
if (!m || !m[2]) return;
|
|
353
|
+
let current;
|
|
354
|
+
try { current = sddFingerprint(resolvePath(dirname(path), m[1])); } catch { r.strict(`Designed in: ${m[1]} or a child SDD it lists cannot be read`); return; }
|
|
355
|
+
if (current !== m[2]) r.strict(`Designed in: sdd-sha256 does not match ${m[1]}; the SDD changed since the genome was written`);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** [flows, headed]: the '### Flow N' blocks, or — when there is no such heading but the section names a
|
|
359
|
+
* unit of work — the whole section as one flow. The heading is a format rule; the unit of work is the contract. */
|
|
360
|
+
function effectiveFlows(ts) {
|
|
361
|
+
const blocks = flowBlocks(ts);
|
|
362
|
+
if (blocks.length) return [blocks, true];
|
|
363
|
+
if (/unit of work/i.test(ts)) return [[["Flow 1", ts]], false];
|
|
364
|
+
return [[], false];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const DECIDED_CHAIN = /:\s+([^:]*→[^:]*|[A-Za-z][\w.-]*)\s*$/;
|
|
368
|
+
// project names after the source's last ': ' joined by any chain separator; only ' → ' names a chain
|
|
369
|
+
const DECIDED_LIST = /:\s+([A-Z][\w.-]*(?:\s*(?:→|->|,|\band\b)\s*[A-Z][\w.-]*)+)\s*$/;
|
|
370
|
+
const LIST_SEPARATOR = /\s*(?:→|->|,|\band\b)\s*/g;
|
|
371
|
+
|
|
372
|
+
/** Transactional Shape: the stub, or flow blocks of the transactional shape format. */
|
|
373
|
+
function checkTransactional(text, level, r, partOf = false) {
|
|
374
|
+
const ts = sectionBody(text, "Transactional Shape");
|
|
375
|
+
if (!ts.trim() || ts.trim().startsWith(STUB)) return;
|
|
376
|
+
if (ts.includes("**Recommendation:**") || /^\|\s*(Producer|Consumer)\s*\|/m.test(ts)) r.strict("Transactional Shape carries a verdict (Recommendation line or Producer/Consumer mode table)");
|
|
377
|
+
const [flows, headed] = effectiveFlows(ts);
|
|
378
|
+
if (!flows.length) { r.shape("Transactional Shape is neither the stub nor flows naming their unit of work"); return; }
|
|
379
|
+
if (!headed) r.strict("Transactional Shape describes its flow without '### Flow N' headings");
|
|
380
|
+
// a component reached through a process genome's links is inside it, with or without its 'Part of:' line
|
|
381
|
+
const inProcess = level === "component" && (partOf || text.includes("Part of:"));
|
|
382
|
+
if (!inProcess && !ts.includes("**Flows:**")) r.strict("Transactional Shape has no 'Flows:' line");
|
|
383
|
+
const unfilled = TEMPLATE_PLACEHOLDERS.filter((p) => ts.includes(p));
|
|
384
|
+
if (unfilled.length) {
|
|
385
|
+
const first = unfilled.reduce((a, b) => (ts.indexOf(b) < ts.indexOf(a) ? b : a));
|
|
386
|
+
r.strict(`Transactional Shape leaves a template placeholder unfilled: ${first}`);
|
|
387
|
+
}
|
|
388
|
+
for (const [name, body] of flows) {
|
|
389
|
+
if (inProcess) {
|
|
390
|
+
if (!body.includes("**Role:**")) r.shape(`Transactional Shape ${name}: a component inside a process has no 'Role:' line`);
|
|
391
|
+
if (!body.includes("per the process genome")) r.strict(`Transactional Shape ${name}: does not point to the process genome's split options`);
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (!/unit of work/i.test(body)) r.shape(`Transactional Shape ${name}: names no unit of work`);
|
|
395
|
+
else if (!body.includes("**Unit of work:**")) r.strict(`Transactional Shape ${name}: no '**Unit of work:**' line`);
|
|
396
|
+
const external = body.match(EXTERNAL_SIDE);
|
|
397
|
+
const split = tableRows(body, "| Unit of work | Option |");
|
|
398
|
+
if (!external && !split.length) r.strict(`Transactional Shape ${name}: no Split options table and no 'outside this genome' line`);
|
|
399
|
+
if (!body.includes("| Aspect | As-is |")) r.strict(`Transactional Shape ${name}: no As-is table`);
|
|
400
|
+
const consumerOutside = Boolean(external && external[1].toLowerCase() === "consumer");
|
|
401
|
+
if (!consumerOutside) {
|
|
402
|
+
const rows = tableRows(body, "| Outcome |").filter((row) => row.length).map((row) => row[0]);
|
|
403
|
+
for (const needed of ["Success", "Business exception", "System exception"]) if (!rows.includes(needed)) r.strict(`Transactional Shape ${name}: no '${needed}' outcome row`);
|
|
404
|
+
for (const extra of rows.filter((x) => !OUTCOME_ROWS.has(x))) r.strict(`Transactional Shape ${name}: outcome row '${extra}' — a source's own results map to Success or a Business exception`);
|
|
405
|
+
// the consumer owes the item retry and the consecutive-failure stop
|
|
406
|
+
if (!/retr(y|ie)/i.test(body) || !/consecutive|stops? after \d/i.test(body)) r.strict(`Transactional Shape ${name}: outcomes do not state the item retry and the consecutive-failure stop`);
|
|
407
|
+
}
|
|
408
|
+
if (external) continue;
|
|
409
|
+
const units = new Map();
|
|
410
|
+
for (const row of split) {
|
|
411
|
+
const m = row.length >= 2 ? row[1].match(/^([ABC])\b/) : null;
|
|
412
|
+
if (m) { if (!units.has(row[0])) units.set(row[0], new Set()); units.get(row[0]).add(m[1]); }
|
|
413
|
+
if (row.length >= 2 && !SPLIT_OPTIONS.includes(row[1].trim())) r.strict(`Transactional Shape ${name}: option cell '${row[1]}' of '${row[0]}' holds more than its letter — the transactional shape guide defines A, B and C`);
|
|
414
|
+
}
|
|
415
|
+
// a split the SDD, the request or the refactor answers already took (`**Decided:** B, ...`) lists that option alone, never reopened
|
|
416
|
+
const decidedLine = lines(body).find((l) => l.startsWith("**Decided:**")) ?? "";
|
|
417
|
+
const decided = decidedLine.match(/^\*\*Decided:\*\*\s*([ABC])\b(?:,\s*([^—–]+?))?\s*(?:[—–]\s*(.*)|$)/);
|
|
418
|
+
if (decidedLine && !decided) r.strict(`Transactional Shape ${name}: the 'Decided:' line does not start with the option letter`);
|
|
419
|
+
if (decided) {
|
|
420
|
+
// `<source>: <Project> → <Project> …` — a bare single name after the last ': ' is a one-project chain
|
|
421
|
+
const chain = (decided[3] ?? "").match(DECIDED_CHAIN);
|
|
422
|
+
const list = decided[1] === "B" ? (decided[3] ?? "").match(DECIDED_LIST) : null;
|
|
423
|
+
if (list && list[1].match(LIST_SEPARATOR).some((sep) => sep.trim() !== "→")) {
|
|
424
|
+
r.strict(`Transactional Shape ${name}: the 'Decided:' project chain '${list[1].trim()}' separates its projects with '->', ',' or ' and ' — separate them with ' → '`);
|
|
425
|
+
} else if (chain) {
|
|
426
|
+
const projects = chain[1].split("→").map((p) => p.trim());
|
|
427
|
+
if (decided[1] !== "B") r.strict(`Transactional Shape ${name}: the 'Decided:' line of option ${decided[1]} names a project chain — only option B names its projects`);
|
|
428
|
+
else if (projects.length < 2 || projects.some((p) => !p)) r.strict(`Transactional Shape ${name}: the 'Decided:' project chain '${chain[1].trim()}' does not name two or more projects separated by ' → '`);
|
|
429
|
+
}
|
|
430
|
+
const unit = (decided[2] ?? "").trim();
|
|
431
|
+
const pool = unit && units.has(unit) ? [units.get(unit)] : unit ? [] : [...units.values()];
|
|
432
|
+
if (!pool.some((opts) => opts.has(decided[1]))) r.strict(`Transactional Shape ${name}: decided option ${decided[1]}${unit ? ` of '${unit}'` : ""} has no Split options row`);
|
|
433
|
+
} else {
|
|
434
|
+
for (const [unit, opts] of units) {
|
|
435
|
+
const missing = SPLIT_OPTIONS.filter((o) => !opts.has(o));
|
|
436
|
+
if (missing.length) r.strict(`Transactional Shape ${name}: unit '${unit}' lacks option(s) ${repr(missing)}`);
|
|
437
|
+
}
|
|
438
|
+
const alt = lines(body).find((l) => l.startsWith("**Alternative units of work:**")) ?? "";
|
|
439
|
+
if (alt && !/:\*\*\s*none\b/i.test(alt) && units.size < 2) r.strict(`Transactional Shape ${name}: alternative units of work named but split options cover only one unit`);
|
|
440
|
+
}
|
|
441
|
+
const header = lines(body).find((l) => l.trim().startsWith("| Unit of work | Option |")) ?? "";
|
|
442
|
+
const cols = cells(header).map((c) => c.toLowerCase());
|
|
443
|
+
if (!cols.includes("requires") || !cols.includes("changes against as-is")) {
|
|
444
|
+
r.strict(`Transactional Shape ${name}: Split options table has no Requires and Changes against as-is columns`);
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (cols.join("\u0000") !== SPLIT_COLUMNS.join("\u0000")) r.strict(`Transactional Shape ${name}: Split options columns are ${repr(cols)}, expected Unit of work, Option, Requires, Changes against as-is`);
|
|
448
|
+
const ir = cols.indexOf("requires"), ic = cols.indexOf("changes against as-is");
|
|
449
|
+
for (const row of split) {
|
|
450
|
+
if (row.length > Math.max(ir, ic) && SPLIT_OPTIONS.includes(row[1].slice(0, 1))) {
|
|
451
|
+
if (!row[ir] || !row[ic]) r.strict(`Transactional Shape ${name}: option ${row[1].slice(0, 1)} of '${row[0]}' has an empty Requires or Changes cell`);
|
|
452
|
+
if (/\b(recommended|best option|preferred)\b/i.test(`${row[ir]} ${row[ic]}`)) r.strict(`Transactional Shape ${name}: option ${row[1].slice(0, 1)} of '${row[0]}' ranks the options`);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/** --shape: what the Transactional Shape of this genome must describe. */
|
|
459
|
+
function checkShapeAssertion(text, shape, flows, units, r) {
|
|
460
|
+
const ts = sectionBody(text, "Transactional Shape");
|
|
461
|
+
const stub = ts.trim().startsWith(STUB);
|
|
462
|
+
if (shape === "stub") { if (!stub) r.core("Transactional Shape: expected the 'Not transactional' stub"); return; }
|
|
463
|
+
if (stub) { r.core("Transactional Shape: expected flow blocks, found the stub"); return; }
|
|
464
|
+
const [blocks] = effectiveFlows(ts);
|
|
465
|
+
if (!blocks.length) { r.core("Transactional Shape: expected flows naming their unit of work, found none"); return; }
|
|
466
|
+
if (flows !== null && blocks.length !== flows) r.core(`Transactional Shape: ${blocks.length} flow(s), expected ${flows}`);
|
|
467
|
+
// the primary unit's line only: never the alternatives line or a table header, and whole words ('row', not 'throw')
|
|
468
|
+
const unitLines = lines(ts).filter((l) => /^[*_\s>-]*unit of work\b/i.test(l)).join(" ");
|
|
469
|
+
for (const tok of units) if (!new RegExp(`\\b${esc(tok)}s?\\b`, "i").test(unitLines)) r.core(`Transactional Shape: no 'Unit of work' line names '${tok}'`);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** An extracted genome's step table: one row per Workflow step (core), reference-only cells (strict). */
|
|
473
|
+
function checkStepsTable(text, r) {
|
|
474
|
+
if (!sectionBody(text, "Source Map").trim()) return;
|
|
475
|
+
const table = stepsTable(text);
|
|
476
|
+
if (table === null) { r.core("Source Map has no '### Steps' table pairing each Workflow step with its source objects"); return; }
|
|
477
|
+
const [header, rows] = table;
|
|
478
|
+
if (header.join("\u0000") !== STEPS_COLUMNS.join("\u0000")) r.strict(`step table columns are ${repr(header)}, expected Step, Source objects, Data sets, Captures, Notes`);
|
|
479
|
+
const steps = workflowSteps(text);
|
|
480
|
+
const keys = rows.map((row) => row[0]);
|
|
481
|
+
const count = (k) => keys.filter((x) => x === k).length;
|
|
482
|
+
for (const step of steps) if (count(step) !== 1) r.core(`step table: Workflow step ${step} has ${count(step)} rows, expected exactly one`);
|
|
483
|
+
const orphans = [...new Set(keys)].filter((k) => !steps.includes(k)).sort((a, b) => a.length - b.length || (a < b ? -1 : a > b ? 1 : 0));
|
|
484
|
+
for (const key of orphans) r.core(`step table: row '${key}' names no Workflow step — key a row by the step's number only`);
|
|
485
|
+
for (let row of rows) {
|
|
486
|
+
row = [...row, ...Array(Math.max(0, STEPS_COLUMNS.length - row.length)).fill("")];
|
|
487
|
+
const [sources, prose] = references(row[1]);
|
|
488
|
+
if (!sources.length) r.strict(`step table, step ${row[0]}: no source object`);
|
|
489
|
+
const [data, dataProse] = references(row[2]);
|
|
490
|
+
for (const part of [...prose, ...dataProse]) r.strict(`step table, step ${row[0]}: '${part.slice(0, 60)}' is not a reference — move it to Notes`);
|
|
491
|
+
if (!data.length && row[2].trim().toLowerCase() !== "none") r.strict(`step table, step ${row[0]}: Data sets is empty — write 'none' when the step reads no data set`);
|
|
492
|
+
if (!/^\d+$/.test(row[3])) r.strict(`step table, step ${row[0]}: Captures '${row[3]}' is not a count`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// --- levels -------------------------------------------------------------------------------------
|
|
497
|
+
|
|
498
|
+
/** [link, component genome path, is a library] per row of a process genome's Components table. */
|
|
499
|
+
export function componentLinks(path, text) {
|
|
500
|
+
const out = [];
|
|
501
|
+
for (const row of tableRows(sectionBody(text, "Components"), "| #")) {
|
|
502
|
+
const m = row.join(" | ").match(/\]\(([^)]+-genome\.md)\)/);
|
|
503
|
+
if (m) out.push([m[1], resolvePath(dirname(path), m[1]), row.length > 2 && /\blibrary\b/i.test(row[2])]);
|
|
504
|
+
}
|
|
505
|
+
return out;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function checkComponent(path, a, partOf, shape = true, library = false) {
|
|
509
|
+
const text = read(path);
|
|
510
|
+
// a library is named so in its process genome's Components table, or in its own Transactional Shape stub
|
|
511
|
+
library = library || /^Not transactional:[^\n]*\blibrar(y|ies)\b/i.test(sectionBody(text, "Transactional Shape").trim());
|
|
512
|
+
const r = new Report(a.profile, a.shapeChecks === "gate");
|
|
513
|
+
const level = complexityOf(text);
|
|
514
|
+
const minSteps = MIN_STEPS_BY_COMPLEXITY[level] ?? a.minSteps;
|
|
515
|
+
checkCommon(path, text, "component", COMPONENT_SECTIONS, r, MIN_CRITERIA_BY_COMPLEXITY[level] ?? a.minCriteria);
|
|
516
|
+
const pos = h2Positions(text);
|
|
517
|
+
const bw = sectionPos(pos, "Build With"), wf = sectionPos(pos, "Workflow");
|
|
518
|
+
if (bw !== null && wf !== null && bw > wf) r.core("Build With must precede Workflow");
|
|
519
|
+
if (!/uipath-[a-z-]+/.test(sectionBody(text, "Build With"))) r.core("Build With names no skill");
|
|
520
|
+
const workflow = sectionBody(text, "Workflow");
|
|
521
|
+
const steps = (workflow.match(/^(?:\d+\.|[-*]) \S/gm) ?? []).length; // top-level numbered or bulleted steps
|
|
522
|
+
// a test component's steps are its cases and a library's its public workflows
|
|
523
|
+
const exempt = library || /^\d+\. \*\*Test case:/m.test(workflow);
|
|
524
|
+
if (steps < CORE_FLOOR && !exempt) r.core(`workflow: ${steps} numbered steps, expected >= ${CORE_FLOOR}`);
|
|
525
|
+
else if (steps < minSteps && !exempt) r.strict(`workflow: ${steps} numbered steps, expected >= ${minSteps} for complexity ${level || "not stated"}`);
|
|
526
|
+
if ((workflow.match(/^\d+\. \*\*/gm) ?? []).length < Math.min(steps, minSteps)) r.strict("workflow: steps not all in the '1. **Step name**' form");
|
|
527
|
+
const cq = sectionBody(text, "Configuration Questions");
|
|
528
|
+
const questions = cq.match(/^\d+\. /gm) ?? [];
|
|
529
|
+
if (!cq.trim()) r.core("Configuration Questions section is empty");
|
|
530
|
+
else if (!questions.length && !cq.includes("no configuration needed")) r.strict("Configuration Questions: neither a numbered list of questions nor the stub line");
|
|
531
|
+
if (a.sourceMap.length) {
|
|
532
|
+
const sm = sectionBody(text, "Source Map");
|
|
533
|
+
if (!sm.trim()) r.core("missing or empty '## Source Map' section");
|
|
534
|
+
for (const tok of a.sourceMap) if (!sm.includes(tok)) r.core(`Source Map does not mention '${tok}'`);
|
|
535
|
+
}
|
|
536
|
+
checkStepsTable(text, r);
|
|
537
|
+
if (!partOf && !text.includes("Part of:")) checkSourceFramework(text, r);
|
|
538
|
+
if (partOf && !text.includes("Part of:")) r.strict("component inside a process genome lacks the 'Part of:' line");
|
|
539
|
+
checkTransactional(text, "component", r, partOf);
|
|
540
|
+
if (a.shape && shape) checkShapeAssertion(text, a.shape, a.flows, a.unit, r);
|
|
541
|
+
for (const tok of a.expect) if (!text.toLowerCase().includes(tok.toLowerCase())) r.core(`expected token '${tok}' not found`);
|
|
542
|
+
return r.errors.map((e) => `${baseName(path)}: ${e}`);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
function checkProcess(path, a) {
|
|
546
|
+
const text = read(path);
|
|
547
|
+
const r = new Report(a.profile, a.shapeChecks === "gate");
|
|
548
|
+
checkCommon(path, text, "process", PROCESS_SECTIONS, r, MIN_CRITERIA_BY_COMPLEXITY[complexityOf(text)] ?? a.minCriteria);
|
|
549
|
+
const pos = h2Positions(text);
|
|
550
|
+
const cp = sectionPos(pos, "Components"), pm = sectionPos(pos, "Process Map");
|
|
551
|
+
if (cp !== null && pm !== null && cp > pm) r.core("Components must precede Process Map");
|
|
552
|
+
const comp = sectionBody(text, "Components");
|
|
553
|
+
if (lines(comp).filter((l) => l.startsWith("|") && l.includes("uipath-")).length < 2) r.core("Components table: fewer than 2 rows naming a skill");
|
|
554
|
+
for (const s of a.skills) if (!new RegExp(`\\b${esc(s)}\\b`).test(comp)) r.core(`Components table lacks skill '${s}'`);
|
|
555
|
+
for (const row of tableRows(comp, "| #")) {
|
|
556
|
+
if (row.length > 2 && /\b(dispatcher|performer)\b/i.test(row[2])) r.strict(`Components: role word in the Type cell of '${row[1]}' — it reads the component type only`);
|
|
557
|
+
}
|
|
558
|
+
const links = componentLinks(path, text);
|
|
559
|
+
if (!links.length) r.core("Components table links no component genome");
|
|
560
|
+
const targets = links.map(([, t]) => posix(t).toLowerCase());
|
|
561
|
+
const first = (i) => targets.indexOf(targets[i]) === i;
|
|
562
|
+
for (const [link] of links.filter((_, i) => !first(i))) r.strict(`Components table links ${link} more than once`);
|
|
563
|
+
checkSourceFramework(text, r);
|
|
564
|
+
const componentErrors = [];
|
|
565
|
+
for (const [link, target, isLibrary] of links.filter((_, i) => first(i))) {
|
|
566
|
+
if (!existsSync(target)) r.core(`linked component genome missing on disk: ${link}`);
|
|
567
|
+
else {
|
|
568
|
+
// one unreadable component file is one finding; the process genome and its other components are still checked
|
|
569
|
+
try { componentErrors.push(...checkComponent(target, { ...a, expect: [], sourceMap: [] }, true, false, isLibrary)); }
|
|
570
|
+
catch (e) { if (!(e instanceof InputError)) throw e; r.core(e.message); }
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const handoffs = lines(sectionBody(text, "Handoffs")).filter((l) => l.startsWith("|"));
|
|
574
|
+
if (handoffs.length < 4) r.core(`Handoffs table: ${Math.max(0, handoffs.length - 2)} rows, expected >= 2`); // header + separator + >= 2 rows
|
|
575
|
+
checkTransactional(text, "process", r);
|
|
576
|
+
if (a.shape) checkShapeAssertion(text, a.shape, a.flows, a.unit, r);
|
|
577
|
+
for (const tok of a.expect) if (!text.toLowerCase().includes(tok.toLowerCase())) r.core(`expected token '${tok}' not found`);
|
|
578
|
+
return [...r.errors.map((e) => `${baseName(path)}: ${e}`), ...componentErrors];
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** [failures, notes] of every step table against the export's inventory. Ids are compared as text. */
|
|
582
|
+
export function checkExport(genomes, processes, recordsets) {
|
|
583
|
+
const byId = new Map(processes.map((p) => [String(p.id), p]));
|
|
584
|
+
const byName = new Map();
|
|
585
|
+
for (const p of processes) {
|
|
586
|
+
const key = p.name.toLowerCase();
|
|
587
|
+
if (!byName.has(key)) byName.set(key, []);
|
|
588
|
+
byName.get(key).push(p);
|
|
589
|
+
}
|
|
590
|
+
const data = new Map(recordsets.map((d) => [String(d.id), d]));
|
|
591
|
+
const errors = [], notes = [], used = [];
|
|
592
|
+
for (const [path, isLibrary] of genomes) {
|
|
593
|
+
const table = existsSync(path) ? stepsTable(read(path)) : null;
|
|
594
|
+
for (let row of table ? table[1] : []) {
|
|
595
|
+
row = [...row, ...Array(Math.max(0, STEPS_COLUMNS.length - row.length)).fill("")];
|
|
596
|
+
const where = `${baseName(path)} step ${row[0]}`;
|
|
597
|
+
const [sources] = references(row[1]);
|
|
598
|
+
if (!sources.length) errors.push(`${where}: no source object`);
|
|
599
|
+
for (const [name, ident] of sources) {
|
|
600
|
+
const p = byId.get(ident ?? "");
|
|
601
|
+
if (ident === null) errors.push(`${where}: \`${name}\` has no id — cite it as \`Name\` (id)`);
|
|
602
|
+
else if (p === undefined) errors.push(`${where}: \`${name}\` (${ident}) is no process of the export${data.has(ident) ? " — it is a data set: move it to Data sets" : ""}`);
|
|
603
|
+
else if (p.name.toLowerCase() !== name.toLowerCase()) errors.push(`${where}: id ${ident} is \`${p.name}\`, the row says \`${name}\``);
|
|
604
|
+
else used.push([where, isLibrary, p]);
|
|
605
|
+
}
|
|
606
|
+
for (const [name, ident] of references(row[2])[0]) {
|
|
607
|
+
const d = data.get(ident ?? "");
|
|
608
|
+
if (ident === null) errors.push(`${where}: data set \`${name}\` has no id — cite it as \`Name\` (id)`);
|
|
609
|
+
else if (d === undefined) errors.push(`${where}: data set \`${name}\` (${ident}) is no data set of the export${byId.has(ident) ? " — it is a process: move it to Source objects" : ""}`);
|
|
610
|
+
else if (d.drives === false) errors.push(`${where}: \`${name}\` (${ident}) drives nothing (a file the step writes, a URL) — name it in Notes`);
|
|
611
|
+
else if (d.name.toLowerCase() !== name.toLowerCase() && !d.name.toLowerCase().endsWith(`::${name.toLowerCase()}`)) errors.push(`${where}: data set id ${ident} is \`${d.name}\`, the row says \`${name}\``);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
// the built roots: every process a non-library step was built from, and what they call
|
|
616
|
+
const roots = used.filter(([, lib]) => !lib).map(([, , p]) => String(p.id));
|
|
617
|
+
const scope = new Set(roots.length ? roots : byId.keys());
|
|
618
|
+
const frontier = [...scope];
|
|
619
|
+
while (frontier.length) {
|
|
620
|
+
for (const c of byId.get(frontier.pop())?.calls ?? []) {
|
|
621
|
+
const callee = String(c.calleeId);
|
|
622
|
+
if (!scope.has(callee)) { scope.add(callee); frontier.push(callee); }
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
for (const [where, lib, p] of used) {
|
|
626
|
+
if (lib && !scope.has(String(p.id))) {
|
|
627
|
+
const twins = (byName.get(p.name.toLowerCase()) ?? []).map((q) => String(q.id)).filter((id) => scope.has(id));
|
|
628
|
+
if (twins.length) errors.push(`${where}: \`${p.name}\` (${p.id}) is not reachable from the built roots; the copy they run is ${twins.join(", ")}`);
|
|
629
|
+
else notes.push(`${where}: \`${p.name}\` (${p.id}) is a library workflow no built component calls`);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return [errors, notes];
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
const baseName = (p) => posix(p).split("/").pop();
|
|
636
|
+
|
|
637
|
+
/** Files matching a path or a glob relative to the working directory (`*`, `?`, `**`), sorted. */
|
|
638
|
+
function resolveGlob(pattern) {
|
|
639
|
+
if (existsSync(pattern) || !/[*?[]/.test(pattern)) return existsSync(pattern) ? [pattern] : [];
|
|
640
|
+
const toRe = (seg) => new RegExp(`^${seg.split("").map((c) => (c === "*" ? "[^/]*" : c === "?" ? "[^/]" : esc(c))).join("")}$`);
|
|
641
|
+
let matches = [""];
|
|
642
|
+
for (const seg of posix(pattern).split("/").filter(Boolean)) {
|
|
643
|
+
const next = [];
|
|
644
|
+
for (const base of matches) {
|
|
645
|
+
const dir = base || ".";
|
|
646
|
+
if (seg === "**") {
|
|
647
|
+
const walk = (d, rel) => {
|
|
648
|
+
next.push(rel);
|
|
649
|
+
for (const e of safeList(d)) if (e.isDirectory()) walk(join(d, e.name), rel ? `${rel}/${e.name}` : e.name);
|
|
650
|
+
};
|
|
651
|
+
walk(dir, base);
|
|
652
|
+
} else if (/[*?]/.test(seg)) {
|
|
653
|
+
const re = toRe(seg);
|
|
654
|
+
for (const e of safeList(dir)) if (re.test(e.name)) next.push(base ? `${base}/${e.name}` : e.name);
|
|
655
|
+
} else next.push(base ? `${base}/${seg}` : seg);
|
|
656
|
+
}
|
|
657
|
+
matches = [...new Set(next)];
|
|
658
|
+
}
|
|
659
|
+
return matches.filter((m) => m && existsSync(m) && statSync(m).isFile()).sort();
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function safeList(dir) {
|
|
663
|
+
try { return readdirSync(dir, { withFileTypes: true }); } catch { return []; }
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function checkTokens(paths, tokens, minimum, files) {
|
|
667
|
+
const errors = [];
|
|
668
|
+
if (files !== null && paths.length !== files) errors.push(`${paths.length} file(s) match, expected ${files}: ${paths.map(posix).join(", ") || "none"}`);
|
|
669
|
+
const text = paths.map(read).join("\n");
|
|
670
|
+
const missing = tokens.filter((t) => !text.includes(t));
|
|
671
|
+
if (tokens.length && (tokens.length - missing.length) / tokens.length < minimum) {
|
|
672
|
+
errors.push(`${tokens.length - missing.length}/${tokens.length} tokens found, expected >= ${Math.round(minimum * 100)}%; missing: ${missing.join(", ")}`);
|
|
673
|
+
}
|
|
674
|
+
return errors;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function loadInventory(path, what) {
|
|
678
|
+
if (!existsSync(path)) throw new InputError(`${posix(path)}: the ${what} file does not exist`);
|
|
679
|
+
let data;
|
|
680
|
+
try { data = JSON.parse(decode(path)[1]); } catch (e) {
|
|
681
|
+
if (e instanceof InputError) throw e;
|
|
682
|
+
throw new InputError(`${posix(path)}: the ${what} is not valid JSON (${e.message})`);
|
|
683
|
+
}
|
|
684
|
+
if (!Array.isArray(data) || !data.every((x) => x && typeof x === "object" && "id" in x && "name" in x)) {
|
|
685
|
+
throw new InputError(`${posix(path)}: the ${what} is a list of objects with 'id' and 'name' (regenerate it with the source guide's script)`);
|
|
686
|
+
}
|
|
687
|
+
return data;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const DESIGNED_IN = /^>\s*Designed in:\s*\[[^\]]*\]\(([^)]+)\)(?:[^\n]*?\bsdd-sha256\s+([0-9a-f]{64})\b)?/m;
|
|
691
|
+
|
|
692
|
+
// --- command line -------------------------------------------------------------------------------
|
|
693
|
+
|
|
694
|
+
const USAGE = "usage: check-genome.mjs {component,process,tokens} <genome> [options] | skills";
|
|
695
|
+
const HELP = `${USAGE}
|
|
696
|
+
|
|
697
|
+
component|process <genome> check a genome: [--profile core|strict] [--expect TOKEN ...] [--source-map TOKEN ...]
|
|
698
|
+
[--skills SKILL ...] [--shape transactional|stub] [--flows N] [--unit TOKEN ...]
|
|
699
|
+
[--shape-checks gate|advisory] [--min-steps N] [--min-criteria N]
|
|
700
|
+
[--processes <inventory.json> --recordsets <recordsets.json>]
|
|
701
|
+
tokens <pattern> --expect TOKEN ... [--min FRACTION] [--files N]
|
|
702
|
+
skills JSON of the skill names a genome may cite
|
|
703
|
+
|
|
704
|
+
Options take '--flag value' or '--flag=value'. Exit 0 pass, 1 failures, 2 usage error.`;
|
|
705
|
+
const LIST = { "--expect": "expect", "--source-map": "sourceMap", "--skills": "skills", "--unit": "unit" };
|
|
706
|
+
const VALUE = {
|
|
707
|
+
"--profile": ["profile", ["core", "strict"]], "--shape": ["shape", ["transactional", "stub"]],
|
|
708
|
+
"--shape-checks": ["shapeChecks", ["gate", "advisory"]], "--flows": ["flows", "int"], "--min-steps": ["minSteps", "int"],
|
|
709
|
+
"--min-criteria": ["minCriteria", "int"], "--min": ["min", "float"], "--files": ["files", "int"],
|
|
710
|
+
"--processes": ["processes", "str"], "--recordsets": ["recordsets", "str"],
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
class UsageError extends Error {}
|
|
714
|
+
|
|
715
|
+
function parse(argv) {
|
|
716
|
+
const a = { ...DEFAULTS, expect: [], sourceMap: [], skills: [], unit: [] };
|
|
717
|
+
const positional = [];
|
|
718
|
+
for (let i = 0; i < argv.length; i++) {
|
|
719
|
+
let arg = argv[i], inline = null;
|
|
720
|
+
const eq = arg.startsWith("--") ? arg.indexOf("=") : -1;
|
|
721
|
+
if (eq > 2) [arg, inline] = [arg.slice(0, eq), arg.slice(eq + 1)];
|
|
722
|
+
if (arg in LIST) {
|
|
723
|
+
if (inline !== null) a[LIST[arg]].push(inline);
|
|
724
|
+
else while (i + 1 < argv.length && !argv[i + 1].startsWith("-")) a[LIST[arg]].push(argv[++i]);
|
|
725
|
+
if (!a[LIST[arg]].length) throw new UsageError(`argument ${arg}: expected at least one argument`);
|
|
726
|
+
} else if (arg in VALUE) {
|
|
727
|
+
const [key, kind] = VALUE[arg];
|
|
728
|
+
if (inline === null && i + 1 >= argv.length) throw new UsageError(`argument ${arg}: expected one argument`);
|
|
729
|
+
const value = inline ?? argv[++i];
|
|
730
|
+
if (Array.isArray(kind) && !kind.includes(value)) throw new UsageError(`argument ${arg}: invalid choice: '${value}' (choose from ${kind.join(", ")})`);
|
|
731
|
+
let number = null;
|
|
732
|
+
if (kind === "int") {
|
|
733
|
+
if (!/^[+-]?\d+$/.test(value.trim())) throw new UsageError(`argument ${arg}: invalid int value: '${value}'`);
|
|
734
|
+
number = Number.parseInt(value, 10);
|
|
735
|
+
} else if (kind === "float") {
|
|
736
|
+
number = value.trim() === "" ? Number.NaN : Number(value);
|
|
737
|
+
if (!Number.isFinite(number)) throw new UsageError(`argument ${arg}: invalid float value: '${value}'`);
|
|
738
|
+
}
|
|
739
|
+
a[key] = number ?? value;
|
|
740
|
+
} else if (inline !== null) {
|
|
741
|
+
throw new UsageError(`unrecognized arguments: ${argv[i]}`);
|
|
742
|
+
} else if (arg.startsWith("-") && arg.length > 1) {
|
|
743
|
+
throw new UsageError(`unrecognized arguments: ${arg}`);
|
|
744
|
+
} else positional.push(arg);
|
|
745
|
+
}
|
|
746
|
+
if (positional.length !== 2) throw new UsageError("the following arguments are required: level, genome");
|
|
747
|
+
if (!["component", "process", "tokens"].includes(positional[0])) throw new UsageError(`argument level: invalid choice: '${positional[0]}' (choose from component, process, tokens, skills)`);
|
|
748
|
+
if (Boolean(a.processes) !== Boolean(a.recordsets)) throw new UsageError("--processes and --recordsets go together");
|
|
749
|
+
[a.level, a.genome] = positional;
|
|
750
|
+
return a;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
export function main(argv = process.argv.slice(2), out = (s) => process.stdout.write(`${s}\n`)) {
|
|
754
|
+
try {
|
|
755
|
+
return run(argv, out);
|
|
756
|
+
} catch (e) {
|
|
757
|
+
if (!(e instanceof InputError)) throw e;
|
|
758
|
+
out(`FAIL: ${e.message}`);
|
|
759
|
+
return 1;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function run(argv, out) {
|
|
764
|
+
if (argv.includes("-h") || argv.includes("--help")) {
|
|
765
|
+
out(HELP);
|
|
766
|
+
return 0;
|
|
767
|
+
}
|
|
768
|
+
if (argv[0] === "skills") {
|
|
769
|
+
out(JSON.stringify({ build: [...VALID_SKILLS].sort(), operate: [...OPERATE_SKILLS].sort() }, null, 2));
|
|
770
|
+
return 0;
|
|
771
|
+
}
|
|
772
|
+
let a;
|
|
773
|
+
try {
|
|
774
|
+
a = parse(argv);
|
|
775
|
+
} catch (e) {
|
|
776
|
+
if (!(e instanceof UsageError)) throw e;
|
|
777
|
+
process.stderr.write(`${USAGE}\ncheck-genome.mjs: error: ${e.message}\n`);
|
|
778
|
+
return 2;
|
|
779
|
+
}
|
|
780
|
+
const paths = resolveGlob(a.genome);
|
|
781
|
+
let errors, notes = [];
|
|
782
|
+
if (a.level === "tokens") {
|
|
783
|
+
errors = [...(paths.length ? [] : [`no file matches ${a.genome}`]), ...checkTokens(paths, a.expect, a.min, a.files)];
|
|
784
|
+
} else if (paths.length !== 1) {
|
|
785
|
+
errors = [`expected exactly one file matching ${a.genome}, found ${paths.length}: ${paths.map(posix).join(", ") || "none"}`];
|
|
786
|
+
} else {
|
|
787
|
+
errors = a.level === "component" ? checkComponent(paths[0], a, false) : checkProcess(paths[0], a);
|
|
788
|
+
if (a.processes) {
|
|
789
|
+
const genomes = a.level === "process" ? componentLinks(paths[0], read(paths[0])).map(([, target, lib]) => [target, lib]) : [[paths[0], false]];
|
|
790
|
+
const [exportErrors, exportNotes] = checkExport(genomes, loadInventory(a.processes, "process inventory"), loadInventory(a.recordsets, "recordset list"));
|
|
791
|
+
errors.push(...exportErrors);
|
|
792
|
+
notes = exportNotes;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
for (const e of errors) out(`FAIL: ${e}`);
|
|
796
|
+
for (const n of notes) out(`NOTE: ${n}`);
|
|
797
|
+
if (!errors.length) out(`OK (${a.level !== "tokens" ? a.profile : "tokens"}): ${paths.map(posix).join(", ")}`);
|
|
798
|
+
return errors.length ? 1 : 0;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) process.exitCode = main();
|