@brunosouzas/stackledger 0.0.0-stage → 0.4.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.
- package/LICENSE +202 -0
- package/README.md +260 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +97 -0
- package/dist/cli.js.map +1 -0
- package/dist/control.d.ts +2 -0
- package/dist/control.js +22 -0
- package/dist/control.js.map +1 -0
- package/dist/discover-command.d.ts +7 -0
- package/dist/discover-command.js +60 -0
- package/dist/discover-command.js.map +1 -0
- package/dist/discovery/annotations.d.ts +24 -0
- package/dist/discovery/annotations.js +37 -0
- package/dist/discovery/annotations.js.map +1 -0
- package/dist/discovery/host.d.ts +47 -0
- package/dist/discovery/host.js +56 -0
- package/dist/discovery/host.js.map +1 -0
- package/dist/discovery/index.d.ts +15 -0
- package/dist/discovery/index.js +30 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/machine.d.ts +14 -0
- package/dist/discovery/machine.js +17 -0
- package/dist/discovery/machine.js.map +1 -0
- package/dist/discovery/run.d.ts +39 -0
- package/dist/discovery/run.js +130 -0
- package/dist/discovery/run.js.map +1 -0
- package/dist/discovery/snapshot.d.ts +60 -0
- package/dist/discovery/snapshot.js +161 -0
- package/dist/discovery/snapshot.js.map +1 -0
- package/dist/discovery/sources/apps.d.ts +3 -0
- package/dist/discovery/sources/apps.js +136 -0
- package/dist/discovery/sources/apps.js.map +1 -0
- package/dist/discovery/sources/brew.d.ts +15 -0
- package/dist/discovery/sources/brew.js +69 -0
- package/dist/discovery/sources/brew.js.map +1 -0
- package/dist/discovery/sources/common.d.ts +39 -0
- package/dist/discovery/sources/common.js +70 -0
- package/dist/discovery/sources/common.js.map +1 -0
- package/dist/discovery/sources/index.d.ts +8 -0
- package/dist/discovery/sources/index.js +12 -0
- package/dist/discovery/sources/index.js.map +1 -0
- package/dist/discovery/sources/launchd.d.ts +3 -0
- package/dist/discovery/sources/launchd.js +65 -0
- package/dist/discovery/sources/launchd.js.map +1 -0
- package/dist/discovery/sources/mas.d.ts +9 -0
- package/dist/discovery/sources/mas.js +25 -0
- package/dist/discovery/sources/mas.js.map +1 -0
- package/dist/discovery/sources/mise.d.ts +5 -0
- package/dist/discovery/sources/mise.js +64 -0
- package/dist/discovery/sources/mise.js.map +1 -0
- package/dist/discovery/sources/npm.d.ts +12 -0
- package/dist/discovery/sources/npm.js +34 -0
- package/dist/discovery/sources/npm.js.map +1 -0
- package/dist/discovery/sources/pipx.d.ts +4 -0
- package/dist/discovery/sources/pipx.js +82 -0
- package/dist/discovery/sources/pipx.js.map +1 -0
- package/dist/discovery/types.d.ts +73 -0
- package/dist/discovery/types.js +10 -0
- package/dist/discovery/types.js.map +1 -0
- package/dist/discovery/write.d.ts +50 -0
- package/dist/discovery/write.js +196 -0
- package/dist/discovery/write.js.map +1 -0
- package/dist/drift-command.d.ts +62 -0
- package/dist/drift-command.js +375 -0
- package/dist/drift-command.js.map +1 -0
- package/dist/drift-formats.d.ts +3 -0
- package/dist/drift-formats.js +54 -0
- package/dist/drift-formats.js.map +1 -0
- package/dist/drift.d.ts +95 -0
- package/dist/drift.js +206 -0
- package/dist/drift.js.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -0
- package/dist/graph.d.ts +103 -0
- package/dist/graph.js +181 -0
- package/dist/graph.js.map +1 -0
- package/dist/ics.d.ts +18 -0
- package/dist/ics.js +103 -0
- package/dist/ics.js.map +1 -0
- package/dist/identity.d.ts +18 -0
- package/dist/identity.js +36 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/map/badges.d.ts +20 -0
- package/dist/map/badges.js +95 -0
- package/dist/map/badges.js.map +1 -0
- package/dist/map/command.d.ts +8 -0
- package/dist/map/command.js +86 -0
- package/dist/map/command.js.map +1 -0
- package/dist/map/heap.d.ts +15 -0
- package/dist/map/heap.js +57 -0
- package/dist/map/heap.js.map +1 -0
- package/dist/map/ink.d.ts +11 -0
- package/dist/map/ink.js +10 -0
- package/dist/map/ink.js.map +1 -0
- package/dist/map/labels.d.ts +43 -0
- package/dist/map/labels.js +172 -0
- package/dist/map/labels.js.map +1 -0
- package/dist/map/layout.d.ts +59 -0
- package/dist/map/layout.js +197 -0
- package/dist/map/layout.js.map +1 -0
- package/dist/map/model.d.ts +46 -0
- package/dist/map/model.js +84 -0
- package/dist/map/model.js.map +1 -0
- package/dist/map/neighbourhood.d.ts +18 -0
- package/dist/map/neighbourhood.js +138 -0
- package/dist/map/neighbourhood.js.map +1 -0
- package/dist/map/parallel.d.ts +21 -0
- package/dist/map/parallel.js +174 -0
- package/dist/map/parallel.js.map +1 -0
- package/dist/map/relations.d.ts +39 -0
- package/dist/map/relations.js +127 -0
- package/dist/map/relations.js.map +1 -0
- package/dist/map/route.d.ts +25 -0
- package/dist/map/route.js +165 -0
- package/dist/map/route.js.map +1 -0
- package/dist/map/strip.d.ts +29 -0
- package/dist/map/strip.js +122 -0
- package/dist/map/strip.js.map +1 -0
- package/dist/map/suggest.d.ts +21 -0
- package/dist/map/suggest.js +97 -0
- package/dist/map/suggest.js.map +1 -0
- package/dist/map/svg.d.ts +22 -0
- package/dist/map/svg.js +232 -0
- package/dist/map/svg.js.map +1 -0
- package/dist/map/themes.d.ts +61 -0
- package/dist/map/themes.js +78 -0
- package/dist/map/themes.js.map +1 -0
- package/dist/map/xml.d.ts +8 -0
- package/dist/map/xml.js +68 -0
- package/dist/map/xml.js.map +1 -0
- package/dist/map/zones.d.ts +19 -0
- package/dist/map/zones.js +46 -0
- package/dist/map/zones.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +145 -0
- package/dist/mcp.js.map +1 -0
- package/dist/money.d.ts +32 -0
- package/dist/money.js +91 -0
- package/dist/money.js.map +1 -0
- package/dist/report-command.d.ts +3 -0
- package/dist/report-command.js +85 -0
- package/dist/report-command.js.map +1 -0
- package/dist/report-formats.d.ts +11 -0
- package/dist/report-formats.js +157 -0
- package/dist/report-formats.js.map +1 -0
- package/dist/reports.d.ts +105 -0
- package/dist/reports.js +247 -0
- package/dist/reports.js.map +1 -0
- package/dist/scaffold.d.ts +30 -0
- package/dist/scaffold.js +140 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/schema.d.ts +330 -0
- package/dist/schema.js +116 -0
- package/dist/schema.js.map +1 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +68 -0
- package/dist/secrets.js.map +1 -0
- package/dist/site/build.d.ts +22 -0
- package/dist/site/build.js +196 -0
- package/dist/site/build.js.map +1 -0
- package/dist/site/command.d.ts +2 -0
- package/dist/site/command.js +221 -0
- package/dist/site/command.js.map +1 -0
- package/dist/site/data.d.ts +205 -0
- package/dist/site/data.js +241 -0
- package/dist/site/data.js.map +1 -0
- package/dist/site/fs-ops.d.ts +35 -0
- package/dist/site/fs-ops.js +26 -0
- package/dist/site/fs-ops.js.map +1 -0
- package/dist/site/owners.d.ts +5 -0
- package/dist/site/owners.js +50 -0
- package/dist/site/owners.js.map +1 -0
- package/dist/site/paths.d.ts +34 -0
- package/dist/site/paths.js +48 -0
- package/dist/site/paths.js.map +1 -0
- package/dist/site/policy.d.ts +17 -0
- package/dist/site/policy.js +26 -0
- package/dist/site/policy.js.map +1 -0
- package/dist/site/publish.d.ts +14 -0
- package/dist/site/publish.js +90 -0
- package/dist/site/publish.js.map +1 -0
- package/dist/site/relative.d.ts +14 -0
- package/dist/site/relative.js +265 -0
- package/dist/site/relative.js.map +1 -0
- package/dist/site/skills-build.d.ts +22 -0
- package/dist/site/skills-build.js +126 -0
- package/dist/site/skills-build.js.map +1 -0
- package/dist/site/skills-data.d.ts +89 -0
- package/dist/site/skills-data.js +94 -0
- package/dist/site/skills-data.js.map +1 -0
- package/dist/site/staging.d.ts +19 -0
- package/dist/site/staging.js +76 -0
- package/dist/site/staging.js.map +1 -0
- package/dist/skills/command.d.ts +8 -0
- package/dist/skills/command.js +64 -0
- package/dist/skills/command.js.map +1 -0
- package/dist/skills/frontmatter.d.ts +37 -0
- package/dist/skills/frontmatter.js +219 -0
- package/dist/skills/frontmatter.js.map +1 -0
- package/dist/skills/graph.d.ts +39 -0
- package/dist/skills/graph.js +100 -0
- package/dist/skills/graph.js.map +1 -0
- package/dist/skills/ignore.d.ts +34 -0
- package/dist/skills/ignore.js +138 -0
- package/dist/skills/ignore.js.map +1 -0
- package/dist/skills/lines.d.ts +53 -0
- package/dist/skills/lines.js +221 -0
- package/dist/skills/lines.js.map +1 -0
- package/dist/skills/map-command.d.ts +28 -0
- package/dist/skills/map-command.js +533 -0
- package/dist/skills/map-command.js.map +1 -0
- package/dist/skills/mermaid.d.ts +29 -0
- package/dist/skills/mermaid.js +261 -0
- package/dist/skills/mermaid.js.map +1 -0
- package/dist/skills/metro.d.ts +8 -0
- package/dist/skills/metro.js +93 -0
- package/dist/skills/metro.js.map +1 -0
- package/dist/skills/read.d.ts +17 -0
- package/dist/skills/read.js +54 -0
- package/dist/skills/read.js.map +1 -0
- package/dist/skills/rules.d.ts +28 -0
- package/dist/skills/rules.js +57 -0
- package/dist/skills/rules.js.map +1 -0
- package/dist/skills/source.d.ts +66 -0
- package/dist/skills/source.js +281 -0
- package/dist/skills/source.js.map +1 -0
- package/dist/skills/walk.d.ts +64 -0
- package/dist/skills/walk.js +281 -0
- package/dist/skills/walk.js.map +1 -0
- package/dist/source.d.ts +40 -0
- package/dist/source.js +199 -0
- package/dist/source.js.map +1 -0
- package/dist/stdout.d.ts +2 -0
- package/dist/stdout.js +24 -0
- package/dist/stdout.js.map +1 -0
- package/dist/validate.d.ts +45 -0
- package/dist/validate.js +321 -0
- package/dist/validate.js.map +1 -0
- package/dist/views.d.ts +25 -0
- package/dist/views.js +58 -0
- package/dist/views.js.map +1 -0
- package/examples/catalogue-repository/.github/workflows/stackledger.yml +122 -0
- package/examples/catalogue-repository/README.md +96 -0
- package/examples/catalogue-repository/catalog/catalog-info.yaml +12 -0
- package/examples/hosting/Caddyfile +69 -0
- package/examples/northwind/catalog-info.yaml +680 -0
- package/examples/northwind/stackledger.yaml +16 -0
- package/examples/northwind-machine/snapshot.json +309 -0
- package/examples/northwind-skills/agents/builder.md +10 -0
- package/examples/northwind-skills/agents/reviewer.md +10 -0
- package/examples/northwind-skills/designer/SKILL.md +8 -0
- package/examples/northwind-skills/editor/SKILL.md +8 -0
- package/examples/northwind-skills/engineering/SKILL.md +12 -0
- package/examples/northwind-skills/linter/SKILL.md +8 -0
- package/examples/northwind-skills/linter/rules.md +5 -0
- package/examples/northwind-skills/publishing/SKILL.md +12 -0
- package/examples/northwind-skills/publishing/rules.md +5 -0
- package/examples/northwind-skills/spec-writer/SKILL.md +8 -0
- package/examples/northwind-skills/stackledger-skills.yaml +51 -0
- package/examples/northwind-skills/tester/SKILL.md +10 -0
- package/examples/northwind-skills/writer/SKILL.md +8 -0
- package/examples/northwind-skills/writer/rules.md +6 -0
- package/npm-shrinkwrap.json +4995 -0
- package/package.json +51 -4
- package/site/LICENSE-astroplate +21 -0
- package/site/README.md +18 -0
- package/site/package.json +6 -0
- package/site/public/favicon.svg +1 -0
- package/site/src/components/Footer.astro +25 -0
- package/site/src/components/Header.astro +35 -0
- package/site/src/components/Impact.astro +55 -0
- package/site/src/components/LinkOrText.astro +12 -0
- package/site/src/components/SkillItem.astro +141 -0
- package/site/src/components/SubNav.astro +40 -0
- package/site/src/components/ThemeSwitch.astro +16 -0
- package/site/src/components/Themed.astro +14 -0
- package/site/src/layouts/Base.astro +52 -0
- package/site/src/lib/site.ts +25 -0
- package/site/src/pages/[reports].astro +222 -0
- package/site/src/pages/agents/[file].astro +14 -0
- package/site/src/pages/index.astro +71 -0
- package/site/src/pages/journeys/[name].astro +50 -0
- package/site/src/pages/journeys/index.astro +37 -0
- package/site/src/pages/licences/[name].astro +56 -0
- package/site/src/pages/map/index.astro +78 -0
- package/site/src/pages/playbooks/[file].astro +14 -0
- package/site/src/pages/rules/[...rules].astro +61 -0
- package/site/src/pages/skill-map/[...map].astro +101 -0
- package/site/src/pages/skills/[...list].astro +75 -0
- package/site/src/pages/skills/[file].astro +14 -0
- package/site/src/pages/software/[name].astro +155 -0
- package/site/src/pages/software/index.astro +71 -0
- package/site/src/scripts/diagram.ts +8 -0
- package/site/src/scripts/links.ts +31 -0
- package/site/src/scripts/map.ts +133 -0
- package/site/src/scripts/software.ts +32 -0
- package/site/src/scripts/theme.ts +52 -0
- package/site/src/styles/base.css +470 -0
- package/site/src/styles/fonts.css +60 -0
- package/site/src/styles/override.css +1 -0
- package/site/src/styles/pages.css +299 -0
- package/site/src/styles/tokens.css +71 -0
- package/skills/stackledger/SKILL.md +155 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type MapGeometry } from '../map/layout.js';
|
|
2
|
+
import { MAX_SIDE_ITEMS } from '../map/relations.js';
|
|
3
|
+
import { type NodeKind, type RelationKind } from '../skills/graph.js';
|
|
4
|
+
import type { SkillSet } from '../skills/source.js';
|
|
5
|
+
export interface Themed {
|
|
6
|
+
light: string;
|
|
7
|
+
dark: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ItemLink {
|
|
10
|
+
ref: string;
|
|
11
|
+
name: string;
|
|
12
|
+
kind: NodeKind;
|
|
13
|
+
href: string;
|
|
14
|
+
}
|
|
15
|
+
export interface RelationLink extends ItemLink {
|
|
16
|
+
relation: RelationKind;
|
|
17
|
+
}
|
|
18
|
+
export interface LineChip {
|
|
19
|
+
ref: string;
|
|
20
|
+
slug: string;
|
|
21
|
+
title: string;
|
|
22
|
+
badge: string;
|
|
23
|
+
color: string;
|
|
24
|
+
badgeSvg: string;
|
|
25
|
+
}
|
|
26
|
+
export interface RuleRow {
|
|
27
|
+
id: string;
|
|
28
|
+
group: string;
|
|
29
|
+
text: string;
|
|
30
|
+
why: string;
|
|
31
|
+
check: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SkillItemPage extends ItemLink {
|
|
34
|
+
file: string;
|
|
35
|
+
description: string;
|
|
36
|
+
/** Absent when a side has more than MAX_SIDE_ITEMS relations; `relationCount` says how many there are. */
|
|
37
|
+
diagram?: Themed;
|
|
38
|
+
relationCount: number;
|
|
39
|
+
broughtInBy: RelationLink[];
|
|
40
|
+
bringsIn: RelationLink[];
|
|
41
|
+
reachedThrough: ItemLink[];
|
|
42
|
+
lines: LineChip[];
|
|
43
|
+
rules: RuleRow[];
|
|
44
|
+
files: string[];
|
|
45
|
+
}
|
|
46
|
+
export interface SkillsRow extends ItemLink {
|
|
47
|
+
description: string;
|
|
48
|
+
rules: number;
|
|
49
|
+
}
|
|
50
|
+
export interface RuleIndexRow {
|
|
51
|
+
id: string;
|
|
52
|
+
text: string;
|
|
53
|
+
group: string;
|
|
54
|
+
owner: ItemLink;
|
|
55
|
+
}
|
|
56
|
+
export interface SkillsData {
|
|
57
|
+
counts: {
|
|
58
|
+
skills: number;
|
|
59
|
+
playbooks: number;
|
|
60
|
+
agents: number;
|
|
61
|
+
rules: number;
|
|
62
|
+
};
|
|
63
|
+
rows: SkillsRow[];
|
|
64
|
+
items: SkillItemPage[];
|
|
65
|
+
rules: RuleIndexRow[];
|
|
66
|
+
map: Themed & {
|
|
67
|
+
empty: boolean;
|
|
68
|
+
lines: (LineChip & {
|
|
69
|
+
stops: ItemLink[];
|
|
70
|
+
})[];
|
|
71
|
+
zones: {
|
|
72
|
+
name: string;
|
|
73
|
+
title: string;
|
|
74
|
+
}[];
|
|
75
|
+
symbols: (Themed & {
|
|
76
|
+
label: string;
|
|
77
|
+
})[];
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** A description for a page: one line, cleaned, cut to 1,023 code points and `…` when longer than 1,024. */
|
|
81
|
+
export declare function descriptionLine(text: string): string;
|
|
82
|
+
/** The page of an item, from the site's root: kind folder and page file name. */
|
|
83
|
+
export declare const itemHref: (kind: NodeKind, name: string) => string;
|
|
84
|
+
/** The page data of a skill set, and the skills map's geometry for the build report. */
|
|
85
|
+
export declare function buildSkillsData(set: SkillSet): {
|
|
86
|
+
data: SkillsData;
|
|
87
|
+
geometry: MapGeometry;
|
|
88
|
+
};
|
|
89
|
+
export { MAX_SIDE_ITEMS };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** SkillsData: the plain JSON object the Skills pages read (skills-site spec), built once per build
|
|
2
|
+
* from one skill set and copied into every view's SiteData, so the Skills pages' `main` is the same in
|
|
3
|
+
* the `full` and `staff` sites. Call buildSkillsData(set).
|
|
4
|
+
*
|
|
5
|
+
* Why: pages never import the skills code. Every text, link, list and SVG they show is prepared here:
|
|
6
|
+
* - Relations and "Reached through" come from src/skills/graph.ts, as `stackledger skills map` draws them.
|
|
7
|
+
* - Links are paths from the site's root without a leading slash, under the kind folders with the item's
|
|
8
|
+
* page file name (`skills/writer/`), so every URL is lowercase ASCII and no name collides with a page.
|
|
9
|
+
* - Text is cleaned of control and format characters; descriptions are one line, cut at 1,024 code points.
|
|
10
|
+
* - A source file is shown as its path below its given folder; no absolute path or folder argument is
|
|
11
|
+
* ever put in the data, so the output does not depend on where the folders are.
|
|
12
|
+
* Nothing comes from the catalogue view, so the staff guarantees are untouched.
|
|
13
|
+
*/
|
|
14
|
+
import { compareText } from '../identity.js';
|
|
15
|
+
import { layoutMap } from '../map/layout.js';
|
|
16
|
+
import { relations, renderRelations, MAX_SIDE_ITEMS } from '../map/relations.js';
|
|
17
|
+
import { renderLineBadge } from '../map/strip.js';
|
|
18
|
+
import { renderSvg, renderSymbol } from '../map/svg.js';
|
|
19
|
+
import { inkOf, themes, widestInk } from '../map/themes.js';
|
|
20
|
+
import { buildGraph, compareListed, incoming, outgoing, reachedThrough } from '../skills/graph.js';
|
|
21
|
+
import { KIND_FOLDERS, pageFileName } from '../skills/mermaid.js';
|
|
22
|
+
import { buildSkillsMapModel, cleanText, stationRef } from '../skills/metro.js';
|
|
23
|
+
const UNSAFE = /[\p{Cc}\p{Cf}]/gu;
|
|
24
|
+
const MAX_DESCRIPTION_CODE_POINTS = 1024;
|
|
25
|
+
/** A description for a page: one line, cleaned, cut to 1,023 code points and `…` when longer than 1,024. */
|
|
26
|
+
export function descriptionLine(text) {
|
|
27
|
+
const points = Array.from(text.replace(/\s+/g, ' ').replace(UNSAFE, '').trim());
|
|
28
|
+
return points.length > MAX_DESCRIPTION_CODE_POINTS ? points.slice(0, MAX_DESCRIPTION_CODE_POINTS - 1).join('') + '…' : points.join('');
|
|
29
|
+
}
|
|
30
|
+
/** The page of an item, from the site's root: kind folder and page file name. */
|
|
31
|
+
export const itemHref = (kind, name) => `${KIND_FOLDERS[kind]}/${pageFileName(name)}/`;
|
|
32
|
+
const link = (node) => ({ ref: stationRef(node.kind, node.name), name: cleanText(node.name), kind: node.kind, href: itemHref(node.kind, node.name) });
|
|
33
|
+
const themed = (render) => ({ light: render(themes.light), dark: render(themes.dark) });
|
|
34
|
+
/** The page data of a skill set, and the skills map's geometry for the build report. */
|
|
35
|
+
export function buildSkillsData(set) {
|
|
36
|
+
const graph = buildGraph(set);
|
|
37
|
+
const model = buildSkillsMapModel(set);
|
|
38
|
+
// Both themes from one geometry laid out with the widest ink, as the software map page does.
|
|
39
|
+
const ink = widestInk(inkOf(themes.light), inkOf(themes.dark));
|
|
40
|
+
const geometry = layoutMap(model, themes.light.lineWidth, ink);
|
|
41
|
+
const darkGeometry = themes.dark.lineWidth === themes.light.lineWidth ? geometry : layoutMap(model, themes.dark.lineWidth, ink);
|
|
42
|
+
const stations = new Map(model.stations.map(station => [station.ref, station]));
|
|
43
|
+
const chip = (line) => ({ ref: line.ref, slug: line.name.toLowerCase(), title: line.title, badge: line.badge, color: line.color, badgeSvg: renderLineBadge(line) });
|
|
44
|
+
const stopLink = (ref) => {
|
|
45
|
+
const station = stations.get(ref);
|
|
46
|
+
const kind = ref.slice(0, ref.indexOf(':'));
|
|
47
|
+
return { ref, name: cleanText(station.name), kind, href: itemHref(kind, station.name) };
|
|
48
|
+
};
|
|
49
|
+
const sources = new Map();
|
|
50
|
+
for (const skill of set.skills)
|
|
51
|
+
sources.set(`${skill.kind}:${skill.name}`, skill);
|
|
52
|
+
for (const agent of set.agents)
|
|
53
|
+
sources.set(`agent:${agent.name}`, agent);
|
|
54
|
+
const listed = [...graph.nodes].sort(compareListed);
|
|
55
|
+
const items = listed.map(node => {
|
|
56
|
+
const source = sources.get(`${node.kind}:${node.name}`);
|
|
57
|
+
const ref = stationRef(node.kind, node.name);
|
|
58
|
+
const near = relations(graph, node);
|
|
59
|
+
const left = incoming(graph, node), right = outgoing(graph, node);
|
|
60
|
+
const rules = 'rules' in source ? source.rules : [];
|
|
61
|
+
return {
|
|
62
|
+
...link(node), file: pageFileName(node.name), description: descriptionLine(node.description),
|
|
63
|
+
...(near ? { diagram: themed(theme => renderRelations(near, theme)) } : {}), relationCount: left.length + right.length,
|
|
64
|
+
broughtInBy: left.map(edge => ({ ...link(edge.from), relation: edge.kind })),
|
|
65
|
+
bringsIn: right.map(edge => ({ ...link(edge.to), relation: edge.kind })),
|
|
66
|
+
reachedThrough: reachedThrough(graph, node).map(link),
|
|
67
|
+
lines: model.lines.filter(line => line.stops.includes(ref)).map(chip),
|
|
68
|
+
rules: rules.map(rule => ({ id: cleanText(rule.id), group: cleanText(rule.group ?? ''), text: cleanText(rule.text), why: cleanText(rule.why ?? ''), check: cleanText(rule.check ?? '') })),
|
|
69
|
+
files: source.files.map(file => cleanText(file.below)),
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
const rules = items.flatMap(item => item.rules.map(rule => ({ id: rule.id, text: rule.text, group: rule.group,
|
|
73
|
+
owner: { ref: item.ref, name: item.name, kind: item.kind, href: item.href } })))
|
|
74
|
+
.sort((one, two) => compareText(one.id, two.id) || compareText(one.owner.name, two.owner.name));
|
|
75
|
+
const count = (kind) => graph.nodes.filter(node => node.kind === kind).length;
|
|
76
|
+
return {
|
|
77
|
+
data: {
|
|
78
|
+
counts: { skills: count('skill'), playbooks: count('playbook'), agents: count('agent'), rules: rules.length },
|
|
79
|
+
rows: items.map(item => ({ ref: item.ref, name: item.name, kind: item.kind, href: item.href, description: item.description, rules: item.rules.length })),
|
|
80
|
+
items, rules,
|
|
81
|
+
map: {
|
|
82
|
+
light: renderSvg(geometry, themes.light, { chrome: false }),
|
|
83
|
+
dark: renderSvg(darkGeometry, themes.dark, { chrome: false }),
|
|
84
|
+
empty: model.lines.length === 0,
|
|
85
|
+
lines: model.lines.map(line => ({ ...chip(line), stops: line.stops.map(stopLink) })),
|
|
86
|
+
zones: geometry.zones.map(zone => ({ name: zone.name, title: zone.title })),
|
|
87
|
+
symbols: geometry.legend.symbols.map(symbol => ({ label: symbol[0].toUpperCase() + symbol.slice(1), ...themed(theme => renderSymbol(symbol, theme)) })),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
geometry,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export { MAX_SIDE_ITEMS };
|
|
94
|
+
//# sourceMappingURL=skills-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills-data.js","sourceRoot":"","sources":["../../src/site/skills-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAoB,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAc,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAkD,MAAM,oBAAoB,CAAC;AACnJ,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAA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I,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;gBAC3E,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aACzJ;SACF;QACD,QAAQ;KACT,CAAC;AACJ,CAAC;AACD,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type FsOps } from './fs-ops.js';
|
|
2
|
+
import { type FolderIdentity } from './paths.js';
|
|
3
|
+
/** Prefix of the staging folders inside the output folder. */
|
|
4
|
+
export declare const STAGING_PREFIX = ".stackledger-tmp-";
|
|
5
|
+
/** Folder of the staging folder that holds the entries a publication replaces. */
|
|
6
|
+
export declare const OLD_NAME = "old";
|
|
7
|
+
/** Empty file in the staging folder of a personal build (spec.sites: [full]): it has no staff site,
|
|
8
|
+
* so its publication only moves an earlier `staff` into `old/`, and the manual restore keeps a
|
|
9
|
+
* `staff` it finds in the output folder. */
|
|
10
|
+
export declare const FULL_ONLY = "full-only";
|
|
11
|
+
/** Where a reader learns to restore an output folder by hand. */
|
|
12
|
+
export declare const RESTORE_GUIDE = "docs/site.md, section \"Restoring after a failed publication\"";
|
|
13
|
+
/** The staging folders among `names` (the entries of `out`) that a build may remove. Throws,
|
|
14
|
+
* changing nothing, an InternalError (exit 1) when one holds `old/`, or a usage error (exit 2) when
|
|
15
|
+
* a `.stackledger-tmp-*` entry is a link or not a folder. */
|
|
16
|
+
export declare function staleStaging(out: string, names: readonly string[], ops?: FsOps): string[];
|
|
17
|
+
/** Remove the stale staging folders found by staleStaging. Each is looked at again, and the output
|
|
18
|
+
* folder's identity checked, immediately before its removal. */
|
|
19
|
+
export declare function removeStaging(paths: readonly string[], identity: FolderIdentity, ops?: FsOps): void;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Staging folders left in the output folder by earlier builds (build-command, Interrupted
|
|
2
|
+
* publication; design D8). Called by src/site/command.ts before anything changes.
|
|
3
|
+
*
|
|
4
|
+
* A staging folder `<out>/.stackledger-tmp-*` gets an `old/` folder just before publication's first
|
|
5
|
+
* rename (publish.ts). So a staging folder without `old/` holds only fresh output from a build that
|
|
6
|
+
* crashed or failed before publishing, and is removed. One with `old/` may hold the only copy of the
|
|
7
|
+
* previous build: the command refuses the whole output folder (exit 1), changes nothing and points
|
|
8
|
+
* to the manual restore in docs/site.md. stackledger never moves entries back by itself: code review
|
|
9
|
+
* showed that automatic recovery from what a staging folder says is itself a way to lose the site.
|
|
10
|
+
*
|
|
11
|
+
* Nothing here follows a symbolic link: every entry is looked at with lstat, a `.stackledger-tmp-*`
|
|
12
|
+
* entry that is a link or a file is refused (exit 2), and a folder is removed with rm, which removes
|
|
13
|
+
* links inside it without following them. An `old` entry that cannot be looked at counts as present.
|
|
14
|
+
*/
|
|
15
|
+
import { basename, join } from 'node:path';
|
|
16
|
+
import { InternalError } from '../errors.js';
|
|
17
|
+
import { NODE_FS } from './fs-ops.js';
|
|
18
|
+
import { assertSameFolder, lstatOrUndefined } from './paths.js';
|
|
19
|
+
/** Prefix of the staging folders inside the output folder. */
|
|
20
|
+
export const STAGING_PREFIX = '.stackledger-tmp-';
|
|
21
|
+
/** Folder of the staging folder that holds the entries a publication replaces. */
|
|
22
|
+
export const OLD_NAME = 'old';
|
|
23
|
+
/** Empty file in the staging folder of a personal build (spec.sites: [full]): it has no staff site,
|
|
24
|
+
* so its publication only moves an earlier `staff` into `old/`, and the manual restore keeps a
|
|
25
|
+
* `staff` it finds in the output folder. */
|
|
26
|
+
export const FULL_ONLY = 'full-only';
|
|
27
|
+
/** Where a reader learns to restore an output folder by hand. */
|
|
28
|
+
export const RESTORE_GUIDE = 'docs/site.md, section "Restoring after a failed publication"';
|
|
29
|
+
/** True unless `staging` certainly has no `old` entry (of any kind: folder, file or link). */
|
|
30
|
+
function hasOld(staging, ops) {
|
|
31
|
+
try {
|
|
32
|
+
ops.lstat(join(staging, OLD_NAME));
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return error.code !== 'ENOENT';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function stagingState(path, ops) {
|
|
40
|
+
const stats = lstatOrUndefined(path, ops);
|
|
41
|
+
if (!stats)
|
|
42
|
+
return 'gone';
|
|
43
|
+
if (!stats.isDirectory())
|
|
44
|
+
return 'not-a-folder';
|
|
45
|
+
return hasOld(path, ops) ? 'publication' : 'stale';
|
|
46
|
+
}
|
|
47
|
+
/** The staging folders among `names` (the entries of `out`) that a build may remove. Throws,
|
|
48
|
+
* changing nothing, an InternalError (exit 1) when one holds `old/`, or a usage error (exit 2) when
|
|
49
|
+
* a `.stackledger-tmp-*` entry is a link or not a folder. */
|
|
50
|
+
export function staleStaging(out, names, ops = NODE_FS) {
|
|
51
|
+
const paths = names.filter(name => name.startsWith(STAGING_PREFIX)).sort().map(name => join(out, name));
|
|
52
|
+
const states = paths.map(path => ({ path, state: stagingState(path, ops) }));
|
|
53
|
+
const kept = states.find(({ state }) => state === 'publication');
|
|
54
|
+
if (kept) {
|
|
55
|
+
throw new InternalError(`stackledger build: ${kept.path} holds entries that an earlier publication replaced (its ${OLD_NAME}/ folder); nothing was changed. Restore them by hand as ${RESTORE_GUIDE} explains, then remove that folder`);
|
|
56
|
+
}
|
|
57
|
+
const foreign = states.find(({ state }) => state === 'not-a-folder');
|
|
58
|
+
if (foreign) {
|
|
59
|
+
throw new Error(`Output folder entry ${basename(foreign.path)} is a symbolic link or not a folder; stackledger build removes only its own staging folders, so remove it by hand`);
|
|
60
|
+
}
|
|
61
|
+
return states.filter(({ state }) => state === 'stale').map(({ path }) => path);
|
|
62
|
+
}
|
|
63
|
+
/** Remove the stale staging folders found by staleStaging. Each is looked at again, and the output
|
|
64
|
+
* folder's identity checked, immediately before its removal. */
|
|
65
|
+
export function removeStaging(paths, identity, ops = NODE_FS) {
|
|
66
|
+
for (const path of paths) {
|
|
67
|
+
const state = stagingState(path, ops);
|
|
68
|
+
if (state === 'gone')
|
|
69
|
+
continue;
|
|
70
|
+
if (state !== 'stale')
|
|
71
|
+
throw new InternalError(`stackledger build: ${path} changed during the build; stopped without further changes`);
|
|
72
|
+
assertSameFolder(identity, ops);
|
|
73
|
+
ops.rm(path);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=staging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staging.js","sourceRoot":"","sources":["../../src/site/staging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAc,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAuB,MAAM,YAAY,CAAC;AAErF,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAElD,kFAAkF;AAClF,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,CAAC;AAE9B;;4CAE4C;AAC5C,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AAErC,iEAAiE;AACjE,MAAM,CAAC,MAAM,aAAa,GAAG,8DAA8D,CAAC;AAK5F,8FAA8F;AAC9F,SAAS,MAAM,CAAC,OAAe,EAAE,GAAU;IACzC,IAAI,CAAC;QACH,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;QACnC,OA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O,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,KAAK,cAAc,CAAC,CAAC;IACrE,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,mHAAmH,CAAC,CAAC;IACpL,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;AACjF,CAAC;AAED;gEACgE;AAChE,MAAM,UAAU,aAAa,CAAC,KAAwB,EAAE,QAAwB,EAAE,MAAa,OAAO;IACpG,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACtC,IAAI,KAAK,KAAK,MAAM;YAAE,SAAS;QAC/B,IAAI,KAAK,KAAK,OAAO;YAAE,MAAM,IAAI,aAAa,CAAC,sBAAsB,IAAI,4DAA4D,CAAC,CAAC;QACvI,gBAAgB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAChC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type SkillSet } from './source.js';
|
|
2
|
+
/** The default output: one line per problem, then the counts. */
|
|
3
|
+
export declare function formatText(set: Pick<SkillSet, 'problems' | 'summary'>): string;
|
|
4
|
+
/** The `--json` output: problems, the paths skipped by ignore files and the summary, in that order, with
|
|
5
|
+
* U+007F–U+009F escaped. */
|
|
6
|
+
export declare function formatJson(set: Pick<SkillSet, 'problems' | 'ignored' | 'summary'>): string;
|
|
7
|
+
/** Run `stackledger skills …` with the whole argument list (`skills` first). */
|
|
8
|
+
export declare function skillsCommand(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** `stackledger skills validate [folder...] [--json]` (skills-validate-command spec), and the dispatch
|
|
2
|
+
* of `stackledger skills map` to src/skills/map-command.ts (skills-map-command spec). Called by
|
|
3
|
+
* src/cli.ts; run `node dist/cli.js skills validate /path/to/skills`.
|
|
4
|
+
*
|
|
5
|
+
* Reads the given folders (none: the current folder) as one skill set through src/skills/source.ts and
|
|
6
|
+
* prints its problems: one line each and a counts line (`ignored` counts the entries skipped by
|
|
7
|
+
* `.stackledgerignore` files), or one JSON object with `--json`. Exit 0 with
|
|
8
|
+
* no error (warnings allowed), 1 with at least one error. A usage error or a given folder that cannot
|
|
9
|
+
* be checked throws a plain Error before anything is written, so src/cli.ts prints the reason and the
|
|
10
|
+
* usage on stderr and exits 2 with stdout empty; any other failure (an ignore file matcher that throws,
|
|
11
|
+
* say) is an InternalError (exit 1).
|
|
12
|
+
*
|
|
13
|
+
* Text lines lose their control characters and JSON has U+007F–U+009F as `\u` escapes (src/control.ts),
|
|
14
|
+
* because folder and file names come from outside and may hold ESC or U+009B. Only reads; no network.
|
|
15
|
+
*/
|
|
16
|
+
import { parseArgs } from 'node:util';
|
|
17
|
+
import { escapeJsonControls, withoutControls } from '../control.js';
|
|
18
|
+
import { internal } from '../errors.js';
|
|
19
|
+
import { writeStdout } from '../stdout.js';
|
|
20
|
+
import { readSkillSet } from './source.js';
|
|
21
|
+
import { SkillsFolderError } from './walk.js';
|
|
22
|
+
const SUBCOMMANDS = ['validate', 'map'];
|
|
23
|
+
/** The default output: one line per problem, then the counts. */
|
|
24
|
+
export function formatText(set) {
|
|
25
|
+
const lines = set.problems.map(p => withoutControls(`${p.path}:${p.line}:${p.column} ${p.severity} ${p.field ?? '-'} ${p.message}`));
|
|
26
|
+
const s = set.summary;
|
|
27
|
+
lines.push(`skills: ${s.skills}, playbooks: ${s.playbooks}, agents: ${s.agents}, rules: ${s.rules}, ignored: ${s.ignored}, errors: ${s.errors}, warnings: ${s.warnings}`);
|
|
28
|
+
return lines.join('\n') + '\n';
|
|
29
|
+
}
|
|
30
|
+
/** The `--json` output: problems, the paths skipped by ignore files and the summary, in that order, with
|
|
31
|
+
* U+007F–U+009F escaped. */
|
|
32
|
+
export function formatJson(set) {
|
|
33
|
+
return escapeJsonControls(JSON.stringify({ problems: set.problems, ignored: set.ignored, summary: set.summary })) + '\n';
|
|
34
|
+
}
|
|
35
|
+
/** Run `stackledger skills …` with the whole argument list (`skills` first). */
|
|
36
|
+
export async function skillsCommand(args) {
|
|
37
|
+
// `skills map` parses its own options strictly; the non-strict parse only finds the subcommand, so
|
|
38
|
+
// validate keeps its exact checks and messages below.
|
|
39
|
+
const found = parseArgs({ args, strict: false, allowPositionals: true, options: { json: { type: 'boolean' }, out: { type: 'string' }, check: { type: 'boolean' } } });
|
|
40
|
+
if (found.positionals[1] === 'map') {
|
|
41
|
+
const { skillsMapCommand } = await import('./map-command.js');
|
|
42
|
+
await skillsMapCommand(args);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// An unknown option (named in parseArgs' message) is a usage error, thrown before anything is read.
|
|
46
|
+
const { values, positionals } = parseArgs({ args, strict: true, allowPositionals: true, options: { json: { type: 'boolean' } } });
|
|
47
|
+
const [, subcommand, ...folders] = positionals;
|
|
48
|
+
if (subcommand === undefined)
|
|
49
|
+
throw new Error(`A skills subcommand is required; expected ${SUBCOMMANDS.join(', ')}`);
|
|
50
|
+
if (!SUBCOMMANDS.includes(subcommand))
|
|
51
|
+
throw new Error(`Unknown skills subcommand '${subcommand}'; expected ${SUBCOMMANDS.join(', ')}`);
|
|
52
|
+
let set;
|
|
53
|
+
try {
|
|
54
|
+
set = await readSkillSet(folders);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof SkillsFolderError)
|
|
58
|
+
throw new Error(error.message);
|
|
59
|
+
throw internal('skills validate', error);
|
|
60
|
+
}
|
|
61
|
+
await writeStdout(values.json ? formatJson(set) : formatText(set), 'stackledger skills validate: cannot write the output');
|
|
62
|
+
process.exitCode = set.summary.errors ? 1 : 0;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/skills/command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,WAAW,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAExC,iEAAiE;AACjE,MAAM,UAAU,UAAU,CAAC,GAA2C;IACpE,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACrI,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;IACtB,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,gBAAgB,CAAC,CAAC,SAAS,aAAa,CAAC,CAAC,MAAM,YAAY,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,eAAe,CAAC,CAAC,QAAQ,E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C,GAAG,WAAW,CAAC;IAC/C,IAAI,UAAU,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrH,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,UAAU,eAAe,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxI,IAAI,GAAa,CAAC;IAClB,IAAI,CAAC;QAAC,GAAG,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC;IAAC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACxD,IAAI,KAAK,YAAY,iBAAiB;YAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACvE,MAAM,QAAQ,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,sDAAsD,CAAC,CAAC;IAC3H,OAAO,CAAC,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type FieldPath, type Problem, type Source } from '../source.js';
|
|
2
|
+
export declare const KIND_KEY = "stackledger-kind";
|
|
3
|
+
export declare const SKILLS_KEY = "stackledger-skills";
|
|
4
|
+
export declare const AGENTS_KEY = "stackledger-agents";
|
|
5
|
+
export type SkillKind = 'skill' | 'playbook';
|
|
6
|
+
export type Frontmatter = Source;
|
|
7
|
+
export type FrontmatterResult = {
|
|
8
|
+
status: 'read';
|
|
9
|
+
frontmatter: Frontmatter;
|
|
10
|
+
}
|
|
11
|
+
/** The file does not start with a `---` line (an agent file then gets a warning instead of an error). */
|
|
12
|
+
| {
|
|
13
|
+
status: 'absent';
|
|
14
|
+
problem: Problem;
|
|
15
|
+
} | {
|
|
16
|
+
status: 'invalid';
|
|
17
|
+
problem: Problem;
|
|
18
|
+
};
|
|
19
|
+
/** Split and parse the frontmatter block of a file's text. */
|
|
20
|
+
export declare function readFrontmatter(path: string, text: string): FrontmatterResult;
|
|
21
|
+
/** A problem at a field's value (or key), or at `1:1` when the field is absent. */
|
|
22
|
+
export declare function at(frontmatter: Frontmatter, path: FieldPath, message: string, severity?: Problem['severity'], key?: boolean): Problem;
|
|
23
|
+
/** Step 5: `name` and `description` must be non-empty strings; both are reported. */
|
|
24
|
+
export declare function checkNameAndDescription(frontmatter: Frontmatter): Problem[];
|
|
25
|
+
export interface SkillFields {
|
|
26
|
+
problems: Problem[];
|
|
27
|
+
kind: SkillKind;
|
|
28
|
+
}
|
|
29
|
+
/** Step 6 for a skill: specification checks, outside fields, metadata and relation keys; all reported. */
|
|
30
|
+
export declare function checkSkillFields(frontmatter: Frontmatter, folderName: string): SkillFields;
|
|
31
|
+
/** Step 6 for an agent: `skills`, when present, must be a list of strings; returns the preloads read. */
|
|
32
|
+
export declare function checkAgentFields(frontmatter: Frontmatter): {
|
|
33
|
+
problems: Problem[];
|
|
34
|
+
preloads: string[];
|
|
35
|
+
};
|
|
36
|
+
/** Names of a relation value: separated by any whitespace; a blank string declares none. */
|
|
37
|
+
export declare function relationNames(value: string): string[];
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/** Frontmatter of `SKILL.md` and agent files, and the checks of one file's fields (skill-source spec:
|
|
2
|
+
* Frontmatter, Name and description, Agent Skills specification checks, Fields outside the
|
|
3
|
+
* specification, Relation keys). Used by src/skills/source.ts; pure functions, no I/O.
|
|
4
|
+
*
|
|
5
|
+
* Positions: the frontmatter is parsed as the file's text with its opening `---` line replaced by an
|
|
6
|
+
* empty line, so the parser's line and column are the file's own. A missing field and a whole-file
|
|
7
|
+
* problem are at `1:1` (unlike the catalogue's problem(), which uses the start of the mapping).
|
|
8
|
+
*
|
|
9
|
+
* A file whose frontmatter is absent, unclosed, not one YAML mapping or has duplicate keys gets
|
|
10
|
+
* exactly one error at `1:1` with a fixed message: parser messages can quote the file, and a value
|
|
11
|
+
* that breaks a secret rule must never reach the output.
|
|
12
|
+
*/
|
|
13
|
+
import { isMap, isScalar, LineCounter, parseAllDocuments } from 'yaml';
|
|
14
|
+
import { compareText } from '../identity.js';
|
|
15
|
+
import { fieldName, fileProblem, resolveNode, sourceNode } from '../source.js';
|
|
16
|
+
const BYTE_ORDER_MARK = '\uFEFF';
|
|
17
|
+
const FENCE_LINE = '---';
|
|
18
|
+
/** Top-level fields the Agent Skills specification allows. */
|
|
19
|
+
const SPECIFICATION_FIELDS = new Set(['name', 'description', 'license', 'compatibility', 'metadata', 'allowed-tools']);
|
|
20
|
+
const MAX_NAME_CODE_POINTS = 64;
|
|
21
|
+
const MAX_DESCRIPTION_CODE_POINTS = 1024;
|
|
22
|
+
const MAX_COMPATIBILITY_CODE_POINTS = 500;
|
|
23
|
+
const RELATION_PREFIX = 'stackledger-';
|
|
24
|
+
export const KIND_KEY = 'stackledger-kind';
|
|
25
|
+
export const SKILLS_KEY = 'stackledger-skills';
|
|
26
|
+
export const AGENTS_KEY = 'stackledger-agents';
|
|
27
|
+
const RELATION_KEYS = new Set([KIND_KEY, SKILLS_KEY, AGENTS_KEY]);
|
|
28
|
+
const KINDS = ['skill', 'playbook'];
|
|
29
|
+
/** Split and parse the frontmatter block of a file's text. */
|
|
30
|
+
export function readFrontmatter(path, text) {
|
|
31
|
+
const body = text.startsWith(BYTE_ORDER_MARK) ? text.slice(1) : text;
|
|
32
|
+
const opening = /^---\r?\n/.exec(body);
|
|
33
|
+
if (!opening) {
|
|
34
|
+
const unclosed = body === FENCE_LINE || body === `${FENCE_LINE}\r`;
|
|
35
|
+
return unclosed ? { status: 'invalid', problem: fileProblem(path, 'Frontmatter is not closed by a --- line') }
|
|
36
|
+
: { status: 'absent', problem: fileProblem(path, 'File has no frontmatter: the first line must be ---') };
|
|
37
|
+
}
|
|
38
|
+
let start = opening[0].length, close = -1;
|
|
39
|
+
while (start <= body.length) {
|
|
40
|
+
const end = body.indexOf('\n', start);
|
|
41
|
+
const line = body.slice(start, end < 0 ? body.length : end);
|
|
42
|
+
if (line === FENCE_LINE || line === `${FENCE_LINE}\r`) {
|
|
43
|
+
close = start;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
if (end < 0)
|
|
47
|
+
break;
|
|
48
|
+
start = end + 1;
|
|
49
|
+
}
|
|
50
|
+
if (close < 0)
|
|
51
|
+
return { status: 'invalid', problem: fileProblem(path, 'Frontmatter is not closed by a --- line') };
|
|
52
|
+
// The opening line becomes an empty line, so positions in the parsed text are positions in the file.
|
|
53
|
+
const yamlText = '\n' + body.slice(opening[0].length, close);
|
|
54
|
+
const counter = new LineCounter();
|
|
55
|
+
const documents = parseAllDocuments(yamlText, { lineCounter: counter, prettyErrors: false, uniqueKeys: true, logLevel: 'silent' });
|
|
56
|
+
const list = Array.isArray(documents) ? documents : [];
|
|
57
|
+
const error = list.flatMap(document => document.errors)[0];
|
|
58
|
+
// Only the parser's stable error code is shown: its message can quote the file.
|
|
59
|
+
if (error)
|
|
60
|
+
return { status: 'invalid', problem: fileProblem(path, `Frontmatter is not valid YAML (${error.code})`) };
|
|
61
|
+
const document = list[0];
|
|
62
|
+
if (list.length !== 1 || !document || !isMap(document.contents)) {
|
|
63
|
+
return { status: 'invalid', problem: fileProblem(path, 'Frontmatter must be one YAML mapping') };
|
|
64
|
+
}
|
|
65
|
+
let value;
|
|
66
|
+
try {
|
|
67
|
+
value = document.toJS({ maxAliasCount: 100 });
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return { status: 'invalid', problem: fileProblem(path, 'Frontmatter cannot be expanded safely') };
|
|
71
|
+
}
|
|
72
|
+
return { status: 'read', frontmatter: { path, document: document, counter, value } };
|
|
73
|
+
}
|
|
74
|
+
/** A problem at a field's value (or key), or at `1:1` when the field is absent. */
|
|
75
|
+
export function at(frontmatter, path, message, severity = 'error', key = false) {
|
|
76
|
+
const node = sourceNode(frontmatter, path, key);
|
|
77
|
+
const offset = node?.range?.[0];
|
|
78
|
+
const position = offset === undefined ? { line: 1, col: 1 } : frontmatter.counter.linePos(offset);
|
|
79
|
+
return { path: frontmatter.path, line: position.line, column: position.col, severity, field: fieldName(path), message };
|
|
80
|
+
}
|
|
81
|
+
function codePoints(text) {
|
|
82
|
+
return Array.from(text).length;
|
|
83
|
+
}
|
|
84
|
+
/** A plain YAML mapping. `!!omap`, `!!pairs` and `!!set` decode to `Map` or `Set` objects and are not
|
|
85
|
+
* accepted, so a relation written inside one is reported instead of silently skipped. */
|
|
86
|
+
function isMapping(value) {
|
|
87
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
88
|
+
return false;
|
|
89
|
+
const prototype = Object.getPrototypeOf(value);
|
|
90
|
+
return prototype === Object.prototype || prototype === null;
|
|
91
|
+
}
|
|
92
|
+
/** Step 5: `name` and `description` must be non-empty strings; both are reported. */
|
|
93
|
+
export function checkNameAndDescription(frontmatter) {
|
|
94
|
+
const problems = [];
|
|
95
|
+
for (const field of ['name', 'description']) {
|
|
96
|
+
if (!Object.hasOwn(frontmatter.value, field))
|
|
97
|
+
problems.push(at(frontmatter, [field], `${field} is required`));
|
|
98
|
+
else {
|
|
99
|
+
const value = frontmatter.value[field];
|
|
100
|
+
if (typeof value !== 'string' || !value)
|
|
101
|
+
problems.push(at(frontmatter, [field], `${field} must be a non-empty string`));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return problems;
|
|
105
|
+
}
|
|
106
|
+
/** Warnings on the name's format: the specification's rules, applied after NFKC normalisation. */
|
|
107
|
+
function nameFormat(name) {
|
|
108
|
+
const normalised = name.normalize('NFKC');
|
|
109
|
+
const messages = [];
|
|
110
|
+
if (codePoints(normalised) > MAX_NAME_CODE_POINTS)
|
|
111
|
+
messages.push(`name is longer than ${MAX_NAME_CODE_POINTS} characters`);
|
|
112
|
+
if (/[\p{Lu}\p{Lt}]/u.test(normalised))
|
|
113
|
+
messages.push('name has an upper-case letter');
|
|
114
|
+
if (!/^[\p{L}\p{N}-]*$/u.test(normalised))
|
|
115
|
+
messages.push('name may hold only letters, digits and hyphens');
|
|
116
|
+
if (normalised.startsWith('-') || normalised.endsWith('-'))
|
|
117
|
+
messages.push('name starts or ends with a hyphen');
|
|
118
|
+
if (normalised.includes('--'))
|
|
119
|
+
messages.push('name holds two hyphens in a row');
|
|
120
|
+
return messages;
|
|
121
|
+
}
|
|
122
|
+
/** Step 6 for a skill: specification checks, outside fields, metadata and relation keys; all reported. */
|
|
123
|
+
export function checkSkillFields(frontmatter, folderName) {
|
|
124
|
+
const problems = [];
|
|
125
|
+
const value = frontmatter.value;
|
|
126
|
+
const name = value.name, description = value.description;
|
|
127
|
+
for (const message of nameFormat(name))
|
|
128
|
+
problems.push(at(frontmatter, ['name'], message, 'warning'));
|
|
129
|
+
// Compared without normalisation: the tool looks the folder up by its exact name.
|
|
130
|
+
if (name !== folderName)
|
|
131
|
+
problems.push(at(frontmatter, ['name'], `name differs from the folder name ${folderName}`, 'warning'));
|
|
132
|
+
if (codePoints(description) > MAX_DESCRIPTION_CODE_POINTS) {
|
|
133
|
+
problems.push(at(frontmatter, ['description'], `description is longer than ${MAX_DESCRIPTION_CODE_POINTS} characters`, 'warning'));
|
|
134
|
+
}
|
|
135
|
+
if (Object.hasOwn(value, 'compatibility')) {
|
|
136
|
+
const compatibility = value.compatibility;
|
|
137
|
+
if (typeof compatibility !== 'string' || codePoints(compatibility) < 1 || codePoints(compatibility) > MAX_COMPATIBILITY_CODE_POINTS) {
|
|
138
|
+
problems.push(at(frontmatter, ['compatibility'], `compatibility must be a string of 1 to ${MAX_COMPATIBILITY_CODE_POINTS} characters`, 'warning'));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const field of ['license', 'allowed-tools']) {
|
|
142
|
+
if (Object.hasOwn(value, field) && typeof value[field] !== 'string')
|
|
143
|
+
problems.push(at(frontmatter, [field], `${field} must be a string`, 'warning'));
|
|
144
|
+
}
|
|
145
|
+
const outside = Object.keys(value).filter(key => !SPECIFICATION_FIELDS.has(key)).sort(compareText);
|
|
146
|
+
if (outside.length) {
|
|
147
|
+
problems.push({ ...fileProblem(frontmatter.path, `Fields outside the Agent Skills specification: ${outside.join(', ')}`, 'warning') });
|
|
148
|
+
}
|
|
149
|
+
let kind = 'skill';
|
|
150
|
+
if (Object.hasOwn(value, 'metadata')) {
|
|
151
|
+
if (!isMapping(value.metadata))
|
|
152
|
+
problems.push(at(frontmatter, ['metadata'], 'metadata must be a mapping of strings', 'warning'));
|
|
153
|
+
else
|
|
154
|
+
kind = checkMetadata(frontmatter, problems);
|
|
155
|
+
}
|
|
156
|
+
return { problems, kind };
|
|
157
|
+
}
|
|
158
|
+
/** A problem at a node of the frontmatter (a key or value as written), or at `1:1` without one. */
|
|
159
|
+
function atNode(frontmatter, node, path, message, severity = 'error') {
|
|
160
|
+
const offset = node?.range?.[0];
|
|
161
|
+
const position = offset === undefined ? { line: 1, col: 1 } : frontmatter.counter.linePos(offset);
|
|
162
|
+
return { path: frontmatter.path, line: position.line, column: position.col, severity, field: fieldName(path), message };
|
|
163
|
+
}
|
|
164
|
+
/** Metadata keys and values; returns the kind (`skill` when absent or invalid). Positions are those of
|
|
165
|
+
* the key or value as written (an alias where one is used); types are those of the resolved node. */
|
|
166
|
+
function checkMetadata(frontmatter, problems) {
|
|
167
|
+
let kind = 'skill';
|
|
168
|
+
const mapping = resolveNode(frontmatter, sourceNode(frontmatter, ['metadata']));
|
|
169
|
+
if (!isMap(mapping))
|
|
170
|
+
return kind;
|
|
171
|
+
const values = frontmatter.value.metadata;
|
|
172
|
+
for (const pair of mapping.items) {
|
|
173
|
+
const keyNode = pair.key, valueNode = pair.value;
|
|
174
|
+
const key = resolveNode(frontmatter, keyNode);
|
|
175
|
+
if (!isScalar(key) || typeof key.value !== 'string') {
|
|
176
|
+
// The field is written from the key's text, so `42:` is `metadata.42`.
|
|
177
|
+
const text = isScalar(key) ? (key.source ?? String(key.value)) : String(key);
|
|
178
|
+
problems.push(atNode(frontmatter, keyNode, ['metadata', text], 'metadata key must be a string', 'warning'));
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const name = key.value;
|
|
182
|
+
const path = ['metadata', name];
|
|
183
|
+
const value = values[name];
|
|
184
|
+
if (name.toLowerCase().startsWith(RELATION_PREFIX)) {
|
|
185
|
+
if (!RELATION_KEYS.has(name)) {
|
|
186
|
+
problems.push(atNode(frontmatter, keyNode, path, `Unknown key; expected ${KIND_KEY}, ${SKILLS_KEY} or ${AGENTS_KEY}`));
|
|
187
|
+
}
|
|
188
|
+
else if (typeof value !== 'string') {
|
|
189
|
+
problems.push(atNode(frontmatter, valueNode, path, name === KIND_KEY ? `${KIND_KEY} must be skill or playbook`
|
|
190
|
+
: `${name} must be a string of names separated by spaces`));
|
|
191
|
+
}
|
|
192
|
+
else if (name === KIND_KEY) {
|
|
193
|
+
if (KINDS.includes(value))
|
|
194
|
+
kind = value;
|
|
195
|
+
else
|
|
196
|
+
problems.push(atNode(frontmatter, valueNode, path, `${KIND_KEY} must be skill or playbook`));
|
|
197
|
+
}
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (typeof value !== 'string')
|
|
201
|
+
problems.push(atNode(frontmatter, valueNode, path, 'metadata values must be strings', 'warning'));
|
|
202
|
+
}
|
|
203
|
+
return kind;
|
|
204
|
+
}
|
|
205
|
+
/** Step 6 for an agent: `skills`, when present, must be a list of strings; returns the preloads read. */
|
|
206
|
+
export function checkAgentFields(frontmatter) {
|
|
207
|
+
if (!Object.hasOwn(frontmatter.value, 'skills'))
|
|
208
|
+
return { problems: [], preloads: [] };
|
|
209
|
+
const skills = frontmatter.value.skills;
|
|
210
|
+
if (!Array.isArray(skills) || !skills.every(item => typeof item === 'string')) {
|
|
211
|
+
return { problems: [at(frontmatter, ['skills'], 'skills must be a list of skill names', 'warning')], preloads: [] };
|
|
212
|
+
}
|
|
213
|
+
return { problems: [], preloads: skills };
|
|
214
|
+
}
|
|
215
|
+
/** Names of a relation value: separated by any whitespace; a blank string declares none. */
|
|
216
|
+
export function relationNames(value) {
|
|
217
|
+
return value.split(/\s+/).filter(Boolean);
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=frontmatter.js.map
|