@shrkcrft/rules 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 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/rules
2
+
3
+ SharkCraft rules service: typed rule entries, relevance lookup, AI formatting.
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/rules
11
+ ```
12
+
13
+ ## License
14
+
15
+ MIT — see [LICENSE](./LICENSE).
@@ -0,0 +1,5 @@
1
+ export * from './rule.js';
2
+ export * from './rule-query.js';
3
+ export * from './rule-formatter.js';
4
+ export * from './rule-service.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./rule.js";
2
+ export * from "./rule-query.js";
3
+ export * from "./rule-formatter.js";
4
+ export * from "./rule-service.js";
@@ -0,0 +1,8 @@
1
+ import { type IKnowledgeEntry } from '@shrkcrft/knowledge';
2
+ import type { IRule } from './rule.js';
3
+ export declare function formatRuleCompact(rule: IRule): string;
4
+ export declare function formatRuleFull(rule: IRule, options?: {
5
+ includeExamples?: boolean;
6
+ }): string;
7
+ export declare function formatRulesForAi(rules: readonly IKnowledgeEntry[]): string;
8
+ //# sourceMappingURL=rule-formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-formatter.d.ts","sourceRoot":"","sources":["../src/rule-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAChG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,CAErD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,MAAM,CAE/F;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,GAAG,MAAM,CAK1E"}
@@ -0,0 +1,14 @@
1
+ import { formatEntryCompact, formatEntryFull } from '@shrkcrft/knowledge';
2
+ export function formatRuleCompact(rule) {
3
+ return formatEntryCompact(rule);
4
+ }
5
+ export function formatRuleFull(rule, options = {}) {
6
+ return formatEntryFull(rule, { includeExamples: options.includeExamples ?? true });
7
+ }
8
+ export function formatRulesForAi(rules) {
9
+ if (rules.length === 0)
10
+ return 'No relevant rules found.';
11
+ return rules
12
+ .map((r, i) => `${i + 1}. [${r.id}] ${r.title}\n ${r.content.trim()}`)
13
+ .join('\n\n');
14
+ }
@@ -0,0 +1,9 @@
1
+ export interface IRuleQuery {
2
+ task?: string;
3
+ scope?: readonly string[];
4
+ tags?: readonly string[];
5
+ appliesWhen?: readonly string[];
6
+ minPriority?: string;
7
+ limit?: number;
8
+ }
9
+ //# sourceMappingURL=rule-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-query.d.ts","sourceRoot":"","sources":["../src/rule-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,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { type IKnowledgeEntry } from '@shrkcrft/knowledge';
2
+ import type { IRule } from './rule.js';
3
+ import type { IRuleQuery } from './rule-query.js';
4
+ export declare class RuleService {
5
+ private readonly index;
6
+ constructor(entries: readonly IKnowledgeEntry[]);
7
+ list(): IRule[];
8
+ get(id: string): IRule | null;
9
+ search(query: IRuleQuery): IRule[];
10
+ getRelevant(task: string, options?: Partial<IRuleQuery>): IRule[];
11
+ }
12
+ //# sourceMappingURL=rule-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-service.d.ts","sourceRoot":"","sources":["../src/rule-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiB;gBAE3B,OAAO,EAAE,SAAS,eAAe,EAAE;IAI/C,IAAI,IAAI,KAAK,EAAE;IAIf,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAM7B,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE;IAalC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAO,CAAC,UAAU,CAAM,GAAG,KAAK,EAAE;CAGtE"}
@@ -0,0 +1,31 @@
1
+ import { KnowledgeIndex, KnowledgeType } from '@shrkcrft/knowledge';
2
+ export class RuleService {
3
+ index;
4
+ constructor(entries) {
5
+ this.index = new KnowledgeIndex(entries);
6
+ }
7
+ list() {
8
+ return this.index.filter((e) => String(e.type) === KnowledgeType.Rule);
9
+ }
10
+ get(id) {
11
+ const entry = this.index.get(id);
12
+ if (!entry || String(entry.type) !== KnowledgeType.Rule)
13
+ return null;
14
+ return entry;
15
+ }
16
+ search(query) {
17
+ const results = this.index.search({
18
+ query: query.task,
19
+ types: [KnowledgeType.Rule],
20
+ scope: query.scope,
21
+ tags: query.tags,
22
+ appliesWhen: query.appliesWhen,
23
+ minPriority: query.minPriority,
24
+ limit: query.limit,
25
+ });
26
+ return results.map((r) => r.entry);
27
+ }
28
+ getRelevant(task, options = {}) {
29
+ return this.search({ ...options, task, limit: options.limit ?? 10 });
30
+ }
31
+ }
package/dist/rule.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { IKnowledgeEntry } from '@shrkcrft/knowledge';
2
+ import { type DefineKnowledgeInput } from '@shrkcrft/knowledge';
3
+ export type IRule = IKnowledgeEntry;
4
+ export type DefineRuleInput = Omit<DefineKnowledgeInput, 'type'> & {
5
+ type?: string;
6
+ };
7
+ export declare function defineRule(input: DefineRuleInput): IRule;
8
+ //# sourceMappingURL=rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule.d.ts","sourceRoot":"","sources":["../src/rule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAuC,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAErG,MAAM,MAAM,KAAK,GAAG,eAAe,CAAC;AAEpC,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErF,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,CAKxD"}
package/dist/rule.js ADDED
@@ -0,0 +1,7 @@
1
+ import { defineKnowledgeEntry, KnowledgeType } from '@shrkcrft/knowledge';
2
+ export function defineRule(input) {
3
+ return defineKnowledgeEntry({
4
+ ...input,
5
+ type: input.type ?? KnowledgeType.Rule,
6
+ });
7
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@shrkcrft/rules",
3
+ "version": "0.1.0-alpha.2",
4
+ "description": "SharkCraft rules service: typed rule entries, relevance lookup, AI formatting.",
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/rules"
27
+ },
28
+ "homepage": "https://github.com/shrkcrft/sharkcraft",
29
+ "bugs": {
30
+ "url": "https://github.com/shrkcrft/sharkcraft/issues"
31
+ },
32
+ "keywords": [
33
+ "sharkcraft",
34
+ "rules",
35
+ "coding-standards",
36
+ "ai"
37
+ ],
38
+ "engines": {
39
+ "bun": ">=1.1.0",
40
+ "node": ">=18"
41
+ },
42
+ "scripts": {
43
+ "typecheck": "tsc --noEmit -p tsconfig.json"
44
+ },
45
+ "dependencies": {
46
+ "@shrkcrft/core": "^0.1.0-alpha.2",
47
+ "@shrkcrft/knowledge": "^0.1.0-alpha.2"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ }
52
+ }