@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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +150 -0
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js +585 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/mappers/model-adapter.d.ts +27 -0
  7. package/dist/mappers/model-adapter.js +248 -0
  8. package/dist/mappers/model-adapter.js.map +1 -0
  9. package/dist/mappers/schema-adapter.d.ts +22 -0
  10. package/dist/mappers/schema-adapter.js +89 -0
  11. package/dist/mappers/schema-adapter.js.map +1 -0
  12. package/dist/mappers/types.d.ts +23 -0
  13. package/dist/mappers/types.js +22 -0
  14. package/dist/mappers/types.js.map +1 -0
  15. package/dist/models/analysis.d.ts +18 -0
  16. package/dist/models/analysis.js +1 -0
  17. package/dist/models/analysis.js.map +1 -0
  18. package/dist/models/common.d.ts +15 -0
  19. package/dist/models/common.js +12 -0
  20. package/dist/models/common.js.map +1 -0
  21. package/dist/models/constituenta.d.ts +38 -0
  22. package/dist/models/constituenta.js +1 -0
  23. package/dist/models/constituenta.js.map +1 -0
  24. package/dist/models/diagnostic.d.ts +17 -0
  25. package/dist/models/diagnostic.js +1 -0
  26. package/dist/models/diagnostic.js.map +1 -0
  27. package/dist/models/evaluation.d.ts +23 -0
  28. package/dist/models/evaluation.js +1 -0
  29. package/dist/models/evaluation.js.map +1 -0
  30. package/dist/models/index.d.ts +13 -0
  31. package/dist/models/index.js +491 -0
  32. package/dist/models/index.js.map +1 -0
  33. package/dist/models/model-value.d.ts +37 -0
  34. package/dist/models/model-value.js +1 -0
  35. package/dist/models/model-value.js.map +1 -0
  36. package/dist/models/rstool-agent.d.ts +36 -0
  37. package/dist/models/rstool-agent.js +480 -0
  38. package/dist/models/rstool-agent.js.map +1 -0
  39. package/dist/models/session.d.ts +29 -0
  40. package/dist/models/session.js +1 -0
  41. package/dist/models/session.js.map +1 -0
  42. package/dist/models/tool-contract.d.ts +33 -0
  43. package/dist/models/tool-contract.js +6 -0
  44. package/dist/models/tool-contract.js.map +1 -0
  45. package/dist/session/session-store.d.ts +26 -0
  46. package/dist/session/session-store.js +66 -0
  47. package/dist/session/session-store.js.map +1 -0
  48. package/dist/wrapper/client.d.ts +30 -0
  49. package/dist/wrapper/client.js +96 -0
  50. package/dist/wrapper/client.js.map +1 -0
  51. package/dist/wrapper/stdio-wrapper.d.ts +1 -0
  52. package/dist/wrapper/stdio-wrapper.js +679 -0
  53. package/dist/wrapper/stdio-wrapper.js.map +1 -0
  54. package/docs/CONSTITUENTA.md +55 -0
  55. package/docs/DIAGNOSTICS.md +125 -0
  56. package/docs/DOMAIN.md +89 -0
  57. package/docs/GRAMMAR-REF.md +98 -0
  58. package/docs/PORTAL-API.md +48 -0
  59. package/docs/README.md +15 -0
  60. package/docs/SYNTAX.md +139 -0
  61. package/docs/TYPIFICATION.md +79 -0
  62. package/package.json +76 -0
  63. package/skills/README.md +15 -0
  64. package/skills/rstool-helper/EXAMPLES.md +154 -0
  65. package/skills/rstool-helper/REFERENCE.md +169 -0
  66. package/skills/rstool-helper/SKILL.md +148 -0
  67. package/src/index.ts +43 -0
  68. package/src/mappers/model-adapter.ts +276 -0
  69. package/src/mappers/schema-adapter.ts +87 -0
  70. package/src/mappers/types.ts +35 -0
  71. package/src/models/analysis.ts +13 -0
  72. package/src/models/common.ts +17 -0
  73. package/src/models/constituenta.ts +35 -0
  74. package/src/models/diagnostic.ts +12 -0
  75. package/src/models/evaluation.ts +25 -0
  76. package/src/models/index.ts +33 -0
  77. package/src/models/model-value.ts +31 -0
  78. package/src/models/rstool-agent.test.ts +300 -0
  79. package/src/models/rstool-agent.ts +143 -0
  80. package/src/models/session.ts +22 -0
  81. package/src/models/tool-contract.ts +47 -0
  82. package/src/session/session-store.ts +81 -0
  83. package/src/wrapper/client.ts +116 -0
  84. package/src/wrapper/stdio-wrapper.ts +225 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/wrapper/stdio-wrapper.ts","../../src/mappers/model-adapter.ts","../../src/mappers/types.ts","../../src/mappers/schema-adapter.ts","../../src/session/session-store.ts","../../src/models/tool-contract.ts","../../src/models/rstool-agent.ts"],"sourcesContent":["#!/usr/bin/env node\nimport readline from 'node:readline';\n\nimport { RSToolAgent } from '../models/rstool-agent';\n\ninterface StdioRequest {\n id: string | number;\n method: string;\n params?: unknown;\n}\n\ninterface StdioResponse {\n id: string | number | null;\n ok: boolean;\n result?: unknown;\n error?: {\n code: string;\n message: string;\n details?: unknown;\n };\n}\n\nconst tool = new RSToolAgent();\n\nconst METHODS = [\n 'createSession',\n 'addOrUpdateConstituenta',\n 'analyzeExpression',\n 'getFormState',\n 'listDiagnostics',\n 'commitStep',\n 'exportSession',\n 'importSession',\n 'setConstituentaValue',\n 'setConstituentaValues',\n 'clearConstituentaValues',\n 'getModelState',\n 'evaluateExpression',\n 'evaluateConstituenta',\n 'recalculateModel'\n] as const;\n\nfunction writeResponse(response: StdioResponse): void {\n if (!process.stdout.writable || process.stdout.destroyed || process.stdout.writableEnded) {\n return;\n }\n try {\n process.stdout.write(`${JSON.stringify(response)}\\n`);\n } catch {\n // The client might have already closed stdout (EPIPE). Safe to ignore.\n }\n}\n\nfunction asObject(value: unknown): Record<string, unknown> {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return {};\n }\n return value as Record<string, unknown>;\n}\n\nfunction requiredString(input: Record<string, unknown>, key: string): string {\n const value = input[key];\n if (typeof value !== 'string' || value.length === 0) {\n throw new Error(`Missing or invalid \"${key}\"`);\n }\n return value;\n}\n\nasync function handleRequest(request: StdioRequest): Promise<StdioResponse> {\n try {\n const params = asObject(request.params);\n switch (request.method) {\n case 'ping':\n return { id: request.id, ok: true, result: { pong: true } };\n case 'methods':\n return { id: request.id, ok: true, result: METHODS };\n case 'createSession':\n return {\n id: request.id,\n ok: true,\n result: tool.createSession(params.initial as never)\n };\n case 'addOrUpdateConstituenta':\n return {\n id: request.id,\n ok: true,\n result: tool.addOrUpdateConstituenta(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'analyzeExpression':\n return {\n id: request.id,\n ok: true,\n result: tool.analyzeExpression(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'getFormState':\n return {\n id: request.id,\n ok: true,\n result: tool.getFormState(requiredString(params, 'sessionId'))\n };\n case 'listDiagnostics':\n return {\n id: request.id,\n ok: true,\n result: tool.listDiagnostics(requiredString(params, 'sessionId'), params.filters as never)\n };\n case 'commitStep':\n return {\n id: request.id,\n ok: true,\n result: tool.commitStep(requiredString(params, 'sessionId'), params.message as string | undefined)\n };\n case 'exportSession':\n return {\n id: request.id,\n ok: true,\n result: tool.exportSession(requiredString(params, 'sessionId'))\n };\n case 'importSession':\n return {\n id: request.id,\n ok: true,\n result: tool.importSession(requiredString(params, 'payload'))\n };\n case 'setConstituentaValue':\n return {\n id: request.id,\n ok: true,\n result: await tool.setConstituentaValue(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'setConstituentaValues':\n return {\n id: request.id,\n ok: true,\n result: await tool.setConstituentaValues(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'clearConstituentaValues':\n return {\n id: request.id,\n ok: true,\n result: await tool.clearConstituentaValues(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'getModelState':\n return {\n id: request.id,\n ok: true,\n result: tool.getModelState(requiredString(params, 'sessionId'))\n };\n case 'evaluateExpression':\n return {\n id: request.id,\n ok: true,\n result: tool.evaluateExpression(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'evaluateConstituenta':\n return {\n id: request.id,\n ok: true,\n result: tool.evaluateConstituenta(requiredString(params, 'sessionId'), params.input as never)\n };\n case 'recalculateModel':\n return {\n id: request.id,\n ok: true,\n result: tool.recalculateModel(requiredString(params, 'sessionId'))\n };\n default:\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'METHOD_NOT_FOUND',\n message: `Unknown method: ${request.method}`\n }\n };\n }\n } catch (error) {\n return {\n id: request.id ?? null,\n ok: false,\n error: {\n code: 'INTERNAL_ERROR',\n message: error instanceof Error ? error.message : 'Unknown error',\n details: error\n }\n };\n }\n}\n\nconst input = readline.createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n});\n\nwriteResponse({\n id: null,\n ok: true,\n result: {\n ready: true,\n wrapper: 'rstool-stdio',\n contractVersion: tool.contractVersion\n }\n});\n\ninput.on('line', line => {\n if (!line.trim()) {\n return;\n }\n try {\n const request = JSON.parse(line) as StdioRequest;\n if (!('id' in request) || !('method' in request)) {\n throw new Error('Request must include \"id\" and \"method\"');\n }\n void handleRequest(request).then(writeResponse);\n } catch (error) {\n writeResponse({\n id: null,\n ok: false,\n error: {\n code: 'BAD_REQUEST',\n message: error instanceof Error ? error.message : 'Invalid JSON'\n }\n });\n }\n});\n","import { Graph } from '@rsconcept/domain/graph/graph';\nimport { extractGlobals } from '@rsconcept/domain/rslang/api';\nimport { type ExpressionType, RSLangAnalyzer, type Value, type ValueClass } from '@rsconcept/domain/rslang';\nimport { isBaseSet } from '@rsconcept/domain/library/rsform-api';\nimport { type Constituenta, CstType, type RSForm } from '@rsconcept/domain/library/rsform';\nimport { RSEngine, type RSEngineServices } from '@rsconcept/domain/library/rsengine';\nimport { type BasicBinding, EvalStatus, type RSModel } from '@rsconcept/domain/library/rsmodel';\nimport {\n isInferrable,\n isInterpretable,\n toBasicBinding,\n validateBasicBindingData,\n validateValueData\n} from '@rsconcept/domain/library/rsmodel-api';\n\nimport {\n type ConstituentaState,\n type EvaluationResult,\n type RecalculateModelResult,\n type SessionModelState,\n type SessionState,\n type SetConstituentaValueInput\n} from '../models';\nimport { toPublicError } from './types';\n\nconst SESSION_MODEL_ID = 0;\n\nexport class ModelAdapter {\n public async setConstituentaValue(\n session: SessionState,\n input: SetConstituentaValueInput\n ): Promise<SessionModelState> {\n this.validateSetInput(session, input);\n const engine = this.createEngine(session);\n const cst = session.items.find(item => item.id === input.target)!;\n const frontendType = cst.cstType;\n\n if (isBaseSet(frontendType)) {\n const binding = toBasicBinding(input.value as Record<string | number, string>);\n await engine.setBasicValue(input.target, binding);\n } else {\n await engine.setStructureValue(input.target, input.value as Value);\n }\n session.updatedAt = new Date().toISOString();\n return structuredClone(session.model);\n }\n\n public async setConstituentaValues(\n session: SessionState,\n input: { items: SetConstituentaValueInput[] }\n ): Promise<SessionModelState> {\n for (const item of input.items) {\n await this.setConstituentaValue(session, item);\n }\n return structuredClone(session.model);\n }\n\n public async clearConstituentaValues(session: SessionState, ids: number[]): Promise<SessionModelState> {\n const engine = this.createEngine(session);\n for (const id of ids) {\n await engine.resetValue(id);\n session.updatedAt = new Date().toISOString();\n }\n return structuredClone(session.model);\n }\n\n public evaluateExpression(session: SessionState, expression: string, cstType: CstType): EvaluationResult {\n const engine = this.createEngine(session);\n const result = engine.evaluateExpression(expression, cstType);\n const status =\n result.value === null\n ? result.errors.length > 0\n ? EvalStatus.EVAL_FAIL\n : EvalStatus.EMPTY\n : EvalStatus.HAS_DATA;\n return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);\n }\n\n public evaluateConstituenta(session: SessionState, constituentId: number): EvaluationResult {\n const cst = session.items.find(item => item.id === constituentId);\n if (!cst) {\n throw new Error(`Unknown constituent: ${constituentId}`);\n }\n const engine = this.createEngine(session);\n const result = engine.calculateCst(constituentId);\n const status = engine.getCstStatus(constituentId);\n return toPublicEvaluationResult(result.value, result.errors, result.iterations, result.cacheHits, status);\n }\n\n public recalculateModel(session: SessionState): RecalculateModelResult {\n const engine = this.createEngine(session);\n engine.recalculateAll();\n const items = session.items.map(item => ({\n id: item.id,\n alias: item.alias,\n value: engine.getCstValue(item.id) as number | number[] | null,\n status: engine.getCstStatus(item.id)\n }));\n return { items };\n }\n\n public createEngine(session: SessionState): RSEngine {\n const schema = buildRSFormFromSession(session);\n const model = buildRSModelFromSession(session);\n const engine = new RSEngine(SESSION_MODEL_ID, createInMemoryServices(session));\n engine.loadData(schema, model);\n return engine;\n }\n\n private validateSetInput(session: SessionState, input: SetConstituentaValueInput): void {\n const cst = session.items.find(item => item.id === input.target);\n if (!cst) {\n throw new Error(`Unknown constituent: ${input.target}`);\n }\n const frontendType = cst.cstType;\n if (!isInterpretable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is not interpretable`);\n }\n if (isInferrable(frontendType)) {\n throw new Error(`Constituent ${cst.alias} is inferrable and cannot be set directly`);\n }\n if (isBaseSet(frontendType)) {\n if (!validateBasicBindingData(input.value)) {\n throw new Error(`Invalid basic binding for ${cst.alias}`);\n }\n return;\n }\n if (!validateValueData(input.value)) {\n throw new Error(`Invalid structured value for ${cst.alias}`);\n }\n }\n}\n\nfunction createInMemoryServices(session: SessionState): RSEngineServices {\n return {\n setCstValue: async ({ data }) => {\n for (const item of data) {\n const entry = {\n id: item.target,\n type: item.type,\n value: item.data as Value | BasicBinding\n };\n const index = session.model.items.findIndex(existing => existing.id === item.target);\n if (index === -1) {\n session.model.items.push(entry);\n } else {\n session.model.items[index] = entry;\n }\n }\n },\n clearValues: async ({ data }) => {\n const ids = new Set(data.items);\n session.model.items = session.model.items.filter(item => !ids.has(item.id));\n }\n };\n}\n\nfunction buildRSFormFromSession(session: SessionState): RSForm {\n const graph = new Graph<number>();\n const cstByAlias = new Map<string, Constituenta>();\n const cstByID = new Map<number, Constituenta>();\n const analyzer = new RSLangAnalyzer();\n\n const items = session.items.map(item => {\n const cst = toFrontendConstituenta(item);\n cstByAlias.set(cst.alias, cst);\n cstByID.set(cst.id, cst);\n graph.addNode(cst.id);\n if (item.cstType === CstType.BASE) {\n analyzer.addBase(cst.alias);\n }\n if (cst.effectiveType) {\n analyzer.setGlobal(cst.alias, cst.effectiveType, cst.analysis.valueClass as ValueClass | null);\n }\n return cst;\n });\n\n for (const cst of items) {\n for (const alias of extractGlobals(cst.definition_formal)) {\n const source = cstByAlias.get(alias);\n if (source) {\n graph.addEdge(source.id, cst.id);\n }\n }\n }\n\n return {\n id: 0,\n items,\n cstByAlias,\n cstByID,\n graph,\n analyzer,\n inheritance: [],\n attribution: [],\n attribution_graph: graph.clone(),\n oss: [],\n models: [],\n editors: [],\n versions: [],\n is_produced: false,\n is_attributive: false,\n version: 'latest'\n } as unknown as RSForm;\n}\n\nfunction buildRSModelFromSession(session: SessionState): RSModel {\n return {\n id: SESSION_MODEL_ID,\n schema: 0,\n editors: [],\n items: session.model.items.map(item => ({\n id: item.id,\n type: item.type,\n value: item.value as Value | BasicBinding\n }))\n } as unknown as RSModel;\n}\n\nfunction toFrontendConstituenta(item: ConstituentaState): Constituenta {\n const effectiveType = (item.analysis.type ?? null) as ExpressionType | null;\n return {\n id: item.id,\n alias: item.alias,\n cst_type: item.cstType,\n definition_formal: item.definitionFormal,\n definition_raw: item.definitionFormal,\n definition_resolved: item.definitionFormal,\n term_raw: item.term,\n term_resolved: item.term,\n term_forms: [],\n convention: item.convention,\n typification_manual: '',\n value_is_property: false,\n crucial: false,\n attributes: [],\n homonyms: [],\n formalDuplicates: [],\n analysis: {\n success: item.analysis.success,\n type: effectiveType,\n valueClass: item.analysis.valueClass\n },\n effectiveType,\n is_type_mismatch: false,\n schema: 0,\n cst_class: 'derived',\n status: item.analysis.success ? 'verified' : 'incorrect',\n is_template: false,\n is_simple_expression: true,\n parent_schema_index: 0,\n parent_schema: null,\n is_inherited: false,\n has_inherited_children: false,\n spawn: [],\n spawn_alias: []\n } as unknown as Constituenta;\n}\n\nfunction toPublicEvaluationResult(\n value: Value | null,\n errors: { code: number; from: number; to: number; params?: readonly string[] }[],\n iterations: number,\n cacheHits: number,\n status: EvalStatus\n): EvaluationResult {\n const diagnostics = errors.map(toPublicError);\n return {\n success: diagnostics.length === 0 && value !== null,\n value: value as EvaluationResult['value'],\n status,\n iterations,\n cacheHits,\n diagnostics\n };\n}\n","import { type ValueClass } from '@rsconcept/domain/rslang';\n\nimport { type AnalysisResult, type RSToolErrorDescription } from '../models';\n\nexport interface DomainErrorLike {\n code: number;\n from: number;\n to: number;\n params?: readonly string[];\n}\n\nexport interface DomainAnalysisLike {\n success: boolean;\n type: Record<string, unknown> | null;\n valueClass: ValueClass | null;\n errors: DomainErrorLike[];\n}\n\nexport function toPublicError(error: DomainErrorLike): RSToolErrorDescription {\n return {\n code: error.code,\n from: error.from,\n to: error.to,\n params: error.params\n };\n}\n\nexport function toPublicAnalysis(analysis: DomainAnalysisLike): AnalysisResult {\n return {\n success: analysis.success,\n type: analysis.type,\n valueClass: analysis.valueClass,\n diagnostics: analysis.errors.map(toPublicError)\n };\n}\n","import { RSLangAnalyzer, type AnalysisFull, type ValueClass } from '@rsconcept/domain/rslang';\nimport { getAnalysisFor } from '@rsconcept/domain/library/rsform-api';\nimport { CstType, type RSForm } from '@rsconcept/domain/library/rsform';\n\nimport {\n type AnalysisResult,\n type ConstituentaDraft,\n type ConstituentaState,\n type DiagnosticRecord,\n type SessionState\n} from '../models';\nimport { toPublicAnalysis, toPublicError } from './types';\n\nexport class SchemaAdapter {\n public analyzeAgainstSession(\n session: SessionState,\n draft: ConstituentaDraft\n ): { result: AnalysisResult; diagnostics: DiagnosticRecord[] } {\n const analyzer = this.buildAnalyzer(session);\n const schema = this.toPseudoRSFormState(session, analyzer);\n const analysis = getAnalysisFor(draft.definitionFormal, draft.cstType, schema as unknown as RSForm, draft.alias);\n const result = toPublicAnalysis({\n success: analysis.success,\n type: analysis.type as Record<string, unknown> | null,\n valueClass: analysis.valueClass,\n errors: analysis.errors\n });\n return {\n result,\n diagnostics: analysis.errors.map(error => ({\n sessionId: session.sessionId,\n constituentId: draft.id,\n expression: draft.definitionFormal,\n error: toPublicError(error)\n }))\n };\n }\n\n public mergeStateWithDraft(\n session: SessionState,\n draft: ConstituentaDraft,\n analysis: AnalysisResult\n ): ConstituentaState {\n const state: ConstituentaState = {\n ...draft,\n term: draft.term ?? '',\n definitionText: draft.definitionText ?? '',\n convention: draft.convention ?? '',\n analysis\n };\n const index = session.items.findIndex(item => item.id === draft.id);\n if (index === -1) {\n session.items.push(state);\n } else {\n session.items[index] = state;\n }\n session.updatedAt = new Date().toISOString();\n return state;\n }\n\n public toPseudoRSFormState(\n session: SessionState,\n analyzer: RSLangAnalyzer\n ): Pick<RSForm, 'items' | 'cstByAlias' | 'analyzer'> {\n const cstByAlias = new Map(session.items.map(item => [item.alias, item]));\n return {\n items: session.items as unknown as RSForm['items'],\n cstByAlias: cstByAlias as unknown as RSForm['cstByAlias'],\n analyzer\n };\n }\n\n private buildAnalyzer(session: SessionState): RSLangAnalyzer {\n const analyzer = new RSLangAnalyzer();\n for (const item of session.items) {\n if (item.cstType === CstType.BASE) {\n analyzer.addBase(item.alias);\n }\n analyzer.setGlobal(\n item.alias,\n item.analysis.type as AnalysisFull['type'],\n item.analysis.valueClass as ValueClass | null\n );\n }\n return analyzer;\n }\n}\n","import { randomUUID } from 'node:crypto';\n\nimport {\n type DiagnosticRecord,\n type ListDiagnosticsFilters,\n type SessionHandle,\n type SessionRevision,\n type SessionState\n} from '../models';\n\ninterface SessionEnvelope {\n state: SessionState;\n diagnostics: DiagnosticRecord[];\n}\n\nexport class SessionStore {\n private sessions = new Map<string, SessionEnvelope>();\n\n public create(initial?: Partial<SessionState>, contractVersion?: string): SessionHandle {\n const now = new Date().toISOString();\n const sessionId = initial?.sessionId ?? randomUUID();\n const state: SessionState = {\n sessionId,\n createdAt: initial?.createdAt ?? now,\n updatedAt: now,\n revisions: initial?.revisions ?? [],\n items: initial?.items ?? [],\n model: initial?.model ?? { items: [] }\n };\n this.sessions.set(sessionId, {\n state,\n diagnostics: []\n });\n return {\n sessionId,\n contractVersion: contractVersion ?? '1.0.0'\n };\n }\n\n public get(sessionId: string): SessionEnvelope {\n const found = this.sessions.get(sessionId);\n if (!found) {\n throw new Error(`Unknown session: ${sessionId}`);\n }\n return found;\n }\n\n public replaceState(sessionId: string, nextState: SessionState): void {\n const found = this.get(sessionId);\n found.state = {\n ...nextState,\n updatedAt: new Date().toISOString()\n };\n }\n\n public addRevision(sessionId: string, message?: string): SessionRevision {\n const found = this.get(sessionId);\n const revision: SessionRevision = {\n revisionId: randomUUID(),\n at: new Date().toISOString(),\n message\n };\n found.state.revisions.push(revision);\n found.state.updatedAt = revision.at;\n return revision;\n }\n\n public appendDiagnostics(sessionId: string, records: DiagnosticRecord[]): void {\n const found = this.get(sessionId);\n found.diagnostics.push(...records);\n found.state.updatedAt = new Date().toISOString();\n }\n\n public listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[] {\n const found = this.get(sessionId);\n if (!filters?.constituentId) {\n return [...found.diagnostics];\n }\n return found.diagnostics.filter(record => record.constituentId === filters.constituentId);\n }\n}\n","import { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';\nimport {\n type AddOrUpdateConstituentaInput,\n type AddOrUpdateConstituentaResult\n} from './constituenta';\nimport {\n type DiagnosticRecord,\n type ListDiagnosticsFilters\n} from './diagnostic';\nimport {\n type EvaluateConstituentaInput,\n type EvaluateExpressionInput,\n type EvaluationResult\n} from './evaluation';\nimport {\n type ClearConstituentaValuesInput,\n type RecalculateModelResult,\n type SessionModelState,\n type SetConstituentaValueInput,\n type SetConstituentaValuesInput\n} from './model-value';\nimport {\n type SessionHandle,\n type SessionRevision,\n type SessionState\n} from './session';\n\nexport const CONTRACT_VERSION = '1.2.0';\n\nexport interface RSToolAgentContract {\n readonly contractVersion: string;\n createSession(initial?: Partial<SessionState>): SessionHandle;\n addOrUpdateConstituenta(sessionId: string, input: AddOrUpdateConstituentaInput): AddOrUpdateConstituentaResult;\n analyzeExpression(sessionId: string, input: AnalyzeExpressionInput): AnalysisResult;\n getFormState(sessionId: string): SessionState;\n listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters): DiagnosticRecord[];\n commitStep(sessionId: string, message?: string): SessionRevision;\n exportSession(sessionId: string): string;\n importSession(payload: string): SessionHandle;\n setConstituentaValue(sessionId: string, input: SetConstituentaValueInput): Promise<SessionModelState>;\n setConstituentaValues(sessionId: string, input: SetConstituentaValuesInput): Promise<SessionModelState>;\n clearConstituentaValues(sessionId: string, input: ClearConstituentaValuesInput): Promise<SessionModelState>;\n getModelState(sessionId: string): SessionModelState;\n evaluateExpression(sessionId: string, input: EvaluateExpressionInput): EvaluationResult;\n evaluateConstituenta(sessionId: string, input: EvaluateConstituentaInput): EvaluationResult;\n recalculateModel(sessionId: string): RecalculateModelResult;\n}\n","import { ModelAdapter } from '../mappers/model-adapter';\nimport { SchemaAdapter } from '../mappers/schema-adapter';\nimport { SessionStore } from '../session/session-store';\nimport { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';\nimport {\n type AddOrUpdateConstituentaInput,\n type AddOrUpdateConstituentaResult\n} from './constituenta';\nimport { type ListDiagnosticsFilters } from './diagnostic';\nimport {\n type EvaluateConstituentaInput,\n type EvaluateExpressionInput,\n type EvaluationResult\n} from './evaluation';\nimport {\n type ClearConstituentaValuesInput,\n type RecalculateModelResult,\n type SessionModelState,\n type SetConstituentaValueInput,\n type SetConstituentaValuesInput\n} from './model-value';\nimport { type SessionHandle, type SessionRevision, type SessionState } from './session';\nimport { CONTRACT_VERSION, type RSToolAgentContract } from './tool-contract';\n\nexport class RSToolAgent implements RSToolAgentContract {\n public readonly contractVersion = CONTRACT_VERSION;\n private readonly sessions = new SessionStore();\n private readonly adapter = new SchemaAdapter();\n private readonly evaluation = new ModelAdapter();\n\n public createSession(initial?: Partial<SessionState>): SessionHandle {\n return this.sessions.create(initial, this.contractVersion);\n }\n\n public addOrUpdateConstituenta(\n sessionId: string,\n input: AddOrUpdateConstituentaInput\n ): AddOrUpdateConstituentaResult {\n const envelope = this.sessions.get(sessionId);\n const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, input.draft);\n const state = this.adapter.mergeStateWithDraft(envelope.state, input.draft, result);\n this.sessions.appendDiagnostics(sessionId, diagnostics);\n return {\n state,\n diagnostics\n };\n }\n\n public analyzeExpression(sessionId: string, input: AnalyzeExpressionInput): AnalysisResult {\n const envelope = this.sessions.get(sessionId);\n const { result, diagnostics } = this.adapter.analyzeAgainstSession(envelope.state, {\n id: -1,\n alias: '_analysis',\n cstType: input.cstType,\n definitionFormal: input.expression\n });\n this.sessions.appendDiagnostics(\n sessionId,\n diagnostics.map(item => ({ ...item, constituentId: undefined }))\n );\n return result;\n }\n\n public getFormState(sessionId: string): SessionState {\n const envelope = this.sessions.get(sessionId);\n return structuredClone(envelope.state);\n }\n\n public listDiagnostics(sessionId: string, filters?: ListDiagnosticsFilters) {\n return this.sessions.listDiagnostics(sessionId, filters);\n }\n\n public commitStep(sessionId: string, message?: string): SessionRevision {\n return this.sessions.addRevision(sessionId, message);\n }\n\n public exportSession(sessionId: string): string {\n const envelope = this.sessions.get(sessionId);\n return JSON.stringify(\n {\n contractVersion: this.contractVersion,\n state: envelope.state,\n diagnostics: envelope.diagnostics\n },\n null,\n 2\n );\n }\n\n public importSession(payload: string): SessionHandle {\n const parsed = JSON.parse(payload) as {\n state: SessionState;\n };\n if (!parsed.state.model) {\n parsed.state.model = { items: [] };\n }\n return this.sessions.create(parsed.state, this.contractVersion);\n }\n\n public async setConstituentaValue(\n sessionId: string,\n input: SetConstituentaValueInput\n ): Promise<SessionModelState> {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.setConstituentaValue(envelope.state, input);\n }\n\n public async setConstituentaValues(\n sessionId: string,\n input: SetConstituentaValuesInput\n ): Promise<SessionModelState> {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.setConstituentaValues(envelope.state, input);\n }\n\n public async clearConstituentaValues(\n sessionId: string,\n input: ClearConstituentaValuesInput\n ): Promise<SessionModelState> {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.clearConstituentaValues(envelope.state, input.items);\n }\n\n public getModelState(sessionId: string): SessionModelState {\n const envelope = this.sessions.get(sessionId);\n return structuredClone(envelope.state.model);\n }\n\n public evaluateExpression(sessionId: string, input: EvaluateExpressionInput): EvaluationResult {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.evaluateExpression(envelope.state, input.expression, input.cstType);\n }\n\n public evaluateConstituenta(sessionId: string, input: EvaluateConstituentaInput): EvaluationResult {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.evaluateConstituenta(envelope.state, input.constituentId);\n }\n\n public recalculateModel(sessionId: string): RecalculateModelResult {\n const envelope = this.sessions.get(sessionId);\n return this.evaluation.recalculateModel(envelope.state);\n }\n}\n"],"mappings":";;;AACA,OAAO,cAAc;;;ACDrB,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAC/B,SAA8B,sBAAmD;AACjF,SAAS,iBAAiB;AAC1B,SAA4B,eAA4B;AACxD,SAAS,gBAAuC;AAChD,SAA4B,kBAAgC;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACKA,SAAS,cAAc,OAAgD;AAC5E,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,IAAI,MAAM;AAAA,IACV,QAAQ,MAAM;AAAA,EAChB;AACF;AAEO,SAAS,iBAAiB,UAA8C;AAC7E,SAAO;AAAA,IACL,SAAS,SAAS;AAAA,IAClB,MAAM,SAAS;AAAA,IACf,YAAY,SAAS;AAAA,IACrB,aAAa,SAAS,OAAO,IAAI,aAAa;AAAA,EAChD;AACF;;;ADTA,IAAM,mBAAmB;AAElB,IAAM,eAAN,MAAmB;AAAA,EACxB,MAAa,qBACX,SACAA,QAC4B;AAC5B,SAAK,iBAAiB,SAASA,MAAK;AACpC,UAAM,SAAS,KAAK,aAAa,OAAO;AACxC,UAAM,MAAM,QAAQ,MAAM,KAAK,UAAQ,KAAK,OAAOA,OAAM,MAAM;AAC/D,UAAM,eAAe,IAAI;AAEzB,QAAI,UAAU,YAAY,GAAG;AAC3B,YAAM,UAAU,eAAeA,OAAM,KAAwC;AAC7E,YAAM,OAAO,cAAcA,OAAM,QAAQ,OAAO;AAAA,IAClD,OAAO;AACL,YAAM,OAAO,kBAAkBA,OAAM,QAAQA,OAAM,KAAc;AAAA,IACnE;AACA,YAAQ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L,IAAI,QAAQ,MAAM;AAAA,MAClB,IAAI;AAAA,MACJ,OAAO;AAAA,QACL,MAAM;AAAA,QACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,QAClD,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAM,QAAQ,SAAS,gBAAgB;AAAA,EACrC,OAAO,QAAQ;AAAA,EACf,WAAW;AACb,CAAC;AAED,cAAc;AAAA,EACZ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,IACT,iBAAiB,KAAK;AAAA,EACxB;AACF,CAAC;AAED,MAAM,GAAG,QAAQ,UAAQ;AACvB,MAAI,CAAC,KAAK,KAAK,GAAG;AAChB;AAAA,EACF;AACA,MAAI;AACF,UAAM,UAAU,KAAK,MAAM,IAAI;AAC/B,QAAI,EAAE,QAAQ,YAAY,EAAE,YAAY,UAAU;AAChD,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AACA,SAAK,cAAc,OAAO,EAAE,KAAK,aAAa;AAAA,EAChD,SAAS,OAAO;AACd,kBAAc;AAAA,MACZ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,OAAO;AAAA,QACL,MAAM;AAAA,QACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MACpD;AAAA,IACF,CAAC;AAAA,EACH;AACF,CAAC;","names":["input","RSLangAnalyzer","CstType","RSLangAnalyzer","CstType","input","input"]}
@@ -0,0 +1,55 @@
1
+ # Constituenta reference
2
+
3
+ Distilled from `help-cst-attributes`, the rstool skill table, and `CONTEXT.md`. Use this when upserting constituents via `addOrUpdateConstituenta`.
4
+
5
+ ## `ConstituentaDraft` fields
6
+
7
+ | Field | Required | Description |
8
+ |-------|----------|-------------|
9
+ | `id` | yes | Stable integer id within the session |
10
+ | `alias` | yes | Display alias (`X1`, `D5`, `F2`) — must match `cstType` prefix |
11
+ | `cstType` | yes | One of `CstType` values (see table below) |
12
+ | `definitionFormal` | yes (may be empty) | RS expression. Empty for `basic` / `constant` |
13
+ | `term` | optional | Natural-language term name |
14
+ | `definitionText` | optional | Natural-language definition / interpretation |
15
+ | `convention` | optional | Convention text for undefined concepts |
16
+
17
+ Omitted text fields default to `''` in stored state.
18
+
19
+ ## `cstType` table
20
+
21
+ | `cstType` (value) | Prefix | Formal definition | Notes |
22
+ |-------|--------|-------|-------|
23
+ | `basic` (`X`) | `X#` | **must be empty** | Base set; non-empty formal → `definitionNotAllowed` |
24
+ | `constant` (`C`) | `C#` | **must be empty** | Constant set; same rule |
25
+ | `nominal` (`N`) | `N#` | allowed | Free vocabulary item, no semantic constraint |
26
+ | `structure` (`S`) | `S#` | allowed | Structured undefined concept, defines the typification grade |
27
+ | `term` (`D`) | `D#` | allowed | Derived term (set / value) |
28
+ | `axiom` (`A`) | `A#` | allowed (must be `Logic`) | Logical statement asserting a requirement |
29
+ | `statement` (`T`) | `T#` | allowed (must be `Logic`) | Logical assertion about the model |
30
+ | `function` (`F`) | `F#` | allowed (parameterised) | Term-function |
31
+ | `predicate` (`P`) | `P#` | allowed (parameterised) | Predicate-function |
32
+
33
+ ### Interpretability and inferrability
34
+
35
+ - **Interpretable** (a value can be assigned via `setConstituentaValue`): `basic`, `constant`, `structure`, `term`, `axiom`, `statement`.
36
+ - **Inferrable** (computed from definitions, never set directly): `term`, `axiom`, `statement`. Assigning to an inferrable raises an error.
37
+
38
+ In practice, agents only set values for `basic` and `constant` constituents (and `structure` when an explicit value is required). Everything else is recalculated via `evaluateConstituenta` / `recalculateModel`.
39
+
40
+ ## Validation rules
41
+
42
+ 1. **Prefix ↔ `cstType`**: `alias` letter must match the type prefix.
43
+ 2. **Empty formal for undefined concepts**: `basic` and `constant` must have `definitionFormal === ''`. Any non-empty value triggers `definitionNotAllowed` (`0x8862`).
44
+ 3. **Dependency declaration order**: every global identifier referenced in `definitionFormal` must correspond to an already-upserted constituent in the session.
45
+ 4. **Logical-only definitions**: `axiom` and `statement` definitions must typecheck to `Logic`; otherwise `expectedLogic`.
46
+ 5. **Empty derived expression**: a derived constituent with empty `definitionFormal` triggers `cstEmptyDerived`.
47
+
48
+ ## Recommended upsert order
49
+
50
+ 1. All `basic` (`X#`) and `constant` (`C#`) constituents (empty formal).
51
+ 2. Core `structure` (`S#`) and crucial concepts.
52
+ 3. Topological order of derived concepts: every dependency upserted before its dependent.
53
+ 4. Axioms and statements after the constituents they reference.
54
+
55
+ Use `analyzeExpression` on a scratch expression before upsert; use `addOrUpdateConstituenta` only when the expression typechecks. Read `result.diagnostics` for actionable error info and patch by `from`/`to` ranges.
@@ -0,0 +1,125 @@
1
+ # Diagnostics reference
2
+
3
+ Distilled from `@rsconcept/domain/rslang/error.ts`, the Portal i18n catalog `rslang.en.ts`, and rstool `EXAMPLES.md`. Use this when an `analyzeExpression` / `addOrUpdateConstituenta` call returns errors in `result.diagnostics`.
4
+
5
+ ## How to read a diagnostic
6
+
7
+ Each `DiagnosticRecord` carries:
8
+
9
+ - `code` — numeric `RSErrorCode` (see table). The high nibble identifies the class (`0x82xx` lexer, `0x84xx` parser, `0x88xx` semantic, `0x81xx` runtime, `0x28xx` warnings).
10
+ - `params` — substitution arguments for the message (identifier names, sets, etc.).
11
+ - `from`, `to` — character positions in the *expression text* that should be patched. Always edit `definitionFormal` by range.
12
+ - `constituentId` — present in session diagnostics from `listDiagnostics`.
13
+
14
+ Map a `code` to a human-readable message via `@rsconcept/domain` helpers (`getRSErrorPrefix`, `RSErrorClass`). If you need a fully localised text, consult the Portal i18n keys `tx.rslang.error.*`; rstool does not bundle those.
15
+
16
+ ## Class table
17
+
18
+ | Mask | Class | Behaviour |
19
+ |------|-------|-----------|
20
+ | `0x8400` family | Parser | Lexical / syntactic problems; expression cannot be analysed further |
21
+ | `0x8800` family | Semantic | Definition-level issues (types, scopes, structure) |
22
+ | `0x8100` family | Runtime / evaluation | Raised during `evaluateExpression` / `evaluateConstituenta` |
23
+ | `0x2800` family | Warning | Not critical; expression still valid |
24
+ | `0x88Cx` | Schema-level | Rules enforced by the schema layer (`cstEmptyDerived`, `definitionNotAllowed`) |
25
+
26
+ `isCritical(code)` returns `false` only for `localDoubleDeclare` and `localNotUsed`.
27
+
28
+ ## High-priority codes
29
+
30
+ ### Parser
31
+
32
+ | Code | Symbol | Typical cause | Agent fix |
33
+ |------|--------|---------------|-----------|
34
+ | `0x8400` | `unknownSyntax` | Stray token / typo | Re-tokenise around `from`–`to` |
35
+ | `0x8406` | `missingParenthesis` | Unmatched `(` `)` | Insert matching paren near `to` |
36
+ | `0x8407` | `missingCurlyBrace` | Unmatched `{` `}` | Insert matching brace |
37
+ | `0x8408` | `missingSquareBracket` | Unmatched `[` `]` | Insert matching bracket |
38
+ | `0x8409` | `bracketMismatch` | Mixed bracket types | Replace one bracket to match |
39
+ | `0x840A` | `doubleParenthesis` | `(( ... ))` redundancy | Remove one pair |
40
+ | `0x840B` | `missingOpenBracket` | Closing bracket without opener | Insert opening bracket earlier |
41
+ | `0x8415` | `expectedLocal` | Quantifier or filter expects a local | Provide a lowercase variable |
42
+ | `0x8416` | `expectedType` | Missing typification annotation | Add explicit grade |
43
+
44
+ ### Semantic — locals and scopes
45
+
46
+ | Code | Symbol | Typical cause | Agent fix |
47
+ |------|--------|---------------|-----------|
48
+ | `0x8801` | `localUndeclared` | Variable used before declaration | Bind via quantifier / parameter |
49
+ | `0x8802` | `localShadowing` | Local redeclared in inner scope | Rename inner variable |
50
+ | `0x8815` | `localOutOfScope` | Local escapes its binder | Move usage inside the binder |
51
+ | `0x2801` | `localDoubleDeclare` | Same local declared twice | Warning; rename |
52
+ | `0x2802` | `localNotUsed` | Declared local never referenced | Warning; remove or use |
53
+
54
+ ### Semantic — types
55
+
56
+ | Code | Symbol | Typical cause | Agent fix |
57
+ |------|--------|---------------|-----------|
58
+ | `0x8803` | `typesNotEqual` | Operands have different typifications | Convert / project to matching grade |
59
+ | `0x8804` | `globalNotTyped` | Referenced global has no typification | Ensure dependency is upserted and typechecked first |
60
+ | `0x8805` | `invalidDecart` | Cartesian product on non-set operand | Wrap operand in `ℬ(...)` if appropriate |
61
+ | `0x8806` | `invalidBoolean` | `ℬ(...)` applied to a non-set | Use a set-grade operand |
62
+ | `0x8807` | `invalidTypeOperation` | Operator not defined for these types | Re-check the typification table |
63
+ | `0x8808` | `invalidCard` | `card(...)` on a non-set | Use a set operand |
64
+ | `0x8809` | `invalidDebool` | `debool(...)` on non-singleton | Ensure exactly one element first |
65
+ | `0x880B` | `globalFuncWithoutArgs` | Calling a function without `[]` args | Provide arguments |
66
+ | `0x8810` | `invalidReduce` | `red(...)` on something not `ℬ(ℬ(...))` | Wrap in extra `ℬ` or change source |
67
+ | `0x8811` | `invalidProjectionTuple` | `pr_i((a,b))` with out-of-range index | Use valid index |
68
+ | `0x8812` | `invalidProjectionSet` | `Pr_i(S)` on non-tuple set | Use a tuple-set source |
69
+ | `0x8813` | `invalidEnumeration` | `{a, b}` with incompatible element types | Match element typifications |
70
+ | `0x8814` | `invalidCortegeDeclare` | Tuple declaration with mismatched arity | Match declaration to use |
71
+ | `0x8816` | `invalidElementPredicate` | `ξ ∈ S` typification mismatch | Match `ξ`'s grade to elements of `S` |
72
+ | `0x8817` | `invalidEmptySetUsage` | `∅` in a position that needs a concrete element | Provide explicit typified operand |
73
+ | `0x8818` | `invalidArgsArity` | Wrong number of arguments to function | Match function declaration |
74
+ | `0x8819` | `invalidArgumentType` | Argument typification mismatch | Adjust caller or function signature |
75
+ | `0x881C` | `globalStructure` | Wrong structural shape of referenced global | Re-check `structure` constituent shape |
76
+ | `0x8821` | `radicalUsage` | Radical used outside parameter domain | Move usage into parameter declarations |
77
+ | `0x8822` | `invalidFilterArgumentType` | `Fi[D](S)` parameter does not match index typification | Match `D` to projected grade |
78
+ | `0x8823` | `invalidFilterArity` | Filter parameter count ≠ multi-index length | Align lengths |
79
+ | `0x8824` | `arithmeticNotSupported` | Arithmetic operator outside integer context | Use integer expressions |
80
+ | `0x8825` | `typesNotCompatible` | Generic type incompatibility | Re-examine surrounding context |
81
+ | `0x8826` | `orderingNotSupported` | `<`, `≤` etc. used outside integer | Ensure operands are integers |
82
+ | `0x8827` | `expectedLogic` | Definition where `Logic` is required | Wrap in logical expression or change `cstType` |
83
+ | `0x8828` | `expectedSetexpr` | Definition where STE required | Convert from logic to set expression |
84
+ | `0x8829` | `invalidArgumentCortegeDeclare` | Tuple parameter declaration mismatch | Match tuple arity in declaration |
85
+
86
+ ### Schema / cstType validation
87
+
88
+ | Code | Symbol | Trigger | Fix |
89
+ |------|--------|---------|-----|
90
+ | `0x8861` | `cstEmptyDerived` | Derived constituent with empty `definitionFormal` | Provide a definition |
91
+ | `0x8862` | `definitionNotAllowed` | `basic`/`constant` with non-empty formal | Clear the formal |
92
+ | `0x8840` | `globalNoValue` | Reference to global without a model value | Set value via `setConstituentaValue` before evaluating |
93
+ | `0x8841` | `invalidPropertyUsage` | Property-only constituent used where value is required | Use a different operand |
94
+
95
+ ### Runtime (evaluation)
96
+
97
+ | Code | Symbol | Cause |
98
+ |------|--------|-------|
99
+ | `0x8100` | `calcUnknownError` | Unspecified evaluation failure |
100
+ | `0x8101` | `setOverflow` | Intermediate set too large |
101
+ | `0x8102` | `booleanBaseLimit` | `ℬ(X)` overflow at runtime |
102
+ | `0x8103` | `calcGlobalMissing` | Referenced global has no current value |
103
+ | `0x8104` | `iterationsLimit` | Iterative computation exceeded limit |
104
+ | `0x8105` | `calcInvalidDebool` | `debool` on multi-element set at runtime |
105
+ | `0x8106` | `iterateInfinity` | Iteration over an infinite set |
106
+ | `0x8107` | `calculationNotSupported` | Construct cannot be evaluated |
107
+
108
+ ## Common agent mistakes
109
+
110
+ - **Setting a value on a derived constituent**: derived `term`, `axiom`, `statement` are inferrable. Use `evaluateConstituenta` / `recalculateModel`. Setting them throws `Constituent <alias> is inferrable and cannot be set directly`.
111
+ - **Forgetting empty formal on `basic` / `constant`**: results in `definitionNotAllowed`. Pass `definitionFormal: ''`.
112
+ - **Out-of-order dependencies**: referencing `D2` before upserting it raises `localUndeclared` or `globalNotTyped`. Always topologically sort.
113
+ - **Wrong cstType for the role**: `axiom`/`statement` whose definition is not `Logic` raises `expectedLogic`. A `term` whose body is logical raises `expectedSetexpr`.
114
+ - **Negative literals**: `-5` does not parse. Use `0 - 5`.
115
+ - **Radicals in result expressions**: `[α∈R1] (α, R1)` raises `radicalUsage`. Use radicals only in parameter domains.
116
+ - **Evaluating before bindings are set**: `evaluateExpression` referencing `X1` without a `setConstituentaValue(..., target: <X1.id>)` raises `calcGlobalMissing` (`0x8103`).
117
+
118
+ ## Diagnostics loop
119
+
120
+ 1. Run `analyzeExpression` on a scratch.
121
+ 2. If `analysis.success === false`, iterate `analysis.diagnostics`.
122
+ 3. For each diagnostic: read `code`, `from`, `to`, and `params`. Map `code` via `getRSErrorPrefix` if you need a category prefix.
123
+ 4. Patch `definitionFormal` based on the range — never blindly retry without changing the input.
124
+ 5. Re-send. Repeat until success.
125
+ 6. Only then call `addOrUpdateConstituenta` to commit the constituent into the session.
package/docs/DOMAIN.md ADDED
@@ -0,0 +1,89 @@
1
+ # Domain reference
2
+
3
+ Compact English distillation of the canonical Russian domain glossary (`CONTEXT.md`). Read this first if you are an agent unfamiliar with the Concept Portal vocabulary.
4
+
5
+ ## Core concepts
6
+
7
+ - **Subject domain** — a sphere of human activity that requires coordination and communication.
8
+ - **Conceptual schema (`КС`)** — a formal system of definitions for a subject domain, made of constituents.
9
+ - **Conceptual model (`РСМодель`)** — a pairing of a conceptual schema with an interpretation in concrete data.
10
+ - **Operations Synthesis Schema (`ОСС`)** — a graph of load and synthesis operations that drives schema construction and evolution.
11
+ - **RS language (`родоструктурная экспликация`)** — the formal genus-structure language used to define concepts, relations and operations inside a schema.
12
+ - **Typification** — the computable structural type of a constituent's formal definition; the formal constraint on admissible interpretations.
13
+ - **Term graph** — a directed dependency graph over constituents; an edge means "constituent A appears in constituent B's definition".
14
+
15
+ ## Constituents
16
+
17
+ A **constituent** is the atomic building block of a conceptual schema. Each constituent may carry a term, a convention, a typification, a formal definition, a textual interpretation, and a comment. By role, a constituent is either undefined, derived, or a statement.
18
+
19
+ Constituent aliases follow a strict prefix scheme:
20
+
21
+ | Alias prefix | Role | Notes |
22
+ |-----|------|-------|
23
+ | `N#` | Nominoid | Free vocabulary item, no formal definition |
24
+ | `X#` | Base set | Undefined concept, set of distinguishable elements |
25
+ | `C#` | Constant set | Undefined concept, set-theoretic constant with operations |
26
+ | `S#` | Structured concept | Undefined concept with explicit typification, axioms, convention |
27
+ | `D#` | Term | Derived concept (set / value) defined by a formal expression |
28
+ | `F#` | Term-function | Parameterised derived concept yielding an STE |
29
+ | `P#` | Predicate-function | Parameterised derived concept yielding a logical expression |
30
+ | `A#` | Axiom | Logical statement asserting requirements |
31
+ | `T#` | Statement | Logical assertion about the model |
32
+ | `R#` | Radical | Template placeholder for arbitrary typification |
33
+
34
+ **Undefined concepts** (`X#`, `C#`, `S#`) are introduced by conventions (and optional axioms); they have **no formal definition**. **Derived concepts** (`D#`, `F#`, `P#`, `A#`, `T#`) carry a formal expression and must follow declaration order — every referenced constituent must already exist.
35
+
36
+ A **crucial constituent** is marked as content-bearing for filtering / focus; it has no semantic effect on the formal calculus.
37
+
38
+ ## Statuses
39
+
40
+ Each constituent has one of the following correctness statuses:
41
+
42
+ | Status | Meaning |
43
+ |--------|---------|
44
+ | Unknown | Not yet validated |
45
+ | OK | Validated as correct |
46
+ | Error | Validation failed |
47
+ | Property | Defines a non-computable set; only membership tests are admissible |
48
+ | Incalculable | Cannot be evaluated directly (e.g. expected exponential blow-up) |
49
+
50
+ ## RSModel evaluation states
51
+
52
+ In a conceptual model each item has one of the following evaluation statuses:
53
+
54
+ | Status | Meaning |
55
+ |--------|---------|
56
+ | `NO_EVAL` (1) | Not evaluated (definition is not interpretable) |
57
+ | `NOT_PROCESSED` (2) | Interpretation has not been computed yet |
58
+ | `INVALID_DATA` (3) | Provided data is invalid |
59
+ | `EVAL_FAIL` (4) | Evaluation raised an error |
60
+ | `AXIOM_FALSE` (5) | Axiom evaluated to FALSE |
61
+ | `EMPTY` (6) | Result is the empty set |
62
+ | `HAS_DATA` (7) | Interpretation computed and non-empty |
63
+
64
+ ## Synthesis and OSS
65
+
66
+ - **Load operation** attaches an existing schema to the OSS graph.
67
+ - **Synthesis operation** combines operand schemas via an **identification table** (pairs of constituents to be treated as equivalent) and produces a result schema with **inherited constituents**.
68
+ - **Cross-cutting changes** propagate edits from a **source constituent** to its **inherited constituents** through the OSS. Inherited constituents are not edited directly.
69
+ - **Diamond synthesis** uses operand schemas with shared ancestors.
70
+ - **Concept block** is a nominal grouping of schemas inside the OSS.
71
+
72
+ ## Relationships
73
+
74
+ - A conceptual schema **contains** many constituents.
75
+ - A conceptual model **interprets** exactly one schema at a given state.
76
+ - An OSS **contains** load and synthesis operations.
77
+ - A synthesis operation **consumes** one or more input schemas plus an identification table and **produces** a result schema with inherited constituents.
78
+ - Cross-cutting changes **propagate** from a source constituent to its inherited descendants.
79
+ - The term graph is **derived** from the formal definitions of constituents.
80
+
81
+ ## Dependency vocabulary
82
+
83
+ - **Consumers** — constituents that mention this one in their definitions.
84
+ - **Suppliers** — constituents this one mentions in its definition.
85
+ - **Dependents** — direct and transitive consumers.
86
+ - **Influencers** — direct and transitive suppliers.
87
+ - **Generating expression** — a definition referencing a single external constituent with no added content.
88
+ - **Base concept (for generation)** — the constituent on which a generating expression is built.
89
+ - **Generated concept** — a constituent produced from a generating expression.
@@ -0,0 +1,98 @@
1
+ # Grammar reference (pointers)
2
+
3
+ The full Lezer grammar ships inside `@rsconcept/domain` at `node_modules/@rsconcept/domain/src/rslang/parser/rslang.grammar`. The generated parser is `parser.ts` in the same folder. Below is a compact token map agents can use without opening the grammar.
4
+
5
+ ## Token classes
6
+
7
+ | Class | Tokens / examples |
8
+ |-------|-------------------|
9
+ | Whitespace | space, tab, newline |
10
+ | Integer literal | `0`, `42` |
11
+ | Empty set | `∅` |
12
+ | Integer set | `Z` |
13
+ | Globals | `X#`, `C#`, `S#`, `D#`, `F#`, `P#`, `A#`, `T#`, `N#`, `R#` |
14
+ | Locals | `x`, `ξ`, `μ2`, `y1` |
15
+ | Punctuation | `(`, `)`, `[`, `]`, `{`, `}`, `,`, `;` |
16
+ | Comment | none — RSLang has no comments inside formal expressions |
17
+
18
+ ## Set / structural operators
19
+
20
+ | Token | Symbol |
21
+ |-------|--------|
22
+ | Union | `∪` |
23
+ | Intersection | `∩` |
24
+ | Difference | `\` |
25
+ | Symmetric difference | `∆` |
26
+ | Cartesian product | `×` |
27
+ | Boolean | `ℬ` |
28
+ | Sum set | `red` |
29
+ | Singleton | `bool` |
30
+ | Desingleton | `debool` |
31
+ | Small projection | `pr1`, `pr1,3`, … |
32
+ | Large projection | `Pr1`, `Pr2,4`, … |
33
+ | Filter | `Fi1[D](S)`, `Fi1,2[D](S)` |
34
+ | Cardinality | `card` |
35
+
36
+ ## Predicates
37
+
38
+ | Token | Symbol |
39
+ |-------|--------|
40
+ | Membership | `∈` |
41
+ | Non-membership | `∉` |
42
+ | Inclusion | `⊆` |
43
+ | Strict inclusion | `⊂` |
44
+ | Non-inclusion | `⊄` |
45
+ | Equality | `=` |
46
+ | Inequality | `≠` |
47
+ | Less | `<` |
48
+ | Less-or-equal | `≤` |
49
+ | Greater | `>` |
50
+ | Greater-or-equal | `≥` |
51
+
52
+ ## Logical connectives
53
+
54
+ | Token | Symbol |
55
+ |-------|--------|
56
+ | Negation | `¬` |
57
+ | Conjunction | `&` |
58
+ | Disjunction | `∨` |
59
+ | Implication | `⇒` |
60
+ | Equivalence | `⇔` |
61
+
62
+ ## Quantifiers
63
+
64
+ | Token | Symbol |
65
+ |-------|--------|
66
+ | Universal | `∀` |
67
+ | Existential | `∃` |
68
+
69
+ ## Declarators
70
+
71
+ | Token | Form |
72
+ |-------|------|
73
+ | Function declaration | `F# ::= [<params>] <body STE>` |
74
+ | Predicate declaration | `P# ::= [<params>] <body LE>` |
75
+ | Parameter declaration | `α ∈ <STE>` (commas separate; commas inside `[]`) |
76
+ | Function call | `F#[<arg1>, <arg2>, …]` |
77
+
78
+ ## Precedence (from highest to lowest)
79
+
80
+ 1. Function calls, projections, boolean
81
+ 2. Cartesian product `×`
82
+ 3. Multiplicative `*`
83
+ 4. Additive `+`, `-`
84
+ 5. Set operators `∪`, `∩`, `\`, `∆`
85
+ 6. Predicates (`∈`, `=`, `<`, …)
86
+ 7. Negation `¬`
87
+ 8. Conjunction `&`
88
+ 9. Disjunction `∨`
89
+ 10. Implication `⇒`
90
+ 11. Equivalence `⇔`
91
+
92
+ Multi-index tokens inside projections / filters are parsed as a comma-separated list of natural numbers.
93
+
94
+ ## When to consult the full grammar
95
+
96
+ - Grammar conflicts or surprising error positions — read `rslang.grammar` directly.
97
+ - Adding new operators or precedence rules — must be done in the domain package, not in rstool.
98
+ - Lezer terms / token IDs — see `@rsconcept/domain/src/rslang/parser/token.ts` and `parser.terms.ts`.
@@ -0,0 +1,48 @@
1
+ # Portal REST API (read-only reference)
2
+
3
+ When an agent needs to **inspect existing** RSForms, OSS, or RSModels persisted on the Portal, use the REST API on `api.portal.acconcept.ru`. The rstool library itself never calls the Portal API — it always works on in-memory sessions. This document is for agents that combine rstool sessions with data fetched from a live Portal.
4
+
5
+ ## Hosts
6
+
7
+ - **UI:** `https://portal.acconcept.ru/`
8
+ - **REST API:** `https://api.portal.acconcept.ru/`
9
+ - **Local dev:** path prefix `/api/...`, base URL from `VITE_PORTAL_BACKEND`.
10
+
11
+ ## Path rewrite rules
12
+
13
+ Drop UI hash query params (`?tab=`, etc.). Keep numeric ids exactly as the UI shows them.
14
+
15
+ | Portal UI path | REST target |
16
+ |----------------|-------------|
17
+ | `/rsforms/:id` | `GET /api/rsforms/:id` (metadata: owner, titles) |
18
+ | `/rsforms/:id` (full payload) | `GET /api/rsforms/:id/details` |
19
+ | `/rsforms/:id` (a saved version) | `GET /api/library/:id/versions/:version` |
20
+ | `/oss/:id` | `GET /api/oss/:id` (and the sibling OSS viewset routes) |
21
+ | `/models/:id` | `GET /api/models/:id` (RSModel router) |
22
+
23
+ ## OpenAPI
24
+
25
+ Machine-readable schema:
26
+
27
+ ```
28
+ GET https://api.portal.acconcept.ru/schema
29
+ ```
30
+
31
+ Prefer `/schema` for JSON. The Swagger UI is separate.
32
+
33
+ ## What rstool consumes
34
+
35
+ rstool itself works with in-memory sessions via `RSToolAgent` or the stdio wrapper. To bridge between the REST payload and a rstool session, the typical flow is:
36
+
37
+ 1. `GET /api/rsforms/:id/details` to fetch the persisted RSForm.
38
+ 2. Convert the response (constituents, formal definitions, term, convention, etc.) into a series of `addOrUpdateConstituenta` calls inside a fresh `createSession`.
39
+ 3. Operate offline: analyse, edit, evaluate, then `exportSession` for hand-off.
40
+
41
+ There is no backend write path in rstool: edits never round-trip to the Portal automatically. Publish changes back to the Portal through the existing Portal UI or REST writes.
42
+
43
+ ## Don'ts
44
+
45
+ - Do not scrape the SPA HTML.
46
+ - Do not pass UI hash params (`?tab=editor`, etc.) to REST.
47
+ - Do not call `/api/rsforms/:id/details` for trivial metadata — `GET /api/rsforms/:id` is cheaper.
48
+ - Do not assume the API host is the same as the UI host in production — they are different.
package/docs/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # rstool docs
2
+
3
+ Standalone English reference distilled from the Portal manuals and `CONTEXT.md`. Bundled with `@rsconcept/rstool` so external agents never need to read the Portal frontend source tree.
4
+
5
+ | File | Read when |
6
+ |------|-----------|
7
+ | [`DOMAIN.md`](DOMAIN.md) | You need the Concept Portal vocabulary (constituenta, conceptual schema/model, OSS, synthesis). |
8
+ | [`CONSTITUENTA.md`](CONSTITUENTA.md) | You are upserting constituents — fields, `cstType` table, validation rules, recommended order. |
9
+ | [`SYNTAX.md`](SYNTAX.md) | You are constructing RSLang expressions — operators, quantifiers, parameterised functions, examples. |
10
+ | [`TYPIFICATION.md`](TYPIFICATION.md) | You are interpreting `AnalysisResult.type` / `valueClass` or constructing template expressions with radicals. |
11
+ | [`DIAGNOSTICS.md`](DIAGNOSTICS.md) | You received `analysis.diagnostics` and need to map error codes to fixes. |
12
+ | [`PORTAL-API.md`](PORTAL-API.md) | You need to fetch an existing RSForm/OSS/RSModel from the live Portal REST API. |
13
+ | [`GRAMMAR-REF.md`](GRAMMAR-REF.md) | You need a compact token / precedence table; the full grammar lives in `@rsconcept/domain`. |
14
+
15
+ For the rstool agent contract itself (methods, types, stdio protocol) see [`../skills/rstool-helper/REFERENCE.md`](../skills/rstool-helper/REFERENCE.md).