@varveai/adit-engine 0.3.0 → 0.3.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.
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intent classification for user prompts and AI responses.
|
|
3
|
+
*
|
|
4
|
+
* Uses keyword/regex matching to assign semantic labels to events.
|
|
5
|
+
* Designed to be fast (< 0.2ms) since it runs inside hook handlers.
|
|
6
|
+
*/
|
|
7
|
+
/** A single classification rule. */
|
|
8
|
+
export interface IntentRule {
|
|
9
|
+
/** Machine-readable intent key, e.g. "rollback" */
|
|
10
|
+
intent: string;
|
|
11
|
+
/** Pre-compiled regex patterns (applied against lowercased text). */
|
|
12
|
+
patterns: RegExp[];
|
|
13
|
+
/** Human-readable description of this intent. */
|
|
14
|
+
description: string;
|
|
15
|
+
}
|
|
16
|
+
/** Default intent rules covering common development activities. */
|
|
17
|
+
export declare const DEFAULT_INTENT_RULES: IntentRule[];
|
|
18
|
+
/**
|
|
19
|
+
* Classify intent from user prompt only (lightweight, for prompt_submit).
|
|
20
|
+
* Returns an array of matched intent keys.
|
|
21
|
+
*/
|
|
22
|
+
export declare function classifyIntentFromPrompt(prompt: string): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Classify intent from both user prompt and AI response.
|
|
25
|
+
* Combines matches from both sources for a richer classification.
|
|
26
|
+
*/
|
|
27
|
+
export declare function classifyIntent(prompt: string, responseText?: string | null): string[];
|
|
28
|
+
//# sourceMappingURL=intent-classifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-classifier.d.ts","sourceRoot":"","sources":["../../src/timeline/intent-classifier.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oCAAoC;AACpC,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,EAAE,UAAU,EAgE5C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAGjE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAC3B,MAAM,EAAE,CAmBV"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intent classification for user prompts and AI responses.
|
|
3
|
+
*
|
|
4
|
+
* Uses keyword/regex matching to assign semantic labels to events.
|
|
5
|
+
* Designed to be fast (< 0.2ms) since it runs inside hook handlers.
|
|
6
|
+
*/
|
|
7
|
+
/** Default intent rules covering common development activities. */
|
|
8
|
+
export const DEFAULT_INTENT_RULES = [
|
|
9
|
+
{
|
|
10
|
+
intent: "rollback",
|
|
11
|
+
patterns: [
|
|
12
|
+
/\bundo\b/,
|
|
13
|
+
/\brevert\b/,
|
|
14
|
+
/\brollback\b/,
|
|
15
|
+
/\b回滚\b/,
|
|
16
|
+
/\b撤回\b/,
|
|
17
|
+
/\b恢复到\b/,
|
|
18
|
+
/\b还原\b/,
|
|
19
|
+
/go back to/i,
|
|
20
|
+
/restore to/i,
|
|
21
|
+
/reset (to|--hard)/i,
|
|
22
|
+
/git checkout\b/,
|
|
23
|
+
/reverted commit/i,
|
|
24
|
+
],
|
|
25
|
+
description: "Rolling back or undoing code changes",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
intent: "debug",
|
|
29
|
+
patterns: [
|
|
30
|
+
/\bdebug\b/,
|
|
31
|
+
/\b调试\b/,
|
|
32
|
+
/\bfix bug\b/i,
|
|
33
|
+
/\bfix\b/,
|
|
34
|
+
/\b修复\b/,
|
|
35
|
+
/\b报错\b/,
|
|
36
|
+
/\bstack trace\b/i,
|
|
37
|
+
/\b崩溃\b/,
|
|
38
|
+
/\berror\b/i,
|
|
39
|
+
/\bexception\b/i,
|
|
40
|
+
/\bcrash\b/i,
|
|
41
|
+
],
|
|
42
|
+
description: "Debugging or fixing bugs",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
intent: "refactor",
|
|
46
|
+
patterns: [
|
|
47
|
+
/\brefactor\b/,
|
|
48
|
+
/\b重构\b/,
|
|
49
|
+
/\brestructure\b/,
|
|
50
|
+
/\breorganize\b/,
|
|
51
|
+
/clean\s?up/i,
|
|
52
|
+
/\b整理代码\b/,
|
|
53
|
+
],
|
|
54
|
+
description: "Refactoring or restructuring code",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
intent: "question",
|
|
58
|
+
patterns: [
|
|
59
|
+
/\bexplain\b/,
|
|
60
|
+
/\b解释\b/,
|
|
61
|
+
/\bwhat is\b/i,
|
|
62
|
+
/\b什么是\b/,
|
|
63
|
+
/\bwhy\b/,
|
|
64
|
+
/\b为什么\b/,
|
|
65
|
+
/\bhow does\b/i,
|
|
66
|
+
/\b是怎么/,
|
|
67
|
+
/\bhow do\b/i,
|
|
68
|
+
/\uFF1F$/, // Chinese question mark at end
|
|
69
|
+
],
|
|
70
|
+
description: "Asking a question or requesting explanation",
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
/**
|
|
74
|
+
* Classify intent from user prompt only (lightweight, for prompt_submit).
|
|
75
|
+
* Returns an array of matched intent keys.
|
|
76
|
+
*/
|
|
77
|
+
export function classifyIntentFromPrompt(prompt) {
|
|
78
|
+
if (!prompt || prompt.trim().length === 0)
|
|
79
|
+
return [];
|
|
80
|
+
return matchRules(prompt);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Classify intent from both user prompt and AI response.
|
|
84
|
+
* Combines matches from both sources for a richer classification.
|
|
85
|
+
*/
|
|
86
|
+
export function classifyIntent(prompt, responseText) {
|
|
87
|
+
if (!prompt || prompt.trim().length === 0)
|
|
88
|
+
return [];
|
|
89
|
+
const labels = matchRules(prompt);
|
|
90
|
+
if (responseText) {
|
|
91
|
+
for (const rule of DEFAULT_INTENT_RULES) {
|
|
92
|
+
if (labels.includes(rule.intent))
|
|
93
|
+
continue;
|
|
94
|
+
if (rule.patterns.some((p) => p.test(responseText.toLowerCase()))) {
|
|
95
|
+
labels.push(rule.intent);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (labels.length === 0) {
|
|
100
|
+
labels.push("normal_execution");
|
|
101
|
+
}
|
|
102
|
+
return labels;
|
|
103
|
+
}
|
|
104
|
+
function matchRules(text) {
|
|
105
|
+
const lower = text.toLowerCase();
|
|
106
|
+
const labels = [];
|
|
107
|
+
for (const rule of DEFAULT_INTENT_RULES) {
|
|
108
|
+
if (rule.patterns.some((p) => p.test(lower))) {
|
|
109
|
+
labels.push(rule.intent);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return labels;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=intent-classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-classifier.js","sourceRoot":"","sources":["../../src/timeline/intent-classifier.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,mEAAmE;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAiB;IAChD;QACE,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE;YACR,UAAU;YACV,YAAY;YACZ,cAAc;YACd,QAAQ;YACR,QAAQ;YACR,SAAS;YACT,QAAQ;YACR,aAAa;YACb,aAAa;YACb,oBAAoB;YACpB,gBAAgB;YAChB,kBAAkB;SACnB;QACD,WAAW,EAAE,sCAAsC;KACpD;IACD;QACE,MAAM,EAAE,OAAO;QACf,QAAQ,EAAE;YACR,WAAW;YACX,QAAQ;YACR,cAAc;YACd,SAAS;YACT,QAAQ;YACR,QAAQ;YACR,kBAAkB;YAClB,QAAQ;YACR,YAAY;YACZ,gBA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3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,KAAK,MAAM,IAAI,IAAI,oBAAoB,EAAE,CAAC;QACxC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varveai/adit-engine",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Git operations, snapshots, detection, and timeline engine for ADIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@varveai/adit-core": "0.3.
|
|
18
|
+
"@varveai/adit-core": "0.3.2"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/better-sqlite3": "^7.6.13",
|