@shrkcrft/knowledge 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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/define/define-knowledge-base.d.ts +7 -0
  4. package/dist/define/define-knowledge-base.d.ts.map +1 -0
  5. package/dist/define/define-knowledge-base.js +3 -0
  6. package/dist/define/define-knowledge-entry.d.ts +20 -0
  7. package/dist/define/define-knowledge-entry.d.ts.map +1 -0
  8. package/dist/define/define-knowledge-entry.js +35 -0
  9. package/dist/format/action-hints-formatter.d.ts +35 -0
  10. package/dist/format/action-hints-formatter.d.ts.map +1 -0
  11. package/dist/format/action-hints-formatter.js +120 -0
  12. package/dist/format/knowledge-formatter.d.ts +11 -0
  13. package/dist/format/knowledge-formatter.d.ts.map +1 -0
  14. package/dist/format/knowledge-formatter.js +58 -0
  15. package/dist/index/knowledge-index.d.ts +16 -0
  16. package/dist/index/knowledge-index.d.ts.map +1 -0
  17. package/dist/index/knowledge-index.js +63 -0
  18. package/dist/index/relevance-score.d.ts +9 -0
  19. package/dist/index/relevance-score.d.ts.map +1 -0
  20. package/dist/index/relevance-score.js +89 -0
  21. package/dist/index.d.ts +20 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +19 -0
  24. package/dist/load/knowledge-loader.d.ts +11 -0
  25. package/dist/load/knowledge-loader.d.ts.map +1 -0
  26. package/dist/load/knowledge-loader.js +1 -0
  27. package/dist/load/markdown-knowledge-loader.d.ts +6 -0
  28. package/dist/load/markdown-knowledge-loader.d.ts.map +1 -0
  29. package/dist/load/markdown-knowledge-loader.js +84 -0
  30. package/dist/load/typescript-knowledge-loader.d.ts +11 -0
  31. package/dist/load/typescript-knowledge-loader.d.ts.map +1 -0
  32. package/dist/load/typescript-knowledge-loader.js +78 -0
  33. package/dist/model/action-hints.d.ts +63 -0
  34. package/dist/model/action-hints.d.ts.map +1 -0
  35. package/dist/model/action-hints.js +23 -0
  36. package/dist/model/knowledge-base.d.ts +6 -0
  37. package/dist/model/knowledge-base.d.ts.map +1 -0
  38. package/dist/model/knowledge-base.js +1 -0
  39. package/dist/model/knowledge-entry.d.ts +84 -0
  40. package/dist/model/knowledge-entry.d.ts.map +1 -0
  41. package/dist/model/knowledge-entry.js +1 -0
  42. package/dist/model/knowledge-priority.d.ts +9 -0
  43. package/dist/model/knowledge-priority.d.ts.map +1 -0
  44. package/dist/model/knowledge-priority.js +16 -0
  45. package/dist/model/knowledge-query.d.ts +17 -0
  46. package/dist/model/knowledge-query.d.ts.map +1 -0
  47. package/dist/model/knowledge-query.js +1 -0
  48. package/dist/model/knowledge-search-result.d.ts +11 -0
  49. package/dist/model/knowledge-search-result.d.ts.map +1 -0
  50. package/dist/model/knowledge-search-result.js +1 -0
  51. package/dist/model/knowledge-type.d.ts +25 -0
  52. package/dist/model/knowledge-type.d.ts.map +1 -0
  53. package/dist/model/knowledge-type.js +27 -0
  54. package/dist/search/knowledge-filter.d.ts +9 -0
  55. package/dist/search/knowledge-filter.d.ts.map +1 -0
  56. package/dist/search/knowledge-filter.js +15 -0
  57. package/dist/search/knowledge-search.d.ts +5 -0
  58. package/dist/search/knowledge-search.d.ts.map +1 -0
  59. package/dist/search/knowledge-search.js +5 -0
  60. package/dist/validate/validate-knowledge-entries.d.ts +29 -0
  61. package/dist/validate/validate-knowledge-entries.d.ts.map +1 -0
  62. package/dist/validate/validate-knowledge-entries.js +101 -0
  63. package/package.json +52 -0
@@ -0,0 +1,84 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { basename, extname } from 'node:path';
3
+ import { KnowledgeType } from "../model/knowledge-type.js";
4
+ import { KnowledgePriority } from "../model/knowledge-priority.js";
5
+ import { normalizeKnowledgeId, toKebabCase } from '@shrkcrft/core';
6
+ const FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n?/;
7
+ function parseFrontmatter(text) {
8
+ const match = FRONTMATTER_RE.exec(text);
9
+ if (!match)
10
+ return { meta: {}, body: text };
11
+ const block = match[1] ?? '';
12
+ const body = text.slice(match[0].length);
13
+ const meta = {};
14
+ for (const line of block.split('\n')) {
15
+ const idx = line.indexOf(':');
16
+ if (idx === -1)
17
+ continue;
18
+ const key = line.slice(0, idx).trim();
19
+ let value = line.slice(idx + 1).trim();
20
+ if (value.startsWith('[') && value.endsWith(']')) {
21
+ value = value
22
+ .slice(1, -1)
23
+ .split(',')
24
+ .map((v) => v.replace(/^["']|["']$/g, '').trim())
25
+ .filter(Boolean);
26
+ }
27
+ else if (value.startsWith('"') || value.startsWith("'")) {
28
+ value = value.replace(/^["']|["']$/g, '');
29
+ }
30
+ meta[key] = value;
31
+ }
32
+ return { meta, body };
33
+ }
34
+ function toArray(value) {
35
+ if (!value)
36
+ return [];
37
+ if (Array.isArray(value))
38
+ return value;
39
+ return value
40
+ .split(',')
41
+ .map((v) => v.trim())
42
+ .filter(Boolean);
43
+ }
44
+ export class MarkdownKnowledgeLoader {
45
+ canLoad(filePath) {
46
+ return extname(filePath).toLowerCase() === '.md';
47
+ }
48
+ async load(filePath) {
49
+ const warnings = [];
50
+ const entries = [];
51
+ const sourceFiles = [];
52
+ if (!existsSync(filePath)) {
53
+ warnings.push(`Markdown file not found: ${filePath}`);
54
+ return { entries, warnings, sourceFiles };
55
+ }
56
+ sourceFiles.push(filePath);
57
+ let text;
58
+ try {
59
+ text = readFileSync(filePath, 'utf8');
60
+ }
61
+ catch (e) {
62
+ warnings.push(`Failed to read ${filePath}: ${e.message}`);
63
+ return { entries, warnings, sourceFiles };
64
+ }
65
+ const { meta, body } = parseFrontmatter(text);
66
+ const baseName = basename(filePath, '.md');
67
+ const titleFromBody = /^#\s+(.+)$/m.exec(body)?.[1]?.trim();
68
+ const entry = {
69
+ id: meta.id ? normalizeKnowledgeId(meta.id) : `doc.${toKebabCase(baseName)}`,
70
+ title: meta.title || titleFromBody || baseName,
71
+ type: meta.type || KnowledgeType.Technical,
72
+ priority: meta.priority || KnowledgePriority.Medium,
73
+ scope: Object.freeze(toArray(meta.scope)),
74
+ tags: Object.freeze(toArray(meta.tags).length > 0 ? toArray(meta.tags) : ['markdown', 'doc']),
75
+ appliesWhen: Object.freeze(toArray(meta.appliesWhen)),
76
+ content: body.trim(),
77
+ summary: meta.summary,
78
+ related: meta.related ? Object.freeze(toArray(meta.related)) : undefined,
79
+ source: { origin: filePath, loader: 'markdown' },
80
+ };
81
+ entries.push(entry);
82
+ return { entries, warnings, sourceFiles };
83
+ }
84
+ }
@@ -0,0 +1,11 @@
1
+ import { type IImportContext } from '@shrkcrft/core';
2
+ import type { ILoadedKnowledge, IKnowledgeLoader } from './knowledge-loader.js';
3
+ export declare class TypeScriptKnowledgeLoader implements IKnowledgeLoader {
4
+ private readonly _importContext;
5
+ constructor(options?: {
6
+ importContext?: IImportContext;
7
+ });
8
+ canLoad(filePath: string): boolean;
9
+ load(filePath: string): Promise<ILoadedKnowledge>;
10
+ }
11
+ //# sourceMappingURL=typescript-knowledge-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-knowledge-loader.d.ts","sourceRoot":"","sources":["../../src/load/typescript-knowledge-loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAc,MAAM,gBAAgB,CAAC;AAEjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAiChF,qBAAa,yBAA0B,YAAW,gBAAgB;IAChE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA6B;gBAEhD,OAAO,GAAE;QAAE,aAAa,CAAC,EAAE,cAAc,CAAA;KAAO;IAI5D,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI5B,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoCxD"}
@@ -0,0 +1,78 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { extname } from 'node:path';
3
+ import { safeImport } from '@shrkcrft/core';
4
+ const TS_EXTENSIONS = new Set(['.ts', '.tsx', '.js', '.mjs', '.cjs']);
5
+ function isLikelyEntry(value) {
6
+ if (!value || typeof value !== 'object')
7
+ return false;
8
+ const v = value;
9
+ return typeof v.id === 'string' && typeof v.title === 'string' && typeof v.content === 'string';
10
+ }
11
+ function collectEntriesFromModule(mod, entries) {
12
+ const seen = new Set();
13
+ const tryPush = (value) => {
14
+ if (!isLikelyEntry(value))
15
+ return;
16
+ if (seen.has(value.id))
17
+ return;
18
+ seen.add(value.id);
19
+ entries.push(value);
20
+ };
21
+ for (const key of Object.keys(mod)) {
22
+ const value = mod[key];
23
+ if (isLikelyEntry(value)) {
24
+ tryPush(value);
25
+ }
26
+ else if (Array.isArray(value)) {
27
+ for (const item of value)
28
+ tryPush(item);
29
+ }
30
+ else if (value && typeof value === 'object' && 'entries' in value) {
31
+ const inner = value.entries;
32
+ if (Array.isArray(inner)) {
33
+ for (const item of inner)
34
+ tryPush(item);
35
+ }
36
+ }
37
+ }
38
+ }
39
+ export class TypeScriptKnowledgeLoader {
40
+ _importContext;
41
+ constructor(options = {}) {
42
+ this._importContext = options.importContext;
43
+ }
44
+ canLoad(filePath) {
45
+ return TS_EXTENSIONS.has(extname(filePath));
46
+ }
47
+ async load(filePath) {
48
+ const warnings = [];
49
+ const entries = [];
50
+ const sourceFiles = [];
51
+ if (!existsSync(filePath)) {
52
+ warnings.push(`Knowledge file not found: ${filePath}`);
53
+ return { entries, warnings, sourceFiles };
54
+ }
55
+ sourceFiles.push(filePath);
56
+ const result = this._importContext
57
+ ? await this._importContext.load(filePath)
58
+ : await safeImport(filePath, { skipExistsCheck: true });
59
+ if (!result.ok) {
60
+ const label = result.timedOut ? 'timed out importing' : 'Failed to import';
61
+ warnings.push(`${label} ${filePath}: ${result.error.message}`);
62
+ return { entries, warnings, sourceFiles };
63
+ }
64
+ collectEntriesFromModule(result.module, entries);
65
+ for (const entry of entries) {
66
+ if (!entry.source?.origin) {
67
+ entry.source = {
68
+ origin: filePath,
69
+ loader: 'typescript',
70
+ };
71
+ }
72
+ }
73
+ if (entries.length === 0) {
74
+ warnings.push(`No knowledge entries detected in ${filePath}`);
75
+ }
76
+ return { entries, warnings, sourceFiles };
77
+ }
78
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Action guidance attached to a knowledge entry.
3
+ *
4
+ * The model exists so structured knowledge can answer "what should the agent
5
+ * do?" — not just "what is the rule?". Entries that are purely descriptive
6
+ * (e.g. project-overview, glossary) leave actionHints undefined.
7
+ */
8
+ export interface IActionHintCommand {
9
+ /** A shell command. Placeholders like <task>, <repo>, <name> are conventional. */
10
+ command: string;
11
+ /** Why this command is run. */
12
+ purpose?: string;
13
+ /** Loose ordering hint: 'before' | 'during' | 'after' | free-form. */
14
+ when?: string;
15
+ /** True if the agent should treat this as mandatory for the flow. */
16
+ required?: boolean;
17
+ }
18
+ export interface IActionHintMcpTool {
19
+ /** MCP tool name (e.g. 'get_relevant_context'). */
20
+ tool: string;
21
+ purpose?: string;
22
+ when?: string;
23
+ required?: boolean;
24
+ }
25
+ export declare enum WritePolicy {
26
+ CliOnly = "cli-only",
27
+ None = "none",
28
+ /** Reserved — currently no MCP tool writes; kept so packs can declare intent. */
29
+ McpAllowed = "mcp-allowed"
30
+ }
31
+ export interface IActionHints {
32
+ /** CLI commands the agent should run. */
33
+ commands?: readonly IActionHintCommand[];
34
+ /** MCP tools the agent should call. */
35
+ mcpTools?: readonly IActionHintMcpTool[];
36
+ /**
37
+ * Ordered list of step ids (MCP tool names, CLI command strings, or pipeline
38
+ * step ids). Used by the context builder to render a "Preferred Flow"
39
+ * section. The highest-priority entry that defines a preferredFlow wins
40
+ * during aggregation.
41
+ */
42
+ preferredFlow?: readonly string[];
43
+ /** Things the agent must NOT do. Free-text. */
44
+ forbiddenActions?: readonly string[];
45
+ /** Template ids likely needed. */
46
+ relatedTemplates?: readonly string[];
47
+ /** Path convention ids likely needed. */
48
+ relatedPathConventions?: readonly string[];
49
+ /** Other knowledge entry ids to cross-reference. */
50
+ relatedKnowledge?: readonly string[];
51
+ /** Commands to run after generation. */
52
+ verificationCommands?: readonly string[];
53
+ /** Reminders about safety, replay, idempotency etc. */
54
+ safetyNotes?: readonly string[];
55
+ /** True if a human must review before any write. */
56
+ requiresHumanReview?: boolean;
57
+ /** Who is allowed to actually write files. */
58
+ writePolicy?: WritePolicy | 'cli-only' | 'mcp-allowed' | 'none';
59
+ }
60
+ export declare function hasActionHints(entry: {
61
+ actionHints?: IActionHints;
62
+ }): boolean;
63
+ //# sourceMappingURL=action-hints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-hints.d.ts","sourceRoot":"","sources":["../../src/model/action-hints.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,oBAAY,WAAW;IACrB,OAAO,aAAa;IACpB,IAAI,SAAS;IACb,iFAAiF;IACjF,UAAU,gBAAgB;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,QAAQ,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACzC,uCAAuC;IACvC,QAAQ,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACzC;;;;;OAKG;IACH,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,yCAAyC;IACzC,sBAAsB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,oDAAoD;IACpD,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,wCAAwC;IACxC,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,uDAAuD;IACvD,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,oDAAoD;IACpD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,aAAa,GAAG,MAAM,CAAC;CACjE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE;IAAE,WAAW,CAAC,EAAE,YAAY,CAAA;CAAE,GAAG,OAAO,CAgB7E"}
@@ -0,0 +1,23 @@
1
+ export var WritePolicy;
2
+ (function (WritePolicy) {
3
+ WritePolicy["CliOnly"] = "cli-only";
4
+ WritePolicy["None"] = "none";
5
+ /** Reserved — currently no MCP tool writes; kept so packs can declare intent. */
6
+ WritePolicy["McpAllowed"] = "mcp-allowed";
7
+ })(WritePolicy || (WritePolicy = {}));
8
+ export function hasActionHints(entry) {
9
+ const a = entry.actionHints;
10
+ if (!a)
11
+ return false;
12
+ return Boolean((a.commands && a.commands.length) ||
13
+ (a.mcpTools && a.mcpTools.length) ||
14
+ (a.preferredFlow && a.preferredFlow.length) ||
15
+ (a.forbiddenActions && a.forbiddenActions.length) ||
16
+ (a.relatedTemplates && a.relatedTemplates.length) ||
17
+ (a.relatedPathConventions && a.relatedPathConventions.length) ||
18
+ (a.relatedKnowledge && a.relatedKnowledge.length) ||
19
+ (a.verificationCommands && a.verificationCommands.length) ||
20
+ (a.safetyNotes && a.safetyNotes.length) ||
21
+ a.requiresHumanReview !== undefined ||
22
+ a.writePolicy !== undefined);
23
+ }
@@ -0,0 +1,6 @@
1
+ import type { IKnowledgeEntry } from './knowledge-entry.js';
2
+ export interface IKnowledgeBaseDefinition {
3
+ name?: string;
4
+ entries: readonly IKnowledgeEntry[];
5
+ }
6
+ //# sourceMappingURL=knowledge-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-base.d.ts","sourceRoot":"","sources":["../../src/model/knowledge-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;CACrC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,84 @@
1
+ import type { KnowledgeType } from './knowledge-type.js';
2
+ import type { KnowledgePriority } from './knowledge-priority.js';
3
+ import type { IActionHints } from './action-hints.js';
4
+ export interface IKnowledgeExample {
5
+ title?: string;
6
+ description?: string;
7
+ code?: string;
8
+ language?: string;
9
+ }
10
+ export interface IKnowledgeSource {
11
+ /** Originating file path or URL. */
12
+ origin?: string;
13
+ /** Optional identifier of the loader that produced this entry. */
14
+ loader?: string;
15
+ }
16
+ /**
17
+ * Structured reference attached to a knowledge entry.
18
+ *
19
+ * References make the entry verifiable: stale-check confirms each target
20
+ * still exists; rename advisory reports affected entries when a target is
21
+ * renamed.
22
+ */
23
+ export type KnowledgeReferenceKind = 'file' | 'directory' | 'symbol' | 'command' | 'template' | 'playbook' | 'construct' | 'helper' | 'policy' | 'boundary-rule' | 'path-convention' | 'package' | 'url';
24
+ export interface IKnowledgeReference {
25
+ kind: KnowledgeReferenceKind;
26
+ /** Project-relative path for `file` / `directory`. */
27
+ path?: string;
28
+ /** Symbol name for `symbol` references (function, class, type). */
29
+ symbol?: string;
30
+ /** Id for `command` / `template` / `playbook` / `construct` / `helper` / `policy` / `boundary-rule` / `path-convention` / `package`. */
31
+ id?: string;
32
+ /** Raw command line for `command` (alternative to `id`). */
33
+ command?: string;
34
+ /** Whether the stale-check treats a missing target as an error (default false). */
35
+ required?: boolean;
36
+ /** Free-form note carried verbatim. */
37
+ note?: string;
38
+ }
39
+ /**
40
+ * Anchor — a named point inside or related to an entry. Anchors are what
41
+ * the rename advisory tool updates when a target is moved.
42
+ */
43
+ export type KnowledgeAnchorKind = 'file' | 'symbol' | 'command' | 'construct' | 'template' | 'helper' | 'playbook' | 'policy';
44
+ export interface IKnowledgeAnchor {
45
+ id: string;
46
+ kind: KnowledgeAnchorKind;
47
+ path?: string;
48
+ symbol?: string;
49
+ targetId?: string;
50
+ description?: string;
51
+ }
52
+ export interface IKnowledgeEntry {
53
+ id: string;
54
+ title: string;
55
+ type: KnowledgeType | string;
56
+ priority: KnowledgePriority | string;
57
+ scope: readonly string[];
58
+ tags: readonly string[];
59
+ appliesWhen: readonly string[];
60
+ content: string;
61
+ summary?: string;
62
+ examples?: readonly IKnowledgeExample[];
63
+ related?: readonly string[];
64
+ source?: IKnowledgeSource;
65
+ metadata?: Readonly<Record<string, unknown>>;
66
+ /**
67
+ * Optional structured action guidance for AI agents. When present, the
68
+ * context builder surfaces commands / MCP tools / forbidden actions /
69
+ * verification commands etc. so the agent does not have to guess the flow.
70
+ */
71
+ actionHints?: IActionHints;
72
+ /**
73
+ * Optional verifiable references to repo artefacts.
74
+ *
75
+ * Optional — entries that omit this field still load.
76
+ */
77
+ references?: readonly IKnowledgeReference[];
78
+ /**
79
+ * Optional named anchors describing what the entry is *about*.
80
+ * Anchors get updated by `shrk knowledge rename-symbol|rename-file`.
81
+ */
82
+ anchors?: readonly IKnowledgeAnchor[];
83
+ }
84
+ //# sourceMappingURL=knowledge-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-entry.d.ts","sourceRoot":"","sources":["../../src/model/knowledge-entry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAC9B,MAAM,GACN,WAAW,GACX,QAAQ,GACR,SAAS,GACT,UAAU,GACV,UAAU,GACV,WAAW,GACX,QAAQ,GACR,QAAQ,GACR,eAAe,GACf,iBAAiB,GACjB,SAAS,GACT,KAAK,CAAC;AAEV,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wIAAwI;IACxI,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uCAAuC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC3B,MAAM,GACN,QAAQ,GACR,SAAS,GACT,WAAW,GACX,UAAU,GACV,QAAQ,GACR,UAAU,GACV,QAAQ,CAAC;AAEb,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC;IAC7B,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAAC;IACrC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACxC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7C;;;;OAIG;IACH,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAC5C;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACvC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare enum KnowledgePriority {
2
+ Critical = "critical",
3
+ High = "high",
4
+ Medium = "medium",
5
+ Low = "low"
6
+ }
7
+ export declare const PRIORITY_WEIGHTS: Readonly<Record<KnowledgePriority, number>>;
8
+ export declare function priorityWeight(priority: KnowledgePriority | undefined): number;
9
+ //# sourceMappingURL=knowledge-priority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-priority.d.ts","sourceRoot":"","sources":["../../src/model/knowledge-priority.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAC3B,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,GAAG,QAAQ;CACZ;AAED,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAKvE,CAAC;AAEH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,iBAAiB,GAAG,SAAS,GAAG,MAAM,CAE9E"}
@@ -0,0 +1,16 @@
1
+ export var KnowledgePriority;
2
+ (function (KnowledgePriority) {
3
+ KnowledgePriority["Critical"] = "critical";
4
+ KnowledgePriority["High"] = "high";
5
+ KnowledgePriority["Medium"] = "medium";
6
+ KnowledgePriority["Low"] = "low";
7
+ })(KnowledgePriority || (KnowledgePriority = {}));
8
+ export const PRIORITY_WEIGHTS = Object.freeze({
9
+ [KnowledgePriority.Critical]: 100,
10
+ [KnowledgePriority.High]: 70,
11
+ [KnowledgePriority.Medium]: 40,
12
+ [KnowledgePriority.Low]: 10,
13
+ });
14
+ export function priorityWeight(priority) {
15
+ return PRIORITY_WEIGHTS[priority ?? KnowledgePriority.Medium];
16
+ }
@@ -0,0 +1,17 @@
1
+ export interface IKnowledgeQuery {
2
+ /** Free-text query (matched against title/summary/content/tags). */
3
+ query?: string;
4
+ /** Restrict by knowledge type. */
5
+ types?: readonly string[];
6
+ /** Restrict by scope (framework/area). */
7
+ scope?: readonly string[];
8
+ /** Tag filter (AND). */
9
+ tags?: readonly string[];
10
+ /** appliesWhen filter (any-match). */
11
+ appliesWhen?: readonly string[];
12
+ /** Minimum priority threshold. */
13
+ minPriority?: string;
14
+ /** Limit on returned entries. */
15
+ limit?: number;
16
+ }
17
+ //# sourceMappingURL=knowledge-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-query.d.ts","sourceRoot":"","sources":["../../src/model/knowledge-query.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,0CAA0C;IAC1C,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,wBAAwB;IACxB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,sCAAsC;IACtC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { IKnowledgeEntry } from './knowledge-entry.js';
2
+ export interface IKnowledgeMatchReason {
3
+ field: string;
4
+ match: string;
5
+ }
6
+ export interface IKnowledgeSearchResult {
7
+ entry: IKnowledgeEntry;
8
+ score: number;
9
+ reasons: readonly IKnowledgeMatchReason[];
10
+ }
11
+ //# sourceMappingURL=knowledge-search-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-search-result.d.ts","sourceRoot":"","sources":["../../src/model/knowledge-search-result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,eAAe,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC3C"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ export declare enum KnowledgeType {
2
+ Rule = "rule",
3
+ Path = "path",
4
+ Template = "template",
5
+ Architecture = "architecture",
6
+ Technical = "technical",
7
+ Business = "business",
8
+ Command = "command",
9
+ Environment = "environment",
10
+ Dependency = "dependency",
11
+ Feature = "feature",
12
+ Task = "task",
13
+ Warning = "warning",
14
+ Decision = "decision",
15
+ Convention = "convention",
16
+ Workflow = "workflow",
17
+ Testing = "testing",
18
+ Security = "security",
19
+ Deployment = "deployment",
20
+ Integration = "integration",
21
+ Custom = "custom"
22
+ }
23
+ export declare const ALL_KNOWLEDGE_TYPES: readonly KnowledgeType[];
24
+ export declare function isKnowledgeType(value: unknown): value is KnowledgeType;
25
+ //# sourceMappingURL=knowledge-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-type.d.ts","sourceRoot":"","sources":["../../src/model/knowledge-type.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,WAAW,gBAAgB;IAC3B,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,UAAU,eAAe;IACzB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAC3B,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,mBAAmB,EAAE,SAAS,aAAa,EAEvD,CAAC;AAEF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE"}
@@ -0,0 +1,27 @@
1
+ export var KnowledgeType;
2
+ (function (KnowledgeType) {
3
+ KnowledgeType["Rule"] = "rule";
4
+ KnowledgeType["Path"] = "path";
5
+ KnowledgeType["Template"] = "template";
6
+ KnowledgeType["Architecture"] = "architecture";
7
+ KnowledgeType["Technical"] = "technical";
8
+ KnowledgeType["Business"] = "business";
9
+ KnowledgeType["Command"] = "command";
10
+ KnowledgeType["Environment"] = "environment";
11
+ KnowledgeType["Dependency"] = "dependency";
12
+ KnowledgeType["Feature"] = "feature";
13
+ KnowledgeType["Task"] = "task";
14
+ KnowledgeType["Warning"] = "warning";
15
+ KnowledgeType["Decision"] = "decision";
16
+ KnowledgeType["Convention"] = "convention";
17
+ KnowledgeType["Workflow"] = "workflow";
18
+ KnowledgeType["Testing"] = "testing";
19
+ KnowledgeType["Security"] = "security";
20
+ KnowledgeType["Deployment"] = "deployment";
21
+ KnowledgeType["Integration"] = "integration";
22
+ KnowledgeType["Custom"] = "custom";
23
+ })(KnowledgeType || (KnowledgeType = {}));
24
+ export const ALL_KNOWLEDGE_TYPES = Object.freeze(Object.values(KnowledgeType));
25
+ export function isKnowledgeType(value) {
26
+ return typeof value === 'string' && ALL_KNOWLEDGE_TYPES.includes(value);
27
+ }
@@ -0,0 +1,9 @@
1
+ import type { IKnowledgeEntry } from '../model/knowledge-entry.js';
2
+ export interface KnowledgeFilterOptions {
3
+ types?: readonly string[];
4
+ scope?: readonly string[];
5
+ tags?: readonly string[];
6
+ appliesWhen?: readonly string[];
7
+ }
8
+ export declare function filterKnowledge(entries: readonly IKnowledgeEntry[], options: KnowledgeFilterOptions): IKnowledgeEntry[];
9
+ //# sourceMappingURL=knowledge-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-filter.d.ts","sourceRoot":"","sources":["../../src/search/knowledge-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,EAAE,CAanB"}
@@ -0,0 +1,15 @@
1
+ export function filterKnowledge(entries, options) {
2
+ return entries.filter((entry) => {
3
+ if (options.types?.length && !options.types.includes(String(entry.type)))
4
+ return false;
5
+ if (options.scope?.length && !options.scope.some((s) => entry.scope.includes(s)))
6
+ return false;
7
+ if (options.tags?.length && !options.tags.every((t) => entry.tags.includes(t)))
8
+ return false;
9
+ if (options.appliesWhen?.length &&
10
+ !options.appliesWhen.some((a) => entry.appliesWhen.includes(a))) {
11
+ return false;
12
+ }
13
+ return true;
14
+ });
15
+ }
@@ -0,0 +1,5 @@
1
+ import type { IKnowledgeEntry } from '../model/knowledge-entry.js';
2
+ import type { IKnowledgeQuery } from '../model/knowledge-query.js';
3
+ import type { IKnowledgeSearchResult } from '../model/knowledge-search-result.js';
4
+ export declare function searchKnowledge(entries: readonly IKnowledgeEntry[], query: IKnowledgeQuery): IKnowledgeSearchResult[];
5
+ //# sourceMappingURL=knowledge-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-search.d.ts","sourceRoot":"","sources":["../../src/search/knowledge-search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAGlF,wBAAgB,eAAe,CAC7B,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,KAAK,EAAE,eAAe,GACrB,sBAAsB,EAAE,CAG1B"}
@@ -0,0 +1,5 @@
1
+ import { KnowledgeIndex } from "../index/knowledge-index.js";
2
+ export function searchKnowledge(entries, query) {
3
+ const index = new KnowledgeIndex(entries);
4
+ return index.search(query);
5
+ }
@@ -0,0 +1,29 @@
1
+ import type { IKnowledgeEntry } from '../model/knowledge-entry.js';
2
+ export interface IKnowledgeValidationIssue {
3
+ /** Stable identifier for the issue category. */
4
+ code: 'missing-id' | 'invalid-id-format' | 'duplicate-id' | 'missing-title' | 'missing-content' | 'missing-type' | 'invalid-type' | 'invalid-priority';
5
+ /** Affected entry id (or '?' if unknown). */
6
+ entryId: string;
7
+ /** Source file path if available. */
8
+ source?: string;
9
+ /** Human-readable message. */
10
+ message: string;
11
+ /** Severity hint. */
12
+ severity: 'error' | 'warning';
13
+ }
14
+ export interface IKnowledgeValidationResult {
15
+ valid: boolean;
16
+ issues: IKnowledgeValidationIssue[];
17
+ /** Entries with the first-seen winner for each id (duplicates dropped). */
18
+ uniqueEntries: IKnowledgeEntry[];
19
+ }
20
+ /**
21
+ * Validate a list of knowledge entries. Catches the classic problems:
22
+ * - missing or malformed id
23
+ * - duplicate ids (warning — first occurrence wins)
24
+ * - missing title/content/type
25
+ * - unknown type (warning — custom types are allowed but get flagged)
26
+ * - unknown priority (error)
27
+ */
28
+ export declare function validateKnowledgeEntries(entries: readonly IKnowledgeEntry[]): IKnowledgeValidationResult;
29
+ //# sourceMappingURL=validate-knowledge-entries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-knowledge-entries.d.ts","sourceRoot":"","sources":["../../src/validate/validate-knowledge-entries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAInE,MAAM,WAAW,yBAAyB;IACxC,gDAAgD;IAChD,IAAI,EACA,YAAY,GACZ,mBAAmB,GACnB,cAAc,GACd,eAAe,GACf,iBAAiB,GACjB,cAAc,GACd,cAAc,GACd,kBAAkB,CAAC;IACvB,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,yBAAyB,EAAE,CAAC;IACpC,2EAA2E;IAC3E,aAAa,EAAE,eAAe,EAAE,CAAC;CAClC;AAKD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,SAAS,eAAe,EAAE,GAClC,0BAA0B,CA4F5B"}