@holoscript/plugin-wisdom-gotcha 2.0.1 → 2.0.2
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/package.json +3 -3
- package/src/index.ts +17 -3
- package/src/traits/GotchaTrait.ts +38 -9
- package/src/traits/WisdomTrait.ts +48 -11
- package/src/traits/types.ts +22 -4
- package/tsconfig.json +5 -1
- package/LICENSE +0 -21
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holoscript/plugin-wisdom-gotcha",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@holoscript/core": "8.0.
|
|
6
|
+
"@holoscript/core": ">=8.0.0"
|
|
7
7
|
},
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "vitest run --passWithNoTests",
|
|
11
11
|
"test:coverage": "vitest run --coverage --passWithNoTests"
|
|
12
12
|
}
|
|
13
|
-
}
|
|
13
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
createWisdomHandler,
|
|
3
|
+
type WisdomConfig,
|
|
4
|
+
type WisdomSeverity,
|
|
5
|
+
type WisdomDomain,
|
|
6
|
+
} from './traits/WisdomTrait';
|
|
7
|
+
export {
|
|
8
|
+
createGotchaHandler,
|
|
9
|
+
type GotchaConfig,
|
|
10
|
+
type GotchaSeverity,
|
|
11
|
+
type GuardAction,
|
|
12
|
+
} from './traits/GotchaTrait';
|
|
3
13
|
export * from './traits/types';
|
|
4
14
|
|
|
5
15
|
import { createWisdomHandler } from './traits/WisdomTrait';
|
|
6
16
|
import { createGotchaHandler } from './traits/GotchaTrait';
|
|
7
17
|
|
|
8
|
-
export const pluginMeta = {
|
|
18
|
+
export const pluginMeta = {
|
|
19
|
+
name: '@holoscript/plugin-wisdom-gotcha',
|
|
20
|
+
version: '1.0.0',
|
|
21
|
+
traits: ['wisdom', 'gotcha'],
|
|
22
|
+
};
|
|
9
23
|
export const traitHandlers = [createWisdomHandler(), createGotchaHandler()];
|
|
@@ -28,30 +28,59 @@ export interface GotchaState {
|
|
|
28
28
|
tripCount: number;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const defaultConfig: GotchaConfig = {
|
|
31
|
+
const defaultConfig: GotchaConfig = {
|
|
32
|
+
id: '',
|
|
33
|
+
trap: '',
|
|
34
|
+
severity: 'error',
|
|
35
|
+
guard: 'warn',
|
|
36
|
+
filePatterns: [],
|
|
37
|
+
codePatterns: [],
|
|
38
|
+
remediation: '',
|
|
39
|
+
};
|
|
32
40
|
|
|
33
41
|
export function createGotchaHandler(): TraitHandler<GotchaConfig> {
|
|
34
|
-
return {
|
|
42
|
+
return {
|
|
43
|
+
name: 'gotcha',
|
|
44
|
+
defaultConfig,
|
|
35
45
|
onAttach(n: HSPlusNode, c: GotchaConfig, ctx: TraitContext) {
|
|
36
46
|
n.__gotchaState = { tripped: false, trippedAt: null, guardActivated: false, tripCount: 0 };
|
|
37
47
|
ctx.emit?.('gotcha:armed', { id: c.id, guard: c.guard });
|
|
38
48
|
},
|
|
39
|
-
onDetach(n: HSPlusNode, _c: GotchaConfig, ctx: TraitContext) {
|
|
49
|
+
onDetach(n: HSPlusNode, _c: GotchaConfig, ctx: TraitContext) {
|
|
50
|
+
delete n.__gotchaState;
|
|
51
|
+
ctx.emit?.('gotcha:disarmed');
|
|
52
|
+
},
|
|
40
53
|
onUpdate() {},
|
|
41
54
|
onEvent(n: HSPlusNode, c: GotchaConfig, ctx: TraitContext, e: TraitEvent) {
|
|
42
|
-
const s = n.__gotchaState as GotchaState | undefined;
|
|
55
|
+
const s = n.__gotchaState as GotchaState | undefined;
|
|
56
|
+
if (!s) return;
|
|
43
57
|
if (e.type === 'gotcha:check') {
|
|
44
58
|
const file = (e.payload?.file as string) ?? '';
|
|
45
59
|
const code = (e.payload?.code as string) ?? '';
|
|
46
|
-
const fileMatch =
|
|
47
|
-
|
|
60
|
+
const fileMatch =
|
|
61
|
+
c.filePatterns.length === 0 || c.filePatterns.some((p) => file.includes(p));
|
|
62
|
+
const codeMatch =
|
|
63
|
+
c.codePatterns.length === 0 || c.codePatterns.some((p) => code.includes(p));
|
|
48
64
|
if (fileMatch && codeMatch) {
|
|
49
|
-
s.tripped = true;
|
|
65
|
+
s.tripped = true;
|
|
66
|
+
s.trippedAt = Date.now();
|
|
67
|
+
s.tripCount++;
|
|
50
68
|
if (c.guard !== 'warn') s.guardActivated = true;
|
|
51
|
-
ctx.emit?.('gotcha:tripped', {
|
|
69
|
+
ctx.emit?.('gotcha:tripped', {
|
|
70
|
+
id: c.id,
|
|
71
|
+
severity: c.severity,
|
|
72
|
+
trap: c.trap,
|
|
73
|
+
guard: c.guard,
|
|
74
|
+
remediation: c.remediation,
|
|
75
|
+
blocked: c.guard !== 'warn',
|
|
76
|
+
});
|
|
52
77
|
}
|
|
53
78
|
}
|
|
54
|
-
if (e.type === 'gotcha:acknowledge') {
|
|
79
|
+
if (e.type === 'gotcha:acknowledge') {
|
|
80
|
+
s.tripped = false;
|
|
81
|
+
s.guardActivated = false;
|
|
82
|
+
ctx.emit?.('gotcha:acknowledged', { id: c.id });
|
|
83
|
+
}
|
|
55
84
|
},
|
|
56
85
|
};
|
|
57
86
|
}
|
|
@@ -8,7 +8,13 @@
|
|
|
8
8
|
import type { TraitHandler, HSPlusNode, TraitContext, TraitEvent } from './types';
|
|
9
9
|
|
|
10
10
|
export type WisdomSeverity = 'info' | 'warning' | 'error' | 'suggestion';
|
|
11
|
-
export type WisdomDomain =
|
|
11
|
+
export type WisdomDomain =
|
|
12
|
+
| 'performance'
|
|
13
|
+
| 'security'
|
|
14
|
+
| 'correctness'
|
|
15
|
+
| 'style'
|
|
16
|
+
| 'compatibility'
|
|
17
|
+
| 'architecture';
|
|
12
18
|
|
|
13
19
|
export interface WisdomConfig {
|
|
14
20
|
id: string;
|
|
@@ -30,31 +36,62 @@ export interface WisdomState {
|
|
|
30
36
|
suppressedByUser: boolean;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
const defaultConfig: WisdomConfig = {
|
|
39
|
+
const defaultConfig: WisdomConfig = {
|
|
40
|
+
id: '',
|
|
41
|
+
message: '',
|
|
42
|
+
severity: 'info',
|
|
43
|
+
domain: 'correctness',
|
|
44
|
+
autoFix: false,
|
|
45
|
+
appliesTo: [],
|
|
46
|
+
references: [],
|
|
47
|
+
confidence: 0.9,
|
|
48
|
+
};
|
|
34
49
|
|
|
35
50
|
export function createWisdomHandler(): TraitHandler<WisdomConfig> {
|
|
36
|
-
return {
|
|
51
|
+
return {
|
|
52
|
+
name: 'wisdom',
|
|
53
|
+
defaultConfig,
|
|
37
54
|
onAttach(n: HSPlusNode, c: WisdomConfig, ctx: TraitContext) {
|
|
38
|
-
n.__wisdomState = {
|
|
55
|
+
n.__wisdomState = {
|
|
56
|
+
triggered: false,
|
|
57
|
+
triggeredAt: null,
|
|
58
|
+
fixApplied: false,
|
|
59
|
+
suppressedByUser: false,
|
|
60
|
+
};
|
|
39
61
|
ctx.emit?.('wisdom:registered', { id: c.id, severity: c.severity, domain: c.domain });
|
|
40
62
|
},
|
|
41
|
-
onDetach(n: HSPlusNode, _c: WisdomConfig, ctx: TraitContext) {
|
|
63
|
+
onDetach(n: HSPlusNode, _c: WisdomConfig, ctx: TraitContext) {
|
|
64
|
+
delete n.__wisdomState;
|
|
65
|
+
ctx.emit?.('wisdom:unregistered');
|
|
66
|
+
},
|
|
42
67
|
onUpdate() {},
|
|
43
68
|
onEvent(n: HSPlusNode, c: WisdomConfig, ctx: TraitContext, e: TraitEvent) {
|
|
44
|
-
const s = n.__wisdomState as WisdomState | undefined;
|
|
69
|
+
const s = n.__wisdomState as WisdomState | undefined;
|
|
70
|
+
if (!s) return;
|
|
45
71
|
if (e.type === 'wisdom:check') {
|
|
46
|
-
const context = e.payload?.context as string ?? '';
|
|
47
|
-
const matches =
|
|
72
|
+
const context = (e.payload?.context as string) ?? '';
|
|
73
|
+
const matches =
|
|
74
|
+
c.appliesTo.length === 0 || c.appliesTo.some((pattern) => context.includes(pattern));
|
|
48
75
|
if (matches && !s.suppressedByUser) {
|
|
49
|
-
s.triggered = true;
|
|
50
|
-
|
|
76
|
+
s.triggered = true;
|
|
77
|
+
s.triggeredAt = Date.now();
|
|
78
|
+
ctx.emit?.('wisdom:triggered', {
|
|
79
|
+
id: c.id,
|
|
80
|
+
severity: c.severity,
|
|
81
|
+
message: c.message,
|
|
82
|
+
autoFix: c.autoFix,
|
|
83
|
+
fixDescription: c.fixDescription,
|
|
84
|
+
});
|
|
51
85
|
}
|
|
52
86
|
}
|
|
53
87
|
if (e.type === 'wisdom:apply_fix' && c.autoFix && s.triggered) {
|
|
54
88
|
s.fixApplied = true;
|
|
55
89
|
ctx.emit?.('wisdom:fix_applied', { id: c.id, transform: c.fixTransform });
|
|
56
90
|
}
|
|
57
|
-
if (e.type === 'wisdom:suppress') {
|
|
91
|
+
if (e.type === 'wisdom:suppress') {
|
|
92
|
+
s.suppressedByUser = true;
|
|
93
|
+
ctx.emit?.('wisdom:suppressed', { id: c.id });
|
|
94
|
+
}
|
|
58
95
|
},
|
|
59
96
|
};
|
|
60
97
|
}
|
package/src/traits/types.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
export interface HSPlusNode {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export interface HSPlusNode {
|
|
2
|
+
id?: string;
|
|
3
|
+
properties?: Record<string, unknown>;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface TraitContext {
|
|
7
|
+
emit?: (event: string, payload?: unknown) => void;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface TraitEvent {
|
|
11
|
+
type: string;
|
|
12
|
+
payload?: Record<string, unknown>;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface TraitHandler<T = unknown> {
|
|
16
|
+
name: string;
|
|
17
|
+
defaultConfig: T;
|
|
18
|
+
onAttach(n: HSPlusNode, c: T, ctx: TraitContext): void;
|
|
19
|
+
onDetach(n: HSPlusNode, c: T, ctx: TraitContext): void;
|
|
20
|
+
onUpdate(n: HSPlusNode, c: T, ctx: TraitContext, d: number): void;
|
|
21
|
+
onEvent(n: HSPlusNode, c: T, ctx: TraitContext, e: TraitEvent): void;
|
|
22
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.json",
|
|
3
|
+
"compilerOptions": { "outDir": "dist", "rootDir": "src", "declaration": true },
|
|
4
|
+
"include": ["src"]
|
|
5
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025-2026 HoloScript Contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|