@rasensio/aidlc 0.6.0 → 1.1.0

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 (113) hide show
  1. package/README.md +113 -0
  2. package/dist/cli.js +13 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/discover.d.ts +6 -2
  5. package/dist/commands/discover.d.ts.map +1 -1
  6. package/dist/commands/discover.js +30 -4
  7. package/dist/commands/discover.js.map +1 -1
  8. package/dist/commands/gate.d.ts.map +1 -1
  9. package/dist/commands/gate.js +8 -0
  10. package/dist/commands/gate.js.map +1 -1
  11. package/dist/commands/init.d.ts +17 -11
  12. package/dist/commands/init.d.ts.map +1 -1
  13. package/dist/commands/init.js +280 -45
  14. package/dist/commands/init.js.map +1 -1
  15. package/dist/commands/knowledge.d.ts +16 -0
  16. package/dist/commands/knowledge.d.ts.map +1 -0
  17. package/dist/commands/knowledge.js +454 -0
  18. package/dist/commands/knowledge.js.map +1 -0
  19. package/dist/commands/start.d.ts +2 -1
  20. package/dist/commands/start.d.ts.map +1 -1
  21. package/dist/commands/start.js +31 -1
  22. package/dist/commands/start.js.map +1 -1
  23. package/dist/commands/transition.d.ts.map +1 -1
  24. package/dist/commands/transition.js +14 -1
  25. package/dist/commands/transition.js.map +1 -1
  26. package/dist/commands/update.d.ts.map +1 -1
  27. package/dist/commands/update.js +9 -2
  28. package/dist/commands/update.js.map +1 -1
  29. package/dist/compile/adapters/claude-code.d.ts.map +1 -1
  30. package/dist/compile/adapters/claude-code.js +7 -2
  31. package/dist/compile/adapters/claude-code.js.map +1 -1
  32. package/dist/compile/adapters/codex.d.ts.map +1 -1
  33. package/dist/compile/adapters/codex.js +5 -0
  34. package/dist/compile/adapters/codex.js.map +1 -1
  35. package/dist/compile/adapters/cursor.d.ts.map +1 -1
  36. package/dist/compile/adapters/cursor.js +5 -0
  37. package/dist/compile/adapters/cursor.js.map +1 -1
  38. package/dist/compile/adapters/kiro.d.ts.map +1 -1
  39. package/dist/compile/adapters/kiro.js +7 -1
  40. package/dist/compile/adapters/kiro.js.map +1 -1
  41. package/dist/compile/adapters/windsurf.d.ts.map +1 -1
  42. package/dist/compile/adapters/windsurf.js +5 -0
  43. package/dist/compile/adapters/windsurf.js.map +1 -1
  44. package/dist/compile/knowledge-section.d.ts +19 -0
  45. package/dist/compile/knowledge-section.d.ts.map +1 -0
  46. package/dist/compile/knowledge-section.js +46 -0
  47. package/dist/compile/knowledge-section.js.map +1 -0
  48. package/dist/core/types.d.ts +3 -1
  49. package/dist/core/types.d.ts.map +1 -1
  50. package/dist/discover/scanner.d.ts.map +1 -1
  51. package/dist/discover/scanner.js +18 -12
  52. package/dist/discover/scanner.js.map +1 -1
  53. package/dist/discover/workspaces.d.ts +24 -0
  54. package/dist/discover/workspaces.d.ts.map +1 -0
  55. package/dist/discover/workspaces.js +116 -0
  56. package/dist/discover/workspaces.js.map +1 -0
  57. package/dist/knowledge/compact.d.ts +24 -0
  58. package/dist/knowledge/compact.d.ts.map +1 -0
  59. package/dist/knowledge/compact.js +70 -0
  60. package/dist/knowledge/compact.js.map +1 -0
  61. package/dist/knowledge/context-generator.d.ts +36 -0
  62. package/dist/knowledge/context-generator.d.ts.map +1 -0
  63. package/dist/knowledge/context-generator.js +150 -0
  64. package/dist/knowledge/context-generator.js.map +1 -0
  65. package/dist/knowledge/engine.d.ts +40 -0
  66. package/dist/knowledge/engine.d.ts.map +1 -0
  67. package/dist/knowledge/engine.js +79 -0
  68. package/dist/knowledge/engine.js.map +1 -0
  69. package/dist/knowledge/gate-criterion.d.ts +36 -0
  70. package/dist/knowledge/gate-criterion.d.ts.map +1 -0
  71. package/dist/knowledge/gate-criterion.js +60 -0
  72. package/dist/knowledge/gate-criterion.js.map +1 -0
  73. package/dist/knowledge/index/knowledge-index.d.ts +45 -0
  74. package/dist/knowledge/index/knowledge-index.d.ts.map +1 -0
  75. package/dist/knowledge/index/knowledge-index.js +20 -0
  76. package/dist/knowledge/index/knowledge-index.js.map +1 -0
  77. package/dist/knowledge/index/sqlite-index.d.ts +53 -0
  78. package/dist/knowledge/index/sqlite-index.d.ts.map +1 -0
  79. package/dist/knowledge/index/sqlite-index.js +354 -0
  80. package/dist/knowledge/index/sqlite-index.js.map +1 -0
  81. package/dist/knowledge/merge-driver.d.ts +36 -0
  82. package/dist/knowledge/merge-driver.d.ts.map +1 -0
  83. package/dist/knowledge/merge-driver.js +130 -0
  84. package/dist/knowledge/merge-driver.js.map +1 -0
  85. package/dist/knowledge/reader.d.ts +32 -0
  86. package/dist/knowledge/reader.d.ts.map +1 -0
  87. package/dist/knowledge/reader.js +74 -0
  88. package/dist/knowledge/reader.js.map +1 -0
  89. package/dist/knowledge/seed.d.ts +38 -0
  90. package/dist/knowledge/seed.d.ts.map +1 -0
  91. package/dist/knowledge/seed.js +254 -0
  92. package/dist/knowledge/seed.js.map +1 -0
  93. package/dist/knowledge/staleness.d.ts +41 -0
  94. package/dist/knowledge/staleness.d.ts.map +1 -0
  95. package/dist/knowledge/staleness.js +102 -0
  96. package/dist/knowledge/staleness.js.map +1 -0
  97. package/dist/knowledge/sync.d.ts +31 -0
  98. package/dist/knowledge/sync.d.ts.map +1 -0
  99. package/dist/knowledge/sync.js +103 -0
  100. package/dist/knowledge/sync.js.map +1 -0
  101. package/dist/knowledge/types.d.ts +87 -0
  102. package/dist/knowledge/types.d.ts.map +1 -0
  103. package/dist/knowledge/types.js +82 -0
  104. package/dist/knowledge/types.js.map +1 -0
  105. package/dist/knowledge/writer.d.ts +67 -0
  106. package/dist/knowledge/writer.d.ts.map +1 -0
  107. package/dist/knowledge/writer.js +189 -0
  108. package/dist/knowledge/writer.js.map +1 -0
  109. package/dist/knowledge/yaml-source.d.ts +48 -0
  110. package/dist/knowledge/yaml-source.d.ts.map +1 -0
  111. package/dist/knowledge/yaml-source.js +195 -0
  112. package/dist/knowledge/yaml-source.js.map +1 -0
  113. package/package.json +3 -3
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Data model for the local knowledge graph.
3
+ *
4
+ * Entities and relationships are stored as YAML source files in
5
+ * `.aidlc/knowledge/` (source of truth) and mirrored into a SQLite index
6
+ * (derived cache). Built-in types are closed sets; `custom:<name>` extends
7
+ * both without a schema change.
8
+ *
9
+ * Requirements: KG 1.1–1.5, 2.4, 11.1
10
+ *
11
+ * @module
12
+ */
13
+ /** Built-in entity types (KG Req 1.1). */
14
+ export declare const ENTITY_TYPES: readonly ["module", "service", "domain-entity", "convention", "decision", "debt", "dependency", "endpoint", "config"];
15
+ export type BuiltInEntityType = (typeof ENTITY_TYPES)[number];
16
+ export type EntityType = BuiltInEntityType | `custom:${string}`;
17
+ /** Built-in relationship types (KG Req 1.4). */
18
+ export declare const RELATIONSHIP_TYPES: readonly ["depends-on", "implements", "calls", "owns", "contains", "extends", "uses", "produces", "consumes", "conflicts-with"];
19
+ export type BuiltInRelationshipType = (typeof RELATIONSHIP_TYPES)[number];
20
+ export type RelationshipType = BuiltInRelationshipType | `custom:${string}`;
21
+ /** Current schema version for YAML sources and the SQLite index (KG Req 11.1). */
22
+ export declare const KNOWLEDGE_SCHEMA_VERSION = 1;
23
+ /** Confidence assigned to facts inferred by static analysis (KG Req 8.3). */
24
+ export declare const DISCOVERY_CONFIDENCE = 0.6;
25
+ /** Default confidence for agent-asserted facts (KG Req 8.3). */
26
+ export declare const AGENT_CONFIDENCE = 0.9;
27
+ /** Entities below this confidence are excluded from context output (KG Req 7.5). */
28
+ export declare const STALE_CONFIDENCE_FLOOR = 0.3;
29
+ /** A node in the knowledge graph (KG Req 1.2, 12.1). */
30
+ export interface Entity {
31
+ /** Unique lowercase slug, e.g. "payment-service". */
32
+ id: string;
33
+ type: EntityType;
34
+ /** Human-readable name. */
35
+ name: string;
36
+ /** Free-text explanation. */
37
+ description: string;
38
+ /** Certainty 0.0–1.0. */
39
+ confidence: number;
40
+ /** File path the fact derives from, or "agent-inferred". */
41
+ source: string;
42
+ /** Who asserted the fact: git user name, "auto-discovery", or AIDLC_AUTHOR. */
43
+ author: string;
44
+ tags: string[];
45
+ /** ISO 8601 timestamp of last confirmation. */
46
+ lastVerified: string;
47
+ metadata?: Record<string, unknown>;
48
+ }
49
+ /** A directed, typed edge between two entities (KG Req 1.3). */
50
+ export interface Relationship {
51
+ /** Source entity id. */
52
+ from: string;
53
+ /** Target entity id. */
54
+ to: string;
55
+ type: RelationshipType;
56
+ metadata?: Record<string, unknown>;
57
+ lastVerified: string;
58
+ }
59
+ /** `_meta` header document present in every YAML source file (KG Req 2.4). */
60
+ export interface SourceFileMeta {
61
+ schemaVersion: number;
62
+ lastIndexed: string;
63
+ entityType: string;
64
+ }
65
+ export interface GraphQueryResult {
66
+ entities: Entity[];
67
+ relationships: Relationship[];
68
+ totalCount: number;
69
+ }
70
+ export interface ContextOutput {
71
+ markdown: string;
72
+ tokenEstimate: number;
73
+ entityCount: number;
74
+ sections: string[];
75
+ }
76
+ /** Entity ids are lowercase slugs: letters, digits, hyphens. */
77
+ export declare const ENTITY_ID_RE: RegExp;
78
+ export declare function isValidEntityType(type: string): boolean;
79
+ export declare function isValidRelationshipType(type: string): boolean;
80
+ /**
81
+ * Map an entity type to its YAML source filename (KG Req 2.1).
82
+ * Custom types share a single `custom.yaml`.
83
+ */
84
+ export declare function sourceFileForType(type: string): string;
85
+ /** Relationships live in a dedicated cross-cutting file. */
86
+ export declare const RELATIONSHIPS_FILE = "relationships.yaml";
87
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/knowledge/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,0CAA0C;AAC1C,eAAO,MAAM,YAAY,uHAUf,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9D,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,UAAU,MAAM,EAAE,CAAC;AAEhE,gDAAgD;AAChD,eAAO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AW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAMD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAMD,gEAAgE;AAChE,eAAO,MAAM,YAAY,QAAyB,CAAC;AAEnD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKvD;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAK7D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAatD;AAED,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB,uBAAuB,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Data model for the local knowledge graph.
3
+ *
4
+ * Entities and relationships are stored as YAML source files in
5
+ * `.aidlc/knowledge/` (source of truth) and mirrored into a SQLite index
6
+ * (derived cache). Built-in types are closed sets; `custom:<name>` extends
7
+ * both without a schema change.
8
+ *
9
+ * Requirements: KG 1.1–1.5, 2.4, 11.1
10
+ *
11
+ * @module
12
+ */
13
+ // ---------------------------------------------------------------------------
14
+ // Type constants
15
+ // ---------------------------------------------------------------------------
16
+ /** Built-in entity types (KG Req 1.1). */
17
+ export const ENTITY_TYPES = [
18
+ 'module',
19
+ 'service',
20
+ 'domain-entity',
21
+ 'convention',
22
+ 'decision',
23
+ 'debt',
24
+ 'dependency',
25
+ 'endpoint',
26
+ 'config',
27
+ ];
28
+ /** Built-in relationship types (KG Req 1.4). */
29
+ export const RELATIONSHIP_TYPES = [
30
+ 'depends-on',
31
+ 'implements',
32
+ 'calls',
33
+ 'owns',
34
+ 'contains',
35
+ 'extends',
36
+ 'uses',
37
+ 'produces',
38
+ 'consumes',
39
+ 'conflicts-with',
40
+ ];
41
+ /** Current schema version for YAML sources and the SQLite index (KG Req 11.1). */
42
+ export const KNOWLEDGE_SCHEMA_VERSION = 1;
43
+ /** Confidence assigned to facts inferred by static analysis (KG Req 8.3). */
44
+ export const DISCOVERY_CONFIDENCE = 0.6;
45
+ /** Default confidence for agent-asserted facts (KG Req 8.3). */
46
+ export const AGENT_CONFIDENCE = 0.9;
47
+ /** Entities below this confidence are excluded from context output (KG Req 7.5). */
48
+ export const STALE_CONFIDENCE_FLOOR = 0.3;
49
+ // ---------------------------------------------------------------------------
50
+ // Validation helpers
51
+ // ---------------------------------------------------------------------------
52
+ /** Entity ids are lowercase slugs: letters, digits, hyphens. */
53
+ export const ENTITY_ID_RE = /^[a-z0-9][a-z0-9-]*$/;
54
+ export function isValidEntityType(type) {
55
+ return (ENTITY_TYPES.includes(type) ||
56
+ (type.startsWith('custom:') && type.length > 'custom:'.length));
57
+ }
58
+ export function isValidRelationshipType(type) {
59
+ return (RELATIONSHIP_TYPES.includes(type) ||
60
+ (type.startsWith('custom:') && type.length > 'custom:'.length));
61
+ }
62
+ /**
63
+ * Map an entity type to its YAML source filename (KG Req 2.1).
64
+ * Custom types share a single `custom.yaml`.
65
+ */
66
+ export function sourceFileForType(type) {
67
+ const map = {
68
+ module: 'modules.yaml',
69
+ service: 'services.yaml',
70
+ 'domain-entity': 'domain-entities.yaml',
71
+ convention: 'conventions.yaml',
72
+ decision: 'decisions.yaml',
73
+ debt: 'debt.yaml',
74
+ dependency: 'dependencies.yaml',
75
+ endpoint: 'endpoints.yaml',
76
+ config: 'config-entities.yaml',
77
+ };
78
+ return map[type] ?? 'custom.yaml';
79
+ }
80
+ /** Relationships live in a dedicated cross-cutting file. */
81
+ export const RELATIONSHIPS_FILE = 'relationships.yaml';
82
+ //# sourceMappingURL=types.js.map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C,SAAS,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAC/D,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,GAAG,GAA2B;QAClC,MAAM,EAAE,cAAc;QACtB,OAAO,EAAE,eAAe;QACxB,eAAe,EAAE,sBAAsB;QACvC,UAAU,EAAE,kBAAkB;QAC9B,QAAQ,EAAE,gBAAgB;QAC1B,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,mBAAmB;QAC/B,QAAQ,EAAE,gBAAgB;QAC1B,MAAM,EAAE,sBAAsB;KAC/B,CAAC;IACF,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC;AACpC,CAAC;AAED,4DAA4D;AAC5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * KnowledgeWriter — validated writes to the YAML sources plus index sync.
3
+ *
4
+ * Same-id adds merge instead of duplicating (KG Req 4.4): union tags, keep
5
+ * the higher confidence, prefer the incoming description, bump lastVerified.
6
+ * Descriptions and metadata are screened for common secret patterns with a
7
+ * warning — never store credentials in the graph (NFR N6).
8
+ *
9
+ * Requirements: KG 4.1–4.6, 12.1, 12.5
10
+ *
11
+ * @module
12
+ */
13
+ import type { Entity, Relationship } from './types.js';
14
+ import type { YamlSourceStore } from './yaml-source.js';
15
+ import type { KnowledgeIndex } from './index/knowledge-index.js';
16
+ export interface WriteResult {
17
+ entity: Entity;
18
+ merged: boolean;
19
+ warnings: string[];
20
+ }
21
+ export interface ImportResult {
22
+ added: number;
23
+ updated: number;
24
+ errors: string[];
25
+ warnings: string[];
26
+ }
27
+ /** Resolve the author for a write: AIDLC_AUTHOR → git user.name → "unknown" (KG Req 12.1). */
28
+ export declare function resolveAuthor(cwd?: string): string;
29
+ export declare class KnowledgeWriter {
30
+ private readonly source;
31
+ private readonly index;
32
+ constructor(source: YamlSourceStore, index: KnowledgeIndex);
33
+ /**
34
+ * Add an entity; if the id already exists, merge fields (KG Req 4.4).
35
+ * Fills defaults: confidence 0.9, author resolution, lastVerified now.
36
+ */
37
+ addEntity(input: Partial<Entity> & {
38
+ id: string;
39
+ type: string;
40
+ name: string;
41
+ }): WriteResult;
42
+ /** Create a relationship between two existing entities (KG Req 4.2). */
43
+ addRelationship(input: {
44
+ from: string;
45
+ to: string;
46
+ type: string;
47
+ metadata?: Record<string, unknown>;
48
+ }): Relationship;
49
+ /** Update fields on an existing entity (KG Req 4.3). */
50
+ updateEntity(id: string, updates: Partial<Pick<Entity, 'description' | 'confidence' | 'tags' | 'name' | 'source' | 'metadata'>>): WriteResult;
51
+ /** Bulk import entities then relationships; per-item errors don't abort (KG Req 4.6). */
52
+ importBatch(entities: Array<Partial<Entity> & {
53
+ id: string;
54
+ type: string;
55
+ name: string;
56
+ }>, relationships: Array<{
57
+ from: string;
58
+ to: string;
59
+ type: string;
60
+ metadata?: Record<string, unknown>;
61
+ }>): ImportResult;
62
+ private validateEntity;
63
+ private screenForSecrets;
64
+ }
65
+ /** Merge an incoming entity into an existing one (KG Req 4.4). */
66
+ export declare function mergeEntities(existing: Entity, incoming: Entity): Entity;
67
+ //# sourceMappingURL=writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/knowledge/writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAWjE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM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AC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,GAAG,YAAY;IA6B9M,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,gBAAgB;CAYzB;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAUxE"}
@@ -0,0 +1,189 @@
1
+ /**
2
+ * KnowledgeWriter — validated writes to the YAML sources plus index sync.
3
+ *
4
+ * Same-id adds merge instead of duplicating (KG Req 4.4): union tags, keep
5
+ * the higher confidence, prefer the incoming description, bump lastVerified.
6
+ * Descriptions and metadata are screened for common secret patterns with a
7
+ * warning — never store credentials in the graph (NFR N6).
8
+ *
9
+ * Requirements: KG 4.1–4.6, 12.1, 12.5
10
+ *
11
+ * @module
12
+ */
13
+ import { execSync } from 'node:child_process';
14
+ import { ENTITY_ID_RE, isValidEntityType, isValidRelationshipType, AGENT_CONFIDENCE, } from './types.js';
15
+ /** Patterns that suggest a credential is being written into the graph (NFR N6). */
16
+ const SECRET_PATTERNS = [
17
+ /-----BEGIN [A-Z ]*PRIVATE KEY-----/,
18
+ /\bAKIA[0-9A-Z]{16}\b/, // AWS access key id
19
+ /\bgh[pousr]_[A-Za-z0-9]{36,}\b/, // GitHub tokens
20
+ /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/, // Slack tokens
21
+ /\b(?:api[_-]?key|secret|password|token)\s*[:=]\s*['"][^'"]{8,}['"]/i,
22
+ ];
23
+ /** Resolve the author for a write: AIDLC_AUTHOR → git user.name → "unknown" (KG Req 12.1). */
24
+ export function resolveAuthor(cwd) {
25
+ const env = process.env.AIDLC_AUTHOR;
26
+ if (env && env.trim())
27
+ return env.trim();
28
+ try {
29
+ const name = execSync('git config user.name', {
30
+ cwd,
31
+ encoding: 'utf8',
32
+ stdio: ['ignore', 'pipe', 'ignore'],
33
+ }).trim();
34
+ if (name)
35
+ return name;
36
+ }
37
+ catch {
38
+ // git absent or unconfigured
39
+ }
40
+ return 'unknown';
41
+ }
42
+ export class KnowledgeWriter {
43
+ source;
44
+ index;
45
+ constructor(source, index) {
46
+ this.source = source;
47
+ this.index = index;
48
+ }
49
+ /**
50
+ * Add an entity; if the id already exists, merge fields (KG Req 4.4).
51
+ * Fills defaults: confidence 0.9, author resolution, lastVerified now.
52
+ */
53
+ addEntity(input) {
54
+ const warnings = [];
55
+ const entity = {
56
+ id: input.id,
57
+ type: input.type,
58
+ name: input.name,
59
+ description: input.description ?? '',
60
+ confidence: input.confidence ?? AGENT_CONFIDENCE,
61
+ source: input.source ?? 'agent-inferred',
62
+ author: input.author ?? resolveAuthor(),
63
+ tags: input.tags ?? [],
64
+ lastVerified: input.lastVerified ?? new Date().toISOString(),
65
+ ...(input.metadata !== undefined ? { metadata: input.metadata } : {}),
66
+ };
67
+ this.validateEntity(entity);
68
+ this.screenForSecrets(entity, warnings);
69
+ const existing = this.index.getEntity(entity.id);
70
+ if (existing) {
71
+ const merged = mergeEntities(existing, entity);
72
+ this.source.updateEntity(merged);
73
+ this.index.upsertEntity(merged);
74
+ return { entity: merged, merged: true, warnings };
75
+ }
76
+ this.source.appendEntity(entity);
77
+ this.index.upsertEntity(entity);
78
+ return { entity, merged: false, warnings };
79
+ }
80
+ /** Create a relationship between two existing entities (KG Req 4.2). */
81
+ addRelationship(input) {
82
+ if (!isValidRelationshipType(input.type)) {
83
+ throw new Error(`Unknown relationship type '${input.type}'. Use one of the built-in types or 'custom:<name>'.`);
84
+ }
85
+ if (!this.index.getEntity(input.from)) {
86
+ throw new Error(`Entity not found: '${input.from}'. Add it first with 'aidlc knowledge add'.`);
87
+ }
88
+ if (!this.index.getEntity(input.to)) {
89
+ throw new Error(`Entity not found: '${input.to}'. Add it first with 'aidlc knowledge add'.`);
90
+ }
91
+ const rel = {
92
+ from: input.from,
93
+ to: input.to,
94
+ type: input.type,
95
+ ...(input.metadata !== undefined ? { metadata: input.metadata } : {}),
96
+ lastVerified: new Date().toISOString(),
97
+ };
98
+ this.source.appendRelationship(rel);
99
+ this.index.upsertRelationship(rel);
100
+ return rel;
101
+ }
102
+ /** Update fields on an existing entity (KG Req 4.3). */
103
+ updateEntity(id, updates) {
104
+ const existing = this.index.getEntity(id);
105
+ if (!existing) {
106
+ throw new Error(`Entity not found: '${id}'`);
107
+ }
108
+ const warnings = [];
109
+ const updated = {
110
+ ...existing,
111
+ ...stripUndefined(updates),
112
+ lastVerified: new Date().toISOString(),
113
+ };
114
+ this.validateEntity(updated);
115
+ this.screenForSecrets(updated, warnings);
116
+ this.source.updateEntity(updated);
117
+ this.index.upsertEntity(updated);
118
+ return { entity: updated, merged: false, warnings };
119
+ }
120
+ /** Bulk import entities then relationships; per-item errors don't abort (KG Req 4.6). */
121
+ importBatch(entities, relationships) {
122
+ const result = { added: 0, updated: 0, errors: [], warnings: [] };
123
+ for (const input of entities) {
124
+ try {
125
+ const write = this.addEntity(input);
126
+ if (write.merged)
127
+ result.updated++;
128
+ else
129
+ result.added++;
130
+ result.warnings.push(...write.warnings);
131
+ }
132
+ catch (err) {
133
+ result.errors.push(`${input.id ?? '<no id>'}: ${err.message}`);
134
+ }
135
+ }
136
+ for (const rel of relationships) {
137
+ try {
138
+ this.addRelationship(rel);
139
+ }
140
+ catch (err) {
141
+ result.errors.push(`${rel.from}->${rel.to}: ${err.message}`);
142
+ }
143
+ }
144
+ return result;
145
+ }
146
+ // -------------------------------------------------------------------------
147
+ // Validation
148
+ // -------------------------------------------------------------------------
149
+ validateEntity(entity) {
150
+ if (!entity.id || !ENTITY_ID_RE.test(entity.id)) {
151
+ throw new Error(`Invalid entity id '${entity.id}' (must be a lowercase slug: letters, digits, hyphens)`);
152
+ }
153
+ if (!isValidEntityType(entity.type)) {
154
+ throw new Error(`Unknown entity type '${entity.type}'. Use one of the built-in types or 'custom:<name>'.`);
155
+ }
156
+ if (typeof entity.confidence !== 'number' || entity.confidence < 0 || entity.confidence > 1) {
157
+ throw new Error(`Confidence must be between 0.0 and 1.0, got: ${entity.confidence}`);
158
+ }
159
+ if (!entity.name) {
160
+ throw new Error('Entity name is required');
161
+ }
162
+ }
163
+ screenForSecrets(entity, warnings) {
164
+ const text = `${entity.description} ${JSON.stringify(entity.metadata ?? {})}`;
165
+ for (const pattern of SECRET_PATTERNS) {
166
+ if (pattern.test(text)) {
167
+ warnings.push(`Entity '${entity.id}' may contain a credential (matched ${pattern.source.slice(0, 30)}…). ` +
168
+ 'Never store secrets in the knowledge graph.');
169
+ return;
170
+ }
171
+ }
172
+ }
173
+ }
174
+ /** Merge an incoming entity into an existing one (KG Req 4.4). */
175
+ export function mergeEntities(existing, incoming) {
176
+ return {
177
+ ...existing,
178
+ name: incoming.name || existing.name,
179
+ description: incoming.description || existing.description,
180
+ confidence: Math.max(existing.confidence, incoming.confidence),
181
+ tags: [...new Set([...existing.tags, ...incoming.tags])],
182
+ lastVerified: new Date().toISOString(),
183
+ metadata: { ...existing.metadata, ...incoming.metadata },
184
+ };
185
+ }
186
+ function stripUndefined(obj) {
187
+ return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined));
188
+ }
189
+ //# sourceMappingURL=writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.js","sourceRoot":"","sources":["../../src/knowledge/writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAKpB,mFAAmF;AACnF,MAAM,eAAe,GAAa;IAChC,oCAAoC;IACpC,sBAAsB,EAAE,oBAAoB;IAC5C,gCAAgC,EAAE,gBAAgB;IAClD,kCAAkC,EAAE,eAAe;IACnD,qEAAqE;CACtE,CAAC;AAeF,8FAA8F;AAC9F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AAC;QACH,CAAC;IACH,CAAC;CACF;AAED,kEAAkE;AAClE,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,QAAgB;IAC9D,OAAO;QACL,GAAG,QAAQ;QACX,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI;QACpC,WAAW,EAAE,QAAQ,CAAC,WAAW,IAAI,QAAQ,CAAC,WAAW;QACzD,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC;QAC9D,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QACxD,YAAY,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACtC,QAAQ,EAAE,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE;KACzD,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAmB,GAAM;IAC9C,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAM,CAAC;AACzF,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * YAML source layer — the knowledge graph's source of truth.
3
+ *
4
+ * One multi-document file per entity type plus `relationships.yaml`, each with
5
+ * a `_meta` header document. Writes are append-only by default (KG Req 2.5,
6
+ * 12.5): new entities go to the end of the file; only explicit updates rewrite
7
+ * an existing document. Only the affected file is ever touched (KG Req 2.3).
8
+ *
9
+ * Requirements: KG 2.1–2.5, 11.1, 12.5
10
+ *
11
+ * @module
12
+ */
13
+ import type { Entity, Relationship } from './types.js';
14
+ /** Result of loading all YAML sources. */
15
+ export interface LoadedGraph {
16
+ entities: Entity[];
17
+ relationships: Relationship[];
18
+ /** Parse problems encountered (file → message); corrupted docs are skipped. */
19
+ warnings: string[];
20
+ }
21
+ export declare class YamlSourceStore {
22
+ private readonly knowledgeDir;
23
+ constructor(knowledgeDir: string);
24
+ /** Absolute path of the knowledge directory. */
25
+ get dir(): string;
26
+ /** True once any source file exists. */
27
+ exists(): boolean;
28
+ /** Append a new entity document to its type file (KG Req 2.5). */
29
+ appendEntity(entity: Entity): void;
30
+ /** Rewrite an existing entity document in place (explicit update path). */
31
+ updateEntity(entity: Entity): void;
32
+ /** Append a relationship document to relationships.yaml (KG Req 2.5). */
33
+ appendRelationship(rel: Relationship): void;
34
+ /**
35
+ * Rewrite a whole source file from scratch (used only by `compact`,
36
+ * the sanctioned exception to append-only — KG Req 12.6).
37
+ */
38
+ rewriteFile(filename: string, entityType: string, docs: Array<Entity | Relationship>): void;
39
+ /** Update the `_meta.lastIndexed` timestamp of every source file. */
40
+ touchLastIndexed(timestamp: string): void;
41
+ /** Parse every source file into entities and relationships (KG Req 3.2). */
42
+ loadAll(): LoadedGraph;
43
+ /** List YAML source files (basenames), excluding the index db. */
44
+ listSourceFiles(): string[];
45
+ private ensureFile;
46
+ private metaHeader;
47
+ }
48
+ //# sourceMappingURL=yaml-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml-source.d.ts","sourceRoot":"","sources":["../../src/knowledge/yaml-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAWH,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAkB,MAAM,YAAY,CAAC;AAEvE,0CAA0C;AAC1C,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,+EAA+E;IAC/E,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAAZ,YAAY,EAAE,MAAM;IAEjD,gDAAgD;IAChD,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,wCAAwC;IACxC,MAAM,IAAI,OAAO;IASjB,kEAAkE;IAClE,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAQlC,2EAA2E;IAC3E,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IA4BlC,yEAAyE;IACzE,kBAAkB,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI;IAQ3C;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC,GAAG,IAAI;IAO3F,qEAAqE;IACrE,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IA2BzC,4EAA4E;IAC5E,OAAO,IAAI,WAAW;IAkDtB,kEAAkE;IAClE,eAAe,IAAI,MAAM,EAAE;IAe3B,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,UAAU;CAQnB"}