@rsconcept/rstool 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.
- package/LICENSE +21 -0
- package/README.md +150 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +585 -0
- package/dist/index.js.map +1 -0
- package/dist/mappers/model-adapter.d.ts +27 -0
- package/dist/mappers/model-adapter.js +248 -0
- package/dist/mappers/model-adapter.js.map +1 -0
- package/dist/mappers/schema-adapter.d.ts +22 -0
- package/dist/mappers/schema-adapter.js +89 -0
- package/dist/mappers/schema-adapter.js.map +1 -0
- package/dist/mappers/types.d.ts +23 -0
- package/dist/mappers/types.js +22 -0
- package/dist/mappers/types.js.map +1 -0
- package/dist/models/analysis.d.ts +18 -0
- package/dist/models/analysis.js +1 -0
- package/dist/models/analysis.js.map +1 -0
- package/dist/models/common.d.ts +15 -0
- package/dist/models/common.js +12 -0
- package/dist/models/common.js.map +1 -0
- package/dist/models/constituenta.d.ts +38 -0
- package/dist/models/constituenta.js +1 -0
- package/dist/models/constituenta.js.map +1 -0
- package/dist/models/diagnostic.d.ts +17 -0
- package/dist/models/diagnostic.js +1 -0
- package/dist/models/diagnostic.js.map +1 -0
- package/dist/models/evaluation.d.ts +23 -0
- package/dist/models/evaluation.js +1 -0
- package/dist/models/evaluation.js.map +1 -0
- package/dist/models/index.d.ts +13 -0
- package/dist/models/index.js +491 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/model-value.d.ts +37 -0
- package/dist/models/model-value.js +1 -0
- package/dist/models/model-value.js.map +1 -0
- package/dist/models/rstool-agent.d.ts +36 -0
- package/dist/models/rstool-agent.js +480 -0
- package/dist/models/rstool-agent.js.map +1 -0
- package/dist/models/session.d.ts +29 -0
- package/dist/models/session.js +1 -0
- package/dist/models/session.js.map +1 -0
- package/dist/models/tool-contract.d.ts +33 -0
- package/dist/models/tool-contract.js +6 -0
- package/dist/models/tool-contract.js.map +1 -0
- package/dist/session/session-store.d.ts +26 -0
- package/dist/session/session-store.js +66 -0
- package/dist/session/session-store.js.map +1 -0
- package/dist/wrapper/client.d.ts +30 -0
- package/dist/wrapper/client.js +96 -0
- package/dist/wrapper/client.js.map +1 -0
- package/dist/wrapper/stdio-wrapper.d.ts +1 -0
- package/dist/wrapper/stdio-wrapper.js +679 -0
- package/dist/wrapper/stdio-wrapper.js.map +1 -0
- package/docs/CONSTITUENTA.md +55 -0
- package/docs/DIAGNOSTICS.md +125 -0
- package/docs/DOMAIN.md +89 -0
- package/docs/GRAMMAR-REF.md +98 -0
- package/docs/PORTAL-API.md +48 -0
- package/docs/README.md +15 -0
- package/docs/SYNTAX.md +139 -0
- package/docs/TYPIFICATION.md +79 -0
- package/package.json +76 -0
- package/skills/README.md +15 -0
- package/skills/rstool-helper/EXAMPLES.md +154 -0
- package/skills/rstool-helper/REFERENCE.md +169 -0
- package/skills/rstool-helper/SKILL.md +148 -0
- package/src/index.ts +43 -0
- package/src/mappers/model-adapter.ts +276 -0
- package/src/mappers/schema-adapter.ts +87 -0
- package/src/mappers/types.ts +35 -0
- package/src/models/analysis.ts +13 -0
- package/src/models/common.ts +17 -0
- package/src/models/constituenta.ts +35 -0
- package/src/models/diagnostic.ts +12 -0
- package/src/models/evaluation.ts +25 -0
- package/src/models/index.ts +33 -0
- package/src/models/model-value.ts +31 -0
- package/src/models/rstool-agent.test.ts +300 -0
- package/src/models/rstool-agent.ts +143 -0
- package/src/models/session.ts +22 -0
- package/src/models/tool-contract.ts +47 -0
- package/src/session/session-store.ts +81 -0
- package/src/wrapper/client.ts +116 -0
- package/src/wrapper/stdio-wrapper.ts +225 -0
package/docs/SYNTAX.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# RSLang syntax reference
|
|
2
|
+
|
|
3
|
+
Distilled from the Portal help topics under `help-rslang-*`. Use this when constructing or repairing RSLang expressions. For full grammar tokens see `GRAMMAR-REF.md`. For typification rules see `TYPIFICATION.md`.
|
|
4
|
+
|
|
5
|
+
## Identifier rules
|
|
6
|
+
|
|
7
|
+
- **Globals** (concept aliases): uppercase Latin letter + digits — `X1`, `C2`, `S3`, `D11`, `F7`, `P4`, `A6`, `T9`, `N12`. The leading letter must match the constituent's role.
|
|
8
|
+
- **Radicals**: identifiers starting with `R` — used inside template parameterised expressions to denote arbitrary typifications (`R1`, `R2`).
|
|
9
|
+
- **Locals** (bound variables): lowercase Latin or Greek letter, optionally with digits — `x`, `ξ`, `μ2`, `y1`.
|
|
10
|
+
- **Special identifiers** — reserved tokens (`Z`, `∅`, operators).
|
|
11
|
+
|
|
12
|
+
## Literals
|
|
13
|
+
|
|
14
|
+
- **Integers**: digit sequence, no negative literal: `0`, `42`. Negation is a binary subtraction `0 - n`.
|
|
15
|
+
- **Integer set**: `Z`.
|
|
16
|
+
- **Empty set**: `∅` (typification `ℬ(R0)` — set of arbitrary element structure).
|
|
17
|
+
|
|
18
|
+
## Set-theoretic expressions
|
|
19
|
+
|
|
20
|
+
| Construct | Syntax | Notes |
|
|
21
|
+
|-----------|--------|-------|
|
|
22
|
+
| Union | `D1 ∪ D2` | |
|
|
23
|
+
| Intersection | `D1 ∩ D2` | |
|
|
24
|
+
| Difference | `D1 \ D2` | |
|
|
25
|
+
| Symmetric difference | `D1 ∆ D2` | |
|
|
26
|
+
| Cartesian product | `X1 × X2` | typification: tuple |
|
|
27
|
+
| Boolean / power set | `ℬ(X1)` | set of all subsets |
|
|
28
|
+
| Tuple | `(a, b, c)` | ordered, n ≥ 2 |
|
|
29
|
+
| Enumeration | `{a, b, c}` | unordered, n ≥ 1 |
|
|
30
|
+
| Singleton | `bool(a)` ≡ `{a}` | |
|
|
31
|
+
| Desingleton | `debool({a})` ≡ `a` | only for one-element sets |
|
|
32
|
+
| Sum set | `red(S1)` | union of inner sets; `S1` must be a set of sets |
|
|
33
|
+
| Small projection | `pr1((a1, …, an))` | returns `a1` |
|
|
34
|
+
| Large projection | `Pr1(S1)` | set of first components of tuples in `S1` |
|
|
35
|
+
| Filter | `Fi1[D1](S1)` | subset of `S1` whose first projection ∈ `D1` |
|
|
36
|
+
|
|
37
|
+
Indices `1` may be any natural number or comma-separated multi-index (`pr1,3((a1, a2, a3, a4)) = (a1, a3)`, `Fi1,2[D1](S1)`).
|
|
38
|
+
|
|
39
|
+
## Logical expressions
|
|
40
|
+
|
|
41
|
+
### Set-theoretic predicates
|
|
42
|
+
|
|
43
|
+
| Predicate | Syntax |
|
|
44
|
+
|-----------|--------|
|
|
45
|
+
| Membership | `ξ ∈ S` |
|
|
46
|
+
| Non-membership | `ξ ∉ S` |
|
|
47
|
+
| Set equality | `S1 = S2` |
|
|
48
|
+
| Set inequality | `S1 ≠ S2` |
|
|
49
|
+
| Inclusion | `S1 ⊆ S2` |
|
|
50
|
+
| Strict inclusion | `S1 ⊂ S2` |
|
|
51
|
+
| Non-inclusion | `S1 ⊄ S2` |
|
|
52
|
+
|
|
53
|
+
### Arithmetic predicates (typification `Logic`)
|
|
54
|
+
|
|
55
|
+
`a = b`, `a ≠ b`, `a < b`, `a ≤ b`, `a > b`, `a ≥ b`.
|
|
56
|
+
|
|
57
|
+
### Connectives
|
|
58
|
+
|
|
59
|
+
| Connective | Syntax |
|
|
60
|
+
|------------|--------|
|
|
61
|
+
| Negation | `¬A` |
|
|
62
|
+
| Conjunction | `A & B` |
|
|
63
|
+
| Disjunction | `A ∨ B` |
|
|
64
|
+
| Implication | `A ⇒ B` |
|
|
65
|
+
| Equivalence | `A ⇔ B` |
|
|
66
|
+
|
|
67
|
+
The constants `TRUE` and `FALSE` are **not** used inside schema explications.
|
|
68
|
+
|
|
69
|
+
## Quantifiers
|
|
70
|
+
|
|
71
|
+
| Form | Syntax |
|
|
72
|
+
|------|--------|
|
|
73
|
+
| Universal | `∀ξ∈STE (LE(ξ))` |
|
|
74
|
+
| Existential | `∃ξ∈STE (LE(ξ))` |
|
|
75
|
+
| Tuple binding | `∀(ξ1, ξ2)∈STE (LE(ξ1, ξ2))` |
|
|
76
|
+
| Variable list | `∀ξ1, ξ2 ∈ STE (LE(ξ1, ξ2))` |
|
|
77
|
+
|
|
78
|
+
Parentheses around `LE` may be omitted for atomic logical expressions.
|
|
79
|
+
|
|
80
|
+
## Arithmetic
|
|
81
|
+
|
|
82
|
+
Operations `a + b`, `a - b`, `a * b` form set-theoretic expressions with typification `Z`. Negative numbers are computed, never literal.
|
|
83
|
+
|
|
84
|
+
`card(S)` returns the integer cardinality of `S` (always finite in practice).
|
|
85
|
+
|
|
86
|
+
## Parameterised expressions
|
|
87
|
+
|
|
88
|
+
### Term-function declaration
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
F1 ::= [α1∈STE1, α2∈STE2(α1)] STE(α1, α2)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- Inside `[]` is an ordered list of parameter declarations separated by commas.
|
|
95
|
+
- A parameter is declared with `∈`: `local_var ∈ domain`.
|
|
96
|
+
- A declared variable can appear in subsequent parameter domains and in the result STE.
|
|
97
|
+
|
|
98
|
+
### Predicate-function declaration
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
P1 ::= [α1∈STE1, α2∈STE2(α1)] LE(α1, α2)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The only difference from a term-function is that the body is a logical expression.
|
|
105
|
+
|
|
106
|
+
### Calling parameterised functions
|
|
107
|
+
|
|
108
|
+
`F1[ξ1, S1]`, `P1[ξ1\ξ2, ξ3]` — arguments are positional and listed in square brackets after the function name. Argument typifications are checked against parameter typifications. Result is an STE (term-function) or LE (predicate-function).
|
|
109
|
+
|
|
110
|
+
### Template expressions
|
|
111
|
+
|
|
112
|
+
Functions that use radicals as parameter typifications are templates:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
F2 ::= [α1∈R1×R2, α2∈R1] α2 = pr1(α1)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- Radical values are **inferred** from the call-site argument typifications. All inferred values for the same radical index must agree.
|
|
119
|
+
- Different radical indices are independent.
|
|
120
|
+
- Radicals may only appear in parameter domains — never in the result expression.
|
|
121
|
+
|
|
122
|
+
## Examples
|
|
123
|
+
|
|
124
|
+
- `¬α ∈ S1`
|
|
125
|
+
- `D1 ∈ S1 ⇒ 2 + 2 = 5`
|
|
126
|
+
- `D1 ⊆ D2 ⇔ ∀x∈D1 x∈D2`
|
|
127
|
+
- `∀x∈D1 ∃y∈D2 (x, y)∈S1 & (x, x)∈S1`
|
|
128
|
+
- `(4 + 5) * 3`, `card(X1) > 5`
|
|
129
|
+
- `ℬ(2) = {{}, {1}, {2}, {1, 2}}`
|
|
130
|
+
- `pr2((5, 4, 3, 2, 1)) = 4`
|
|
131
|
+
- `red({{1, 2, 3}, {3, 4}}) = {1, 2, 3, 4}`
|
|
132
|
+
- `Fi2[{2, 4}]({((1, 2), (3, 4), (5, 6))}) = {((1, 2), (3, 4))}`
|
|
133
|
+
|
|
134
|
+
## Correctness model
|
|
135
|
+
|
|
136
|
+
- Expression checking happens in the **global context**: known typifications and bijective portability of every referenced identifier. Unknown identifiers are errors.
|
|
137
|
+
- Set-theoretic rules follow from bijective portability of the membership predicate — an element must match the typification of the set it is tested against.
|
|
138
|
+
- Logical consistency cannot generally be checked automatically. The existence of an interpretation example in a conceptual model is a basis for accepting consistency.
|
|
139
|
+
- All formal definitions must be **bijectively portable**: values are independent of any bijective replacement of undefined-concept interpretations.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Typification reference
|
|
2
|
+
|
|
3
|
+
Distilled from `help-rslang-typification`, `help-rslang-expression-structure`, and `help-rslang-expression-parameter`. Agents must understand grades to interpret `AnalysisResult.type` and to construct correct expressions.
|
|
4
|
+
|
|
5
|
+
## Grades
|
|
6
|
+
|
|
7
|
+
A genus-structure expression `ξ` has typification (a *structure*) if `ξ ∈ H` holds, where `H` is a valid **grade**. Grades are built recursively:
|
|
8
|
+
|
|
9
|
+
| Grade | Form | Notes |
|
|
10
|
+
|-------|------|-------|
|
|
11
|
+
| Element | `Xi`, `Ci` | grade of an undefined concept's elements |
|
|
12
|
+
| Integer | `Z` | grade of integer arithmetic results |
|
|
13
|
+
| Tuple of arity n | `(H1 × H2 × … × Hn)` | ordered structured grade |
|
|
14
|
+
| Set | `ℬ(H)` | set of values of grade `H` |
|
|
15
|
+
|
|
16
|
+
The empty set `∅` has typification `ℬ(R0)` — a set with arbitrary element structure. The radical `R0` ensures it conforms to any element grade in context.
|
|
17
|
+
|
|
18
|
+
## Extended typifications
|
|
19
|
+
|
|
20
|
+
Beyond set-theoretic grades, RSLang uses two additional grade-like markers:
|
|
21
|
+
|
|
22
|
+
- **Logic** — typification of logical expressions (axioms, statements, predicate bodies) that evaluate to TRUE or FALSE.
|
|
23
|
+
- **Parameterised** — typification of term-functions and predicate-functions:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
Hr 🠔 [H1, H2, …, Hi]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
where `Hr` is the result typification (an STE grade or `Logic`) and `H1 … Hi` are the argument typifications.
|
|
30
|
+
|
|
31
|
+
## Radicals
|
|
32
|
+
|
|
33
|
+
Template parameterised expressions may contain notations `R1, R2, …` (and `R0` for `∅`). Each radical corresponds to an arbitrary grade that is **inferred** from the typifications of the arguments at the point of use.
|
|
34
|
+
|
|
35
|
+
- All occurrences of the same radical index must resolve to the same grade.
|
|
36
|
+
- Radicals with different indices are independent.
|
|
37
|
+
- Radicals may only appear in parameter domains, **not in the result expression**.
|
|
38
|
+
|
|
39
|
+
## Encoded shape in `AnalysisResult.type`
|
|
40
|
+
|
|
41
|
+
The contract exposes `type: Record<string, unknown> | null` because typifications are JSON-encoded by the analyzer. Useful properties exposed by `@rsconcept/domain` helpers:
|
|
42
|
+
|
|
43
|
+
- `TypeID` enum: `Element`, `Integer`, `Tuple`, `Boolean`, `Logic`, `Functional` — discriminates the top-level shape.
|
|
44
|
+
- `TypeClass` enum: `Element`, `Integer`, `Logic`, `Functional`, `Collection` (set / tuple), `Other`.
|
|
45
|
+
- `TypePath` (sequence of indices) addresses positions inside a tuple-of-sets-of-tuples structure; use `makeTypePath` to construct.
|
|
46
|
+
- `parseTypeText(...)` parses an ASCII representation `B(X1)`, `(X1×X2)`, etc., into a `Typification`.
|
|
47
|
+
|
|
48
|
+
For agents inspecting types from rstool output:
|
|
49
|
+
|
|
50
|
+
1. Check `analysis.success === true` and `analysis.type !== null`.
|
|
51
|
+
2. Use `analysis.type` (object) only as opaque input to `@rsconcept/domain` helpers — do not pattern-match it manually.
|
|
52
|
+
3. The `valueClass` companion indicates `Value`, `Property` (non-computable membership only), or `Invalid`.
|
|
53
|
+
|
|
54
|
+
## Forming structures vs. derived structures
|
|
55
|
+
|
|
56
|
+
Forming operations build a new grade:
|
|
57
|
+
|
|
58
|
+
- `ℬ(H)` — power set
|
|
59
|
+
- `H1 × H2` — Cartesian product
|
|
60
|
+
- `(a, b, c)` — tuple
|
|
61
|
+
- `{a, b, c}` — enumeration
|
|
62
|
+
- `bool(a)` — singleton
|
|
63
|
+
|
|
64
|
+
Derived structures consume a grade:
|
|
65
|
+
|
|
66
|
+
- `red(S)` — union of inner sets; requires `S : ℬ(ℬ(H))`
|
|
67
|
+
- `debool({a})` — extracts the single element of a singleton
|
|
68
|
+
- `pr1((a1, …, an))`, `Pr1(S)` — projections (multi-indices allowed: `pr1,3`, `Pr2,4`)
|
|
69
|
+
- `Fi1[D](S)` — filters by membership in `D`; multi-index variants must match parameter arity
|
|
70
|
+
|
|
71
|
+
## Common typification pitfalls
|
|
72
|
+
|
|
73
|
+
- Negative integer literals do not exist — use `0 - n`.
|
|
74
|
+
- `debool(S)` fails if `S` is not a singleton.
|
|
75
|
+
- `red(S)` fails unless `S : ℬ(ℬ(H))`.
|
|
76
|
+
- Tuple projections require the argument to be a tuple of sufficient arity; `pr3((a, b))` is an error.
|
|
77
|
+
- Filter parameter list arity must match the multi-index in `Fi[...]`.
|
|
78
|
+
- A radical in the **result expression** of a template is a hard error (`radicalUsage`).
|
|
79
|
+
- An `axiom` or `statement` must have typification `Logic`; non-logical formal definitions raise `expectedLogic`.
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rsconcept/rstool",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Agent-facing library for incremental RSForm construction, RSLang analysis, diagnostics, modeling, and evaluation. Wraps @rsconcept/domain with a deterministic session contract and stdio wrapper.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "IRBorisov",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/IRBorisov/ConceptPortal",
|
|
10
|
+
"directory": "rsconcept/rstool"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://portal.acconcept.ru",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"rslang",
|
|
15
|
+
"rsform",
|
|
16
|
+
"rstool",
|
|
17
|
+
"agent",
|
|
18
|
+
"llm",
|
|
19
|
+
"mcp",
|
|
20
|
+
"formal-language",
|
|
21
|
+
"set-theory"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./wrapper": {
|
|
32
|
+
"types": "./dist/wrapper/client.d.ts",
|
|
33
|
+
"import": "./dist/wrapper/client.js"
|
|
34
|
+
},
|
|
35
|
+
"./skills/rstool-helper/*": "./skills/rstool-helper/*",
|
|
36
|
+
"./docs/*": "./docs/*",
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"bin": {
|
|
40
|
+
"rstool-wrapper": "./dist/wrapper/stdio-wrapper.js"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"src",
|
|
45
|
+
"skills",
|
|
46
|
+
"docs",
|
|
47
|
+
"README.md",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
],
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"wrapper": "tsx src/wrapper/stdio-wrapper.ts",
|
|
55
|
+
"example:client": "tsx examples/agent-client.ts",
|
|
56
|
+
"example:build-schema": "tsx examples/build-sample-rsform.ts",
|
|
57
|
+
"example:build-rsmodel": "tsx examples/build-sample-rsmodel.ts",
|
|
58
|
+
"example:build-kinship-schema": "tsx examples/build-kinship-rsform.ts",
|
|
59
|
+
"example:build-kinship-rsmodel": "tsx examples/build-kinship-rsmodel.ts",
|
|
60
|
+
"kinship:cli": "tsx examples/kinship/cli.ts",
|
|
61
|
+
"prepublishOnly": "npm run build"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@rsconcept/domain": "^1.0.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/node": "^24.0.0",
|
|
68
|
+
"tsup": "^8.5.0",
|
|
69
|
+
"tsx": "^4.21.0",
|
|
70
|
+
"typescript": "^5.9.3",
|
|
71
|
+
"vitest": "^4.1.5"
|
|
72
|
+
},
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public"
|
|
75
|
+
}
|
|
76
|
+
}
|
package/skills/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Agent skills (rstool)
|
|
2
|
+
|
|
3
|
+
Versioned copy of agent skills for this package.
|
|
4
|
+
|
|
5
|
+
## `rstool-helper`
|
|
6
|
+
|
|
7
|
+
Teaches agents RS language and the rstool session API. Files:
|
|
8
|
+
|
|
9
|
+
- `rstool-helper/SKILL.md` — entry and workflow
|
|
10
|
+
- `rstool-helper/REFERENCE.md` — contract, stdio, grammar pointers
|
|
11
|
+
- `rstool-helper/EXAMPLES.md` — runnable patterns
|
|
12
|
+
|
|
13
|
+
**Also committed for Cursor:** `.agents/skills/rstool-helper/` (same files). When you change this skill, update **both** directories in the same change set so they stay identical.
|
|
14
|
+
|
|
15
|
+
Contract changes: see `rsconcept/rstool/AGENTS.md` (sync checklist).
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# rstool — worked examples
|
|
2
|
+
|
|
3
|
+
Install first:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @rsconcept/rstool
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## In-process
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { CstType, RSToolAgent } from '@rsconcept/rstool';
|
|
13
|
+
|
|
14
|
+
const tool = new RSToolAgent();
|
|
15
|
+
const { sessionId } = tool.createSession();
|
|
16
|
+
|
|
17
|
+
// Base set — formal must be empty
|
|
18
|
+
tool.addOrUpdateConstituenta(sessionId, {
|
|
19
|
+
draft: { id: 1, alias: 'X1', cstType: CstType.BASE, definitionFormal: '' }
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Term referencing base
|
|
23
|
+
const { state, diagnostics } = tool.addOrUpdateConstituenta(sessionId, {
|
|
24
|
+
draft: { id: 2, alias: 'D1', cstType: CstType.TERM, definitionFormal: 'X1×X1' }
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log(state.analysis.success, diagnostics.length);
|
|
28
|
+
|
|
29
|
+
// Scratch check
|
|
30
|
+
tool.analyzeExpression(sessionId, {
|
|
31
|
+
expression: '(',
|
|
32
|
+
cstType: CstType.TERM
|
|
33
|
+
}); // success: false, syntax diagnostics
|
|
34
|
+
|
|
35
|
+
// Set base binding and evaluate a term
|
|
36
|
+
tool.setConstituentaValue(sessionId, {
|
|
37
|
+
target: 1,
|
|
38
|
+
value: { 0: 'zero', 1: 'one' }
|
|
39
|
+
});
|
|
40
|
+
const evalResult = tool.evaluateExpression(sessionId, {
|
|
41
|
+
expression: '1+2',
|
|
42
|
+
cstType: CstType.TERM
|
|
43
|
+
});
|
|
44
|
+
console.log(evalResult.success, evalResult.value); // true, 3
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Wrapper client
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { CstType } from '@rsconcept/rstool';
|
|
51
|
+
import { RSToolWrapperClient } from '@rsconcept/rstool/wrapper';
|
|
52
|
+
|
|
53
|
+
const client = new RSToolWrapperClient();
|
|
54
|
+
await client.waitUntilReady();
|
|
55
|
+
|
|
56
|
+
const { sessionId } = await client.call<{ sessionId: string }>('createSession');
|
|
57
|
+
await client.call('addOrUpdateConstituenta', {
|
|
58
|
+
sessionId,
|
|
59
|
+
input: {
|
|
60
|
+
draft: { id: 1, alias: 'X1', cstType: CstType.BASE, definitionFormal: '' }
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await client.call('addOrUpdateConstituenta', {
|
|
65
|
+
sessionId,
|
|
66
|
+
input: {
|
|
67
|
+
draft: { id: 2, alias: 'D1', cstType: CstType.TERM, definitionFormal: 'X1×X1' }
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const diagnostics = await client.call('listDiagnostics', { sessionId });
|
|
72
|
+
console.log(diagnostics);
|
|
73
|
+
|
|
74
|
+
await client.close();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Manual stdio
|
|
78
|
+
|
|
79
|
+
Start wrapper in one terminal:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npx rstool-wrapper
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Paste one JSON request per line after the ready line appears:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{ "id": "1", "method": "createSession", "params": {} }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Use the returned `sessionId` in subsequent lines:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{ "id": "2", "method": "addOrUpdateConstituenta", "params": { "sessionId": "...", "input": { "draft": { "id": 1, "alias": "X1", "cstType": "basic", "definitionFormal": "" } } } }
|
|
95
|
+
{ "id": "3", "method": "addOrUpdateConstituenta", "params": { "sessionId": "...", "input": { "draft": { "id": 2, "alias": "D1", "cstType": "term", "definitionFormal": "X1×X1" } } } }
|
|
96
|
+
{ "id": "4", "method": "listDiagnostics", "params": { "sessionId": "..." } }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Export a small RSForm session
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { CstType, RSToolAgent } from '@rsconcept/rstool';
|
|
103
|
+
|
|
104
|
+
const tool = new RSToolAgent();
|
|
105
|
+
const { sessionId } = tool.createSession();
|
|
106
|
+
|
|
107
|
+
tool.addOrUpdateConstituenta(sessionId, {
|
|
108
|
+
draft: { id: 1, alias: 'X1', cstType: CstType.BASE, definitionFormal: '' }
|
|
109
|
+
});
|
|
110
|
+
tool.addOrUpdateConstituenta(sessionId, {
|
|
111
|
+
draft: { id: 2, alias: 'C1', cstType: CstType.CONSTANT, definitionFormal: '' }
|
|
112
|
+
});
|
|
113
|
+
tool.addOrUpdateConstituenta(sessionId, {
|
|
114
|
+
draft: { id: 3, alias: 'D1', cstType: CstType.TERM, definitionFormal: 'X1×X1' }
|
|
115
|
+
});
|
|
116
|
+
tool.addOrUpdateConstituenta(sessionId, {
|
|
117
|
+
draft: { id: 4, alias: 'A1', cstType: CstType.AXIOM, definitionFormal: '1=1' }
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const payload = tool.exportSession(sessionId);
|
|
121
|
+
console.log(payload);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Model and evaluation
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
tool.setConstituentaValue(sessionId, {
|
|
128
|
+
target: 1,
|
|
129
|
+
value: { 0: 'zero', 1: 'one' }
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const evaluated = tool.evaluateConstituenta(sessionId, {
|
|
133
|
+
constituentId: 3
|
|
134
|
+
});
|
|
135
|
+
console.log(evaluated.success, evaluated.value);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Common mistakes
|
|
139
|
+
|
|
140
|
+
| Mistake | Symptom |
|
|
141
|
+
| -------------------------------------------------- | ------------------------------------------------ |
|
|
142
|
+
| `definitionFormal: 'Z'` on `X1` (`basic`) | `0x8862` definitionNotAllowed |
|
|
143
|
+
| `D1` uses `D2` before `D2` exists | globalNotTyped / undeclared global |
|
|
144
|
+
| `analyzeExpression` with wrong `cstType` | Role-specific semantic errors |
|
|
145
|
+
| Non-empty formal on `C1` (`constant`) | Same as basic — definition not allowed |
|
|
146
|
+
| `setConstituentaValue` on inferrable `D1` (`term`) | Error: inferrable and cannot be set directly |
|
|
147
|
+
| Evaluating before base binding set | May fail or return empty depending on expression |
|
|
148
|
+
|
|
149
|
+
## Fixing a syntax error
|
|
150
|
+
|
|
151
|
+
1. `analyzeExpression` with the broken fragment and correct `cstType`.
|
|
152
|
+
2. Read first diagnostic `{ from, to, code }`.
|
|
153
|
+
3. Edit substring of `definitionFormal` at those offsets.
|
|
154
|
+
4. `addOrUpdateConstituenta` again with the same `id` / `alias`.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# RS language and rstool — reference
|
|
2
|
+
|
|
3
|
+
## rstool contract
|
|
4
|
+
|
|
5
|
+
- Package: `@rsconcept/rstool`
|
|
6
|
+
- Contract version: `1.2.0` (`CONTRACT_VERSION`)
|
|
7
|
+
- Core class: `RSToolAgent`
|
|
8
|
+
- Public imports: `@rsconcept/rstool` and `@rsconcept/rstool/wrapper`
|
|
9
|
+
|
|
10
|
+
### Methods
|
|
11
|
+
|
|
12
|
+
| Method | Purpose |
|
|
13
|
+
| ----------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
14
|
+
| `createSession(initial?)` | New in-memory session → `{ sessionId, contractVersion }` |
|
|
15
|
+
| `addOrUpdateConstituenta(sessionId, { draft })` | Merge draft; analyze in session context → `{ state, diagnostics }` |
|
|
16
|
+
| `analyzeExpression(sessionId, { expression, cstType })` | Parse/typecheck snippet without persisting a constituent |
|
|
17
|
+
| `getFormState(sessionId)` | Clone of full session state |
|
|
18
|
+
| `listDiagnostics(sessionId, filters?)` | Accumulated diagnostics; optional `constituentId` filter |
|
|
19
|
+
| `commitStep(sessionId, message?)` | Record revision checkpoint |
|
|
20
|
+
| `exportSession(sessionId)` | JSON string `{ contractVersion, state, diagnostics }` |
|
|
21
|
+
| `importSession(payload)` | New session from export |
|
|
22
|
+
| `setConstituentaValue(sessionId, { target, type?, value })` | Set one base binding or structured value → `SessionModelState` |
|
|
23
|
+
| `setConstituentaValues(sessionId, { items })` | Batch set values → `SessionModelState` |
|
|
24
|
+
| `clearConstituentaValues(sessionId, { items })` | Clear values by constituent id → `SessionModelState` |
|
|
25
|
+
| `getModelState(sessionId)` | Clone of session interpretation state |
|
|
26
|
+
| `evaluateExpression(sessionId, { expression, cstType })` | Evaluate snippet in session context → `EvaluationResult` |
|
|
27
|
+
| `evaluateConstituenta(sessionId, { constituentId })` | Evaluate stored definition → `EvaluationResult` |
|
|
28
|
+
| `recalculateModel(sessionId)` | Recalculate all inferrable constituents → `{ items[] }` |
|
|
29
|
+
|
|
30
|
+
### `ConstituentaDraft`
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
{
|
|
34
|
+
id: number; // stable id within session
|
|
35
|
+
alias: string; // e.g. "D1", "X1"
|
|
36
|
+
cstType: CstType; // see SKILL.md table
|
|
37
|
+
definitionFormal: string;
|
|
38
|
+
term?: string;
|
|
39
|
+
definitionText?: string;
|
|
40
|
+
convention?: string;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Omitted text fields default to `''` in stored state.
|
|
45
|
+
|
|
46
|
+
### Model and evaluation types
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
type RSToolValue = number | RSToolValue[]; // runtime value (sets, tuples, logic 0/1)
|
|
50
|
+
type BasicBinding = Record<number, string>; // base-set element labels
|
|
51
|
+
|
|
52
|
+
interface SessionModelState {
|
|
53
|
+
items: { id: number; type: string; value: RSToolValue | BasicBinding }[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface EvaluationResult {
|
|
57
|
+
success: boolean;
|
|
58
|
+
value: RSToolValue | BasicBinding | null;
|
|
59
|
+
status: EvalStatus; // 1=NO_EVAL … 7=HAS_DATA
|
|
60
|
+
iterations: number;
|
|
61
|
+
cacheHits: number;
|
|
62
|
+
diagnostics: { code: number; from: number; to: number; params?: string[] }[];
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Base/constant bindings use `type: "basic"` and `value: { "0": "label", … }`. Structured values use normalized typification as `type` and nested arrays for sets/tuples.
|
|
67
|
+
|
|
68
|
+
### Stdio protocol
|
|
69
|
+
|
|
70
|
+
Process: `npx rstool-wrapper`
|
|
71
|
+
|
|
72
|
+
1. **Ready** (no request): `{"id":null,"ok":true,"result":{"ready":true,"wrapper":"rstool-stdio","contractVersion":"1.2.0"}}`
|
|
73
|
+
2. **Request**: `{"id":"<unique>","method":"<name>","params":{...}}`
|
|
74
|
+
3. **Response**: `{"id":"<same>","ok":true,"result":...}` or `{"id":"...","ok":false,"error":{"code":"...","message":"..."}}`
|
|
75
|
+
|
|
76
|
+
Extra methods: `ping`, `methods`.
|
|
77
|
+
|
|
78
|
+
Example chain:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{"id":"1","method":"createSession","params":{}}
|
|
82
|
+
{"id":"2","method":"addOrUpdateConstituenta","params":{"sessionId":"…","input":{"draft":{"id":3,"alias":"D1","cstType":"term","definitionFormal":"X1×X1"}}}}
|
|
83
|
+
{"id":"3","method":"analyzeExpression","params":{"sessionId":"…","input":{"expression":"1+2","cstType":"term"}}}
|
|
84
|
+
{"id":"4","method":"listDiagnostics","params":{"sessionId":"…"}}
|
|
85
|
+
{"id":"5","method":"commitStep","params":{"sessionId":"…","message":"checkpoint"}}
|
|
86
|
+
{"id":"6","method":"exportSession","params":{"sessionId":"…"}}
|
|
87
|
+
{"id":"7","method":"setConstituentaValue","params":{"sessionId":"…","input":{"target":1,"value":{"0":"a","1":"b"}}}}
|
|
88
|
+
{"id":"8","method":"evaluateExpression","params":{"sessionId":"…","input":{"expression":"1+2","cstType":"term"}}}
|
|
89
|
+
{"id":"9","method":"evaluateConstituenta","params":{"sessionId":"…","input":{"constituentId":3}}}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`RSToolWrapperClient`: spawns `rstool-wrapper` by default and implements `waitUntilReady()`, `call(method, params)`, `close()`.
|
|
93
|
+
|
|
94
|
+
### Analysis result
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
interface AnalysisResult {
|
|
98
|
+
success: boolean;
|
|
99
|
+
type: Record<string, unknown> | null; // typification tree
|
|
100
|
+
valueClass: 'value' | 'property' | null;
|
|
101
|
+
diagnostics: { code: number; from: number; to: number; params?: string[] }[];
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## RS language — conceptual model
|
|
106
|
+
|
|
107
|
+
- **Typification**: computed structure type from a formal definition; grades include elements (`Xi`, `Ci`), `Z`, tuples `(H1×…×Hn)`, sets `ℬ(H)`, logic `Logic`, parameterized `Hr 🠔 [H1,…,Hi]`.
|
|
108
|
+
- **Term graph**: directed dependencies between constituenta via alias references in definitions.
|
|
109
|
+
|
|
110
|
+
Intro (help): language is FOL-based; set vs logic expression split; parameterized templates for term/predicate functions; structural expressions reshape stages.
|
|
111
|
+
|
|
112
|
+
## Grammar tokens (selected)
|
|
113
|
+
|
|
114
|
+
From `rslang.grammar`:
|
|
115
|
+
|
|
116
|
+
| Category | Tokens / forms |
|
|
117
|
+
| ---------------------- | ---------------------------------------------------------- |
|
|
118
|
+
| Globals | `X`, `C`, `S`, `D`, `A`, `T`, `N` + digits (`Global` rule) |
|
|
119
|
+
| Functions / predicates | `F<n>`, `P<n>` |
|
|
120
|
+
| Radicals | `R<n>` |
|
|
121
|
+
| Locals | `_a-zα-ω` + optional digits |
|
|
122
|
+
| Logic | `¬` `∀` `∃` `⇔` `⇒` `∨` `&` |
|
|
123
|
+
| Sets | `ℬ` `∪` `\` `∆` `∩` `×` `∈` `∉` `⊆` `⊂` … |
|
|
124
|
+
| Ops | `Pr`, `pr`, `Fi`, `card`, `bool`, `debool`, `red` |
|
|
125
|
+
| Literals | digits, `Z`, `∅` |
|
|
126
|
+
|
|
127
|
+
Full grammar pointers and precedence notes: `docs/GRAMMAR-REF.md`.
|
|
128
|
+
|
|
129
|
+
## Help topic map (companion docs)
|
|
130
|
+
|
|
131
|
+
Standalone agents should consult the bundled distilled docs (`docs/*.md` inside `@rsconcept/rstool`):
|
|
132
|
+
|
|
133
|
+
| Topic | Bundled doc |
|
|
134
|
+
| ------------------------------------ | ------------------------------------------ |
|
|
135
|
+
| Identifiers, literals | `docs/SYNTAX.md` § *Identifier rules* |
|
|
136
|
+
| Grades, `Logic`, parameterized types | `docs/TYPIFICATION.md` |
|
|
137
|
+
| Logical expressions | `docs/SYNTAX.md` § *Logical expressions* |
|
|
138
|
+
| Set operators | `docs/SYNTAX.md` § *Set-theoretic* |
|
|
139
|
+
| Integer arithmetic | `docs/SYNTAX.md` § *Arithmetic* |
|
|
140
|
+
| Structural / typification reshaping | `docs/TYPIFICATION.md` § *Forming/derived* |
|
|
141
|
+
| Quantifiers | `docs/SYNTAX.md` § *Quantifiers* |
|
|
142
|
+
| Parameterized functions, templates | `docs/SYNTAX.md` § *Parameterised* |
|
|
143
|
+
| Correctness / validation mindset | `docs/SYNTAX.md` § *Correctness model* |
|
|
144
|
+
| Domain vocabulary | `docs/DOMAIN.md` |
|
|
145
|
+
| Constituent fields and ordering | `docs/CONSTITUENTA.md` |
|
|
146
|
+
| Portal REST API | `docs/PORTAL-API.md` |
|
|
147
|
+
| Grammar tokens / precedence | `docs/GRAMMAR-REF.md` |
|
|
148
|
+
|
|
149
|
+
## Error codes (rstool-relevant)
|
|
150
|
+
|
|
151
|
+
rstool re-exports `RSErrorCode.definitionNotAllowed` (`0x8862`) for base/constant violations.
|
|
152
|
+
|
|
153
|
+
Categories and per-code fix guidance: `docs/DIAGNOSTICS.md`.
|
|
154
|
+
|
|
155
|
+
Categories:
|
|
156
|
+
|
|
157
|
+
- `0x84xx` — syntax / parse
|
|
158
|
+
- `0x28xx` — local declaration warnings
|
|
159
|
+
- `0x88xx` — semantic / type
|
|
160
|
+
- `0x886x` — constituent-level (empty derived, definition not allowed)
|
|
161
|
+
- `0x81xx` — evaluation (runtime; returned by `evaluateExpression` / `evaluateConstituenta`)
|
|
162
|
+
|
|
163
|
+
## Exported session shape
|
|
164
|
+
|
|
165
|
+
`exportSession(sessionId)` returns a JSON string with `{ contractVersion, state, diagnostics }`.
|
|
166
|
+
|
|
167
|
+
- `state.items[]` contains each constituent with `id`, `alias`, `cstType`, `definitionFormal`, optional text fields, and nested analysis output.
|
|
168
|
+
- `state.model.items[]` is present when interpretation values have been set.
|
|
169
|
+
- `diagnostics[]` contains accumulated diagnostics with offsets and codes.
|