@toolproof-core/lib 1.0.47 → 1.0.49
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/dist/lookups/lookups.d.ts +9 -0
- package/dist/utils/mutableStrategyOverlay.d.ts +45 -42
- package/dist/utils/mutableStrategyOverlay.js +18 -18
- package/dist/utils/stepCreation.js +10 -5
- package/dist/utils/stepExpansion.d.ts +2 -2
- package/dist/utils/stepExpansion.js +9 -9
- package/dist/utils/stepParallelization.d.ts +2 -2
- package/dist/utils/stepParallelization.js +13 -13
- package/dist/utils/strategyAssembly.d.ts +1 -1
- package/dist/utils/strategyCanonicalization.d.ts +2 -2
- package/dist/utils/strategyCanonicalization.js +37 -30
- package/dist/utils/strategyStateResolution.d.ts +7 -7
- package/dist/utils/strategyStateResolution.js +1 -1
- package/dist/utils/strategyThreading.d.ts +2 -2
- package/package.json +2 -2
- package/src/utils/mutableStrategyOverlay.ts +92 -107
- package/src/utils/stepCreation.ts +10 -5
- package/src/utils/stepExpansion.ts +15 -22
- package/src/utils/stepParallelization.ts +20 -23
- package/src/utils/strategyAssembly.ts +2 -2
- package/src/utils/strategyCanonicalization.ts +41 -33
- package/src/utils/strategyStateResolution.ts +13 -16
- package/src/utils/strategyThreading.ts +3 -10
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -68,6 +68,11 @@ export declare const CONSTANTS: {
|
|
|
68
68
|
readonly StepArrayArray: "StepArrayArray";
|
|
69
69
|
readonly StepKind: "StepKind";
|
|
70
70
|
readonly StepKindFacet: "StepKindFacet";
|
|
71
|
+
readonly StepPath: "StepPath";
|
|
72
|
+
readonly StepPathSegment: "StepPathSegment";
|
|
73
|
+
readonly StepPathSegmentKind: "StepPathSegmentKind";
|
|
74
|
+
readonly StepPathSlot: "StepPathSlot";
|
|
75
|
+
readonly StepPathSpec: "StepPathSpec";
|
|
71
76
|
readonly StepsByThreadIndexFacet: "StepsByThreadIndexFacet";
|
|
72
77
|
readonly StepsFacet: "StepsFacet";
|
|
73
78
|
readonly Strategy: "Strategy";
|
|
@@ -189,6 +194,10 @@ export declare const CONSTANTS: {
|
|
|
189
194
|
readonly while: "while";
|
|
190
195
|
readonly for: "for";
|
|
191
196
|
};
|
|
197
|
+
readonly StepPathSegmentKind: {
|
|
198
|
+
readonly case: "case";
|
|
199
|
+
readonly cases: "cases";
|
|
200
|
+
};
|
|
192
201
|
readonly StrategyStateEntryKind: {
|
|
193
202
|
readonly materializedResource: "materializedResource";
|
|
194
203
|
readonly externalInputPotential: "externalInputPotential";
|
|
@@ -1,55 +1,58 @@
|
|
|
1
1
|
import type { BranchStep, Case, ExternalInputPotential, ForStep, MaterializedResource, InternalInputPotential, Resource, RoleName, Strategy, Tool, ToolHandle, ToolStep, ToolStepRoleAddress, WhileStep } from '@toolproof-core/genesis';
|
|
2
|
-
export type MutableToolStepKey = string
|
|
3
|
-
export type MutableBranchStepKey = string
|
|
4
|
-
export type MutableWhileStepKey = string
|
|
5
|
-
export type MutableForStepKey = string
|
|
2
|
+
export type MutableToolStepKey = `TOOL_STEP-${string}`;
|
|
3
|
+
export type MutableBranchStepKey = `BRANCH_STEP-${string}`;
|
|
4
|
+
export type MutableWhileStepKey = `WHILE_STEP-${string}`;
|
|
5
|
+
export type MutableForStepKey = `FOR_STEP-${string}`;
|
|
6
6
|
export type MutableLoopStepKey = MutableWhileStepKey | MutableForStepKey;
|
|
7
7
|
export type MutableMacroStepKey = MutableBranchStepKey | MutableLoopStepKey;
|
|
8
|
+
export type MutableStepKey = MutableToolStepKey | MutableMacroStepKey;
|
|
8
9
|
export type MutableMaterializedResource = MaterializedResource;
|
|
9
|
-
export type MutableToolStepRoleAddress
|
|
10
|
-
|
|
10
|
+
export type MutableToolStepRoleAddress = Omit<ToolStepRoleAddress, 'toolStepPath'> & {
|
|
11
|
+
stepKey: MutableToolStepKey;
|
|
11
12
|
};
|
|
12
|
-
export type MutableInternalInputPotential
|
|
13
|
-
toolStepRoleAddress: MutableToolStepRoleAddress
|
|
13
|
+
export type MutableInternalInputPotential = Omit<InternalInputPotential, 'toolStepRoleAddress'> & {
|
|
14
|
+
toolStepRoleAddress: MutableToolStepRoleAddress;
|
|
14
15
|
};
|
|
15
16
|
export type MutableExternalInputPotential = ExternalInputPotential;
|
|
16
|
-
export type MutableStrategyStateEntry
|
|
17
|
-
export type MutableStrategyStateEntryByRoleName
|
|
18
|
-
export type MutableStrategyState
|
|
19
|
-
export type MutableToolStep
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
export type MutableCase
|
|
23
|
-
when: MutableToolStep
|
|
24
|
-
what: MutableToolStep
|
|
25
|
-
};
|
|
26
|
-
export type MutableBranchStep
|
|
17
|
+
export type MutableStrategyStateEntry = MutableMaterializedResource | MutableInternalInputPotential | MutableExternalInputPotential;
|
|
18
|
+
export type MutableStrategyStateEntryByRoleName = Partial<Record<RoleName, MutableStrategyStateEntry>>;
|
|
19
|
+
export type MutableStrategyState = Partial<Record<MutableToolStepKey, MutableStrategyStateEntryByRoleName>>;
|
|
20
|
+
export type MutableToolStep = ToolStep & {
|
|
21
|
+
stepKey: MutableToolStepKey;
|
|
22
|
+
};
|
|
23
|
+
export type MutableCase = Omit<Case, 'when' | 'what'> & {
|
|
24
|
+
when: MutableToolStep;
|
|
25
|
+
what: MutableToolStep;
|
|
26
|
+
};
|
|
27
|
+
export type MutableBranchStep = Omit<BranchStep, 'cases'> & {
|
|
28
|
+
stepKey: MutableBranchStepKey;
|
|
27
29
|
macroStepKey: MutableBranchStepKey;
|
|
28
|
-
cases: [MutableCase
|
|
30
|
+
cases: [MutableCase, ...MutableCase[]];
|
|
29
31
|
};
|
|
30
|
-
export type MutableWhileStep
|
|
32
|
+
export type MutableWhileStep = Omit<WhileStep, 'case'> & {
|
|
33
|
+
stepKey: MutableWhileStepKey;
|
|
31
34
|
macroStepKey: MutableWhileStepKey;
|
|
32
|
-
case: MutableCase
|
|
35
|
+
case: MutableCase;
|
|
33
36
|
};
|
|
34
|
-
export type MutableForStep
|
|
37
|
+
export type MutableForStep = Omit<ForStep, 'case'> & {
|
|
38
|
+
stepKey: MutableForStepKey;
|
|
35
39
|
macroStepKey: MutableForStepKey;
|
|
36
|
-
case: MutableCase
|
|
37
|
-
};
|
|
38
|
-
export type MutableStep
|
|
39
|
-
export type MutableStrategy
|
|
40
|
-
stepsByThreadIndex:
|
|
41
|
-
strategyState:
|
|
42
|
-
};
|
|
43
|
-
export declare function getAuthoringSteps
|
|
44
|
-
export declare function setAuthoringSteps
|
|
45
|
-
|
|
46
|
-
export declare function
|
|
47
|
-
export declare function
|
|
48
|
-
export declare function
|
|
49
|
-
export declare function
|
|
50
|
-
export declare function
|
|
51
|
-
|
|
52
|
-
toolStepByKey: ReadonlyMap<TKey, MutableToolStep<TKey>>;
|
|
40
|
+
case: MutableCase;
|
|
41
|
+
};
|
|
42
|
+
export type MutableStep = MutableToolStep | MutableBranchStep | MutableWhileStep | MutableForStep;
|
|
43
|
+
export type MutableStrategy = Omit<Strategy, 'stepsByThreadIndex' | 'strategyState'> & {
|
|
44
|
+
stepsByThreadIndex: MutableStep[][];
|
|
45
|
+
strategyState: MutableStrategyState;
|
|
46
|
+
};
|
|
47
|
+
export declare function getAuthoringSteps(strategy: MutableStrategy): MutableStep[];
|
|
48
|
+
export declare function setAuthoringSteps(strategy: MutableStrategy, steps: MutableStep[]): MutableStrategy;
|
|
49
|
+
export declare function getStrategyStateEntryByRoleName(strategyState: MutableStrategyState, stepKey: MutableToolStepKey): MutableStrategyStateEntryByRoleName | undefined;
|
|
50
|
+
export declare function getStrategyStateEntry(strategyState: MutableStrategyState, toolStepRoleAddress: MutableToolStepRoleAddress): MutableStrategyStateEntry | undefined;
|
|
51
|
+
export declare function setStrategyStateEntry(strategyState: MutableStrategyState, toolStepRoleAddress: MutableToolStepRoleAddress, entry: MutableStrategyStateEntry): MutableStrategyState;
|
|
52
|
+
export declare function clearInputBinding(strategyState: MutableStrategyState, toolStepRoleAddress: MutableToolStepRoleAddress): MutableStrategyState;
|
|
53
|
+
export declare function bindMaterializedResource(strategyState: MutableStrategyState, target: MutableToolStepRoleAddress, resource: Resource): MutableStrategyState;
|
|
54
|
+
export declare function bindInternalInputPotential(strategyState: MutableStrategyState, targetAddress: MutableToolStepRoleAddress, sourceAddress: MutableToolStepRoleAddress, context: {
|
|
55
|
+
toolStepByKey: ReadonlyMap<MutableToolStepKey, MutableToolStep>;
|
|
53
56
|
toolMap: ReadonlyMap<ToolHandle, Tool>;
|
|
54
|
-
}):
|
|
55
|
-
export declare function bindExternalInputPotential
|
|
57
|
+
}): MutableStrategyState;
|
|
58
|
+
export declare function bindExternalInputPotential(strategyState: MutableStrategyState, target: MutableToolStepRoleAddress): MutableStrategyState;
|
|
@@ -10,25 +10,25 @@ export function setAuthoringSteps(strategy, steps) {
|
|
|
10
10
|
stepsByThreadIndex: nextStepsByThreadIndex,
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export function getStrategyStateEntryByRoleName(strategyState,
|
|
14
|
-
return strategyState[
|
|
13
|
+
export function getStrategyStateEntryByRoleName(strategyState, stepKey) {
|
|
14
|
+
return strategyState[stepKey];
|
|
15
15
|
}
|
|
16
16
|
export function getStrategyStateEntry(strategyState, toolStepRoleAddress) {
|
|
17
|
-
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.
|
|
17
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.stepKey);
|
|
18
18
|
return inputEntryByRoleName?.[toolStepRoleAddress.roleName];
|
|
19
19
|
}
|
|
20
20
|
export function setStrategyStateEntry(strategyState, toolStepRoleAddress, entry) {
|
|
21
|
-
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.
|
|
21
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.stepKey) ?? {};
|
|
22
22
|
return {
|
|
23
23
|
...strategyState,
|
|
24
|
-
[toolStepRoleAddress.
|
|
24
|
+
[toolStepRoleAddress.stepKey]: {
|
|
25
25
|
...inputEntryByRoleName,
|
|
26
26
|
[toolStepRoleAddress.roleName]: entry,
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
export function clearInputBinding(strategyState, toolStepRoleAddress) {
|
|
31
|
-
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.
|
|
31
|
+
const inputEntryByRoleName = getStrategyStateEntryByRoleName(strategyState, toolStepRoleAddress.stepKey);
|
|
32
32
|
if (!inputEntryByRoleName || !(toolStepRoleAddress.roleName in inputEntryByRoleName)) {
|
|
33
33
|
return strategyState;
|
|
34
34
|
}
|
|
@@ -36,12 +36,12 @@ export function clearInputBinding(strategyState, toolStepRoleAddress) {
|
|
|
36
36
|
delete nextInputEntryByRoleName[toolStepRoleAddress.roleName];
|
|
37
37
|
if (Object.keys(nextInputEntryByRoleName).length === 0) {
|
|
38
38
|
const nextStrategyState = { ...strategyState };
|
|
39
|
-
delete nextStrategyState[toolStepRoleAddress.
|
|
39
|
+
delete nextStrategyState[toolStepRoleAddress.stepKey];
|
|
40
40
|
return nextStrategyState;
|
|
41
41
|
}
|
|
42
42
|
return {
|
|
43
43
|
...strategyState,
|
|
44
|
-
[toolStepRoleAddress.
|
|
44
|
+
[toolStepRoleAddress.stepKey]: nextInputEntryByRoleName,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
export function bindMaterializedResource(strategyState, target, resource) {
|
|
@@ -58,13 +58,13 @@ function getOutputRoleValue(tool, roleName) {
|
|
|
58
58
|
return tool.roleSpec.outputRoleValueByName[roleName];
|
|
59
59
|
}
|
|
60
60
|
export function bindInternalInputPotential(strategyState, targetAddress, sourceAddress, context) {
|
|
61
|
-
const sourceToolStep = context.toolStepByKey.get(sourceAddress.
|
|
61
|
+
const sourceToolStep = context.toolStepByKey.get(sourceAddress.stepKey);
|
|
62
62
|
if (!sourceToolStep) {
|
|
63
|
-
throw new Error(`Source tool step not found for '${sourceAddress.
|
|
63
|
+
throw new Error(`Source tool step not found for '${sourceAddress.stepKey}'.`);
|
|
64
64
|
}
|
|
65
|
-
const targetToolStep = context.toolStepByKey.get(targetAddress.
|
|
65
|
+
const targetToolStep = context.toolStepByKey.get(targetAddress.stepKey);
|
|
66
66
|
if (!targetToolStep) {
|
|
67
|
-
throw new Error(`Target tool step not found for '${targetAddress.
|
|
67
|
+
throw new Error(`Target tool step not found for '${targetAddress.stepKey}'.`);
|
|
68
68
|
}
|
|
69
69
|
const sourceTool = context.toolMap.get(sourceToolStep.toolHandle);
|
|
70
70
|
if (!sourceTool) {
|
|
@@ -76,11 +76,11 @@ export function bindInternalInputPotential(strategyState, targetAddress, sourceA
|
|
|
76
76
|
}
|
|
77
77
|
const targetInputRoleValue = getInputRoleValue(targetTool, targetAddress.roleName);
|
|
78
78
|
if (!targetInputRoleValue) {
|
|
79
|
-
throw new Error(`Target input role not found for (${targetAddress.
|
|
79
|
+
throw new Error(`Target input role not found for (${targetAddress.stepKey}, ${targetAddress.roleName}).`);
|
|
80
80
|
}
|
|
81
81
|
const sourceOutputRoleValue = getOutputRoleValue(sourceTool, sourceAddress.roleName);
|
|
82
82
|
const sourceInputRoleValue = getInputRoleValue(sourceTool, sourceAddress.roleName);
|
|
83
|
-
const sourceInputEntryByRoleName = strategyState[sourceAddress.
|
|
83
|
+
const sourceInputEntryByRoleName = strategyState[sourceAddress.stepKey];
|
|
84
84
|
const sourceInputEntry = sourceInputEntryByRoleName?.[sourceAddress.roleName];
|
|
85
85
|
const sourceRoleType = sourceOutputRoleValue
|
|
86
86
|
? extractResourceTypeHandleFromRoleValue(sourceOutputRoleValue)
|
|
@@ -90,19 +90,19 @@ export function bindInternalInputPotential(strategyState, targetAddress, sourceA
|
|
|
90
90
|
const targetRoleType = extractResourceTypeHandleFromRoleValue(targetInputRoleValue);
|
|
91
91
|
if (!sourceOutputRoleValue && sourceInputRoleValue) {
|
|
92
92
|
if (!sourceInputEntry) {
|
|
93
|
-
throw new Error(`Source input role is not bound for (${sourceAddress.
|
|
93
|
+
throw new Error(`Source input role is not bound for (${sourceAddress.stepKey}, ${sourceAddress.roleName}).`); // ATTENTION: not an ontological invariant, but it might help catch some mistakes early on.
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
if (!sourceOutputRoleValue && !sourceInputRoleValue) {
|
|
97
|
-
throw new Error(`Source role not found for (${sourceAddress.
|
|
97
|
+
throw new Error(`Source role not found for (${sourceAddress.stepKey}, ${sourceAddress.roleName}).`);
|
|
98
98
|
}
|
|
99
99
|
if (!sourceRoleType || !targetRoleType || sourceRoleType !== targetRoleType) {
|
|
100
|
-
throw new Error(`Reference type mismatch between source (${sourceAddress.
|
|
100
|
+
throw new Error(`Reference type mismatch between source (${sourceAddress.stepKey}, ${sourceAddress.roleName}) and target (${targetAddress.stepKey}, ${targetAddress.roleName}).`);
|
|
101
101
|
}
|
|
102
102
|
return setStrategyStateEntry(strategyState, targetAddress, {
|
|
103
103
|
strategyStateEntryKind: 'internalInputPotential',
|
|
104
104
|
toolStepRoleAddress: {
|
|
105
|
-
|
|
105
|
+
stepKey: sourceAddress.stepKey,
|
|
106
106
|
roleName: sourceAddress.roleName,
|
|
107
107
|
},
|
|
108
108
|
});
|
|
@@ -14,7 +14,7 @@ function getRoleBindingSpec(tool) {
|
|
|
14
14
|
}
|
|
15
15
|
export function createToolStepFromTool(tool) {
|
|
16
16
|
return {
|
|
17
|
-
|
|
17
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
18
18
|
stepKind: CONSTANTS.Enums.StepKind.tool,
|
|
19
19
|
toolHandle: tool.handle,
|
|
20
20
|
roleBindingSpec: getRoleBindingSpec(tool),
|
|
@@ -32,12 +32,14 @@ export function createCaseFromToolStepPair(what, when) {
|
|
|
32
32
|
export function createLoopStepFromCase(stepCase, stepKind) {
|
|
33
33
|
if (stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
34
34
|
return {
|
|
35
|
+
stepKey: generateIdentifier('ForStepKey'),
|
|
35
36
|
macroStepKey: generateIdentifier('ForStepKey'),
|
|
36
37
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
37
38
|
case: stepCase,
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
return {
|
|
42
|
+
stepKey: generateIdentifier('WhileStepKey'),
|
|
41
43
|
macroStepKey: generateIdentifier('WhileStepKey'),
|
|
42
44
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
43
45
|
case: stepCase,
|
|
@@ -46,6 +48,7 @@ export function createLoopStepFromCase(stepCase, stepKind) {
|
|
|
46
48
|
export function createBranchStepFromCases(cases) {
|
|
47
49
|
assertNonEmpty(cases, 'createBranchStepFromCases requires at least one case');
|
|
48
50
|
return {
|
|
51
|
+
stepKey: generateIdentifier('BranchStepKey'),
|
|
49
52
|
macroStepKey: generateIdentifier('BranchStepKey'),
|
|
50
53
|
stepKind: CONSTANTS.Enums.StepKind.branch,
|
|
51
54
|
cases,
|
|
@@ -53,32 +56,34 @@ export function createBranchStepFromCases(cases) {
|
|
|
53
56
|
}
|
|
54
57
|
export function cloneForStep(forStep) {
|
|
55
58
|
return {
|
|
59
|
+
stepKey: generateIdentifier('ForStepKey'),
|
|
56
60
|
macroStepKey: generateIdentifier('ForStepKey'),
|
|
57
61
|
stepKind: CONSTANTS.Enums.StepKind.for,
|
|
58
62
|
case: {
|
|
59
63
|
what: {
|
|
60
64
|
...forStep.case.what,
|
|
61
|
-
|
|
65
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
62
66
|
},
|
|
63
67
|
when: {
|
|
64
68
|
...forStep.case.when,
|
|
65
|
-
|
|
69
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
66
70
|
},
|
|
67
71
|
},
|
|
68
72
|
};
|
|
69
73
|
}
|
|
70
74
|
export function cloneWhileStep(whileStep) {
|
|
71
75
|
return {
|
|
76
|
+
stepKey: generateIdentifier('WhileStepKey'),
|
|
72
77
|
macroStepKey: generateIdentifier('WhileStepKey'),
|
|
73
78
|
stepKind: CONSTANTS.Enums.StepKind.while,
|
|
74
79
|
case: {
|
|
75
80
|
what: {
|
|
76
81
|
...whileStep.case.what,
|
|
77
|
-
|
|
82
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
78
83
|
},
|
|
79
84
|
when: {
|
|
80
85
|
...whileStep.case.when,
|
|
81
|
-
|
|
86
|
+
stepKey: generateIdentifier('ToolStepKey'),
|
|
82
87
|
},
|
|
83
88
|
},
|
|
84
89
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { MutableStep, MutableToolStep
|
|
1
|
+
import type { MutableStep, MutableToolStep } from './mutableStrategyOverlay.js';
|
|
2
2
|
export type StepExpansionOrder = {
|
|
3
3
|
branchCaseOrder?: 'when-what' | 'what-when';
|
|
4
4
|
loopCaseOrder?: 'what-when' | 'when-what';
|
|
5
5
|
};
|
|
6
|
-
export declare function extractToolStepsFromStep
|
|
6
|
+
export declare function extractToolStepsFromStep(step: MutableStep, order?: StepExpansionOrder): MutableToolStep[];
|
|
@@ -5,28 +5,28 @@ export function extractToolStepsFromStep(step, order = {}) {
|
|
|
5
5
|
return [step];
|
|
6
6
|
}
|
|
7
7
|
if (step.stepKind === CONSTANTS.Enums.StepKind.branch) {
|
|
8
|
-
const
|
|
9
|
-
const cases =
|
|
8
|
+
const branchStep = step;
|
|
9
|
+
const cases = branchStep.cases ?? [];
|
|
10
10
|
return cases.flatMap((stepCase) => {
|
|
11
11
|
if (branchCaseOrder === 'what-when') {
|
|
12
12
|
return [stepCase.what, stepCase.when];
|
|
13
13
|
}
|
|
14
14
|
return [stepCase.when, stepCase.what];
|
|
15
|
-
})
|
|
15
|
+
});
|
|
16
16
|
}
|
|
17
17
|
if (step.stepKind === CONSTANTS.Enums.StepKind.while) {
|
|
18
|
-
const
|
|
18
|
+
const whileStep = step;
|
|
19
19
|
if (loopCaseOrder === 'when-what') {
|
|
20
|
-
return [
|
|
20
|
+
return [whileStep.case.when, whileStep.case.what];
|
|
21
21
|
}
|
|
22
|
-
return [
|
|
22
|
+
return [whileStep.case.what, whileStep.case.when];
|
|
23
23
|
}
|
|
24
24
|
if (step.stepKind === CONSTANTS.Enums.StepKind.for) {
|
|
25
|
-
const
|
|
25
|
+
const forStep = step;
|
|
26
26
|
if (loopCaseOrder === 'when-what') {
|
|
27
|
-
return [
|
|
27
|
+
return [forStep.case.when, forStep.case.what];
|
|
28
28
|
}
|
|
29
|
-
return [
|
|
29
|
+
return [forStep.case.what, forStep.case.when];
|
|
30
30
|
}
|
|
31
31
|
return [];
|
|
32
32
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MutableStep, MutableStrategyState
|
|
2
|
-
export declare function getIndependentThreads
|
|
1
|
+
import type { MutableStep, MutableStrategyState } from './mutableStrategyOverlay.js';
|
|
2
|
+
export declare function getIndependentThreads(steps: MutableStep[], strategyState: MutableStrategyState): MutableStep[][];
|
|
@@ -4,17 +4,17 @@ export function getIndependentThreads(steps, strategyState) {
|
|
|
4
4
|
const step = steps[ownerIndex];
|
|
5
5
|
return `steps[${ownerIndex}] stepKind=${step?.stepKind ?? 'unknown'}`;
|
|
6
6
|
};
|
|
7
|
-
const
|
|
7
|
+
const stepKeyToOwner = new Map();
|
|
8
8
|
const toolStepByKey = new Map();
|
|
9
9
|
const addToolStep = (toolStep, ownerIndex) => {
|
|
10
10
|
if (!toolStep)
|
|
11
11
|
return;
|
|
12
|
-
const existingOwner =
|
|
12
|
+
const existingOwner = stepKeyToOwner.get(toolStep.stepKey);
|
|
13
13
|
if (existingOwner !== undefined) {
|
|
14
|
-
throw new Error(`Duplicate
|
|
14
|
+
throw new Error(`Duplicate stepKey '${toolStep.stepKey}' found in ${getOwnerLabel(ownerIndex)} and ${getOwnerLabel(existingOwner)}`);
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
toolStepByKey.set(toolStep.
|
|
16
|
+
stepKeyToOwner.set(toolStep.stepKey, ownerIndex);
|
|
17
|
+
toolStepByKey.set(toolStep.stepKey, toolStep);
|
|
18
18
|
};
|
|
19
19
|
steps.forEach((step, ownerIndex) => {
|
|
20
20
|
for (const toolStep of extractToolStepsFromStep(step, { branchCaseOrder: 'what-when' })) {
|
|
@@ -32,22 +32,22 @@ export function getIndependentThreads(steps, strategyState) {
|
|
|
32
32
|
for (let index = 0; index < steps.length; index++) {
|
|
33
33
|
ensureOwner(index);
|
|
34
34
|
}
|
|
35
|
-
for (const [
|
|
35
|
+
for (const [stepKey, ownerIndex] of stepKeyToOwner) {
|
|
36
36
|
ensureOwner(ownerIndex);
|
|
37
|
-
const toolStep = toolStepByKey.get(
|
|
37
|
+
const toolStep = toolStepByKey.get(stepKey);
|
|
38
38
|
const inputBindings = toolStep?.roleBindingSpec?.inputBindings ?? [];
|
|
39
|
-
const bucket = strategyState[
|
|
39
|
+
const bucket = strategyState[stepKey];
|
|
40
40
|
for (const inputRoleId of inputBindings) {
|
|
41
41
|
const entry = bucket?.[inputRoleId];
|
|
42
42
|
if (!entry || entry.strategyStateEntryKind !== 'internalInputPotential')
|
|
43
43
|
continue;
|
|
44
|
-
const
|
|
45
|
-
if (typeof
|
|
46
|
-
throw new Error(`Unresolvable internalInputPotential in toolStep '${
|
|
44
|
+
const producerStepKey = entry.toolStepRoleAddress?.stepKey;
|
|
45
|
+
if (typeof producerStepKey !== 'string') {
|
|
46
|
+
throw new Error(`Unresolvable internalInputPotential in toolStep '${stepKey}' (${getOwnerLabel(ownerIndex)}): missing toolStepRoleAddress.stepKey for role '${inputRoleId}'`);
|
|
47
47
|
}
|
|
48
|
-
const producerOwner =
|
|
48
|
+
const producerOwner = stepKeyToOwner.get(producerStepKey);
|
|
49
49
|
if (producerOwner === undefined) {
|
|
50
|
-
throw new Error(`Unresolvable internalInputPotential in toolStep '${
|
|
50
|
+
throw new Error(`Unresolvable internalInputPotential in toolStep '${stepKey}' (${getOwnerLabel(ownerIndex)}): source stepKey '${producerStepKey}' not found in strategy steps`);
|
|
51
51
|
}
|
|
52
52
|
ensureOwner(producerOwner);
|
|
53
53
|
ownerAdj.get(ownerIndex)?.add(producerOwner);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Strategy } from '@toolproof-core/genesis';
|
|
2
2
|
import type { MutableStrategy } from './mutableStrategyOverlay.js';
|
|
3
|
-
export declare function composeStrategyForExecution
|
|
3
|
+
export declare function composeStrategyForExecution(mutableStrategy: MutableStrategy): Strategy;
|
|
@@ -2,5 +2,5 @@ import type { Strategy, ToolStepPath } from '@toolproof-core/genesis';
|
|
|
2
2
|
import type { MutableStrategy, MutableStrategyStateEntryByRoleName, MutableToolStepKey } from './mutableStrategyOverlay.js';
|
|
3
3
|
export declare function strategyToMutableStrategy(strategy: Strategy): MutableStrategy;
|
|
4
4
|
export declare function mutableStrategyToStrategy(mutableStrategy: MutableStrategy): Strategy;
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
5
|
+
export declare function mutableStepKeyToToolStepPath(mutableStrategy: MutableStrategy, stepKey: MutableToolStepKey): ToolStepPath;
|
|
6
|
+
export declare function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(mutableStrategy: MutableStrategy, stepKey: MutableToolStepKey, entries: MutableStrategyStateEntryByRoleName): Strategy['strategyState'];
|
|
@@ -2,8 +2,8 @@ import { CONSTANTS } from '../lookups/lookups.js';
|
|
|
2
2
|
import { generateIdentifier } from './identifierGeneration.js';
|
|
3
3
|
function stripMutableCase(stepCase) {
|
|
4
4
|
const { when, what, ...rest } = stepCase;
|
|
5
|
-
const {
|
|
6
|
-
const {
|
|
5
|
+
const { stepKey: _whenStepKey, ...canonicalWhen } = when;
|
|
6
|
+
const { stepKey: _whatStepKey, ...canonicalWhat } = what;
|
|
7
7
|
return {
|
|
8
8
|
...rest,
|
|
9
9
|
when: canonicalWhen,
|
|
@@ -15,18 +15,18 @@ function buildExecutionPathMap(strategy) {
|
|
|
15
15
|
const registerStep = (step, pathPrefix) => {
|
|
16
16
|
switch (step.stepKind) {
|
|
17
17
|
case CONSTANTS.Enums.StepKind.tool:
|
|
18
|
-
executionPathByKey.set(step.
|
|
18
|
+
executionPathByKey.set(step.stepKey, `${pathPrefix}/self`);
|
|
19
19
|
return;
|
|
20
20
|
case CONSTANTS.Enums.StepKind.branch:
|
|
21
21
|
step.cases.forEach((stepCase, caseIndex) => {
|
|
22
|
-
executionPathByKey.set(stepCase.when.
|
|
23
|
-
executionPathByKey.set(stepCase.what.
|
|
22
|
+
executionPathByKey.set(stepCase.when.stepKey, `${pathPrefix}/cases/${caseIndex}/when`);
|
|
23
|
+
executionPathByKey.set(stepCase.what.stepKey, `${pathPrefix}/cases/${caseIndex}/what`);
|
|
24
24
|
});
|
|
25
25
|
return;
|
|
26
26
|
case CONSTANTS.Enums.StepKind.while:
|
|
27
27
|
case CONSTANTS.Enums.StepKind.for:
|
|
28
|
-
executionPathByKey.set(step.case.when.
|
|
29
|
-
executionPathByKey.set(step.case.what.
|
|
28
|
+
executionPathByKey.set(step.case.when.stepKey, `${pathPrefix}/case/when`);
|
|
29
|
+
executionPathByKey.set(step.case.what.stepKey, `${pathPrefix}/case/what`);
|
|
30
30
|
return;
|
|
31
31
|
default:
|
|
32
32
|
throw new Error('Unsupported step kind while projecting strategy.');
|
|
@@ -43,9 +43,9 @@ function toCanonicalStrategyStateEntry(entry, executionPathByKey) {
|
|
|
43
43
|
if (entry.strategyStateEntryKind !== 'internalInputPotential') {
|
|
44
44
|
return entry;
|
|
45
45
|
}
|
|
46
|
-
const sourceToolStepPath = executionPathByKey.get(entry.toolStepRoleAddress.
|
|
46
|
+
const sourceToolStepPath = executionPathByKey.get(entry.toolStepRoleAddress.stepKey);
|
|
47
47
|
if (!sourceToolStepPath) {
|
|
48
|
-
throw new Error(`Cannot project strategy state: no execution path found for
|
|
48
|
+
throw new Error(`Cannot project strategy state: no execution path found for stepKey '${entry.toolStepRoleAddress.stepKey}'.`);
|
|
49
49
|
}
|
|
50
50
|
return {
|
|
51
51
|
strategyStateEntryKind: 'internalInputPotential',
|
|
@@ -58,11 +58,11 @@ function toCanonicalStrategyStateEntry(entry, executionPathByKey) {
|
|
|
58
58
|
function toCanonicalStep(step) {
|
|
59
59
|
switch (step.stepKind) {
|
|
60
60
|
case CONSTANTS.Enums.StepKind.tool: {
|
|
61
|
-
const {
|
|
61
|
+
const { stepKey: _stepKey, ...canonicalToolStep } = step;
|
|
62
62
|
return canonicalToolStep;
|
|
63
63
|
}
|
|
64
64
|
case CONSTANTS.Enums.StepKind.branch: {
|
|
65
|
-
const { macroStepKey: _macroStepKey, cases, ...rest } = step;
|
|
65
|
+
const { stepKey: _stepKey, macroStepKey: _macroStepKey, cases, ...rest } = step;
|
|
66
66
|
return {
|
|
67
67
|
...rest,
|
|
68
68
|
cases: cases.map(stripMutableCase),
|
|
@@ -70,7 +70,7 @@ function toCanonicalStep(step) {
|
|
|
70
70
|
}
|
|
71
71
|
case CONSTANTS.Enums.StepKind.while:
|
|
72
72
|
case CONSTANTS.Enums.StepKind.for: {
|
|
73
|
-
const { macroStepKey: _macroStepKey, case: stepCase, ...rest } = step;
|
|
73
|
+
const { stepKey: _stepKey, macroStepKey: _macroStepKey, case: stepCase, ...rest } = step;
|
|
74
74
|
return {
|
|
75
75
|
...rest,
|
|
76
76
|
case: stripMutableCase(stepCase),
|
|
@@ -91,15 +91,16 @@ function toMutableStrategyStateEntry(entry, executionKeyByPath) {
|
|
|
91
91
|
return {
|
|
92
92
|
strategyStateEntryKind: 'internalInputPotential',
|
|
93
93
|
toolStepRoleAddress: {
|
|
94
|
-
|
|
94
|
+
stepKey: sourceToolStepKey,
|
|
95
95
|
roleName: entry.toolStepRoleAddress.roleName,
|
|
96
96
|
},
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
function toMutableToolStep(step) {
|
|
100
|
+
const key = generateIdentifier('ToolStepKey');
|
|
100
101
|
return {
|
|
101
102
|
...step,
|
|
102
|
-
|
|
103
|
+
stepKey: key,
|
|
103
104
|
};
|
|
104
105
|
}
|
|
105
106
|
function toMutableCase(stepCase) {
|
|
@@ -112,25 +113,31 @@ function toMutableCase(stepCase) {
|
|
|
112
113
|
}
|
|
113
114
|
function toMutableBranchStep(step) {
|
|
114
115
|
const { cases, ...rest } = step;
|
|
116
|
+
const key = generateIdentifier('BranchStepKey');
|
|
115
117
|
return {
|
|
116
118
|
...rest,
|
|
117
|
-
|
|
119
|
+
stepKey: key,
|
|
120
|
+
macroStepKey: key,
|
|
118
121
|
cases: cases.map(toMutableCase),
|
|
119
122
|
};
|
|
120
123
|
}
|
|
121
124
|
function toMutableWhileStep(step) {
|
|
122
125
|
const { case: stepCase, ...rest } = step;
|
|
126
|
+
const key = generateIdentifier('WhileStepKey');
|
|
123
127
|
return {
|
|
124
128
|
...rest,
|
|
125
|
-
|
|
129
|
+
stepKey: key,
|
|
130
|
+
macroStepKey: key,
|
|
126
131
|
case: toMutableCase(stepCase),
|
|
127
132
|
};
|
|
128
133
|
}
|
|
129
134
|
function toMutableForStep(step) {
|
|
130
135
|
const { case: stepCase, ...rest } = step;
|
|
136
|
+
const key = generateIdentifier('ForStepKey');
|
|
131
137
|
return {
|
|
132
138
|
...rest,
|
|
133
|
-
|
|
139
|
+
stepKey: key,
|
|
140
|
+
macroStepKey: key,
|
|
134
141
|
case: toMutableCase(stepCase),
|
|
135
142
|
};
|
|
136
143
|
}
|
|
@@ -151,8 +158,8 @@ function toMutableStep(step) {
|
|
|
151
158
|
function buildExecutionKeyMap(strategy) {
|
|
152
159
|
const executionPathByKey = buildExecutionPathMap(strategy);
|
|
153
160
|
const executionKeyByPath = new Map();
|
|
154
|
-
for (const [
|
|
155
|
-
executionKeyByPath.set(toolStepPath,
|
|
161
|
+
for (const [stepKey, toolStepPath] of executionPathByKey.entries()) {
|
|
162
|
+
executionKeyByPath.set(toolStepPath, stepKey);
|
|
156
163
|
}
|
|
157
164
|
return executionKeyByPath;
|
|
158
165
|
}
|
|
@@ -189,17 +196,17 @@ export function strategyToMutableStrategy(strategy) {
|
|
|
189
196
|
export function mutableStrategyToStrategy(mutableStrategy) {
|
|
190
197
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
191
198
|
const strategyState = {};
|
|
192
|
-
for (const [
|
|
199
|
+
for (const [stepKey, inputEntryByRoleName] of Object.entries(mutableStrategy.strategyState)) {
|
|
193
200
|
if (!inputEntryByRoleName) {
|
|
194
201
|
continue;
|
|
195
202
|
}
|
|
196
|
-
const toolStepPath = executionPathByKey.get(
|
|
203
|
+
const toolStepPath = executionPathByKey.get(stepKey);
|
|
197
204
|
if (!toolStepPath) {
|
|
198
|
-
throw new Error(`Cannot project strategy state: no execution path found for
|
|
205
|
+
throw new Error(`Cannot project strategy state: no execution path found for stepKey '${stepKey}'.`);
|
|
199
206
|
}
|
|
200
207
|
strategyState[toolStepPath] = Object.fromEntries(Object.entries(inputEntryByRoleName).map(([roleName, entry]) => {
|
|
201
208
|
if (entry === undefined) {
|
|
202
|
-
throw new Error(`Cannot project strategy state: role '${roleName}' on
|
|
209
|
+
throw new Error(`Cannot project strategy state: role '${roleName}' on stepKey '${stepKey}' is explicitly undefined.`);
|
|
203
210
|
}
|
|
204
211
|
return [
|
|
205
212
|
roleName,
|
|
@@ -213,25 +220,25 @@ export function mutableStrategyToStrategy(mutableStrategy) {
|
|
|
213
220
|
strategyState,
|
|
214
221
|
};
|
|
215
222
|
}
|
|
216
|
-
export function
|
|
223
|
+
export function mutableStepKeyToToolStepPath(mutableStrategy, stepKey) {
|
|
217
224
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
218
|
-
const toolStepPath = executionPathByKey.get(
|
|
225
|
+
const toolStepPath = executionPathByKey.get(stepKey);
|
|
219
226
|
if (!toolStepPath) {
|
|
220
|
-
throw new Error(`Cannot project toolStepPath: no execution path found for
|
|
227
|
+
throw new Error(`Cannot project toolStepPath: no execution path found for stepKey '${stepKey}'.`);
|
|
221
228
|
}
|
|
222
229
|
return toolStepPath;
|
|
223
230
|
}
|
|
224
|
-
export function
|
|
231
|
+
export function projectMutableStrategyStateEntriesByStepKeyToCanonicalDelta(mutableStrategy, stepKey, entries) {
|
|
225
232
|
const executionPathByKey = buildExecutionPathMap(mutableStrategy);
|
|
226
|
-
const toolStepPath = executionPathByKey.get(
|
|
233
|
+
const toolStepPath = executionPathByKey.get(stepKey);
|
|
227
234
|
if (!toolStepPath) {
|
|
228
|
-
throw new Error(`Cannot project strategy state delta: no execution path found for
|
|
235
|
+
throw new Error(`Cannot project strategy state delta: no execution path found for stepKey '${stepKey}'.`);
|
|
229
236
|
}
|
|
230
237
|
const canonicalEntries = Object.fromEntries(Object.entries(entries)
|
|
231
238
|
.filter(([, entry]) => entry !== undefined)
|
|
232
239
|
.map(([roleName, entry]) => {
|
|
233
240
|
if (entry === undefined) {
|
|
234
|
-
throw new Error(`Cannot project strategy state delta: role '${roleName}' on
|
|
241
|
+
throw new Error(`Cannot project strategy state delta: role '${roleName}' on stepKey '${stepKey}' is explicitly undefined.`);
|
|
235
242
|
}
|
|
236
243
|
return [
|
|
237
244
|
roleName,
|