@witchpot/gmc 0.6.0 → 0.9.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/CHANGELOG.md +88 -0
- package/README.md +3 -0
- package/package.json +2 -3
- package/skill/gmc-analysis/CHANGELOG.md +197 -0
- package/skill/gmc-analysis/SKILL.md +411 -7
- package/skill/gmc-analysis.manifest.json +2 -2
- package/src/args.js +42 -4
- package/src/constants.js +23 -3
- package/src/help.js +238 -1
- package/src/index.js +1 -0
- package/src/main.js +7 -1
- package/src/main.test.js +130 -0
- package/src/projection.js +21 -0
- package/src/requests.js +474 -2
- package/src/requests.test.js +1065 -0
- package/src/workflows.js +15 -1
- package/src/workflows.test.js +156 -0
- package/scripts/check-release-readiness.mjs +0 -177
- package/scripts/gen-skill-manifest.mjs +0 -151
- package/scripts/smoke-beta.mjs +0 -246
- package/scripts/smoke-pack.mjs +0 -123
package/src/workflows.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
composeResolvePayload,
|
|
12
12
|
composeReviewPatternsPayload,
|
|
13
13
|
composeShowcaseFitPayload,
|
|
14
|
+
composeShowcaseHistoryPayload,
|
|
14
15
|
getPreferredShowcaseTags,
|
|
15
16
|
mergeSearchPages
|
|
16
17
|
} from "@witchpot/gmc-core";
|
|
@@ -22,7 +23,8 @@ export {
|
|
|
22
23
|
composeComparePayload,
|
|
23
24
|
composeResolvePayload,
|
|
24
25
|
composeReviewPatternsPayload,
|
|
25
|
-
composeShowcaseFitPayload
|
|
26
|
+
composeShowcaseFitPayload,
|
|
27
|
+
composeShowcaseHistoryPayload
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
export async function executeRequestPlan(baseUrl, request, { apiKey }) {
|
|
@@ -47,6 +49,9 @@ export async function executeRequestPlan(baseUrl, request, { apiKey }) {
|
|
|
47
49
|
if (request.kind === "showcaseFit") {
|
|
48
50
|
return executeShowcaseFitRequest(baseUrl, request, { apiKey });
|
|
49
51
|
}
|
|
52
|
+
if (request.kind === "showcaseHistory") {
|
|
53
|
+
return executeShowcaseHistoryRequest(baseUrl, request, { apiKey });
|
|
54
|
+
}
|
|
50
55
|
|
|
51
56
|
const response = await fetchJson(createRequestUrl(baseUrl, request), {
|
|
52
57
|
apiKey,
|
|
@@ -240,6 +245,15 @@ async function executeShowcaseFitRequest(baseUrl, request, { apiKey }) {
|
|
|
240
245
|
});
|
|
241
246
|
}
|
|
242
247
|
|
|
248
|
+
async function executeShowcaseHistoryRequest(baseUrl, request, { apiKey }) {
|
|
249
|
+
const detailRequest = {
|
|
250
|
+
path: `/api/v1/steam/games/${encodeURIComponent(request.externalId)}/analysis`,
|
|
251
|
+
query: request.detailQuery
|
|
252
|
+
};
|
|
253
|
+
const detail = await fetchJson(createRequestUrl(baseUrl, detailRequest), { apiKey });
|
|
254
|
+
return composeShowcaseHistoryPayload(request, { detail });
|
|
255
|
+
}
|
|
256
|
+
|
|
243
257
|
async function executeSearchPages(baseUrl, searchRequest, sampling, { apiKey }) {
|
|
244
258
|
if (!sampling) {
|
|
245
259
|
return {
|
package/src/workflows.test.js
CHANGED
|
@@ -152,6 +152,162 @@ test("executeRequestPlan normalizes list game resolution for cohort workflows",
|
|
|
152
152
|
}
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
+
test("games language-topics passes the insufficient-evidence envelope through untouched", async () => {
|
|
156
|
+
// NAK-455: the CLI is a transport for this endpoint. Evidence state,
|
|
157
|
+
// coverage, denominators, and the raw/weighted split must arrive exactly as
|
|
158
|
+
// the API produced them — an insufficient_evidence answer must never be
|
|
159
|
+
// flattened into empty rows or a zero.
|
|
160
|
+
const envelope = {
|
|
161
|
+
data: {
|
|
162
|
+
appid: 730,
|
|
163
|
+
evidenceState: "insufficient_evidence",
|
|
164
|
+
snapshot: {
|
|
165
|
+
periodStart: "2026-02-06",
|
|
166
|
+
periodEnd: "2026-08-06",
|
|
167
|
+
analysisVersion: "v1",
|
|
168
|
+
generatedAt: "2026-08-06T04:00:00.000Z"
|
|
169
|
+
},
|
|
170
|
+
estimateCaveat: "Weighted values are estimates.",
|
|
171
|
+
coverage: {
|
|
172
|
+
totalRows: 226,
|
|
173
|
+
rowsAtThreshold: 0,
|
|
174
|
+
languagesAtThreshold: 0,
|
|
175
|
+
topicsAtThreshold: 0,
|
|
176
|
+
appliedMinReviews: 30,
|
|
177
|
+
insufficientRowsReturned: 1,
|
|
178
|
+
insufficientRowsTruncated: false
|
|
179
|
+
},
|
|
180
|
+
rows: [
|
|
181
|
+
{
|
|
182
|
+
appid: 730,
|
|
183
|
+
clusterId: 11,
|
|
184
|
+
topic: "performance",
|
|
185
|
+
language: "german",
|
|
186
|
+
counts: {
|
|
187
|
+
sourceReviews: 400,
|
|
188
|
+
sampledReviews: 90,
|
|
189
|
+
analyzedReviews: 21,
|
|
190
|
+
distinctReviews: 12
|
|
191
|
+
},
|
|
192
|
+
estimates: { samplingWeightMethod: "source_over_analyzed_by_language_voted_up_v1" },
|
|
193
|
+
evidence: { minimumN: 30, status: "insufficient_evidence", meetsRequestedThreshold: false }
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
},
|
|
197
|
+
meta: { requestId: "req_test" },
|
|
198
|
+
warnings: []
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const originalFetch = globalThis.fetch;
|
|
202
|
+
const seenUrls = [];
|
|
203
|
+
globalThis.fetch = async (url) => {
|
|
204
|
+
seenUrls.push(String(url));
|
|
205
|
+
return jsonResponse(envelope);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
const payload = await executeRequestPlan("https://gamemarketcopilot.com", {
|
|
210
|
+
path: "/api/v1/steam/games/730/review-topics/languages",
|
|
211
|
+
query: { include_insufficient: "true" }
|
|
212
|
+
}, { apiKey: "gmck_test" });
|
|
213
|
+
|
|
214
|
+
assert.deepEqual(payload, envelope);
|
|
215
|
+
assert.equal(payload.data.evidenceState, "insufficient_evidence");
|
|
216
|
+
assert.equal(payload.data.coverage.totalRows, 226);
|
|
217
|
+
assert.equal(payload.data.rows[0].counts.distinctReviews, 12);
|
|
218
|
+
assert.deepEqual(seenUrls, [
|
|
219
|
+
"https://gamemarketcopilot.com/api/v1/steam/games/730/review-topics/languages?include_insufficient=true"
|
|
220
|
+
]);
|
|
221
|
+
} finally {
|
|
222
|
+
globalThis.fetch = originalFetch;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("games review-history passes the three arrays through untouched", async () => {
|
|
227
|
+
// NAK-428: the CLI is a transport for this endpoint. An empty events or
|
|
228
|
+
// discountWindows array is a COLLECTION state the agent has to see as-is —
|
|
229
|
+
// the CLI must never drop, merge, or window the arrays, and must never turn
|
|
230
|
+
// an unmatched (open) discount window into a closed one.
|
|
231
|
+
const envelope = {
|
|
232
|
+
data: {
|
|
233
|
+
series: [
|
|
234
|
+
{ date: "2026-08-01", totalReviews: 1000 },
|
|
235
|
+
{ date: "2026-08-03", totalReviews: 1040 }
|
|
236
|
+
],
|
|
237
|
+
events: [
|
|
238
|
+
{ type: "release", date: "2026-07-01" },
|
|
239
|
+
{
|
|
240
|
+
type: "announcement",
|
|
241
|
+
date: "2026-08-02",
|
|
242
|
+
count: 3,
|
|
243
|
+
label: "Patch 1.2 is live",
|
|
244
|
+
url: "https://store.steampowered.com/news/app/730/view/1"
|
|
245
|
+
}
|
|
246
|
+
],
|
|
247
|
+
discountWindows: [
|
|
248
|
+
{ startDate: "2026-08-01", endDate: "2026-08-05", discountPercent: 33 },
|
|
249
|
+
{ startDate: "2026-08-20", endDate: null, discountPercent: null }
|
|
250
|
+
]
|
|
251
|
+
},
|
|
252
|
+
meta: { requestId: "req_test" },
|
|
253
|
+
warnings: []
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const originalFetch = globalThis.fetch;
|
|
257
|
+
const seenUrls = [];
|
|
258
|
+
globalThis.fetch = async (url) => {
|
|
259
|
+
seenUrls.push(String(url));
|
|
260
|
+
return jsonResponse(envelope);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
const payload = await executeRequestPlan("https://gamemarketcopilot.com", {
|
|
265
|
+
path: "/api/v1/steam/games/730/review-history",
|
|
266
|
+
query: {}
|
|
267
|
+
}, { apiKey: "gmck_test" });
|
|
268
|
+
|
|
269
|
+
assert.deepEqual(payload, envelope);
|
|
270
|
+
// The gap between 08-01 and 08-03 survives: collection gaps are real and
|
|
271
|
+
// consumers must scale by date, not by array index.
|
|
272
|
+
assert.deepEqual(payload.data.series.map((point) => point.date), ["2026-08-01", "2026-08-03"]);
|
|
273
|
+
assert.equal(payload.data.discountWindows[1].endDate, null);
|
|
274
|
+
// No query string appended for an endpoint that takes no parameters.
|
|
275
|
+
assert.deepEqual(seenUrls, [
|
|
276
|
+
"https://gamemarketcopilot.com/api/v1/steam/games/730/review-history"
|
|
277
|
+
]);
|
|
278
|
+
} finally {
|
|
279
|
+
globalThis.fetch = originalFetch;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test("games review-history passes an all-empty payload through as-is", async () => {
|
|
284
|
+
// Empty arrays mean "nothing collected", never "nothing happened". The CLI
|
|
285
|
+
// must hand the agent the same empty arrays the API produced rather than
|
|
286
|
+
// omitting the keys, which would read as absent fields.
|
|
287
|
+
const envelope = {
|
|
288
|
+
data: { series: [], events: [], discountWindows: [] },
|
|
289
|
+
meta: { requestId: "req_test" },
|
|
290
|
+
warnings: ["static_fixture_data"]
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const originalFetch = globalThis.fetch;
|
|
294
|
+
globalThis.fetch = async () => jsonResponse(envelope);
|
|
295
|
+
|
|
296
|
+
try {
|
|
297
|
+
const payload = await executeRequestPlan("https://gamemarketcopilot.com", {
|
|
298
|
+
path: "/api/v1/steam/games/730/review-history",
|
|
299
|
+
query: {}
|
|
300
|
+
}, { apiKey: "gmck_test" });
|
|
301
|
+
|
|
302
|
+
assert.deepEqual(payload, envelope);
|
|
303
|
+
assert.deepEqual(payload.data.events, []);
|
|
304
|
+
assert.deepEqual(payload.data.discountWindows, []);
|
|
305
|
+
assert.deepEqual(payload.warnings, ["static_fixture_data"]);
|
|
306
|
+
} finally {
|
|
307
|
+
globalThis.fetch = originalFetch;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
155
311
|
function jsonResponse(payload, status = 200) {
|
|
156
312
|
return {
|
|
157
313
|
ok: status >= 200 && status < 300,
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { spawnSync } from "node:child_process";
|
|
4
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
|
|
7
|
-
const packageDir = path.resolve(new URL("..", import.meta.url).pathname);
|
|
8
|
-
const packageJsonPath = path.join(packageDir, "package.json");
|
|
9
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
10
|
-
|
|
11
|
-
const requiredFiles = [
|
|
12
|
-
"bin/gmc.mjs",
|
|
13
|
-
"src/index.js",
|
|
14
|
-
"src/main.js",
|
|
15
|
-
"src/requests.js",
|
|
16
|
-
"src/workflows.js",
|
|
17
|
-
"skill/gmc-analysis/SKILL.md",
|
|
18
|
-
"skill/gmc-analysis/references/recipes.md",
|
|
19
|
-
"skill/gmc-analysis/references/pitfalls.md",
|
|
20
|
-
"skill/gmc-analysis/references/validity.md",
|
|
21
|
-
"skill/gmc-analysis/references/quota.md",
|
|
22
|
-
"skill/gmc-analysis/references/charts.md",
|
|
23
|
-
"skill/gmc-analysis/CHANGELOG.md",
|
|
24
|
-
"README.md",
|
|
25
|
-
"CHANGELOG.md"
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
const requiredFileGlobs = ["bin", "src", "scripts", "skill", "README.md", "CHANGELOG.md"];
|
|
29
|
-
const forbiddenPatterns = [
|
|
30
|
-
{ pattern: /@supabase\//, message: "CLI package must not import Supabase SDKs." },
|
|
31
|
-
{ pattern: /@clerk\//, message: "CLI package must not import Clerk SDKs." },
|
|
32
|
-
{ pattern: /src\/server|server\/gmc|server-only/, message: "CLI package must not import server-only app code." },
|
|
33
|
-
{ pattern: /SUPABASE_[A-Z0-9_]*|CLERK_[A-Z0-9_]*|STRIPE_[A-Z0-9_]*/, message: "CLI package must not reference server secret environment variables." }
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
const sourceFiles = [
|
|
37
|
-
"bin/gmc.mjs",
|
|
38
|
-
"src/index.js",
|
|
39
|
-
"src/args.js",
|
|
40
|
-
"src/browser-login.js",
|
|
41
|
-
"src/config.js",
|
|
42
|
-
"src/constants.js",
|
|
43
|
-
"src/help.js",
|
|
44
|
-
"src/main.js",
|
|
45
|
-
"src/output.js",
|
|
46
|
-
"src/projection.js",
|
|
47
|
-
"src/requests.js",
|
|
48
|
-
"src/workflows.js"
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
const failures = [];
|
|
52
|
-
|
|
53
|
-
if (packageJson.private === true) {
|
|
54
|
-
failures.push("packages/gmc-cli/package.json must not have private:true for beta publishing.");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (packageJson.name !== "@witchpot/gmc") {
|
|
58
|
-
failures.push(`Unexpected package name: ${packageJson.name}`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (packageJson.publishConfig?.access !== "public") {
|
|
62
|
-
failures.push("publishConfig.access must be public for npm beta-tag publishing.");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
for (const binName of ["gmc", "gmcp", "game-market-copilot"]) {
|
|
66
|
-
if (packageJson.bin?.[binName] !== "bin/gmc.mjs") {
|
|
67
|
-
failures.push(`bin.${binName} must point to bin/gmc.mjs.`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (packageJson.main !== "./src/index.js") {
|
|
72
|
-
failures.push("main must point to ./src/index.js.");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (packageJson.exports?.["."] !== "./src/index.js") {
|
|
76
|
-
failures.push("exports['.'] must point to ./src/index.js.");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
for (const required of requiredFileGlobs) {
|
|
80
|
-
if (!packageJson.files?.includes(required)) {
|
|
81
|
-
failures.push(`package.json files must include ${required}.`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
for (const file of requiredFiles) {
|
|
86
|
-
if (!existsSync(path.join(packageDir, file))) {
|
|
87
|
-
failures.push(`Missing required package file: ${file}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const constantsPath = path.join(packageDir, "src/constants.js");
|
|
92
|
-
const constantsSource = readFileSync(constantsPath, "utf8");
|
|
93
|
-
const versionMatch = constantsSource.match(/CLI_VERSION\s*=\s*"([^"]+)"/);
|
|
94
|
-
if (!versionMatch) {
|
|
95
|
-
failures.push("src/constants.js must export a string CLI_VERSION.");
|
|
96
|
-
} else if (versionMatch[1] !== packageJson.version) {
|
|
97
|
-
failures.push(`CLI_VERSION (${versionMatch[1]}) must match package version (${packageJson.version}).`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const changelog = readFileSync(path.join(packageDir, "CHANGELOG.md"), "utf8");
|
|
101
|
-
if (!changelog.includes(`## ${packageJson.version} -`)) {
|
|
102
|
-
failures.push(`CHANGELOG.md must include a section for ${packageJson.version}.`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const skillSource = readFileSync(path.join(packageDir, "skill/gmc-analysis/SKILL.md"), "utf8");
|
|
106
|
-
const skillVersionMatch = skillSource.match(/^\s*version:\s*"?([0-9][0-9A-Za-z.\-]*)"?\s*$/m);
|
|
107
|
-
if (!skillVersionMatch) {
|
|
108
|
-
failures.push("skill/gmc-analysis/SKILL.md must declare metadata.version in its frontmatter.");
|
|
109
|
-
} else {
|
|
110
|
-
const skillChangelog = readFileSync(path.join(packageDir, "skill/gmc-analysis/CHANGELOG.md"), "utf8");
|
|
111
|
-
if (!skillChangelog.includes(`## ${skillVersionMatch[1]} -`)) {
|
|
112
|
-
failures.push(`skill CHANGELOG.md must include a section for skill version ${skillVersionMatch[1]}.`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
for (const file of sourceFiles) {
|
|
117
|
-
const source = readFileSync(path.join(packageDir, file), "utf8");
|
|
118
|
-
for (const forbidden of forbiddenPatterns) {
|
|
119
|
-
if (forbidden.pattern.test(source)) {
|
|
120
|
-
failures.push(`${file}: ${forbidden.message}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// The skill content-hash manifest (NAK-190) is also enforced by
|
|
126
|
-
// src/skill-manifest.test.js, but release:check/prepublishOnly run WITHOUT
|
|
127
|
-
// the test suite — recheck here so a stale manifest can never reach npm.
|
|
128
|
-
const { buildSkillManifest, MANIFEST_PATH } = await import("./gen-skill-manifest.mjs");
|
|
129
|
-
if (!existsSync(MANIFEST_PATH)) {
|
|
130
|
-
failures.push("skill/gmc-analysis.manifest.json is missing — run npm run skill:manifest.");
|
|
131
|
-
} else {
|
|
132
|
-
const committedManifest = JSON.parse(readFileSync(MANIFEST_PATH, "utf8"));
|
|
133
|
-
const currentManifest = buildSkillManifest();
|
|
134
|
-
if (
|
|
135
|
-
committedManifest.contentHash !== currentManifest.contentHash ||
|
|
136
|
-
committedManifest.version !== currentManifest.version
|
|
137
|
-
) {
|
|
138
|
-
failures.push(
|
|
139
|
-
"skill/gmc-analysis.manifest.json is stale: bump metadata.version in SKILL.md, run npm run skill:manifest, and re-sync the gmc-agent-skills distribution repo."
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// The public distribution repo (github.com/witchpot-studio/gmc-agent-skills)
|
|
145
|
-
// mirrors skill/gmc-analysis. When it is checked out as a workspace sibling,
|
|
146
|
-
// a drift between the two is a release blocker — MCP-only users install the
|
|
147
|
-
// skill from that repo and must get the same content the npm package ships.
|
|
148
|
-
const explicitAgentSkillsDir = process.env.GMC_AGENT_SKILLS_DIR;
|
|
149
|
-
const agentSkillsRepo =
|
|
150
|
-
explicitAgentSkillsDir ?? path.join(packageDir, "..", "..", "..", "gmc-agent-skills");
|
|
151
|
-
const agentSkillsSyncScript = path.join(agentSkillsRepo, "scripts", "sync-from-cli.mjs");
|
|
152
|
-
if (explicitAgentSkillsDir && !existsSync(agentSkillsSyncScript)) {
|
|
153
|
-
failures.push(
|
|
154
|
-
`GMC_AGENT_SKILLS_DIR is set but ${agentSkillsSyncScript} does not exist — fix the path or unset the variable.`
|
|
155
|
-
);
|
|
156
|
-
} else if (existsSync(agentSkillsSyncScript)) {
|
|
157
|
-
const drift = spawnSync(process.execPath, ["scripts/sync-from-cli.mjs", "--check"], {
|
|
158
|
-
cwd: agentSkillsRepo,
|
|
159
|
-
encoding: "utf8",
|
|
160
|
-
// Pin the canonical source to THIS checkout — the sync script's own
|
|
161
|
-
// default (../GMC relative to the skills repo) could silently compare
|
|
162
|
-
// against a different GMC checkout.
|
|
163
|
-
env: { ...process.env, GMC_REPO_DIR: path.join(packageDir, "..", "..") }
|
|
164
|
-
});
|
|
165
|
-
if (drift.status !== 0) {
|
|
166
|
-
failures.push(
|
|
167
|
-
`gmc-agent-skills repo has drifted from skill/gmc-analysis — run node scripts/sync-from-cli.mjs there.\n${(drift.stderr || "").trim()}`
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (failures.length > 0) {
|
|
173
|
-
process.stderr.write(`GMC CLI release readiness failed:\n${failures.map((failure) => `- ${failure}`).join("\n")}\n`);
|
|
174
|
-
process.exit(1);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
process.stdout.write(`GMC CLI release readiness ok: ${packageJson.name}@${packageJson.version}\n`);
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// Regenerates skill/gmc-analysis.manifest.json — a content-hash fingerprint
|
|
4
|
-
// of the packaged gmc-analysis skill (SKILL.md + references/ + CHANGELOG.md).
|
|
5
|
-
//
|
|
6
|
-
// Maintainer rule: any time skill/gmc-analysis/** content changes, bump
|
|
7
|
-
// metadata.version in SKILL.md, then run `npm run skill:manifest` (in
|
|
8
|
-
// packages/gmc-cli) to regenerate this manifest, and re-sync the
|
|
9
|
-
// gmc-agent-skills distribution repo (node scripts/sync-from-cli.mjs there).
|
|
10
|
-
// src/skill-manifest.test.js recomputes the same hash on every
|
|
11
|
-
// `npm run test:cli` / `npm run verify` and fails loudly if it no longer
|
|
12
|
-
// matches the committed manifest — this is the drift guard that would have
|
|
13
|
-
// caught the unversioned charts.md changes in PR #18 / PR #43 (NAK-190).
|
|
14
|
-
//
|
|
15
|
-
// The manifest is written OUTSIDE skill/gmc-analysis/ on purpose: that
|
|
16
|
-
// directory is mirrored byte-for-byte into the public gmc-agent-skills
|
|
17
|
-
// distribution repo, and the manifest must never be part of (or affect the
|
|
18
|
-
// hash of) the content it describes.
|
|
19
|
-
|
|
20
|
-
import { spawnSync } from "node:child_process";
|
|
21
|
-
import { createHash } from "node:crypto";
|
|
22
|
-
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
23
|
-
import path from "node:path";
|
|
24
|
-
import { fileURLToPath } from "node:url";
|
|
25
|
-
|
|
26
|
-
const packageDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
27
|
-
export const SKILL_DIR = path.join(packageDir, "skill", "gmc-analysis");
|
|
28
|
-
export const MANIFEST_PATH = path.join(packageDir, "skill", "gmc-analysis.manifest.json");
|
|
29
|
-
|
|
30
|
-
/** List every file under `dir`, as sorted relative POSIX paths. */
|
|
31
|
-
export function listSkillFiles(dir = SKILL_DIR) {
|
|
32
|
-
const results = [];
|
|
33
|
-
walk(dir, dir, results);
|
|
34
|
-
return results.sort();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function walk(root, current, results) {
|
|
38
|
-
const entries = readdirSync(current, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
39
|
-
for (const entry of entries) {
|
|
40
|
-
const abs = path.join(current, entry.name);
|
|
41
|
-
if (entry.isDirectory()) {
|
|
42
|
-
walk(root, abs, results);
|
|
43
|
-
} else if (entry.isFile()) {
|
|
44
|
-
results.push(path.relative(root, abs).split(path.sep).join("/"));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function sha256Hex(buffer) {
|
|
50
|
-
return createHash("sha256").update(buffer).digest("hex");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Hash every file under `dir` and fold the per-file hashes into one
|
|
55
|
-
* top-level sha256 over `relpath\nfilehash\n` lines (sorted, deterministic).
|
|
56
|
-
*/
|
|
57
|
-
export function computeSkillContentHash(dir = SKILL_DIR) {
|
|
58
|
-
const files = listSkillFiles(dir);
|
|
59
|
-
const digest = createHash("sha256");
|
|
60
|
-
for (const relPath of files) {
|
|
61
|
-
const fileHash = sha256Hex(readFileSync(path.join(dir, relPath)));
|
|
62
|
-
digest.update(`${relPath}\n${fileHash}\n`);
|
|
63
|
-
}
|
|
64
|
-
return { contentHash: digest.digest("hex"), files: files.length };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Parse metadata.version out of SKILL.md source text; undefined when absent. */
|
|
68
|
-
export function parseSkillVersion(source) {
|
|
69
|
-
const frontmatter = source.match(/^---\n([\s\S]*?)\n---/);
|
|
70
|
-
return frontmatter?.[1].match(/^\s*version:\s*"?([0-9][0-9A-Za-z.\-]*)"?\s*$/m)?.[1];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Read metadata.version from SKILL.md's YAML frontmatter. */
|
|
74
|
-
export function readSkillManifestVersion(dir = SKILL_DIR) {
|
|
75
|
-
const version = parseSkillVersion(readFileSync(path.join(dir, "SKILL.md"), "utf8"));
|
|
76
|
-
if (!version) {
|
|
77
|
-
throw new Error(`${path.join(dir, "SKILL.md")} must declare metadata.version in its frontmatter.`);
|
|
78
|
-
}
|
|
79
|
-
return version;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Build the manifest object (version + contentHash + files) for `dir`. */
|
|
83
|
-
export function buildSkillManifest(dir = SKILL_DIR) {
|
|
84
|
-
const { contentHash, files } = computeSkillContentHash(dir);
|
|
85
|
-
return { version: readSkillManifestVersion(dir), contentHash, files };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Baseline manifest for the version-bump rule. The authoritative baseline is
|
|
90
|
-
* the manifest COMMITTED ON origin/main (read via `git show`, so deleting or
|
|
91
|
-
* hand-editing the local file cannot dodge the rule); the local file is only
|
|
92
|
-
* a fallback for environments where the git baseline is unreadable.
|
|
93
|
-
*/
|
|
94
|
-
function baselineSkillManifest() {
|
|
95
|
-
const result = spawnSync("git", ["show", "origin/main:packages/gmc-cli/skill/gmc-analysis.manifest.json"], {
|
|
96
|
-
cwd: packageDir,
|
|
97
|
-
encoding: "utf8"
|
|
98
|
-
});
|
|
99
|
-
if (result.status === 0 && typeof result.stdout === "string") {
|
|
100
|
-
try {
|
|
101
|
-
return JSON.parse(result.stdout);
|
|
102
|
-
} catch {
|
|
103
|
-
// fall through to the local file
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (existsSync(MANIFEST_PATH)) {
|
|
107
|
-
try {
|
|
108
|
-
return JSON.parse(readFileSync(MANIFEST_PATH, "utf8"));
|
|
109
|
-
} catch {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Pure regen-permission rule (unit-tested in src/skill-manifest.test.js).
|
|
118
|
-
* Content that differs from the baseline while keeping the baseline's
|
|
119
|
-
* version is refused: once a version's content is on origin/main, changing
|
|
120
|
-
* content under that version always requires a bump. A differing version
|
|
121
|
-
* (the in-flight bump case, iterated freely within one branch) and a
|
|
122
|
-
* missing baseline (true first generation) are allowed. There is
|
|
123
|
-
* deliberately NO force escape hatch: an override flag would let
|
|
124
|
-
* unversioned content changes reach npm and the public skills repo.
|
|
125
|
-
*/
|
|
126
|
-
export function assertRegenAllowed({ baseline, next }) {
|
|
127
|
-
if (!baseline) return;
|
|
128
|
-
if (baseline.contentHash === next.contentHash) return;
|
|
129
|
-
if (baseline.version !== next.version) return;
|
|
130
|
-
throw new Error(
|
|
131
|
-
`skill content changed but metadata.version is still ${next.version}, whose content is already fixed by the baseline manifest (origin/main) — bump the version in SKILL.md, then rerun npm run skill:manifest.`
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function main() {
|
|
136
|
-
const manifest = buildSkillManifest();
|
|
137
|
-
try {
|
|
138
|
-
assertRegenAllowed({ baseline: baselineSkillManifest(), next: manifest });
|
|
139
|
-
} catch (error) {
|
|
140
|
-
console.error(error.message);
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
writeFileSync(MANIFEST_PATH, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
144
|
-
process.stdout.write(
|
|
145
|
-
`Wrote ${path.relative(packageDir, MANIFEST_PATH)}: version ${manifest.version}, ${manifest.files} files, contentHash ${manifest.contentHash}\n`
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
150
|
-
main();
|
|
151
|
-
}
|