@codsy/cli 0.0.0-stage → 1.0.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 +201 -0
- package/README.md +227 -2
- package/dist/check-screen-OZJD7UHU.js +80 -0
- package/dist/chunk-46NW6PYM.js +115 -0
- package/dist/chunk-52CMOWJF.js +59 -0
- package/dist/chunk-6AVERKMZ.js +17 -0
- package/dist/chunk-BJYMGFW2.js +14 -0
- package/dist/chunk-FVNSMO6G.js +313 -0
- package/dist/chunk-JVEULAOD.js +24 -0
- package/dist/chunk-KFHC377Y.js +21 -0
- package/dist/chunk-MOIYJ6UU.js +48 -0
- package/dist/chunk-TDOJ55BG.js +120 -0
- package/dist/chunk-UWXPACZ7.js +54 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.js +2032 -0
- package/dist/home-screen-UIUS4UOT.js +206 -0
- package/dist/init-wizard-MXAFTYCQ.js +54 -0
- package/dist/new-schema-wizard-NYIHF47J.js +123 -0
- package/dist/new-skill-wizard-AZJ5DLDM.js +121 -0
- package/package.json +66 -4
- package/templates/blank/.github/PULL_REQUEST_TEMPLATE.md +7 -0
- package/templates/blank/.github/workflows/codsy.yml +33 -0
- package/templates/blank/AGENTS.md +8 -0
- package/templates/blank/CODEOWNERS +4 -0
- package/templates/blank/README.md +12 -0
- package/templates/blank/codsy.config.yaml +1 -0
- package/templates/blank/context/company.md +4 -0
- package/templates/blank/context/customers.md +4 -0
- package/templates/blank/context/industry.md +4 -0
- package/templates/blank/context/operations.md +4 -0
- package/templates/blank/context/products.md +4 -0
- package/templates/blank/context/strategy.md +4 -0
- package/templates/blank/evals/.gitkeep +0 -0
- package/templates/blank/schemas/.gitkeep +0 -0
- package/templates/blank/skills/.gitkeep +0 -0
- package/templates/finance/.github/PULL_REQUEST_TEMPLATE.md +8 -0
- package/templates/finance/.github/workflows/codsy.yml +33 -0
- package/templates/finance/AGENTS.md +14 -0
- package/templates/finance/CODEOWNERS +4 -0
- package/templates/finance/README.md +16 -0
- package/templates/finance/codsy.config.yaml +1 -0
- package/templates/finance/context/company.md +6 -0
- package/templates/finance/context/customers.md +5 -0
- package/templates/finance/context/industry.md +5 -0
- package/templates/finance/context/operations.md +6 -0
- package/templates/finance/context/products.md +4 -0
- package/templates/finance/context/strategy.md +4 -0
- package/templates/finance/evals/collections-classification/cases.yaml +81 -0
- package/templates/finance/schemas/account.schema.json +21 -0
- package/templates/finance/skills/collections-classification/SKILL.md +49 -0
- package/templates/sales/.github/PULL_REQUEST_TEMPLATE.md +7 -0
- package/templates/sales/.github/workflows/codsy.yml +33 -0
- package/templates/sales/AGENTS.md +11 -0
- package/templates/sales/CODEOWNERS +4 -0
- package/templates/sales/README.md +13 -0
- package/templates/sales/codsy.config.yaml +1 -0
- package/templates/sales/context/company.md +6 -0
- package/templates/sales/context/customers.md +5 -0
- package/templates/sales/context/industry.md +5 -0
- package/templates/sales/context/operations.md +5 -0
- package/templates/sales/context/products.md +4 -0
- package/templates/sales/context/strategy.md +4 -0
- package/templates/sales/evals/lead-qualification/cases.yaml +87 -0
- package/templates/sales/schemas/lead.schema.json +26 -0
- package/templates/sales/skills/lead-qualification/SKILL.md +46 -0
- package/templates/support/.github/PULL_REQUEST_TEMPLATE.md +7 -0
- package/templates/support/.github/workflows/codsy.yml +33 -0
- package/templates/support/AGENTS.md +11 -0
- package/templates/support/CODEOWNERS +4 -0
- package/templates/support/README.md +13 -0
- package/templates/support/codsy.config.yaml +1 -0
- package/templates/support/context/company.md +5 -0
- package/templates/support/context/customers.md +5 -0
- package/templates/support/context/industry.md +5 -0
- package/templates/support/context/operations.md +5 -0
- package/templates/support/context/products.md +4 -0
- package/templates/support/context/strategy.md +4 -0
- package/templates/support/evals/ticket-triage/cases.yaml +81 -0
- package/templates/support/schemas/ticket.schema.json +22 -0
- package/templates/support/skills/ticket-triage/SKILL.md +46 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
THEME
|
|
3
|
+
} from "./chunk-BJYMGFW2.js";
|
|
4
|
+
|
|
5
|
+
// src/ui/components/KeyHintFooter.tsx
|
|
6
|
+
import { Text } from "ink";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
var DEFAULT_KEY_HINTS = "\u2191\u2193/jk move \xB7 enter select \xB7 esc back \xB7 ? help";
|
|
9
|
+
function KeyHintFooter({ hints = DEFAULT_KEY_HINTS }) {
|
|
10
|
+
return /* @__PURE__ */ jsx(Text, { color: THEME.dim, children: hints });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
DEFAULT_KEY_HINTS,
|
|
15
|
+
KeyHintFooter
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=chunk-6AVERKMZ.js.map
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// src/cli/home.ts
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { join as join3 } from "path";
|
|
4
|
+
|
|
5
|
+
// src/core/project-loader.ts
|
|
6
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
7
|
+
import { join as join2, relative } from "path";
|
|
8
|
+
import { load as loadYaml2 } from "js-yaml";
|
|
9
|
+
|
|
10
|
+
// src/core/fs-helpers.ts
|
|
11
|
+
import { readFile, readdir } from "fs/promises";
|
|
12
|
+
import { join } from "path";
|
|
13
|
+
async function readFileIfExists(filePath) {
|
|
14
|
+
try {
|
|
15
|
+
return await readFile(filePath, "utf8");
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (isNotFoundError(error)) return null;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function listDirectoryNames(dirPath) {
|
|
22
|
+
return listEntries(dirPath, (entry) => entry.isDirectory());
|
|
23
|
+
}
|
|
24
|
+
async function listFileNames(dirPath) {
|
|
25
|
+
return listEntries(dirPath, (entry) => entry.isFile());
|
|
26
|
+
}
|
|
27
|
+
async function listFilesRecursively(dirPath) {
|
|
28
|
+
const result = [];
|
|
29
|
+
async function walk(currentDir, prefix) {
|
|
30
|
+
let entries;
|
|
31
|
+
try {
|
|
32
|
+
entries = await readdir(currentDir, { withFileTypes: true });
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (isNotFoundError(error)) return;
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
39
|
+
if (entry.isDirectory()) {
|
|
40
|
+
await walk(join(currentDir, entry.name), relativePath);
|
|
41
|
+
} else if (entry.isFile()) {
|
|
42
|
+
result.push(relativePath);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
await walk(dirPath, "");
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
async function listEntries(dirPath, predicate) {
|
|
50
|
+
try {
|
|
51
|
+
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
52
|
+
return entries.filter(predicate).map((entry) => entry.name);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (isNotFoundError(error)) return [];
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function isNotFoundError(error) {
|
|
59
|
+
return error instanceof Error && error.code === "ENOENT";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/core/skill-parser.ts
|
|
63
|
+
import { load as loadYaml } from "js-yaml";
|
|
64
|
+
|
|
65
|
+
// src/core/type-guards.ts
|
|
66
|
+
function isRecord(value) {
|
|
67
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/core/skill-parser.ts
|
|
71
|
+
var FRONTMATTER_FENCE = "---";
|
|
72
|
+
var HEADING_PATTERN = /^(#{1,6})\s+(.+?)\s*$/;
|
|
73
|
+
function parseSkillMarkdown(raw) {
|
|
74
|
+
const lines = raw.split("\n");
|
|
75
|
+
const { frontmatter, frontmatterError, bodyStartLine } = extractFrontmatter(lines);
|
|
76
|
+
const sections = buildSectionTree(lines, bodyStartLine);
|
|
77
|
+
return { frontmatter, frontmatterError, bodyStartLine, sections };
|
|
78
|
+
}
|
|
79
|
+
function extractFrontmatter(lines) {
|
|
80
|
+
if ((lines[0] ?? "").trim() !== FRONTMATTER_FENCE) {
|
|
81
|
+
return {
|
|
82
|
+
frontmatter: {},
|
|
83
|
+
frontmatterError: "Missing YAML frontmatter fence (---) at the top of the file.",
|
|
84
|
+
bodyStartLine: 1
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const closingIndex = lines.findIndex(
|
|
88
|
+
(line, index) => index > 0 && line.trim() === FRONTMATTER_FENCE
|
|
89
|
+
);
|
|
90
|
+
if (closingIndex === -1) {
|
|
91
|
+
return {
|
|
92
|
+
frontmatter: {},
|
|
93
|
+
frontmatterError: "Frontmatter is missing its closing --- line.",
|
|
94
|
+
bodyStartLine: 1
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const yamlText = lines.slice(1, closingIndex).join("\n");
|
|
98
|
+
try {
|
|
99
|
+
const parsed = loadYaml(yamlText);
|
|
100
|
+
const frontmatter = isRecord(parsed) ? parsed : {};
|
|
101
|
+
return { frontmatter, frontmatterError: null, bodyStartLine: closingIndex + 2 };
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
104
|
+
return {
|
|
105
|
+
frontmatter: {},
|
|
106
|
+
frontmatterError: `Frontmatter is not valid YAML: ${message}`,
|
|
107
|
+
bodyStartLine: closingIndex + 2
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function buildSectionTree(lines, bodyStartLine) {
|
|
112
|
+
const flat = [];
|
|
113
|
+
for (let i = bodyStartLine - 1; i < lines.length; i += 1) {
|
|
114
|
+
const match = HEADING_PATTERN.exec(lines[i] ?? "");
|
|
115
|
+
const level = match?.[1];
|
|
116
|
+
const heading = match?.[2];
|
|
117
|
+
if (level !== void 0 && heading !== void 0) {
|
|
118
|
+
flat.push({ level: level.length, line: i + 1, heading });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const nodes = flat.map((entry, index) => {
|
|
122
|
+
const nextLine = flat[index + 1]?.line ?? lines.length + 1;
|
|
123
|
+
const body = lines.slice(entry.line, nextLine - 1).join("\n").trim();
|
|
124
|
+
return { heading: entry.heading, level: entry.level, line: entry.line, body, children: [] };
|
|
125
|
+
});
|
|
126
|
+
const roots = [];
|
|
127
|
+
const stack = [];
|
|
128
|
+
nodes.forEach((node) => {
|
|
129
|
+
while (stack.length > 0) {
|
|
130
|
+
const top = stack[stack.length - 1];
|
|
131
|
+
if (top && top.level >= node.level) {
|
|
132
|
+
stack.pop();
|
|
133
|
+
} else {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const parent = stack[stack.length - 1];
|
|
138
|
+
if (parent) {
|
|
139
|
+
parent.children.push(node);
|
|
140
|
+
} else {
|
|
141
|
+
roots.push(node);
|
|
142
|
+
}
|
|
143
|
+
stack.push(node);
|
|
144
|
+
});
|
|
145
|
+
return roots;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/core/project-loader.ts
|
|
149
|
+
async function loadProject(rootDir) {
|
|
150
|
+
const [schemas, skills, contextFiles, evalSuites] = await Promise.all([
|
|
151
|
+
loadSchemas(rootDir),
|
|
152
|
+
loadSkills(rootDir),
|
|
153
|
+
loadContextFiles(rootDir),
|
|
154
|
+
loadEvalSuites(rootDir)
|
|
155
|
+
]);
|
|
156
|
+
return { rootDir, schemas, skills, contextFiles, evalSuites };
|
|
157
|
+
}
|
|
158
|
+
async function loadSchemas(rootDir) {
|
|
159
|
+
const dirPath = join2(rootDir, "schemas");
|
|
160
|
+
const fileNames = (await listFileNames(dirPath)).filter((name) => name.endsWith(".schema.json"));
|
|
161
|
+
return Promise.all(
|
|
162
|
+
fileNames.map(async (fileName) => {
|
|
163
|
+
const filePath = join2(dirPath, fileName);
|
|
164
|
+
const raw = await readFile2(filePath, "utf8");
|
|
165
|
+
let json;
|
|
166
|
+
let parseError = null;
|
|
167
|
+
try {
|
|
168
|
+
json = JSON.parse(raw);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
parseError = error instanceof Error ? error.message : String(error);
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
name: fileName.replace(/\.schema\.json$/, ""),
|
|
174
|
+
filePath,
|
|
175
|
+
relativePath: toPosixRelative(rootDir, filePath),
|
|
176
|
+
raw,
|
|
177
|
+
json,
|
|
178
|
+
parseError
|
|
179
|
+
};
|
|
180
|
+
})
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
async function loadSkills(rootDir) {
|
|
184
|
+
const dirPath = join2(rootDir, "skills");
|
|
185
|
+
const dirNames = await listDirectoryNames(dirPath);
|
|
186
|
+
const skills = [];
|
|
187
|
+
for (const dirName of dirNames) {
|
|
188
|
+
const filePath = join2(dirPath, dirName, "SKILL.md");
|
|
189
|
+
const raw = await readFileIfExists(filePath);
|
|
190
|
+
if (raw === null) continue;
|
|
191
|
+
const parsed = parseSkillMarkdown(raw);
|
|
192
|
+
const files = (await listFilesRecursively(join2(dirPath, dirName))).filter(
|
|
193
|
+
(name) => name !== "SKILL.md"
|
|
194
|
+
);
|
|
195
|
+
skills.push({
|
|
196
|
+
...parsed,
|
|
197
|
+
dirName,
|
|
198
|
+
filePath,
|
|
199
|
+
relativePath: toPosixRelative(rootDir, filePath),
|
|
200
|
+
raw,
|
|
201
|
+
files
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return skills;
|
|
205
|
+
}
|
|
206
|
+
async function loadContextFiles(rootDir) {
|
|
207
|
+
const dirPath = join2(rootDir, "context");
|
|
208
|
+
const fileNames = (await listFileNames(dirPath)).filter((name) => name.endsWith(".md"));
|
|
209
|
+
return Promise.all(
|
|
210
|
+
fileNames.map(async (fileName) => {
|
|
211
|
+
const filePath = join2(dirPath, fileName);
|
|
212
|
+
const raw = await readFile2(filePath, "utf8");
|
|
213
|
+
return {
|
|
214
|
+
name: fileName.replace(/\.md$/, ""),
|
|
215
|
+
filePath,
|
|
216
|
+
relativePath: toPosixRelative(rootDir, filePath),
|
|
217
|
+
raw
|
|
218
|
+
};
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
async function loadEvalSuites(rootDir) {
|
|
223
|
+
const dirPath = join2(rootDir, "evals");
|
|
224
|
+
const dirNames = await listDirectoryNames(dirPath);
|
|
225
|
+
const suites = [];
|
|
226
|
+
for (const dirName of dirNames) {
|
|
227
|
+
const filePath = join2(dirPath, dirName, "cases.yaml");
|
|
228
|
+
const raw = await readFileIfExists(filePath);
|
|
229
|
+
if (raw === null) continue;
|
|
230
|
+
let skill = null;
|
|
231
|
+
let cases = [];
|
|
232
|
+
let parseError = null;
|
|
233
|
+
try {
|
|
234
|
+
const parsed = loadYaml2(raw);
|
|
235
|
+
if (isRecord(parsed)) {
|
|
236
|
+
skill = typeof parsed.skill === "string" ? parsed.skill : null;
|
|
237
|
+
cases = Array.isArray(parsed.cases) ? parsed.cases : [];
|
|
238
|
+
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
parseError = error instanceof Error ? error.message : String(error);
|
|
241
|
+
}
|
|
242
|
+
suites.push({
|
|
243
|
+
skill,
|
|
244
|
+
filePath,
|
|
245
|
+
relativePath: toPosixRelative(rootDir, filePath),
|
|
246
|
+
raw,
|
|
247
|
+
cases,
|
|
248
|
+
parseError
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return suites;
|
|
252
|
+
}
|
|
253
|
+
function toPosixRelative(rootDir, filePath) {
|
|
254
|
+
return relative(rootDir, filePath).split("\\").join("/");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/cli/home.ts
|
|
258
|
+
async function detectProjectStatus(rootDir) {
|
|
259
|
+
const inProject = existsSync(join3(rootDir, "codsy.config.yaml"));
|
|
260
|
+
if (!inProject) {
|
|
261
|
+
return { inProject: false, skillCount: 0, schemaCount: 0, contextFileCount: 0 };
|
|
262
|
+
}
|
|
263
|
+
const project = await loadProject(rootDir);
|
|
264
|
+
return {
|
|
265
|
+
inProject: true,
|
|
266
|
+
skillCount: project.skills.length,
|
|
267
|
+
schemaCount: project.schemas.length,
|
|
268
|
+
contextFileCount: project.contextFiles.length
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function statusLine(status) {
|
|
272
|
+
return `${status.skillCount} skills \xB7 ${status.schemaCount} schemas \xB7 ${status.contextFileCount} context files`;
|
|
273
|
+
}
|
|
274
|
+
var HOME_MENU_ITEMS = [
|
|
275
|
+
{ label: "Start a new project", command: "codsy init" },
|
|
276
|
+
{ label: "Add a skill", command: "codsy new skill" },
|
|
277
|
+
{ label: "Check my project", command: "codsy check" },
|
|
278
|
+
{ label: "Run evals", command: "codsy eval" },
|
|
279
|
+
{ label: "Learn the basics", command: "codsy explain CODSY010" }
|
|
280
|
+
];
|
|
281
|
+
var ONE_LINE_DESCRIPTION = "Codsy helps you write operational knowledge as versioned files people and AI agents can both read.";
|
|
282
|
+
function formatPlainHome(status) {
|
|
283
|
+
const lines = [ONE_LINE_DESCRIPTION, ""];
|
|
284
|
+
if (status.inProject) {
|
|
285
|
+
lines.push(statusLine(status), "");
|
|
286
|
+
}
|
|
287
|
+
lines.push("Commands:");
|
|
288
|
+
for (const item of HOME_MENU_ITEMS) {
|
|
289
|
+
lines.push(` ${item.command} \u2014 ${item.label}`);
|
|
290
|
+
}
|
|
291
|
+
return `${lines.join("\n")}
|
|
292
|
+
`;
|
|
293
|
+
}
|
|
294
|
+
async function runHomeCommand(options) {
|
|
295
|
+
const status = await detectProjectStatus(options.rootDir);
|
|
296
|
+
if (options.isInteractive && options.renderRichHome) {
|
|
297
|
+
await options.renderRichHome(status);
|
|
298
|
+
} else {
|
|
299
|
+
options.write(formatPlainHome(status));
|
|
300
|
+
}
|
|
301
|
+
return 0;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export {
|
|
305
|
+
readFileIfExists,
|
|
306
|
+
listFilesRecursively,
|
|
307
|
+
isRecord,
|
|
308
|
+
loadProject,
|
|
309
|
+
statusLine,
|
|
310
|
+
HOME_MENU_ITEMS,
|
|
311
|
+
runHomeCommand
|
|
312
|
+
};
|
|
313
|
+
//# sourceMappingURL=chunk-FVNSMO6G.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/cli/templates/schema-json.ts
|
|
2
|
+
function buildSchemaJson(answers) {
|
|
3
|
+
const properties = {};
|
|
4
|
+
for (const field of answers.fields) {
|
|
5
|
+
properties[field.name] = { type: field.type, description: field.description };
|
|
6
|
+
}
|
|
7
|
+
const schema = {
|
|
8
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
9
|
+
title: titleCase(answers.name),
|
|
10
|
+
description: answers.description,
|
|
11
|
+
type: "object",
|
|
12
|
+
properties
|
|
13
|
+
};
|
|
14
|
+
return `${JSON.stringify(schema, null, 2)}
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
function titleCase(name) {
|
|
18
|
+
return name.split(/[-_\s]+/).filter((word) => word.length > 0).map((word) => word[0].toUpperCase() + word.slice(1)).join(" ");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
buildSchemaJson
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=chunk-JVEULAOD.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
THEME
|
|
3
|
+
} from "./chunk-BJYMGFW2.js";
|
|
4
|
+
|
|
5
|
+
// src/ui/components/StepIndicator.tsx
|
|
6
|
+
import { Text } from "ink";
|
|
7
|
+
import { jsxs } from "react/jsx-runtime";
|
|
8
|
+
function StepIndicator({ current, total, label }) {
|
|
9
|
+
return /* @__PURE__ */ jsxs(Text, { color: THEME.dim, children: [
|
|
10
|
+
"Step ",
|
|
11
|
+
current,
|
|
12
|
+
" of ",
|
|
13
|
+
total,
|
|
14
|
+
label ? ` \u2014 ${label}` : ""
|
|
15
|
+
] });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
StepIndicator
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-KFHC377Y.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_KEY_HINTS,
|
|
3
|
+
KeyHintFooter
|
|
4
|
+
} from "./chunk-6AVERKMZ.js";
|
|
5
|
+
import {
|
|
6
|
+
THEME
|
|
7
|
+
} from "./chunk-BJYMGFW2.js";
|
|
8
|
+
|
|
9
|
+
// src/ui/components/SelectList.tsx
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
import { Box, Text, useInput } from "ink";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
function SelectList({
|
|
14
|
+
items,
|
|
15
|
+
onSelect,
|
|
16
|
+
onCancel,
|
|
17
|
+
initialIndex = 0
|
|
18
|
+
}) {
|
|
19
|
+
const [index, setIndex] = useState(initialIndex);
|
|
20
|
+
const [helpVisible, setHelpVisible] = useState(false);
|
|
21
|
+
useInput((input, key) => {
|
|
22
|
+
if (items.length === 0) return;
|
|
23
|
+
if (key.upArrow || input === "k") {
|
|
24
|
+
setIndex((current) => (current - 1 + items.length) % items.length);
|
|
25
|
+
} else if (key.downArrow || input === "j") {
|
|
26
|
+
setIndex((current) => (current + 1) % items.length);
|
|
27
|
+
} else if (key.return) {
|
|
28
|
+
const item = items[index];
|
|
29
|
+
if (item) onSelect(item.value);
|
|
30
|
+
} else if (key.escape) {
|
|
31
|
+
onCancel?.();
|
|
32
|
+
} else if (input === "?") {
|
|
33
|
+
setHelpVisible((visible) => !visible);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
|
|
37
|
+
items.map((item, itemIndex) => /* @__PURE__ */ jsxs(Text, { ...itemIndex === index ? { color: THEME.sand } : {}, children: [
|
|
38
|
+
itemIndex === index ? "> " : " ",
|
|
39
|
+
item.label
|
|
40
|
+
] }, item.value)),
|
|
41
|
+
helpVisible && /* @__PURE__ */ jsx(KeyHintFooter, { hints: DEFAULT_KEY_HINTS })
|
|
42
|
+
] });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
SelectList
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=chunk-MOIYJ6UU.js.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// src/cli/check-format.ts
|
|
2
|
+
function summarize(diagnostics) {
|
|
3
|
+
return {
|
|
4
|
+
errorCount: diagnostics.filter((d) => d.severity === "error").length,
|
|
5
|
+
warnCount: diagnostics.filter((d) => d.severity === "warn").length
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function summaryLine(summary) {
|
|
9
|
+
const fix = pluralize(summary.errorCount, "thing to fix", "things to fix");
|
|
10
|
+
const suggest = pluralize(summary.warnCount, "suggestion", "suggestions");
|
|
11
|
+
if (summary.errorCount === 0 && summary.warnCount === 0) {
|
|
12
|
+
return "Everything checks out.";
|
|
13
|
+
}
|
|
14
|
+
return `${summary.errorCount} ${fix}, ${summary.warnCount} ${suggest}.`;
|
|
15
|
+
}
|
|
16
|
+
function pluralize(count, singular, plural) {
|
|
17
|
+
return count === 1 ? singular : plural;
|
|
18
|
+
}
|
|
19
|
+
function nextStepLine(summary) {
|
|
20
|
+
if (summary.errorCount > 0) {
|
|
21
|
+
return "Fix the errors above, then run codsy check again.";
|
|
22
|
+
}
|
|
23
|
+
if (summary.warnCount > 0) {
|
|
24
|
+
return "No errors. Review the suggestions above when you have time.";
|
|
25
|
+
}
|
|
26
|
+
return "No further action needed.";
|
|
27
|
+
}
|
|
28
|
+
function groupByFile(diagnostics) {
|
|
29
|
+
const groups = /* @__PURE__ */ new Map();
|
|
30
|
+
for (const diagnostic of diagnostics) {
|
|
31
|
+
const existing = groups.get(diagnostic.file);
|
|
32
|
+
if (existing) {
|
|
33
|
+
existing.push(diagnostic);
|
|
34
|
+
} else {
|
|
35
|
+
groups.set(diagnostic.file, [diagnostic]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return groups;
|
|
39
|
+
}
|
|
40
|
+
function formatPlainText(diagnostics) {
|
|
41
|
+
const summary = summarize(diagnostics);
|
|
42
|
+
if (diagnostics.length === 0) {
|
|
43
|
+
return `${summaryLine(summary)}
|
|
44
|
+
${nextStepLine(summary)}
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
const lines = [];
|
|
48
|
+
const groups = groupByFile(diagnostics);
|
|
49
|
+
for (const [file, fileDiagnostics] of groups) {
|
|
50
|
+
lines.push(file);
|
|
51
|
+
for (const diagnostic of fileDiagnostics) {
|
|
52
|
+
lines.push(
|
|
53
|
+
` ${diagnostic.severity.toUpperCase()} ${diagnostic.ruleId} line ${diagnostic.line}: ${diagnostic.message}`
|
|
54
|
+
);
|
|
55
|
+
if (diagnostic.fixHint) {
|
|
56
|
+
lines.push(` Fix: ${diagnostic.fixHint}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
lines.push("");
|
|
61
|
+
lines.push(summaryLine(summary));
|
|
62
|
+
lines.push(nextStepLine(summary));
|
|
63
|
+
return `${lines.join("\n")}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
function formatJson(diagnostics) {
|
|
67
|
+
const summary = summarize(diagnostics);
|
|
68
|
+
return `${JSON.stringify({ diagnostics, summary }, null, 2)}
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
71
|
+
var SARIF_SEVERITY = {
|
|
72
|
+
error: "error",
|
|
73
|
+
warn: "warning",
|
|
74
|
+
off: "note"
|
|
75
|
+
};
|
|
76
|
+
function formatSarif(diagnostics) {
|
|
77
|
+
const sarif = {
|
|
78
|
+
$schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
|
|
79
|
+
version: "2.1.0",
|
|
80
|
+
runs: [
|
|
81
|
+
{
|
|
82
|
+
tool: {
|
|
83
|
+
driver: {
|
|
84
|
+
name: "codsy",
|
|
85
|
+
informationUri: "https://github.com/faelreis/codsy",
|
|
86
|
+
rules: [...new Set(diagnostics.map((d) => d.ruleId))].map((ruleId) => ({ id: ruleId }))
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
results: diagnostics.map((diagnostic) => ({
|
|
90
|
+
ruleId: diagnostic.ruleId,
|
|
91
|
+
level: SARIF_SEVERITY[diagnostic.severity],
|
|
92
|
+
message: { text: diagnostic.message },
|
|
93
|
+
locations: [
|
|
94
|
+
{
|
|
95
|
+
physicalLocation: {
|
|
96
|
+
artifactLocation: { uri: diagnostic.file },
|
|
97
|
+
region: { startLine: diagnostic.line }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}))
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
};
|
|
105
|
+
return `${JSON.stringify(sarif, null, 2)}
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
function formatReport(diagnostics, format) {
|
|
109
|
+
if (format === "json") return formatJson(diagnostics);
|
|
110
|
+
if (format === "sarif") return formatSarif(diagnostics);
|
|
111
|
+
return formatPlainText(diagnostics);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export {
|
|
115
|
+
summarize,
|
|
116
|
+
summaryLine,
|
|
117
|
+
nextStepLine,
|
|
118
|
+
formatReport
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=chunk-TDOJ55BG.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
THEME
|
|
3
|
+
} from "./chunk-BJYMGFW2.js";
|
|
4
|
+
|
|
5
|
+
// src/ui/components/TextInput.tsx
|
|
6
|
+
import { Text, useInput } from "ink";
|
|
7
|
+
import { jsxs } from "react/jsx-runtime";
|
|
8
|
+
function TextInput({ value, onChange, onSubmit, placeholder }) {
|
|
9
|
+
useInput((input, key) => {
|
|
10
|
+
if (key.return) {
|
|
11
|
+
onSubmit?.(value);
|
|
12
|
+
} else if (key.backspace || key.delete) {
|
|
13
|
+
onChange(value.slice(0, -1));
|
|
14
|
+
} else if (!key.ctrl && !key.meta && input) {
|
|
15
|
+
onChange(value + input);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
if (value.length === 0 && placeholder) {
|
|
19
|
+
return /* @__PURE__ */ jsxs(Text, { color: THEME.dim, children: [
|
|
20
|
+
placeholder,
|
|
21
|
+
"\u258C"
|
|
22
|
+
] });
|
|
23
|
+
}
|
|
24
|
+
return /* @__PURE__ */ jsxs(Text, { children: [
|
|
25
|
+
value,
|
|
26
|
+
"\u258C"
|
|
27
|
+
] });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/ui/components/FramedPanel.tsx
|
|
31
|
+
import { Box, Text as Text2 } from "ink";
|
|
32
|
+
import { jsx, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
33
|
+
function FramedPanel({ title, width, children }) {
|
|
34
|
+
return /* @__PURE__ */ jsxs2(
|
|
35
|
+
Box,
|
|
36
|
+
{
|
|
37
|
+
flexDirection: "column",
|
|
38
|
+
borderStyle: "round",
|
|
39
|
+
borderColor: THEME.dim,
|
|
40
|
+
paddingX: 1,
|
|
41
|
+
width,
|
|
42
|
+
children: [
|
|
43
|
+
title && /* @__PURE__ */ jsx(Text2, { color: THEME.sand, bold: true, children: title }),
|
|
44
|
+
children
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
TextInput,
|
|
52
|
+
FramedPanel
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=chunk-UWXPACZ7.js.map
|
package/dist/cli.d.ts
ADDED