@viberails/context 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/LICENSE +21 -0
- package/dist/index.cjs +107 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alex Casasola
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
generateContext: () => generateContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/generate-context.ts
|
|
28
|
+
var NAMING_EXAMPLES = {
|
|
29
|
+
"kebab-case": "`user-profile.ts`, not `UserProfile.ts`",
|
|
30
|
+
camelCase: "`userProfile.ts`, not `user-profile.ts`",
|
|
31
|
+
PascalCase: "`UserProfile.ts`, not `user-profile.ts`",
|
|
32
|
+
snake_case: "`user_profile.ts`, not `UserProfile.ts`"
|
|
33
|
+
};
|
|
34
|
+
function conventionValue(cv) {
|
|
35
|
+
return typeof cv === "string" ? cv : cv.value;
|
|
36
|
+
}
|
|
37
|
+
function formatEnforcedRules(config) {
|
|
38
|
+
const { rules, conventions, structure } = config;
|
|
39
|
+
const lines = [];
|
|
40
|
+
if (rules.maxFileLines > 0) {
|
|
41
|
+
lines.push(
|
|
42
|
+
`- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (rules.maxFunctionLines > 0) {
|
|
46
|
+
lines.push(
|
|
47
|
+
`- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (rules.enforceNaming && conventions.fileNaming) {
|
|
51
|
+
const val = conventionValue(conventions.fileNaming);
|
|
52
|
+
const examples = NAMING_EXAMPLES[val] ?? `e.g. \`my-module.ts\``;
|
|
53
|
+
lines.push(`- Source files use **${val}**: ${examples}.`);
|
|
54
|
+
}
|
|
55
|
+
if (rules.requireTests && structure.testPattern) {
|
|
56
|
+
const srcDir = structure.srcDir ?? "src";
|
|
57
|
+
lines.push(
|
|
58
|
+
`- Every source file in \`${srcDir}/\` must have a corresponding \`${structure.testPattern}\` file.`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return lines;
|
|
62
|
+
}
|
|
63
|
+
function generateContext(config) {
|
|
64
|
+
const sections = [];
|
|
65
|
+
sections.push("# viberails enforced rules\n");
|
|
66
|
+
if (config.enforcement === "enforce") {
|
|
67
|
+
sections.push("Commits will be rejected if these rules are violated:\n");
|
|
68
|
+
} else {
|
|
69
|
+
sections.push(
|
|
70
|
+
"These rules are checked before commits. Violations will be **warned** but not blocked:\n"
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
const ruleLines = formatEnforcedRules(config);
|
|
74
|
+
if (ruleLines.length > 0) {
|
|
75
|
+
sections.push(ruleLines.join("\n"));
|
|
76
|
+
} else {
|
|
77
|
+
sections.push("_(No rules configured. Edit `viberails.config.json` to add rules.)_");
|
|
78
|
+
}
|
|
79
|
+
const boundaryLines = formatBoundaryRules(config);
|
|
80
|
+
if (boundaryLines.length > 0) {
|
|
81
|
+
sections.push("");
|
|
82
|
+
sections.push(boundaryLines.join("\n"));
|
|
83
|
+
}
|
|
84
|
+
sections.push("");
|
|
85
|
+
sections.push("Run `viberails check` before committing to catch violations early.\n");
|
|
86
|
+
return sections.join("\n");
|
|
87
|
+
}
|
|
88
|
+
function formatBoundaryRules(config) {
|
|
89
|
+
if (!config.rules.enforceBoundaries || !config.boundaries || config.boundaries.length === 0) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const denyRules = config.boundaries.filter((r) => !r.allow);
|
|
93
|
+
if (denyRules.length === 0) return [];
|
|
94
|
+
const lines = [];
|
|
95
|
+
lines.push("## Boundary rules\n");
|
|
96
|
+
lines.push("These import boundaries are enforced:\n");
|
|
97
|
+
for (const rule of denyRules) {
|
|
98
|
+
const reason = rule.reason ? ` (${rule.reason})` : "";
|
|
99
|
+
lines.push(`- \`${rule.from}\` must NOT import from \`${rule.to}\`${reason}`);
|
|
100
|
+
}
|
|
101
|
+
return lines;
|
|
102
|
+
}
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
generateContext
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/generate-context.ts"],"sourcesContent":["export { generateContext } from './generate-context.js';\n","import type { ConventionValue, ViberailsConfig } from '@viberails/types';\n\n/** Naming convention examples for directive formatting. */\nconst NAMING_EXAMPLES: Record<string, string> = {\n 'kebab-case': '`user-profile.ts`, not `UserProfile.ts`',\n camelCase: '`userProfile.ts`, not `user-profile.ts`',\n PascalCase: '`UserProfile.ts`, not `user-profile.ts`',\n snake_case: '`user_profile.ts`, not `UserProfile.ts`',\n};\n\n/**\n * Extract the effective value from a ConventionValue (string or object).\n */\nfunction conventionValue(cv: ConventionValue): string {\n return typeof cv === 'string' ? cv : cv.value;\n}\n\n/**\n * Build the list of enforced rules as markdown bullet points.\n */\nfunction formatEnforcedRules(config: ViberailsConfig): string[] {\n const { rules, conventions, structure } = config;\n const lines: string[] = [];\n\n if (rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n\n if (rules.enforceNaming && conventions.fileNaming) {\n const val = conventionValue(conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (rules.requireTests && structure.testPattern) {\n const srcDir = structure.srcDir ?? 'src';\n lines.push(\n `- Every source file in \\`${srcDir}/\\` must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n }\n\n return lines;\n}\n\n/**\n * Generate a rules-focused context document from a ViberailsConfig.\n *\n * The output tells AI agents what rules are enforced and that commits\n * will fail if they are violated. It does not describe the project's\n * stack, structure, or architecture — that is trivially discoverable.\n *\n * @param config - The viberails configuration\n * @returns Markdown string for `.viberails/context.md`\n */\nexport function generateContext(config: ViberailsConfig): string {\n const sections: string[] = [];\n\n sections.push('# viberails enforced rules\\n');\n\n if (config.enforcement === 'enforce') {\n sections.push('Commits will be rejected if these rules are violated:\\n');\n } else {\n sections.push(\n 'These rules are checked before commits. Violations will be **warned** but not blocked:\\n',\n );\n }\n\n const ruleLines = formatEnforcedRules(config);\n if (ruleLines.length > 0) {\n sections.push(ruleLines.join('\\n'));\n } else {\n sections.push('_(No rules configured. Edit `viberails.config.json` to add rules.)_');\n }\n\n const boundaryLines = formatBoundaryRules(config);\n if (boundaryLines.length > 0) {\n sections.push('');\n sections.push(boundaryLines.join('\\n'));\n }\n\n sections.push('');\n sections.push('Run `viberails check` before committing to catch violations early.\\n');\n\n return sections.join('\\n');\n}\n\n/**\n * Build the boundary rules section as markdown lines.\n * Only includes deny rules (allow: false).\n */\nfunction formatBoundaryRules(config: ViberailsConfig): string[] {\n if (!config.rules.enforceBoundaries || !config.boundaries || config.boundaries.length === 0) {\n return [];\n }\n\n const denyRules = config.boundaries.filter((r) => !r.allow);\n if (denyRules.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Boundary rules\\n');\n lines.push('These import boundaries are enforced:\\n');\n\n for (const rule of denyRules) {\n const reason = rule.reason ? ` (${rule.reason})` : '';\n lines.push(`- \\`${rule.from}\\` must NOT import from \\`${rule.to}\\`${reason}`);\n }\n\n return lines;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,IAAM,kBAA0C;AAAA,EAC9C,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AACd;AAKA,SAAS,gBAAgB,IAA6B;AACpD,SAAO,OAAO,OAAO,WAAW,KAAK,GAAG;AAC1C;AAKA,SAAS,oBAAoB,QAAmC;AAC9D,QAAM,EAAE,OAAO,aAAa,UAAU,IAAI;AAC1C,QAAM,QAAkB,CAAC;AAEzB,MAAI,MAAM,eAAe,GAAG;AAC1B,UAAM;AAAA,MACJ,6BAA6B,MAAM,YAAY;AAAA,IACjD;AAAA,EACF;AAEA,MAAI,MAAM,mBAAmB,GAAG;AAC9B,UAAM;AAAA,MACJ,iCAAiC,MAAM,gBAAgB;AAAA,IACzD;AAAA,EACF;AAEA,MAAI,MAAM,iBAAiB,YAAY,YAAY;AACjD,UAAM,MAAM,gBAAgB,YAAY,UAAU;AAClD,UAAM,WAAW,gBAAgB,GAAG,KAAK;AACzC,UAAM,KAAK,wBAAwB,GAAG,OAAO,QAAQ,GAAG;AAAA,EAC1D;AAEA,MAAI,MAAM,gBAAgB,UAAU,aAAa;AAC/C,UAAM,SAAS,UAAU,UAAU;AACnC,UAAM;AAAA,MACJ,4BAA4B,MAAM,mCAAmC,UAAU,WAAW;AAAA,IAC5F;AAAA,EACF;AAEA,SAAO;AACT;AAYO,SAAS,gBAAgB,QAAiC;AAC/D,QAAM,WAAqB,CAAC;AAE5B,WAAS,KAAK,8BAA8B;AAE5C,MAAI,OAAO,gBAAgB,WAAW;AACpC,aAAS,KAAK,yDAAyD;AAAA,EACzE,OAAO;AACL,aAAS;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,oBAAoB,MAAM;AAC5C,MAAI,UAAU,SAAS,GAAG;AACxB,aAAS,KAAK,UAAU,KAAK,IAAI,CAAC;AAAA,EACpC,OAAO;AACL,aAAS,KAAK,qEAAqE;AAAA,EACrF;AAEA,QAAM,gBAAgB,oBAAoB,MAAM;AAChD,MAAI,cAAc,SAAS,GAAG;AAC5B,aAAS,KAAK,EAAE;AAChB,aAAS,KAAK,cAAc,KAAK,IAAI,CAAC;AAAA,EACxC;AAEA,WAAS,KAAK,EAAE;AAChB,WAAS,KAAK,sEAAsE;AAEpF,SAAO,SAAS,KAAK,IAAI;AAC3B;AAMA,SAAS,oBAAoB,QAAmC;AAC9D,MAAI,CAAC,OAAO,MAAM,qBAAqB,CAAC,OAAO,cAAc,OAAO,WAAW,WAAW,GAAG;AAC3F,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,YAAY,OAAO,WAAW,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK;AAC1D,MAAI,UAAU,WAAW,EAAG,QAAO,CAAC;AAEpC,QAAM,QAAkB,CAAC;AACzB,QAAM,KAAK,qBAAqB;AAChC,QAAM,KAAK,yCAAyC;AAEpD,aAAW,QAAQ,WAAW;AAC5B,UAAM,SAAS,KAAK,SAAS,KAAK,KAAK,MAAM,MAAM;AACnD,UAAM,KAAK,OAAO,KAAK,IAAI,6BAA6B,KAAK,EAAE,KAAK,MAAM,EAAE;AAAA,EAC9E;AAEA,SAAO;AACT;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ViberailsConfig } from '@viberails/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate a rules-focused context document from a ViberailsConfig.
|
|
5
|
+
*
|
|
6
|
+
* The output tells AI agents what rules are enforced and that commits
|
|
7
|
+
* will fail if they are violated. It does not describe the project's
|
|
8
|
+
* stack, structure, or architecture — that is trivially discoverable.
|
|
9
|
+
*
|
|
10
|
+
* @param config - The viberails configuration
|
|
11
|
+
* @returns Markdown string for `.viberails/context.md`
|
|
12
|
+
*/
|
|
13
|
+
declare function generateContext(config: ViberailsConfig): string;
|
|
14
|
+
|
|
15
|
+
export { generateContext };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ViberailsConfig } from '@viberails/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate a rules-focused context document from a ViberailsConfig.
|
|
5
|
+
*
|
|
6
|
+
* The output tells AI agents what rules are enforced and that commits
|
|
7
|
+
* will fail if they are violated. It does not describe the project's
|
|
8
|
+
* stack, structure, or architecture — that is trivially discoverable.
|
|
9
|
+
*
|
|
10
|
+
* @param config - The viberails configuration
|
|
11
|
+
* @returns Markdown string for `.viberails/context.md`
|
|
12
|
+
*/
|
|
13
|
+
declare function generateContext(config: ViberailsConfig): string;
|
|
14
|
+
|
|
15
|
+
export { generateContext };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/generate-context.ts
|
|
2
|
+
var NAMING_EXAMPLES = {
|
|
3
|
+
"kebab-case": "`user-profile.ts`, not `UserProfile.ts`",
|
|
4
|
+
camelCase: "`userProfile.ts`, not `user-profile.ts`",
|
|
5
|
+
PascalCase: "`UserProfile.ts`, not `user-profile.ts`",
|
|
6
|
+
snake_case: "`user_profile.ts`, not `UserProfile.ts`"
|
|
7
|
+
};
|
|
8
|
+
function conventionValue(cv) {
|
|
9
|
+
return typeof cv === "string" ? cv : cv.value;
|
|
10
|
+
}
|
|
11
|
+
function formatEnforcedRules(config) {
|
|
12
|
+
const { rules, conventions, structure } = config;
|
|
13
|
+
const lines = [];
|
|
14
|
+
if (rules.maxFileLines > 0) {
|
|
15
|
+
lines.push(
|
|
16
|
+
`- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
if (rules.maxFunctionLines > 0) {
|
|
20
|
+
lines.push(
|
|
21
|
+
`- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
if (rules.enforceNaming && conventions.fileNaming) {
|
|
25
|
+
const val = conventionValue(conventions.fileNaming);
|
|
26
|
+
const examples = NAMING_EXAMPLES[val] ?? `e.g. \`my-module.ts\``;
|
|
27
|
+
lines.push(`- Source files use **${val}**: ${examples}.`);
|
|
28
|
+
}
|
|
29
|
+
if (rules.requireTests && structure.testPattern) {
|
|
30
|
+
const srcDir = structure.srcDir ?? "src";
|
|
31
|
+
lines.push(
|
|
32
|
+
`- Every source file in \`${srcDir}/\` must have a corresponding \`${structure.testPattern}\` file.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return lines;
|
|
36
|
+
}
|
|
37
|
+
function generateContext(config) {
|
|
38
|
+
const sections = [];
|
|
39
|
+
sections.push("# viberails enforced rules\n");
|
|
40
|
+
if (config.enforcement === "enforce") {
|
|
41
|
+
sections.push("Commits will be rejected if these rules are violated:\n");
|
|
42
|
+
} else {
|
|
43
|
+
sections.push(
|
|
44
|
+
"These rules are checked before commits. Violations will be **warned** but not blocked:\n"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const ruleLines = formatEnforcedRules(config);
|
|
48
|
+
if (ruleLines.length > 0) {
|
|
49
|
+
sections.push(ruleLines.join("\n"));
|
|
50
|
+
} else {
|
|
51
|
+
sections.push("_(No rules configured. Edit `viberails.config.json` to add rules.)_");
|
|
52
|
+
}
|
|
53
|
+
const boundaryLines = formatBoundaryRules(config);
|
|
54
|
+
if (boundaryLines.length > 0) {
|
|
55
|
+
sections.push("");
|
|
56
|
+
sections.push(boundaryLines.join("\n"));
|
|
57
|
+
}
|
|
58
|
+
sections.push("");
|
|
59
|
+
sections.push("Run `viberails check` before committing to catch violations early.\n");
|
|
60
|
+
return sections.join("\n");
|
|
61
|
+
}
|
|
62
|
+
function formatBoundaryRules(config) {
|
|
63
|
+
if (!config.rules.enforceBoundaries || !config.boundaries || config.boundaries.length === 0) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
const denyRules = config.boundaries.filter((r) => !r.allow);
|
|
67
|
+
if (denyRules.length === 0) return [];
|
|
68
|
+
const lines = [];
|
|
69
|
+
lines.push("## Boundary rules\n");
|
|
70
|
+
lines.push("These import boundaries are enforced:\n");
|
|
71
|
+
for (const rule of denyRules) {
|
|
72
|
+
const reason = rule.reason ? ` (${rule.reason})` : "";
|
|
73
|
+
lines.push(`- \`${rule.from}\` must NOT import from \`${rule.to}\`${reason}`);
|
|
74
|
+
}
|
|
75
|
+
return lines;
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
generateContext
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generate-context.ts"],"sourcesContent":["import type { ConventionValue, ViberailsConfig } from '@viberails/types';\n\n/** Naming convention examples for directive formatting. */\nconst NAMING_EXAMPLES: Record<string, string> = {\n 'kebab-case': '`user-profile.ts`, not `UserProfile.ts`',\n camelCase: '`userProfile.ts`, not `user-profile.ts`',\n PascalCase: '`UserProfile.ts`, not `user-profile.ts`',\n snake_case: '`user_profile.ts`, not `UserProfile.ts`',\n};\n\n/**\n * Extract the effective value from a ConventionValue (string or object).\n */\nfunction conventionValue(cv: ConventionValue): string {\n return typeof cv === 'string' ? cv : cv.value;\n}\n\n/**\n * Build the list of enforced rules as markdown bullet points.\n */\nfunction formatEnforcedRules(config: ViberailsConfig): string[] {\n const { rules, conventions, structure } = config;\n const lines: string[] = [];\n\n if (rules.maxFileLines > 0) {\n lines.push(\n `- Files must not exceed **${rules.maxFileLines} lines**. Split into focused modules.`,\n );\n }\n\n if (rules.maxFunctionLines > 0) {\n lines.push(\n `- Functions must not exceed **${rules.maxFunctionLines} lines**. Extract helpers for complex logic.`,\n );\n }\n\n if (rules.enforceNaming && conventions.fileNaming) {\n const val = conventionValue(conventions.fileNaming);\n const examples = NAMING_EXAMPLES[val] ?? `e.g. \\`my-module.ts\\``;\n lines.push(`- Source files use **${val}**: ${examples}.`);\n }\n\n if (rules.requireTests && structure.testPattern) {\n const srcDir = structure.srcDir ?? 'src';\n lines.push(\n `- Every source file in \\`${srcDir}/\\` must have a corresponding \\`${structure.testPattern}\\` file.`,\n );\n }\n\n return lines;\n}\n\n/**\n * Generate a rules-focused context document from a ViberailsConfig.\n *\n * The output tells AI agents what rules are enforced and that commits\n * will fail if they are violated. It does not describe the project's\n * stack, structure, or architecture — that is trivially discoverable.\n *\n * @param config - The viberails configuration\n * @returns Markdown string for `.viberails/context.md`\n */\nexport function generateContext(config: ViberailsConfig): string {\n const sections: string[] = [];\n\n sections.push('# viberails enforced rules\\n');\n\n if (config.enforcement === 'enforce') {\n sections.push('Commits will be rejected if these rules are violated:\\n');\n } else {\n sections.push(\n 'These rules are checked before commits. Violations will be **warned** but not blocked:\\n',\n );\n }\n\n const ruleLines = formatEnforcedRules(config);\n if (ruleLines.length > 0) {\n sections.push(ruleLines.join('\\n'));\n } else {\n sections.push('_(No rules configured. Edit `viberails.config.json` to add rules.)_');\n }\n\n const boundaryLines = formatBoundaryRules(config);\n if (boundaryLines.length > 0) {\n sections.push('');\n sections.push(boundaryLines.join('\\n'));\n }\n\n sections.push('');\n sections.push('Run `viberails check` before committing to catch violations early.\\n');\n\n return sections.join('\\n');\n}\n\n/**\n * Build the boundary rules section as markdown lines.\n * Only includes deny rules (allow: false).\n */\nfunction formatBoundaryRules(config: ViberailsConfig): string[] {\n if (!config.rules.enforceBoundaries || !config.boundaries || config.boundaries.length === 0) {\n return [];\n }\n\n const denyRules = config.boundaries.filter((r) => !r.allow);\n if (denyRules.length === 0) return [];\n\n const lines: string[] = [];\n lines.push('## Boundary rules\\n');\n lines.push('These import boundaries are enforced:\\n');\n\n for (const rule of denyRules) {\n const reason = rule.reason ? ` (${rule.reason})` : '';\n lines.push(`- \\`${rule.from}\\` must NOT import from \\`${rule.to}\\`${reason}`);\n }\n\n return lines;\n}\n"],"mappings":";AAGA,IAAM,kBAA0C;AAAA,EAC9C,cAAc;AAAA,EACd,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AACd;AAKA,SAAS,gBAAgB,IAA6B;AACpD,SAAO,OAAO,OAAO,WAAW,KAAK,GAAG;AAC1C;AAKA,SAAS,oBAAoB,QAAmC;AAC9D,QAAM,EAAE,OAAO,aAAa,UAAU,IAAI;AAC1C,QAAM,QAAkB,CAAC;AAEzB,MAAI,MAAM,eAAe,GAAG;AAC1B,UAAM;AAAA,MACJ,6BAA6B,MAAM,YAAY;AAAA,IACjD;AAAA,EACF;AAEA,MAAI,MAAM,mBAAmB,GAAG;AAC9B,UAAM;AAAA,MACJ,iCAAiC,MAAM,gBAAgB;AAAA,IACzD;AAAA,EACF;AAEA,MAAI,MAAM,iBAAiB,YAAY,YAAY;AACjD,UAAM,MAAM,gBAAgB,YAAY,UAAU;AAClD,UAAM,WAAW,gBAAgB,GAAG,KAAK;AACzC,UAAM,KAAK,wBAAwB,GAAG,OAAO,QAAQ,GAAG;AAAA,EAC1D;AAEA,MAAI,MAAM,gBAAgB,UAAU,aAAa;AAC/C,UAAM,SAAS,UAAU,UAAU;AACnC,UAAM;AAAA,MACJ,4BAA4B,MAAM,mCAAmC,UAAU,WAAW;AAAA,IAC5F;AAAA,EACF;AAEA,SAAO;AACT;AAYO,SAAS,gBAAgB,QAAiC;AAC/D,QAAM,WAAqB,CAAC;AAE5B,WAAS,KAAK,8BAA8B;AAE5C,MAAI,OAAO,gBAAgB,WAAW;AACpC,aAAS,KAAK,yDAAyD;AAAA,EACzE,OAAO;AACL,aAAS;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,oBAAoB,MAAM;AAC5C,MAAI,UAAU,SAAS,GAAG;AACxB,aAAS,KAAK,UAAU,KAAK,IAAI,CAAC;AAAA,EACpC,OAAO;AACL,aAAS,KAAK,qEAAqE;AAAA,EACrF;AAEA,QAAM,gBAAgB,oBAAoB,MAAM;AAChD,MAAI,cAAc,SAAS,GAAG;AAC5B,aAAS,KAAK,EAAE;AAChB,aAAS,KAAK,cAAc,KAAK,IAAI,CAAC;AAAA,EACxC;AAEA,WAAS,KAAK,EAAE;AAChB,WAAS,KAAK,sEAAsE;AAEpF,SAAO,SAAS,KAAK,IAAI;AAC3B;AAMA,SAAS,oBAAoB,QAAmC;AAC9D,MAAI,CAAC,OAAO,MAAM,qBAAqB,CAAC,OAAO,cAAc,OAAO,WAAW,WAAW,GAAG;AAC3F,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,YAAY,OAAO,WAAW,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK;AAC1D,MAAI,UAAU,WAAW,EAAG,QAAO,CAAC;AAEpC,QAAM,QAAkB,CAAC;AACzB,QAAM,KAAK,qBAAqB;AAChC,QAAM,KAAK,yCAAyC;AAEpD,aAAW,QAAQ,WAAW;AAC5B,UAAM,SAAS,KAAK,SAAS,KAAK,KAAK,MAAM,MAAM;AACnD,UAAM,KAAK,OAAO,KAAK,IAAI,6BAA6B,KAAK,EAAE,KAAK,MAAM,EAAE;AAAA,EAC9E;AAEA,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@viberails/context",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AI context file generation for viberails",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@viberails/types": "0.1.0",
|
|
29
|
+
"@viberails/config": "0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"lint": "biome check src/",
|
|
35
|
+
"clean": "rm -rf dist"
|
|
36
|
+
}
|
|
37
|
+
}
|