@greenrenge/skills 0.2.0 → 0.3.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/README.md +27 -2
- package/bin/cli.mjs +115 -0
- package/bin/lib/onboard.mjs +12 -1
- package/bin/lib/probe.mjs +151 -0
- package/bin/lib/recipes/index.mjs +57 -0
- package/bin/lib/recipes/security-cron.mjs +1140 -0
- package/catalog.json +63 -2
- package/package.json +4 -3
- package/skills/security-remediation-epic/prompt-template.md +87 -20
- package/skills/ticket-orchestrator/SKILL.md +349 -0
- package/skills/ticket-orchestrator/references/proving-the-gates.md +63 -0
|
@@ -0,0 +1,1140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dedicated recipe: `security-cron`
|
|
3
|
+
*
|
|
4
|
+
* Composes overlapping security + harness-agnostic orchestration skills,
|
|
5
|
+
* probes repo lockfiles/scanners/harnesses, renders a tailored remediation
|
|
6
|
+
* prompt (including Phase 0–6, No-fix path, Cleanup, and adversarial disproof),
|
|
7
|
+
* and generates runnable schedule artifacts for T3 Code, Claude Code,
|
|
8
|
+
* OS cron (systemd / launchd / crontab), GitHub Actions, or prompt-only.
|
|
9
|
+
*/
|
|
10
|
+
import { chmodSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { homedir, platform } from "node:os";
|
|
12
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
13
|
+
import {
|
|
14
|
+
c,
|
|
15
|
+
createPrompter,
|
|
16
|
+
expandPlan,
|
|
17
|
+
promptOcrSetupWizard,
|
|
18
|
+
promptRunContractWizard,
|
|
19
|
+
renderInstallPlan,
|
|
20
|
+
} from "../onboard.mjs";
|
|
21
|
+
import {
|
|
22
|
+
collectToolsToProbe,
|
|
23
|
+
evaluateRequirements,
|
|
24
|
+
probeHost,
|
|
25
|
+
probeSecurityRepo,
|
|
26
|
+
TOOL_META,
|
|
27
|
+
toolInstallHint,
|
|
28
|
+
} from "../probe.mjs";
|
|
29
|
+
|
|
30
|
+
export const VALID_HARNESSES = ["t3", "claude", "codex", "opencode", "generic"];
|
|
31
|
+
export const VALID_SCHEDULES = ["t3", "claude-code", "os-cron", "github-actions", "prompt-only"];
|
|
32
|
+
export const VALID_SEVERITIES = ["critical", "high", "medium", "low"];
|
|
33
|
+
export const VALID_TRACKERS = ["local", "github-issues"];
|
|
34
|
+
export const VALID_OS_SCHEDULERS = ["auto", "systemd", "launchd", "crontab"];
|
|
35
|
+
|
|
36
|
+
const DOW_SYSTEMD = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
37
|
+
|
|
38
|
+
function slugify(str) {
|
|
39
|
+
return (
|
|
40
|
+
String(str || "repo")
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
43
|
+
.replace(/^-+|-+$/g, "") || "repo"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function pad2(n) {
|
|
48
|
+
return String(n).padStart(2, "0");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function parseDowField(field) {
|
|
52
|
+
if (!field || field === "*" || field === "?") return null;
|
|
53
|
+
const days = new Set();
|
|
54
|
+
for (const part of field.split(",")) {
|
|
55
|
+
const trimmed = part.trim();
|
|
56
|
+
if (!trimmed) continue;
|
|
57
|
+
if (trimmed.includes("-")) {
|
|
58
|
+
const [aRaw, bRaw] = trimmed.split("-");
|
|
59
|
+
const a = Number(aRaw);
|
|
60
|
+
const b = Number(bRaw);
|
|
61
|
+
if (Number.isInteger(a) && Number.isInteger(b) && a >= 0 && b <= 7) {
|
|
62
|
+
for (let d = a; d <= b; d++) {
|
|
63
|
+
days.add(d === 7 ? 0 : d);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const n = Number(trimmed);
|
|
68
|
+
if (Number.isInteger(n) && n >= 0 && n <= 7) {
|
|
69
|
+
days.add(n === 7 ? 0 : n);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (days.size === 0 || days.size === 7) return null;
|
|
74
|
+
return [...days].sort((a, b) => a - b);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parse a 5-field cron expression (and optional explicit HH:MM time) into
|
|
79
|
+
* T3 fixed_time, systemd OnCalendar, and launchd StartCalendarInterval forms.
|
|
80
|
+
*/
|
|
81
|
+
export function parseCronSchedule(cronExpr = "0 2 * * 1", explicitTime = null) {
|
|
82
|
+
const cleaned = String(cronExpr || "0 2 * * 1").trim();
|
|
83
|
+
const fields = cleaned.split(/\s+/);
|
|
84
|
+
let minute = 0;
|
|
85
|
+
let hour = 2;
|
|
86
|
+
let weekdays = [1];
|
|
87
|
+
|
|
88
|
+
if (fields.length === 5) {
|
|
89
|
+
const m = Number(fields[0]);
|
|
90
|
+
const h = Number(fields[1]);
|
|
91
|
+
if (Number.isInteger(m) && m >= 0 && m <= 59) minute = m;
|
|
92
|
+
if (Number.isInteger(h) && h >= 0 && h <= 23) hour = h;
|
|
93
|
+
weekdays = parseDowField(fields[4]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (explicitTime) {
|
|
97
|
+
const m = String(explicitTime).trim().match(/^(\d{1,2}):(\d{2})$/);
|
|
98
|
+
if (m) {
|
|
99
|
+
const h = Number(m[1]);
|
|
100
|
+
const min = Number(m[2]);
|
|
101
|
+
if (h >= 0 && h <= 23 && min >= 0 && min <= 59) {
|
|
102
|
+
hour = h;
|
|
103
|
+
minute = min;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const normalizedCron =
|
|
109
|
+
fields.length === 5 && !explicitTime
|
|
110
|
+
? cleaned
|
|
111
|
+
: `${minute} ${hour} * * ${weekdays ? weekdays.join(",") : "*"}`;
|
|
112
|
+
|
|
113
|
+
const timeOfDay = `${pad2(hour)}:${pad2(minute)}`;
|
|
114
|
+
const dowPrefix = weekdays ? `${weekdays.map((d) => DOW_SYSTEMD[d]).join(",")} ` : "";
|
|
115
|
+
const systemdOnCalendar = `${dowPrefix}*-*-* ${timeOfDay}:00`;
|
|
116
|
+
|
|
117
|
+
const launchdIntervals = weekdays
|
|
118
|
+
? weekdays.map((d) => ({ Weekday: d, Hour: hour, Minute: minute }))
|
|
119
|
+
: [{ Hour: hour, Minute: minute }];
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
cron: normalizedCron,
|
|
123
|
+
minute,
|
|
124
|
+
hour,
|
|
125
|
+
timeOfDay,
|
|
126
|
+
weekdays,
|
|
127
|
+
systemdOnCalendar,
|
|
128
|
+
launchdIntervals,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function resolveSecurityCronSkills(recipeMeta, { harness = "claude", withOcr = false } = {}) {
|
|
133
|
+
const list = [...(recipeMeta?.baseSkills ?? ["security-remediation-epic", "ticket-orchestrator", "ticket-scheme"])];
|
|
134
|
+
if (harness === "t3" && recipeMeta?.overlays?.t3) {
|
|
135
|
+
for (const s of recipeMeta.overlays.t3) {
|
|
136
|
+
if (!list.includes(s)) list.push(s);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (withOcr && recipeMeta?.overlays?.ocr) {
|
|
140
|
+
for (const s of recipeMeta.overlays.ocr) {
|
|
141
|
+
if (!list.includes(s)) list.push(s);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return list;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function severityLabel(sev) {
|
|
148
|
+
const map = {
|
|
149
|
+
critical: "Critical",
|
|
150
|
+
high: "High or higher",
|
|
151
|
+
medium: "Medium or higher",
|
|
152
|
+
low: "Low or higher (all severities)",
|
|
153
|
+
};
|
|
154
|
+
return map[sev] ?? "Medium or higher";
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function targetsForHarness(harness) {
|
|
158
|
+
switch (harness) {
|
|
159
|
+
case "claude":
|
|
160
|
+
return ["claude"];
|
|
161
|
+
case "codex":
|
|
162
|
+
return ["codex"];
|
|
163
|
+
case "t3":
|
|
164
|
+
return ["claude", "codex"];
|
|
165
|
+
case "opencode":
|
|
166
|
+
return ["claude", "codex"];
|
|
167
|
+
default:
|
|
168
|
+
return ["claude", "codex"];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function renderSecurityRemediationPrompt({
|
|
173
|
+
ownerRepo,
|
|
174
|
+
defaultBranch = "main",
|
|
175
|
+
harness = "claude",
|
|
176
|
+
tracker = "local",
|
|
177
|
+
severity = "medium",
|
|
178
|
+
withOcr = false,
|
|
179
|
+
prLabel = "",
|
|
180
|
+
contractPath = "",
|
|
181
|
+
lockfiles = [],
|
|
182
|
+
recommendedScanners = ["osv-scanner"],
|
|
183
|
+
}) {
|
|
184
|
+
const repoDisplay = ownerRepo || "{owner}/{repo}";
|
|
185
|
+
const isT3 = harness === "t3";
|
|
186
|
+
const orchSkill = isT3 ? "t3-ticket-orchestrator" : "ticket-orchestrator";
|
|
187
|
+
const contractNote = contractPath
|
|
188
|
+
? `reading the repo Run Contract from \`${contractPath}\``
|
|
189
|
+
: "reading the repo Run Contract (`~/.agents/rules/<repo>-contract.md` or `docs/agents/orchestrator-contract.md`, if present)";
|
|
190
|
+
const trackerLine =
|
|
191
|
+
tracker === "github-issues"
|
|
192
|
+
? "Track tickets as GitHub Issues per `ticket-scheme`."
|
|
193
|
+
: "Run in local mode: no GitHub issues created — tickets are local files in the gitignored scratch directory.";
|
|
194
|
+
const ocrLine = withOcr
|
|
195
|
+
? "\n- Review gate: run `ocr review` on the full `security/<short-slug>` branch diff once after fixes (using `open-code-review` / `.opencodereview/rule.json`); fix each finding or record its rejection reason with evidence."
|
|
196
|
+
: "";
|
|
197
|
+
const prLabelNote = prLabel
|
|
198
|
+
? ` Add label \`${prLabel}\` when opening the PR (\`gh pr create --label ${prLabel}\`).`
|
|
199
|
+
: "";
|
|
200
|
+
const scannerHint =
|
|
201
|
+
lockfiles.length > 0
|
|
202
|
+
? `Detected lockfiles: ${lockfiles.map((f) => `\`${f}\``).join(", ")} (recommended local scanners: ${recommendedScanners.map((s) => `\`${s}\``).join(", ")}).`
|
|
203
|
+
: "Local lockfile scanners: `osv-scanner`, or `pip-audit` / `pnpm audit` / `npm audit` / `cargo audit` / `govulncheck` per ecosystem.";
|
|
204
|
+
|
|
205
|
+
const phase6Lines = isT3
|
|
206
|
+
? [
|
|
207
|
+
" - Per the skill's T3 Code end-of-run rule: link (`link_pull_request`) and watch (`watch_pull_request`) the PR, and answer every bot-review round (one batched push per round, verify line green before pushing).",
|
|
208
|
+
" - When the round is answered with required checks green, call `unwatch_pull_request` and **settle the thread** (`t3_thread_organize`, action `settle`). The human merge decision is not waited on.",
|
|
209
|
+
" - Blocked states (bot turn budget exhausted, behaviour fork) also settle, with the blocker documented.",
|
|
210
|
+
" - Never merge or close the PR yourself.",
|
|
211
|
+
" - Then run the **Cleanup** steps below.",
|
|
212
|
+
]
|
|
213
|
+
: [
|
|
214
|
+
" - Per the skill's non-T3 end-of-run rule: verify CI checks (`gh pr checks`), do not poll indefinitely, and do not wait on a human merge decision.",
|
|
215
|
+
" - Emit a structured final report naming the PR URL, check state, fixed/accepted/Undetermined counts, and host-side (or CI artifact) evidence paths.",
|
|
216
|
+
" - Blocked states (unresolvable blocker, behaviour fork) also exit cleanly with the blocker documented.",
|
|
217
|
+
" - Never merge or close the PR yourself.",
|
|
218
|
+
" - Then run the **Cleanup** steps below.",
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
const noFixStep4 = isT3
|
|
222
|
+
? "4. **Settle the T3 thread** (`t3_thread_organize`, action `settle`) with a final summary: outcome (\"no fix required\"), counts, any accepted-with-justification or `Undetermined` items, the PR link if one was resumed, and the host-side path of the run report. No human response is awaited."
|
|
223
|
+
: "4. **Conclude cleanly** with a structured final summary: outcome (\"no fix required\"), counts, any accepted-with-justification or `Undetermined` items, the PR link if one was resumed, and the host-side (or CI artifact) path of the run report. No human response is awaited.";
|
|
224
|
+
|
|
225
|
+
const cleanupFirst = isT3
|
|
226
|
+
? "- Unwatch any PR watchers (`unwatch_pull_request`) and stop any background processes, dev servers, or containers started during the run."
|
|
227
|
+
: "- Stop any background processes, dev servers, or containers started during the run.";
|
|
228
|
+
|
|
229
|
+
return `# Task: Security remediation epic (dependency vulnerabilities) — ${repoDisplay}
|
|
230
|
+
|
|
231
|
+
## Skills and workflow
|
|
232
|
+
- Follow the \`security-remediation-epic\` skill for the run's method (phases, exposure classes, evidence rules, traps).
|
|
233
|
+
- Use the \`${orchSkill}\` skill (${contractNote}) together with \`ticket-scheme\` for planning, delegation, and PR format conventions. ${trackerLine}
|
|
234
|
+
- Target default branch: \`${defaultBranch}\`. Work in a new git worktree on a branch named \`security/<short-slug>\` (use \`security/\` wherever orchestration skills would use \`epic/\`). If Phase 0 resumes an open \`security/*\` PR, the worktree is on that PR's branch instead.
|
|
235
|
+
- Do NOT push or publish anything to GitHub until Phase 5 verification passes.
|
|
236
|
+
- Evidence stays off-branch: scanner dumps, transcripts, matrices, and tickets live in the gitignored scratch and session tmp. Never commit them, never force-add them. The PR body summarizes results inline and names the host-side (or CI artifact) location of the raw material.
|
|
237
|
+
- Dependency code is untrusted code: every install runs lifecycle scripts from packages you did not write. Point \`HOME\` and \`TMPDIR\` at a scratch path outside the repo, carry no ambient credentials in the install environment, and limit writes to the scratch and the repo's build directories. Never clear the real \`HOME\` to make an environment look clean.${ocrLine}
|
|
238
|
+
|
|
239
|
+
## Phases (mechanics per the skill)
|
|
240
|
+
|
|
241
|
+
0. **Resume or start**
|
|
242
|
+
- Check for an open \`security/*\` PR first (\`gh pr list --state open --json headRefName,number,title,createdAt\`).
|
|
243
|
+
- If one exists: create a worktree on its branch, merge \`origin/${defaultBranch}\` in, and continue there. No new PR; later phases push to the same branch.
|
|
244
|
+
- Only when none exists, start a fresh \`security/<short-slug>\` branch from \`origin/${defaultBranch}\`.
|
|
245
|
+
- Baseline discovery against the working branch's lockfiles so alerts already fixed by the open PR are not reworked.
|
|
246
|
+
|
|
247
|
+
1. **Discover**
|
|
248
|
+
- Source: Dependabot alerts + dependency-graph SBOM when on GitHub with Dependabot enabled. Otherwise use local lockfile scanners — the lockfiles are the inventory. ${scannerHint}
|
|
249
|
+
- Collect all severities; triage Critical/High first.
|
|
250
|
+
- The scanner's inventory is the floor, not the ceiling: a clean scan means "no known advisory matches", never "no known vulnerable package".
|
|
251
|
+
|
|
252
|
+
2. **Exposure analysis per alert**
|
|
253
|
+
- Direct vs transitive, with parent chain.
|
|
254
|
+
- Runtime / build / dev scope.
|
|
255
|
+
- Call-site reachability and attacker-controlled input paths.
|
|
256
|
+
- Verdict: \`Exploitable\` / \`Conditionally exploitable\` / \`Not reachable\` / \`Undetermined\`, with \`file:line\` justification.
|
|
257
|
+
- Include the client–image skew check.
|
|
258
|
+
- **Adversarial disproof pass:** every *Not reachable* verdict is handed to a fresh reader whose only job is to disprove it — re-reading the cited lines without taking the first reader's conclusion as a premise. A failed disproof is recorded as the verdict's justification; a successful disproof re-classifies the alert. \`Exploitable\` / \`Conditionally exploitable\` verdicts are not re-graded. \`Undetermined\` carries no severity, is never an acceptance, and is listed as an open item with its missing fact.
|
|
259
|
+
- Bound the phase: count alerts, work Critical→High→Medium→Low, stop at the bound, and record every alert not analysed as a named gap.
|
|
260
|
+
|
|
261
|
+
3. **Risk assessment**
|
|
262
|
+
- Build a severity × exposure matrix over the **decided** alerts with an action per alert.
|
|
263
|
+
- Policy: every alert rated **${severityLabel(severity)}** after exposure analysis MUST be fixed. Anything accepted below that line needs written justification. \`Undetermined\` alerts sit beside the matrix as open, unresolved, and unaccepted — never folded into "below the line".
|
|
264
|
+
- **Decision gate:** if no alert requires a fix, take the **No-fix path** below instead of continuing to Phase 4.
|
|
265
|
+
|
|
266
|
+
4. **Fix, evidence-based only**
|
|
267
|
+
- Provide before/after scanner output plus regression proof: repo verify line green; the same inputs through the old and new stack give the same answers; the app boots and affected flows behave as before.
|
|
268
|
+
- No self-reported success. Surface blockers, never hide them.
|
|
269
|
+
- **A scoped override is a refusal:** name who legitimately uses the refused version range (other packages in the subtree, workspace members pinning it directly, plugins and extra groups sharing the lockfile) and why the refusal is acceptable for each before recommending it.
|
|
270
|
+
|
|
271
|
+
5. **Final verification (orchestrator)**
|
|
272
|
+
- Independently re-run from scratch: fresh install from the new lockfiles (isolated per the untrusted-code ground rule), full build, tests, app startup, re-scan.
|
|
273
|
+
- The scan is clean when it reports no alert the fix set was supposed to close — accepted and \`Undetermined\` alerts are expected to still appear, and naming them is the point.
|
|
274
|
+
- Only after this passes, push:
|
|
275
|
+
- to the resumed PR's branch when continuing (no new PR, add an incremental note to its body), or
|
|
276
|
+
- branch + PR into \`${defaultBranch}\` when the run started fresh.${prLabelNote}
|
|
277
|
+
|
|
278
|
+
6. **End of run — no human waits**
|
|
279
|
+
${phase6Lines.join("\n")}
|
|
280
|
+
|
|
281
|
+
## No-fix path (nothing needs fixing this run)
|
|
282
|
+
Applies when, after Phase 3, any of these holds:
|
|
283
|
+
- discovery found no alerts;
|
|
284
|
+
- every decided alert is below the fix threshold (${severityLabel(severity)}) after exposure analysis and has a written justification;
|
|
285
|
+
- every alert at or above the fix threshold is already fixed by the resumed open PR.
|
|
286
|
+
|
|
287
|
+
Steps:
|
|
288
|
+
1. **Confirm independently.** Re-scan the working branch's lockfiles from scratch and confirm the result matches the Phase 1–3 conclusion. Do not trust earlier output.
|
|
289
|
+
2. **Write a short run report** in the gitignored scratch: scanner/version used, date, alert counts by severity, the matrix, any \`Undetermined\` or unanalysed gaps, and a one-line justification per accepted alert.
|
|
290
|
+
3. **Publish nothing new.**
|
|
291
|
+
- No branch push, no new PR, no empty commit.
|
|
292
|
+
- If resuming an open PR, comment/update only if its body needs a brief incremental note ("re-scanned, no further action required"); otherwise leave it untouched.
|
|
293
|
+
- Never merge or close any PR.
|
|
294
|
+
${noFixStep4}
|
|
295
|
+
5. Run **Cleanup**.
|
|
296
|
+
|
|
297
|
+
## Cleanup (every end state: no-fix, completed, or blocked)
|
|
298
|
+
${cleanupFirst}
|
|
299
|
+
- Remove the run's worktree (\`git worktree remove\`, then \`git worktree prune\`).
|
|
300
|
+
- Delete the local \`security/<short-slug>\` branch only if it was created this run AND has no commits and no pushed remote. Never delete a branch backing an open PR, and never delete anything holding unpushed commits (if any exist, keep them and mention it in the closing summary).
|
|
301
|
+
- Clear session tmp and build artifacts (\`node_modules\`, build outputs, caches) created in the worktree.
|
|
302
|
+
- Keep in the gitignored scratch only the evidence worth retaining (run report, matrix, before/after scanner output, transcripts the PR body points to). Delete intermediate scratch such as tickets and temp dumps.
|
|
303
|
+
- Verify that the main checkout is clean (\`git status\`), the default branch (\`${defaultBranch}\`) is untouched, and nothing from the scratch is tracked or staged.
|
|
304
|
+
- List what was removed and what was kept (with paths) in the final closing note.
|
|
305
|
+
|
|
306
|
+
## PR body requirements (when a PR is created or updated)
|
|
307
|
+
- Summary and the risk matrix.
|
|
308
|
+
- Table of alerts: fixed / mitigated / accepted, with rationale.
|
|
309
|
+
- **Every alert the run did not analyse** (the cost bound's gap) and **every \`Undetermined\` alert** (the missing fact and who can settle it), each listed as an open item — neither list is optional and neither is summarised away.
|
|
310
|
+
- Flow-by-flow human verification guide — for each changed package or impacted flow:
|
|
311
|
+
- what changed and why it matters;
|
|
312
|
+
- which user-facing or system flow is affected;
|
|
313
|
+
- exact manual steps with the expected result;
|
|
314
|
+
- pointer to the automated evidence (inline key numbers; raw transcripts live on the run host or CI artifact).
|
|
315
|
+
- Rollback notes.
|
|
316
|
+
`;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function renderT3SchedulePayload({ repoSlug, scheduleInfo, promptContent }) {
|
|
320
|
+
const schedule = {
|
|
321
|
+
type: "fixed_time",
|
|
322
|
+
timeOfDay: scheduleInfo.timeOfDay,
|
|
323
|
+
};
|
|
324
|
+
if (scheduleInfo.weekdays && scheduleInfo.weekdays.length > 0) {
|
|
325
|
+
schedule.weekdays = scheduleInfo.weekdays;
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
title: `Security Remediation — ${repoSlug}`,
|
|
329
|
+
enabled: true,
|
|
330
|
+
bindToCurrentThread: false,
|
|
331
|
+
schedule,
|
|
332
|
+
prompt: promptContent,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function renderClaudeSlashCommand({ promptRelPath }) {
|
|
337
|
+
return `---
|
|
338
|
+
description: Run the five-phase security remediation epic (discover, exposure analysis, risk matrix, evidence-backed fixes, verification, cleanup)
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
Read and execute the security remediation prompt at \`${promptRelPath}\` strictly from Phase 0 through Cleanup.
|
|
342
|
+
If the user passes \`--dry-run\` or \`discover-only\` as arguments, run **Phase 0 and Phase 1 only** (no branch pushes, no PRs, no package edits) and print the discovered alert inventory and recommended scanner summary.
|
|
343
|
+
`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function renderRunnerScript({ harness = "claude", promptRelPath }) {
|
|
347
|
+
const defaultHarness = harness === "t3" ? "claude" : harness;
|
|
348
|
+
return `#!/usr/bin/env bash
|
|
349
|
+
set -euo pipefail
|
|
350
|
+
|
|
351
|
+
# Harness-agnostic scheduled runner for security-remediation-epic
|
|
352
|
+
# Generated by @greenrenge/skills (recipe: security-cron)
|
|
353
|
+
|
|
354
|
+
REPO_ROOT="$(cd "$(dirname "\${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
355
|
+
PROMPT_FILE="\${PROMPT_FILE:-\$REPO_ROOT/${promptRelPath}}"
|
|
356
|
+
AGENT_HARNESS="\${AGENT_HARNESS:-${defaultHarness}}"
|
|
357
|
+
DRY_RUN=0
|
|
358
|
+
|
|
359
|
+
for arg in "$@"; do
|
|
360
|
+
case "$arg" in
|
|
361
|
+
--dry-run) DRY_RUN=1 ;;
|
|
362
|
+
esac
|
|
363
|
+
done
|
|
364
|
+
|
|
365
|
+
if [ ! -f "$PROMPT_FILE" ]; then
|
|
366
|
+
echo "error: prompt file not found: $PROMPT_FILE" >&2
|
|
367
|
+
exit 1
|
|
368
|
+
fi
|
|
369
|
+
|
|
370
|
+
STATE_DIR="\${XDG_STATE_HOME:-\$HOME/.local/state}/security-remediation"
|
|
371
|
+
mkdir -p "$STATE_DIR"
|
|
372
|
+
REPO_SLUG="$(basename "$REPO_ROOT")"
|
|
373
|
+
LOCK_DIR="$STATE_DIR/\${REPO_SLUG}.lock"
|
|
374
|
+
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
|
|
375
|
+
LOG_FILE="$STATE_DIR/\${REPO_SLUG}-\${STAMP}.log"
|
|
376
|
+
|
|
377
|
+
if ! mkdir "$LOCK_DIR" 2>/dev/null; then
|
|
378
|
+
echo "Another security-remediation run is already active ($LOCK_DIR). Exiting." >&2
|
|
379
|
+
exit 0
|
|
380
|
+
fi
|
|
381
|
+
trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT
|
|
382
|
+
|
|
383
|
+
PROMPT_TEXT="$(cat "$PROMPT_FILE")"
|
|
384
|
+
if [ "$DRY_RUN" = "1" ]; then
|
|
385
|
+
PROMPT_TEXT="\${PROMPT_TEXT}
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
## DRY-RUN OVERRIDE
|
|
389
|
+
Execute **Phase 0 and Phase 1 (Discover) ONLY**. Do not modify files, do not create branches or commits, do not open PRs. Print the discovered vulnerability inventory and exit."
|
|
390
|
+
fi
|
|
391
|
+
|
|
392
|
+
cd "$REPO_ROOT"
|
|
393
|
+
echo "[\$(date -u +%FT%TZ)] Starting security remediation (harness=\$AGENT_HARNESS, dry_run=\$DRY_RUN)" | tee -a "$LOG_FILE"
|
|
394
|
+
|
|
395
|
+
if [ -n "\${AGENT_CMD:-}" ]; then
|
|
396
|
+
printf '%s' "$PROMPT_TEXT" | eval "$AGENT_CMD" 2>&1 | tee -a "$LOG_FILE"
|
|
397
|
+
exit "\${PIPESTATUS[1]}"
|
|
398
|
+
fi
|
|
399
|
+
|
|
400
|
+
case "$AGENT_HARNESS" in
|
|
401
|
+
claude)
|
|
402
|
+
command -v claude >/dev/null 2>&1 || { echo "error: claude CLI not found in PATH" >&2; exit 127; }
|
|
403
|
+
claude -p "$PROMPT_TEXT" --permission-mode acceptEdits 2>&1 | tee -a "$LOG_FILE"
|
|
404
|
+
;;
|
|
405
|
+
codex)
|
|
406
|
+
command -v codex >/dev/null 2>&1 || { echo "error: codex CLI not found in PATH" >&2; exit 127; }
|
|
407
|
+
codex exec "$PROMPT_TEXT" 2>&1 | tee -a "$LOG_FILE"
|
|
408
|
+
;;
|
|
409
|
+
opencode)
|
|
410
|
+
command -v opencode >/dev/null 2>&1 || { echo "error: opencode CLI not found in PATH" >&2; exit 127; }
|
|
411
|
+
opencode run "$PROMPT_TEXT" 2>&1 | tee -a "$LOG_FILE"
|
|
412
|
+
;;
|
|
413
|
+
*)
|
|
414
|
+
echo "error: unsupported AGENT_HARNESS='$AGENT_HARNESS'. Set AGENT_CMD to your custom agent command." >&2
|
|
415
|
+
exit 2
|
|
416
|
+
;;
|
|
417
|
+
esac
|
|
418
|
+
`;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function renderSystemdUnits({ slug, repoDir, scriptAbsPath, scheduleInfo }) {
|
|
422
|
+
const serviceName = `security-remediation-${slug}`;
|
|
423
|
+
const service = `[Unit]
|
|
424
|
+
Description=Scheduled Security Remediation (${slug})
|
|
425
|
+
After=network-online.target
|
|
426
|
+
|
|
427
|
+
[Service]
|
|
428
|
+
Type=oneshot
|
|
429
|
+
WorkingDirectory=${repoDir}
|
|
430
|
+
ExecStart=/usr/bin/env bash ${scriptAbsPath}
|
|
431
|
+
Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin
|
|
432
|
+
Nice=10
|
|
433
|
+
|
|
434
|
+
[Install]
|
|
435
|
+
WantedBy=default.target
|
|
436
|
+
`;
|
|
437
|
+
|
|
438
|
+
const timer = `[Unit]
|
|
439
|
+
Description=Timer for Scheduled Security Remediation (${slug})
|
|
440
|
+
|
|
441
|
+
[Timer]
|
|
442
|
+
OnCalendar=${scheduleInfo.systemdOnCalendar}
|
|
443
|
+
Persistent=true
|
|
444
|
+
RandomizedDelaySec=5m
|
|
445
|
+
|
|
446
|
+
[Install]
|
|
447
|
+
WantedBy=timers.target
|
|
448
|
+
`;
|
|
449
|
+
|
|
450
|
+
return { serviceName, service, timer };
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export function renderLaunchdPlist({ slug, repoDir, scriptAbsPath, scheduleInfo }) {
|
|
454
|
+
const label = `com.greenrenge.security-remediation.${slug}`;
|
|
455
|
+
const intervalXml =
|
|
456
|
+
scheduleInfo.launchdIntervals.length === 1
|
|
457
|
+
? renderLaunchdDict(scheduleInfo.launchdIntervals[0], " ")
|
|
458
|
+
: ` <array>\n${scheduleInfo.launchdIntervals.map((d) => renderLaunchdDict(d, " ")).join("\n")}\n </array>`;
|
|
459
|
+
|
|
460
|
+
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
461
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
462
|
+
<plist version="1.0">
|
|
463
|
+
<dict>
|
|
464
|
+
<key>Label</key>
|
|
465
|
+
<string>${label}</string>
|
|
466
|
+
<key>WorkingDirectory</key>
|
|
467
|
+
<string>${repoDir}</string>
|
|
468
|
+
<key>ProgramArguments</key>
|
|
469
|
+
<array>
|
|
470
|
+
<string>/bin/bash</string>
|
|
471
|
+
<string>${scriptAbsPath}</string>
|
|
472
|
+
</array>
|
|
473
|
+
<key>StartCalendarInterval</key>
|
|
474
|
+
${intervalXml}
|
|
475
|
+
<key>StandardOutPath</key>
|
|
476
|
+
<string>/tmp/${label}.out.log</string>
|
|
477
|
+
<key>StandardErrorPath</key>
|
|
478
|
+
<string>/tmp/${label}.err.log</string>
|
|
479
|
+
</dict>
|
|
480
|
+
</plist>
|
|
481
|
+
`;
|
|
482
|
+
return { label, plist };
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function renderLaunchdDict(obj, indent) {
|
|
486
|
+
const lines = [`${indent}<dict>`];
|
|
487
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
488
|
+
lines.push(`${indent} <key>${k}</key>`);
|
|
489
|
+
lines.push(`${indent} <integer>${v}</integer>`);
|
|
490
|
+
}
|
|
491
|
+
lines.push(`${indent}</dict>`);
|
|
492
|
+
return lines.join("\n");
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export function renderCrontabEntry({ scriptAbsPath, scheduleInfo }) {
|
|
496
|
+
return `# Scheduled Security Remediation (generated by @greenrenge/skills)
|
|
497
|
+
${scheduleInfo.cron} /bin/bash "${scriptAbsPath}"
|
|
498
|
+
`;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export function renderGithubActionsWorkflow({
|
|
502
|
+
pkgName,
|
|
503
|
+
harness = "claude",
|
|
504
|
+
scheduleInfo,
|
|
505
|
+
promptRelPath,
|
|
506
|
+
resolvedSkills = [],
|
|
507
|
+
targets = ["claude", "codex"],
|
|
508
|
+
ecosystems = [],
|
|
509
|
+
}) {
|
|
510
|
+
const effectiveHarness = harness === "t3" ? "claude" : harness;
|
|
511
|
+
const skillListArg = resolvedSkills.join(" ");
|
|
512
|
+
const targetArg = targets.join(",");
|
|
513
|
+
|
|
514
|
+
let cliInstallStep = "";
|
|
515
|
+
let runAgentStep = "";
|
|
516
|
+
if (effectiveHarness === "claude") {
|
|
517
|
+
cliInstallStep = ` - name: Install Claude Code CLI
|
|
518
|
+
run: npm install -g @anthropic-ai/claude-code`;
|
|
519
|
+
runAgentStep = ` - name: Run security remediation (Claude Code)
|
|
520
|
+
env:
|
|
521
|
+
ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
|
|
522
|
+
CLAUDE_CODE_OAUTH_TOKEN: \${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
|
523
|
+
GH_TOKEN: \${{ secrets.SECURITY_BOT_PAT || secrets.GITHUB_TOKEN }}
|
|
524
|
+
DRY_RUN: \${{ inputs.dry_run || 'false' }}
|
|
525
|
+
run: |
|
|
526
|
+
if [ -z "\${ANTHROPIC_API_KEY:-}" ] && [ -z "\${CLAUDE_CODE_OAUTH_TOKEN:-}" ]; then
|
|
527
|
+
echo "::error::Set ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN in repository secrets."
|
|
528
|
+
exit 1
|
|
529
|
+
fi
|
|
530
|
+
PROMPT="$(cat ${promptRelPath})"
|
|
531
|
+
if [ "$DRY_RUN" = "true" ]; then
|
|
532
|
+
PROMPT="$PROMPT"$'\\n\\n---\\n## DRY-RUN OVERRIDE\\nExecute Phase 0 and Phase 1 (Discover) ONLY. Do not modify files, push, or open a PR.'
|
|
533
|
+
fi
|
|
534
|
+
mkdir -p .scratch/security-remediation
|
|
535
|
+
claude -p "$PROMPT" --permission-mode acceptEdits 2>&1 | tee .scratch/security-remediation/run.log`;
|
|
536
|
+
} else if (effectiveHarness === "codex") {
|
|
537
|
+
cliInstallStep = ` - name: Install Codex CLI
|
|
538
|
+
run: npm install -g @openai/codex`;
|
|
539
|
+
runAgentStep = ` - name: Run security remediation (Codex)
|
|
540
|
+
env:
|
|
541
|
+
OPENAI_API_KEY: \${{ secrets.OPENAI_API_KEY }}
|
|
542
|
+
GH_TOKEN: \${{ secrets.SECURITY_BOT_PAT || secrets.GITHUB_TOKEN }}
|
|
543
|
+
DRY_RUN: \${{ inputs.dry_run || 'false' }}
|
|
544
|
+
run: |
|
|
545
|
+
if [ -z "\${OPENAI_API_KEY:-}" ]; then
|
|
546
|
+
echo "::error::Set OPENAI_API_KEY in repository secrets."
|
|
547
|
+
exit 1
|
|
548
|
+
fi
|
|
549
|
+
PROMPT="$(cat ${promptRelPath})"
|
|
550
|
+
if [ "$DRY_RUN" = "true" ]; then
|
|
551
|
+
PROMPT="$PROMPT"$'\\n\\n---\\n## DRY-RUN OVERRIDE\\nExecute Phase 0 and Phase 1 (Discover) ONLY. Do not modify files, push, or open a PR.'
|
|
552
|
+
fi
|
|
553
|
+
mkdir -p .scratch/security-remediation
|
|
554
|
+
codex exec "$PROMPT" 2>&1 | tee .scratch/security-remediation/run.log`;
|
|
555
|
+
} else if (effectiveHarness === "opencode") {
|
|
556
|
+
cliInstallStep = ` - name: Install OpenCode CLI
|
|
557
|
+
run: npm install -g opencode-ai`;
|
|
558
|
+
runAgentStep = ` - name: Run security remediation (OpenCode)
|
|
559
|
+
env:
|
|
560
|
+
ANTHROPIC_API_KEY: \${{ secrets.ANTHROPIC_API_KEY }}
|
|
561
|
+
OPENAI_API_KEY: \${{ secrets.OPENAI_API_KEY }}
|
|
562
|
+
OPENCODE_API_KEY: \${{ secrets.OPENCODE_API_KEY }}
|
|
563
|
+
GH_TOKEN: \${{ secrets.SECURITY_BOT_PAT || secrets.GITHUB_TOKEN }}
|
|
564
|
+
DRY_RUN: \${{ inputs.dry_run || 'false' }}
|
|
565
|
+
run: |
|
|
566
|
+
PROMPT="$(cat ${promptRelPath})"
|
|
567
|
+
if [ "$DRY_RUN" = "true" ]; then
|
|
568
|
+
PROMPT="$PROMPT"$'\\n\\n---\\n## DRY-RUN OVERRIDE\\nExecute Phase 0 and Phase 1 (Discover) ONLY. Do not modify files, push, or open a PR.'
|
|
569
|
+
fi
|
|
570
|
+
mkdir -p .scratch/security-remediation
|
|
571
|
+
opencode run "$PROMPT" 2>&1 | tee .scratch/security-remediation/run.log`;
|
|
572
|
+
} else {
|
|
573
|
+
cliInstallStep = ` - name: Verify custom agent command
|
|
574
|
+
run: |
|
|
575
|
+
if [ -z "\${{ vars.SECURITY_AGENT_CMD }}" ]; then
|
|
576
|
+
echo "::error::Set repository variable SECURITY_AGENT_CMD (reads prompt from stdin)."
|
|
577
|
+
exit 1
|
|
578
|
+
fi`;
|
|
579
|
+
runAgentStep = ` - name: Run security remediation (custom harness)
|
|
580
|
+
env:
|
|
581
|
+
AGENT_CMD: \${{ vars.SECURITY_AGENT_CMD }}
|
|
582
|
+
AGENT_API_KEY: \${{ secrets.AGENT_API_KEY }}
|
|
583
|
+
GH_TOKEN: \${{ secrets.SECURITY_BOT_PAT || secrets.GITHUB_TOKEN }}
|
|
584
|
+
DRY_RUN: \${{ inputs.dry_run || 'false' }}
|
|
585
|
+
run: |
|
|
586
|
+
PROMPT="$(cat ${promptRelPath})"
|
|
587
|
+
if [ "$DRY_RUN" = "true" ]; then
|
|
588
|
+
PROMPT="$PROMPT"$'\\n\\n---\\n## DRY-RUN OVERRIDE\\nExecute Phase 0 and Phase 1 (Discover) ONLY. Do not modify files, push, or open a PR.'
|
|
589
|
+
fi
|
|
590
|
+
mkdir -p .scratch/security-remediation
|
|
591
|
+
printf '%s' "$PROMPT" | eval "$AGENT_CMD" 2>&1 | tee .scratch/security-remediation/run.log`;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const ecoHint =
|
|
595
|
+
ecosystems.includes("python")
|
|
596
|
+
? "\n # Optional: install pip-audit if scanning Python lockfiles (uv.lock / requirements.txt)\n # - run: pipx install pip-audit\n"
|
|
597
|
+
: "";
|
|
598
|
+
|
|
599
|
+
return `# Generated by ${pkgName} (recipe: security-cron)
|
|
600
|
+
# Required GitHub Secrets:
|
|
601
|
+
# - ${effectiveHarness === "codex" ? "OPENAI_API_KEY" : effectiveHarness === "generic" ? "AGENT_API_KEY (+ repo var SECURITY_AGENT_CMD)" : "ANTHROPIC_API_KEY (or CLAUDE_CODE_OAUTH_TOKEN)"}
|
|
602
|
+
# Optional GitHub Secrets:
|
|
603
|
+
# - SECURITY_BOT_PAT: fine-grained PAT (contents:write, pull_requests:write, vulnerability_alerts:read)
|
|
604
|
+
# Use when you want Dependabot alert API access or PR CI workflows triggered on bot-opened PRs.
|
|
605
|
+
|
|
606
|
+
name: Security Remediation Cron
|
|
607
|
+
|
|
608
|
+
on:
|
|
609
|
+
schedule:
|
|
610
|
+
- cron: "${scheduleInfo.cron}"
|
|
611
|
+
workflow_dispatch:
|
|
612
|
+
inputs:
|
|
613
|
+
dry_run:
|
|
614
|
+
description: "Run Phase 0 + Phase 1 discovery only (no edits or PRs)"
|
|
615
|
+
type: boolean
|
|
616
|
+
default: false
|
|
617
|
+
|
|
618
|
+
concurrency:
|
|
619
|
+
group: security-remediation
|
|
620
|
+
cancel-in-progress: false
|
|
621
|
+
|
|
622
|
+
permissions:
|
|
623
|
+
contents: write
|
|
624
|
+
pull-requests: write
|
|
625
|
+
security-events: read
|
|
626
|
+
|
|
627
|
+
jobs:
|
|
628
|
+
remediate:
|
|
629
|
+
runs-on: ubuntu-latest
|
|
630
|
+
timeout-minutes: 90
|
|
631
|
+
steps:
|
|
632
|
+
- name: Checkout repository
|
|
633
|
+
uses: actions/checkout@v4
|
|
634
|
+
with:
|
|
635
|
+
fetch-depth: 0
|
|
636
|
+
token: \${{ secrets.SECURITY_BOT_PAT || secrets.GITHUB_TOKEN }}
|
|
637
|
+
|
|
638
|
+
- name: Configure git identity
|
|
639
|
+
run: |
|
|
640
|
+
git config user.name "security-remediation[bot]"
|
|
641
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
642
|
+
|
|
643
|
+
- name: Setup Node.js
|
|
644
|
+
uses: actions/setup-node@v4
|
|
645
|
+
with:
|
|
646
|
+
node-version: "22"
|
|
647
|
+
|
|
648
|
+
- name: Materialize agent skills
|
|
649
|
+
run: |
|
|
650
|
+
if [ -f skillfold.yaml ] && [ -f skillfold.lock ]; then
|
|
651
|
+
npx --yes skillfold install --frozen
|
|
652
|
+
else
|
|
653
|
+
npx --yes ${pkgName}@latest install ${skillListArg} --targets ${targetArg} --yes --no-check
|
|
654
|
+
fi
|
|
655
|
+
|
|
656
|
+
- name: Install osv-scanner
|
|
657
|
+
run: |
|
|
658
|
+
OSV_URL="https://github.com/google/osv-scanner/releases/latest/download/osv-scanner_linux_amd64"
|
|
659
|
+
curl -fsSL "$OSV_URL" -o /usr/local/bin/osv-scanner
|
|
660
|
+
chmod +x /usr/local/bin/osv-scanner
|
|
661
|
+
osv-scanner --version
|
|
662
|
+
${ecoHint}
|
|
663
|
+
${cliInstallStep}
|
|
664
|
+
|
|
665
|
+
${runAgentStep}
|
|
666
|
+
|
|
667
|
+
- name: Upload off-branch security evidence
|
|
668
|
+
if: always()
|
|
669
|
+
uses: actions/upload-artifact@v4
|
|
670
|
+
with:
|
|
671
|
+
name: security-remediation-evidence-\${{ github.run_id }}
|
|
672
|
+
path: .scratch/security-remediation/
|
|
673
|
+
if-no-files-found: ignore
|
|
674
|
+
retention-days: 30
|
|
675
|
+
`;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function writeFileEnsureDir(filePath, content, { executable = false } = {}) {
|
|
679
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
680
|
+
writeFileSync(filePath, content, "utf8");
|
|
681
|
+
if (executable) chmodSync(filePath, 0o755);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function renderSecurityPreflight(secRepo, probeResult) {
|
|
685
|
+
const lines = [];
|
|
686
|
+
lines.push(c.bold("Security & Repo Preflight"));
|
|
687
|
+
lines.push(
|
|
688
|
+
` Repository: ${secRepo.ownerRepo ? c.cyan(secRepo.ownerRepo) : c.dim("(no origin remote detected — using {owner}/{repo})")} ${c.dim(`branch=${secRepo.defaultBranch}`)}`,
|
|
689
|
+
);
|
|
690
|
+
lines.push(
|
|
691
|
+
` Lockfiles: ${secRepo.lockfiles.length > 0 ? secRepo.lockfiles.join(", ") : c.dim("(none detected at repo root)")}`,
|
|
692
|
+
);
|
|
693
|
+
if (secRepo.ecosystems.length > 0) {
|
|
694
|
+
lines.push(` Ecosystems: ${secRepo.ecosystems.join(", ")}`);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
lines.push("");
|
|
698
|
+
lines.push(" Scanners & GitHub CLI:");
|
|
699
|
+
const scannerTools = ["git", "gh", ...secRepo.recommendedScanners];
|
|
700
|
+
for (const t of [...new Set(scannerTools)]) {
|
|
701
|
+
const st = probeResult.tools[t] ?? { ok: false };
|
|
702
|
+
const label = TOOL_META[t]?.label ?? t;
|
|
703
|
+
if (st.ok) {
|
|
704
|
+
const detail = st.detail ? ` — ${st.detail}` : "";
|
|
705
|
+
lines.push(` ${c.green("✓")} ${label} ${c.dim((st.version || st.path || "") + detail)}`);
|
|
706
|
+
} else {
|
|
707
|
+
const hint = toolInstallHint(t, probeResult.host.platform);
|
|
708
|
+
lines.push(` ${c.yellow("○")} ${label} ${c.dim("(missing)")}${hint ? ` → ${c.dim(hint)}` : ""}`);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
lines.push("");
|
|
713
|
+
lines.push(" Detected agent CLIs:");
|
|
714
|
+
for (const cli of ["claude", "codex", "opencode"]) {
|
|
715
|
+
const st = probeResult.tools[cli] ?? { ok: false };
|
|
716
|
+
if (st.ok) {
|
|
717
|
+
lines.push(` ${c.green("✓")} ${cli} ${c.dim(st.version || st.path || "")}`);
|
|
718
|
+
} else {
|
|
719
|
+
lines.push(` ${c.dim("·")} ${cli} ${c.dim("not in PATH")}`);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return lines.join("\n");
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function validateChoice(value, allowed, flagName) {
|
|
727
|
+
if (!allowed.includes(value)) {
|
|
728
|
+
throw new Error(`Invalid ${flagName} "${value}". Allowed: ${allowed.join(", ")}`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
export async function runSecurityCronRecipe(ctx) {
|
|
733
|
+
const {
|
|
734
|
+
catalog,
|
|
735
|
+
pkgJson,
|
|
736
|
+
flags,
|
|
737
|
+
resolveRoot,
|
|
738
|
+
parseTargetsList,
|
|
739
|
+
ensureManifest,
|
|
740
|
+
addSkillToManifest,
|
|
741
|
+
skillSource,
|
|
742
|
+
runSkillfold,
|
|
743
|
+
} = ctx;
|
|
744
|
+
|
|
745
|
+
const recipeMeta = catalog.recipes?.["security-cron"];
|
|
746
|
+
const root = resolveRoot(flags);
|
|
747
|
+
const projectDir = flags.global ? process.cwd() : root;
|
|
748
|
+
const secRepo = probeSecurityRepo(projectDir);
|
|
749
|
+
|
|
750
|
+
const probeTools = new Set([
|
|
751
|
+
"git",
|
|
752
|
+
"gh",
|
|
753
|
+
"ocr",
|
|
754
|
+
"claude",
|
|
755
|
+
"codex",
|
|
756
|
+
"opencode",
|
|
757
|
+
...secRepo.recommendedScanners,
|
|
758
|
+
]);
|
|
759
|
+
const probeResult = probeHost({ projectDir, onlyTools: probeTools });
|
|
760
|
+
|
|
761
|
+
console.log("");
|
|
762
|
+
console.log(c.bold(`${pkgJson.name} v${pkgJson.version} — Setup: security-cron`));
|
|
763
|
+
console.log(
|
|
764
|
+
c.dim(
|
|
765
|
+
"Dedicated workflow: overlapping security + harness-agnostic orchestration skills + tailored prompt + scheduler.",
|
|
766
|
+
),
|
|
767
|
+
);
|
|
768
|
+
console.log("");
|
|
769
|
+
console.log(renderSecurityPreflight(secRepo, probeResult));
|
|
770
|
+
|
|
771
|
+
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY && !flags.yes);
|
|
772
|
+
|
|
773
|
+
// Defaults (overridden by CLI flags or interactive answers)
|
|
774
|
+
const detectedCli = probeResult.tools.claude?.ok
|
|
775
|
+
? "claude"
|
|
776
|
+
: probeResult.tools.codex?.ok
|
|
777
|
+
? "codex"
|
|
778
|
+
: probeResult.tools.opencode?.ok
|
|
779
|
+
? "opencode"
|
|
780
|
+
: "claude";
|
|
781
|
+
|
|
782
|
+
let harness = flags.harness ?? (flags.schedule === "t3" ? "t3" : detectedCli);
|
|
783
|
+
let schedule = flags.schedule ?? (harness === "t3" ? "t3" : "prompt-only");
|
|
784
|
+
let cronExpr = flags.cron ?? "0 2 * * 1";
|
|
785
|
+
let explicitTime = flags.time ?? null;
|
|
786
|
+
let severity = flags.severity ?? "medium";
|
|
787
|
+
let tracker = flags.tracker ?? "local";
|
|
788
|
+
let ownerRepo = flags.repo ?? secRepo.ownerRepo ?? "";
|
|
789
|
+
let defaultBranch = flags.branch ?? secRepo.defaultBranch ?? "main";
|
|
790
|
+
let prLabel = flags.label ?? "";
|
|
791
|
+
let withOcr = flags.withOcr === true ? true : flags.withOcr === false ? false : Boolean(probeResult.tools.ocr?.ok);
|
|
792
|
+
let osScheduler = flags.osScheduler ?? "auto";
|
|
793
|
+
let installSchedule = Boolean(flags.installSchedule);
|
|
794
|
+
|
|
795
|
+
if (interactive) {
|
|
796
|
+
const prompter = createPrompter();
|
|
797
|
+
try {
|
|
798
|
+
console.log("");
|
|
799
|
+
console.log(c.bold("Step 1/3 — Target harness & scheduler"));
|
|
800
|
+
if (!flags.harness) {
|
|
801
|
+
harness = (
|
|
802
|
+
await prompter.ask(
|
|
803
|
+
`Agent harness (${VALID_HARNESSES.join(" / ")})`,
|
|
804
|
+
harness,
|
|
805
|
+
)
|
|
806
|
+
).toLowerCase();
|
|
807
|
+
}
|
|
808
|
+
validateChoice(harness, VALID_HARNESSES, "--harness");
|
|
809
|
+
|
|
810
|
+
if (!flags.schedule) {
|
|
811
|
+
const defaultSched =
|
|
812
|
+
harness === "t3"
|
|
813
|
+
? "t3"
|
|
814
|
+
: harness === "claude"
|
|
815
|
+
? "claude-code"
|
|
816
|
+
: "os-cron";
|
|
817
|
+
schedule = (
|
|
818
|
+
await prompter.ask(
|
|
819
|
+
`Schedule backend (${VALID_SCHEDULES.join(" / ")})`,
|
|
820
|
+
defaultSched,
|
|
821
|
+
)
|
|
822
|
+
).toLowerCase();
|
|
823
|
+
}
|
|
824
|
+
validateChoice(schedule, VALID_SCHEDULES, "--schedule");
|
|
825
|
+
|
|
826
|
+
if (schedule === "os-cron" && !flags.osScheduler) {
|
|
827
|
+
const platDefault = platform() === "darwin" ? "launchd" : "systemd";
|
|
828
|
+
osScheduler = (
|
|
829
|
+
await prompter.ask(
|
|
830
|
+
`OS scheduler (${VALID_OS_SCHEDULERS.join(" / ")})`,
|
|
831
|
+
platDefault,
|
|
832
|
+
)
|
|
833
|
+
).toLowerCase();
|
|
834
|
+
}
|
|
835
|
+
validateChoice(osScheduler, VALID_OS_SCHEDULERS, "--os-scheduler");
|
|
836
|
+
|
|
837
|
+
if (schedule !== "prompt-only" && !flags.cron && !flags.time) {
|
|
838
|
+
cronExpr = await prompter.ask(
|
|
839
|
+
"Schedule cron expression (5 fields, e.g. '0 2 * * 1' = Mon 02:00, '0 4 * * *' = daily 04:00)",
|
|
840
|
+
cronExpr,
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
console.log("");
|
|
845
|
+
console.log(c.bold("Step 2/3 — Remediation policy & overlays"));
|
|
846
|
+
if (!flags.repo) {
|
|
847
|
+
ownerRepo = await prompter.ask(
|
|
848
|
+
"Repository slug (owner/repo)",
|
|
849
|
+
ownerRepo || "{owner}/{repo}",
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
if (!flags.branch) {
|
|
853
|
+
defaultBranch = await prompter.ask("Default branch", defaultBranch);
|
|
854
|
+
}
|
|
855
|
+
if (!flags.severity) {
|
|
856
|
+
severity = (
|
|
857
|
+
await prompter.ask(
|
|
858
|
+
`Minimum severity that MUST be fixed (${VALID_SEVERITIES.join(" / ")})`,
|
|
859
|
+
severity,
|
|
860
|
+
)
|
|
861
|
+
).toLowerCase();
|
|
862
|
+
}
|
|
863
|
+
validateChoice(severity, VALID_SEVERITIES, "--severity");
|
|
864
|
+
|
|
865
|
+
if (!flags.tracker) {
|
|
866
|
+
tracker = (
|
|
867
|
+
await prompter.ask(
|
|
868
|
+
`Ticket tracker mode (${VALID_TRACKERS.join(" / ")})`,
|
|
869
|
+
tracker,
|
|
870
|
+
)
|
|
871
|
+
).toLowerCase();
|
|
872
|
+
}
|
|
873
|
+
validateChoice(tracker, VALID_TRACKERS, "--tracker");
|
|
874
|
+
|
|
875
|
+
if (flags.withOcr === null || flags.withOcr === undefined) {
|
|
876
|
+
withOcr = await prompter.confirm(
|
|
877
|
+
"Include Open Code Review (ocr) gate skills (open-code-review + open-code-review-rules)?",
|
|
878
|
+
withOcr,
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
if (!flags.label) {
|
|
883
|
+
prLabel = await prompter.ask(
|
|
884
|
+
"Optional PR review bot label (blank for none)",
|
|
885
|
+
"",
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
if (schedule === "os-cron" && !flags.installSchedule) {
|
|
890
|
+
installSchedule = await prompter.confirm(
|
|
891
|
+
"Install generated OS schedule into your user scheduler (systemd/launchd) after writing?",
|
|
892
|
+
false,
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
} finally {
|
|
896
|
+
prompter.close();
|
|
897
|
+
}
|
|
898
|
+
} else {
|
|
899
|
+
validateChoice(harness, VALID_HARNESSES, "--harness");
|
|
900
|
+
validateChoice(schedule, VALID_SCHEDULES, "--schedule");
|
|
901
|
+
validateChoice(severity, VALID_SEVERITIES, "--severity");
|
|
902
|
+
validateChoice(tracker, VALID_TRACKERS, "--tracker");
|
|
903
|
+
validateChoice(osScheduler, VALID_OS_SCHEDULERS, "--os-scheduler");
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
const scheduleInfo = parseCronSchedule(cronExpr, explicitTime);
|
|
907
|
+
const selectedSkillInputs = resolveSecurityCronSkills(recipeMeta, { harness, withOcr });
|
|
908
|
+
const plan = expandPlan(selectedSkillInputs, catalog, { includeDeps: !flags.noDeps });
|
|
909
|
+
const targets = flags.targets
|
|
910
|
+
? parseTargetsList(flags.targets)
|
|
911
|
+
: targetsForHarness(harness);
|
|
912
|
+
|
|
913
|
+
console.log("");
|
|
914
|
+
console.log(c.bold("Step 3/3 — Skill plan & artifact generation"));
|
|
915
|
+
console.log(
|
|
916
|
+
renderInstallPlan(plan, catalog, {
|
|
917
|
+
scope: flags.global ? "global (~/.config/skillfold)" : "project",
|
|
918
|
+
targets,
|
|
919
|
+
root,
|
|
920
|
+
}),
|
|
921
|
+
);
|
|
922
|
+
|
|
923
|
+
// Install overlapping skills cleanly into skillfold.yaml (unless --skip-install)
|
|
924
|
+
if (!flags.skipInstall) {
|
|
925
|
+
const manifestPath = ensureManifest(root, targets, flags.targets !== null);
|
|
926
|
+
for (const name of plan.ordered) {
|
|
927
|
+
const src = skillSource(name, { local: flags.local });
|
|
928
|
+
addSkillToManifest(manifestPath, name, src);
|
|
929
|
+
}
|
|
930
|
+
console.log("");
|
|
931
|
+
console.log(c.dim(`Merged ${plan.counts.total} skills into ${manifestPath}. Running skillfold install...`));
|
|
932
|
+
runSkillfold(["install"], flags);
|
|
933
|
+
} else {
|
|
934
|
+
console.log("");
|
|
935
|
+
console.log(c.dim("Skipped skillfold install (--skip-install)."));
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// Optional OCR & Run Contract interactive follow-up
|
|
939
|
+
if (interactive && !flags.skipInstall) {
|
|
940
|
+
const evalTools = collectToolsToProbe(plan.ordered, catalog);
|
|
941
|
+
const fullProbe = probeHost({ projectDir, onlyTools: evalTools });
|
|
942
|
+
const evalResult = evaluateRequirements(plan.ordered, catalog, fullProbe);
|
|
943
|
+
if (evalResult.needsOcrSetup || (evalResult.needsRunContract && !evalResult.contractFound)) {
|
|
944
|
+
const prompter = createPrompter();
|
|
945
|
+
try {
|
|
946
|
+
if (evalResult.needsOcrSetup) {
|
|
947
|
+
await promptOcrSetupWizard(prompter, fullProbe);
|
|
948
|
+
}
|
|
949
|
+
if (evalResult.needsRunContract && !evalResult.contractFound) {
|
|
950
|
+
console.log("");
|
|
951
|
+
const doContract = await prompter.confirm(
|
|
952
|
+
"No Run Contract detected for this repo. Scaffold one now?",
|
|
953
|
+
true,
|
|
954
|
+
);
|
|
955
|
+
if (doContract) {
|
|
956
|
+
await promptRunContractWizard(prompter, fullProbe, {
|
|
957
|
+
defaultPlanSkill: "ticket-scheme",
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
} finally {
|
|
962
|
+
prompter.close();
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// Render & write recipe artifacts
|
|
968
|
+
const contractPath = probeResult.rules.contractPaths[0] ?? "";
|
|
969
|
+
const promptRelPath = ".agents/prompts/security-remediation.md";
|
|
970
|
+
const promptAbsPath = join(projectDir, promptRelPath);
|
|
971
|
+
const promptContent = renderSecurityRemediationPrompt({
|
|
972
|
+
ownerRepo: ownerRepo === "{owner}/{repo}" ? "" : ownerRepo,
|
|
973
|
+
defaultBranch,
|
|
974
|
+
harness,
|
|
975
|
+
tracker,
|
|
976
|
+
severity,
|
|
977
|
+
withOcr,
|
|
978
|
+
prLabel,
|
|
979
|
+
contractPath,
|
|
980
|
+
lockfiles: secRepo.lockfiles,
|
|
981
|
+
recommendedScanners: secRepo.recommendedScanners,
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
const written = [];
|
|
985
|
+
writeFileEnsureDir(promptAbsPath, promptContent);
|
|
986
|
+
written.push({ path: promptAbsPath, kind: "Prompt" });
|
|
987
|
+
|
|
988
|
+
const slug = slugify(ownerRepo ? ownerRepo.split("/").pop() : secRepo.repoSlug);
|
|
989
|
+
const nextSteps = [];
|
|
990
|
+
|
|
991
|
+
if (schedule === "t3") {
|
|
992
|
+
const payloadPath = join(projectDir, ".agents", "schedules", "t3-security-remediation.json");
|
|
993
|
+
const payload = renderT3SchedulePayload({
|
|
994
|
+
repoSlug: ownerRepo || secRepo.repoSlug,
|
|
995
|
+
scheduleInfo,
|
|
996
|
+
promptContent,
|
|
997
|
+
});
|
|
998
|
+
writeFileEnsureDir(payloadPath, JSON.stringify(payload, null, 2) + "\n");
|
|
999
|
+
written.push({ path: payloadPath, kind: "T3 schedule_task payload" });
|
|
1000
|
+
nextSteps.push(
|
|
1001
|
+
`In T3 Code, ask your agent to register the schedule: "Call schedule_task using ${relative(projectDir, payloadPath)}" (or paste ${promptRelPath} into T3 Scheduled Tasks at ${scheduleInfo.timeOfDay}).`,
|
|
1002
|
+
);
|
|
1003
|
+
} else if (schedule === "claude-code") {
|
|
1004
|
+
const cmdPath = join(projectDir, ".claude", "commands", "security-remediation.md");
|
|
1005
|
+
writeFileEnsureDir(cmdPath, renderClaudeSlashCommand({ promptRelPath }));
|
|
1006
|
+
written.push({ path: cmdPath, kind: "Claude Code slash command (/security-remediation)" });
|
|
1007
|
+
|
|
1008
|
+
const scriptPath = join(projectDir, ".agents", "scripts", "security-remediation-run.sh");
|
|
1009
|
+
writeFileEnsureDir(scriptPath, renderRunnerScript({ harness: "claude", promptRelPath }), {
|
|
1010
|
+
executable: true,
|
|
1011
|
+
});
|
|
1012
|
+
written.push({ path: scriptPath, kind: "Headless runner script" });
|
|
1013
|
+
|
|
1014
|
+
nextSteps.push("Interactive in Claude Code: run `/security-remediation` (or `/security-remediation --dry-run`).");
|
|
1015
|
+
nextSteps.push(
|
|
1016
|
+
`Headless dry-run test: bash ${relative(projectDir, scriptPath)} --dry-run`,
|
|
1017
|
+
);
|
|
1018
|
+
} else if (schedule === "os-cron") {
|
|
1019
|
+
const scriptPath = join(projectDir, ".agents", "scripts", "security-remediation-run.sh");
|
|
1020
|
+
writeFileEnsureDir(scriptPath, renderRunnerScript({ harness, promptRelPath }), {
|
|
1021
|
+
executable: true,
|
|
1022
|
+
});
|
|
1023
|
+
written.push({ path: scriptPath, kind: "Harness-agnostic runner script" });
|
|
1024
|
+
|
|
1025
|
+
const effectiveOs =
|
|
1026
|
+
osScheduler === "auto"
|
|
1027
|
+
? platform() === "darwin"
|
|
1028
|
+
? "launchd"
|
|
1029
|
+
: "systemd"
|
|
1030
|
+
: osScheduler;
|
|
1031
|
+
|
|
1032
|
+
if (effectiveOs === "systemd") {
|
|
1033
|
+
const { serviceName, service, timer } = renderSystemdUnits({
|
|
1034
|
+
slug,
|
|
1035
|
+
repoDir: resolve(projectDir),
|
|
1036
|
+
scriptAbsPath: resolve(scriptPath),
|
|
1037
|
+
scheduleInfo,
|
|
1038
|
+
});
|
|
1039
|
+
const svcPath = join(projectDir, ".agents", "schedules", `${serviceName}.service`);
|
|
1040
|
+
const tmrPath = join(projectDir, ".agents", "schedules", `${serviceName}.timer`);
|
|
1041
|
+
writeFileEnsureDir(svcPath, service);
|
|
1042
|
+
writeFileEnsureDir(tmrPath, timer);
|
|
1043
|
+
written.push({ path: svcPath, kind: "systemd user service" });
|
|
1044
|
+
written.push({ path: tmrPath, kind: "systemd user timer" });
|
|
1045
|
+
|
|
1046
|
+
if (installSchedule) {
|
|
1047
|
+
const userUnitDir = join(homedir(), ".config", "systemd", "user");
|
|
1048
|
+
writeFileEnsureDir(join(userUnitDir, `${serviceName}.service`), service);
|
|
1049
|
+
writeFileEnsureDir(join(userUnitDir, `${serviceName}.timer`), timer);
|
|
1050
|
+
written.push({ path: join(userUnitDir, `${serviceName}.timer`), kind: "Installed systemd timer (enable with systemctl)" });
|
|
1051
|
+
nextSteps.push(
|
|
1052
|
+
`Enable timer: systemctl --user daemon-reload && systemctl --user enable --now ${serviceName}.timer`,
|
|
1053
|
+
);
|
|
1054
|
+
} else {
|
|
1055
|
+
nextSteps.push(
|
|
1056
|
+
`Install systemd timer: cp ${relative(projectDir, svcPath)} ${relative(projectDir, tmrPath)} ~/.config/systemd/user/ && systemctl --user daemon-reload && systemctl --user enable --now ${serviceName}.timer`,
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
} else if (effectiveOs === "launchd") {
|
|
1060
|
+
const { label, plist } = renderLaunchdPlist({
|
|
1061
|
+
slug,
|
|
1062
|
+
repoDir: resolve(projectDir),
|
|
1063
|
+
scriptAbsPath: resolve(scriptPath),
|
|
1064
|
+
scheduleInfo,
|
|
1065
|
+
});
|
|
1066
|
+
const plistPath = join(projectDir, ".agents", "schedules", `${label}.plist`);
|
|
1067
|
+
writeFileEnsureDir(plistPath, plist);
|
|
1068
|
+
written.push({ path: plistPath, kind: "macOS launchd plist" });
|
|
1069
|
+
|
|
1070
|
+
if (installSchedule) {
|
|
1071
|
+
const agentDir = join(homedir(), "Library", "LaunchAgents");
|
|
1072
|
+
const installedPlist = join(agentDir, `${label}.plist`);
|
|
1073
|
+
writeFileEnsureDir(installedPlist, plist);
|
|
1074
|
+
written.push({ path: installedPlist, kind: "Installed launchd plist" });
|
|
1075
|
+
nextSteps.push(`Load plist: launchctl load -w "${installedPlist}"`);
|
|
1076
|
+
} else {
|
|
1077
|
+
nextSteps.push(
|
|
1078
|
+
`Install launchd agent: cp "${relative(projectDir, plistPath)}" ~/Library/LaunchAgents/ && launchctl load -w ~/Library/LaunchAgents/${label}.plist`,
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
} else {
|
|
1082
|
+
const cronFile = join(projectDir, ".agents", "schedules", "security-remediation.crontab");
|
|
1083
|
+
writeFileEnsureDir(
|
|
1084
|
+
cronFile,
|
|
1085
|
+
renderCrontabEntry({ scriptAbsPath: resolve(scriptPath), scheduleInfo }),
|
|
1086
|
+
);
|
|
1087
|
+
written.push({ path: cronFile, kind: "crontab snippet" });
|
|
1088
|
+
nextSteps.push(
|
|
1089
|
+
`Add to crontab: (crontab -l 2>/dev/null; cat "${relative(projectDir, cronFile)}") | crontab -`,
|
|
1090
|
+
);
|
|
1091
|
+
}
|
|
1092
|
+
nextSteps.push(
|
|
1093
|
+
`Dry-run test now: AGENT_HARNESS=${harness === "t3" ? "claude" : harness} bash ${relative(projectDir, scriptPath)} --dry-run`,
|
|
1094
|
+
);
|
|
1095
|
+
} else if (schedule === "github-actions") {
|
|
1096
|
+
const wfPath = join(projectDir, ".github", "workflows", "security-remediation-cron.yml");
|
|
1097
|
+
const wfContent = renderGithubActionsWorkflow({
|
|
1098
|
+
pkgName: pkgJson.name,
|
|
1099
|
+
harness,
|
|
1100
|
+
scheduleInfo,
|
|
1101
|
+
promptRelPath,
|
|
1102
|
+
resolvedSkills: selectedSkillInputs,
|
|
1103
|
+
targets,
|
|
1104
|
+
ecosystems: secRepo.ecosystems,
|
|
1105
|
+
});
|
|
1106
|
+
writeFileEnsureDir(wfPath, wfContent);
|
|
1107
|
+
written.push({ path: wfPath, kind: "GitHub Actions cron workflow" });
|
|
1108
|
+
|
|
1109
|
+
const effectiveHarness = harness === "t3" ? "claude" : harness;
|
|
1110
|
+
const primarySecret =
|
|
1111
|
+
effectiveHarness === "codex"
|
|
1112
|
+
? "OPENAI_API_KEY"
|
|
1113
|
+
: effectiveHarness === "generic"
|
|
1114
|
+
? "AGENT_API_KEY (+ repo variable SECURITY_AGENT_CMD)"
|
|
1115
|
+
: "ANTHROPIC_API_KEY (or CLAUDE_CODE_OAUTH_TOKEN)";
|
|
1116
|
+
|
|
1117
|
+
nextSteps.push(`Commit ${promptRelPath}, ${relative(projectDir, wfPath)}, and skillfold.yaml / skillfold.lock.`);
|
|
1118
|
+
nextSteps.push(`Add GitHub Actions secret: ${primarySecret}.`);
|
|
1119
|
+
nextSteps.push(
|
|
1120
|
+
"Optional secret: SECURITY_BOT_PAT (fine-grained PAT with contents:write, pull_requests:write, vulnerability_alerts:read) for Dependabot alerts API & triggering PR CI checks.",
|
|
1121
|
+
);
|
|
1122
|
+
nextSteps.push("Test immediately from GitHub → Actions → Security Remediation Cron → Run workflow (dry_run=true).");
|
|
1123
|
+
} else {
|
|
1124
|
+
nextSteps.push(
|
|
1125
|
+
`Prompt ready at ${promptRelPath}. Feed it to your preferred agent CLI or scheduler.`,
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
console.log("");
|
|
1130
|
+
console.log(c.green(c.bold("security-cron setup complete")));
|
|
1131
|
+
console.log(" Generated artifacts:");
|
|
1132
|
+
for (const item of written) {
|
|
1133
|
+
console.log(` ${c.green("✓")} ${item.path} ${c.dim(`(${item.kind})`)}`);
|
|
1134
|
+
}
|
|
1135
|
+
console.log("");
|
|
1136
|
+
console.log(c.bold("Next steps:"));
|
|
1137
|
+
for (let i = 0; i < nextSteps.length; i++) {
|
|
1138
|
+
console.log(` ${i + 1}. ${nextSteps[i]}`);
|
|
1139
|
+
}
|
|
1140
|
+
}
|