@setzkasten/cli 0.1.0-rc.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 +21 -0
- package/README.md +38 -0
- package/package.json +38 -0
- package/src/index.js +509 -0
- package/src/lib/core.js +129 -0
- package/src/lib/events.js +52 -0
- package/src/lib/manifest-lib.js +613 -0
- package/src/lib/policy.js +271 -0
- package/src/lib/quote.js +219 -0
- package/src/lib/scanner.js +176 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Setzkasten
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @setzkasten/cli
|
|
2
|
+
|
|
3
|
+
CLI-first tool for font license governance, audit logging, and deterministic policy/quote checks.
|
|
4
|
+
|
|
5
|
+
## What it does (V1)
|
|
6
|
+
- Initializes a project manifest (`LICENSE_MANIFEST.json`)
|
|
7
|
+
- Writes an append-only event log (`.setzkasten/events.log`)
|
|
8
|
+
- Adds/removes font entries
|
|
9
|
+
- Scans controlled local assets for usage signals
|
|
10
|
+
- Evaluates policy decisions (`allow`, `warn`, `escalate`)
|
|
11
|
+
- Generates deterministic quote output
|
|
12
|
+
- Provides a migration stub command
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @setzkasten/cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
```bash
|
|
21
|
+
setzkasten init --name "My Project"
|
|
22
|
+
setzkasten add --font-id inter --family "Inter" --source oss
|
|
23
|
+
setzkasten scan --path .
|
|
24
|
+
setzkasten policy
|
|
25
|
+
setzkasten quote
|
|
26
|
+
setzkasten migrate
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Data written locally
|
|
30
|
+
- `LICENSE_MANIFEST.json`
|
|
31
|
+
- `.setzkasten/events.log`
|
|
32
|
+
|
|
33
|
+
## Constraints (V1)
|
|
34
|
+
- No proprietary font hosting/distribution
|
|
35
|
+
- No proprietary font preview
|
|
36
|
+
- No general web crawling
|
|
37
|
+
- Offline-first core behavior
|
|
38
|
+
- Not legal advice
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@setzkasten/cli",
|
|
3
|
+
"version": "0.1.0-rc.1",
|
|
4
|
+
"description": "Setzkasten CLI for font license governance and audit trails.",
|
|
5
|
+
"private": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"setzkasten": "src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "src/index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"src/index.js",
|
|
13
|
+
"src/lib/",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "node --check src/index.js && node --check src/lib/*.js",
|
|
19
|
+
"test": "node --test \"src/**/*.test.js\"",
|
|
20
|
+
"lint": "node --check src/index.js && node --check src/lib/*.js",
|
|
21
|
+
"pack:dry-run": "npm pack --dry-run --json",
|
|
22
|
+
"prepublishOnly": "npm run build && npm run lint"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"fonts",
|
|
26
|
+
"license",
|
|
27
|
+
"governance",
|
|
28
|
+
"audit",
|
|
29
|
+
"cli"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { access } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { MANIFEST_FILENAME, parseListFlag, slugifyId } from "./lib/core.js";
|
|
7
|
+
import { appendProjectEvent } from "./lib/events.js";
|
|
8
|
+
import {
|
|
9
|
+
addFontToManifest,
|
|
10
|
+
createManifest,
|
|
11
|
+
getManifestProjectId,
|
|
12
|
+
loadManifest,
|
|
13
|
+
removeFontFromManifest,
|
|
14
|
+
saveManifest,
|
|
15
|
+
} from "./lib/manifest-lib.js";
|
|
16
|
+
import { evaluatePolicy } from "./lib/policy.js";
|
|
17
|
+
import { generateQuote } from "./lib/quote.js";
|
|
18
|
+
import { applyScanResultToManifest, scanProject } from "./lib/scanner.js";
|
|
19
|
+
|
|
20
|
+
function printHelp() {
|
|
21
|
+
const helpText = `Setzkasten CLI (V1)
|
|
22
|
+
|
|
23
|
+
Usage:
|
|
24
|
+
setzkasten <command> [options]
|
|
25
|
+
|
|
26
|
+
Commands:
|
|
27
|
+
init Create ${MANIFEST_FILENAME} and .setzkasten/events.log
|
|
28
|
+
add Add font entry to manifest
|
|
29
|
+
remove Remove font entry from manifest
|
|
30
|
+
scan Scan local repository usage and update manifest usage fields
|
|
31
|
+
policy Evaluate policy decision (allow|warn|escalate)
|
|
32
|
+
quote Generate deterministic quote from license schema data
|
|
33
|
+
migrate Generate migration stub plan
|
|
34
|
+
|
|
35
|
+
Common options:
|
|
36
|
+
--manifest <path> Explicit path to ${MANIFEST_FILENAME}
|
|
37
|
+
|
|
38
|
+
Examples:
|
|
39
|
+
setzkasten init --name "Acme Project"
|
|
40
|
+
setzkasten add --font-id inter --family "Inter" --source oss
|
|
41
|
+
setzkasten policy --fail-on escalate
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
process.stdout.write(`${helpText}\n`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function parseInput(argv) {
|
|
48
|
+
if (argv.length === 0) {
|
|
49
|
+
return {
|
|
50
|
+
command: null,
|
|
51
|
+
flags: {},
|
|
52
|
+
positionals: [],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const [command, ...rest] = argv;
|
|
57
|
+
const flags = {};
|
|
58
|
+
const positionals = [];
|
|
59
|
+
|
|
60
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
61
|
+
const token = rest[index];
|
|
62
|
+
|
|
63
|
+
if (!token.startsWith("--")) {
|
|
64
|
+
positionals.push(token);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const normalized = token.slice(2);
|
|
69
|
+
|
|
70
|
+
if (normalized.length === 0) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (normalized.includes("=")) {
|
|
75
|
+
const [rawKey, rawValue] = normalized.split(/=(.*)/, 2);
|
|
76
|
+
addFlag(flags, rawKey, rawValue.length > 0 ? rawValue : "true");
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const next = rest[index + 1];
|
|
81
|
+
if (next && !next.startsWith("--")) {
|
|
82
|
+
addFlag(flags, normalized, next);
|
|
83
|
+
index += 1;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
addFlag(flags, normalized, true);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
command,
|
|
92
|
+
flags,
|
|
93
|
+
positionals,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function addFlag(flags, key, value) {
|
|
98
|
+
const existing = flags[key];
|
|
99
|
+
|
|
100
|
+
if (existing === undefined) {
|
|
101
|
+
flags[key] = value;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (Array.isArray(existing)) {
|
|
106
|
+
existing.push(String(value));
|
|
107
|
+
flags[key] = existing;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
flags[key] = [String(existing), String(value)];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function getStringFlag(flags, key) {
|
|
115
|
+
const value = flags[key];
|
|
116
|
+
|
|
117
|
+
if (typeof value === "string") {
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
122
|
+
return value[value.length - 1];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getBooleanFlag(flags, key) {
|
|
129
|
+
const value = flags[key];
|
|
130
|
+
|
|
131
|
+
if (typeof value === "boolean") {
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (typeof value === "string") {
|
|
136
|
+
return value === "true";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
140
|
+
return value[value.length - 1] === "true";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function getListFlag(flags, key) {
|
|
147
|
+
const value = flags[key];
|
|
148
|
+
|
|
149
|
+
if (value === undefined) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return parseListFlag(value);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function requireStringFlag(flags, key) {
|
|
157
|
+
const value = getStringFlag(flags, key);
|
|
158
|
+
if (!value || value.trim().length === 0) {
|
|
159
|
+
throw new Error(`Missing required option --${key}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return value.trim();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function exists(filePath) {
|
|
166
|
+
try {
|
|
167
|
+
await access(filePath);
|
|
168
|
+
return true;
|
|
169
|
+
} catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function resolveManifestPathFromFlag(cwd, flags) {
|
|
175
|
+
const value = getStringFlag(flags, "manifest");
|
|
176
|
+
return value ? path.resolve(cwd, value) : undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function printJson(value) {
|
|
180
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function handleInit(cwd, flags) {
|
|
184
|
+
const force = getBooleanFlag(flags, "force");
|
|
185
|
+
const providedManifestPath = resolveManifestPathFromFlag(cwd, flags);
|
|
186
|
+
const manifestPath = providedManifestPath ?? path.join(cwd, MANIFEST_FILENAME);
|
|
187
|
+
|
|
188
|
+
if (!force && (await exists(manifestPath))) {
|
|
189
|
+
throw new Error(
|
|
190
|
+
`${MANIFEST_FILENAME} already exists at ${manifestPath}. Use --force to overwrite.`,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const projectName = getStringFlag(flags, "name") ?? path.basename(cwd);
|
|
195
|
+
const projectId = getStringFlag(flags, "project-id") ?? slugifyId(projectName);
|
|
196
|
+
const licenseeName = getStringFlag(flags, "licensee-name") ?? projectName;
|
|
197
|
+
|
|
198
|
+
const manifest = createManifest({
|
|
199
|
+
projectName,
|
|
200
|
+
projectId,
|
|
201
|
+
projectRepo: getStringFlag(flags, "repo"),
|
|
202
|
+
projectDomains: getListFlag(flags, "domain"),
|
|
203
|
+
licenseeId: getStringFlag(flags, "licensee-id"),
|
|
204
|
+
licenseeType: getStringFlag(flags, "licensee-type") ?? "organization",
|
|
205
|
+
licenseeLegalName: licenseeName,
|
|
206
|
+
licenseeCountry: getStringFlag(flags, "licensee-country"),
|
|
207
|
+
licenseeVatId: getStringFlag(flags, "licensee-vat-id"),
|
|
208
|
+
licenseeContactEmail: getStringFlag(flags, "licensee-email"),
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
await saveManifest(manifestPath, manifest);
|
|
212
|
+
|
|
213
|
+
const projectRoot = path.dirname(manifestPath);
|
|
214
|
+
await appendProjectEvent({
|
|
215
|
+
projectRoot,
|
|
216
|
+
projectId: getManifestProjectId(manifest),
|
|
217
|
+
eventType: "manifest.created",
|
|
218
|
+
payload: {
|
|
219
|
+
manifest_path: manifestPath,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
printJson({
|
|
224
|
+
ok: true,
|
|
225
|
+
command: "init",
|
|
226
|
+
manifest_path: manifestPath,
|
|
227
|
+
project_id: projectId,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function handleAdd(cwd, flags) {
|
|
234
|
+
const manifestPath = resolveManifestPathFromFlag(cwd, flags);
|
|
235
|
+
const { manifest, manifestPath: resolvedManifestPath, projectRoot } = await loadManifest({
|
|
236
|
+
cwd,
|
|
237
|
+
manifestPath,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const fontId = requireStringFlag(flags, "font-id");
|
|
241
|
+
const familyName = requireStringFlag(flags, "family");
|
|
242
|
+
const sourceType = requireStringFlag(flags, "source");
|
|
243
|
+
|
|
244
|
+
if (sourceType !== "oss" && sourceType !== "byo") {
|
|
245
|
+
throw new Error("--source must be either 'oss' or 'byo'.");
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const licenseInstanceIds = getListFlag(flags, "license-instance-id");
|
|
249
|
+
const activeLicenseInstanceId = getStringFlag(flags, "active-license-instance-id");
|
|
250
|
+
|
|
251
|
+
if (activeLicenseInstanceId && !licenseInstanceIds.includes(activeLicenseInstanceId)) {
|
|
252
|
+
licenseInstanceIds.push(activeLicenseInstanceId);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const updatedManifest = addFontToManifest(manifest, {
|
|
256
|
+
font_id: fontId,
|
|
257
|
+
family_name: familyName,
|
|
258
|
+
source: {
|
|
259
|
+
type: sourceType,
|
|
260
|
+
name: getStringFlag(flags, "source-name"),
|
|
261
|
+
uri: getStringFlag(flags, "source-uri"),
|
|
262
|
+
notes: getStringFlag(flags, "notes"),
|
|
263
|
+
},
|
|
264
|
+
active_license_instance_id: activeLicenseInstanceId,
|
|
265
|
+
license_instance_ids: licenseInstanceIds,
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
await saveManifest(resolvedManifestPath, updatedManifest);
|
|
269
|
+
|
|
270
|
+
await appendProjectEvent({
|
|
271
|
+
projectRoot,
|
|
272
|
+
projectId: getManifestProjectId(updatedManifest),
|
|
273
|
+
eventType: "manifest.font_added",
|
|
274
|
+
payload: {
|
|
275
|
+
font_id: fontId,
|
|
276
|
+
family_name: familyName,
|
|
277
|
+
source_type: sourceType,
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
printJson({
|
|
282
|
+
ok: true,
|
|
283
|
+
command: "add",
|
|
284
|
+
manifest_path: resolvedManifestPath,
|
|
285
|
+
font_id: fontId,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async function handleRemove(cwd, flags) {
|
|
292
|
+
const manifestPath = resolveManifestPathFromFlag(cwd, flags);
|
|
293
|
+
const { manifest, manifestPath: resolvedManifestPath, projectRoot } = await loadManifest({
|
|
294
|
+
cwd,
|
|
295
|
+
manifestPath,
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const fontId = requireStringFlag(flags, "font-id");
|
|
299
|
+
const result = removeFontFromManifest(manifest, fontId);
|
|
300
|
+
|
|
301
|
+
if (!result.removed) {
|
|
302
|
+
throw new Error(`Font '${fontId}' not found in manifest.`);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
await saveManifest(resolvedManifestPath, result.manifest);
|
|
306
|
+
|
|
307
|
+
await appendProjectEvent({
|
|
308
|
+
projectRoot,
|
|
309
|
+
projectId: getManifestProjectId(result.manifest),
|
|
310
|
+
eventType: "manifest.font_removed",
|
|
311
|
+
payload: {
|
|
312
|
+
font_id: fontId,
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
printJson({
|
|
317
|
+
ok: true,
|
|
318
|
+
command: "remove",
|
|
319
|
+
manifest_path: resolvedManifestPath,
|
|
320
|
+
font_id: fontId,
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
return 0;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async function handleScan(cwd, flags) {
|
|
327
|
+
const manifestPath = resolveManifestPathFromFlag(cwd, flags);
|
|
328
|
+
const { manifest, manifestPath: resolvedManifestPath, projectRoot } = await loadManifest({
|
|
329
|
+
cwd,
|
|
330
|
+
manifestPath,
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
const scanRoot = path.resolve(cwd, getStringFlag(flags, "path") ?? projectRoot);
|
|
334
|
+
const maxMatchedPaths = Number(getStringFlag(flags, "max-matched-paths") ?? "30");
|
|
335
|
+
|
|
336
|
+
const scanResult = await scanProject({
|
|
337
|
+
rootPath: scanRoot,
|
|
338
|
+
manifest,
|
|
339
|
+
maxMatchedPathsPerFont: Number.isFinite(maxMatchedPaths) ? maxMatchedPaths : 30,
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
const updatedManifest = applyScanResultToManifest(manifest, scanResult);
|
|
343
|
+
await saveManifest(resolvedManifestPath, updatedManifest);
|
|
344
|
+
|
|
345
|
+
await appendProjectEvent({
|
|
346
|
+
projectRoot,
|
|
347
|
+
projectId: getManifestProjectId(updatedManifest),
|
|
348
|
+
eventType: "scan.completed",
|
|
349
|
+
payload: {
|
|
350
|
+
scanned_at: scanResult.scanned_at,
|
|
351
|
+
scanned_files_count: scanResult.scanned_files_count,
|
|
352
|
+
root_path: scanResult.root_path,
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
printJson({
|
|
357
|
+
ok: true,
|
|
358
|
+
command: "scan",
|
|
359
|
+
result: scanResult,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return 0;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
async function handlePolicy(cwd, flags) {
|
|
366
|
+
const manifestPath = resolveManifestPathFromFlag(cwd, flags);
|
|
367
|
+
const { manifest, projectRoot } = await loadManifest({
|
|
368
|
+
cwd,
|
|
369
|
+
manifestPath,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
const policy = evaluatePolicy(manifest);
|
|
373
|
+
|
|
374
|
+
await appendProjectEvent({
|
|
375
|
+
projectRoot,
|
|
376
|
+
projectId: getManifestProjectId(manifest),
|
|
377
|
+
eventType: policy.decision === "allow" ? "policy.ok" : "policy.warning_raised",
|
|
378
|
+
payload: {
|
|
379
|
+
decision: policy.decision,
|
|
380
|
+
reasons_count: policy.reasons.length,
|
|
381
|
+
evidence_required: policy.evidence_required,
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
printJson(policy);
|
|
386
|
+
|
|
387
|
+
const failOn = getStringFlag(flags, "fail-on") ?? "escalate";
|
|
388
|
+
if (failOn === "warn") {
|
|
389
|
+
return policy.decision === "allow" ? 0 : 2;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (failOn === "escalate") {
|
|
393
|
+
return policy.decision === "escalate" ? 2 : 0;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return 0;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
async function handleQuote(cwd, flags) {
|
|
400
|
+
const manifestPath = resolveManifestPathFromFlag(cwd, flags);
|
|
401
|
+
const { manifest, projectRoot } = await loadManifest({
|
|
402
|
+
cwd,
|
|
403
|
+
manifestPath,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
const quote = generateQuote(manifest);
|
|
407
|
+
|
|
408
|
+
await appendProjectEvent({
|
|
409
|
+
projectRoot,
|
|
410
|
+
projectId: getManifestProjectId(manifest),
|
|
411
|
+
eventType: "quote.generated",
|
|
412
|
+
payload: {
|
|
413
|
+
generated_at: quote.generated_at,
|
|
414
|
+
totals: quote.totals,
|
|
415
|
+
line_items_count: quote.line_items.length,
|
|
416
|
+
skipped_count: quote.skipped.length,
|
|
417
|
+
deterministic_hash: quote.deterministic_hash,
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
printJson(quote);
|
|
422
|
+
return 0;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
async function handleMigrate(cwd, flags) {
|
|
426
|
+
const manifestPath = resolveManifestPathFromFlag(cwd, flags);
|
|
427
|
+
const { manifest, projectRoot } = await loadManifest({
|
|
428
|
+
cwd,
|
|
429
|
+
manifestPath,
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
const currentVersion =
|
|
433
|
+
typeof manifest.manifest_version === "string" ? manifest.manifest_version : "unknown";
|
|
434
|
+
|
|
435
|
+
const migrationPlan = {
|
|
436
|
+
mode: "stub",
|
|
437
|
+
from_manifest_version: currentVersion,
|
|
438
|
+
to_manifest_version: "1.0.0",
|
|
439
|
+
actions: [
|
|
440
|
+
"Inspect schema differences",
|
|
441
|
+
"Draft migration transformations",
|
|
442
|
+
"Run dry-run migration validation",
|
|
443
|
+
],
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
await appendProjectEvent({
|
|
447
|
+
projectRoot,
|
|
448
|
+
projectId: getManifestProjectId(manifest),
|
|
449
|
+
eventType: "migration.planned",
|
|
450
|
+
payload: migrationPlan,
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
printJson({
|
|
454
|
+
ok: true,
|
|
455
|
+
command: "migrate",
|
|
456
|
+
migration: migrationPlan,
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
return 0;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export async function runCli(argv = process.argv.slice(2), cwd = process.cwd()) {
|
|
463
|
+
const parsed = parseInput(argv);
|
|
464
|
+
|
|
465
|
+
if (!parsed.command || parsed.command === "help" || parsed.command === "--help") {
|
|
466
|
+
printHelp();
|
|
467
|
+
return 0;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
switch (parsed.command) {
|
|
471
|
+
case "init":
|
|
472
|
+
return handleInit(cwd, parsed.flags);
|
|
473
|
+
case "add":
|
|
474
|
+
return handleAdd(cwd, parsed.flags);
|
|
475
|
+
case "remove":
|
|
476
|
+
return handleRemove(cwd, parsed.flags);
|
|
477
|
+
case "scan":
|
|
478
|
+
return handleScan(cwd, parsed.flags);
|
|
479
|
+
case "policy":
|
|
480
|
+
return handlePolicy(cwd, parsed.flags);
|
|
481
|
+
case "quote":
|
|
482
|
+
return handleQuote(cwd, parsed.flags);
|
|
483
|
+
case "migrate":
|
|
484
|
+
return handleMigrate(cwd, parsed.flags);
|
|
485
|
+
default:
|
|
486
|
+
throw new Error(`Unknown command '${parsed.command}'. Run 'setzkasten --help'.`);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function isMainModule(importMetaUrl) {
|
|
491
|
+
const entry = process.argv[1];
|
|
492
|
+
if (!entry) {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return pathToFileURL(entry).href === importMetaUrl;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (isMainModule(import.meta.url)) {
|
|
500
|
+
runCli()
|
|
501
|
+
.then((exitCode) => {
|
|
502
|
+
process.exit(exitCode);
|
|
503
|
+
})
|
|
504
|
+
.catch((error) => {
|
|
505
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
506
|
+
process.stderr.write(`${message}\n`);
|
|
507
|
+
process.exit(1);
|
|
508
|
+
});
|
|
509
|
+
}
|