@specferret/core 0.1.4 → 0.2.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.
- package/dist/extractor/frontmatter.d.ts +4 -0
- package/dist/extractor/frontmatter.d.ts.map +1 -1
- package/dist/extractor/frontmatter.js +5 -0
- package/dist/extractor/frontmatter.js.map +1 -1
- package/dist/extractor/upward-classifier.d.ts +25 -0
- package/dist/extractor/upward-classifier.d.ts.map +1 -0
- package/dist/extractor/upward-classifier.js +48 -0
- package/dist/extractor/upward-classifier.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/store/sqlite.d.ts +1 -1
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +37 -32
- package/dist/store/sqlite.js.map +1 -1
- package/dist/store/types.d.ts +6 -2
- package/dist/store/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/extractor/frontmatter.test.ts +74 -0
- package/src/extractor/frontmatter.ts +10 -0
- package/src/extractor/upward-classifier.test.ts +188 -0
- package/src/extractor/upward-classifier.ts +68 -0
- package/src/index.ts +1 -0
- package/src/store/sqlite.test.ts +135 -79
- package/src/store/sqlite.ts +45 -92
- package/src/store/types.ts +7 -6
|
@@ -8,6 +8,10 @@ export interface ExtractionResult {
|
|
|
8
8
|
shape: object;
|
|
9
9
|
shape_hash: string;
|
|
10
10
|
imports: string[];
|
|
11
|
+
/** Path to the TypeScript source file (code-first contracts only). */
|
|
12
|
+
sourceFile?: string;
|
|
13
|
+
/** TypeScript symbol name (code-first contracts only). */
|
|
14
|
+
sourceSymbol?: string;
|
|
11
15
|
}>;
|
|
12
16
|
extractedBy: 'gray-matter' | 'tree-sitter';
|
|
13
17
|
extractedAt: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../src/extractor/frontmatter.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,SAAS,EAAE,KAAK,CAAC;QACf,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,YAAY,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../src/extractor/frontmatter.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,SAAS,EAAE,KAAK,CAAC;QACf,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,YAAY,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,sEAAsE;QACtE,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,0DAA0D;QAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC,CAAC;IACH,WAAW,EAAE,aAAa,GAAG,aAAa,CAAC;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,gBAAgB,CAkD3F"}
|
|
@@ -36,6 +36,9 @@ export function extractFromSpecFile(filePath, fileContent) {
|
|
|
36
36
|
// validateFerretSchema never throws — only warns on unsupported keywords
|
|
37
37
|
const validation = validateFerretSchema(ferret.shape, filePath);
|
|
38
38
|
validation.warnings.forEach((w) => process.stderr.write(w + '\n'));
|
|
39
|
+
const source = ferret.source;
|
|
40
|
+
const sourceFile = typeof source?.file === 'string' ? source.file : undefined;
|
|
41
|
+
const sourceSymbol = typeof source?.symbol === 'string' ? source.symbol : undefined;
|
|
39
42
|
return {
|
|
40
43
|
filePath,
|
|
41
44
|
fileType: 'spec',
|
|
@@ -46,6 +49,8 @@ export function extractFromSpecFile(filePath, fileContent) {
|
|
|
46
49
|
shape: ferret.shape,
|
|
47
50
|
shape_hash: hashSchema(ferret.shape),
|
|
48
51
|
imports: Array.isArray(ferret.imports) ? ferret.imports : [],
|
|
52
|
+
...(sourceFile !== undefined && { sourceFile }),
|
|
53
|
+
...(sourceSymbol !== undefined && { sourceSymbol }),
|
|
49
54
|
},
|
|
50
55
|
],
|
|
51
56
|
extractedBy: 'gray-matter',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../src/extractor/frontmatter.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,kFAAkF;AAElF,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../src/extractor/frontmatter.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,kFAAkF;AAElF,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAsBvC;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAgB,EAAE,WAAmB;IACvE,MAAM,EAA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,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9E,MAAM,YAAY,GAAG,OAAO,MAAM,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAEpF,OAAO;QACL,QAAQ;QACR,QAAQ,EAAE,MAAM;QAChB,SAAS,EAAE;YACT;gBACE,EAAE,EAAE,MAAM,CAAC,EAAY;gBACvB,IAAI,EAAE,cAAc,CAAC,KAAK;gBAC1B,KAAK,EAAE,MAAM,CAAC,KAAe;gBAC7B,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC;gBACpC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,OAAoB,CAAC,CAAC,CAAC,EAAE;gBAC1E,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,CAAC;gBAC/C,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,CAAC;aACpD;SACF;QACD,WAAW,EAAE,aAAa;QAC1B,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type UpwardDriftClass = 'BREAKING' | 'NON_BREAKING' | 'NOOP';
|
|
2
|
+
export interface UpwardDriftResult {
|
|
3
|
+
contractId: string;
|
|
4
|
+
driftClass: UpwardDriftClass;
|
|
5
|
+
sourceFile: string;
|
|
6
|
+
sourceSymbol: string;
|
|
7
|
+
reason: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Classifies the drift between a declared contract schema and the live code-derived schema.
|
|
11
|
+
*
|
|
12
|
+
* Input:
|
|
13
|
+
* - declaredSchema: the schema declared in the .contract.md frontmatter (the spec)
|
|
14
|
+
* - codeSchema: the schema extracted from the TypeScript source at lint time
|
|
15
|
+
*
|
|
16
|
+
* Output:
|
|
17
|
+
* - BREAKING: code change breaks the declared contract (required field removed, type changed, etc.)
|
|
18
|
+
* - NON_BREAKING: code change is additive but not declared (optional field added, enum value added)
|
|
19
|
+
* - NOOP: code and declared schema are semantically identical (hash-stable, no action needed)
|
|
20
|
+
*
|
|
21
|
+
* Uses the same classification taxonomy as compareSchemas for consistency.
|
|
22
|
+
* No-op formatting changes (property reorder with stable hash) return NOOP.
|
|
23
|
+
*/
|
|
24
|
+
export declare function classifyUpwardDrift(contractId: string, declaredSchema: unknown, codeSchema: unknown, sourceFile: string, sourceSymbol: string): UpwardDriftResult;
|
|
25
|
+
//# sourceMappingURL=upward-classifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upward-classifier.d.ts","sourceRoot":"","sources":["../../src/extractor/upward-classifier.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,cAAc,GAAG,MAAM,CAAC;AAEpE,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,gBAAgB,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,OAAO,EACvB,UAAU,EAAE,OAAO,EACnB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GACnB,iBAAiB,CA8BnB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Pure function. No I/O. No side effects. Ever.
|
|
2
|
+
// Upward drift classifier — detects when a TypeScript implementation diverges from
|
|
3
|
+
// its declared contract schema (code → spec direction).
|
|
4
|
+
import { compareSchemas } from './validator.js';
|
|
5
|
+
/**
|
|
6
|
+
* Classifies the drift between a declared contract schema and the live code-derived schema.
|
|
7
|
+
*
|
|
8
|
+
* Input:
|
|
9
|
+
* - declaredSchema: the schema declared in the .contract.md frontmatter (the spec)
|
|
10
|
+
* - codeSchema: the schema extracted from the TypeScript source at lint time
|
|
11
|
+
*
|
|
12
|
+
* Output:
|
|
13
|
+
* - BREAKING: code change breaks the declared contract (required field removed, type changed, etc.)
|
|
14
|
+
* - NON_BREAKING: code change is additive but not declared (optional field added, enum value added)
|
|
15
|
+
* - NOOP: code and declared schema are semantically identical (hash-stable, no action needed)
|
|
16
|
+
*
|
|
17
|
+
* Uses the same classification taxonomy as compareSchemas for consistency.
|
|
18
|
+
* No-op formatting changes (property reorder with stable hash) return NOOP.
|
|
19
|
+
*/
|
|
20
|
+
export function classifyUpwardDrift(contractId, declaredSchema, codeSchema, sourceFile, sourceSymbol) {
|
|
21
|
+
const comparison = compareSchemas(declaredSchema, codeSchema);
|
|
22
|
+
if (comparison.classification === 'no-change') {
|
|
23
|
+
return {
|
|
24
|
+
contractId,
|
|
25
|
+
driftClass: 'NOOP',
|
|
26
|
+
sourceFile,
|
|
27
|
+
sourceSymbol,
|
|
28
|
+
reason: comparison.reason,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (comparison.classification === 'breaking') {
|
|
32
|
+
return {
|
|
33
|
+
contractId,
|
|
34
|
+
driftClass: 'BREAKING',
|
|
35
|
+
sourceFile,
|
|
36
|
+
sourceSymbol,
|
|
37
|
+
reason: comparison.reason,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
contractId,
|
|
42
|
+
driftClass: 'NON_BREAKING',
|
|
43
|
+
sourceFile,
|
|
44
|
+
sourceSymbol,
|
|
45
|
+
reason: comparison.reason,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=upward-classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upward-classifier.js","sourceRoot":"","sources":["../../src/extractor/upward-classifier.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,mFAAmF;AACnF,wDAAwD;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAYhD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAkB,EAClB,cAAuB,EACvB,UAAmB,EACnB,UAAkB,EAClB,YAAoB;IAEpB,MAAM,UAAU,GAAG,cAAc,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAE9D,IAAI,UAAU,CAAC,cAAc,KAAK,WAAW,EAAE,CAAC;QAC9C,OAAO;YACL,UAAU;YACV,UAAU,EAAE,MAAM;YAClB,UAAU;YACV,YAAY;YACZ,MAAM,EAAE,UAAU,CAAC,MAAM;SAC1B,CAAC;IACJ,CAAC;IAED,IAAI,UAAU,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;QAC7C,OAAO;YACL,UAAU;YACV,UAAU,EAAE,UAAU;YACtB,UAAU;YACV,YAAY;YACZ,MAAM,EAAE,UAAU,CAAC,MAAM;SAC1B,CAAC;IACJ,CAAC;IAED,OAAO;QACL,UAAU;QACV,UAAU,EAAE,cAAc;QAC1B,UAAU;QACV,YAAY;QACZ,MAAM,EAAE,UAAU,CAAC,MAAM;KAC1B,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './extractor/typescript.js';
|
|
|
3
3
|
export * from './extractor/validator.js';
|
|
4
4
|
export * from './extractor/contract-types.js';
|
|
5
5
|
export * from './extractor/hash.js';
|
|
6
|
+
export * from './extractor/upward-classifier.js';
|
|
6
7
|
export * from './context/index.js';
|
|
7
8
|
export * from './store/types.js';
|
|
8
9
|
export * from './store/sqlite.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './extractor/typescript.js';
|
|
|
5
5
|
export * from './extractor/validator.js';
|
|
6
6
|
export * from './extractor/contract-types.js';
|
|
7
7
|
export * from './extractor/hash.js';
|
|
8
|
+
export * from './extractor/upward-classifier.js';
|
|
8
9
|
export * from './context/index.js';
|
|
9
10
|
export * from './store/types.js';
|
|
10
11
|
export * from './store/sqlite.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,4EAA4E;AAE5E,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,4EAA4E;AAE5E,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
package/dist/store/sqlite.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DBStore, FerretNode, FerretContract, FerretDependency, FerretReconciliationLog, FerretPlacementDecision, NodeStatus } from
|
|
1
|
+
import type { DBStore, FerretNode, FerretContract, FerretDependency, FerretReconciliationLog, FerretPlacementDecision, NodeStatus } from './types.js';
|
|
2
2
|
export declare class SqliteStore implements DBStore {
|
|
3
3
|
private db;
|
|
4
4
|
private dbPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/store/sqlite.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/store/sqlite.ts"],"names":[],"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,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IASpE,qBAAqB,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC;IAM3D,uBAAuB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IASzE,qBAAqB,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC;CAGlE"}
|
package/dist/store/sqlite.js
CHANGED
|
@@ -1,38 +1,33 @@
|
|
|
1
|
-
import { Database } from
|
|
2
|
-
import * as path from
|
|
3
|
-
import * as fs from
|
|
4
|
-
import { randomUUID } from
|
|
5
|
-
import { findProjectRoot } from
|
|
1
|
+
import { Database } from 'bun:sqlite';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { findProjectRoot } from '../utils/paths.js';
|
|
6
6
|
export class SqliteStore {
|
|
7
7
|
db = null;
|
|
8
8
|
dbPath;
|
|
9
9
|
constructor(customPath) {
|
|
10
10
|
const root = findProjectRoot();
|
|
11
|
-
const defaultPath = path.join(root,
|
|
12
|
-
this.dbPath =
|
|
13
|
-
customPath === ":memory:"
|
|
14
|
-
? ":memory:"
|
|
15
|
-
: customPath
|
|
16
|
-
? path.resolve(root, customPath)
|
|
17
|
-
: defaultPath;
|
|
11
|
+
const defaultPath = path.join(root, '.ferret', 'graph.db');
|
|
12
|
+
this.dbPath = customPath === ':memory:' ? ':memory:' : customPath ? path.resolve(root, customPath) : defaultPath;
|
|
18
13
|
}
|
|
19
14
|
async init() {
|
|
20
15
|
if (this.db)
|
|
21
16
|
return;
|
|
22
|
-
if (this.dbPath !==
|
|
17
|
+
if (this.dbPath !== ':memory:') {
|
|
23
18
|
const ferretDir = path.dirname(this.dbPath);
|
|
24
19
|
if (!fs.existsSync(ferretDir)) {
|
|
25
20
|
fs.mkdirSync(ferretDir, { recursive: true });
|
|
26
21
|
}
|
|
27
|
-
const gitignorePath = path.join(ferretDir,
|
|
22
|
+
const gitignorePath = path.join(ferretDir, '.gitignore');
|
|
28
23
|
try {
|
|
29
|
-
fs.writeFileSync(gitignorePath,
|
|
24
|
+
fs.writeFileSync(gitignorePath, '*\n!.gitignore\n!context.json\n', 'utf-8');
|
|
30
25
|
}
|
|
31
26
|
catch { }
|
|
32
27
|
}
|
|
33
28
|
this.db = new Database(this.dbPath);
|
|
34
|
-
this.db.exec(
|
|
35
|
-
this.db.exec(
|
|
29
|
+
this.db.exec('PRAGMA journal_mode = WAL;');
|
|
30
|
+
this.db.exec('PRAGMA foreign_keys = ON;');
|
|
36
31
|
this.db.exec(`
|
|
37
32
|
CREATE TABLE IF NOT EXISTS ferret_nodes (
|
|
38
33
|
id TEXT PRIMARY KEY,
|
|
@@ -80,6 +75,14 @@ export class SqliteStore {
|
|
|
80
75
|
this.db.exec(`ALTER TABLE ferret_contracts ADD COLUMN shape_schema TEXT NOT NULL DEFAULT '{}';`);
|
|
81
76
|
}
|
|
82
77
|
catch { }
|
|
78
|
+
try {
|
|
79
|
+
this.db.exec(`ALTER TABLE ferret_contracts ADD COLUMN code_source_file TEXT;`);
|
|
80
|
+
}
|
|
81
|
+
catch { }
|
|
82
|
+
try {
|
|
83
|
+
this.db.exec(`ALTER TABLE ferret_contracts ADD COLUMN code_source_symbol TEXT;`);
|
|
84
|
+
}
|
|
85
|
+
catch { }
|
|
83
86
|
}
|
|
84
87
|
async close() {
|
|
85
88
|
if (this.db) {
|
|
@@ -88,7 +91,7 @@ export class SqliteStore {
|
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
async getNodeByFilePath(filePath) {
|
|
91
|
-
const row = this.db.prepare(
|
|
94
|
+
const row = this.db.prepare('SELECT * FROM ferret_nodes WHERE file_path = ?').get(filePath);
|
|
92
95
|
return row ?? null;
|
|
93
96
|
}
|
|
94
97
|
async upsertNode(node) {
|
|
@@ -103,19 +106,21 @@ export class SqliteStore {
|
|
|
103
106
|
`).run(node.id, node.file_path, node.hash, node.status);
|
|
104
107
|
}
|
|
105
108
|
async getAllContractIds() {
|
|
106
|
-
return this.db.prepare(
|
|
109
|
+
return this.db.prepare('SELECT id FROM ferret_contracts').all().map((r) => r.id);
|
|
107
110
|
}
|
|
108
111
|
async upsertContract(contract) {
|
|
109
112
|
this.db.prepare(`
|
|
110
|
-
INSERT INTO ferret_contracts (id, node_id, shape_hash, shape_schema, type, status)
|
|
111
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
113
|
+
INSERT INTO ferret_contracts (id, node_id, shape_hash, shape_schema, type, status, code_source_file, code_source_symbol)
|
|
114
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
112
115
|
ON CONFLICT(id) DO UPDATE SET
|
|
113
116
|
node_id = excluded.node_id,
|
|
114
117
|
shape_hash = excluded.shape_hash,
|
|
115
118
|
shape_schema = excluded.shape_schema,
|
|
116
119
|
type = excluded.type,
|
|
117
|
-
status = excluded.status
|
|
118
|
-
|
|
120
|
+
status = excluded.status,
|
|
121
|
+
code_source_file = excluded.code_source_file,
|
|
122
|
+
code_source_symbol = excluded.code_source_symbol
|
|
123
|
+
`).run(contract.id, contract.node_id, contract.shape_hash, contract.shape_schema, contract.type, contract.status, contract.code_source_file ?? null, contract.code_source_symbol ?? null);
|
|
119
124
|
}
|
|
120
125
|
async upsertDependency(dependency) {
|
|
121
126
|
this.db.prepare(`
|
|
@@ -126,7 +131,7 @@ export class SqliteStore {
|
|
|
126
131
|
}
|
|
127
132
|
async replaceDependenciesForSourceNode(sourceNodeId, targetContractIds) {
|
|
128
133
|
const uniqueTargets = [...new Set(targetContractIds)].sort();
|
|
129
|
-
const deleteStatement = this.db.prepare(
|
|
134
|
+
const deleteStatement = this.db.prepare('DELETE FROM ferret_dependencies WHERE source_node_id = ?');
|
|
130
135
|
const insertStatement = this.db.prepare(`
|
|
131
136
|
INSERT INTO ferret_dependencies (id, source_node_id, target_contract_id)
|
|
132
137
|
VALUES (?, ?, ?)
|
|
@@ -140,23 +145,23 @@ export class SqliteStore {
|
|
|
140
145
|
transaction(sourceNodeId);
|
|
141
146
|
}
|
|
142
147
|
async getNodes() {
|
|
143
|
-
return this.db.prepare(
|
|
148
|
+
return this.db.prepare('SELECT * FROM ferret_nodes').all();
|
|
144
149
|
}
|
|
145
150
|
async getNodesByStatus(status) {
|
|
146
|
-
return this.db.prepare(
|
|
151
|
+
return this.db.prepare('SELECT * FROM ferret_nodes WHERE status = ?').all(status);
|
|
147
152
|
}
|
|
148
153
|
async getContracts() {
|
|
149
|
-
return this.db.prepare(
|
|
154
|
+
return this.db.prepare('SELECT * FROM ferret_contracts').all();
|
|
150
155
|
}
|
|
151
156
|
async getContract(id) {
|
|
152
|
-
const row = this.db.prepare(
|
|
157
|
+
const row = this.db.prepare('SELECT * FROM ferret_contracts WHERE id = ?').get(id);
|
|
153
158
|
return row ?? null;
|
|
154
159
|
}
|
|
155
160
|
async getDependencies() {
|
|
156
|
-
return this.db.prepare(
|
|
161
|
+
return this.db.prepare('SELECT * FROM ferret_dependencies').all();
|
|
157
162
|
}
|
|
158
163
|
async updateNodeStatus(nodeId, status) {
|
|
159
|
-
this.db.prepare(
|
|
164
|
+
this.db.prepare('UPDATE ferret_nodes SET status = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?').run(status, nodeId);
|
|
160
165
|
}
|
|
161
166
|
async insertReconciliationLog(log) {
|
|
162
167
|
this.db.prepare(`
|
|
@@ -165,7 +170,7 @@ export class SqliteStore {
|
|
|
165
170
|
`).run(log.id, log.node_id, log.triggered_by, log.resolved_by ?? null, log.resolution_notes ?? null);
|
|
166
171
|
}
|
|
167
172
|
async getReconciliationLogs() {
|
|
168
|
-
return this.db.prepare(
|
|
173
|
+
return this.db.prepare('SELECT id, node_id, triggered_by, resolved_by, resolution_notes FROM ferret_reconciliation_log').all();
|
|
169
174
|
}
|
|
170
175
|
async insertPlacementDecision(decision) {
|
|
171
176
|
this.db.prepare(`
|
|
@@ -174,7 +179,7 @@ export class SqliteStore {
|
|
|
174
179
|
`).run(decision.id, decision.node_id, decision.placed_by, decision.reasoning ?? null);
|
|
175
180
|
}
|
|
176
181
|
async getPlacementDecisions() {
|
|
177
|
-
return this.db.prepare(
|
|
182
|
+
return this.db.prepare('SELECT id, node_id, placed_by, reasoning FROM ferret_placement_decisions').all();
|
|
178
183
|
}
|
|
179
184
|
}
|
|
180
185
|
//# sourceMappingURL=sqlite.js.map
|
package/dist/store/sqlite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/store/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/store/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,MAAM,OAAO,WAAW;IACd,EAAE,GAAoB,IAAI,CAAC;IAC3B,MAAM,CAAS;IAEvB,YAAY,UAAmB;QAC7B,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;QAC/B,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,GAAG,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CA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AQ,CAAC,SAAS,IAAI,IAAI,CAAC,CAAC;IACvF,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,OAAO,IAAI,CAAC,EAAG,CAAC,OAAO,CAAC,0EAA0E,CAAC,CAAC,GAAG,EAA0C,CAAC;IACpJ,CAAC;CACF"}
|
package/dist/store/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type NodeStatus =
|
|
2
|
-
export type ContractStatus =
|
|
1
|
+
export type NodeStatus = 'stable' | 'needs-review' | 'roadmap' | 'blocked';
|
|
2
|
+
export type ContractStatus = 'stable' | 'roadmap' | 'needs-review';
|
|
3
3
|
export interface FerretNode {
|
|
4
4
|
id: string;
|
|
5
5
|
file_path: string;
|
|
@@ -14,6 +14,10 @@ export interface FerretContract {
|
|
|
14
14
|
shape_schema: string;
|
|
15
15
|
type: string;
|
|
16
16
|
status: ContractStatus;
|
|
17
|
+
/** Path to the TypeScript file this contract was generated from (code-first contracts only). */
|
|
18
|
+
code_source_file?: string;
|
|
19
|
+
/** TypeScript symbol name this contract was generated from (code-first contracts only). */
|
|
20
|
+
code_source_symbol?: string;
|
|
17
21
|
}
|
|
18
22
|
export interface FerretDependency {
|
|
19
23
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/store/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,cAAc,GAAG,SAAS,GAAG,SAAS,CAAC;AAC3E,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,SAAS,GAAG,cAAc,CAAC;AAEnE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC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C,UAAU,EAAE,CAAC,CAAC;IAC5D,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAC1C,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACxD,eAAe,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAE/C,4DAA4D;IAC5D,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE,wDAAwD;IACxD,uBAAuB,CAAC,GAAG,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE,qBAAqB,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC;IAE5D,8CAA8C;IAC9C,uBAAuB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1E,qBAAqB,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC;CAC7D"}
|
package/package.json
CHANGED
|
@@ -215,3 +215,77 @@ ferret:
|
|
|
215
215
|
assert.equal(r1.contracts[0].shape_hash, r2.contracts[0].shape_hash);
|
|
216
216
|
});
|
|
217
217
|
});
|
|
218
|
+
|
|
219
|
+
describe('extractFromSpecFile — S50 source block', () => {
|
|
220
|
+
const SPEC_WITH_SOURCE = `---
|
|
221
|
+
ferret:
|
|
222
|
+
id: auth.jwt
|
|
223
|
+
type: type
|
|
224
|
+
source:
|
|
225
|
+
file: src/auth/jwt.ts
|
|
226
|
+
symbol: JwtPayload
|
|
227
|
+
shape:
|
|
228
|
+
type: object
|
|
229
|
+
properties:
|
|
230
|
+
sub:
|
|
231
|
+
type: string
|
|
232
|
+
required: [sub]
|
|
233
|
+
---
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
const SPEC_WITHOUT_SOURCE = `---
|
|
237
|
+
ferret:
|
|
238
|
+
id: auth.jwt
|
|
239
|
+
type: type
|
|
240
|
+
shape:
|
|
241
|
+
type: object
|
|
242
|
+
properties:
|
|
243
|
+
sub:
|
|
244
|
+
type: string
|
|
245
|
+
required: [sub]
|
|
246
|
+
---
|
|
247
|
+
`;
|
|
248
|
+
|
|
249
|
+
it('parses source.file and source.symbol when present', () => {
|
|
250
|
+
const result = extractFromSpecFile('contracts/auth/jwt.contract.md', SPEC_WITH_SOURCE);
|
|
251
|
+
assert.equal(result.contracts.length, 1);
|
|
252
|
+
assert.equal(result.contracts[0].sourceFile, 'src/auth/jwt.ts');
|
|
253
|
+
assert.equal(result.contracts[0].sourceSymbol, 'JwtPayload');
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('has undefined sourceFile and sourceSymbol when source block absent', () => {
|
|
257
|
+
const result = extractFromSpecFile('contracts/auth/jwt.contract.md', SPEC_WITHOUT_SOURCE);
|
|
258
|
+
assert.equal(result.contracts.length, 1);
|
|
259
|
+
assert.equal(result.contracts[0].sourceFile, undefined);
|
|
260
|
+
assert.equal(result.contracts[0].sourceSymbol, undefined);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('ignores source block with non-string fields gracefully', () => {
|
|
264
|
+
const specBadSource = `---
|
|
265
|
+
ferret:
|
|
266
|
+
id: auth.jwt
|
|
267
|
+
type: type
|
|
268
|
+
source:
|
|
269
|
+
file: 42
|
|
270
|
+
symbol: [not, a, string]
|
|
271
|
+
shape:
|
|
272
|
+
type: object
|
|
273
|
+
---
|
|
274
|
+
`;
|
|
275
|
+
const result = extractFromSpecFile('contracts/auth/jwt.contract.md', specBadSource);
|
|
276
|
+
assert.equal(result.contracts[0].sourceFile, undefined);
|
|
277
|
+
assert.equal(result.contracts[0].sourceSymbol, undefined);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('source block does not affect shape_hash', () => {
|
|
281
|
+
const r1 = extractFromSpecFile('contracts/a.contract.md', SPEC_WITH_SOURCE);
|
|
282
|
+
const r2 = extractFromSpecFile('contracts/b.contract.md', SPEC_WITHOUT_SOURCE);
|
|
283
|
+
assert.equal(r1.contracts[0].shape_hash, r2.contracts[0].shape_hash);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('identical source blocks produce identical shape_hash (deterministic snapshot)', () => {
|
|
287
|
+
const r1 = extractFromSpecFile('contracts/a.contract.md', SPEC_WITH_SOURCE);
|
|
288
|
+
const r2 = extractFromSpecFile('contracts/b.contract.md', SPEC_WITH_SOURCE);
|
|
289
|
+
assert.equal(r1.contracts[0].shape_hash, r2.contracts[0].shape_hash);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
@@ -15,6 +15,10 @@ export interface ExtractionResult {
|
|
|
15
15
|
shape: object;
|
|
16
16
|
shape_hash: string;
|
|
17
17
|
imports: string[];
|
|
18
|
+
/** Path to the TypeScript source file (code-first contracts only). */
|
|
19
|
+
sourceFile?: string;
|
|
20
|
+
/** TypeScript symbol name (code-first contracts only). */
|
|
21
|
+
sourceSymbol?: string;
|
|
18
22
|
}>;
|
|
19
23
|
extractedBy: 'gray-matter' | 'tree-sitter';
|
|
20
24
|
extractedAt: number; // unix ms
|
|
@@ -59,6 +63,10 @@ export function extractFromSpecFile(filePath: string, fileContent: string): Extr
|
|
|
59
63
|
const validation = validateFerretSchema(ferret.shape, filePath);
|
|
60
64
|
validation.warnings.forEach((w) => process.stderr.write(w + '\n'));
|
|
61
65
|
|
|
66
|
+
const source = ferret.source as { file?: unknown; symbol?: unknown } | undefined;
|
|
67
|
+
const sourceFile = typeof source?.file === 'string' ? source.file : undefined;
|
|
68
|
+
const sourceSymbol = typeof source?.symbol === 'string' ? source.symbol : undefined;
|
|
69
|
+
|
|
62
70
|
return {
|
|
63
71
|
filePath,
|
|
64
72
|
fileType: 'spec',
|
|
@@ -69,6 +77,8 @@ export function extractFromSpecFile(filePath: string, fileContent: string): Extr
|
|
|
69
77
|
shape: ferret.shape as object,
|
|
70
78
|
shape_hash: hashSchema(ferret.shape),
|
|
71
79
|
imports: Array.isArray(ferret.imports) ? (ferret.imports as string[]) : [],
|
|
80
|
+
...(sourceFile !== undefined && { sourceFile }),
|
|
81
|
+
...(sourceSymbol !== undefined && { sourceSymbol }),
|
|
72
82
|
},
|
|
73
83
|
],
|
|
74
84
|
extractedBy: 'gray-matter',
|