@volter/twin-standard 1.0.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/LICENSE +202 -0
- package/README.md +20 -0
- package/dist/src/check-sources.d.ts +33 -0
- package/dist/src/check-sources.js +128 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +105 -0
- package/dist/src/derive.d.ts +2 -0
- package/dist/src/derive.js +349 -0
- package/dist/src/gate.d.ts +9 -0
- package/dist/src/gate.js +109 -0
- package/dist/src/grade.d.ts +30 -0
- package/dist/src/grade.js +36 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +11 -0
- package/dist/src/lanes.d.ts +2 -0
- package/dist/src/lanes.js +33 -0
- package/dist/src/p3-rules.d.ts +8 -0
- package/dist/src/p3-rules.js +43 -0
- package/dist/src/protocol-3.d.ts +5 -0
- package/dist/src/protocol-3.js +721 -0
- package/dist/src/published.d.ts +13 -0
- package/dist/src/published.js +36 -0
- package/dist/src/spec-documents.d.ts +12 -0
- package/dist/src/spec-documents.js +61 -0
- package/dist/src/spec-ir-client.d.ts +20 -0
- package/dist/src/spec-ir-client.js +77 -0
- package/dist/src/spec-ir-commands.d.ts +38 -0
- package/dist/src/spec-ir-commands.js +38 -0
- package/dist/src/spec-ir-discovery.d.ts +11 -0
- package/dist/src/spec-ir-discovery.js +106 -0
- package/dist/src/spec-ir-graphql.d.ts +25 -0
- package/dist/src/spec-ir-graphql.js +46 -0
- package/dist/src/spec-ir-lines.d.ts +19 -0
- package/dist/src/spec-ir-lines.js +76 -0
- package/dist/src/spec-ir-proto.d.ts +80 -0
- package/dist/src/spec-ir-proto.js +339 -0
- package/dist/src/spec-ir.d.ts +104 -0
- package/dist/src/spec-ir.js +691 -0
- package/dist/src/spec-patches.d.ts +8 -0
- package/dist/src/spec-patches.js +24 -0
- package/dist/src/spec.d.ts +5 -0
- package/dist/src/spec.js +7 -0
- package/dist/src/types.d.ts +75 -0
- package/dist/src/types.js +4 -0
- package/dist/src/unit.d.ts +5 -0
- package/dist/src/unit.js +14 -0
- package/package.json +71 -0
- package/src/check-sources.ts +109 -0
- package/src/cli.ts +75 -0
- package/src/derive.ts +316 -0
- package/src/gate.ts +95 -0
- package/src/grade.ts +47 -0
- package/src/index.ts +12 -0
- package/src/lanes.ts +29 -0
- package/src/p3-rules.ts +44 -0
- package/src/protocol-3.ts +617 -0
- package/src/published.ts +37 -0
- package/src/spec-documents.ts +58 -0
- package/src/spec-ir-client.ts +86 -0
- package/src/spec-ir-commands.ts +50 -0
- package/src/spec-ir-discovery.ts +104 -0
- package/src/spec-ir-graphql.ts +64 -0
- package/src/spec-ir-lines.ts +76 -0
- package/src/spec-ir-proto.ts +289 -0
- package/src/spec-ir.ts +689 -0
- package/src/spec-patches.ts +23 -0
- package/src/spec.ts +8 -0
- package/src/types.ts +53 -0
- package/src/unit.ts +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @volter/twin-standard
|
|
2
|
+
|
|
3
|
+
The Protocol 3 standard for Volter twin packs, as one versioned package: the criteria a pack is graded by
|
|
4
|
+
(`protocol-3@3`), the grader, the gate, and the spec derivation the grade reproduces. A pack repository's hook and
|
|
5
|
+
workflow, a release, and the twin catalog's check of a submitted version all run it at the version they pin, so every
|
|
6
|
+
place a pack is judged judges it by the same standard.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
twin-standard gate <pack repository> [<pack or lane dir>…] # every unit passes the form section, or exit 1
|
|
10
|
+
twin-standard gate-published <name>@<version>… [--registry <url>] # a published version, as the catalog grades a submission
|
|
11
|
+
twin-standard grade <pack or lane dir>… [--static] [--form] # each criterion's result
|
|
12
|
+
twin-standard derive <pack or lane dir> [--out <dir>] # write src/generated/ from the vendored spec
|
|
13
|
+
twin-standard check-sources <pack or lane dir> [--recheck] # fetch and record the sources the unit cites
|
|
14
|
+
twin-standard --version # this package's version and each standard's
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
What each criterion asks, and the rules for changing one, are twin-world's
|
|
18
|
+
[architecture, "The grade"](https://github.com/volter-ai/twin-world/blob/main/docs/contributing/architecture.md#the-grade).
|
|
19
|
+
A changed criterion is a release of this package: a criterion's id never changes meaning; a changed criterion takes a
|
|
20
|
+
new id and a new standard version, and a tightened check names what newly fails.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
export type SourceRecord = {
|
|
3
|
+
status: number;
|
|
4
|
+
checked: string;
|
|
5
|
+
quotes?: Record<string, boolean>;
|
|
6
|
+
};
|
|
7
|
+
export type Patch = {
|
|
8
|
+
op: string;
|
|
9
|
+
path: string;
|
|
10
|
+
why: string;
|
|
11
|
+
source?: {
|
|
12
|
+
url?: string;
|
|
13
|
+
spec?: string;
|
|
14
|
+
quote: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/** Every URL in a text, without trailing punctuation. */
|
|
18
|
+
export declare const urlsIn: (text: string) => string[];
|
|
19
|
+
/** The citations a pack's handlers write: each comment line of `src/semantics/` reading `source: <citation>`, where it
|
|
20
|
+
* stands (`<file>:<line>`) and what it cites ("What an author writes, and how": a rule carries its citation beside it). */
|
|
21
|
+
export declare function handlerCitations(pkg: string): Array<{
|
|
22
|
+
where: string;
|
|
23
|
+
source: string;
|
|
24
|
+
}>;
|
|
25
|
+
/** A handler citation's page and the words it says the page holds (`https://… "quote"`), when it quotes. */
|
|
26
|
+
export declare const quotedPage: (source: string) => {
|
|
27
|
+
url: string;
|
|
28
|
+
quote: string;
|
|
29
|
+
} | undefined;
|
|
30
|
+
/** What a pack cites: each URL, and the quotes a patch says the URL's page holds. */
|
|
31
|
+
export declare function citations(pkg: string): Promise<Map<string, Set<string>>>;
|
|
32
|
+
/** Fetch and record the sources the unit at `args[0]` cites (`--recheck`: every one, not only those due). */
|
|
33
|
+
export declare function checkSources(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
3
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
4
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
5
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return path;
|
|
9
|
+
};
|
|
10
|
+
// check-sources — the evidence a derived pack cites, fetched (docs/contributing/architecture.md,
|
|
11
|
+
// "Protocol 3", Correcting the spec and The semantics layer). Every URL a state transition's `source`,
|
|
12
|
+
// a handler's `// source:` line or a spec patch's `why` names is fetched once and its answer recorded in `spec/sources.json`; a patch's
|
|
13
|
+
// `quote` is looked for in the text of the page its `source` names. derive-pack reads the record offline
|
|
14
|
+
// and refuses a dead source, one never checked, and a quote its page does not hold.
|
|
15
|
+
//
|
|
16
|
+
// Documentation pages, never a vendor's API: each is fetched at most once per run, sixteen at a time,
|
|
17
|
+
// and a page already recorded as found is not fetched again (--recheck fetches everything).
|
|
18
|
+
//
|
|
19
|
+
// Usage: twin-standard check-sources <pack dir> [--recheck] (twin-world: bun scripts/check-sources.ts <vendor>)
|
|
20
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
import { unitAt } from "./unit.js";
|
|
23
|
+
/** Every URL in a text, without trailing punctuation. */
|
|
24
|
+
export const urlsIn = (text) => (text.match(/https?:\/\/[^\s"'<>]+/g) ?? []).map((u) => u.replace(/[),.;:\]]+$/, ''));
|
|
25
|
+
/** The citations a pack's handlers write: each comment line of `src/semantics/` reading `source: <citation>`, where it
|
|
26
|
+
* stands (`<file>:<line>`) and what it cites ("What an author writes, and how": a rule carries its citation beside it). */
|
|
27
|
+
export function handlerCitations(pkg) {
|
|
28
|
+
const dir = join(pkg, 'src', 'semantics');
|
|
29
|
+
if (!existsSync(dir))
|
|
30
|
+
return [];
|
|
31
|
+
return readdirSync(dir).filter((f) => /\.tsx?$/.test(f) && !/\.test\.tsx?$/.test(f)).sort().flatMap((f) => readFileSync(join(dir, f), 'utf8').split('\n').flatMap((line, i) => {
|
|
32
|
+
// a line of its own (`// source:`, `* source:` in a doc comment) or a comment ending a statement
|
|
33
|
+
const m = /(?:^\s*(?:\/\/|\/?\*+)|[\s;,)}\]]\/\/)\s*source:\s*(.+?)\s*(?:\*\/)?\s*$/i.exec(line);
|
|
34
|
+
return m ? [{ where: `${f}:${i + 1}`, source: m[1] }] : [];
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
/** A handler citation's page and the words it says the page holds (`https://… "quote"`), when it quotes. */
|
|
38
|
+
export const quotedPage = (source) => {
|
|
39
|
+
const m = /^(https?:\/\/\S+)\s+"([\s\S]+)"$/.exec(source.trim());
|
|
40
|
+
return m && m[2].trim() ? { url: m[1].replace(/[),.;:\]]+$/, ''), quote: m[2].replace(/\\"/g, '"') } : undefined;
|
|
41
|
+
};
|
|
42
|
+
/** What a pack cites: each URL, and the quotes a patch says the URL's page holds. */
|
|
43
|
+
export async function citations(pkg) {
|
|
44
|
+
const cited = new Map();
|
|
45
|
+
const cite = (url, quote) => { if (!cited.has(url))
|
|
46
|
+
cited.set(url, new Set()); if (quote)
|
|
47
|
+
cited.get(url).add(quote); };
|
|
48
|
+
const { manifest } = (await import(__rewriteRelativeImportExtension(join(pkg, 'src', 'manifest.ts'))));
|
|
49
|
+
for (const r of Object.values(manifest.resources))
|
|
50
|
+
for (const f of Object.values(r.state ?? {}))
|
|
51
|
+
for (const t of f.transitions)
|
|
52
|
+
for (const u of urlsIn(String(t.source ?? '')))
|
|
53
|
+
cite(u);
|
|
54
|
+
for (const c of handlerCitations(pkg)) {
|
|
55
|
+
const q = quotedPage(c.source);
|
|
56
|
+
if (q)
|
|
57
|
+
cite(q.url, q.quote);
|
|
58
|
+
else
|
|
59
|
+
for (const u of urlsIn(c.source))
|
|
60
|
+
cite(u);
|
|
61
|
+
}
|
|
62
|
+
const patchPath = join(pkg, 'spec', 'patches.json');
|
|
63
|
+
if (existsSync(patchPath)) {
|
|
64
|
+
for (const p of JSON.parse(readFileSync(patchPath, 'utf8')).patches) {
|
|
65
|
+
for (const u of urlsIn(p.why))
|
|
66
|
+
cite(u);
|
|
67
|
+
if (p.source?.url)
|
|
68
|
+
cite(p.source.url, p.source.quote);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return cited;
|
|
72
|
+
}
|
|
73
|
+
// a page's characters with its markup, entities and whitespace gone, so a quote from the rendered page is
|
|
74
|
+
// found in it however the page highlights or wraps it (a code example is a span per token, and an external link
|
|
75
|
+
// carries an invisible U+2060 word joiner beside its icon: clerk.com/docs/webhooks/overview, "Clerk uses Svix")
|
|
76
|
+
const textOf = (html) => bare(html.replace(/<script[\s\S]*?<\/script>/gi, '').replace(/<style[\s\S]*?<\/style>/gi, '').replace(/<[^>]+>/g, '')
|
|
77
|
+
.replace(/"/g, '"').replace(/'|'/g, "'").replace(/</g, '<').replace(/>/g, '>').replace(/ /g, ' ').replace(/&/g, '&'));
|
|
78
|
+
const bare = (s) => s.replace(/[\s\p{Cf}]+/gu, '');
|
|
79
|
+
/** Fetch and record the sources the unit at `args[0]` cites (`--recheck`: every one, not only those due). */
|
|
80
|
+
export async function checkSources(args) {
|
|
81
|
+
const vendor = args[0];
|
|
82
|
+
if (!vendor) {
|
|
83
|
+
console.error('usage: twin-standard check-sources <pack dir> [--recheck]');
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
const pkg = unitAt(vendor).dir;
|
|
87
|
+
const recordPath = join(pkg, 'spec', 'sources.json');
|
|
88
|
+
const record = existsSync(recordPath) ? JSON.parse(readFileSync(recordPath, 'utf8')) : {};
|
|
89
|
+
const cited = await citations(pkg);
|
|
90
|
+
const recheck = args.includes('--recheck');
|
|
91
|
+
const due = [...cited].filter(([url, quotes]) => recheck || record[url]?.status !== 200 || [...quotes].some((q) => record[url]?.quotes?.[q] !== true));
|
|
92
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
93
|
+
let next = 0;
|
|
94
|
+
await Promise.all(Array.from({ length: 16 }, async () => {
|
|
95
|
+
while (next < due.length) {
|
|
96
|
+
const [url, quotes] = due[next++];
|
|
97
|
+
let status = 0;
|
|
98
|
+
let text = '';
|
|
99
|
+
try {
|
|
100
|
+
const get = (agent) => fetch(url, { redirect: 'follow', signal: AbortSignal.timeout(8000), headers: { 'user-agent': agent } });
|
|
101
|
+
let res = await get('Mozilla/5.0 (volter twin source check)');
|
|
102
|
+
// a site that refuses a browser-like agent it cannot verify (dev.mysql.com) is asked again as the tool this is
|
|
103
|
+
if (res.status === 403)
|
|
104
|
+
res = await get('volter-source-check/1.0 (+https://volter.ai)');
|
|
105
|
+
status = res.status;
|
|
106
|
+
// an HTML page's text without its markup; a plain page (a raw source file, a markdown document) as it is: its
|
|
107
|
+
// `<name>` placeholders and `=>` arrows are not tags
|
|
108
|
+
text = (res.headers.get('content-type') ?? '').includes('html') ? textOf(await res.text()) : bare(await res.text());
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
status = 0;
|
|
112
|
+
}
|
|
113
|
+
const found = Object.fromEntries([...quotes].map((q) => [q, status === 200 && text.includes(bare(q))]));
|
|
114
|
+
record[url] = { status, checked: today, ...(quotes.size ? { quotes: found } : {}) };
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
const sorted = Object.fromEntries(Object.entries(record).filter(([url]) => cited.has(url)).sort(([a], [b]) => a.localeCompare(b)));
|
|
118
|
+
writeFileSync(recordPath, `${JSON.stringify(sorted, null, 2)}\n`);
|
|
119
|
+
const bad = Object.entries(sorted).filter(([, r]) => r.status !== 200);
|
|
120
|
+
const unquoted = Object.entries(sorted).flatMap(([url, r]) => Object.entries(r.quotes ?? {}).filter(([, ok]) => !ok).map(([q]) => `${url}: "${q}"`));
|
|
121
|
+
console.log(`${vendor}: ${cited.size} cited pages, ${due.length} fetched; ${bad.length} not found or not fetchable, ${unquoted.length} quotes not on their page`);
|
|
122
|
+
for (const [url, r] of bad)
|
|
123
|
+
console.log(` ${r.status || 'no answer'} ${url}`);
|
|
124
|
+
for (const u of unquoted)
|
|
125
|
+
console.log(` quote missing: ${u}`);
|
|
126
|
+
}
|
|
127
|
+
if (import.meta.main)
|
|
128
|
+
await checkSources(process.argv.slice(2));
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// twin-standard — the Protocol 3 standard's commands, the same wherever they run (a pack repository's hook and workflow,
|
|
3
|
+
// a release, the catalog's check of a submission, an author's machine):
|
|
4
|
+
//
|
|
5
|
+
// twin-standard gate <pack repository> [<pack or lane dir>…] every unit passes the form section, or exit 1
|
|
6
|
+
// twin-standard gate-published <name>@<version>… [--registry <url>]
|
|
7
|
+
// each published version passes the gate, as the catalog
|
|
8
|
+
// grades a submission (its tarball, unpacked)
|
|
9
|
+
// twin-standard grade <pack or lane dir>… [--static] [--form] each criterion's result
|
|
10
|
+
// twin-standard derive <pack or lane dir> [--out <dir>] write the unit's src/generated/ from its spec
|
|
11
|
+
// twin-standard check-sources <pack or lane dir> [--recheck] fetch and record the sources the unit cites
|
|
12
|
+
// twin-standard --version the package's version and each standard's
|
|
13
|
+
import { readFileSync } from 'node:fs';
|
|
14
|
+
import { relative, resolve } from 'node:path';
|
|
15
|
+
import { unitsOf, p3Gate } from "./gate.js";
|
|
16
|
+
import { grade, STANDARDS } from "./grade.js";
|
|
17
|
+
import { gatePublished } from "./published.js";
|
|
18
|
+
const [command, ...args] = process.argv.slice(2);
|
|
19
|
+
const usage = () => {
|
|
20
|
+
console.error('usage: twin-standard gate <repo> [units…] | gate-published <name>@<version>… [--registry <url>] | grade <unit>… [--static] [--form] | derive <unit> [--out <dir>] | check-sources <unit> [--recheck] | --version');
|
|
21
|
+
process.exit(2);
|
|
22
|
+
};
|
|
23
|
+
if (command === '--version') {
|
|
24
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
25
|
+
console.log(`@volter/twin-standard ${pkg.version} · ${STANDARDS.map((s) => `${s.id}@${s.version}`).join(' ')}`);
|
|
26
|
+
}
|
|
27
|
+
else if (command === 'gate') {
|
|
28
|
+
const [repoArg, ...only] = args;
|
|
29
|
+
if (!repoArg)
|
|
30
|
+
usage();
|
|
31
|
+
const repo = resolve(repoArg);
|
|
32
|
+
const results = await p3Gate(only.length ? only.map((u) => resolve(u)) : unitsOf(repo));
|
|
33
|
+
let blocked = 0;
|
|
34
|
+
for (const r of results) {
|
|
35
|
+
const name = relative(repo, r.unit) || r.unit;
|
|
36
|
+
if (r.failures.length) {
|
|
37
|
+
blocked++;
|
|
38
|
+
console.error(`✗ ${name}`);
|
|
39
|
+
for (const f of r.failures)
|
|
40
|
+
console.error(` ${f}`);
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
console.log(`✓ ${name}`);
|
|
44
|
+
}
|
|
45
|
+
console.log(blocked ? `gate: ${blocked} of ${results.length} units are not Protocol 3; they may not be in ${repo}` : `gate: all ${results.length} units are Protocol 3`);
|
|
46
|
+
process.exit(blocked ? 1 : 0);
|
|
47
|
+
}
|
|
48
|
+
else if (command === 'gate-published') {
|
|
49
|
+
const at = args.indexOf('--registry');
|
|
50
|
+
const registry = at >= 0 ? args[at + 1] : undefined;
|
|
51
|
+
const specs = args.filter((a, i) => !a.startsWith('--') && (at < 0 || i !== at + 1));
|
|
52
|
+
if (!specs.length)
|
|
53
|
+
usage();
|
|
54
|
+
let blocked = 0;
|
|
55
|
+
for (const spec of specs) {
|
|
56
|
+
let r;
|
|
57
|
+
try {
|
|
58
|
+
r = await gatePublished(spec, registry ? { registry } : {});
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
blocked++;
|
|
62
|
+
console.error(`✗ ${spec}\n ${e.message}`);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (r.failures.length) {
|
|
66
|
+
blocked++;
|
|
67
|
+
console.error(`✗ ${spec}`);
|
|
68
|
+
for (const f of r.failures)
|
|
69
|
+
for (const x of f.failures)
|
|
70
|
+
console.error(` ${f.unit}: ${x}`);
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
console.log(`✓ ${spec}`);
|
|
74
|
+
}
|
|
75
|
+
console.log(blocked ? `gate: ${blocked} of ${specs.length} versions are not Protocol 3` : `gate: all ${specs.length} versions are Protocol 3`);
|
|
76
|
+
process.exit(blocked ? 1 : 0);
|
|
77
|
+
}
|
|
78
|
+
else if (command === 'grade') {
|
|
79
|
+
const units = args.filter((a) => !a.startsWith('--'));
|
|
80
|
+
if (!units.length)
|
|
81
|
+
usage();
|
|
82
|
+
for (const unit of units) {
|
|
83
|
+
const grades = await grade(unit, { static: args.includes('--static'), ...(args.includes('--form') ? { sections: ['form'] } : {}) });
|
|
84
|
+
for (const [key, s] of Object.entries(grades)) {
|
|
85
|
+
console.log(`${unit} ${key} ${s.met}/${s.total}`);
|
|
86
|
+
for (const c of s.criteria)
|
|
87
|
+
console.log(` ${c.pass ? 'ok ' : 'NO '} ${c.section.padEnd(9)} ${c.id.padEnd(22)} ${c.reason}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (command === 'derive') {
|
|
92
|
+
if (!args[0])
|
|
93
|
+
usage();
|
|
94
|
+
// the derivation is a script over process.argv: it reads the unit from its first argument
|
|
95
|
+
process.argv = [process.argv[0], process.argv[1], ...args];
|
|
96
|
+
await import("./derive.js");
|
|
97
|
+
}
|
|
98
|
+
else if (command === 'check-sources') {
|
|
99
|
+
if (!args[0])
|
|
100
|
+
usage();
|
|
101
|
+
await (await import("./check-sources.js")).checkSources(args);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
usage();
|
|
105
|
+
}
|