@1aboveio/engineering-skills 0.1.18 → 0.1.19
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/package.json +2 -2
- package/skills/better-review/SKILL.md +1 -1
- package/skills/e2e-test/SKILL.md +1 -1
- package/skills/engineering/SKILL.md +1 -1
- package/skills/engineering-runtime/SKILL.md +1 -1
- package/skills/engineering-runtime/coherence/workflow.json +13 -13
- package/skills/ensure-coverage/SKILL.md +1 -1
- package/skills/golden-path/SKILL.md +1 -1
- package/skills/harness-runtime/SKILL.md +1 -1
- package/skills/resolve-issues/SKILL.md +4 -2
- package/skills/resolve-issues/references/preflight.md +17 -3
- package/skills/resolve-issues/references/retention.md +162 -0
- package/skills/resolve-issues/references/workspaces.md +40 -10
- package/skills/resolve-issues/scripts/daily-cleanup.mjs +169 -0
- package/skills/resolve-issues/scripts/resource-formats.mjs +625 -0
- package/skills/resolve-issues/scripts/retention-lock.mjs +548 -0
- package/skills/resolve-issues/scripts/retention-plans.mjs +57 -0
- package/skills/resolve-issues/scripts/retention.mjs +2314 -0
- package/skills/resolve-release/SKILL.md +1 -1
- package/skills/rush-issues/SKILL.md +1 -1
- package/skills/rush-release/SKILL.md +1 -1
- package/skills/test-quality/SKILL.md +1 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Enroll only the explicitly named repository; no project-directory discovery.
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import { execFileSync, spawnSync } from 'node:child_process'
|
|
5
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { homedir } from 'node:os'
|
|
7
|
+
import { delimiter, dirname, isAbsolute, join, resolve } from 'node:path'
|
|
8
|
+
import { fileURLToPath } from 'node:url'
|
|
9
|
+
import { isMainModule } from '../../engineering-runtime/scripts/main-module.mjs'
|
|
10
|
+
|
|
11
|
+
const SCRIPT = fileURLToPath(import.meta.url)
|
|
12
|
+
const RETENTION = join(dirname(SCRIPT), 'retention.mjs')
|
|
13
|
+
const PATH = '/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
|
|
14
|
+
|
|
15
|
+
function days(value) {
|
|
16
|
+
const number = Number(value)
|
|
17
|
+
if (!Number.isSafeInteger(number) || number < 1) throw new Error('--older-than-days must be a positive integer')
|
|
18
|
+
return number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function escapeXml(value) {
|
|
22
|
+
return String(value).replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char])
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function systemdArgument(value) {
|
|
26
|
+
if (/[\r\n\0]/.test(value)) throw new Error('Scheduler paths cannot contain line breaks or NUL')
|
|
27
|
+
return `"${String(value).replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/%/g, '%%').replace(/\$/g, '$$')}"`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Prefer the PATH alias for this exact runtime. Package managers can remove a
|
|
31
|
+
// versioned Cellar directory while keeping their stable opt/bin alias current.
|
|
32
|
+
export function durableNodePath(executable = process.execPath, searchPath = process.env.PATH ?? '') {
|
|
33
|
+
let identity
|
|
34
|
+
try { identity = realpathSync(executable) } catch { return executable }
|
|
35
|
+
for (const directory of searchPath.split(delimiter)) {
|
|
36
|
+
if (!isAbsolute(directory)) continue
|
|
37
|
+
const candidate = join(directory, 'node')
|
|
38
|
+
try { if (realpathSync(candidate) === identity) return candidate } catch { /* not this runtime */ }
|
|
39
|
+
}
|
|
40
|
+
return executable
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function schedulePlan({ repo, olderThanDays = 30, platform = process.platform,
|
|
44
|
+
home = homedir(), node = durableNodePath(), script = SCRIPT } = {}) {
|
|
45
|
+
if (!isAbsolute(repo ?? '')) throw new Error('--repo must be an absolute repository path')
|
|
46
|
+
const canonical = realpathSync(repo)
|
|
47
|
+
if (!existsSync(join(canonical, '.git'))) throw new Error('Daily cleanup requires a Git repository root')
|
|
48
|
+
if (!isAbsolute(home) || !isAbsolute(node) || !isAbsolute(script)) throw new Error('Scheduler paths must be absolute')
|
|
49
|
+
const retention = days(olderThanDays)
|
|
50
|
+
const id = `io.1above.resolve-issues.cleanup.${createHash('sha256').update(canonical).digest('hex').slice(0, 20)}`
|
|
51
|
+
const args = [node, script, 'run', '--repo', canonical, '--older-than-days', String(retention), '--apply']
|
|
52
|
+
if (args.some(value => /[\r\n\0]/.test(value))) throw new Error('Scheduler paths cannot contain line breaks or NUL')
|
|
53
|
+
if (platform === 'darwin') {
|
|
54
|
+
const logs = join(home, 'Library', 'Logs', 'resolve-issues')
|
|
55
|
+
const file = join(home, 'Library', 'LaunchAgents', `${id}.plist`)
|
|
56
|
+
const content = `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict>\n<key>Label</key><string>${id}</string>\n<key>ProgramArguments</key><array>${args.map(arg => `<string>${escapeXml(arg)}</string>`).join('')}</array>\n<key>RunAtLoad</key><true/>\n<key>StartInterval</key><integer>43200</integer>\n<key>EnvironmentVariables</key><dict><key>PATH</key><string>${PATH}</string></dict>\n<key>StandardOutPath</key><string>${escapeXml(join(logs, `${id}.log`))}</string>\n<key>StandardErrorPath</key><string>${escapeXml(join(logs, `${id}.err`))}</string>\n</dict></plist>\n`
|
|
57
|
+
return { repo: canonical, id, retentionDays: retention, platform, files: [{ path: file, content }], directories: [logs], args }
|
|
58
|
+
}
|
|
59
|
+
if (platform === 'linux') {
|
|
60
|
+
const root = join(home, '.config', 'systemd', 'user')
|
|
61
|
+
const service = `[Unit]\nDescription=Reclaim declared disposable resolve-issues resources for ${id}\n\n[Service]\nType=oneshot\nEnvironment=PATH=${PATH}\nExecStart=${args.map(systemdArgument).join(' ')}\nTimeoutStartSec=30min\n`
|
|
62
|
+
const timer = `[Unit]\nDescription=Daily tiered resource retention for ${id}\n\n[Timer]\nOnCalendar=daily\nOnBootSec=5min\nPersistent=true\nUnit=${id}.service\n\n[Install]\nWantedBy=timers.target\n`
|
|
63
|
+
return { repo: canonical, id, retentionDays: retention, platform,
|
|
64
|
+
files: [{ path: join(root, `${id}.service`), content: service }, { path: join(root, `${id}.timer`), content: timer }], directories: [], args }
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Daily cleanup scheduling is unsupported on ${platform}; no job was installed`)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const defaultRun = (command, args) => execFileSync(command, args, { encoding: 'utf8', timeout: 30000, stdio: ['ignore', 'pipe', 'pipe'] })
|
|
70
|
+
|
|
71
|
+
export function installSchedule(options = {}, { run = defaultRun, uid = process.getuid?.() } = {}) {
|
|
72
|
+
const plan = schedulePlan(options)
|
|
73
|
+
for (const file of plan.files) {
|
|
74
|
+
let current = file.path
|
|
75
|
+
while (current !== dirname(current)) {
|
|
76
|
+
try {
|
|
77
|
+
if (lstatSync(current).isSymbolicLink()) throw new Error(`Scheduler path is a symbolic link: ${current}`)
|
|
78
|
+
} catch (error) { if (error.code !== 'ENOENT') throw error }
|
|
79
|
+
current = dirname(current)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const domain = `gui/${uid}`
|
|
83
|
+
const same = plan.files.every(file => existsSync(file.path) && readFileSync(file.path, 'utf8') === file.content)
|
|
84
|
+
if (same) {
|
|
85
|
+
try {
|
|
86
|
+
if (plan.platform === 'darwin') run('launchctl', ['print', `${domain}/${plan.id}`])
|
|
87
|
+
else {
|
|
88
|
+
run('systemctl', ['--user', 'is-enabled', `${plan.id}.timer`])
|
|
89
|
+
run('systemctl', ['--user', 'is-active', `${plan.id}.timer`])
|
|
90
|
+
}
|
|
91
|
+
return { ok: true, action: 'unchanged', ...plan }
|
|
92
|
+
} catch { /* A saved job is not necessarily loaded. */ }
|
|
93
|
+
}
|
|
94
|
+
// Preflight the user scheduler before saving any files.
|
|
95
|
+
if (plan.platform === 'darwin') run('launchctl', ['print', domain])
|
|
96
|
+
else run('systemctl', ['--user', 'show-environment'])
|
|
97
|
+
for (const path of plan.directories) mkdirSync(path, { recursive: true })
|
|
98
|
+
if (plan.platform === 'darwin') {
|
|
99
|
+
let loaded = false
|
|
100
|
+
try { run('launchctl', ['print', `${domain}/${plan.id}`]); loaded = true } catch { /* absent */ }
|
|
101
|
+
if (loaded) run('launchctl', ['bootout', `${domain}/${plan.id}`])
|
|
102
|
+
}
|
|
103
|
+
for (const file of plan.files) {
|
|
104
|
+
mkdirSync(dirname(file.path), { recursive: true })
|
|
105
|
+
writeFileSync(file.path, file.content, { mode: 0o600 })
|
|
106
|
+
}
|
|
107
|
+
if (plan.platform === 'darwin') run('launchctl', ['bootstrap', domain, plan.files[0].path])
|
|
108
|
+
else {
|
|
109
|
+
run('systemctl', ['--user', 'daemon-reload'])
|
|
110
|
+
run('systemctl', ['--user', 'enable', '--now', `${plan.id}.timer`])
|
|
111
|
+
}
|
|
112
|
+
return { ok: true, action: 'installed', ...plan }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function uninstallSchedule(options = {}, { run = defaultRun, uid = process.getuid?.() } = {}) {
|
|
116
|
+
const plan = schedulePlan(options)
|
|
117
|
+
if (plan.platform === 'darwin') {
|
|
118
|
+
let loaded = false
|
|
119
|
+
try { run('launchctl', ['print', `gui/${uid}/${plan.id}`]); loaded = true } catch { /* absent */ }
|
|
120
|
+
if (loaded) run('launchctl', ['bootout', `gui/${uid}/${plan.id}`])
|
|
121
|
+
} else run('systemctl', ['--user', 'disable', '--now', `${plan.id}.timer`])
|
|
122
|
+
for (const file of plan.files) rmSync(file.path, { force: true })
|
|
123
|
+
if (plan.platform === 'linux') run('systemctl', ['--user', 'daemon-reload'])
|
|
124
|
+
return { ok: true, action: 'uninstalled', repo: plan.repo, id: plan.id }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function runDaily({ repo, olderThanDays = 30, apply = false } = {}, run = spawnSync) {
|
|
128
|
+
if (!isAbsolute(repo ?? '')) throw new Error('--repo must be absolute')
|
|
129
|
+
const args = [RETENTION, apply ? 'apply' : 'plan', '--repo', realpathSync(repo), '--generated-days', '7', '--artifact-days', String(days(olderThanDays)), '--json']
|
|
130
|
+
if (apply) args.push('--apply')
|
|
131
|
+
const result = run(process.execPath, args, { encoding: 'utf8', timeout: 25 * 60 * 1000, maxBuffer: 4 * 1024 * 1024 })
|
|
132
|
+
if (result.error) throw result.error
|
|
133
|
+
return { status: result.status ?? 1, stdout: result.stdout ?? '', stderr: result.stderr ?? '' }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function main(argv) {
|
|
137
|
+
try {
|
|
138
|
+
const [command, ...rest] = argv
|
|
139
|
+
const options = {}
|
|
140
|
+
for (let i = 0; i < rest.length; i++) {
|
|
141
|
+
if (rest[i] === '--apply') { options.apply = true; continue }
|
|
142
|
+
if (!['--repo', '--older-than-days'].includes(rest[i])) throw new Error(`Unknown argument ${rest[i]}`)
|
|
143
|
+
const flag = rest[i]
|
|
144
|
+
const value = rest[++i]
|
|
145
|
+
if (!value || value.startsWith('--')) throw new Error(`${flag} needs a value`)
|
|
146
|
+
options[flag === '--repo' ? 'repo' : 'olderThanDays'] = value
|
|
147
|
+
}
|
|
148
|
+
if (!options.repo) throw new Error('--repo is required')
|
|
149
|
+
options.repo = resolve(options.repo)
|
|
150
|
+
if (command === 'run') {
|
|
151
|
+
const result = runDaily(options)
|
|
152
|
+
process.stdout.write(result.stdout)
|
|
153
|
+
process.stderr.write(result.stderr)
|
|
154
|
+
return result.status
|
|
155
|
+
}
|
|
156
|
+
if (options.apply) throw new Error('--apply is only valid with run')
|
|
157
|
+
const result = command === 'install' ? installSchedule(options)
|
|
158
|
+
: command === 'uninstall' ? uninstallSchedule(options)
|
|
159
|
+
: command === 'plan' ? schedulePlan(options) : null
|
|
160
|
+
if (!result) throw new Error('Usage: daily-cleanup.mjs install|uninstall|plan|run --repo PATH [--older-than-days 30] [--apply]')
|
|
161
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`)
|
|
162
|
+
return 0
|
|
163
|
+
} catch (error) {
|
|
164
|
+
process.stderr.write(`daily-cleanup: ${error.message}\n`)
|
|
165
|
+
return 1
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (isMainModule(import.meta.url)) process.exitCode = main(process.argv.slice(2))
|