@nella-labs/core 0.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.
- package/README.md +82 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/run.d.ts +63 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +259 -0
- package/dist/run.js.map +1 -0
- package/dist/safety/index.d.ts +5 -0
- package/dist/safety/index.d.ts.map +1 -0
- package/dist/safety/index.js +21 -0
- package/dist/safety/index.js.map +1 -0
- package/dist/safety/refusal-detector.d.ts +60 -0
- package/dist/safety/refusal-detector.d.ts.map +1 -0
- package/dist/safety/refusal-detector.js +250 -0
- package/dist/safety/refusal-detector.js.map +1 -0
- package/dist/types/agent.d.ts +39 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +8 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/result.d.ts +166 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +8 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/task.d.ts +105 -0
- package/dist/types/task.d.ts.map +1 -0
- package/dist/types/task.js +8 -0
- package/dist/types/task.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +56 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +127 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/workspace.d.ts +45 -0
- package/dist/utils/workspace.d.ts.map +1 -0
- package/dist/utils/workspace.js +199 -0
- package/dist/utils/workspace.js.map +1 -0
- package/dist/validators/command-runner.d.ts +33 -0
- package/dist/validators/command-runner.d.ts.map +1 -0
- package/dist/validators/command-runner.js +135 -0
- package/dist/validators/command-runner.js.map +1 -0
- package/dist/validators/constraint-checker.d.ts +37 -0
- package/dist/validators/constraint-checker.d.ts.map +1 -0
- package/dist/validators/constraint-checker.js +127 -0
- package/dist/validators/constraint-checker.js.map +1 -0
- package/dist/validators/index.d.ts +7 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/index.js +23 -0
- package/dist/validators/index.js.map +1 -0
- package/dist/validators/scope-checker.d.ts +15 -0
- package/dist/validators/scope-checker.d.ts.map +1 -0
- package/dist/validators/scope-checker.js +64 -0
- package/dist/validators/scope-checker.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constraint Checker
|
|
3
|
+
*
|
|
4
|
+
* Validates that changes satisfy declared constraints.
|
|
5
|
+
* Checks forbidden files and forbidden patterns.
|
|
6
|
+
*/
|
|
7
|
+
import { Constraint, ConstraintResult } from "../types";
|
|
8
|
+
/**
|
|
9
|
+
* Check if any modified files violate the "files not to modify" constraint
|
|
10
|
+
*/
|
|
11
|
+
export declare function checkFilesNotToModify(modifiedFiles: string[], constraint: Constraint): ConstraintResult;
|
|
12
|
+
/**
|
|
13
|
+
* Check if diff contains forbidden patterns (regex)
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkForbiddenPatterns(diff: string, constraint: Constraint): ConstraintResult;
|
|
16
|
+
/**
|
|
17
|
+
* Check a single constraint against changes
|
|
18
|
+
*/
|
|
19
|
+
export declare function checkConstraint(modifiedFiles: string[], diff: string, constraint: Constraint): ConstraintResult;
|
|
20
|
+
/**
|
|
21
|
+
* Check all constraints against changes
|
|
22
|
+
*
|
|
23
|
+
* @param modifiedFiles - List of file paths that were modified
|
|
24
|
+
* @param diff - Git diff of all changes
|
|
25
|
+
* @param constraints - Constraints to check
|
|
26
|
+
* @returns Array of constraint check results
|
|
27
|
+
*/
|
|
28
|
+
export declare function checkConstraints(modifiedFiles: string[], diff: string, constraints: Constraint[]): ConstraintResult[];
|
|
29
|
+
/**
|
|
30
|
+
* Get list of violated constraint IDs
|
|
31
|
+
*/
|
|
32
|
+
export declare function getViolatedConstraints(results: ConstraintResult[]): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Count constraint violations
|
|
35
|
+
*/
|
|
36
|
+
export declare function countViolations(results: ConstraintResult[]): number;
|
|
37
|
+
//# sourceMappingURL=constraint-checker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint-checker.d.ts","sourceRoot":"","sources":["../../src/validators/constraint-checker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAgBxD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EAAE,EACvB,UAAU,EAAE,UAAU,GACrB,gBAAgB,CAmBlB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,UAAU,GACrB,gBAAgB,CA6BlB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,EAAE,EACvB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,UAAU,GACrB,gBAAgB,CAqBlB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,MAAM,EAAE,EACvB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,UAAU,EAAE,GACxB,gBAAgB,EAAE,CAIpB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,MAAM,EAAE,CAE5E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAEnE"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Constraint Checker
|
|
4
|
+
*
|
|
5
|
+
* Validates that changes satisfy declared constraints.
|
|
6
|
+
* Checks forbidden files and forbidden patterns.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.checkFilesNotToModify = checkFilesNotToModify;
|
|
10
|
+
exports.checkForbiddenPatterns = checkForbiddenPatterns;
|
|
11
|
+
exports.checkConstraint = checkConstraint;
|
|
12
|
+
exports.checkConstraints = checkConstraints;
|
|
13
|
+
exports.getViolatedConstraints = getViolatedConstraints;
|
|
14
|
+
exports.countViolations = countViolations;
|
|
15
|
+
const minimatch_1 = require("minimatch");
|
|
16
|
+
/**
|
|
17
|
+
* Check if a file path matches a glob pattern
|
|
18
|
+
*/
|
|
19
|
+
function matchesGlob(filePath, pattern) {
|
|
20
|
+
// Normalize paths to forward slashes
|
|
21
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
22
|
+
const normalizedPattern = pattern.replace(/\\/g, "/");
|
|
23
|
+
return (0, minimatch_1.minimatch)(normalizedPath, normalizedPattern, {
|
|
24
|
+
nocase: true,
|
|
25
|
+
dot: true,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if any modified files violate the "files not to modify" constraint
|
|
30
|
+
*/
|
|
31
|
+
function checkFilesNotToModify(modifiedFiles, constraint) {
|
|
32
|
+
const patterns = constraint.filesNotToModify ?? [];
|
|
33
|
+
for (const pattern of patterns) {
|
|
34
|
+
for (const file of modifiedFiles) {
|
|
35
|
+
if (matchesGlob(file, pattern)) {
|
|
36
|
+
return {
|
|
37
|
+
id: constraint.id,
|
|
38
|
+
passed: false,
|
|
39
|
+
violationDetails: `Modified forbidden file: ${file} (matches pattern: ${pattern})`,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
id: constraint.id,
|
|
46
|
+
passed: true,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if diff contains forbidden patterns (regex)
|
|
51
|
+
*/
|
|
52
|
+
function checkForbiddenPatterns(diff, constraint) {
|
|
53
|
+
const patterns = constraint.forbiddenPatterns ?? [];
|
|
54
|
+
for (const pattern of patterns) {
|
|
55
|
+
try {
|
|
56
|
+
const regex = new RegExp(pattern, "gi");
|
|
57
|
+
if (regex.test(diff)) {
|
|
58
|
+
return {
|
|
59
|
+
id: constraint.id,
|
|
60
|
+
passed: false,
|
|
61
|
+
violationDetails: `Diff contains forbidden pattern: ${pattern}`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
// Invalid regex - treat as literal string match
|
|
67
|
+
if (diff.toLowerCase().includes(pattern.toLowerCase())) {
|
|
68
|
+
return {
|
|
69
|
+
id: constraint.id,
|
|
70
|
+
passed: false,
|
|
71
|
+
violationDetails: `Diff contains forbidden pattern: ${pattern}`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
id: constraint.id,
|
|
78
|
+
passed: true,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check a single constraint against changes
|
|
83
|
+
*/
|
|
84
|
+
function checkConstraint(modifiedFiles, diff, constraint) {
|
|
85
|
+
// Check files not to modify
|
|
86
|
+
if (constraint.filesNotToModify && constraint.filesNotToModify.length > 0) {
|
|
87
|
+
const fileResult = checkFilesNotToModify(modifiedFiles, constraint);
|
|
88
|
+
if (!fileResult.passed) {
|
|
89
|
+
return fileResult;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Check forbidden patterns
|
|
93
|
+
if (constraint.forbiddenPatterns && constraint.forbiddenPatterns.length > 0) {
|
|
94
|
+
const patternResult = checkForbiddenPatterns(diff, constraint);
|
|
95
|
+
if (!patternResult.passed) {
|
|
96
|
+
return patternResult;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
id: constraint.id,
|
|
101
|
+
passed: true,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check all constraints against changes
|
|
106
|
+
*
|
|
107
|
+
* @param modifiedFiles - List of file paths that were modified
|
|
108
|
+
* @param diff - Git diff of all changes
|
|
109
|
+
* @param constraints - Constraints to check
|
|
110
|
+
* @returns Array of constraint check results
|
|
111
|
+
*/
|
|
112
|
+
function checkConstraints(modifiedFiles, diff, constraints) {
|
|
113
|
+
return constraints.map((constraint) => checkConstraint(modifiedFiles, diff, constraint));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get list of violated constraint IDs
|
|
117
|
+
*/
|
|
118
|
+
function getViolatedConstraints(results) {
|
|
119
|
+
return results.filter((r) => !r.passed).map((r) => r.id);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Count constraint violations
|
|
123
|
+
*/
|
|
124
|
+
function countViolations(results) {
|
|
125
|
+
return results.filter((r) => !r.passed).length;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=constraint-checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint-checker.js","sourceRoot":"","sources":["../../src/validators/constraint-checker.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAsBH,sDAsBC;AAKD,wDAgCC;AAKD,0CAyBC;AAUD,4CAQC;AAKD,wDAEC;AAKD,0CAEC;AA7ID,yCAAsC;AAGtC;;GAEG;AACH,SAAS,WAAW,CAAC,QAAgB,EAAE,OAAe;IACpD,qCAAqC;IACrC,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACpD,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEtD,OAAO,IAAA,qBAAS,EAAC,c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;;GAEG;AACH,SAAgB,sBAAsB,CAAC,OAA2B;IAChE,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,OAA2B;IACzD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validators - Re-exports
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./constraint-checker"), exports);
|
|
21
|
+
__exportStar(require("./scope-checker"), exports);
|
|
22
|
+
__exportStar(require("./command-runner"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,uDAAqC;AACrC,kDAAgC;AAChC,mDAAiC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope Checker
|
|
3
|
+
*
|
|
4
|
+
* Detects scope creep - files modified outside expected scope.
|
|
5
|
+
*/
|
|
6
|
+
import { ExpectedChanges, ScopeResult } from "../types";
|
|
7
|
+
/**
|
|
8
|
+
* Check for scope creep in modified files
|
|
9
|
+
*
|
|
10
|
+
* @param modifiedFiles - Files that were actually modified
|
|
11
|
+
* @param expected - Expected changes from task definition
|
|
12
|
+
* @returns Scope analysis result
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkScope(modifiedFiles: string[], expected: ExpectedChanges): ScopeResult;
|
|
15
|
+
//# sourceMappingURL=scope-checker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-checker.d.ts","sourceRoot":"","sources":["../../src/validators/scope-checker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAmBxD;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,EAAE,eAAe,GACxB,WAAW,CAyCb"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Scope Checker
|
|
4
|
+
*
|
|
5
|
+
* Detects scope creep - files modified outside expected scope.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.checkScope = checkScope;
|
|
9
|
+
const minimatch_1 = require("minimatch");
|
|
10
|
+
/**
|
|
11
|
+
* Normalize file path for comparison
|
|
12
|
+
*/
|
|
13
|
+
function normalizePath(filePath) {
|
|
14
|
+
return filePath.replace(/\\/g, "/");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check if a file matches any pattern in a list
|
|
18
|
+
*/
|
|
19
|
+
function matchesAnyPattern(file, patterns) {
|
|
20
|
+
const normalizedFile = normalizePath(file);
|
|
21
|
+
return patterns.some((pattern) => (0, minimatch_1.minimatch)(normalizedFile, normalizePath(pattern), { nocase: true, dot: true }));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check for scope creep in modified files
|
|
25
|
+
*
|
|
26
|
+
* @param modifiedFiles - Files that were actually modified
|
|
27
|
+
* @param expected - Expected changes from task definition
|
|
28
|
+
* @returns Scope analysis result
|
|
29
|
+
*/
|
|
30
|
+
function checkScope(modifiedFiles, expected) {
|
|
31
|
+
const expectedFiles = expected.filesToModify ?? [];
|
|
32
|
+
const filesToIgnore = expected.filesToIgnore ?? [];
|
|
33
|
+
// Normalize all paths
|
|
34
|
+
const normalizedModified = modifiedFiles.map(normalizePath);
|
|
35
|
+
const normalizedExpected = expectedFiles.map(normalizePath);
|
|
36
|
+
// Find extra files (modified but not expected and not in ignore list)
|
|
37
|
+
const extraFiles = normalizedModified.filter((file) => {
|
|
38
|
+
// Skip if in ignore list
|
|
39
|
+
if (matchesAnyPattern(file, filesToIgnore)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
// Check if it matches any expected pattern
|
|
43
|
+
return !matchesAnyPattern(file, normalizedExpected);
|
|
44
|
+
});
|
|
45
|
+
// Find missing files (expected but not modified)
|
|
46
|
+
const missingFiles = normalizedExpected.filter((expected) => {
|
|
47
|
+
return !normalizedModified.some((file) => (0, minimatch_1.minimatch)(file, expected, { nocase: true, dot: true }));
|
|
48
|
+
});
|
|
49
|
+
// Calculate scope creep ratio
|
|
50
|
+
// 0 = no scope creep, higher = more creep
|
|
51
|
+
const scopeCreepRatio = expectedFiles.length > 0
|
|
52
|
+
? extraFiles.length / expectedFiles.length
|
|
53
|
+
: extraFiles.length > 0
|
|
54
|
+
? 1
|
|
55
|
+
: 0;
|
|
56
|
+
return {
|
|
57
|
+
expectedFiles: normalizedExpected,
|
|
58
|
+
actualFiles: normalizedModified,
|
|
59
|
+
extraFiles,
|
|
60
|
+
missingFiles,
|
|
61
|
+
scopeCreepRatio,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=scope-checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-checker.js","sourceRoot":"","sources":["../../src/validators/scope-checker.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA6BH,gCA4CC;AAvED,yCAAsC;AAGtC;;GAEG;AACH,SAAS,aAAa,CAAC,QAAgB;IACrC,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB,CAAC,IAAY,EAAE,QAAkB;IACzD,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAC/B,IAAA,qBAAS,EAAC,cAAc,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAC/E,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,UAAU,CACxB,aAAuB,EACvB,QAAyB;IAEzB,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,IAAI,EAAE,CAAC;IACnD,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,IAAI,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/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reliability layer for coding agents - enforces constraints, validates changes, detects when to refuse",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "echo \"No tests yet\"",
|
|
20
|
+
"dev": "tsc --watch",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"coding-agent",
|
|
25
|
+
"ai",
|
|
26
|
+
"reliability",
|
|
27
|
+
"constraints",
|
|
28
|
+
"validation",
|
|
29
|
+
"safety"
|
|
30
|
+
],
|
|
31
|
+
"author": "Nella Labs",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/nella-labs/nella.git",
|
|
36
|
+
"directory": "packages/core"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"minimatch": "^9.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^20.0.0",
|
|
46
|
+
"typescript": "^5.3.0"
|
|
47
|
+
}
|
|
48
|
+
}
|