@rsconcept/rstool 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/agent-workflow-DY-hfAap.d.ts +116 -0
- package/dist/{analysis-DA44pfgA.d.ts → analysis-ktWFu4BY.d.ts} +2 -2
- package/dist/{constituenta-QY5w1x91.d.ts → constituenta-HTnFtmxt.d.ts} +3 -3
- package/dist/{diagnostic-C6TRoBgt.d.ts → diagnostic-CODFUU-Q.d.ts} +5 -4
- package/dist/{diagnostic-assembly-DRunIcKQ.js → diagnostic-assembly-B-6vIA5I.js} +3 -1
- package/dist/diagnostic-assembly-B-6vIA5I.js.map +1 -0
- package/dist/{evaluation-Cd4S7-3t.d.ts → evaluation-6A7rK4t7.d.ts} +2 -2
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1 -1
- package/dist/mappers/model-adapter.d.ts +2 -2
- package/dist/mappers/model-adapter.js +127 -1
- package/dist/mappers/model-adapter.js.map +1 -0
- package/dist/mappers/schema-adapter.d.ts +9 -5
- package/dist/mappers/schema-adapter.js +44 -11
- package/dist/mappers/schema-adapter.js.map +1 -1
- package/dist/mappers/types.d.ts +2 -2
- package/dist/mappers/types.js +1 -1
- package/dist/models/agent-workflow.d.ts +2 -2
- package/dist/models/analysis.d.ts +1 -1
- package/dist/models/constituenta.d.ts +1 -1
- package/dist/models/diagnostic.d.ts +1 -1
- package/dist/models/diagnostic.js +1 -1
- package/dist/models/evaluation.d.ts +1 -1
- package/dist/models/index.d.ts +9 -9
- package/dist/models/index.js +1 -1
- package/dist/models/rstool-agent.d.ts +1 -1
- package/dist/models/rstool-agent.js +1 -1
- package/dist/models/session.d.ts +1 -1
- package/dist/models/tool-contract.d.ts +1 -1
- package/dist/models/tool-contract.js +1 -1
- package/dist/models/tool-contract.js.map +1 -1
- package/dist/{models-B255GaEC.js → models-BKmWx92e.js} +138 -4
- package/dist/models-BKmWx92e.js.map +1 -0
- package/dist/rsform-builder-DKwZfJvN.js +102 -0
- package/dist/rsform-builder-DKwZfJvN.js.map +1 -0
- package/dist/{rstool-agent-BGQAzFly.d.ts → rstool-agent-D-w4DlEo.d.ts} +14 -8
- package/dist/session/session-store.d.ts +2 -2
- package/dist/session/session-store.js +1 -1
- package/dist/{session-CI4rLYby.d.ts → session-Uc_vHrq9.d.ts} +2 -2
- package/dist/{tool-contract-sQfr-DYD.d.ts → tool-contract-i0v2gbWs.d.ts} +18 -8
- package/dist/wrapper/stdio-wrapper.js +14 -2
- package/dist/wrapper/stdio-wrapper.js.map +1 -1
- package/docs/DIAGNOSTICS.md +32 -31
- package/docs/DOMAIN.md +9 -2
- package/docs/README.md +1 -1
- package/package.json +1 -1
- package/skills/rstool-helper/EXAMPLES.md +26 -0
- package/skills/rstool-helper/GUIDE.md +2 -1
- package/skills/rstool-helper/REFERENCE.md +65 -19
- package/src/index.ts +4 -1
- package/src/mappers/diagnostic-assembly.ts +7 -4
- package/src/mappers/rsform-builder.ts +1 -1
- package/src/mappers/schema-adapter.ts +48 -16
- package/src/models/agent-workflow.ts +53 -0
- package/src/models/index.ts +6 -9
- package/src/models/rstool-agent.test.ts +83 -0
- package/src/models/rstool-agent.ts +182 -1
- package/src/models/tool-contract.ts +17 -2
- package/src/wrapper/stdio-handler.ts +15 -1
- package/dist/agent-workflow-D22FeODL.d.ts +0 -64
- package/dist/diagnostic-assembly-DRunIcKQ.js.map +0 -1
- package/dist/model-adapter-D-YmIvQW.js +0 -225
- package/dist/model-adapter-D-YmIvQW.js.map +0 -1
- package/dist/models-B255GaEC.js.map +0 -1
|
@@ -35,6 +35,59 @@ export interface ApplySchemaPatchInput {
|
|
|
35
35
|
commitMessage?: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** Result of {@link RSToolAgent.restoreOrder}. */
|
|
39
|
+
export interface RestoreOrderResult {
|
|
40
|
+
/** Constituent ids in the restored declaration order. */
|
|
41
|
+
orderedIds: number[];
|
|
42
|
+
/** Aliases in the same order as {@link orderedIds}. */
|
|
43
|
+
orderedAliases: string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** One row of an identification (substitution) table, by alias. */
|
|
47
|
+
export interface SynthesisSubstitution {
|
|
48
|
+
/** Alias of the constituenta being replaced (deleted). */
|
|
49
|
+
original: string;
|
|
50
|
+
/** Alias of the surviving constituenta. */
|
|
51
|
+
substitution: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Input for {@link RSToolAgent.synthesize}. */
|
|
55
|
+
export interface SynthesizeInput {
|
|
56
|
+
/** Session whose constituents are merged into the receiver. */
|
|
57
|
+
sourceSessionId: string;
|
|
58
|
+
/**
|
|
59
|
+
* Optional subset of source aliases to import.
|
|
60
|
+
* Omit or pass an empty array to import all source constituents.
|
|
61
|
+
*/
|
|
62
|
+
items?: string[];
|
|
63
|
+
/**
|
|
64
|
+
* Identification table: one endpoint is a source alias, the other a receiver alias
|
|
65
|
+
* (same rules as Portal schema embedding / «Встраивание схемы»).
|
|
66
|
+
*/
|
|
67
|
+
substitutions?: SynthesisSubstitution[];
|
|
68
|
+
/** When set, a revision is recorded after a successful synthesis. */
|
|
69
|
+
commitMessage?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Result of {@link RSToolAgent.synthesize}. */
|
|
73
|
+
export interface SynthesizeResult {
|
|
74
|
+
session: SessionHandle;
|
|
75
|
+
summary: SessionSummary;
|
|
76
|
+
/** False when some constituents failed re-analysis after embedding (best-effort). */
|
|
77
|
+
success: boolean;
|
|
78
|
+
/** Drafts that failed analysis after embedding; empty when {@link success} is true. */
|
|
79
|
+
failed: Array<{ draft: ConstituentaDraft; diagnostics: Diagnostic[] }>;
|
|
80
|
+
/** Source constituent id → inserted id in the receiver (before substitutions). */
|
|
81
|
+
idMap: Record<number, number>;
|
|
82
|
+
/** Alias remapping applied to imported constituents. */
|
|
83
|
+
aliasMapping: Record<string, string>;
|
|
84
|
+
/** Ids removed by substitutions. */
|
|
85
|
+
deletedIds: number[];
|
|
86
|
+
/** Ids of constituents inserted from the source (may include later-deleted ones). */
|
|
87
|
+
insertedIds: number[];
|
|
88
|
+
revision?: SessionRevision;
|
|
89
|
+
}
|
|
90
|
+
|
|
38
91
|
/** Compact view of one constituent in a session summary. */
|
|
39
92
|
export interface SessionSummaryItem {
|
|
40
93
|
id: number;
|
package/src/models/index.ts
CHANGED
|
@@ -2,20 +2,17 @@ export {
|
|
|
2
2
|
type AgentConstituentaPatch,
|
|
3
3
|
type ApplySchemaPatchInput,
|
|
4
4
|
type ApplySchemaPatchResult,
|
|
5
|
+
type RestoreOrderResult,
|
|
5
6
|
type SessionStateDetail,
|
|
6
7
|
type SessionStateResult,
|
|
7
8
|
type SessionSummary,
|
|
8
|
-
type SessionSummaryItem
|
|
9
|
+
type SessionSummaryItem,
|
|
10
|
+
type SynthesisSubstitution,
|
|
11
|
+
type SynthesizeInput,
|
|
12
|
+
type SynthesizeResult
|
|
9
13
|
} from './agent-workflow';
|
|
10
14
|
export { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';
|
|
11
|
-
export {
|
|
12
|
-
CstType,
|
|
13
|
-
EvalStatus,
|
|
14
|
-
RSErrorCode,
|
|
15
|
-
ValueClass,
|
|
16
|
-
type BasicBinding,
|
|
17
|
-
type RSToolValue
|
|
18
|
-
} from './common';
|
|
15
|
+
export { CstType, EvalStatus, RSErrorCode, ValueClass, type BasicBinding, type RSToolValue } from './common';
|
|
19
16
|
export { type ApplyConstituentsMode, type ConstituentaDraft, type ConstituentaState } from './constituenta';
|
|
20
17
|
export {
|
|
21
18
|
type CstDiagnostic,
|
|
@@ -877,6 +877,27 @@ describe('RSToolAgent import and export', () => {
|
|
|
877
877
|
expect(exported.items.map(item => item.alias)).toEqual(['D1', 'S1', 'C1', 'X1']);
|
|
878
878
|
});
|
|
879
879
|
|
|
880
|
+
it('restoreOrder reorders by formal topology and kernel priority', () => {
|
|
881
|
+
const tool = new RSToolAgent();
|
|
882
|
+
const session = tool.createSession({ title: 'Restore', alias: 'RO' });
|
|
883
|
+
tool.applySchemaPatch(
|
|
884
|
+
{
|
|
885
|
+
items: [
|
|
886
|
+
{ alias: 'D1', cstType: CstType.TERM, definitionFormal: 'Pr1(S1)\\X1' },
|
|
887
|
+
{ alias: 'S1', cstType: CstType.STRUCTURED, definitionFormal: 'ℬ(X1×X1)' },
|
|
888
|
+
{ alias: 'A2', cstType: CstType.AXIOM, definitionFormal: 'P1[S1]' },
|
|
889
|
+
{ alias: 'P1', cstType: CstType.PREDICATE, definitionFormal: '[α∈ℬ(R1)] card(α)=0' },
|
|
890
|
+
{ alias: 'X1', cstType: CstType.BASE, definitionFormal: '' }
|
|
891
|
+
]
|
|
892
|
+
},
|
|
893
|
+
session.sessionId
|
|
894
|
+
);
|
|
895
|
+
|
|
896
|
+
const result = tool.restoreOrder(session.sessionId);
|
|
897
|
+
expect(result.orderedAliases.slice(0, 5)).toEqual(['X1', 'P1', 'S1', 'A2', 'D1']);
|
|
898
|
+
expect(fullState(tool, session.sessionId).items.map(item => item.alias)).toEqual(result.orderedAliases);
|
|
899
|
+
});
|
|
900
|
+
|
|
880
901
|
it('round-trips portal schema export and import', () => {
|
|
881
902
|
const tool = new RSToolAgent();
|
|
882
903
|
const session = tool.createSession({ title: 'Round trip', alias: 'RT' });
|
|
@@ -1034,4 +1055,66 @@ describe('RSToolAgent modeling semantics', () => {
|
|
|
1034
1055
|
tool.setModelValues({ set: [{ target: 1, value: [1, 2, 3] as never }] }, session.sessionId)
|
|
1035
1056
|
).rejects.toThrow(/Invalid basic binding/);
|
|
1036
1057
|
});
|
|
1058
|
+
|
|
1059
|
+
it('synthesize merges source session and remaps aliases', () => {
|
|
1060
|
+
const tool = new RSToolAgent();
|
|
1061
|
+
const receiver = tool.createSession({ title: 'Receiver' });
|
|
1062
|
+
tool.applySchemaPatch({ items: [{ alias: 'X1' }] }, receiver.sessionId);
|
|
1063
|
+
|
|
1064
|
+
const source = tool.createSession({ title: 'Source' });
|
|
1065
|
+
tool.applySchemaPatch(
|
|
1066
|
+
{
|
|
1067
|
+
items: [
|
|
1068
|
+
{ alias: 'X1', term: 'person' },
|
|
1069
|
+
{ alias: 'S1', definitionFormal: 'ℬ(X1)' }
|
|
1070
|
+
]
|
|
1071
|
+
},
|
|
1072
|
+
source.sessionId
|
|
1073
|
+
);
|
|
1074
|
+
|
|
1075
|
+
tool.setCurrentSession(receiver.sessionId);
|
|
1076
|
+
const result = tool.synthesize({
|
|
1077
|
+
sourceSessionId: source.sessionId,
|
|
1078
|
+
commitMessage: 'merge source'
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
expect(result.summary.itemCount).toBe(3);
|
|
1082
|
+
expect(result.success).toBe(true);
|
|
1083
|
+
expect(result.failed).toEqual([]);
|
|
1084
|
+
expect(result.aliasMapping).toEqual({ X1: 'X2', S1: 'S1' });
|
|
1085
|
+
const state = tool.getSessionState('full', receiver.sessionId) as {
|
|
1086
|
+
items: Array<{ alias: string; definitionFormal: string }>;
|
|
1087
|
+
};
|
|
1088
|
+
expect(state.items.map(item => item.alias)).toEqual(['X1', 'X2', 'S1']);
|
|
1089
|
+
expect(state.items.find(item => item.alias === 'S1')?.definitionFormal).toBe('ℬ(X2)');
|
|
1090
|
+
expect(result.revision?.message).toBe('merge source');
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
it('synthesize applies identification table', () => {
|
|
1094
|
+
const tool = new RSToolAgent();
|
|
1095
|
+
const receiver = tool.createSession();
|
|
1096
|
+
tool.applySchemaPatch({ items: [{ alias: 'X1', term: 'keep' }] }, receiver.sessionId);
|
|
1097
|
+
|
|
1098
|
+
const source = tool.createSession();
|
|
1099
|
+
tool.applySchemaPatch({ items: [{ alias: 'X1', term: 'drop' }] }, source.sessionId);
|
|
1100
|
+
|
|
1101
|
+
tool.setCurrentSession(receiver.sessionId);
|
|
1102
|
+
const result = tool.synthesize({
|
|
1103
|
+
sourceSessionId: source.sessionId,
|
|
1104
|
+
substitutions: [{ original: 'X1', substitution: 'X1' }]
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
expect(result.summary.itemCount).toBe(1);
|
|
1108
|
+
expect(result.success).toBe(true);
|
|
1109
|
+
expect(result.deletedIds).toHaveLength(1);
|
|
1110
|
+
const state = tool.getSessionState('full', receiver.sessionId) as { items: Array<{ alias: string; term: string }> };
|
|
1111
|
+
expect(state.items[0].alias).toBe('X1');
|
|
1112
|
+
expect(state.items[0].term).toBe('keep');
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
it('synthesize rejects same source and receiver session', () => {
|
|
1116
|
+
const tool = new RSToolAgent();
|
|
1117
|
+
const session = tool.createSession();
|
|
1118
|
+
expect(() => tool.synthesize({ sourceSessionId: session.sessionId }, session.sessionId)).toThrow(/must differ/);
|
|
1119
|
+
});
|
|
1037
1120
|
});
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
inlineSynthesis,
|
|
3
|
+
restoreConstituentOrder,
|
|
4
|
+
type SynthesizableFields
|
|
5
|
+
} from '@rsconcept/domain/library/rsform-api';
|
|
6
|
+
import { type Substitution } from '@rsconcept/domain/library/rsform';
|
|
1
7
|
import {
|
|
2
8
|
portalDetailsToDrafts,
|
|
3
9
|
portalDetailsToSessionSeed,
|
|
@@ -13,9 +19,12 @@ import {
|
|
|
13
19
|
type AgentConstituentaPatch,
|
|
14
20
|
type ApplySchemaPatchInput,
|
|
15
21
|
type ApplySchemaPatchResult,
|
|
22
|
+
type RestoreOrderResult,
|
|
16
23
|
type SessionStateDetail,
|
|
17
24
|
type SessionStateResult,
|
|
18
|
-
type SessionSummary
|
|
25
|
+
type SessionSummary,
|
|
26
|
+
type SynthesizeInput,
|
|
27
|
+
type SynthesizeResult
|
|
19
28
|
} from './agent-workflow';
|
|
20
29
|
import { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';
|
|
21
30
|
import { CstType } from './common';
|
|
@@ -303,6 +312,162 @@ export class RSToolAgent implements RSToolAgentContract {
|
|
|
303
312
|
return result;
|
|
304
313
|
}
|
|
305
314
|
|
|
315
|
+
/** @inheritdoc */
|
|
316
|
+
public restoreOrder(sessionId?: string): RestoreOrderResult {
|
|
317
|
+
const id = this.resolveSessionId(sessionId);
|
|
318
|
+
const envelope = this.sessions.get(id);
|
|
319
|
+
const orderable = envelope.state.items.map(item => ({
|
|
320
|
+
id: item.id,
|
|
321
|
+
alias: item.alias,
|
|
322
|
+
cst_type: item.cstType,
|
|
323
|
+
definition_formal: item.definitionFormal
|
|
324
|
+
}));
|
|
325
|
+
const ordered = restoreConstituentOrder(orderable);
|
|
326
|
+
const byId = new Map(envelope.state.items.map(item => [item.id, item]));
|
|
327
|
+
envelope.state.items = ordered.map(item => byId.get(item.id)!);
|
|
328
|
+
envelope.state.updatedAt = new Date().toISOString();
|
|
329
|
+
this.sessions.replaceState(id, envelope.state);
|
|
330
|
+
return {
|
|
331
|
+
orderedIds: ordered.map(item => item.id),
|
|
332
|
+
orderedAliases: ordered.map(item => item.alias)
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** @inheritdoc */
|
|
337
|
+
public synthesize(input: SynthesizeInput, sessionId?: string): SynthesizeResult {
|
|
338
|
+
const receiverHandle = sessionId
|
|
339
|
+
? { sessionId: this.resolveSessionId(sessionId), contractVersion: this.contractVersion }
|
|
340
|
+
: this.ensureSession();
|
|
341
|
+
const receiverId = receiverHandle.sessionId;
|
|
342
|
+
const sourceId = this.resolveSessionId(input.sourceSessionId);
|
|
343
|
+
|
|
344
|
+
if (sourceId === receiverId) {
|
|
345
|
+
throw new Error('synthesize: sourceSessionId must differ from the receiver session');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const receiverEnvelope = this.sessions.get(receiverId);
|
|
349
|
+
const sourceEnvelope = this.sessions.get(sourceId);
|
|
350
|
+
const snapshot = this.sessions.snapshot(receiverId);
|
|
351
|
+
|
|
352
|
+
try {
|
|
353
|
+
const sourceItems = this.selectSourceItems(sourceEnvelope.state.items, input.items);
|
|
354
|
+
const substitutions = this.resolveSynthesisSubstitutions(
|
|
355
|
+
receiverEnvelope.state.items,
|
|
356
|
+
sourceItems,
|
|
357
|
+
input.substitutions ?? []
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
const nextId = receiverEnvelope.state.items.reduce((max, item) => Math.max(max, item.id), 0) + 1;
|
|
361
|
+
const result = inlineSynthesis({
|
|
362
|
+
receiverItems: receiverEnvelope.state.items.map(toSynthesizableSessionItem),
|
|
363
|
+
sourceItems: sourceItems.map(toSynthesizableSessionItem),
|
|
364
|
+
substitutions,
|
|
365
|
+
nextId
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const drafts: ConstituentaDraft[] = result.items.map(item => ({
|
|
369
|
+
id: item.id,
|
|
370
|
+
alias: item.alias,
|
|
371
|
+
cstType: item.cst_type,
|
|
372
|
+
definitionFormal: item.definition_formal,
|
|
373
|
+
term: item.term_resolved || item.term_raw,
|
|
374
|
+
definitionText: item.definition_resolved || item.definition_raw,
|
|
375
|
+
convention: item.convention
|
|
376
|
+
}));
|
|
377
|
+
|
|
378
|
+
receiverEnvelope.state.items = [];
|
|
379
|
+
receiverEnvelope.state.model = {
|
|
380
|
+
items: receiverEnvelope.state.model.items.filter(value => !result.deletedIds.has(value.id))
|
|
381
|
+
};
|
|
382
|
+
this.sessions.replaceState(receiverId, receiverEnvelope.state);
|
|
383
|
+
|
|
384
|
+
const applied = this.applyConstituents({ drafts, mode: 'best_effort' }, receiverId);
|
|
385
|
+
|
|
386
|
+
const revision = input.commitMessage ? this.commitStep(input.commitMessage, receiverId) : undefined;
|
|
387
|
+
return {
|
|
388
|
+
session: receiverHandle,
|
|
389
|
+
summary: this.buildSessionSummary(receiverId),
|
|
390
|
+
success: applied.success,
|
|
391
|
+
failed: applied.failed,
|
|
392
|
+
idMap: result.idMap,
|
|
393
|
+
aliasMapping: result.aliasMapping,
|
|
394
|
+
deletedIds: [...result.deletedIds],
|
|
395
|
+
insertedIds: result.insertedIds,
|
|
396
|
+
revision
|
|
397
|
+
};
|
|
398
|
+
} catch (error) {
|
|
399
|
+
this.sessions.restore(receiverId, snapshot);
|
|
400
|
+
throw error;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
private selectSourceItems(sourceItems: ConstituentaState[], aliases?: string[]): ConstituentaState[] {
|
|
405
|
+
if (!aliases || aliases.length === 0) {
|
|
406
|
+
return [...sourceItems];
|
|
407
|
+
}
|
|
408
|
+
const byAlias = new Map(sourceItems.map(item => [item.alias, item]));
|
|
409
|
+
const selected: ConstituentaState[] = [];
|
|
410
|
+
for (const alias of aliases) {
|
|
411
|
+
const item = byAlias.get(alias);
|
|
412
|
+
if (!item) {
|
|
413
|
+
throw new Error(`synthesize: unknown source alias "${alias}"`);
|
|
414
|
+
}
|
|
415
|
+
selected.push(item);
|
|
416
|
+
}
|
|
417
|
+
return selected;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
private resolveSynthesisSubstitutions(
|
|
421
|
+
receiverItems: ConstituentaState[],
|
|
422
|
+
sourceItems: ConstituentaState[],
|
|
423
|
+
substitutions: SynthesizeInput['substitutions']
|
|
424
|
+
): Substitution[] {
|
|
425
|
+
if (!substitutions || substitutions.length === 0) {
|
|
426
|
+
return [];
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const receiverByAlias = new Map(receiverItems.map(item => [item.alias, item]));
|
|
430
|
+
const sourceByAlias = new Map(sourceItems.map(item => [item.alias, item]));
|
|
431
|
+
const deletedKeys = new Set<string>();
|
|
432
|
+
const resolved: Substitution[] = [];
|
|
433
|
+
|
|
434
|
+
for (const row of substitutions) {
|
|
435
|
+
const originalSource = sourceByAlias.get(row.original);
|
|
436
|
+
const originalReceiver = receiverByAlias.get(row.original);
|
|
437
|
+
const substitutionSource = sourceByAlias.get(row.substitution);
|
|
438
|
+
const substitutionReceiver = receiverByAlias.get(row.substitution);
|
|
439
|
+
|
|
440
|
+
let originalId: number;
|
|
441
|
+
let substitutionId: number;
|
|
442
|
+
let originalKey: string;
|
|
443
|
+
|
|
444
|
+
// Prefer source→receiver when both sides share the same alias (typical base identification).
|
|
445
|
+
// Session ids are independent, so do not compare numeric ids across sessions.
|
|
446
|
+
if (originalSource && substitutionReceiver) {
|
|
447
|
+
originalId = originalSource.id;
|
|
448
|
+
substitutionId = substitutionReceiver.id;
|
|
449
|
+
originalKey = `s:${originalId}`;
|
|
450
|
+
} else if (originalReceiver && substitutionSource) {
|
|
451
|
+
originalId = originalReceiver.id;
|
|
452
|
+
substitutionId = substitutionSource.id;
|
|
453
|
+
originalKey = `r:${originalId}`;
|
|
454
|
+
} else {
|
|
455
|
+
throw new Error(
|
|
456
|
+
`synthesize: substitution "${row.original}" → "${row.substitution}" must pair one source alias with one receiver alias`
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (deletedKeys.has(originalKey)) {
|
|
461
|
+
throw new Error(`synthesize: constituenta "${row.original}" is substituted more than once`);
|
|
462
|
+
}
|
|
463
|
+
deletedKeys.add(originalKey);
|
|
464
|
+
|
|
465
|
+
resolved.push({ original: originalId, substitution: substitutionId });
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return resolved;
|
|
469
|
+
}
|
|
470
|
+
|
|
306
471
|
private addOrUpdateConstituenta(
|
|
307
472
|
input: AddOrUpdateConstituentaInput,
|
|
308
473
|
sessionId?: string
|
|
@@ -528,3 +693,19 @@ export class RSToolAgent implements RSToolAgentContract {
|
|
|
528
693
|
]);
|
|
529
694
|
}
|
|
530
695
|
}
|
|
696
|
+
|
|
697
|
+
function toSynthesizableSessionItem(item: ConstituentaState): SynthesizableFields & { convention: string } {
|
|
698
|
+
return {
|
|
699
|
+
id: item.id,
|
|
700
|
+
alias: item.alias,
|
|
701
|
+
cst_type: item.cstType,
|
|
702
|
+
definition_formal: item.definitionFormal,
|
|
703
|
+
typification_manual: '',
|
|
704
|
+
term_raw: item.term,
|
|
705
|
+
term_resolved: item.term,
|
|
706
|
+
term_forms: [],
|
|
707
|
+
definition_raw: item.definitionText,
|
|
708
|
+
definition_resolved: item.definitionText,
|
|
709
|
+
convention: item.convention
|
|
710
|
+
};
|
|
711
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ApplySchemaPatchInput,
|
|
3
3
|
type ApplySchemaPatchResult,
|
|
4
|
+
type RestoreOrderResult,
|
|
4
5
|
type SessionStateDetail,
|
|
5
|
-
type SessionStateResult
|
|
6
|
+
type SessionStateResult,
|
|
7
|
+
type SynthesizeInput,
|
|
8
|
+
type SynthesizeResult
|
|
6
9
|
} from './agent-workflow';
|
|
7
10
|
import { type AnalysisResult, type AnalyzeExpressionInput } from './analysis';
|
|
8
11
|
import { type Diagnostic, type ListDiagnosticsFilters } from './diagnostic';
|
|
@@ -12,7 +15,7 @@ import { type RecalculateModelResult, type SessionModelState, type SetModelValue
|
|
|
12
15
|
import { type SessionHandle, type SessionRevision, type SessionState } from './session';
|
|
13
16
|
|
|
14
17
|
/** Agent-visible contract version; bump on breaking API changes. */
|
|
15
|
-
export const CONTRACT_VERSION = '3.
|
|
18
|
+
export const CONTRACT_VERSION = '3.2.0';
|
|
16
19
|
|
|
17
20
|
/** Options for constructing an {@link RSToolAgent}. */
|
|
18
21
|
export interface RSToolAgentOptions {
|
|
@@ -85,4 +88,16 @@ export interface RSToolAgentContract {
|
|
|
85
88
|
|
|
86
89
|
/** Recompute derived model values for all constituents. */
|
|
87
90
|
recalculateModel(sessionId?: string): RecalculateModelResult;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Restore declaration order: formal topology, semantic clusters when ready,
|
|
94
|
+
* otherwise stable against type/kernel preferred ranks.
|
|
95
|
+
*/
|
|
96
|
+
restoreOrder(sessionId?: string): RestoreOrderResult;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Synthesis by embedding: merge constituents from another session into the receiver,
|
|
100
|
+
* then apply an identification table.
|
|
101
|
+
*/
|
|
102
|
+
synthesize(input: SynthesizeInput, sessionId?: string): SynthesizeResult;
|
|
88
103
|
}
|
|
@@ -33,7 +33,9 @@ export const STDIO_METHODS = [
|
|
|
33
33
|
'setModelValues',
|
|
34
34
|
'getModelState',
|
|
35
35
|
'evaluate',
|
|
36
|
-
'recalculateModel'
|
|
36
|
+
'recalculateModel',
|
|
37
|
+
'restoreOrder',
|
|
38
|
+
'synthesize'
|
|
37
39
|
] as const;
|
|
38
40
|
|
|
39
41
|
function asObject(value: unknown): Record<string, unknown> {
|
|
@@ -171,6 +173,18 @@ export async function handleStdioRequest(tool: RSToolAgent, request: StdioReques
|
|
|
171
173
|
ok: true,
|
|
172
174
|
result: tool.recalculateModel(optionalSessionId(params))
|
|
173
175
|
};
|
|
176
|
+
case 'restoreOrder':
|
|
177
|
+
return {
|
|
178
|
+
id: request.id,
|
|
179
|
+
ok: true,
|
|
180
|
+
result: tool.restoreOrder(optionalSessionId(params))
|
|
181
|
+
};
|
|
182
|
+
case 'synthesize':
|
|
183
|
+
return {
|
|
184
|
+
id: request.id,
|
|
185
|
+
ok: true,
|
|
186
|
+
result: tool.synthesize(omitSessionId(params) as never, optionalSessionId(params))
|
|
187
|
+
};
|
|
174
188
|
default:
|
|
175
189
|
return {
|
|
176
190
|
id: request.id ?? null,
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { a as Diagnostic } from "./diagnostic-C6TRoBgt.js";
|
|
2
|
-
import { n as CstType } from "./common-D6TFl6l_.js";
|
|
3
|
-
import { a as ApplyConstituentsResult, i as ApplyConstituentsMode, o as ConstituentaDraft } from "./constituenta-QY5w1x91.js";
|
|
4
|
-
import { n as SessionRevision, r as SessionState, t as SessionHandle } from "./session-CI4rLYby.js";
|
|
5
|
-
|
|
6
|
-
//#region src/models/agent-workflow.d.ts
|
|
7
|
-
/** Level of detail returned by {@link RSToolAgent.getSessionState}. */
|
|
8
|
-
type SessionStateDetail = 'summary' | 'full';
|
|
9
|
-
/** Result of `getSessionState`: compact summary or full cloned session state. */
|
|
10
|
-
type SessionStateResult = SessionSummary | SessionState;
|
|
11
|
-
/**
|
|
12
|
-
* Partial constituent update used in {@link ApplySchemaPatchInput}.
|
|
13
|
-
*
|
|
14
|
-
* `alias` is required; other fields are merged with any existing constituent
|
|
15
|
-
* or inferred from the alias prefix when omitted.
|
|
16
|
-
*/
|
|
17
|
-
interface AgentConstituentaPatch extends Omit<Partial<ConstituentaDraft>, 'alias'> {
|
|
18
|
-
alias: string;
|
|
19
|
-
}
|
|
20
|
-
/** Input for {@link RSToolAgent.applySchemaPatch}. */
|
|
21
|
-
interface ApplySchemaPatchInput {
|
|
22
|
-
/** Metadata used only when a new session is created for this patch. */
|
|
23
|
-
initial?: {
|
|
24
|
-
alias?: string;
|
|
25
|
-
title?: string;
|
|
26
|
-
comment?: string;
|
|
27
|
-
};
|
|
28
|
-
/** Constituent patches to apply in dependency order. */
|
|
29
|
-
items: AgentConstituentaPatch[];
|
|
30
|
-
/** atomic: rollback on first failure; best_effort applies valid drafts. Default: atomic. */
|
|
31
|
-
mode?: ApplyConstituentsMode;
|
|
32
|
-
/** When set, a revision is recorded after a successful patch. */
|
|
33
|
-
commitMessage?: string;
|
|
34
|
-
}
|
|
35
|
-
/** Compact view of one constituent in a session summary. */
|
|
36
|
-
interface SessionSummaryItem {
|
|
37
|
-
id: number;
|
|
38
|
-
alias: string;
|
|
39
|
-
cstType: CstType;
|
|
40
|
-
analysisSuccess: boolean;
|
|
41
|
-
}
|
|
42
|
-
/** Compact session overview returned by default from `getSessionState`. */
|
|
43
|
-
interface SessionSummary {
|
|
44
|
-
sessionId: string;
|
|
45
|
-
contractVersion: string;
|
|
46
|
-
alias: string;
|
|
47
|
-
title: string;
|
|
48
|
-
comment: string;
|
|
49
|
-
itemCount: number;
|
|
50
|
-
modelItemCount: number;
|
|
51
|
-
diagnosticsCount: number;
|
|
52
|
-
items: SessionSummaryItem[];
|
|
53
|
-
diagnostics: Diagnostic[];
|
|
54
|
-
lastRevision?: SessionRevision;
|
|
55
|
-
}
|
|
56
|
-
/** Result of {@link RSToolAgent.applySchemaPatch}. */
|
|
57
|
-
interface ApplySchemaPatchResult extends ApplyConstituentsResult {
|
|
58
|
-
session: SessionHandle;
|
|
59
|
-
summary: SessionSummary;
|
|
60
|
-
revision?: SessionRevision;
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
export { SessionStateResult as a, SessionStateDetail as i, ApplySchemaPatchInput as n, SessionSummary as o, ApplySchemaPatchResult as r, SessionSummaryItem as s, AgentConstituentaPatch as t };
|
|
64
|
-
//# sourceMappingURL=agent-workflow-D22FeODL.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostic-assembly-DRunIcKQ.js","names":[],"sources":["../src/mappers/diagnostic-assembly.ts"],"sourcesContent":["import {\n type Constituenta,\n type CstDiagnostic,\n DiagnosticKind,\n modelStatusCstDiagnostic,\n RSDiagnosticCode\n} from '@rsconcept/domain/library';\nimport { EvalStatus } from '@rsconcept/domain/library/rsmodel';\nimport { isCritical, RSErrorCode, type RSErrorDescription } from '@rsconcept/domain/rslang/error';\n\nexport { DiagnosticKind, RSDiagnosticCode };\n\n/** Severity of a {@link Diagnostic}. */\nexport type DiagnosticSeverity = 'error' | 'warning';\n\n/** Agent-facing diagnostic with redundant fields for autonomous repair. */\nexport interface Diagnostic extends CstDiagnostic {\n name: string;\n severity: DiagnosticSeverity;\n constituentId?: number;\n alias?: string;\n expression: string;\n from: number;\n to: number;\n}\n\n/** Context for attributing a {@link Diagnostic} to a constituent. */\nexport interface DiagnosticTarget {\n constituentId?: number;\n alias?: string;\n}\n\nconst DIAGNOSTIC_NAMES: ReadonlyMap<number, string> = new Map([\n ...Object.entries(RSErrorCode).map(([name, code]) => [code, name] as const),\n ...Object.entries(RSDiagnosticCode).map(([name, code]) => [code, name] as const)\n]);\n\nexport function getDiagnosticName(code: number): string {\n return DIAGNOSTIC_NAMES.get(code) ?? `0x${code.toString(16).toUpperCase()}`;\n}\n\nexport function getDiagnosticSeverity(code: number): DiagnosticSeverity {\n return isCritical(code as RSErrorCode) ? 'error' : 'warning';\n}\n\nexport function expandCstDiagnostic(cst: Constituenta, diagnostic: CstDiagnostic): Diagnostic {\n const expression = expressionForCstDiagnostic(cst, diagnostic);\n return {\n ...diagnostic,\n name: getDiagnosticName(diagnostic.code),\n severity: getDiagnosticSeverity(diagnostic.code),\n constituentId: cst.id,\n alias: cst.alias,\n expression,\n from: 0,\n to: diagnostic.kind === DiagnosticKind.MODEL ? 0 : Math.max(expression.length, 1)\n };\n}\n\nexport function expressionDiagnostic(\n error: RSErrorDescription,\n expression: string,\n target?: DiagnosticTarget\n): Diagnostic {\n return {\n kind: DiagnosticKind.EXPRESSION,\n code: error.code,\n name: getDiagnosticName(error.code),\n severity: getDiagnosticSeverity(error.code),\n constituentId: target?.constituentId,\n alias: target?.alias,\n expression,\n from: error.from,\n to: error.to,\n ...(error.params ? { params: error.params } : {})\n };\n}\n\nexport function modelStatusDiagnostic(status: EvalStatus, cst: Constituenta): Diagnostic | null {\n const base = modelStatusCstDiagnostic(status, cst.cst_type);\n return base ? expandCstDiagnostic(cst, base) : null;\n}\n\nfunction expressionForCstDiagnostic(cst: Constituenta, diagnostic: CstDiagnostic): string {\n switch (diagnostic.code) {\n case RSDiagnosticCode.schemaHomonym:\n case RSDiagnosticCode.schemaMissingTerm:\n return cst.term_resolved;\n case RSDiagnosticCode.schemaMissingConvention:\n return cst.convention;\n case RSDiagnosticCode.schemaTypeMismatch:\n return cst.typification_manual;\n default:\n return cst.definition_formal;\n }\n}\n"],"mappings":";;;AAgCA,MAAM,mBAAgD,IAAI,IAAI,CAC5D,GAAG,OAAO,QAAQ,WAAW,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CAAC,MAAM,IAAI,CAAU,GAC1E,GAAG,OAAO,QAAQ,gBAAgB,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CAAC,MAAM,IAAI,CAAU,CACjF,CAAC;AAED,SAAgB,kBAAkB,MAAsB;CACtD,OAAO,iBAAiB,IAAI,IAAI,KAAK,KAAK,KAAK,SAAS,EAAE,CAAC,CAAC,YAAY;AAC1E;AAEA,SAAgB,sBAAsB,MAAkC;CACtE,OAAO,WAAW,IAAmB,IAAI,UAAU;AACrD;AAEA,SAAgB,oBAAoB,KAAmB,YAAuC;CAC5F,MAAM,aAAa,2BAA2B,KAAK,UAAU;CAC7D,OAAO;EACL,GAAG;EACH,MAAM,kBAAkB,WAAW,IAAI;EACvC,UAAU,sBAAsB,WAAW,IAAI;EAC/C,eAAe,IAAI;EACnB,OAAO,IAAI;EACX;EACA,MAAM;EACN,IAAI,WAAW,SAAS,eAAe,QAAQ,IAAI,KAAK,IAAI,WAAW,QAAQ,CAAC;CAClF;AACF;AAEA,SAAgB,qBACd,OACA,YACA,QACY;CACZ,OAAO;EACL,MAAM,eAAe;EACrB,MAAM,MAAM;EACZ,MAAM,kBAAkB,MAAM,IAAI;EAClC,UAAU,sBAAsB,MAAM,IAAI;EAC1C,eAAe,QAAQ;EACvB,OAAO,QAAQ;EACf;EACA,MAAM,MAAM;EACZ,IAAI,MAAM;EACV,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;CACjD;AACF;AAEA,SAAgB,sBAAsB,QAAoB,KAAsC;CAC9F,MAAM,OAAO,yBAAyB,QAAQ,IAAI,QAAQ;CAC1D,OAAO,OAAO,oBAAoB,KAAK,IAAI,IAAI;AACjD;AAEA,SAAS,2BAA2B,KAAmB,YAAmC;CACxF,QAAQ,WAAW,MAAnB;EACE,KAAK,iBAAiB;EACtB,KAAK,iBAAiB,mBACpB,OAAO,IAAI;EACb,KAAK,iBAAiB,yBACpB,OAAO,IAAI;EACb,KAAK,iBAAiB,oBACpB,OAAO,IAAI;EACb,SACE,OAAO,IAAI;CACf;AACF"}
|