@tyyyho/treg 0.1.11 → 0.1.12
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
CHANGED
|
@@ -35,7 +35,7 @@ npx @tyyyho/treg <command> [options]
|
|
|
35
35
|
- `--force`: Overwrite existing config files
|
|
36
36
|
- `--dry-run`: Print full plan without writing files
|
|
37
37
|
- `--skip-husky-install`: Skip husky install command
|
|
38
|
-
- `--skills`: Update existing `AGENTS.md`/`
|
|
38
|
+
- `--skills`: Update existing `CLAUDE.md`/`AGENTS.md`/`GEMINI.md` with skill guidance (enabled by default)
|
|
39
39
|
- `--no-skills`: Disable skill guidance updates
|
|
40
40
|
- `--help`: Show help
|
|
41
41
|
|
package/README.zh-hant.md
CHANGED
|
@@ -35,7 +35,7 @@ npx @tyyyho/treg <command> [options]
|
|
|
35
35
|
- `--force`:覆寫既有設定檔
|
|
36
36
|
- `--dry-run`:輸出完整執行計畫,但不寫入檔案
|
|
37
37
|
- `--skip-husky-install`:略過 `husky install`
|
|
38
|
-
- `--skills`:更新既有 `AGENTS.md`/`
|
|
38
|
+
- `--skills`:更新既有 `CLAUDE.md`/`AGENTS.md`/`GEMINI.md` 的 skill 指引(預設啟用)
|
|
39
39
|
- `--no-skills`:停用 skill 指引更新
|
|
40
40
|
- `--help`:顯示說明
|
|
41
41
|
|
package/dist/init-project/cli.js
CHANGED
|
@@ -39,8 +39,8 @@ Options:
|
|
|
39
39
|
--force Overwrite existing config files
|
|
40
40
|
--dry-run Print planned changes without writing files
|
|
41
41
|
--skip-husky-install Do not run husky install
|
|
42
|
-
--skills Update AGENTS.md/
|
|
43
|
-
--no-skills Disable AGENTS.md/
|
|
42
|
+
--skills Update CLAUDE.md/AGENTS.md/GEMINI.md with feature skill guidance (default: enabled)
|
|
43
|
+
--no-skills Disable CLAUDE.md/AGENTS.md/GEMINI.md skill guidance updates
|
|
44
44
|
-h, --help Show help
|
|
45
45
|
`;
|
|
46
46
|
function includes(allowed, value) {
|
|
@@ -3,68 +3,70 @@ import { promises as fs } from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
const START_MARKER = "<!-- treg:skills:start -->";
|
|
5
5
|
const END_MARKER = "<!-- treg:skills:end -->";
|
|
6
|
+
const SKILL_SECTION_HEADING = "## treg AI Skills";
|
|
6
7
|
const SKILLS_BASE_DIR = "skills";
|
|
8
|
+
const SKILLS_DOC_CANDIDATES = ["CLAUDE.md", "AGENTS.md", "GEMINI.md"];
|
|
7
9
|
const FEATURE_SKILLS = {
|
|
8
10
|
format: {
|
|
9
11
|
name: "treg/format",
|
|
10
12
|
description: "Run and verify formatting rules.",
|
|
11
|
-
when: "
|
|
12
|
-
checklist: [
|
|
13
|
+
when: "Before committing or after broad edits, normalize formatting across the codebase.",
|
|
14
|
+
checklist: [
|
|
15
|
+
"Run `format`.",
|
|
16
|
+
"Run `format:check`.",
|
|
17
|
+
"Confirm only intended files were changed.",
|
|
18
|
+
],
|
|
13
19
|
},
|
|
14
20
|
husky: {
|
|
15
21
|
name: "treg/husky",
|
|
16
22
|
description: "Verify and maintain git hook automation.",
|
|
17
|
-
when: "
|
|
23
|
+
when: "When pre-commit and pre-push checks must stay enforced and consistent.",
|
|
18
24
|
checklist: [
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
25
|
+
"Ensure hooks are executable.",
|
|
26
|
+
"Ensure hooks include `format:check` and `lint:check`.",
|
|
27
|
+
"If type-checking or tests are enabled, ensure those checks are included.",
|
|
22
28
|
],
|
|
23
29
|
},
|
|
24
30
|
lint: {
|
|
25
31
|
name: "treg/lint",
|
|
26
32
|
description: "Run and validate lint rules.",
|
|
27
|
-
when: "
|
|
28
|
-
checklist: [
|
|
33
|
+
when: "After adding rules or changing tooling, verify lint consistency.",
|
|
34
|
+
checklist: [
|
|
35
|
+
"Run `lint`.",
|
|
36
|
+
"Run `lint:check`.",
|
|
37
|
+
"Fix max-warnings and remaining lint violations.",
|
|
38
|
+
],
|
|
29
39
|
},
|
|
30
40
|
test: {
|
|
31
41
|
name: "treg/test",
|
|
32
42
|
description: "Validate test runner setup and execution.",
|
|
33
|
-
when: "
|
|
43
|
+
when: "When test rules are added or test configuration changes.",
|
|
34
44
|
checklist: [
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
45
|
+
"Confirm the selected test runner matches the project setup.",
|
|
46
|
+
"Run `test`.",
|
|
47
|
+
"Run `test:coverage` when coverage validation is needed.",
|
|
38
48
|
],
|
|
39
49
|
},
|
|
40
50
|
typescript: {
|
|
41
51
|
name: "treg/typescript",
|
|
42
52
|
description: "Validate TypeScript strictness and config.",
|
|
43
|
-
when: "
|
|
53
|
+
when: "When tsconfig or strict typing rules are changed.",
|
|
44
54
|
checklist: [
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
55
|
+
"Run `type:check`.",
|
|
56
|
+
"Confirm strict compiler options remain enabled.",
|
|
57
|
+
"Ensure `exclude` does not hide product-logic paths.",
|
|
48
58
|
],
|
|
49
59
|
},
|
|
50
60
|
};
|
|
51
61
|
const FEATURE_STEP_LABELS = {
|
|
52
|
-
format: "
|
|
53
|
-
husky: "Git
|
|
54
|
-
lint: "Lint
|
|
55
|
-
test: "
|
|
56
|
-
typescript: "TypeScript
|
|
62
|
+
format: "Formatting",
|
|
63
|
+
husky: "Git Hook Maintenance",
|
|
64
|
+
lint: "Lint Validation",
|
|
65
|
+
test: "Test Configuration",
|
|
66
|
+
typescript: "TypeScript Settings",
|
|
57
67
|
};
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
if (existsSync(agentsPath)) {
|
|
61
|
-
return agentsPath;
|
|
62
|
-
}
|
|
63
|
-
const claudePath = path.join(projectDir, "CLAUDE.md");
|
|
64
|
-
if (existsSync(claudePath)) {
|
|
65
|
-
return claudePath;
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
+
function resolveSkillsDocs(projectDir) {
|
|
69
|
+
return SKILLS_DOC_CANDIDATES.map(fileName => path.join(projectDir, fileName)).filter(existsSync);
|
|
68
70
|
}
|
|
69
71
|
function getEnabledFeatures(enabledFeatures) {
|
|
70
72
|
return Object.entries(enabledFeatures)
|
|
@@ -121,17 +123,9 @@ async function ensureSkillFiles(projectDir, enabled, testRunner, dryRun) {
|
|
|
121
123
|
function buildSkillSection(context) {
|
|
122
124
|
const { enabledFeatures, testRunner } = context;
|
|
123
125
|
const enabled = getEnabledFeatures(enabledFeatures);
|
|
124
|
-
const lines = [
|
|
125
|
-
START_MARKER,
|
|
126
|
-
"## treg AI Skills",
|
|
127
|
-
"",
|
|
128
|
-
"### 執行步驟與 Skill 對應",
|
|
129
|
-
"",
|
|
130
|
-
];
|
|
126
|
+
const lines = [SKILL_SECTION_HEADING, "", "### Steps and Skill Mapping", ""];
|
|
131
127
|
if (enabled.length === 0) {
|
|
132
|
-
lines.push("1.
|
|
133
|
-
lines.push("");
|
|
134
|
-
lines.push(END_MARKER);
|
|
128
|
+
lines.push("1. No features are enabled in this run, so no skill call is required.");
|
|
135
129
|
lines.push("");
|
|
136
130
|
return lines.join("\n");
|
|
137
131
|
}
|
|
@@ -141,25 +135,32 @@ function buildSkillSection(context) {
|
|
|
141
135
|
return;
|
|
142
136
|
const skillRelativePath = getSkillRelativePath(feature);
|
|
143
137
|
const stepLabel = FEATURE_STEP_LABELS[feature] ?? feature;
|
|
144
|
-
lines.push(`${index + 1}. ${stepLabel}
|
|
138
|
+
lines.push(`${index + 1}. ${stepLabel}: use [${skill.name}](${skillRelativePath})`);
|
|
145
139
|
if (feature === "test") {
|
|
146
|
-
lines.push(` -
|
|
140
|
+
lines.push(` - Current test runner: \`${testRunner}\``);
|
|
147
141
|
}
|
|
148
142
|
});
|
|
149
143
|
lines.push("");
|
|
150
|
-
lines.push(END_MARKER);
|
|
151
|
-
lines.push("");
|
|
152
144
|
return lines.join("\n");
|
|
153
145
|
}
|
|
154
146
|
function upsertSkillSection(content, nextSection) {
|
|
147
|
+
const replaceSection = (start, end) => {
|
|
148
|
+
const before = content.slice(0, start).trimEnd();
|
|
149
|
+
const after = content.slice(end).trimStart();
|
|
150
|
+
const rebuilt = `${before}\n\n${nextSection.trim()}\n`;
|
|
151
|
+
return after ? `${rebuilt}\n${after}\n` : `${rebuilt}`;
|
|
152
|
+
};
|
|
155
153
|
const start = content.indexOf(START_MARKER);
|
|
156
154
|
const end = content.indexOf(END_MARKER);
|
|
157
155
|
if (start !== -1 && end !== -1 && end > start) {
|
|
158
156
|
const suffixStart = end + END_MARKER.length;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
return replaceSection(start, suffixStart);
|
|
158
|
+
}
|
|
159
|
+
const headingStart = content.indexOf(SKILL_SECTION_HEADING);
|
|
160
|
+
if (headingStart !== -1) {
|
|
161
|
+
const nextHeading = content.indexOf("\n## ", headingStart + 1);
|
|
162
|
+
const sectionEnd = nextHeading === -1 ? content.length : nextHeading + 1;
|
|
163
|
+
return replaceSection(headingStart, sectionEnd);
|
|
163
164
|
}
|
|
164
165
|
if (!content.trim()) {
|
|
165
166
|
return `${nextSection.trim()}\n`;
|
|
@@ -168,26 +169,28 @@ function upsertSkillSection(content, nextSection) {
|
|
|
168
169
|
}
|
|
169
170
|
export async function runAiSkillsRule(context) {
|
|
170
171
|
const { projectDir, dryRun } = context;
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
console.log("Skip ai-skills (AGENTS.md/
|
|
172
|
+
const targetFiles = resolveSkillsDocs(projectDir);
|
|
173
|
+
if (targetFiles.length === 0) {
|
|
174
|
+
console.log("Skip ai-skills (CLAUDE.md/AGENTS.md/GEMINI.md not found)");
|
|
174
175
|
return;
|
|
175
176
|
}
|
|
176
177
|
const enabled = getEnabledFeatures(context.enabledFeatures);
|
|
177
178
|
await ensureSkillFiles(projectDir, enabled, context.testRunner, dryRun);
|
|
178
179
|
const section = buildSkillSection(context);
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
180
|
+
for (const targetFile of targetFiles) {
|
|
181
|
+
if (dryRun) {
|
|
182
|
+
console.log(`[dry-run] Would update ${path.basename(targetFile)} with AI skill guidance`);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const current = await fs.readFile(targetFile, "utf8");
|
|
186
|
+
const updated = upsertSkillSection(current, section);
|
|
187
|
+
if (updated !== current) {
|
|
188
|
+
await fs.writeFile(targetFile, updated, "utf8");
|
|
189
|
+
console.log(`Updated ${path.basename(targetFile)} with AI skill guidance`);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
console.log(`${path.basename(targetFile)} already contains latest AI skill guidance`);
|
|
189
193
|
}
|
|
190
|
-
console.log(`${path.basename(targetFile)} already contains latest AI skill guidance`);
|
|
191
194
|
}
|
|
192
195
|
export const __testables__ = {
|
|
193
196
|
buildSkillSection,
|
|
@@ -195,6 +198,6 @@ export const __testables__ = {
|
|
|
195
198
|
ensureSkillFiles,
|
|
196
199
|
getEnabledFeatures,
|
|
197
200
|
getSkillRelativePath,
|
|
198
|
-
|
|
201
|
+
resolveSkillsDocs,
|
|
199
202
|
upsertSkillSection,
|
|
200
203
|
};
|
|
@@ -10,7 +10,7 @@ function buildHookCommands(runner, enabledFeatures) {
|
|
|
10
10
|
`${runner} lint:check || exit 1`,
|
|
11
11
|
];
|
|
12
12
|
if (enabledFeatures.typescript) {
|
|
13
|
-
preCommit.push(`${runner} type
|
|
13
|
+
preCommit.push(`${runner} type:check || exit 1`);
|
|
14
14
|
}
|
|
15
15
|
const prePush = [...preCommit];
|
|
16
16
|
if (enabledFeatures.test) {
|
|
@@ -16,7 +16,7 @@ export async function runTypescriptRule(context) {
|
|
|
16
16
|
withProjectCwd(projectDir, () => {
|
|
17
17
|
if (dryRun) {
|
|
18
18
|
console.log("[dry-run] Would update tsconfig.json");
|
|
19
|
-
console.log("[dry-run] Would set package script: type
|
|
19
|
+
console.log("[dry-run] Would set package script: type:check");
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
const tsconfig = json("tsconfig.json", {
|
|
@@ -35,6 +35,6 @@ export async function runTypescriptRule(context) {
|
|
|
35
35
|
.set("compilerOptions", mergedCompilerOptions)
|
|
36
36
|
.set("exclude", Array.from(exclude))
|
|
37
37
|
.save();
|
|
38
|
-
packageJson().setScript("type
|
|
38
|
+
packageJson().setScript("type:check", "tsc --noEmit").save();
|
|
39
39
|
});
|
|
40
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tyyyho/treg",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "CLI tool for initializing development conventions in existing projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"lint:check": "eslint . --max-warnings 0",
|
|
28
28
|
"format": "prettier --write .",
|
|
29
29
|
"format:check": "prettier --check .",
|
|
30
|
-
"type
|
|
30
|
+
"type:check": "tsc --noEmit",
|
|
31
31
|
"build": "tsc -p tsconfig.build.json && node scripts/write-dist-package-json.mjs",
|
|
32
32
|
"release": "node scripts/release.mjs",
|
|
33
33
|
"prepare": "husky",
|
|
34
|
-
"prepublishOnly": "pnpm format:check && pnpm lint:check && pnpm type
|
|
34
|
+
"prepublishOnly": "pnpm format:check && pnpm lint:check && pnpm type:check && pnpm test && pnpm build"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"mrm-core": "^7.1.22"
|