mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-30 03:44:38 +01:00
/cso is gone: the skill, its native helper programs, scanner images, CI jobs, docs and the rest of its tests. Upgrading removes gstack's own `/cso` entries and old helper files, and leaves a skill of your own named `cso` alone. Why: on 52 real security advisories, plainly asking the agent to audit the code caught more than /cso (13 vs 7 on particle-1; 12 vs 8 of 51 on Claude Opus 5.5, within the margin of error). To do: nothing. Optional cleanup of old scanner images and reports is in the changelog entry. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#1 reader=outside-voice Review-Finding: p1/outside-voice#2 reader=outside-voice Review-Finding: p1/adversarial-native#1 reader=adversarial-native Review-Finding: p1/adversarial-native#2 reader=adversarial-native
130 lines
5.4 KiB
TypeScript
130 lines
5.4 KiB
TypeScript
/**
|
|
* Shared discovery for SKILL.md and .tmpl files.
|
|
* Scans root + one level of subdirs, skipping node_modules/.git/dist.
|
|
*/
|
|
|
|
import * as fs from 'fs';
|
|
import * as os from 'os';
|
|
import * as path from 'path';
|
|
import type { HostConfig } from './host-config';
|
|
|
|
const SKIP = new Set(['node_modules', '.git', 'dist']);
|
|
|
|
/**
|
|
* Retired skills: no host registers them, and setup removes an earlier
|
|
* install's gstack-owned entry. investigate was cut after a no-gain eval and
|
|
* its source is gone (GST-1717). verify is now build-check (#4593): the old
|
|
* name hid Claude Code's built-in /verify, so an upgrade removes gstack's old
|
|
* entry and leaves a user's own verify skill. cso was cut after a plain security
|
|
* audit request found more than it did (GST-3920), and its source is gone.
|
|
* setup and gstack-relink read the same list from GSTACK_RETIRED_SKILLS in
|
|
* bin/gstack-install-registry.sh.
|
|
*/
|
|
export const RETIRED_SKILLS = ['investigate', 'verify', 'cso'];
|
|
|
|
/**
|
|
* Old skill name → new name. A user's disabled_skills entry under the old name
|
|
* still turns off the renamed skill (#4593). Same map as GSTACK_RENAMED_SKILLS
|
|
* in bin/gstack-install-registry.sh.
|
|
*/
|
|
export const RENAMED_SKILLS: Readonly<Record<string, string>> = { verify: 'build-check' };
|
|
|
|
/**
|
|
* Skills that install as gstack-<folder> in both prefix modes, because a host
|
|
* keeps the plain name for a built-in: Claude Code's own /ship hides a user
|
|
* skill named ship (#4775). The folder and the internal id stay ship. Same
|
|
* list as GSTACK_PREFIXED_SKILLS in bin/gstack-install-registry.sh.
|
|
*/
|
|
export const PREFIXED_SKILLS = ['ship'];
|
|
|
|
/**
|
|
* Review skills /autoplan reads as a phase methodology from its own directory
|
|
* on external hosts: each renders a second time beside gstack-autoplan/SKILL.md
|
|
* as <name>.md, so /autoplan's phase does not depend on the standalone skill
|
|
* staying installed (GST-1698; the standalone /plan-eng-review returned in
|
|
* GST-2726).
|
|
*/
|
|
export const AUTOPLAN_SIBLING_METHODOLOGIES = ['plan-eng-review'];
|
|
|
|
/**
|
|
* The gstack-on-Capy skills (crew/README.md): registered only on a Capy
|
|
* machine, and kept off every host elsewhere like a retired skill. Same list
|
|
* as GSTACK_CREW_SKILLS in bin/gstack-install-registry.sh, and the same Capy
|
|
* test as its gstack_on_capy.
|
|
*/
|
|
export const CREW_SKILLS = ['captain'];
|
|
|
|
export function onCapyMachine(env: NodeJS.ProcessEnv = process.env, home = os.homedir()): boolean {
|
|
return Boolean(env.CAPY_MACHINE_CONFIG) || fs.existsSync(path.join(home, '.capy'));
|
|
}
|
|
|
|
/** What no host registers on this machine: the retired skills, plus the crew skills off Capy. */
|
|
export function unregisteredSkills(env: NodeJS.ProcessEnv = process.env, home = os.homedir()): string[] {
|
|
return onCapyMachine(env, home) ? RETIRED_SKILLS : [...RETIRED_SKILLS, ...CREW_SKILLS];
|
|
}
|
|
|
|
/** The generator and its coverage checks use the same include-minus-skip rule. */
|
|
export function includesSkill(host: HostConfig, skillDir: string): boolean {
|
|
const { includeSkills, skipSkills } = host.generation;
|
|
return (!includeSkills?.length || includeSkills.includes(skillDir))
|
|
&& !skipSkills?.includes(skillDir);
|
|
}
|
|
|
|
function subdirs(root: string): string[] {
|
|
return fs.readdirSync(root, { withFileTypes: true })
|
|
.filter(d => d.isDirectory() && !d.name.startsWith('.') && !SKIP.has(d.name))
|
|
.map(d => d.name);
|
|
}
|
|
|
|
export function discoverTemplates(root: string): Array<{ tmpl: string; output: string }> {
|
|
const dirs = ['', ...subdirs(root)];
|
|
const results: Array<{ tmpl: string; output: string }> = [];
|
|
for (const dir of dirs) {
|
|
const rel = dir ? `${dir}/SKILL.md.tmpl` : 'SKILL.md.tmpl';
|
|
if (fs.existsSync(path.join(root, rel))) {
|
|
results.push({ tmpl: rel, output: rel.replace(/\.tmpl$/, '') });
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
/**
|
|
* Discover on-demand section templates: `<skill>/sections/*.md.tmpl`.
|
|
*
|
|
* Returns the relative tmpl path, its generated output path (`.tmpl` stripped),
|
|
* and the owning skill directory so the generator can build a TemplateContext
|
|
* with the PARENT skill's name (not "sections") — see processSectionTemplate.
|
|
*
|
|
* Scans one level of subdirs (same depth as discoverTemplates), looking only
|
|
* inside a `sections/` child. Skills without a sections/ dir contribute nothing,
|
|
* so this is a no-op for every skill that hasn't been carved.
|
|
*/
|
|
export function discoverSectionTemplates(
|
|
root: string,
|
|
): Array<{ tmpl: string; output: string; skillDir: string }> {
|
|
const results: Array<{ tmpl: string; output: string; skillDir: string }> = [];
|
|
for (const dir of subdirs(root)) {
|
|
const sectionsDir = path.join(root, dir, 'sections');
|
|
if (!fs.existsSync(sectionsDir) || !fs.statSync(sectionsDir).isDirectory()) continue;
|
|
for (const entry of fs.readdirSync(sectionsDir, { withFileTypes: true })) {
|
|
if (!entry.isFile() || !entry.name.endsWith('.md.tmpl')) continue;
|
|
const rel = `${dir}/sections/${entry.name}`;
|
|
results.push({ tmpl: rel, output: rel.replace(/\.tmpl$/, ''), skillDir: dir });
|
|
}
|
|
}
|
|
// Deterministic order so CI freshness checks don't flap on FS iteration order.
|
|
return results.sort((a, b) => a.tmpl.localeCompare(b.tmpl));
|
|
}
|
|
|
|
export function discoverSkillFiles(root: string): string[] {
|
|
const dirs = ['', ...subdirs(root)];
|
|
const results: string[] = [];
|
|
for (const dir of dirs) {
|
|
const rel = dir ? `${dir}/SKILL.md` : 'SKILL.md';
|
|
if (fs.existsSync(path.join(root, rel))) {
|
|
results.push(rel);
|
|
}
|
|
}
|
|
return results;
|
|
}
|