@rsconcept/rstool 0.2.1 → 0.4.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 (50) hide show
  1. package/README.md +3 -1
  2. package/dist/index-uhkmwruf.d.ts +46 -0
  3. package/dist/index.d.ts +5 -4
  4. package/dist/index.js +2 -2
  5. package/dist/mappers/model-adapter.d.ts +1 -1
  6. package/dist/mappers/schema-adapter.d.ts +1 -1
  7. package/dist/models/index.d.ts +5 -4
  8. package/dist/models/index.js +2 -2
  9. package/dist/models/rstool-agent.d.ts +1 -1
  10. package/dist/models/rstool-agent.js +1 -92
  11. package/dist/models/session.d.ts +1 -1
  12. package/dist/models/tool-contract.d.ts +1 -1
  13. package/dist/models/tool-contract.js +1 -1
  14. package/dist/models/tool-contract.js.map +1 -1
  15. package/dist/rstool-agent-BZi5jO1y.js +158 -0
  16. package/dist/rstool-agent-BZi5jO1y.js.map +1 -0
  17. package/dist/{rstool-agent-DkeH5Qml.d.ts → rstool-agent-pRaPnZay.d.ts} +6 -4
  18. package/dist/session/session-store.d.ts +2 -1
  19. package/dist/session/session-store.js +3 -0
  20. package/dist/session/session-store.js.map +1 -1
  21. package/dist/{session-BHGCCLfQ.d.ts → session-BPgsE80c.d.ts} +12 -1
  22. package/dist/{tool-contract-CsGqg_0P.d.ts → tool-contract-n1ghUOrK.d.ts} +5 -3
  23. package/dist/wrapper/stdio-wrapper.js +13 -1
  24. package/dist/wrapper/stdio-wrapper.js.map +1 -1
  25. package/docs/CONCEPTUAL-SCHEMA.md +50 -140
  26. package/docs/CONSTITUENTA.md +37 -62
  27. package/docs/DIAGNOSTICS.md +85 -130
  28. package/docs/DOMAIN.md +68 -91
  29. package/docs/GRAMMAR-REF.md +35 -86
  30. package/docs/MODEL-TESTING.md +57 -0
  31. package/docs/PORTAL-API.md +22 -36
  32. package/docs/README.md +14 -13
  33. package/docs/SYNTAX.md +49 -104
  34. package/docs/TYPIFICATION.md +41 -60
  35. package/package.json +1 -1
  36. package/skills/README.md +6 -8
  37. package/skills/rstool-helper/EXAMPLES.md +91 -105
  38. package/skills/rstool-helper/GUIDE.md +67 -114
  39. package/skills/rstool-helper/REFERENCE.md +43 -11
  40. package/skills/rstool-helper/SKILL.md +5 -8
  41. package/src/index.ts +6 -0
  42. package/src/models/index.ts +8 -0
  43. package/src/models/portal-json.ts +45 -0
  44. package/src/models/rstool-agent.test.ts +98 -0
  45. package/src/models/rstool-agent.ts +72 -4
  46. package/src/models/session.ts +11 -0
  47. package/src/models/tool-contract.ts +3 -1
  48. package/src/session/session-store.ts +3 -0
  49. package/src/wrapper/stdio-wrapper.ts +14 -0
  50. package/dist/models/rstool-agent.js.map +0 -1
@@ -1,16 +1,10 @@
1
- # rstool — worked examples
1
+ # rstool Examples
2
2
 
3
- Install first:
3
+ Short examples for agents. For full scripts, see `../../examples/`.
4
4
 
5
- ```bash
6
- npm install @rsconcept/rstool
7
- ```
8
-
9
- ## Kinship-lite: structure vs term
10
-
11
- `S1` carries **typification** `ℬ(X1×X1)` (pairs over people); `D1` is a **definition** `Pr1(S1)` (parents). Do not put `X1×X1` on a `term` — that is the full Cartesian product.
5
+ ## Minimal Session
12
6
 
13
- ## In-process
7
+ `S1` carries typification `ℬ(X1×X1)` for relation pairs. `D1` computes `Pr1(S1)`. Do not put bare `X1×X1` on a `term` when you mean a relation structure.
14
8
 
15
9
  ```ts
16
10
  import { CstType, RSToolAgent } from '@rsconcept/rstool';
@@ -18,12 +12,10 @@ import { CstType, RSToolAgent } from '@rsconcept/rstool';
18
12
  const tool = new RSToolAgent();
19
13
  const { sessionId } = tool.createSession();
20
14
 
21
- // Base set — formal must be empty
22
15
  tool.addOrUpdateConstituenta(sessionId, {
23
16
  draft: { id: 1, alias: 'X1', cstType: CstType.BASE, definitionFormal: '' }
24
17
  });
25
18
 
26
- // Structure: typification of parent–child pairs (undefined; convention in real schemas)
27
19
  tool.addOrUpdateConstituenta(sessionId, {
28
20
  draft: {
29
21
  id: 2,
@@ -34,32 +26,33 @@ tool.addOrUpdateConstituenta(sessionId, {
34
26
  }
35
27
  });
36
28
 
37
- // Term: derived definition — first projection of S1
38
29
  const { state, diagnostics } = tool.addOrUpdateConstituenta(sessionId, {
39
30
  draft: { id: 3, alias: 'D1', cstType: CstType.TERM, definitionFormal: 'Pr1(S1)' }
40
31
  });
41
32
 
42
33
  console.log(state.analysis.success, diagnostics.length);
34
+ ```
43
35
 
44
- // Scratch check
45
- tool.analyzeExpression(sessionId, {
46
- expression: '(',
47
- cstType: CstType.TERM
48
- }); // success: false, syntax diagnostics
36
+ ## Analyze Before Upsert
49
37
 
50
- // Set base binding and evaluate a scratch arithmetic term
51
- tool.setConstituentaValue(sessionId, {
52
- target: 1,
53
- value: { 0: 'zero', 1: 'one' }
54
- });
55
- const evalResult = tool.evaluateExpression(sessionId, {
56
- expression: '1+2',
38
+ Use scratch analysis when syntax or `cstType` is uncertain.
39
+
40
+ ```ts
41
+ const analysis = tool.analyzeExpression(sessionId, {
42
+ expression: 'Pr1(S1)',
57
43
  cstType: CstType.TERM
58
44
  });
59
- console.log(evalResult.success, evalResult.value); // true, 3
45
+
46
+ if (!analysis.success) {
47
+ console.log(analysis.diagnostics.map(({ code, from, to }) => ({ code, from, to })));
48
+ }
60
49
  ```
61
50
 
62
- ## Wrapper client
51
+ Fix the reported `from` / `to` range, then re-run analysis. Do not retry unchanged input.
52
+
53
+ ## Wrapper Client
54
+
55
+ Use the wrapper when the agent talks to a separate `rstool-wrapper` process.
63
56
 
64
57
  ```ts
65
58
  import { CstType } from '@rsconcept/rstool';
@@ -69,29 +62,13 @@ const client = new RSToolWrapperClient();
69
62
  await client.waitUntilReady();
70
63
 
71
64
  const { sessionId } = await client.call<{ sessionId: string }>('createSession');
65
+
72
66
  await client.call('addOrUpdateConstituenta', {
73
67
  sessionId,
74
68
  input: {
75
69
  draft: { id: 1, alias: 'X1', cstType: CstType.BASE, definitionFormal: '' }
76
70
  }
77
71
  });
78
- await client.call('addOrUpdateConstituenta', {
79
- sessionId,
80
- input: {
81
- draft: {
82
- id: 2,
83
- alias: 'S1',
84
- cstType: CstType.STRUCTURED,
85
- definitionFormal: 'ℬ(X1×X1)'
86
- }
87
- }
88
- });
89
- await client.call('addOrUpdateConstituenta', {
90
- sessionId,
91
- input: {
92
- draft: { id: 3, alias: 'D1', cstType: CstType.TERM, definitionFormal: 'Pr1(S1)' }
93
- }
94
- });
95
72
 
96
73
  const diagnostics = await client.call('listDiagnostics', { sessionId });
97
74
  console.log(diagnostics);
@@ -99,34 +76,57 @@ console.log(diagnostics);
99
76
  await client.close();
100
77
  ```
101
78
 
102
- ## Manual stdio
79
+ Manual stdio is one JSON request per line:
103
80
 
104
- Start wrapper in one terminal:
81
+ ```jsonl
82
+ { "id": "1", "method": "createSession", "params": {} }
83
+ { "id": "2", "method": "addOrUpdateConstituenta", "params": { "sessionId": "...", "input": { "draft": { "id": 1, "alias": "X1", "cstType": "basic", "definitionFormal": "" } } } }
84
+ ```
85
+
86
+ ## Export / Import
105
87
 
106
- ```bash
107
- npx rstool-wrapper
88
+ ```ts
89
+ const payload = tool.exportSession(sessionId);
90
+ const restored = tool.importSession(payload);
108
91
  ```
109
92
 
110
- Paste one JSON request per line after the ready line appears:
93
+ Export includes session state and model values.
111
94
 
112
- ```json
113
- { "id": "1", "method": "createSession", "params": {} }
95
+ To create files the user can upload to an existing Portal object:
96
+
97
+ ```ts
98
+ const schemaJson = tool.exportPortalSchema(sessionId);
99
+ const modelJson = tool.exportPortalModel(sessionId);
114
100
  ```
115
101
 
116
- Use the returned `sessionId` in subsequent lines:
102
+ Use `schemaJson` on a schema page and `modelJson` on a model page via **Load from JSON**.
117
103
 
118
- ```json
119
- { "id": "2", "method": "addOrUpdateConstituenta", "params": { "sessionId": "...", "input": { "draft": { "id": 1, "alias": "X1", "cstType": "basic", "definitionFormal": "" } } } }
120
- { "id": "3", "method": "addOrUpdateConstituenta", "params": { "sessionId": "...", "input": { "draft": { "id": 2, "alias": "S1", "cstType": "structure", "definitionFormal": "ℬ(X1×X1)" } } } }
121
- { "id": "4", "method": "addOrUpdateConstituenta", "params": { "sessionId": "...", "input": { "draft": { "id": 3, "alias": "D1", "cstType": "term", "definitionFormal": "Pr1(S1)" } } } }
122
- { "id": "5", "method": "listDiagnostics", "params": { "sessionId": "..." } }
104
+ ## Evaluation
105
+
106
+ ```ts
107
+ tool.setConstituentaValue(sessionId, {
108
+ target: 1,
109
+ value: { 0: 'zero', 1: 'one' }
110
+ });
111
+
112
+ const scratch = tool.evaluateExpression(sessionId, {
113
+ expression: '1+2',
114
+ cstType: CstType.TERM
115
+ });
116
+
117
+ console.log(scratch.success, scratch.value); // true, 3
123
118
  ```
124
119
 
125
- ## Export a small RSForm session
120
+ For stored definitions, set values for `basic`, `constant`, and `structure`, then call `evaluateConstituenta` or `recalculateModel`.
121
+
122
+ ## Semantic Smoke Test
123
+
124
+ When syntax is valid but meaning is uncertain, build a tiny model and assert the value.
126
125
 
127
126
  ```ts
128
- import { CstType, RSToolAgent } from '@rsconcept/rstool';
127
+ import { CstType, EvalStatus, RSToolAgent } from '@rsconcept/rstool';
129
128
 
129
+ const TUPLE_ID = -111;
130
130
  const tool = new RSToolAgent();
131
131
  const { sessionId } = tool.createSession();
132
132
 
@@ -134,62 +134,48 @@ tool.addOrUpdateConstituenta(sessionId, {
134
134
  draft: { id: 1, alias: 'X1', cstType: CstType.BASE, definitionFormal: '' }
135
135
  });
136
136
  tool.addOrUpdateConstituenta(sessionId, {
137
- draft: { id: 2, alias: 'C1', cstType: CstType.CONSTANT, definitionFormal: '' }
137
+ draft: { id: 2, alias: 'S1', cstType: CstType.STRUCTURED, definitionFormal: 'ℬ(X1×X1)' }
138
138
  });
139
139
  tool.addOrUpdateConstituenta(sessionId, {
140
- draft: {
141
- id: 3,
142
- alias: 'S1',
143
- cstType: CstType.STRUCTURED,
144
- definitionFormal: 'ℬ(X1×X1)',
145
- convention: 'Pairs (parent, child) over X1.'
146
- }
147
- });
148
- tool.addOrUpdateConstituenta(sessionId, {
149
- draft: { id: 4, alias: 'D1', cstType: CstType.TERM, definitionFormal: 'Pr1(S1)' }
150
- });
151
- tool.addOrUpdateConstituenta(sessionId, {
152
- draft: { id: 5, alias: 'A1', cstType: CstType.AXIOM, definitionFormal: '1=1' }
140
+ draft: { id: 3, alias: 'D1', cstType: CstType.TERM, definitionFormal: 'Pr1(S1)' }
153
141
  });
154
142
 
155
- const payload = tool.exportSession(sessionId);
156
- console.log(payload);
157
- ```
158
-
159
- ## Model and evaluation
160
-
161
- Full kinship modeling (`S1` values as tuples, `Pr1(S1)`, …): `examples/build-kinship-rsmodel.ts`.
162
-
163
- Minimal evaluation after bindings:
164
-
165
- ```ts
166
- tool.setConstituentaValue(sessionId, {
167
- target: 1,
168
- value: { 0: 'zero', 1: 'one' }
143
+ tool.setConstituentaValues(sessionId, {
144
+ items: [
145
+ { target: 1, value: { 0: 'ann', 1: 'bob', 2: 'cat' } },
146
+ {
147
+ target: 2,
148
+ value: [
149
+ [TUPLE_ID, 0, 1],
150
+ [TUPLE_ID, 0, 2]
151
+ ]
152
+ }
153
+ ]
169
154
  });
170
155
 
171
- const evaluated = tool.evaluateConstituenta(sessionId, {
172
- constituentId: 4 // D1 = Pr1(S1); needs S1 interpreted — see kinship example
173
- });
174
- console.log(evaluated.success, evaluated.value);
156
+ const result = tool.evaluateConstituenta(sessionId, { constituentId: 3 });
157
+
158
+ if (!result.success || result.status !== EvalStatus.HAS_DATA || JSON.stringify(result.value) !== '[0]') {
159
+ throw new Error(`Expected Pr1(S1) to select the first coordinate; got ${JSON.stringify(result)}`);
160
+ }
175
161
  ```
176
162
 
163
+ Use this pattern for tests that protect important definitions. Full kinship model: `../../examples/build-kinship-rsmodel.ts`. More notes: `../../docs/MODEL-TESTING.md`.
164
+
177
165
  ## Common mistakes
178
166
 
179
- | Mistake | Symptom |
180
- | -------------------------------------------------- | ------------------------------------------------ |
181
- | `definitionFormal: 'Z'` on `X1` (`basic`) | `0x8862` definitionNotAllowed |
182
- | `D1` uses `D2` before `D2` exists | globalNotTyped / undeclared global |
183
- | `analyzeExpression` with wrong `cstType` | Role-specific semantic errors |
184
- | Non-empty formal on `C1` (`constant`) | Same as basic definition not allowed |
185
- | `term` with `X1×X1` when modeling a **relation** | Full Cartesian product instead of typed pairs in `S#` |
186
- | `structure` with `Pr1(S1)` instead of a grade | Wrong role — projections belong on `term` / `F#` |
187
- | `setConstituentaValue` on inferrable `D1` (`term`) | Error: inferrable and cannot be set directly |
188
- | Evaluating before base binding set | May fail or return empty depending on expression |
167
+ - `definitionFormal: 'Z'` on `basic` / `constant` → `definitionNotAllowed`.
168
+ - `D1` uses `D2` before `D2` exists → global not typed / undeclared.
169
+ - Wrong `cstType` in `analyzeExpression` role-specific errors.
170
+ - `term` with `X1×X1` for a relation full Cartesian product, not relation typification.
171
+ - `structure` with `Pr1(S1)` → wrong role; projections belong on `term` / `function`.
172
+ - `setConstituentaValue` on `term`, `axiom`, or `statement` cannot set computed constituents directly.
173
+ - Evaluation before base bindings missing value, empty result, or evaluation failure.
189
174
 
190
- ## Fixing a syntax error
175
+ ## Fix Syntax
191
176
 
192
177
  1. `analyzeExpression` with the broken fragment and correct `cstType`.
193
- 2. Read first diagnostic `{ from, to, code }`.
194
- 3. Edit substring of `definitionFormal` at those offsets.
195
- 4. `addOrUpdateConstituenta` again with the same `id` / `alias`.
178
+ 2. Read `{ code, from, to, params }`.
179
+ 3. Edit the substring of `definitionFormal` at those offsets.
180
+ 4. Re-run analysis.
181
+ 5. Upsert with the same `id` / `alias`.
@@ -1,141 +1,94 @@
1
- # RS Language & rstool — Compact Guide for Agents
1
+ # RS Language & rstool
2
2
 
3
- **RS language** is a formal scheme notation for concepts, relations, operations—extends FOL, core: membership `x∈y`; typification via set-theoretic/logical expressions.
3
+ Compact entry guide for agents. Keep details in linked docs.
4
4
 
5
- **rstool** is the agent API for sessions, upserts, analysis, diagnostics, modeling/evaluation, (de)serialization.
5
+ **RSLang** is a formal notation for conceptual schemas: concepts, relations, operations, assertions. Core ideas: membership `x∈y`, set-theoretic expressions, logical expressions, typification.
6
6
 
7
- - Library: `@rsconcept/rstool` (npm)
8
- - Analyzer: `@rsconcept/domain` (dependency of rstool)
9
- - Language reference: `docs/*.md` next to this package (see table below)
7
+ **rstool** is the agent API for sessions, upserts, analysis, diagnostics, model values, evaluation, export/import.
10
8
 
11
- ## Docs / hints (canonical paths)
9
+ - Library: `@rsconcept/rstool`.
10
+ - Analyzer: `@rsconcept/domain`.
11
+ - Stdio wrapper: `npx rstool-wrapper`, JSON per line.
12
+ - Node client: `RSToolWrapperClient`.
12
13
 
13
- Paths below are relative to **this file** (`skills/rstool-helper/GUIDE.md`).
14
+ ## What to Read
14
15
 
15
- | Info | Location |
16
- | :--- | :--- |
17
- | rstool API, methods, error codes | [REFERENCE.md](REFERENCE.md) |
18
- | Worked examples, common mistakes | [EXAMPLES.md](EXAMPLES.md) |
19
- | Domain vocabulary (English) | [../../docs/DOMAIN.md](../../docs/DOMAIN.md) |
20
- | Designing/reviewing conceptual schemas (agent recommendations) | [../../docs/CONCEPTUAL-SCHEMA.md](../../docs/CONCEPTUAL-SCHEMA.md) |
21
- | Constituenta fields, validation, ordering | [../../docs/CONSTITUENTA.md](../../docs/CONSTITUENTA.md) |
22
- | RSLang syntax (operators, quantifiers) | [../../docs/SYNTAX.md](../../docs/SYNTAX.md) |
23
- | Typification grades, radicals | [../../docs/TYPIFICATION.md](../../docs/TYPIFICATION.md) |
24
- | Diagnostic code → fix table | [../../docs/DIAGNOSTICS.md](../../docs/DIAGNOSTICS.md) |
25
- | Portal REST API (live data) | [../../docs/PORTAL-API.md](../../docs/PORTAL-API.md) |
26
- | Lezer grammar pointers | [../../docs/GRAMMAR-REF.md](../../docs/GRAMMAR-REF.md) |
27
- | Package README | [../../README.md](../../README.md) |
16
+ Paths are relative to this file.
28
17
 
29
- When working from **npm**, the same tree lives under `node_modules/@rsconcept/rstool/` (use the Read tool on those paths from the project root).
18
+ - API, methods, stdio, error codes: [REFERENCE.md](REFERENCE.md).
19
+ - Worked examples and pitfalls: [EXAMPLES.md](EXAMPLES.md).
20
+ - Domain terms: [../../docs/DOMAIN.md](../../docs/DOMAIN.md).
21
+ - Schema design rules: [../../docs/CONCEPTUAL-SCHEMA.md](../../docs/CONCEPTUAL-SCHEMA.md).
22
+ - Constituents and validation: [../../docs/CONSTITUENTA.md](../../docs/CONSTITUENTA.md).
23
+ - Syntax: [../../docs/SYNTAX.md](../../docs/SYNTAX.md).
24
+ - Typification: [../../docs/TYPIFICATION.md](../../docs/TYPIFICATION.md).
25
+ - Definition testing with small conceptual models: [../../docs/MODEL-TESTING.md](../../docs/MODEL-TESTING.md).
26
+ - Diagnostics: [../../docs/DIAGNOSTICS.md](../../docs/DIAGNOSTICS.md).
27
+ - Portal REST reads: [../../docs/PORTAL-API.md](../../docs/PORTAL-API.md).
28
+ - Grammar pointers: [../../docs/GRAMMAR-REF.md](../../docs/GRAMMAR-REF.md).
30
29
 
31
- ## Protocol Summary
30
+ ## Workflow
32
31
 
33
- 1. **Start session**: `createSession`
34
- 2. **Add bases/constants**: type `basic` (`X*`), `constant` (`C*`) `definitionFormal: ''`
35
- 3. **Add derived**: terms, axioms, etc.—only after dependencies present
36
- 4. **Analyze scratch**: `analyzeExpression`
37
- 5. **Process diagnostics**: check `analysis.diagnostics`/`listDiagnostics`; fix by range
38
- 6. **Checkpoint**: `commitStep` (message optional)
39
- 7. **Model values**: `setConstituentaValue` / `setConstituentaValues` for base bindings (`{0:"a",1:"b"}`) or structured values; `getModelState`
40
- 8. **Evaluate**: `evaluateExpression` (scratch) or `evaluateConstituenta` / `recalculateModel` (stored definitions)
41
- 9. **Export/import**: persist with `exportSession`/`importSession` (includes `state.model`)
32
+ 1. `createSession`.
33
+ 2. Add `basic` (`X#`) and `constant` (`C#`) with `definitionFormal: ''`.
34
+ 3. Add dependencies before dependents.
35
+ 4. Use `analyzeExpression` before upsert when unsure.
36
+ 5. When unsure about semantics, build a tiny conceptual model and evaluate test data.
37
+ 6. Fix diagnostics by `from` / `to` range in `definitionFormal`.
38
+ 7. `commitStep` when the state is coherent.
39
+ 8. Set base/model values with `setConstituentaValue(s)`.
40
+ 9. Evaluate with `evaluateExpression`, `evaluateConstituenta`, or `recalculateModel`.
41
+ 10. Persist with `exportSession` / `importSession`.
42
+ 11. For user-uploadable Portal files, use `exportPortalSchema` for schema JSON or `exportPortalModel` for model JSON.
42
43
 
43
- **Clients**:
44
+ ## Portal REST
44
45
 
45
- - Node: use `RSToolWrapperClient`
46
- - Stdio process: `npx rstool-wrapper` — JSON per line
46
+ rstool never calls Portal REST itself. Fetch live data outside rstool, then import constituents with `addOrUpdateConstituenta`.
47
47
 
48
- ## API/REST
48
+ - UI host: `https://portal.acconcept.ru`.
49
+ - API host: `https://api.portal.acconcept.ru`.
50
+ - Useful reads: `/api/rsforms/{id}`, `/api/rsforms/{id}/details`, `/api/library/{id}/versions/{v}`, `/api/oss/{id}`, `/api/models/{id}`, `/schema`.
51
+ - Do not scrape SPA HTML or reuse UI query params like `?tab=`.
49
52
 
50
- For full reference see [../../docs/PORTAL-API.md](../../docs/PORTAL-API.md). Short form:
53
+ ## Syntax Cheatsheet
51
54
 
52
- - **Portal UI**: `https://portal.acconcept.ru`
53
- - **API**: `https://api.portal.acconcept.ru`
54
- - Endpoints: `GET /api/rsforms/{id}`, `GET /api/rsforms/{id}/details`, `GET /api/library/{id}/versions/{v}`, `GET /api/oss/{id}`, `GET /api/models/{id}`, OpenAPI at `GET /schema`.
55
- - Don't scrape SPA or use UI query params (`tab=`, etc.).
56
- - rstool itself never calls the REST API; bring data in via `addOrUpdateConstituenta` after fetching.
55
+ - Globals: `X1`, `C1`, `S1`, `D1`, `F1`, `P1`, `A1`, `T1`, `N1`, `R1`.
56
+ - Locals: `x`, `ξ`, `μ2`.
57
+ - Literals: `42`, `Z`, `∅`.
58
+ - Set expressions: `∪`, `∩`, `\`, `∆`, `×`, `ℬ(...)`, tuples, `Pr*`, `Fi*`.
59
+ - Logic: `¬`, `&`, `∨`, `⇒`, `⇔`, `∀`, `∃`, `=`, `≠`, `<`, `∈`, `⊆`.
60
+ - Parameterized expressions: `[arg1∈H1, arg2∈H2] body`.
57
61
 
58
- ## Constituent Types (`cstType`)
59
-
60
- | cstType | Example | Formal | Notes |
61
- | :-------- | :------ | :-------- | :-------------------------------------------------------- |
62
- | basic | X1 | **empty** | Required |
63
- | constant | C1 | **empty** | Required |
64
- | nominal | S1 | allowed | Naming |
65
- | structure | S1 | allowed | Typification grade; base concept + `convention` |
66
- | term | D1 | allowed | Formal **definition**; derived concept, computed in model |
67
- | axiom | A1 | allowed | Logical; computed in model; required to be TRUE |
68
- | statement | T1 | allowed | Logical; computed in model |
69
- | function | F1 | allowed | Parameterized; derived concept |
70
- | predicate | P1 | allowed | Parameterized; derived concept |
71
-
72
- - Non-empty formal for `basic`/`constant` ⇒ error `0x8862` (`definitionNotAllowed`)
73
- - Empty `basic`/`constant` always typified
74
- - **Interpretable** (can set value): `basic`, `constant`, `structure`
75
- - **Inferrable** (computed, do not set directly): `term`, `axiom`, `statement`
76
-
77
- ## Structure (`S#`) vs term (`D#`)
78
-
79
- The same field `definitionFormal` has **different roles** depending on `cstType`:
80
-
81
- | | `structure` (`S#`) | `term` (`D#`) |
82
- | -------------------------- | ------------------------------------------------------------------------------------ | --------------------------------------------------------------------- |
83
- | Role of `definitionFormal` | **Typification** — declares grade `H` (element structure) | **Definition** — declares how the concept is built from suppliers |
84
- | Concept class | **Undefined** — meaning from `convention` (+ axioms on `S#`) | **Derived** — meaning from the expression; no convention required |
85
- | Model interpretation | Values are **assigned** (or constrained by axioms); domain fills `S#` per convention | Value is **computed** via `evaluateConstituenta` / `recalculateModel` |
86
-
87
- **Same syntax, different semantics:** in `ℬ(X1×X1)` the fragment `X1×X1` is a **grade** (one ordered pair of base elements). On a **term** with body `X1×X1` alone, `×` builds the **full Cartesian product** — the set of all pairs from `X1`, not a relation typification.
88
-
89
- **Agent rule:** for a relation over `X1` (e.g. parent–child), upsert `S1` with `definitionFormal: 'ℬ(X1×X1)'` and a `convention`, then derive terms with projections/filters (`Pr1(S1)`, `Fi2[{ξ}](S1)`, …). Do not use bare `X1×X1` on a `term` when you meant the structure’s typification.
90
-
91
- See [EXAMPLES.md](EXAMPLES.md) (kinship-lite) and `../../examples/build-kinship-rsform.ts`.
92
-
93
- ## Syntax
94
-
95
- - **Globals**: `X1`, `C1`, `D1`, `F1`, `P1`, `A1`, `R1`
96
- - **Locals**: `x`, `ξ`, `μ2`
97
- - **Literals**: `42`, `Z`, `∅`
98
- - Full operator + precedence table: [../../docs/SYNTAX.md](../../docs/SYNTAX.md)
99
- - Grammar pointers: [../../docs/GRAMMAR-REF.md](../../docs/GRAMMAR-REF.md)
100
-
101
- ## Expression Types
102
-
103
- - **Set-theoretic**: `∪`, `∩`, `\`, `∆`, `×`, `∈`, `⊆`, `ℬ(...)`, tuples
104
- - **Logical**: `¬`, `&`, `∨`, `⇒`, `⇔`, `∀`, `∃`, comparisons `=`, `≠`, `<`
105
- - **Parameterized**: `[arg1∈H1, arg2∈H2] body`
106
- - Detailed semantics in [../../docs/SYNTAX.md](../../docs/SYNTAX.md); typification grades and radicals in [../../docs/TYPIFICATION.md](../../docs/TYPIFICATION.md).
107
-
108
- Always set `cstType` in upserts/analysis to true role.
62
+ Read tool output; do not infer types by inspection.
109
63
 
110
64
  ## Diagnostics Loop
111
65
 
112
- 1. Check `analysis.success`
113
- 2. If not, see `analysis.diagnostics` / `listDiagnostics`
114
- 3. Map `code` cause fix via [../../docs/DIAGNOSTICS.md](../../docs/DIAGNOSTICS.md)
115
- 4. Use `from`, `to` to patch `definitionFormal`; re-send
116
-
117
- Don't infer types—always read tool output.
66
+ 1. Check `analysis.success`.
67
+ 2. If false, read `analysis.diagnostics` or `listDiagnostics`.
68
+ 3. Map `code` to a fix in `DIAGNOSTICS.md`.
69
+ 4. Patch the reported `from` / `to` range.
70
+ 5. Re-run only after changing input.
118
71
 
119
72
  ## Declaration Order
120
73
 
121
- 1. All `basic`, `constant`
122
- 2. Core/critical first
123
- 3. Topological: dependencies before dependents (e.g. `D1` before `D2` if `D2` refers to `D1`)
124
- 4. Derived right after their sources
74
+ 1. `basic`, `constant`.
75
+ 2. Core structures and key concepts.
76
+ 3. Derived constituents in topological order.
77
+ 4. Axioms and statements after their references.
125
78
 
126
- ## Natural-language fields: keep one language
79
+ ## Natural-Language Fields
127
80
 
128
- When you create new constituents (concepts) or build a schema from scratch, the fields `term`, `definitionText`, and `convention` must be written **in one consistent natural language**:
81
+ Keep `term`, `definitionText`, and `convention` in one language.
129
82
 
130
- - If you are extending an existing schema/session, write these fields in the **same language that is already used** in the schemas text fields.
131
- - If you are creating a new schema from zero, write these fields in the **language of the users request**.
83
+ - Extending a schema: use the schema's existing language.
84
+ - New schema: use the user's request language.
132
85
 
133
86
  ## Checklist
134
87
 
135
- - [ ] `sessionId` obtained & tracked
136
- - [ ] Bases/constants are empty formal
137
- - [ ] All dependencies exist before upsert
138
- - [ ] Matching `cstType`
139
- - [ ] Diagnostics handled before commit/export
140
- - [ ] Base bindings set before evaluating expressions that reference base elements
141
- - [ ] For other details, open [REFERENCE.md](REFERENCE.md) or linked `docs/*.md`
88
+ - [ ] `sessionId` tracked.
89
+ - [ ] `basic` / `constant` formals are empty.
90
+ - [ ] Dependencies exist before upsert.
91
+ - [ ] `cstType` matches the role.
92
+ - [ ] Diagnostics handled before commit/export.
93
+ - [ ] Ambiguous semantics checked on a small model when data examples are available.
94
+ - [ ] Base values set before evaluation.
@@ -3,7 +3,7 @@
3
3
  ## rstool contract
4
4
 
5
5
  - Package: `@rsconcept/rstool`
6
- - Contract version: `1.2.0` (`CONTRACT_VERSION`)
6
+ - Contract version: `1.4.0` (`CONTRACT_VERSION`)
7
7
  - Core class: `RSToolAgent`
8
8
  - Public imports: `@rsconcept/rstool` and `@rsconcept/rstool/wrapper`
9
9
 
@@ -18,6 +18,8 @@
18
18
  | `listDiagnostics(sessionId, filters?)` | Accumulated diagnostics; optional `constituentId` filter |
19
19
  | `commitStep(sessionId, message?)` | Record revision checkpoint |
20
20
  | `exportSession(sessionId)` | JSON string `{ contractVersion, state, diagnostics }` |
21
+ | `exportPortalSchema(sessionId)` | Portal schema import JSON string using versioned schema shape |
22
+ | `exportPortalModel(sessionId)` | Portal model import JSON string using versioned model values shape |
21
23
  | `importSession(payload)` | New session from export |
22
24
  | `setConstituentaValue(sessionId, { target, type?, value })` | Set one base binding or structured value → `SessionModelState` |
23
25
  | `setConstituentaValues(sessionId, { items })` | Batch set values → `SessionModelState` |
@@ -43,6 +45,20 @@
43
45
 
44
46
  Omitted text fields default to `''` in stored state.
45
47
 
48
+ ### `SessionState` metadata
49
+
50
+ Set on `createSession(initial?)` or via `importSession`:
51
+
52
+ ```ts
53
+ {
54
+ alias: string; // library item alias
55
+ title: string; // display title
56
+ comment: string; // developer notes
57
+ }
58
+ ```
59
+
60
+ All default to `''` when omitted.
61
+
46
62
  ### Model and evaluation types
47
63
 
48
64
  ```ts
@@ -69,7 +85,7 @@ Base/constant bindings use `type: "basic"` and `value: { "0": "label", … }`. S
69
85
 
70
86
  Process: `npx rstool-wrapper`
71
87
 
72
- 1. **Ready** (no request): `{"id":null,"ok":true,"result":{"ready":true,"wrapper":"rstool-stdio","contractVersion":"1.2.0"}}`
88
+ 1. **Ready** (no request): `{"id":null,"ok":true,"result":{"ready":true,"wrapper":"rstool-stdio","contractVersion":"1.4.0"}}`
73
89
  2. **Request**: `{"id":"<unique>","method":"<name>","params":{...}}`
74
90
  3. **Response**: `{"id":"<same>","ok":true,"result":...}` or `{"id":"...","ok":false,"error":{"code":"...","message":"..."}}`
75
91
 
@@ -85,6 +101,8 @@ Example chain:
85
101
  {"id":"4","method":"listDiagnostics","params":{"sessionId":"…"}}
86
102
  {"id":"5","method":"commitStep","params":{"sessionId":"…","message":"checkpoint"}}
87
103
  {"id":"6","method":"exportSession","params":{"sessionId":"…"}}
104
+ {"id":"6a","method":"exportPortalSchema","params":{"sessionId":"…"}}
105
+ {"id":"6b","method":"exportPortalModel","params":{"sessionId":"…"}}
88
106
  {"id":"7","method":"setConstituentaValue","params":{"sessionId":"…","input":{"target":1,"value":{"0":"a","1":"b"}}}}
89
107
  {"id":"8","method":"evaluateExpression","params":{"sessionId":"…","input":{"expression":"1+2","cstType":"term"}}}
90
108
  {"id":"9","method":"evaluateConstituenta","params":{"sessionId":"…","input":{"constituentId":3}}}
@@ -109,7 +127,7 @@ interface AnalysisResult {
109
127
  - **Term graph**: directed dependencies between constituenta via alias references in definitions.
110
128
  - **`S#` vs `D#`**: same `×` token — in `ℬ(X1×X1)` on `S#` it forms a **grade** (pair type); in `X1×X1` on `D#` it is the **Cartesian product** (all pairs). Relations: `S#` + `convention`, then derived `D#` (`Pr1(S1)`, …).
111
129
 
112
- Intro (help): language is FOL-based; set vs logic expression split; parameterized templates for term/predicate functions; structural expressions reshape stages.
130
+ Intro (help): language is FOL-based; set vs logic expression split; parameterized templates for term/predicate functions.
113
131
 
114
132
  ## Grammar tokens (selected)
115
133
 
@@ -134,15 +152,16 @@ Standalone agents should consult the bundled distilled docs (`docs/*.md` inside
134
152
 
135
153
  | Topic | Bundled doc |
136
154
  | ------------------------------------ | ------------------------------------------ |
137
- | Identifiers, literals | `docs/SYNTAX.md` § *Identifier rules* |
155
+ | Identifiers, literals | `docs/SYNTAX.md` § _Identifier rules_ |
138
156
  | Grades, `Logic`, parameterized types | `docs/TYPIFICATION.md` |
139
- | Logical expressions | `docs/SYNTAX.md` § *Logical expressions* |
140
- | Set operators | `docs/SYNTAX.md` § *Set-theoretic* |
141
- | Integer arithmetic | `docs/SYNTAX.md` § *Arithmetic* |
142
- | Structural / typification reshaping | `docs/TYPIFICATION.md` § *Forming/derived* |
143
- | Quantifiers | `docs/SYNTAX.md` § *Quantifiers* |
144
- | Parameterized functions, templates | `docs/SYNTAX.md` § *Parameterised* |
145
- | Correctness / validation mindset | `docs/SYNTAX.md` § *Correctness model* |
157
+ | Logical expressions | `docs/SYNTAX.md` § _Logical expressions_ |
158
+ | Set operators | `docs/SYNTAX.md` § _Set-theoretic_ |
159
+ | Integer arithmetic | `docs/SYNTAX.md` § _Arithmetic_ |
160
+ | Structural / typification reshaping | `docs/TYPIFICATION.md` § _Forming/derived_ |
161
+ | Quantifiers | `docs/SYNTAX.md` § _Quantifiers_ |
162
+ | Parameterized functions, templates | `docs/SYNTAX.md` § _Parameterised_ |
163
+ | Correctness / validation mindset | `docs/SYNTAX.md` § _Correctness model_ |
164
+ | Definition semantic tests | `docs/MODEL-TESTING.md` |
146
165
  | Domain vocabulary | `docs/DOMAIN.md` |
147
166
  | Constituent fields and ordering | `docs/CONSTITUENTA.md` |
148
167
  | Portal REST API | `docs/PORTAL-API.md` |
@@ -166,6 +185,19 @@ Categories:
166
185
 
167
186
  `exportSession(sessionId)` returns a JSON string with `{ contractVersion, state, diagnostics }`.
168
187
 
188
+ - `state.alias`, `state.title`, `state.comment` — library-item metadata for Portal export (`comment` → JSON `description`).
169
189
  - `state.items[]` contains each constituent with `id`, `alias`, `cstType`, `definitionFormal`, optional text fields, and nested analysis output.
170
190
  - `state.model.items[]` is present when interpretation values have been set.
171
191
  - `diagnostics[]` contains accumulated diagnostics with offsets and codes.
192
+
193
+ ## Portal import JSON
194
+
195
+ For **Load from JSON** on an existing Portal schema or model:
196
+
197
+ - `exportPortalSchema(sessionId)` — schema file
198
+ - `exportPortalModel(sessionId)` — model file
199
+
200
+ Both return `contract_version` `1.0.0` plus required `title`, `alias`, `description`, and `items`. Schema files may include `attribution`. Values come from `state.title`, `state.alias`, and `state.comment` (empty fields fall back to `Conceptual schema` / `SCHEMA` or `Conceptual model` / `MODEL` and `""`).
201
+
202
+ - Schema `items[]`: versioned constituent fields (`cst_type`, `definition_formal`, `term_raw`, …).
203
+ - Model `items[]`: `{ id, type, value }` per binding.
@@ -20,13 +20,11 @@ Then continue with the canonical files below.
20
20
 
21
21
  ## Canonical files (read before rstool work)
22
22
 
23
- | What | Path |
24
- | :--- | :--- |
25
- | **Start here** — workflow, cstType, S# vs D# | `node_modules/@rsconcept/rstool/skills/rstool-helper/GUIDE.md` |
26
- | API, stdio, contract | `node_modules/@rsconcept/rstool/skills/rstool-helper/REFERENCE.md` |
27
- | Examples, pitfalls | `node_modules/@rsconcept/rstool/skills/rstool-helper/EXAMPLES.md` |
28
- | Language / domain docs | `node_modules/@rsconcept/rstool/docs/*.md` |
29
- | Install procedure | `node_modules/@rsconcept/rstool/skills/INSTALL.md` |
23
+ - **Start here** workflow: `node_modules/@rsconcept/rstool/skills/rstool-helper/GUIDE.md`
24
+ - API, stdio, contract: `node_modules/@rsconcept/rstool/skills/rstool-helper/REFERENCE.md`
25
+ - Examples, pitfalls: `node_modules/@rsconcept/rstool/skills/rstool-helper/EXAMPLES.md`
26
+ - Language / domain docs: `node_modules/@rsconcept/rstool/docs/*.md`
27
+ - Install procedure: `node_modules/@rsconcept/rstool/skills/INSTALL.md`
30
28
 
31
29
  Always open **GUIDE.md** first when starting a rstool task, then **REFERENCE.md** / **EXAMPLES.md** / relevant `docs/*.md` as needed.
32
30
 
@@ -34,4 +32,3 @@ Always open **GUIDE.md** first when starting a rstool task, then **REFERENCE.md*
34
32
 
35
33
  - Package: `@rsconcept/rstool`; wrapper: `npx rstool-wrapper`
36
34
  - `@rsconcept/domain` is installed as a dependency (analyzer, errors in `src/rslang/error.ts`)
37
- - Do not copy GUIDE, REFERENCE, EXAMPLES, or `docs/` into the project skills folder — read them from `node_modules` paths above
package/src/index.ts CHANGED
@@ -25,6 +25,12 @@ export {
25
25
  type EvaluationResult,
26
26
  type ListDiagnosticsFilters,
27
27
  type ModelValueState,
28
+ PORTAL_JSON_CONTRACT_VERSION,
29
+ type PortalImportMetadata,
30
+ type PortalModelImportData,
31
+ type PortalSchemaConstituenta,
32
+ type PortalSchemaImportData,
33
+ type PortalTermForm,
28
34
  type RecalculateModelResult,
29
35
  type RSToolAgentContract,
30
36
  type RSToolErrorDescription,