@shrkcrft/context 0.1.0-alpha.18 → 0.1.0-alpha.19
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/derive-applies-when.d.ts +2 -0
- package/dist/derive-applies-when.d.ts.map +1 -0
- package/dist/derive-applies-when.js +51 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/relevance-selector.d.ts.map +1 -1
- package/dist/relevance-selector.js +10 -1
- package/package.json +6 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive-applies-when.d.ts","sourceRoot":"","sources":["../src/derive-applies-when.ts"],"names":[],"mappings":"AAqCA,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAWxD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive `appliesWhen` tokens from a free-text task string.
|
|
3
|
+
*
|
|
4
|
+
* `shrk context` ranks knowledge entries via a lexical scorer. Foundational
|
|
5
|
+
* rules (e.g. `architecture.layer-order`) declare an `appliesWhen` like
|
|
6
|
+
* `generate-code` but share no surface tokens with a task such as "add a new
|
|
7
|
+
* plugin command" — so without a derived `appliesWhen` signal they earn no
|
|
8
|
+
* match reason and are dropped before priority is even considered.
|
|
9
|
+
*
|
|
10
|
+
* This maps task verbs/domains to the same canonical `appliesWhen` vocabulary
|
|
11
|
+
* the inspector task-ranker uses, so the rule that *governs* the work surfaces
|
|
12
|
+
* even when the wording doesn't overlap. Deterministic; no model in the loop.
|
|
13
|
+
*
|
|
14
|
+
* NOTE: the verb/domain vocabulary mirrors
|
|
15
|
+
* `packages/inspector/src/task-ranker.ts`. The context layer cannot import the
|
|
16
|
+
* higher inspector layer, so the small map is duplicated here on purpose — keep
|
|
17
|
+
* the two in sync if either grows.
|
|
18
|
+
*/
|
|
19
|
+
const VERB_APPLIES_WHEN = [
|
|
20
|
+
{
|
|
21
|
+
regex: /\b(create|add|implement|generate|new|build|introduce|provide)\b/,
|
|
22
|
+
appliesWhen: ['generate-code', 'generate-service', 'generate-utility', 'generate-template', 'create-feature'],
|
|
23
|
+
},
|
|
24
|
+
{ regex: /\b(refactor|rewrite|migrate|extract|rename)\b/, appliesWhen: ['refactor'] },
|
|
25
|
+
{ regex: /\b(test|spec|coverage)\b/, appliesWhen: ['generate-test'] },
|
|
26
|
+
{ regex: /\b(fix|bug|broken|crash)\b/, appliesWhen: ['fix-bug'] },
|
|
27
|
+
{ regex: /\b(review|audit|inspect)\b/, appliesWhen: ['review-pr', 'review-code', 'check-boundaries'] },
|
|
28
|
+
];
|
|
29
|
+
const DOMAIN_APPLIES_WHEN = [
|
|
30
|
+
{ token: 'service', appliesWhen: ['generate-service'] },
|
|
31
|
+
{ token: 'utility', appliesWhen: ['generate-utility'] },
|
|
32
|
+
{ token: 'utilities', appliesWhen: ['generate-utility'] },
|
|
33
|
+
{ token: 'pipeline', appliesWhen: ['create-pipeline'] },
|
|
34
|
+
{ token: 'route', appliesWhen: ['generate-route'] },
|
|
35
|
+
];
|
|
36
|
+
export function deriveAppliesWhen(task) {
|
|
37
|
+
const text = task.toLowerCase();
|
|
38
|
+
const out = new Set();
|
|
39
|
+
for (const v of VERB_APPLIES_WHEN) {
|
|
40
|
+
if (v.regex.test(text))
|
|
41
|
+
for (const a of v.appliesWhen)
|
|
42
|
+
out.add(a);
|
|
43
|
+
}
|
|
44
|
+
const tokens = new Set(text.split(/[^a-z0-9]+/).filter((t) => t.length >= 3));
|
|
45
|
+
for (const d of DOMAIN_APPLIES_WHEN) {
|
|
46
|
+
if (tokens.has(d.token))
|
|
47
|
+
for (const a of d.appliesWhen)
|
|
48
|
+
out.add(a);
|
|
49
|
+
}
|
|
50
|
+
return [...out].sort();
|
|
51
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export * from './context-section.js';
|
|
|
4
4
|
export * from './context-builder.js';
|
|
5
5
|
export * from './token-estimator.js';
|
|
6
6
|
export * from './relevance-selector.js';
|
|
7
|
+
export * from './derive-applies-when.js';
|
|
7
8
|
export * from './ai-context-formatter.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relevance-selector.d.ts","sourceRoot":"","sources":["../src/relevance-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"relevance-selector.d.ts","sourceRoot":"","sources":["../src/relevance-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AAeD,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,SAAS,eAAe,EAAE,EACtC,OAAO,EAAE,eAAe,EACxB,eAAe,SAAI,GAClB,eAAe,CAgDjB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KnowledgeIndex } from '@shrkcrft/knowledge';
|
|
2
|
+
import { deriveAppliesWhen } from "./derive-applies-when.js";
|
|
2
3
|
const TYPE_BUCKETS = {
|
|
3
4
|
rule: 'rules',
|
|
4
5
|
path: 'paths',
|
|
@@ -19,11 +20,19 @@ export function selectRelevantEntries(allEntries, request, limitPerSection = 5)
|
|
|
19
20
|
scope.push(request.framework);
|
|
20
21
|
if (request.area)
|
|
21
22
|
scope.push(request.area);
|
|
23
|
+
// Merge any explicit appliesWhen with tokens derived from the task verbs /
|
|
24
|
+
// domain so foundational rules that key on `appliesWhen` (e.g.
|
|
25
|
+
// architecture.layer-order on 'generate-code') earn a match reason for a task
|
|
26
|
+
// whose wording doesn't overlap the rule. Without this they score 0 reasons
|
|
27
|
+
// and are dropped before priority matters.
|
|
28
|
+
const appliesWhen = [
|
|
29
|
+
...new Set([...(request.appliesWhen ?? []), ...deriveAppliesWhen(request.task)]),
|
|
30
|
+
];
|
|
22
31
|
const searchAll = index.search({
|
|
23
32
|
query: request.task,
|
|
24
33
|
scope,
|
|
25
34
|
tags,
|
|
26
|
-
appliesWhen
|
|
35
|
+
appliesWhen,
|
|
27
36
|
});
|
|
28
37
|
const buckets = {
|
|
29
38
|
rules: [],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shrkcrft/context",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.19",
|
|
4
4
|
"description": "SharkCraft AI context builder: token-budgeted relevance retrieval for tasks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SharkCraft contributors",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@shrkcrft/core": "^0.1.0-alpha.
|
|
48
|
-
"@shrkcrft/knowledge": "^0.1.0-alpha.
|
|
49
|
-
"@shrkcrft/rules": "^0.1.0-alpha.
|
|
50
|
-
"@shrkcrft/paths": "^0.1.0-alpha.
|
|
51
|
-
"@shrkcrft/templates": "^0.1.0-alpha.
|
|
47
|
+
"@shrkcrft/core": "^0.1.0-alpha.19",
|
|
48
|
+
"@shrkcrft/knowledge": "^0.1.0-alpha.19",
|
|
49
|
+
"@shrkcrft/rules": "^0.1.0-alpha.19",
|
|
50
|
+
"@shrkcrft/paths": "^0.1.0-alpha.19",
|
|
51
|
+
"@shrkcrft/templates": "^0.1.0-alpha.19"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|