@nitra/cursor 1.13.75 → 1.13.82
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/CHANGELOG.md +76 -0
- package/package.json +1 -1
- package/rules/abie/abie.mdc +11 -3
- package/rules/abie/policy/base_deployment_preem/base_deployment_preem.rego +9 -11
- package/rules/abie/policy/health_check_policy/health_check_policy.rego +9 -10
- package/rules/abie/policy/http_route_base/http_route_base.rego +7 -8
- package/rules/changelog/fix/consistency/check.mjs +16 -16
- package/{scripts/utils → rules/changelog/fix/consistency}/package-manifest.mjs +1 -1
- package/rules/docker/docker.mdc +3 -3
- package/rules/docker/fix/lint/check.mjs +3 -3
- package/{scripts/utils → rules/docker/fix/lint}/docker-hadolint.mjs +3 -3
- package/rules/docker/lint/lint.mjs +2 -2
- package/rules/ga/fix/workflows/check.mjs +5 -1
- package/rules/ga/ga.mdc +8 -1
- package/rules/ga/lint/lint.mjs +4 -1
- package/rules/ga/policy/workflow_common/template/uses-min-versions.snippet.json +4 -0
- package/rules/ga/policy/workflow_common/workflow_common.rego +89 -0
- package/rules/graphql/fix/tooling/check.mjs +1 -1
- package/{scripts/utils → rules/graphql/fix/tooling}/graphql-gql-scan.mjs +47 -12
- package/rules/hasura/fix/internal_urls/check.mjs +1 -1
- package/{scripts/utils → rules/js-bun-db/fix/safety}/bun-sql-scan.mjs +1 -1
- package/rules/js-bun-db/fix/safety/check.mjs +1 -1
- package/rules/js-lint/fix/tooling/check.mjs +3 -15
- package/{scripts/utils → rules/js-lint/fix/tooling}/rebuild-oxlint-canonical.mjs +1 -1
- package/rules/js-lint/js-lint.mdc +2 -2
- package/rules/js-mssql/fix/deps/check.mjs +1 -1
- package/{scripts/utils → rules/js-mssql/fix/deps}/mssql-pool-scan.mjs +1 -1
- package/{scripts/utils → rules/js-run/fix/runtime}/bunyan-imports.mjs +1 -1
- package/{scripts/utils → rules/js-run/fix/runtime}/check-env-scan.mjs +1 -1
- package/rules/js-run/fix/runtime/check.mjs +5 -5
- package/{scripts/utils → rules/js-run/fix/runtime}/conn-file-rules.mjs +1 -1
- package/{scripts/utils → rules/js-run/fix/runtime}/conn-imports-scan.mjs +1 -1
- package/{scripts/utils → rules/js-run/fix/runtime}/promise-settimeout-scan.mjs +1 -1
- package/rules/k8s/k8s.mdc +1 -1
- package/rules/npm-module/fix/package_structure/check.mjs +11 -1
- package/rules/test/auto.md +1 -0
- package/rules/test/fix/location/check.mjs +77 -0
- package/rules/test/test.mdc +60 -0
- package/rules/vue/fix/packages/check.mjs +2 -2
- package/rules/vue/vue.mdc +1 -1
- package/scripts/auto-rules.mjs +3 -3
- package/scripts/utils/ast-scan-utils.mjs +3 -2
- package/scripts/utils/with-lock.mjs +120 -0
- package/scripts/utils/workspaces.mjs +1 -1
- package/scripts/utils/worktree-fingerprint.mjs +30 -0
- /package/{scripts/utils → rules/docker/fix/lint}/docker-mirror.mjs +0 -0
- /package/{scripts/utils → rules/js-lint/fix/tooling}/knip-canonical.json +0 -0
- /package/{scripts/utils → rules/js-lint/fix/tooling}/oxlint-canonical-skeleton.json +0 -0
- /package/{scripts/utils → rules/js-lint/fix/tooling}/oxlint-canonical.json +0 -0
- /package/{scripts/utils → rules/js-lint/fix/tooling}/oxlint-rules.tsv +0 -0
- /package/{scripts/utils → rules/vue/fix/packages}/vue-forbidden-imports.mjs +0 -0
package/scripts/auto-rules.mjs
CHANGED
|
@@ -16,13 +16,13 @@ import { existsSync } from 'node:fs'
|
|
|
16
16
|
import { readdir, readFile } from 'node:fs/promises'
|
|
17
17
|
import { basename, join, relative } from 'node:path'
|
|
18
18
|
|
|
19
|
-
import { textHasBunSqlImport } from '
|
|
19
|
+
import { textHasBunSqlImport } from '../rules/js-bun-db/fix/safety/bun-sql-scan.mjs'
|
|
20
20
|
import {
|
|
21
21
|
isGqlScanSourceFile,
|
|
22
22
|
shouldSkipFileForGqlScan,
|
|
23
23
|
sourceFileHasGqlTaggedTemplate
|
|
24
|
-
} from '
|
|
25
|
-
import { contentForVueImportScan } from '
|
|
24
|
+
} from '../rules/graphql/fix/tooling/graphql-gql-scan.mjs'
|
|
25
|
+
import { contentForVueImportScan } from '../rules/vue/fix/packages/vue-forbidden-imports.mjs'
|
|
26
26
|
|
|
27
27
|
/** Порядок автододавання правил відповідно до `rules/<rule>/auto.md`. */
|
|
28
28
|
export const AUTO_RULE_ORDER = Object.freeze([
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* розпізнавання типових вузлів (функцій, `*.join(...)`),
|
|
6
6
|
* робота з `TemplateLiteral` (текст quasis, контекст SQL-списку).
|
|
7
7
|
*
|
|
8
|
-
* Використовується
|
|
9
|
-
*
|
|
8
|
+
* Використовується сканерами у `rules/<rule>/fix/...` (наприклад,
|
|
9
|
+
* `rules/js-bun-db/fix/safety/bun-sql-scan.mjs`, `rules/js-mssql/fix/deps/mssql-pool-scan.mjs`,
|
|
10
|
+
* `rules/js-run/fix/runtime/*-scan.mjs`) для уникнення дублювання boilerplate.
|
|
10
11
|
*/
|
|
11
12
|
import { parseSync } from 'oxc-parser'
|
|
12
13
|
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guard-механізм: атомарний lock + dedup для важких команд.
|
|
3
|
+
* Алгоритм: mkdirSync-based lock, перевірка живості PID, sha256-dedup з TTL.
|
|
4
|
+
*/
|
|
5
|
+
import * as fs from 'node:fs'
|
|
6
|
+
import * as path from 'node:path'
|
|
7
|
+
import * as os from 'node:os'
|
|
8
|
+
import { worktreeFingerprint } from './worktree-fingerprint.mjs'
|
|
9
|
+
|
|
10
|
+
const DEFAULTS = {
|
|
11
|
+
ttl: 600_000,
|
|
12
|
+
staleThreshold: 1_800_000,
|
|
13
|
+
waitTimeout: 1_200_000,
|
|
14
|
+
pollInterval: 1_500,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isAlive(pid) {
|
|
18
|
+
try { process.kill(pid, 0); return true } catch { return false }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function sleep(ms) {
|
|
22
|
+
return new Promise(r => setTimeout(r, ms))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function makeRelease(lockDir) {
|
|
26
|
+
return () => fs.rmSync(lockDir, { recursive: true, force: true })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {{exitCode:number, fingerprint:string|null, finishedAt:number}} result
|
|
31
|
+
* @param {string|null} fingerprint
|
|
32
|
+
* @param {number} ttl
|
|
33
|
+
*/
|
|
34
|
+
export function shouldDedup(result, fingerprint, ttl) {
|
|
35
|
+
if (result.exitCode !== 0) return false
|
|
36
|
+
if (fingerprint === null || result.fingerprint !== fingerprint) return false
|
|
37
|
+
if (Date.now() - result.finishedAt >= ttl) return false
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} key
|
|
43
|
+
* @param {() => Promise<number>} runFn
|
|
44
|
+
* @param {{ttl?:number, staleThreshold?:number, waitTimeout?:number, pollInterval?:number, cacheDir?:string}} [opts]
|
|
45
|
+
* @returns {Promise<number>}
|
|
46
|
+
*/
|
|
47
|
+
export async function withLock(key, runFn, opts = {}) {
|
|
48
|
+
const { ttl, staleThreshold, waitTimeout, pollInterval } = { ...DEFAULTS, ...opts }
|
|
49
|
+
const getFingerprint = opts.getFingerprint ?? worktreeFingerprint
|
|
50
|
+
const cacheDir = opts.cacheDir ?? path.join(process.cwd(), 'node_modules/.cache/n-cursor', key)
|
|
51
|
+
const lockDir = path.join(cacheDir, 'lock')
|
|
52
|
+
const ownerFile = path.join(lockDir, 'owner.json')
|
|
53
|
+
const resultFile = path.join(cacheDir, 'result.json')
|
|
54
|
+
const release = makeRelease(lockDir)
|
|
55
|
+
|
|
56
|
+
const fingerprint = getFingerprint()
|
|
57
|
+
fs.mkdirSync(cacheDir, { recursive: true })
|
|
58
|
+
|
|
59
|
+
const loopStart = Date.now()
|
|
60
|
+
let locked = false
|
|
61
|
+
|
|
62
|
+
// eslint-disable-next-line no-constant-condition
|
|
63
|
+
while (true) {
|
|
64
|
+
if (Date.now() - loopStart >= waitTimeout) {
|
|
65
|
+
console.error(`⚠️ ${key}: чекав ${waitTimeout / 60_000} хв — запускаю без локу`)
|
|
66
|
+
return await runFn()
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
fs.mkdirSync(lockDir)
|
|
70
|
+
fs.writeFileSync(ownerFile, JSON.stringify({ pid: process.pid, host: os.hostname(), startedAt: Date.now(), fingerprint }))
|
|
71
|
+
locked = true
|
|
72
|
+
break
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (error.code !== 'EEXIST') throw error
|
|
75
|
+
let owner
|
|
76
|
+
try { owner = JSON.parse(fs.readFileSync(ownerFile, 'utf8')) } catch {
|
|
77
|
+
fs.rmSync(lockDir, { recursive: true, force: true })
|
|
78
|
+
continue
|
|
79
|
+
}
|
|
80
|
+
const stale = (Date.now() - owner.startedAt > staleThreshold) ||
|
|
81
|
+
(os.hostname() === owner.host && !isAlive(owner.pid))
|
|
82
|
+
if (stale) {
|
|
83
|
+
console.error(`🧹 ${key}: знайдено застарілий лок — очищаю`)
|
|
84
|
+
fs.rmSync(lockDir, { recursive: true, force: true })
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
console.error(`⏳ ${key}: чекаю, лок тримає pid ${owner.pid}…`)
|
|
88
|
+
await sleep(pollInterval)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.error(`🔒 ${key}: лок взято`)
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const raw = fs.readFileSync(resultFile, 'utf8')
|
|
96
|
+
const result = JSON.parse(raw)
|
|
97
|
+
if (shouldDedup(result, fingerprint, ttl)) {
|
|
98
|
+
const elapsed = Math.round((Date.now() - result.finishedAt) / 1000)
|
|
99
|
+
console.error(`♻️ ${key}: те саме дерево, ${elapsed}с тому — пропускаю`)
|
|
100
|
+
release()
|
|
101
|
+
return 0
|
|
102
|
+
}
|
|
103
|
+
} catch { /* result.json не існує або пошкоджений */ }
|
|
104
|
+
|
|
105
|
+
const onSignal = () => { release(); process.exit(130) }
|
|
106
|
+
process.once('SIGINT', onSignal)
|
|
107
|
+
process.once('SIGTERM', onSignal)
|
|
108
|
+
|
|
109
|
+
let code
|
|
110
|
+
try {
|
|
111
|
+
code = await runFn()
|
|
112
|
+
fs.writeFileSync(resultFile, JSON.stringify({ finishedAt: Date.now(), exitCode: code, fingerprint }))
|
|
113
|
+
} finally {
|
|
114
|
+
process.off('SIGINT', onSignal)
|
|
115
|
+
process.off('SIGTERM', onSignal)
|
|
116
|
+
release()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return code
|
|
120
|
+
}
|
|
@@ -11,7 +11,7 @@ import { dirname, join, relative } from 'node:path'
|
|
|
11
11
|
const TRAILING_SLASH_RE = /\/$/
|
|
12
12
|
const LEADING_DOTSLASH_RE = /^\.\//
|
|
13
13
|
|
|
14
|
-
/** Glob-ігнор для workspace-патернів із `*` (узгоджено з `package-manifest.mjs`). */
|
|
14
|
+
/** Glob-ігнор для workspace-патернів із `*` (узгоджено з `rules/changelog/fix/consistency/package-manifest.mjs`). */
|
|
15
15
|
export const WORKSPACE_GLOB_IGNORE = Object.freeze(['**/node_modules/**', '**/.git/**', '**/.venv/**', '**/venv/**'])
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fingerprint поточного стану git-робочого дерева.
|
|
3
|
+
* Повертає sha256-hex (64 символи) або null, якщо не в git-репо.
|
|
4
|
+
* @param {typeof import('child_process').spawnSync} spawn
|
|
5
|
+
*/
|
|
6
|
+
import { spawnSync } from 'node:child_process'
|
|
7
|
+
import { createHash } from 'node:crypto'
|
|
8
|
+
|
|
9
|
+
export function worktreeFingerprint(spawn = spawnSync) {
|
|
10
|
+
/** @param {string[]} args */
|
|
11
|
+
function git(args) {
|
|
12
|
+
const r = spawn('git', args, { encoding: 'utf8' })
|
|
13
|
+
if (r.status !== 0 || r.error) throw new Error(`git ${args[0]} failed`)
|
|
14
|
+
return r.stdout
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const commitHash = git(['rev-parse', 'HEAD']).trim()
|
|
19
|
+
const diffText = git(['diff', 'HEAD'])
|
|
20
|
+
const untrackedRaw = git(['ls-files', '--others', '--exclude-standard'])
|
|
21
|
+
const untrackedFiles = untrackedRaw.split('\n').filter(Boolean)
|
|
22
|
+
const pairs = untrackedFiles
|
|
23
|
+
.map(f => `${f}:${git(['hash-object', f]).trim()}`)
|
|
24
|
+
.sort()
|
|
25
|
+
const raw = [commitHash, diffText, ...pairs].join('\n')
|
|
26
|
+
return createHash('sha256').update(raw).digest('hex')
|
|
27
|
+
} catch {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|