@timiagama/ecr 0.0.1 → 0.1.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.
Files changed (138) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +16 -0
  3. package/README.md +411 -7
  4. package/dist/bin.d.ts +20 -0
  5. package/dist/bin.d.ts.map +1 -0
  6. package/dist/bin.js +26 -0
  7. package/dist/bin.js.map +1 -0
  8. package/dist/cli/corpus-loader.d.ts +198 -0
  9. package/dist/cli/corpus-loader.d.ts.map +1 -0
  10. package/dist/cli/corpus-loader.js +351 -0
  11. package/dist/cli/corpus-loader.js.map +1 -0
  12. package/dist/cli/corpus-statistics.d.ts +113 -0
  13. package/dist/cli/corpus-statistics.d.ts.map +1 -0
  14. package/dist/cli/corpus-statistics.js +119 -0
  15. package/dist/cli/corpus-statistics.js.map +1 -0
  16. package/dist/cli/diagnostic-reporter.d.ts +103 -0
  17. package/dist/cli/diagnostic-reporter.d.ts.map +1 -0
  18. package/dist/cli/diagnostic-reporter.js +254 -0
  19. package/dist/cli/diagnostic-reporter.js.map +1 -0
  20. package/dist/cli/project-ignore.d.ts +113 -0
  21. package/dist/cli/project-ignore.d.ts.map +1 -0
  22. package/dist/cli/project-ignore.js +199 -0
  23. package/dist/cli/project-ignore.js.map +1 -0
  24. package/dist/cli/safe-text.d.ts +25 -0
  25. package/dist/cli/safe-text.d.ts.map +1 -0
  26. package/dist/cli/safe-text.js +34 -0
  27. package/dist/cli/safe-text.js.map +1 -0
  28. package/dist/cli/supervisor.d.ts +108 -0
  29. package/dist/cli/supervisor.d.ts.map +1 -0
  30. package/dist/cli/supervisor.js +139 -0
  31. package/dist/cli/supervisor.js.map +1 -0
  32. package/dist/cli.d.ts +247 -0
  33. package/dist/cli.d.ts.map +1 -0
  34. package/dist/cli.js +591 -0
  35. package/dist/cli.js.map +1 -0
  36. package/dist/corpus-validator.d.ts +183 -0
  37. package/dist/corpus-validator.d.ts.map +1 -0
  38. package/dist/corpus-validator.js +479 -0
  39. package/dist/corpus-validator.js.map +1 -0
  40. package/dist/document-identity-rule.d.ts +198 -0
  41. package/dist/document-identity-rule.d.ts.map +1 -0
  42. package/dist/document-identity-rule.js +244 -0
  43. package/dist/document-identity-rule.js.map +1 -0
  44. package/dist/ecr.d.ts +103 -0
  45. package/dist/ecr.d.ts.map +1 -0
  46. package/dist/ecr.js +216 -0
  47. package/dist/ecr.js.map +1 -0
  48. package/dist/glob-pattern.d.ts +94 -0
  49. package/dist/glob-pattern.d.ts.map +1 -0
  50. package/dist/glob-pattern.js +188 -0
  51. package/dist/glob-pattern.js.map +1 -0
  52. package/dist/heading-source-form.d.ts +77 -0
  53. package/dist/heading-source-form.d.ts.map +1 -0
  54. package/dist/heading-source-form.js +129 -0
  55. package/dist/heading-source-form.js.map +1 -0
  56. package/dist/identifier-grammar.d.ts +212 -0
  57. package/dist/identifier-grammar.d.ts.map +1 -0
  58. package/dist/identifier-grammar.js +273 -0
  59. package/dist/identifier-grammar.js.map +1 -0
  60. package/dist/index.d.ts +19 -0
  61. package/dist/index.d.ts.map +1 -0
  62. package/dist/index.js +11 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/inline-reference-rule.d.ts +557 -0
  65. package/dist/inline-reference-rule.d.ts.map +1 -0
  66. package/dist/inline-reference-rule.js +802 -0
  67. package/dist/inline-reference-rule.js.map +1 -0
  68. package/dist/meta-documents.d.ts +91 -0
  69. package/dist/meta-documents.d.ts.map +1 -0
  70. package/dist/meta-documents.js +133 -0
  71. package/dist/meta-documents.js.map +1 -0
  72. package/dist/per-document-visitor.d.ts +510 -0
  73. package/dist/per-document-visitor.d.ts.map +1 -0
  74. package/dist/per-document-visitor.js +1032 -0
  75. package/dist/per-document-visitor.js.map +1 -0
  76. package/dist/references-section-rule.d.ts +482 -0
  77. package/dist/references-section-rule.d.ts.map +1 -0
  78. package/dist/references-section-rule.js +777 -0
  79. package/dist/references-section-rule.js.map +1 -0
  80. package/dist/section-hierarchy-rule.d.ts +299 -0
  81. package/dist/section-hierarchy-rule.d.ts.map +1 -0
  82. package/dist/section-hierarchy-rule.js +482 -0
  83. package/dist/section-hierarchy-rule.js.map +1 -0
  84. package/dist/source-alignment.d.ts +41 -0
  85. package/dist/source-alignment.d.ts.map +1 -0
  86. package/dist/source-alignment.js +166 -0
  87. package/dist/source-alignment.js.map +1 -0
  88. package/dist/source-lines.d.ts +69 -0
  89. package/dist/source-lines.d.ts.map +1 -0
  90. package/dist/source-lines.js +104 -0
  91. package/dist/source-lines.js.map +1 -0
  92. package/dist/spec-version.d.ts +19 -0
  93. package/dist/spec-version.d.ts.map +1 -0
  94. package/dist/spec-version.js +19 -0
  95. package/dist/spec-version.js.map +1 -0
  96. package/dist/types.d.ts +219 -0
  97. package/dist/types.d.ts.map +1 -0
  98. package/dist/types.js +11 -0
  99. package/dist/types.js.map +1 -0
  100. package/examples/docs/0. Orientation/0.0 - System Overview.md +34 -0
  101. package/examples/docs/0. Orientation/0.0.1 - Glossary.md +21 -0
  102. package/examples/docs/0. Orientation/0.0.2 - Quality Gates.md +22 -0
  103. package/examples/docs/3. Ingestion/3.1 - Ingestion - Validation Rules.md +33 -0
  104. package/examples/docs/4. Payments/4.10 - Settlement.md +22 -0
  105. package/examples/docs/4. Payments/4.2 - Payment Processing Contract.md +33 -0
  106. package/examples/docs/8. Orchestration/8.1 - Workflow Orchestration Contract.md +38 -0
  107. package/examples/docs/8. Orchestration/8.1.3 - Retry Policy.md +17 -0
  108. package/examples/docs/8. Orchestration/8.10 - Dead Letter Queue.md +20 -0
  109. package/examples/docs/README.md +7 -0
  110. package/package.json +65 -7
  111. package/protocol/navigation-protocol.md +223 -0
  112. package/spec/v2/1 - ECR - Structural Specification.md +1467 -0
  113. package/spec/v2/2 - ECR - User Guide.md +845 -0
  114. package/spec/v2/3 - Design Rationale - The Section Separator.md +243 -0
  115. package/src/bin.ts +30 -0
  116. package/src/cli/corpus-loader.ts +482 -0
  117. package/src/cli/corpus-statistics.ts +196 -0
  118. package/src/cli/diagnostic-reporter.ts +344 -0
  119. package/src/cli/project-ignore.ts +238 -0
  120. package/src/cli/safe-text.ts +39 -0
  121. package/src/cli/supervisor.ts +204 -0
  122. package/src/cli.ts +836 -0
  123. package/src/corpus-validator.ts +642 -0
  124. package/src/document-identity-rule.ts +422 -0
  125. package/src/ecr.ts +298 -0
  126. package/src/glob-pattern.ts +242 -0
  127. package/src/heading-source-form.ts +173 -0
  128. package/src/identifier-grammar.ts +380 -0
  129. package/src/index.ts +78 -0
  130. package/src/inline-reference-rule.ts +1235 -0
  131. package/src/meta-documents.ts +159 -0
  132. package/src/per-document-visitor.ts +1528 -0
  133. package/src/references-section-rule.ts +1182 -0
  134. package/src/section-hierarchy-rule.ts +705 -0
  135. package/src/source-alignment.ts +209 -0
  136. package/src/source-lines.ts +123 -0
  137. package/src/spec-version.ts +19 -0
  138. package/src/types.ts +267 -0
package/dist/cli.d.ts ADDED
@@ -0,0 +1,247 @@
1
+ /**
2
+ * ECR Command Line
3
+ *
4
+ * The executable entry point is `bin.ts`; this module only defines the
5
+ * commands, so that tests can drive them without spawning a process.
6
+ *
7
+ * Three commands, and deliberately no more:
8
+ *
9
+ * - `lint` validates a corpus against the ECR structural rules
10
+ * - `stats` measures the explicit structure a corpus already carries
11
+ * - `init` installs the ECR documentation, including the agent navigation
12
+ * protocol, beside a corpus
13
+ *
14
+ * There is no `backlinks` command, and there should never be one. ECR's claim
15
+ * is that a corpus is navigable with `grep` alone; a navigation command here
16
+ * would quietly make the tool a dependency of the thing it exists to prove
17
+ * unnecessary. Navigation belongs in the protocol `init` installs, not in this
18
+ * binary.
19
+ */
20
+ import type { ReportFormat } from './cli/diagnostic-reporter.js';
21
+ import type { SupervisionLimits } from './cli/supervisor.js';
22
+ /** Commands the CLI accepts. */
23
+ export type CommandName = 'lint' | 'stats' | 'init';
24
+ /**
25
+ * The stream a command's output belongs on.
26
+ *
27
+ * Results go to stdout; problems with the invocation itself go to stderr, so
28
+ * that `--format json` output piped into another tool is never interleaved
29
+ * with, or replaced by, an error message.
30
+ */
31
+ export type OutputStream = 'stdout' | 'stderr';
32
+ /**
33
+ * The result of running one command: what to print, where, and how to exit.
34
+ */
35
+ export interface CommandOutcome {
36
+ /** Text to write. */
37
+ readonly output: string;
38
+ /** The stream to write it to. */
39
+ readonly stream: OutputStream;
40
+ /** Process exit code. */
41
+ readonly exitCode: number;
42
+ }
43
+ /**
44
+ * A parsed command line.
45
+ */
46
+ export interface ParsedArguments {
47
+ /** The command to run. */
48
+ readonly command: CommandName;
49
+ /** Directory the command operates on. */
50
+ readonly corpusRoot: string;
51
+ /** Whether to run against the example corpus bundled with the package. */
52
+ readonly useExample: boolean;
53
+ /** Output format for `lint` and `stats`. */
54
+ readonly format: ReportFormat;
55
+ /** Glob patterns excluding project-specific meta-documents. */
56
+ readonly ignorePatterns: readonly string[];
57
+ /**
58
+ * Seconds a `lint` or `stats` run may take, when the command line said so;
59
+ * `0` for no limit, and absent when it did not say, which leaves whatever
60
+ * limit the run was configured with.
61
+ */
62
+ readonly timeoutSeconds?: number;
63
+ /** Mebibytes the run's heap may grow to, on the same terms. */
64
+ readonly maxMemoryMib?: number;
65
+ }
66
+ /**
67
+ * Where a command-line runner works. Both default to the real ones; tests
68
+ * supply their own so that nothing is written into this repository.
69
+ */
70
+ export interface EcrCommandLineOptions {
71
+ /** The directory the command runs from, and the project root for `.ecrignore`. */
72
+ readonly workingDirectory?: string;
73
+ /** The package's own root: where `init` copies from and `--example` reads. */
74
+ readonly packageRoot?: string;
75
+ /**
76
+ * How to run `lint` and `stats` in a child process that can be stopped.
77
+ * Absent, they run in this process: the executable asks for supervision,
78
+ * because only it knows the script a child would have to run, and a host
79
+ * embedding the library bounds its own work.
80
+ */
81
+ readonly supervision?: SupervisionSettings;
82
+ }
83
+ /** How a supervised run is started and bounded. */
84
+ export interface SupervisionSettings {
85
+ /** Path of the script the child runs: this package's executable. */
86
+ readonly entryPoint: string;
87
+ /** Limits overriding {@link DEFAULT_SUPERVISION_LIMITS}. */
88
+ readonly limits?: Partial<SupervisionLimits>;
89
+ }
90
+ /**
91
+ * Parses command-line arguments.
92
+ *
93
+ * Throws on anything it cannot understand rather than guessing, because a
94
+ * silently misread `--ignore` would quietly exclude documents from validation.
95
+ */
96
+ export declare class ArgumentParser {
97
+ /**
98
+ * Parses an argument list.
99
+ *
100
+ * @param argv - Arguments, excluding the node executable and script path
101
+ * @returns The parsed command line
102
+ * @throws Error when the arguments cannot be understood
103
+ */
104
+ parse(argv: readonly string[]): ParsedArguments;
105
+ /**
106
+ * Reads an option's value as a whole number of some unit, where zero means
107
+ * no limit.
108
+ *
109
+ * @param value - The argument following the option
110
+ * @param option - The option's name, for the message
111
+ * @param unit - What the number counts, for the message
112
+ * @param maximum - The largest value the limit can be applied as
113
+ * @returns The number
114
+ * @throws When the value is missing, is not a whole number, or is beyond what can be applied
115
+ */
116
+ private static readWholeNumber;
117
+ /**
118
+ * Determines whether a string names a supported command.
119
+ *
120
+ * @param candidate - The string to test
121
+ * @returns `true` when the string is a command name
122
+ */
123
+ private isCommandName;
124
+ }
125
+ /**
126
+ * Runs the CLI commands.
127
+ *
128
+ * Output is returned rather than printed so that the commands can be exercised
129
+ * directly by tests without capturing a stream.
130
+ */
131
+ export declare class EcrCommandLine {
132
+ /** Parses the command line. */
133
+ private readonly argumentParser;
134
+ /**
135
+ * The directory the command runs from: relative directories resolve against
136
+ * it, and it is the project root whose `.ecrignore` applies.
137
+ */
138
+ private readonly workingDirectory;
139
+ /** The package's own root, holding `package.json` and what `init` installs. */
140
+ private readonly packageRoot;
141
+ /** How to run the parsing commands in a child process, when asked to. */
142
+ private readonly supervision;
143
+ /**
144
+ * Creates a command-line runner.
145
+ *
146
+ * @param options - Where the command runs from and where the package lives; both default to the real ones
147
+ */
148
+ constructor(options?: EcrCommandLineOptions);
149
+ /**
150
+ * Runs one invocation.
151
+ *
152
+ * @param argv - Arguments, excluding the node executable and script path
153
+ * @returns The text to print and the process exit code
154
+ */
155
+ run(argv: readonly string[]): CommandOutcome;
156
+ /**
157
+ * Runs `lint` or `stats` against a corpus.
158
+ *
159
+ * @param parsed - The parsed command line
160
+ * @param corpusRoot - Resolved corpus directory
161
+ * @param displayedRoot - How to name the corpus in messages
162
+ * @param applyProjectIgnore - Whether the project's `.ecrignore` applies
163
+ * @returns The text to print and the process exit code
164
+ */
165
+ private runValidation;
166
+ /**
167
+ * Installs the ECR documentation into a new or empty directory, keeping the
168
+ * repository's layout, and adds that directory to the project's
169
+ * `.ecrignore` so that linting the project does not validate it.
170
+ *
171
+ * Everything that could stop the installation is checked before anything is
172
+ * written, and a failure part-way removes what was copied.
173
+ *
174
+ * @param destination - Resolved installation directory
175
+ * @param displayedDestination - The directory as the user typed it, for messages
176
+ * @returns The text to print and the process exit code
177
+ */
178
+ private runInit;
179
+ /**
180
+ * Removes what a failed installation copied. The destination was new or
181
+ * empty, so nothing of the user's is inside it.
182
+ *
183
+ * @param destination - The installation directory
184
+ * @param existed - Whether it existed, empty, before installation began
185
+ * @returns Why removal failed, or `undefined` when everything copied was removed
186
+ */
187
+ private removePartialInstallation;
188
+ /**
189
+ * Reads how this invocation should bound its parsing, if at all.
190
+ *
191
+ * @returns The supervision settings, or `undefined` when this invocation does the work itself
192
+ */
193
+ private readSupervision;
194
+ /**
195
+ * Runs `lint` or `stats` in a child process with a time limit and a heap
196
+ * limit, and passes on what it produced.
197
+ *
198
+ * A child that had to be stopped produced no usable report, however much of
199
+ * one reached this process, so none of it is passed on: the invocation
200
+ * failed, and says why.
201
+ *
202
+ * @param settings - Where the child's script is, and any limits overriding the defaults
203
+ * @param argv - The arguments to pass on, exactly as they were given
204
+ * @param parsed - The same arguments, for the limits they carry
205
+ * @returns The child's output and exit code, or the reason it was stopped
206
+ */
207
+ private runSupervised;
208
+ /**
209
+ * Describes a child that ended in a way this command never ends.
210
+ *
211
+ * Running out of heap is worth naming, because it is the one such ending a
212
+ * user can do anything about, and the limit that caused it is one they set.
213
+ *
214
+ * @param outcome - What the child produced before it ended
215
+ * @param limits - The limits it was given
216
+ * @returns The reason, as a phrase completing "ecr did not finish..."
217
+ */
218
+ private showAbnormalExit;
219
+ /**
220
+ * Builds a successful outcome, written to stdout.
221
+ *
222
+ * @param output - The text to print
223
+ * @returns The outcome
224
+ */
225
+ private succeed;
226
+ /**
227
+ * Builds the outcome of an invocation that could not run, written to stderr.
228
+ *
229
+ * @param output - The message to print
230
+ * @returns The outcome
231
+ */
232
+ private fail;
233
+ /**
234
+ * Reads the published package version from `package.json`.
235
+ *
236
+ * @returns The package version
237
+ */
238
+ private showPackageVersion;
239
+ /**
240
+ * Determines whether a corpus result contains any error-severity diagnostic.
241
+ *
242
+ * @param corpusResult - The result to inspect
243
+ * @returns `true` when at least one error was reported
244
+ */
245
+ private tellCorpusHasErrors;
246
+ }
247
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAeH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAGjE,OAAO,KAAK,EAAmC,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE9F,gCAAgC;AAChC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qBAAqB;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,yBAAyB;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,0BAA0B;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAA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