@dxos/deus 0.0.0-stage → 0.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 +105 -0
- package/README.md +24 -2
- package/bin/deus.ts +42 -0
- package/dist/lib/chunk-blocks.mjs +151 -0
- package/dist/lib/chunk-blocks.mjs.map +1 -0
- package/dist/lib/chunk-check.mjs +452 -0
- package/dist/lib/chunk-check.mjs.map +1 -0
- package/dist/lib/chunk-completion.mjs +112 -0
- package/dist/lib/chunk-completion.mjs.map +1 -0
- package/dist/lib/chunk-extension.mjs +396 -0
- package/dist/lib/chunk-extension.mjs.map +1 -0
- package/dist/lib/chunk-parse.mjs +21 -0
- package/dist/lib/chunk-parse.mjs.map +1 -0
- package/dist/lib/cli.mjs +946 -0
- package/dist/lib/cli.mjs.map +1 -0
- package/dist/lib/extension.mjs +4 -0
- package/dist/lib/index.mjs +6 -0
- package/dist/lib/parse.mjs +4 -0
- package/dist/lib/review.mjs +260 -0
- package/dist/lib/review.mjs.map +1 -0
- package/dist/lib/spec-index.mjs +28 -0
- package/dist/lib/spec-index.mjs.map +1 -0
- package/dist/types/bin/deus.d.ts +3 -0
- package/dist/types/bin/deus.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps/dx.config.d.ts +8 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-diverged/dx.config.d.ts +8 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-diverged/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-empty/dx.config.d.ts +7 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-empty/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-mismatch/dx.config.d.ts +8 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-mismatch/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-noplugin/dx.config.d.ts +5 -0
- package/dist/types/src/cli/__fixtures__/review/plugin-deps-noplugin/dx.config.d.ts.map +1 -0
- package/dist/types/src/cli/changelog.d.ts +25 -0
- package/dist/types/src/cli/changelog.d.ts.map +1 -0
- package/dist/types/src/cli/cli.test.d.ts +2 -0
- package/dist/types/src/cli/cli.test.d.ts.map +1 -0
- package/dist/types/src/cli/errors.d.ts +183 -0
- package/dist/types/src/cli/errors.d.ts.map +1 -0
- package/dist/types/src/cli/features.d.ts +58 -0
- package/dist/types/src/cli/features.d.ts.map +1 -0
- package/dist/types/src/cli/git.d.ts +8 -0
- package/dist/types/src/cli/git.d.ts.map +1 -0
- package/dist/types/src/cli/index.d.ts +12 -0
- package/dist/types/src/cli/index.d.ts.map +1 -0
- package/dist/types/src/cli/lint.d.ts +17 -0
- package/dist/types/src/cli/lint.d.ts.map +1 -0
- package/dist/types/src/cli/qa-lint.d.ts +40 -0
- package/dist/types/src/cli/qa-lint.d.ts.map +1 -0
- package/dist/types/src/cli/qa.d.ts +86 -0
- package/dist/types/src/cli/qa.d.ts.map +1 -0
- package/dist/types/src/cli/review.d.ts +38 -0
- package/dist/types/src/cli/review.d.ts.map +1 -0
- package/dist/types/src/cli/spec-index.d.ts +17 -0
- package/dist/types/src/cli/spec-index.d.ts.map +1 -0
- package/dist/types/src/extension/blocks.d.ts +65 -0
- package/dist/types/src/extension/blocks.d.ts.map +1 -0
- package/dist/types/src/extension/check.d.ts +99 -0
- package/dist/types/src/extension/check.d.ts.map +1 -0
- package/dist/types/src/extension/check.test.d.ts +2 -0
- package/dist/types/src/extension/check.test.d.ts.map +1 -0
- package/dist/types/src/extension/code.d.ts +7 -0
- package/dist/types/src/extension/code.d.ts.map +1 -0
- package/dist/types/src/extension/complete.d.ts +6 -0
- package/dist/types/src/extension/complete.d.ts.map +1 -0
- package/dist/types/src/extension/completion.d.ts +10 -0
- package/dist/types/src/extension/completion.d.ts.map +1 -0
- package/dist/types/src/extension/constants.d.ts +6 -0
- package/dist/types/src/extension/constants.d.ts.map +1 -0
- package/dist/types/src/extension/fences.d.ts +10 -0
- package/dist/types/src/extension/fences.d.ts.map +1 -0
- package/dist/types/src/extension/gen/mdl.d.ts +3 -0
- package/dist/types/src/extension/gen/mdl.d.ts.map +1 -0
- package/dist/types/src/extension/gen/mdl.terms.d.ts +2 -0
- package/dist/types/src/extension/gen/mdl.terms.d.ts.map +1 -0
- package/dist/types/src/extension/index.d.ts +8 -0
- package/dist/types/src/extension/index.d.ts.map +1 -0
- package/dist/types/src/extension/language.d.ts +20 -0
- package/dist/types/src/extension/language.d.ts.map +1 -0
- package/dist/types/src/extension/lint.d.ts +8 -0
- package/dist/types/src/extension/lint.d.ts.map +1 -0
- package/dist/types/src/extension/parse.d.ts +6 -0
- package/dist/types/src/extension/parse.d.ts.map +1 -0
- package/dist/types/src/extension/parser.test.d.ts +2 -0
- package/dist/types/src/extension/parser.test.d.ts.map +1 -0
- package/dist/types/src/extension/refs.d.ts +32 -0
- package/dist/types/src/extension/refs.d.ts.map +1 -0
- package/dist/types/src/extension/refs.test.d.ts +2 -0
- package/dist/types/src/extension/refs.test.d.ts.map +1 -0
- package/dist/types/src/extension/syntax.d.ts +12 -0
- package/dist/types/src/extension/syntax.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/review/fields.d.ts +9 -0
- package/dist/types/src/review/fields.d.ts.map +1 -0
- package/dist/types/src/review/index.d.ts +5 -0
- package/dist/types/src/review/index.d.ts.map +1 -0
- package/dist/types/src/review/review.d.ts +70 -0
- package/dist/types/src/review/review.d.ts.map +1 -0
- package/dist/types/src/review/review.test.d.ts +2 -0
- package/dist/types/src/review/review.test.d.ts.map +1 -0
- package/dist/types/src/review/source-key.d.ts +35 -0
- package/dist/types/src/review/source-key.d.ts.map +1 -0
- package/dist/types/src/review/symbol.d.ts +17 -0
- package/dist/types/src/review/symbol.d.ts.map +1 -0
- package/dist/types/src/review/symbol.test.d.ts +2 -0
- package/dist/types/src/review/symbol.test.d.ts.map +1 -0
- package/dist/types/src/spec-index/index.d.ts +3 -0
- package/dist/types/src/spec-index/index.d.ts.map +1 -0
- package/dist/types/src/spec-index/parse.d.ts +11 -0
- package/dist/types/src/spec-index/parse.d.ts.map +1 -0
- package/dist/types/src/spec-index/spec-index.d.ts +21 -0
- package/dist/types/src/spec-index/spec-index.d.ts.map +1 -0
- package/dist/types/src/spec-index/spec-index.test.d.ts +2 -0
- package/dist/types/src/spec-index/spec-index.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/docs/DESIGN.md +561 -0
- package/docs/IDIOMS.md +265 -0
- package/lang/PLUGIN-.template.mdl +115 -0
- package/lang/app.mdl +200 -0
- package/lang/changelog.mdl +184 -0
- package/lang/core.mdl +203 -0
- package/lang/examples/chess-1.mdl +149 -0
- package/lang/examples/chess-2.mdl +203 -0
- package/lang/examples/chess-3.mdl +231 -0
- package/lang/features.mdl +92 -0
- package/lang/plugin.mdl +59 -0
- package/lang/qa.mdl +383 -0
- package/lang/review.mdl +103 -0
- package/lang/sql.mdl +72 -0
- package/package.json +74 -3
- package/src/cli/__fixtures__/bad-decision.mdl +13 -0
- package/src/cli/__fixtures__/features/CYCLE.mdl +25 -0
- package/src/cli/__fixtures__/features/FEATURES.mdl +47 -0
- package/src/cli/__fixtures__/features/SPEC.mdl +22 -0
- package/src/cli/__fixtures__/features/SPEC.review.mdl +32 -0
- package/src/cli/__fixtures__/features/TASKS.md +5 -0
- package/src/cli/__fixtures__/lint-refs/SPEC.mdl +7 -0
- package/src/cli/__fixtures__/lint-refs/SPEC.review.mdl +7 -0
- package/src/cli/__fixtures__/qa-lint/packages/plugins/plugin-risky/PLUGIN.mdl +29 -0
- package/src/cli/__fixtures__/qa-list/plugin-sample/spec/PLUGIN.mdl +51 -0
- package/src/cli/__fixtures__/review/SPEC.mdl +23 -0
- package/src/cli/__fixtures__/review/SPEC.review.mdl +26 -0
- package/src/cli/__fixtures__/review/plugin-deps/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps/PLUGIN.review.mdl +13 -0
- package/src/cli/__fixtures__/review/plugin-deps/dx.config.ts +10 -0
- package/src/cli/__fixtures__/review/plugin-deps-diverged/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-diverged/PLUGIN.review.mdl +14 -0
- package/src/cli/__fixtures__/review/plugin-deps-diverged/dx.config.ts +10 -0
- package/src/cli/__fixtures__/review/plugin-deps-empty/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-empty/PLUGIN.review.mdl +13 -0
- package/src/cli/__fixtures__/review/plugin-deps-empty/dx.config.ts +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-mismatch/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-mismatch/PLUGIN.review.mdl +13 -0
- package/src/cli/__fixtures__/review/plugin-deps-mismatch/dx.config.ts +10 -0
- package/src/cli/__fixtures__/review/plugin-deps-noplugin/PLUGIN.mdl +9 -0
- package/src/cli/__fixtures__/review/plugin-deps-noplugin/PLUGIN.review.mdl +13 -0
- package/src/cli/__fixtures__/review/plugin-deps-noplugin/dx.config.ts +7 -0
- package/src/cli/changelog.ts +122 -0
- package/src/cli/cli.test.ts +359 -0
- package/src/cli/errors.ts +23 -0
- package/src/cli/features.ts +320 -0
- package/src/cli/git.ts +35 -0
- package/src/cli/index.ts +27 -0
- package/src/cli/lint.ts +75 -0
- package/src/cli/qa-lint.ts +206 -0
- package/src/cli/qa.ts +300 -0
- package/src/cli/review.ts +359 -0
- package/src/cli/spec-index.ts +54 -0
- package/src/extension/blocks.ts +169 -0
- package/src/extension/check.test.ts +629 -0
- package/src/extension/check.ts +552 -0
- package/src/extension/code.ts +99 -0
- package/src/extension/complete.ts +34 -0
- package/src/extension/completion.ts +64 -0
- package/src/extension/constants.ts +28 -0
- package/src/extension/fences.ts +270 -0
- package/src/extension/gen/mdl.terms.ts +16 -0
- package/src/extension/gen/mdl.ts +16 -0
- package/src/extension/index.ts +25 -0
- package/src/extension/language.ts +33 -0
- package/src/extension/lint.ts +19 -0
- package/src/extension/mdl.grammar +60 -0
- package/src/extension/parse.ts +31 -0
- package/src/extension/parser.test.ts +248 -0
- package/src/extension/refs.test.ts +95 -0
- package/src/extension/refs.ts +94 -0
- package/src/extension/syntax.ts +25 -0
- package/src/index.ts +6 -0
- package/src/review/fields.ts +31 -0
- package/src/review/index.ts +8 -0
- package/src/review/review.test.ts +111 -0
- package/src/review/review.ts +184 -0
- package/src/review/source-key.ts +63 -0
- package/src/review/symbol.test.ts +47 -0
- package/src/review/symbol.ts +96 -0
- package/src/spec-index/index.ts +6 -0
- package/src/spec-index/parse.ts +22 -0
- package/src/spec-index/spec-index.test.ts +56 -0
- package/src/spec-index/spec-index.ts +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dxos/deus
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Pattern specification language for human-agent collaborative software development.
|
|
4
|
+
|
|
5
|
+
A `.mdl` file is the authoritative description of a system — its types,
|
|
6
|
+
behaviour, interfaces, and acceptance criteria — from which implementation,
|
|
7
|
+
tests, and documentation can be derived.
|
|
8
|
+
|
|
9
|
+
This package carries:
|
|
10
|
+
|
|
11
|
+
- **The language spec** — see [`docs/DESIGN.md`](./docs/DESIGN.md).
|
|
12
|
+
- **The idiom format** — [`docs/IDIOMS.md`](./docs/IDIOMS.md).
|
|
13
|
+
- **The core dialect** — [`lang/core.mdl`](./lang/core.mdl).
|
|
14
|
+
- **The changelog dialect** — [`lang/changelog.mdl`](./lang/changelog.mdl): attributed decision log.
|
|
15
|
+
- **The review dialect** — [`lang/review.mdl`](./lang/review.mdl): per-item verdicts on how far the code meets a spec.
|
|
16
|
+
- **The feature map dialect** — [`lang/features.mdl`](./lang/features.mdl): `feature` blocks citing spec items, checked by `deus features check`.
|
|
17
|
+
- **A document template** — [`lang/PLUGIN-.template.mdl`](./lang/PLUGIN-.template.mdl).
|
|
18
|
+
- **Examples** — the chess trilogy under [`lang/examples/`](./lang/examples/).
|
|
19
|
+
- **The CodeMirror extension** — `.mdl` grammar, syntax, lint, completion under [`src/extension/`](./src/extension/).
|
|
20
|
+
|
|
21
|
+
Consumers (e.g. `@dxos/plugin-code`) import the extension barrel:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { mdl, mdlBlockDescription, mdlLint, mdlComplete } from '@dxos/deus/extension';
|
|
25
|
+
```
|
package/bin/deus.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
//
|
|
3
|
+
// Copyright 2026 DXOS.org
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import * as NodeRuntime from '@effect/platform-node/NodeRuntime';
|
|
7
|
+
import * as NodeServices from '@effect/platform-node/NodeServices';
|
|
8
|
+
import * as Cause from 'effect/Cause';
|
|
9
|
+
import * as CliError from 'effect/cli/CliError';
|
|
10
|
+
import * as Command from 'effect/cli/Command';
|
|
11
|
+
import * as Console from 'effect/Console';
|
|
12
|
+
import * as Effect from 'effect/Effect';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
ChangelogCheckError,
|
|
16
|
+
FeatureCheckError,
|
|
17
|
+
LintError,
|
|
18
|
+
QaLintError,
|
|
19
|
+
ReviewCheckError,
|
|
20
|
+
deus,
|
|
21
|
+
} from '../src/cli/index.ts';
|
|
22
|
+
|
|
23
|
+
const VERSION = '0.0.0';
|
|
24
|
+
|
|
25
|
+
/** Failures whose details are already on screen: CLI usage errors and the findings of a failed check. */
|
|
26
|
+
const isReported = (error: unknown): boolean =>
|
|
27
|
+
CliError.isCliError(error) ||
|
|
28
|
+
ChangelogCheckError.is(error) ||
|
|
29
|
+
FeatureCheckError.is(error) ||
|
|
30
|
+
LintError.is(error) ||
|
|
31
|
+
QaLintError.is(error) ||
|
|
32
|
+
ReviewCheckError.is(error);
|
|
33
|
+
|
|
34
|
+
// A reported failure exits non-zero with no further output; any other failure prints its message.
|
|
35
|
+
Command.runWith(deus, { version: VERSION })(process.argv.slice(2)).pipe(
|
|
36
|
+
Effect.tapCause((cause) => {
|
|
37
|
+
const error = Cause.squash(cause);
|
|
38
|
+
return Cause.hasInterruptsOnly(cause) || isReported(error) ? Effect.void : Console.error(`deus: ${error}`);
|
|
39
|
+
}),
|
|
40
|
+
Effect.provide(NodeServices.layer),
|
|
41
|
+
NodeRuntime.runMain({ disableErrorReporting: true }),
|
|
42
|
+
);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
//#region src/extension/blocks.ts
|
|
2
|
+
/**
|
|
3
|
+
* Regex matching the opening fence of a Spec mdl block.
|
|
4
|
+
* All Spec blocks use ```mdl; the block type lives on the first body line.
|
|
5
|
+
*/
|
|
6
|
+
var FENCE_REGEX = /^```mdl\s*$/gm;
|
|
7
|
+
/**
|
|
8
|
+
* Classifies each line of the text by CommonMark fence rules: a fence closes only on a line of the
|
|
9
|
+
* opener's character, at least as long, with no info string, so an example fence encloses nested ones.
|
|
10
|
+
*/
|
|
11
|
+
var scanFenceLines = (text, visit) => {
|
|
12
|
+
let fence;
|
|
13
|
+
let offset = 0;
|
|
14
|
+
for (const line of text.split("\n")) {
|
|
15
|
+
const marker = line.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
|
|
16
|
+
const info = marker?.[2].trim() ?? "";
|
|
17
|
+
if (fence) {
|
|
18
|
+
if (marker && marker[1][0] === fence.char && marker[1].length >= fence.length && info === "") {
|
|
19
|
+
visit({
|
|
20
|
+
line,
|
|
21
|
+
offset,
|
|
22
|
+
kind: "close",
|
|
23
|
+
mdl: fence.mdl
|
|
24
|
+
});
|
|
25
|
+
fence = void 0;
|
|
26
|
+
} else visit({
|
|
27
|
+
line,
|
|
28
|
+
offset,
|
|
29
|
+
kind: "body",
|
|
30
|
+
mdl: fence.mdl
|
|
31
|
+
});
|
|
32
|
+
} else if (marker && !(marker[1][0] === "`" && info.includes("`"))) {
|
|
33
|
+
fence = {
|
|
34
|
+
char: marker[1][0],
|
|
35
|
+
length: marker[1].length,
|
|
36
|
+
mdl: info === "mdl"
|
|
37
|
+
};
|
|
38
|
+
visit({
|
|
39
|
+
line,
|
|
40
|
+
offset,
|
|
41
|
+
kind: "open",
|
|
42
|
+
mdl: fence.mdl
|
|
43
|
+
});
|
|
44
|
+
} else visit({
|
|
45
|
+
line,
|
|
46
|
+
offset,
|
|
47
|
+
kind: "prose",
|
|
48
|
+
mdl: false
|
|
49
|
+
});
|
|
50
|
+
offset += line.length + 1;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Extracts block headers from the raw document text.
|
|
55
|
+
* Returns { type, id, from, to, body } for each top-level `mdl` fence,
|
|
56
|
+
* reading the block type from the first line of the block body.
|
|
57
|
+
* An unclosed block (mid-edit) runs to the end of the text.
|
|
58
|
+
*/
|
|
59
|
+
var parseBlockHeaders = (text) => {
|
|
60
|
+
const results = [];
|
|
61
|
+
let current;
|
|
62
|
+
const flush = () => {
|
|
63
|
+
if (!current) return;
|
|
64
|
+
const body = text.slice(current.bodyStart, current.bodyEnd);
|
|
65
|
+
const lineMatch = body.split("\n", 1)[0].trim().match(/^(\w+)(?:\s+([^\s:][^\n:]*?))?(?::\s*[^\n]*)?\s*$/);
|
|
66
|
+
results.push({
|
|
67
|
+
type: lineMatch?.[1] ?? "",
|
|
68
|
+
id: lineMatch?.[2]?.trim() ?? "",
|
|
69
|
+
from: current.from,
|
|
70
|
+
to: current.to,
|
|
71
|
+
body
|
|
72
|
+
});
|
|
73
|
+
current = void 0;
|
|
74
|
+
};
|
|
75
|
+
scanFenceLines(text, ({ line, offset, kind, mdl }) => {
|
|
76
|
+
const reopens = kind === "body" && mdl && /^ {0,3}`{3,}mdl\s*$/.test(line);
|
|
77
|
+
if (reopens && current) {
|
|
78
|
+
current.bodyEnd = offset;
|
|
79
|
+
flush();
|
|
80
|
+
}
|
|
81
|
+
if (kind === "open" && mdl || reopens) current = {
|
|
82
|
+
from: offset,
|
|
83
|
+
to: offset + line.length,
|
|
84
|
+
bodyStart: offset + line.length + 1,
|
|
85
|
+
bodyEnd: text.length
|
|
86
|
+
};
|
|
87
|
+
else if (kind === "close" && mdl) {
|
|
88
|
+
if (current) current.bodyEnd = offset;
|
|
89
|
+
flush();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
flush();
|
|
93
|
+
return results;
|
|
94
|
+
};
|
|
95
|
+
/** Every fenced `mdl` block of a spec, in document order. */
|
|
96
|
+
var parseMdlBlocks = (text) => parseBlockHeaders(text).map(({ type, id, from, body }) => {
|
|
97
|
+
const newline = body.indexOf("\n");
|
|
98
|
+
const title = (newline === -1 ? body : body.slice(0, newline)).match(/^\s*\w+\s+[^\s:][^\n:]*?:\s*(.+?)\s*$/)?.[1];
|
|
99
|
+
return {
|
|
100
|
+
type,
|
|
101
|
+
id,
|
|
102
|
+
...title && { title },
|
|
103
|
+
body: newline === -1 ? "" : body.slice(newline + 1),
|
|
104
|
+
from
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
/** A block header line: `<type> [<id>][: <title>]`. */
|
|
108
|
+
var BLOCK_HEADER_LINE = /^(\w+)(\s+[^\s:][^\n:]*?)?(:\s*.*)?\s*$/;
|
|
109
|
+
/** The terms a document's `## Extensions` table declares: the backticked first cell of each row. */
|
|
110
|
+
var extensionTerms = (text) => {
|
|
111
|
+
const terms = [];
|
|
112
|
+
let inExtensions = false;
|
|
113
|
+
scanFenceLines(text, ({ line, kind }) => {
|
|
114
|
+
if (kind !== "prose") return;
|
|
115
|
+
if (/^## /.test(line)) inExtensions = /^## Extensions\s*$/.test(line);
|
|
116
|
+
else if (inExtensions) {
|
|
117
|
+
const term = line.match(/^\|\s*`([\w-]+)`/)?.[1];
|
|
118
|
+
if (term) terms.push(term);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return terms;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Finds the block headers an `mdl` fence hides after its first block: lines past the fence's first body line, at
|
|
125
|
+
* column 0 (a block body is always indented), whose first word is one of `types`.
|
|
126
|
+
*/
|
|
127
|
+
var findInnerBlockHeaders = (text, types) => {
|
|
128
|
+
const headers = [];
|
|
129
|
+
let first = false;
|
|
130
|
+
scanFenceLines(text, ({ line, offset, kind, mdl }) => {
|
|
131
|
+
if (kind === "open" || kind === "body" && mdl && /^ {0,3}`{3,}mdl\s*$/.test(line)) first = true;
|
|
132
|
+
else if (kind === "body" && mdl) {
|
|
133
|
+
if (first) {
|
|
134
|
+
first = false;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const match = line.match(BLOCK_HEADER_LINE);
|
|
138
|
+
if (match && types.has(match[1])) headers.push({
|
|
139
|
+
type: match[1],
|
|
140
|
+
id: match[2]?.trim() ?? "",
|
|
141
|
+
from: offset,
|
|
142
|
+
to: offset + line.length
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return headers;
|
|
147
|
+
};
|
|
148
|
+
//#endregion
|
|
149
|
+
export { parseBlockHeaders as a, findInnerBlockHeaders as i, FENCE_REGEX as n, parseMdlBlocks as o, extensionTerms as r, scanFenceLines as s, BLOCK_HEADER_LINE as t };
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=chunk-blocks.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-blocks.mjs","names":[],"sources":["../../src/extension/blocks.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n/**\n * Regex matching the opening fence of a Spec mdl block.\n * All Spec blocks use ```mdl; the block type lives on the first body line.\n */\nexport const FENCE_REGEX = /^```mdl\\s*$/gm;\n\nexport type BlockHeader = { type: string; id: string; from: number; to: number; body: string };\n\n/** One line of a spec text, classified by its fence context. */\nexport type FenceLine = {\n line: string;\n /** Offset of the line in the text. */\n offset: number;\n /** `prose` is outside any fence; `open`/`close` are fence lines; `body` is inside a fence. */\n kind: 'prose' | 'open' | 'body' | 'close';\n /** For `open` and `body`: whether the enclosing fence is a top-level `mdl` block. */\n mdl: boolean;\n};\n\n/**\n * Classifies each line of the text by CommonMark fence rules: a fence closes only on a line of the\n * opener's character, at least as long, with no info string, so an example fence encloses nested ones.\n */\nexport const scanFenceLines = (text: string, visit: (line: FenceLine) => void): void => {\n let fence: { char: string; length: number; mdl: boolean } | undefined;\n let offset = 0;\n for (const line of text.split('\\n')) {\n const marker = line.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);\n const info = marker?.[2].trim() ?? '';\n if (fence) {\n if (marker && marker[1][0] === fence.char && marker[1].length >= fence.length && info === '') {\n visit({ line, offset, kind: 'close', mdl: fence.mdl });\n fence = undefined;\n } else {\n visit({ line, offset, kind: 'body', mdl: fence.mdl });\n }\n } else if (marker && !(marker[1][0] === '`' && info.includes('`'))) {\n fence = { char: marker[1][0], length: marker[1].length, mdl: info === 'mdl' };\n visit({ line, offset, kind: 'open', mdl: fence.mdl });\n } else {\n visit({ line, offset, kind: 'prose', mdl: false });\n }\n offset += line.length + 1;\n }\n};\n\n/**\n * Extracts block headers from the raw document text.\n * Returns { type, id, from, to, body } for each top-level `mdl` fence,\n * reading the block type from the first line of the block body.\n * An unclosed block (mid-edit) runs to the end of the text.\n */\nexport const parseBlockHeaders = (text: string): BlockHeader[] => {\n const results: BlockHeader[] = [];\n let current: { from: number; to: number; bodyStart: number; bodyEnd: number } | undefined;\n const flush = () => {\n if (!current) {\n return;\n }\n const body = text.slice(current.bodyStart, current.bodyEnd);\n const firstBodyLine = body.split('\\n', 1)[0].trim();\n // First body line: \"<blockType> [name][: label]\"\n const lineMatch = firstBodyLine.match(/^(\\w+)(?:\\s+([^\\s:][^\\n:]*?))?(?::\\s*[^\\n]*)?\\s*$/);\n results.push({\n type: lineMatch?.[1] ?? '',\n id: lineMatch?.[2]?.trim() ?? '',\n from: current.from,\n to: current.to,\n body,\n });\n current = undefined;\n };\n\n scanFenceLines(text, ({ line, offset, kind, mdl }) => {\n // A top-level `mdl` opener inside an unclosed block ends it, since a block never nests (mid-edit).\n const reopens = kind === 'body' && mdl && /^ {0,3}`{3,}mdl\\s*$/.test(line);\n if (reopens && current) {\n current.bodyEnd = offset;\n flush();\n }\n if ((kind === 'open' && mdl) || reopens) {\n current = { from: offset, to: offset + line.length, bodyStart: offset + line.length + 1, bodyEnd: text.length };\n } else if (kind === 'close' && mdl) {\n if (current) {\n current.bodyEnd = offset;\n }\n flush();\n }\n });\n flush();\n return results;\n};\n\n/** One fenced `mdl` block: its type, identifier and title from the header line, and the body below it. */\nexport type MdlBlock = {\n type: string;\n /** Empty for a block with no identifier. */\n id: string;\n /** The prose after the header's colon, if any. */\n title?: string;\n /** The block's lines after the header. */\n body: string;\n /** Offset of the opening fence in the text. */\n from: number;\n};\n\n/** Every fenced `mdl` block of a spec, in document order. */\nexport const parseMdlBlocks = (text: string): MdlBlock[] =>\n parseBlockHeaders(text).map(({ type, id, from, body }) => {\n const newline = body.indexOf('\\n');\n const header = newline === -1 ? body : body.slice(0, newline);\n const title = header.match(/^\\s*\\w+\\s+[^\\s:][^\\n:]*?:\\s*(.+?)\\s*$/)?.[1];\n return { type, id, ...(title && { title }), body: newline === -1 ? '' : body.slice(newline + 1), from };\n });\n\n/** A block header line: `<type> [<id>][: <title>]`. */\nexport const BLOCK_HEADER_LINE = /^(\\w+)(\\s+[^\\s:][^\\n:]*?)?(:\\s*.*)?\\s*$/;\n\n/** The terms a document's `## Extensions` table declares: the backticked first cell of each row. */\nexport const extensionTerms = (text: string): string[] => {\n const terms: string[] = [];\n let inExtensions = false;\n scanFenceLines(text, ({ line, kind }) => {\n if (kind !== 'prose') {\n return;\n }\n if (/^## /.test(line)) {\n inExtensions = /^## Extensions\\s*$/.test(line);\n } else if (inExtensions) {\n const term = line.match(/^\\|\\s*`([\\w-]+)`/)?.[1];\n if (term) {\n terms.push(term);\n }\n }\n });\n return terms;\n};\n\n/** A block header that follows another block inside the same fence. */\nexport type InnerBlockHeader = { type: string; id: string; from: number; to: number };\n\n/**\n * Finds the block headers an `mdl` fence hides after its first block: lines past the fence's first body line, at\n * column 0 (a block body is always indented), whose first word is one of `types`.\n */\nexport const findInnerBlockHeaders = (text: string, types: ReadonlySet<string>): InnerBlockHeader[] => {\n const headers: InnerBlockHeader[] = [];\n let first = false;\n scanFenceLines(text, ({ line, offset, kind, mdl }) => {\n // A top-level `mdl` opener inside an unclosed block starts a new block, as in `parseBlockHeaders`.\n if (kind === 'open' || (kind === 'body' && mdl && /^ {0,3}`{3,}mdl\\s*$/.test(line))) {\n first = true;\n } else if (kind === 'body' && mdl) {\n if (first) {\n first = false;\n return;\n }\n const match = line.match(BLOCK_HEADER_LINE);\n if (match && types.has(match[1])) {\n headers.push({ type: match[1], id: match[2]?.trim() ?? '', from: offset, to: offset + line.length });\n }\n }\n });\n return headers;\n};\n"],"mappings":";;;;;AAQA,IAAa,cAAc;;;;;AAmB3B,IAAa,kBAAkB,MAAc,UAA2C;CACtF,IAAI;CACJ,IAAI,SAAS;CACb,KAAK,MAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;EACnC,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