@shrkcrft/paths 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/path-convention.d.ts +17 -0
- package/dist/path-convention.d.ts.map +1 -0
- package/dist/path-convention.js +16 -0
- package/dist/path-query.d.ts +9 -0
- package/dist/path-query.d.ts.map +1 -0
- package/dist/path-query.js +1 -0
- package/dist/path-selector.d.ts +8 -0
- package/dist/path-selector.d.ts.map +1 -0
- package/dist/path-selector.js +36 -0
- package/dist/path-service.d.ts +13 -0
- package/dist/path-service.d.ts.map +1 -0
- package/dist/path-service.js +33 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SharkCraft 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.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @shrkcrft/paths
|
|
2
|
+
|
|
3
|
+
SharkCraft path-convention service: typed path entries and best-fit selection.
|
|
4
|
+
|
|
5
|
+
Part of [SharkCraft](https://github.com/shrkcrft/sharkcraft) — a deterministic, local-first toolkit that gives AI coding agents durable project context. See the main repo for documentation, examples, and the `shrk` CLI.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @shrkcrft/paths
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT — see [LICENSE](./LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type DefineKnowledgeInput, type IKnowledgeEntry } from '@shrkcrft/knowledge';
|
|
2
|
+
export interface IPathConvention extends IKnowledgeEntry {
|
|
3
|
+
readonly metadata: Readonly<{
|
|
4
|
+
path: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
}> & Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export type DefinePathConventionInput = Omit<DefineKnowledgeInput, 'type' | 'content'> & {
|
|
9
|
+
/** The actual path (relative to project root). */
|
|
10
|
+
path: string;
|
|
11
|
+
/** Optional human description. Used as the entry content when no explicit content is given. */
|
|
12
|
+
description?: string;
|
|
13
|
+
/** Optional override for explicit content. */
|
|
14
|
+
content?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function definePathConvention(input: DefinePathConventionInput): IPathConvention;
|
|
17
|
+
//# sourceMappingURL=path-convention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-convention.d.ts","sourceRoot":"","sources":["../src/path-convention.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/F;AAED,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG;IACvF,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,+FAA+F;IAC/F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,eAAe,CAetF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineKnowledgeEntry, KnowledgeType, } from '@shrkcrft/knowledge';
|
|
2
|
+
export function definePathConvention(input) {
|
|
3
|
+
const content = input.content ??
|
|
4
|
+
`${input.description ?? input.title}\nCanonical path: ${input.path}`;
|
|
5
|
+
const entry = defineKnowledgeEntry({
|
|
6
|
+
...input,
|
|
7
|
+
type: KnowledgeType.Path,
|
|
8
|
+
content,
|
|
9
|
+
metadata: {
|
|
10
|
+
...(input.metadata ?? {}),
|
|
11
|
+
path: input.path,
|
|
12
|
+
description: input.description,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
return entry;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-query.d.ts","sourceRoot":"","sources":["../src/path-query.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IPathConvention } from './path-convention.js';
|
|
2
|
+
export interface IPathSelection {
|
|
3
|
+
convention: IPathConvention;
|
|
4
|
+
reason: string;
|
|
5
|
+
score: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function selectBestPath(candidates: readonly IPathConvention[], task: string): IPathSelection | null;
|
|
8
|
+
//# sourceMappingURL=path-selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-selector.d.ts","sourceRoot":"","sources":["../src/path-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,eAAe,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,cAAc,CAC5B,UAAU,EAAE,SAAS,eAAe,EAAE,EACtC,IAAI,EAAE,MAAM,GACX,cAAc,GAAG,IAAI,CAkCvB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function selectBestPath(candidates, task) {
|
|
2
|
+
if (candidates.length === 0)
|
|
3
|
+
return null;
|
|
4
|
+
const taskLower = task.toLowerCase();
|
|
5
|
+
const scored = candidates
|
|
6
|
+
.map((c) => {
|
|
7
|
+
let score = 0;
|
|
8
|
+
const reasons = [];
|
|
9
|
+
if (c.tags.some((t) => taskLower.includes(t.toLowerCase()))) {
|
|
10
|
+
score += 30;
|
|
11
|
+
reasons.push('tag match');
|
|
12
|
+
}
|
|
13
|
+
if (c.appliesWhen.some((a) => taskLower.includes(a.toLowerCase()))) {
|
|
14
|
+
score += 40;
|
|
15
|
+
reasons.push('appliesWhen match');
|
|
16
|
+
}
|
|
17
|
+
if (c.scope.some((s) => taskLower.includes(s.toLowerCase()))) {
|
|
18
|
+
score += 20;
|
|
19
|
+
reasons.push('scope match');
|
|
20
|
+
}
|
|
21
|
+
if (c.title.toLowerCase().includes(taskLower)) {
|
|
22
|
+
score += 25;
|
|
23
|
+
reasons.push('title overlap');
|
|
24
|
+
}
|
|
25
|
+
return { c, score, reasons };
|
|
26
|
+
})
|
|
27
|
+
.sort((a, b) => b.score - a.score);
|
|
28
|
+
const top = scored[0];
|
|
29
|
+
if (!top || top.score === 0)
|
|
30
|
+
return null;
|
|
31
|
+
return {
|
|
32
|
+
convention: top.c,
|
|
33
|
+
reason: top.reasons.length ? top.reasons.join(', ') : 'baseline match',
|
|
34
|
+
score: top.score,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type IKnowledgeEntry } from '@shrkcrft/knowledge';
|
|
2
|
+
import type { IPathConvention } from './path-convention.js';
|
|
3
|
+
import type { IPathQuery } from './path-query.js';
|
|
4
|
+
import { type IPathSelection } from './path-selector.js';
|
|
5
|
+
export declare class PathService {
|
|
6
|
+
private readonly index;
|
|
7
|
+
constructor(entries: readonly IKnowledgeEntry[]);
|
|
8
|
+
list(): IPathConvention[];
|
|
9
|
+
get(id: string): IPathConvention | null;
|
|
10
|
+
search(query: IPathQuery): IPathConvention[];
|
|
11
|
+
findBestForTask(task: string): IPathSelection | null;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=path-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-service.d.ts","sourceRoot":"","sources":["../src/path-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzE,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiB;gBAE3B,OAAO,EAAE,SAAS,eAAe,EAAE;IAI/C,IAAI,IAAI,eAAe,EAAE;IAMzB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAMvC,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,eAAe,EAAE;IAY5C,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;CAGrD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { KnowledgeIndex, KnowledgeType } from '@shrkcrft/knowledge';
|
|
2
|
+
import { selectBestPath } from "./path-selector.js";
|
|
3
|
+
export class PathService {
|
|
4
|
+
index;
|
|
5
|
+
constructor(entries) {
|
|
6
|
+
this.index = new KnowledgeIndex(entries);
|
|
7
|
+
}
|
|
8
|
+
list() {
|
|
9
|
+
return this.index
|
|
10
|
+
.filter((e) => String(e.type) === KnowledgeType.Path)
|
|
11
|
+
.map((e) => e);
|
|
12
|
+
}
|
|
13
|
+
get(id) {
|
|
14
|
+
const entry = this.index.get(id);
|
|
15
|
+
if (!entry || String(entry.type) !== KnowledgeType.Path)
|
|
16
|
+
return null;
|
|
17
|
+
return entry;
|
|
18
|
+
}
|
|
19
|
+
search(query) {
|
|
20
|
+
const results = this.index.search({
|
|
21
|
+
query: query.query ?? query.task,
|
|
22
|
+
types: [KnowledgeType.Path],
|
|
23
|
+
scope: query.scope,
|
|
24
|
+
tags: query.tags,
|
|
25
|
+
appliesWhen: query.appliesWhen,
|
|
26
|
+
limit: query.limit,
|
|
27
|
+
});
|
|
28
|
+
return results.map((r) => r.entry);
|
|
29
|
+
}
|
|
30
|
+
findBestForTask(task) {
|
|
31
|
+
return selectBestPath(this.list(), task);
|
|
32
|
+
}
|
|
33
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shrkcrft/paths",
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
|
+
"description": "SharkCraft path-convention service: typed path entries and best-fit selection.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "SharkCraft contributors",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"bun": "./src/index.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/shrkcrft/sharkcraft.git",
|
|
26
|
+
"directory": "packages/paths"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/shrkcrft/sharkcraft",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/shrkcrft/sharkcraft/issues"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"sharkcraft",
|
|
34
|
+
"paths",
|
|
35
|
+
"conventions"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"bun": ">=1.1.0",
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@shrkcrft/core": "^0.1.0-alpha.2",
|
|
46
|
+
"@shrkcrft/knowledge": "^0.1.0-alpha.2"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|