@rsconcept/rstool 0.1.0 → 0.2.1

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 (77) hide show
  1. package/README.md +21 -26
  2. package/dist/analysis-JiwOYDKx.d.ts +16 -0
  3. package/dist/common-DxLg3eXX.d.ts +17 -0
  4. package/dist/constituenta-Dnd6iToB.d.ts +36 -0
  5. package/dist/diagnostic-BMYvciz8.d.ts +15 -0
  6. package/dist/evaluation-CCVYH0wA.d.ts +21 -0
  7. package/dist/index.d.ts +12 -15
  8. package/dist/index.js +7 -585
  9. package/dist/mappers/model-adapter.d.ts +18 -23
  10. package/dist/mappers/model-adapter.js +183 -231
  11. package/dist/mappers/model-adapter.js.map +1 -1
  12. package/dist/mappers/schema-adapter.d.ts +16 -18
  13. package/dist/mappers/schema-adapter.js +55 -84
  14. package/dist/mappers/schema-adapter.js.map +1 -1
  15. package/dist/mappers/types.d.ts +15 -16
  16. package/dist/mappers/types.js +16 -17
  17. package/dist/mappers/types.js.map +1 -1
  18. package/dist/model-value-SFAVj0dw.d.ts +35 -0
  19. package/dist/models/analysis.d.ts +2 -18
  20. package/dist/models/analysis.js +1 -1
  21. package/dist/models/common.d.ts +2 -15
  22. package/dist/models/common.js +1 -8
  23. package/dist/models/constituenta.d.ts +2 -38
  24. package/dist/models/constituenta.js +1 -1
  25. package/dist/models/diagnostic.d.ts +2 -17
  26. package/dist/models/diagnostic.js +1 -1
  27. package/dist/models/evaluation.d.ts +2 -23
  28. package/dist/models/evaluation.js +1 -1
  29. package/dist/models/index.d.ts +10 -13
  30. package/dist/models/index.js +4 -491
  31. package/dist/models/model-value.d.ts +2 -37
  32. package/dist/models/model-value.js +1 -1
  33. package/dist/models/rstool-agent.d.ts +2 -36
  34. package/dist/models/rstool-agent.js +90 -477
  35. package/dist/models/rstool-agent.js.map +1 -1
  36. package/dist/models/session.d.ts +2 -29
  37. package/dist/models/session.js +1 -1
  38. package/dist/models/tool-contract.d.ts +2 -33
  39. package/dist/models/tool-contract.js +5 -5
  40. package/dist/models/tool-contract.js.map +1 -1
  41. package/dist/rstool-agent-DkeH5Qml.d.ts +33 -0
  42. package/dist/session/session-store.d.ts +14 -21
  43. package/dist/session/session-store.js +59 -63
  44. package/dist/session/session-store.js.map +1 -1
  45. package/dist/session-BHGCCLfQ.d.ts +24 -0
  46. package/dist/tool-contract-CsGqg_0P.d.ts +30 -0
  47. package/dist/wrapper/client.d.ts +26 -24
  48. package/dist/wrapper/client.js +90 -93
  49. package/dist/wrapper/client.js.map +1 -1
  50. package/dist/wrapper/stdio-wrapper.d.ts +1 -1
  51. package/dist/wrapper/stdio-wrapper.js +166 -664
  52. package/dist/wrapper/stdio-wrapper.js.map +1 -1
  53. package/docs/CONCEPTUAL-SCHEMA.md +168 -0
  54. package/docs/CONSTITUENTA.md +46 -23
  55. package/docs/DIAGNOSTICS.md +79 -74
  56. package/docs/DOMAIN.md +32 -30
  57. package/docs/GRAMMAR-REF.md +55 -55
  58. package/docs/PORTAL-API.md +7 -10
  59. package/docs/README.md +1 -0
  60. package/docs/SYNTAX.md +32 -32
  61. package/docs/TYPIFICATION.md +14 -9
  62. package/package.json +8 -7
  63. package/skills/INSTALL.md +35 -0
  64. package/skills/README.md +17 -9
  65. package/skills/rstool-helper/EXAMPLES.md +51 -10
  66. package/skills/rstool-helper/GUIDE.md +141 -0
  67. package/skills/rstool-helper/REFERENCE.md +5 -3
  68. package/skills/rstool-helper/SKILL.md +23 -134
  69. package/dist/index.js.map +0 -1
  70. package/dist/models/analysis.js.map +0 -1
  71. package/dist/models/common.js.map +0 -1
  72. package/dist/models/constituenta.js.map +0 -1
  73. package/dist/models/diagnostic.js.map +0 -1
  74. package/dist/models/evaluation.js.map +0 -1
  75. package/dist/models/index.js.map +0 -1
  76. package/dist/models/model-value.js.map +0 -1
  77. package/dist/models/session.js.map +0 -1
@@ -1 +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,aAAY,oBAAI,KAAK,GAAE,YAAY;AAC3C,WAAO,gBAAgB,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O;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"]}
1
+ {"version":3,"file":"stdio-wrapper.js","names":[],"sources":["../../src/wrapper/stdio-wrapper.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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,eAAe,QAAQ,WAAW,GAAG,OAAO,KAAc;GAC5F;GACF,KAAK,wBACH,OAAO;IACL,IAAI,QAAQ;IACZ,IAAI;IACJ,QAAQ,KAAK,qBAAqB,eAAe,QAAQ,WAAW,GAAG,OAAO,KAAc;GAC9F;GACF,KAAK,oBACH,OAAO;IACL,IAAI,QAAQ;IACZ,IAAI;IACJ,QAAQ,KAAK,iBAAiB,eAAe,QAAQ,WAAW,CAAC;GACnE;GACF,SACE,OAAO;IACL,IAAI,QAAQ,MAAM;IAClB,IAAI;IACJ,OAAO;KACL,MAAM;KACN,SAAS,mBAAmB,QAAQ;IACtC;GACF;EACJ;CACF,SAAS,OAAO;EACd,OAAO;GACL,IAAI,QAAQ,MAAM;GAClB,IAAI;GACJ,OAAO;IACL,MAAM;IACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;IAClD,SAAS;GACX;EACF;CACF;AACF;AAEA,MAAM,QAAQ,SAAS,gBAAgB;CACrC,OAAO,QAAQ;CACf,WAAW;AACb,CAAC;AAED,cAAc;CACZ,IAAI;CACJ,IAAI;CACJ,QAAQ;EACN,OAAO;EACP,SAAS;EACT,iBAAiB,KAAK;CACxB;AACF,CAAC;AAED,MAAM,GAAG,SAAQ,SAAQ;CACvB,IAAI,CAAC,KAAK,KAAK,GACb;CAEF,IAAI;EACF,MAAM,UAAU,KAAK,MAAM,IAAI;EAC/B,IAAI,EAAE,QAAQ,YAAY,EAAE,YAAY,UACtC,MAAM,IAAI,MAAM,4CAAwC;EAE1D,AAAK,cAAc,OAAO,EAAE,KAAK,aAAa;CAChD,SAAS,OAAO;EACd,cAAc;GACZ,IAAI;GACJ,IAAI;GACJ,OAAO;IACL,MAAM;IACN,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GACpD;EACF,CAAC;CACH;AACF,CAAC"}
@@ -0,0 +1,168 @@
1
+ # Conceptual schema (КС) — agent recommendations
2
+
3
+ This note complements the mechanistic references:
4
+
5
+ - `CONSTITUENTA.md` — how to upsert constituents correctly (fields, order, validation)
6
+ - `SYNTAX.md` / `TYPIFICATION.md` — how to construct correct RS expressions
7
+
8
+ Here we focus on **how to design and analyse a conceptual schema as a system of constituents**.
9
+
10
+ ## What makes a schema valuable
11
+
12
+ The value of a conceptual schema is the **diversity of concepts expressed in it**.
13
+
14
+ - A good schema forms a **domain thesaurus**: a stable set of terms and distinctions that people can use for communication and decision-making.
15
+ - “Diversity” is not the same as “many aliases”. Prefer concepts that introduce **new distinctions** (new criteria, roles, constraints, invariants) instead of synonyms.
16
+
17
+ Practical agent heuristic:
18
+
19
+ - If you can remove a derived concept `D#` and lose no important language for reasoning, it is probably redundant.
20
+ - If stakeholders keep rephrasing the same thing in different words, the schema likely misses one or more constituents that capture the missing distinction.
21
+
22
+ ## Rule for text fields (term / definitionText / convention)
23
+
24
+ When you write natural-language text in a schema, follow this strict rule:
25
+
26
+ - **Use only terms that are introduced in the schema itself.**
27
+
28
+ Rationale:
29
+
30
+ - Text definitions that rely on “external vocabulary” quietly import unstated assumptions and weaken the schema as a shared thesaurus.
31
+
32
+ Agent checklist:
33
+
34
+ - When you add a new `definitionText`, scan it for nouns/terms. If a term is essential, introduce it explicitly (typically as `N#`, `X#`, `S#`, or a derived `D#`).
35
+ - Prefer short “closed-world” definitions: explain a concept using already-introduced schema terms plus logical connectives (“and”, “or”, “not”), quantifiers (“for all”, “exists”), and references to RS expressions.
36
+
37
+ ## Modeling genus structures (родовые структуры) as `S#`
38
+
39
+ `S#` constituents represent **base structured concepts**: their `definitionFormal` is a **typification** (grade), and their meaning is set by `convention` plus axioms.
40
+
41
+ ### Define structure components explicitly
42
+
43
+ For a genus structure `S#`, it is often useful to define **all components** as named derived terms.
44
+
45
+ Why:
46
+
47
+ - It gives names to projections / reduced parts of a structure, making the thesaurus usable.
48
+ - It shortens later formulas and prevents agents from repeating long projection chains differently in different places.
49
+
50
+ Typical pattern for a binary relation over a base set:
51
+
52
+ - `X1` — base set (undefined)
53
+ - `S1 : ℬ(X1×X1)` — relation as a structure (undefined, meaning via convention)
54
+ - Component terms:
55
+ - `D_dom := Pr1(S1)` — “domain” / “left elements”
56
+ - `D_cod := Pr2(S1)` — “codomain” / “right elements”
57
+ - `D_pairs := red(bool(S1))` is usually nonsense; instead name the parts you truly use
58
+ - For higher-arity structures, define `Pr1`, `Pr2`, … and relevant multi-projections (`Pr1,3`, etc.)
59
+
60
+ More generally:
61
+
62
+ - **Projections** (`Pr*`, `pr*`) are the main tool for naming components.
63
+ - **Reduce** (`red`) is useful when a component is a set-of-sets and you need a flattened union; introduce a named `D#` when you use `red` in more than one place.
64
+
65
+ ### Avoid “anonymous structure usage”
66
+
67
+ If later definitions repeatedly use expressions like `Pr2(Fi1[D](S7))`, it is usually a sign that:
68
+
69
+ - the schema is missing a named constituent for that concept, or
70
+ - the structure `S7` is underspecified (needs conventions/axioms).
71
+
72
+ Prefer to introduce:
73
+
74
+ - an intermediate derived term `D#` for the filtered relation/set, and
75
+ - separate terms for the projections you interpret in text.
76
+
77
+ ## Axioms as semantic direction
78
+
79
+ An axiom `A#` is a **true statement** that:
80
+
81
+ - defines the intended semantics of genus structures, and
82
+ - enables safe derivations (“in a certain direction”) by providing guarantees needed for operations.
83
+
84
+ Think of axioms as giving you _permission to use certain operators_ without risking typification/runtime failures or semantic ambiguity.
85
+
86
+ ### Example: singleton guarantee for `debool`
87
+
88
+ `debool(S)` is only meaningful when `S` is guaranteed to be a **singleton**.
89
+
90
+ In practice, when you build `S` as a projection/filter result, you often need an axiom that guarantees uniqueness.
91
+
92
+ For example, for a binary relation `S1 : ℬ(X1×X1)` you may want to define a function-like choice:
93
+
94
+ - `D_childOf(x) := debool(Pr2(Fi1[bool(x)](S1)))`
95
+
96
+ This is only valid if for every `x` the filtered projection yields exactly one element.
97
+ That guarantee is provided by an axiom of **right-uniqueness** (functional dependency) for the relation (written in RS logic for your specific structure).
98
+
99
+ Agent rule:
100
+
101
+ - If you see `debool(...)` in a definition, ensure there is an axiom that makes the inner set a singleton on the intended domain.
102
+ - If the axiom is absent, either (a) add the axiom, (b) replace `debool` by keeping the set-valued result, or (c) restrict the domain explicitly so the singleton property holds.
103
+
104
+ ## Expression hygiene: avoid tautological membership checks
105
+
106
+ In well-typed/correct RS expressions, you should avoid adding membership predicates that only restate what is already guaranteed by typification and by the correctness model.
107
+
108
+ Specifically, avoid “sanity checks” like:
109
+
110
+ - `x ∈ X1`
111
+ - `x ∈ ℬ(X1)` (and other plain grade constructions such as `X1×X2`, `B(X1)`, etc.)
112
+
113
+ when `x` is already bound/typed as an element compatible with `X1` (or with the intended element structure induced by `ℬ(X1)`, `X1×X2`, …).
114
+
115
+ Why this is usually meaningless:
116
+
117
+ - `AnalysisResult` checks expressions in a **global context** where identifiers must have known typifications and must satisfy **bijective portability**.
118
+ - Under these guarantees, values of an element grade “already belong” to the corresponding set/grade in the semantic sense; so the predicate becomes (effectively) TRUE and adds no discriminating information.
119
+
120
+ Agent rule:
121
+
122
+ - Use membership (`∈` / `Fi*`) to express *nontrivial* schema semantics (e.g. defining/characterising derived sets), not to re-check that a value matches its own typification.
123
+
124
+ ## Bijective portability (биективная переносимость)
125
+
126
+ **Bijective portability** means that a formal meaning/definition of a constituent depends only on the *structure* that the schema intends, and not on arbitrary “names” of undefined-concept interpretations.
127
+
128
+ Concretely, if you replace interpretations of undefined concepts by a bijective renaming (structure-preserving renaming), then:
129
+
130
+ - the evaluation result of every bijectively portable definition is unchanged up to the same renaming,
131
+ - therefore definitions are stable and reusable across equivalent models.
132
+
133
+ In rstool’s correctness model this property is not optional for the formal part:
134
+
135
+ - all formal definitions are required to be **bijectively portable**,
136
+ - expression checking assumes bijective portability for every referenced identifier.
137
+
138
+ Because of this, membership checks against base sets/grades become redundant in correct expressions: the type discipline plus portability already guarantee the relevant “belonging” constraints.
139
+
140
+ ## Analysis: how to review a schema as a system
141
+
142
+ ### Thesaurus health
143
+
144
+ - **Coverage**: do core domain nouns/roles appear as constituents (`N#`, `X#`, `S#`, `D#`)?
145
+ - **Non-synonymy**: if two terms are interchangeable in all axioms/definitions, collapse or differentiate them.
146
+ - **Naming stability**: avoid renaming “public” terms frequently; prefer adding refined terms and marking old ones as deprecated in text (if your workflow supports that).
147
+
148
+ ### Term graph health (dependencies)
149
+
150
+ - Prefer a **layered graph**: bases/constants → core structures → derived projections/components → higher-level derived concepts → axioms/statements.
151
+
152
+ ### Axiom health
153
+
154
+ - Every axiom should have a clear intent: uniqueness, totality, disjointness, ordering, invariance, domain/range constraints, etc.
155
+ - Prefer a small set of high-leverage axioms that unlock safe derivations, rather than many weak axioms with overlapping meaning.
156
+ - If axioms regularly fail in model evaluation, either the interpretation data violates the intended semantics or the semantics are wrong — in both cases the schema needs revision.
157
+
158
+ ## Practical workflow for agents (recommended)
159
+
160
+ 1. **Start with a vocabulary list** (domain nouns, roles, relations) → introduce `N#` for stable names when formalisation is not ready yet.
161
+ 2. **Introduce bases/constants** (`X#`, `C#`) early with conventions.
162
+ 3. **Introduce core structures** (`S#`) with typifications + conventions; immediately add the most important component terms (`Pr*`, `red`-based terms).
163
+ 4. **Add derived concepts** (`D#`, `F#`, `P#`) incrementally; keep definitions short by using named components.
164
+ 5. **Add axioms** (`A#`) that:
165
+ - encode intended semantics of structures,
166
+ - justify `debool`/functional choices, and
167
+ - restrict domains/ranges so derived concepts remain meaningful.
168
+ 6. Run analysis on scratch expressions before committing, and keep text definitions closed-world (schema terms only).
@@ -1,41 +1,64 @@
1
1
  # Constituenta reference
2
2
 
3
- Distilled from `help-cst-attributes`, the rstool skill table, and `CONTEXT.md`. Use this when upserting constituents via `addOrUpdateConstituenta`.
3
+ Use this when upserting constituents via `addOrUpdateConstituenta`.
4
4
 
5
5
  ## `ConstituentaDraft` fields
6
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 |
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
16
 
17
17
  Omitted text fields default to `''` in stored state.
18
18
 
19
+ ## Language of text fields
20
+
21
+ The natural-language fields `term`, `definitionText`, and `convention` should be written in **one consistent language**:
22
+
23
+ - When editing/extending an existing schema, keep the **same language** that is already used in the schema’s text fields.
24
+ - When creating a new schema from scratch, use the **language of the user’s request**.
25
+
19
26
  ## `cstType` table
20
27
 
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 |
28
+ | `cstType` (value) | Prefix | Formal definition | Notes |
29
+ | ----------------- | ------ | ------------------------- | ------------------------------------------------------------------------------------------------- |
30
+ | `basic` (`X`) | `X#` | **must be empty** | Base set; non-empty formal → `definitionNotAllowed` |
31
+ | `constant` (`C`) | `C#` | **must be empty** | Constant set; same rule |
32
+ | `nominal` (`N`) | `N#` | allowed | Free vocabulary item, no semantic constraint |
33
+ | `structure` (`S`) | `S#` | allowed | **Base** structured concept; `definitionFormal` is its **typification** (grade), not a definition |
34
+ | `term` (`D`) | `D#` | allowed | **Derived** concept; `definitionFormal` is its **definition** (value computed in the model) |
35
+ | `axiom` (`A`) | `A#` | allowed (must be `Logic`) | Logical statement asserting a requirement |
36
+ | `statement` (`T`) | `T#` | allowed (must be `Logic`) | Logical assertion about the model |
37
+ | `function` (`F`) | `F#` | allowed (parameterised) | Term-function |
38
+ | `predicate` (`P`) | `P#` | allowed (parameterised) | Predicate-function |
32
39
 
33
40
  ### Interpretability and inferrability
34
41
 
35
- - **Interpretable** (a value can be assigned via `setConstituentaValue`): `basic`, `constant`, `structure`, `term`, `axiom`, `statement`.
42
+ - **Interpretable** (a value can be assigned via `setConstituentaValue`): `basic`, `constant`, `structure`.
36
43
  - **Inferrable** (computed from definitions, never set directly): `term`, `axiom`, `statement`. Assigning to an inferrable raises an error.
37
44
 
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`.
45
+ ## Structure (`S#`) vs term (`D#`)
46
+
47
+ Do not treat `structure` and `term` as interchangeable because both may contain `×`, `ℬ`, or projections.
48
+
49
+ | | `structure` (`S#`) | `term` (`D#`) |
50
+ | ------------------ | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
51
+ | `definitionFormal` | **Typification** — which grade the elements have (e.g. `ℬ(X1×X1)` = set of pairs over `X1`) | **Definition** — how to obtain the concept (e.g. `Pr1(S1)` = first projection of relation `S1`) |
52
+ | Introduction | `convention` (+ optional axioms); interpretation from the subject domain | Formal expression only; interpretation is **evaluated** |
53
+ | `X1×X1` in context | Inside a grade: **one** pair type `(X1, X1)` | As the whole body: **Cartesian product** `X1 × X1` (all pairs) — rarely what you want for a relation |
54
+
55
+ **Typical pattern (relation over a base set):**
56
+
57
+ 1. `X1` — base set, empty formal, `convention` names the domain elements.
58
+ 2. `S1` — `definitionFormal: 'ℬ(X1×X1)'`, `convention` explains pair order (e.g. parent, child).
59
+ 3. `D1` — `definitionFormal: 'Pr1(S1)'` (or filters / term-functions), `definitionText` explains the derived set.
60
+
61
+ Worked example: `examples/build-kinship-rsform.ts`.
39
62
 
40
63
  ## Validation rules
41
64
 
@@ -1,6 +1,6 @@
1
1
  # Diagnostics reference
2
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`.
3
+ Use this when an `analyzeExpression` / `addOrUpdateConstituenta` call returns errors in `result.diagnostics`.
4
4
 
5
5
  ## How to read a diagnostic
6
6
 
@@ -8,20 +8,25 @@ Each `DiagnosticRecord` carries:
8
8
 
9
9
  - `code` — numeric `RSErrorCode` (see table). The high nibble identifies the class (`0x82xx` lexer, `0x84xx` parser, `0x88xx` semantic, `0x81xx` runtime, `0x28xx` warnings).
10
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.
11
+ - `from`, `to` — character positions in the _expression text_ that should be patched. Always edit `definitionFormal` by range.
12
12
  - `constituentId` — present in session diagnostics from `listDiagnostics`.
13
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.
14
+ Resolve `code` from **`@rsconcept/domain`** (installed: `node_modules/@rsconcept/domain/src/rslang/error.ts`):
15
+
16
+ - **`RSErrorCode`** — reverse-lookup the numeric value to its symbol name (`missingParenthesis`, `globalNotTyped`, …). The identifier is the canonical error kind; inline comments on each member document the hex id.
17
+ - **`getRSErrorPrefix(code)`** — short label with class + hex (`P8406`, `S8803`, …).
18
+ - **`params`** — substitution arguments from the reporter (see `*.test.ts` cases in `domain/src/rslang/` for examples per code).
19
+ - **Tables below** — typical causes and agent fixes when patching `definitionFormal`.
15
20
 
16
21
  ## Class table
17
22
 
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`) |
23
+ | Mask | Class | Behaviour |
24
+ | --------------- | -------------------- | ------------------------------------------------------------------------------ |
25
+ | `0x8400` family | Parser | Lexical / syntactic problems; expression cannot be analysed further |
26
+ | `0x8800` family | Semantic | Definition-level issues (types, scopes, structure) |
27
+ | `0x8100` family | Runtime / evaluation | Raised during `evaluateExpression` / `evaluateConstituenta` |
28
+ | `0x2800` family | Warning | Not critical; expression still valid |
29
+ | `0x88Cx` | Schema-level | Rules enforced by the schema layer (`cstEmptyDerived`, `definitionNotAllowed`) |
25
30
 
26
31
  `isCritical(code)` returns `false` only for `localDoubleDeclare` and `localNotUsed`.
27
32
 
@@ -29,81 +34,81 @@ Map a `code` to a human-readable message via `@rsconcept/domain` helpers (`getRS
29
34
 
30
35
  ### Parser
31
36
 
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 |
37
+ | Code | Symbol | Typical cause | Agent fix |
38
+ | -------- | ---------------------- | ------------------------------------ | ------------------------------- |
39
+ | `0x8400` | `unknownSyntax` | Stray token / typo | Re-tokenise around `from`–`to` |
40
+ | `0x8406` | `missingParenthesis` | Unmatched `(` `)` | Insert matching paren near `to` |
41
+ | `0x8407` | `missingCurlyBrace` | Unmatched `{` `}` | Insert matching brace |
42
+ | `0x8408` | `missingSquareBracket` | Unmatched `[` `]` | Insert matching bracket |
43
+ | `0x8409` | `bracketMismatch` | Mixed bracket types | Replace one bracket to match |
44
+ | `0x840A` | `doubleParenthesis` | `(( ... ))` redundancy | Remove one pair |
45
+ | `0x840B` | `missingOpenBracket` | Closing bracket without opener | Insert opening bracket earlier |
46
+ | `0x8415` | `expectedLocal` | Quantifier or filter expects a local | Provide a lowercase variable |
47
+ | `0x8416` | `expectedType` | Missing typification annotation | Add explicit grade |
43
48
 
44
49
  ### Semantic — locals and scopes
45
50
 
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 |
51
+ | Code | Symbol | Typical cause | Agent fix |
52
+ | -------- | -------------------- | -------------------------------- | ------------------------------- |
53
+ | `0x8801` | `localUndeclared` | Variable used before declaration | Bind via quantifier / parameter |
54
+ | `0x8802` | `localShadowing` | Local redeclared in inner scope | Rename inner variable |
55
+ | `0x8815` | `localOutOfScope` | Local escapes its binder | Move usage inside the binder |
56
+ | `0x2801` | `localDoubleDeclare` | Same local declared twice | Warning; rename |
57
+ | `0x2802` | `localNotUsed` | Declared local never referenced | Warning; remove or use |
53
58
 
54
59
  ### Semantic — types
55
60
 
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 |
61
+ | Code | Symbol | Typical cause | Agent fix |
62
+ | -------- | ------------------------------- | ------------------------------------------------------ | --------------------------------------------------- |
63
+ | `0x8803` | `typesNotEqual` | Operands have different typifications | Convert / project to matching grade |
64
+ | `0x8804` | `globalNotTyped` | Referenced global has no typification | Ensure dependency is upserted and typechecked first |
65
+ | `0x8805` | `invalidDecart` | Cartesian product on non-set operand | Wrap operand in `ℬ(...)` if appropriate |
66
+ | `0x8806` | `invalidBoolean` | `ℬ(...)` applied to a non-set | Use a set-grade operand |
67
+ | `0x8807` | `invalidTypeOperation` | Operator not defined for these types | Re-check the typification table |
68
+ | `0x8808` | `invalidCard` | `card(...)` on a non-set | Use a set operand |
69
+ | `0x8809` | `invalidDebool` | `debool(...)` on non-singleton | Ensure exactly one element first |
70
+ | `0x880B` | `globalFuncWithoutArgs` | Calling a function without `[]` args | Provide arguments |
71
+ | `0x8810` | `invalidReduce` | `red(...)` on something not `ℬ(ℬ(...))` | Wrap in extra `ℬ` or change source |
72
+ | `0x8811` | `invalidProjectionTuple` | `pr_i((a,b))` with out-of-range index | Use valid index |
73
+ | `0x8812` | `invalidProjectionSet` | `Pr_i(S)` on non-tuple set | Use a tuple-set source |
74
+ | `0x8813` | `invalidEnumeration` | `{a, b}` with incompatible element types | Match element typifications |
75
+ | `0x8814` | `invalidCortegeDeclare` | Tuple declaration with mismatched arity | Match declaration to use |
76
+ | `0x8816` | `invalidElementPredicate` | `ξ ∈ S` typification mismatch | Match `ξ`'s grade to elements of `S` |
77
+ | `0x8817` | `invalidEmptySetUsage` | `∅` in a position that needs a concrete element | Provide explicit typified operand |
78
+ | `0x8818` | `invalidArgsArity` | Wrong number of arguments to function | Match function declaration |
79
+ | `0x8819` | `invalidArgumentType` | Argument typification mismatch | Adjust caller or function signature |
80
+ | `0x881C` | `globalStructure` | Wrong structural shape of referenced global | Re-check `structure` constituent shape |
81
+ | `0x8821` | `radicalUsage` | Radical used outside parameter domain | Move usage into parameter declarations |
82
+ | `0x8822` | `invalidFilterArgumentType` | `Fi[D](S)` parameter does not match index typification | Match `D` to projected grade |
83
+ | `0x8823` | `invalidFilterArity` | Filter parameter count ≠ multi-index length | Align lengths |
84
+ | `0x8824` | `arithmeticNotSupported` | Arithmetic operator outside integer context | Use integer expressions |
85
+ | `0x8825` | `typesNotCompatible` | Generic type incompatibility | Re-examine surrounding context |
86
+ | `0x8826` | `orderingNotSupported` | `<`, `≤` etc. used outside integer | Ensure operands are integers |
87
+ | `0x8827` | `expectedLogic` | Definition where `Logic` is required | Wrap in logical expression or change `cstType` |
88
+ | `0x8828` | `expectedSetexpr` | Definition where STE required | Convert from logic to set expression |
89
+ | `0x8829` | `invalidArgumentCortegeDeclare` | Tuple parameter declaration mismatch | Match tuple arity in declaration |
85
90
 
86
91
  ### Schema / cstType validation
87
92
 
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 |
93
+ | Code | Symbol | Trigger | Fix |
94
+ | -------- | ---------------------- | ------------------------------------------------------ | ------------------------------------------------------ |
95
+ | `0x8861` | `cstEmptyDerived` | Derived constituent with empty `definitionFormal` | Provide a definition |
96
+ | `0x8862` | `definitionNotAllowed` | `basic`/`constant` with non-empty formal | Clear the formal |
97
+ | `0x8840` | `globalNoValue` | Reference to global without a model value | Set value via `setConstituentaValue` before evaluating |
98
+ | `0x8841` | `invalidPropertyUsage` | Property-only constituent used where value is required | Use a different operand |
94
99
 
95
100
  ### Runtime (evaluation)
96
101
 
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 |
102
+ | Code | Symbol | Cause |
103
+ | -------- | ------------------------- | ---------------------------------------- |
104
+ | `0x8100` | `calcUnknownError` | Unspecified evaluation failure |
105
+ | `0x8101` | `setOverflow` | Intermediate set too large |
106
+ | `0x8102` | `booleanBaseLimit` | `ℬ(X)` overflow at runtime |
107
+ | `0x8103` | `calcGlobalMissing` | Referenced global has no current value |
108
+ | `0x8104` | `iterationsLimit` | Iterative computation exceeded limit |
109
+ | `0x8105` | `calcInvalidDebool` | `debool` on multi-element set at runtime |
110
+ | `0x8106` | `iterateInfinity` | Iteration over an infinite set |
111
+ | `0x8107` | `calculationNotSupported` | Construct cannot be evaluated |
107
112
 
108
113
  ## Common agent mistakes
109
114
 
@@ -119,7 +124,7 @@ Map a `code` to a human-readable message via `@rsconcept/domain` helpers (`getRS
119
124
 
120
125
  1. Run `analyzeExpression` on a scratch.
121
126
  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.
127
+ 3. For each diagnostic: read `code`, `from`, `to`, and `params`. Look up `code` in `RSErrorCode` (`error.ts`) and use `getRSErrorPrefix` if you need a display id.
123
128
  4. Patch `definitionFormal` based on the range — never blindly retry without changing the input.
124
129
  5. Re-send. Repeat until success.
125
130
  6. Only then call `addOrUpdateConstituenta` to commit the constituent into the session.