@nitra/cursor 1.2.2 → 1.3.1

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.
@@ -13,10 +13,13 @@
13
13
  *
14
14
  * Файл AGENTS.md у корені: щоразу повністю перезаписується змістом з AGENTS.template.md
15
15
  * пакету; список правил у шаблоні будується з файлів *.mdc у .cursor/rules поточного проєкту.
16
+ *
17
+ * Після завантаження: у .cursor/rules видаляються файли *.mdc з префіксом «nitra-» (керовані
18
+ * пакетом), яких немає у списку rules у nitra-cursor.json. Інші .mdc у цій директорії залишаються.
16
19
  */
17
20
 
18
21
  import { existsSync } from 'node:fs'
19
- import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
22
+ import { mkdir, readdir, readFile, unlink, writeFile } from 'node:fs/promises'
20
23
  import { basename, dirname, join } from 'node:path'
21
24
  import { cwd } from 'node:process'
22
25
  import { fileURLToPath } from 'node:url'
@@ -172,6 +175,42 @@ async function listProjectRulesMdcFiles() {
172
175
  return names.filter(n => n.endsWith('.mdc')).sort((a, b) => a.localeCompare(b))
173
176
  }
174
177
 
178
+ /**
179
+ * Базові імена файлів .mdc, які очікуються згідно з nitra-cursor.json (префікс nitra-).
180
+ * @param {string[]} configRules елементи масиву rules з конфігу
181
+ * @returns {Set<string>} множина очікуваних імен файлів (наприклад nitra-bun.mdc)
182
+ */
183
+ function expectedManagedRuleBasenames(configRules) {
184
+ return new Set(configRules.map(rule => `${RULE_PREFIX}${normalizeRuleName(rule)}`))
185
+ }
186
+
187
+ /**
188
+ * Видаляє з каталогу правил файли *.mdc з префіксом nitra-, яких немає у конфігурації.
189
+ * Файли без префікса nitra- не змінює.
190
+ * @param {string} rulesDir абсолютний шлях до .cursor/rules
191
+ * @param {string[]} configRules елементи масиву rules з nitra-cursor.json
192
+ * @returns {Promise<string[]>} відсортовані імена видалених файлів
193
+ */
194
+ async function removeOrphanManagedRuleFiles(rulesDir, configRules) {
195
+ if (!existsSync(rulesDir)) {
196
+ return []
197
+ }
198
+ const expected = expectedManagedRuleBasenames(configRules)
199
+ const names = await readdir(rulesDir)
200
+ const removed = []
201
+ for (const name of names) {
202
+ if (!name.endsWith('.mdc') || !name.startsWith(RULE_PREFIX)) {
203
+ continue
204
+ }
205
+ if (expected.has(name)) {
206
+ continue
207
+ }
208
+ await unlink(join(rulesDir, name))
209
+ removed.push(name)
210
+ }
211
+ return removed.sort((a, b) => a.localeCompare(b))
212
+ }
213
+
175
214
  /**
176
215
  * Повністю перезаписує AGENTS.md у корені cwd з npm/AGENTS.template.md
177
216
  * @returns {Promise<void>} завершення запису файлу
@@ -237,7 +276,21 @@ for (const rule of rules) {
237
276
  }
238
277
  }
239
278
 
240
- // 4. AGENTS.md зі списком файлів *.mdc у .cursor/rules (після оновлення на диску)
279
+ // 4. Прибираємо керовані nitra-*.mdc, яких немає у nitra-cursor.json
280
+ try {
281
+ const removed = await removeOrphanManagedRuleFiles(rulesDir, rules)
282
+ if (removed.length > 0) {
283
+ console.log(`\n🧹 Видалено правила поза списком ${CONFIG_FILE} (${removed.length}):`)
284
+ for (const name of removed) {
285
+ console.log(` − ${RULES_DIR}/${name}`)
286
+ }
287
+ }
288
+ } catch (error) {
289
+ console.error(`❌ Не вдалося прибрати зайві файли в ${RULES_DIR}: ${error.message}`)
290
+ process.exit(1)
291
+ }
292
+
293
+ // 5. AGENTS.md зі списком файлів *.mdc у .cursor/rules (після оновлення на диску)
241
294
  try {
242
295
  await syncAgentsMd()
243
296
  } catch (error) {
@@ -245,7 +298,7 @@ try {
245
298
  process.exit(1)
246
299
  }
247
300
 
248
- // 5. Підсумок
301
+ // 6. Підсумок
249
302
  console.log(`\n✨ Готово: ${successCount} завантажено, ${failCount} з помилками\n`)
250
303
  if (failCount > 0) {
251
304
  process.exit(1)
package/mdc/ga.mdc ADDED
@@ -0,0 +1,92 @@
1
+ ---
2
+ description: Правила форматів для .github/workflows
3
+ alwaysApply: true
4
+ version: '1.0'
5
+ ---
6
+
7
+ #
8
+
9
+ Всі файли в директорії .github/workflows повинні мати розширення тільки yml
10
+
11
+ Якщо є .github/workflows/apply-k8s.yml, то в ньому обов'язково повинно бути вказано що критерій для запуску це:
12
+
13
+ ```yaml
14
+ on:
15
+ push:
16
+ paths:
17
+ - '**/k8s/*.yaml'
18
+ ```
19
+
20
+ Якщо є .github/workflows/apply-nats-consumer.yml, то в ньому обов'язково повинно бути вказано що критерій для запуску це:
21
+
22
+ ```yaml
23
+ on:
24
+ push:
25
+ paths:
26
+ - '**/consumer.yaml'
27
+ ```
28
+
29
+ Повинен бути файл .github/workflows/clean-ga-workflows.yml, зі змістом:
30
+
31
+ ```yaml
32
+ name: Clean action for removing completed workflow runs
33
+
34
+ on:
35
+ schedule:
36
+ - cron: '0 1 16 * *'
37
+
38
+ # Allow workflow to be manually run from the GitHub UI
39
+ workflow_dispatch:
40
+
41
+ jobs:
42
+ cleanup_old_workflows:
43
+ runs-on: ubuntu-latest
44
+ steps:
45
+ - name: Delete workflow runs
46
+ uses: dmvict/clean-workflow-runs@v1.0.0
47
+ with:
48
+ token: ${{ github.token }}
49
+ save_period: 31
50
+ save_min_runs_number: 0
51
+
52
+ ```
53
+
54
+ Повинен бути файл .github/workflows/clean-merged-branch.yml, зі змістом:
55
+
56
+ ```yaml
57
+ name: Clean abandoned branches
58
+
59
+ on:
60
+ # Run daily at midnight
61
+ schedule:
62
+ - cron: '0 1 15 * *'
63
+
64
+ # Allow workflow to be manually run from the GitHub UI
65
+ workflow_dispatch:
66
+
67
+ jobs:
68
+ cleanup_old_branches:
69
+ runs-on: ubuntu-latest
70
+ steps:
71
+ - id: delete_stuff
72
+ name: Delete those pesky dead branches
73
+ uses: phpdocker-io/github-actions-delete-abandoned-branches@v2
74
+ with:
75
+ github_token: ${{ github.token }}
76
+ last_commit_age_days: 90
77
+ ignore_branches: main,dev
78
+ dry_run: no
79
+
80
+ - name: Get output
81
+ run: "echo 'Deleted branches: ${{ steps.delete_stuff.outputs.deleted_branches }}'"
82
+ ```
83
+
84
+ якщо в ignore_branches задані інші бранчі, то це допустимо.
85
+
86
+ в файлі .vscode/extensions.json є налаштування для GitHub Actions:
87
+
88
+ ```json title=".vscode/extensions.json"
89
+ {
90
+ "recommendations": ["github.vscode-github-actions"]
91
+ }
92
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitra/cursor",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "CLI для завантаження cursor-правил Nitra у локальний репозиторій",
5
5
  "keywords": [
6
6
  "cli",