stitchkit 0.136.4 → 0.136.5
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 +7 -0
- package/dist/entrypoints/agent-executor/acp.js +5 -5
- package/dist/entrypoints/agent-executor/claude-sdk.js +7 -7
- package/dist/entrypoints/agent-executor/claude.js +7 -7
- package/dist/entrypoints/agent-executor/codex.js +9 -9
- package/dist/entrypoints/agent-executor/testing.js +9 -9
- package/dist/entrypoints/agent-executor.js +5 -5
- package/dist/entrypoints/agent-runtime/coding-tools.js +2 -2
- package/dist/entrypoints/agent-runtime/postgres.js +4 -4
- package/dist/entrypoints/agent-runtime/sandbox.js +7 -7
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +5 -5
- package/dist/entrypoints/agent-runtime/sqlite/node.js +5 -5
- package/dist/entrypoints/agent-runtime/testing.js +4 -4
- package/dist/entrypoints/agent-runtime.js +4 -4
- package/dist/entrypoints/application/diagnostic-journal.js +3 -3
- package/dist/entrypoints/application/directory-inbox.js +7 -7
- package/dist/entrypoints/cli/publish.d.ts +14 -6
- package/dist/entrypoints/cli/publish.d.ts.map +1 -1
- package/dist/entrypoints/cli/publish.js +685 -30
- package/dist/entrypoints/cli.js +7 -124
- package/dist/entrypoints/files/packaging.js +2 -2
- package/dist/entrypoints/files.d.ts +1 -0
- package/dist/entrypoints/files.d.ts.map +1 -1
- package/dist/entrypoints/files.js +9 -9
- package/dist/entrypoints/node.js +3 -3
- package/dist/entrypoints/observability.js +1 -1
- package/dist/entrypoints/process.js +3 -3
- package/dist/entrypoints/server.js +6 -6
- package/dist/entrypoints/service-host/macos.js +7 -7
- package/dist/entrypoints/service-host/work.js +6 -6
- package/dist/entrypoints/service-host.js +9 -9
- package/dist/entrypoints/spend.js +1 -1
- package/dist/entrypoints/telegram.js +3 -3
- package/dist/entrypoints/tools.js +1 -1
- package/dist/{index-05b65gj4.js → index-0s75mjh7.js} +1 -1
- package/dist/{index-s2e3h616.js → index-150b1qyw.js} +10 -1
- package/dist/{index-tcv71frn.js → index-1fhbe4e4.js} +1 -1
- package/dist/{index-8cek82ar.js → index-1h0dtfz3.js} +1 -1
- package/dist/{index-jwtmw39p.js → index-2qnqvq11.js} +1 -1
- package/dist/index-2rs7ze0q.js +376 -0
- package/dist/{index-2wm9b9vs.js → index-3cwq5byx.js} +2 -2
- package/dist/{index-mtpcax6d.js → index-5md04mwc.js} +3 -3
- package/dist/{index-b0mh2t9x.js → index-67mzzkdv.js} +3 -3
- package/dist/{index-d5mhgx72.js → index-8tn10tp6.js} +1 -1
- package/dist/{index-0sxj3y45.js → index-afaq0nc4.js} +1 -1
- package/dist/{index-nfm15ej7.js → index-bbpygynk.js} +1 -1
- package/dist/{index-g04hszcm.js → index-chapre0y.js} +1 -1
- package/dist/{index-vh4291qh.js → index-ctaxjpa4.js} +1 -1
- package/dist/{index-x1r7kxzd.js → index-e4zt2x70.js} +3 -3
- package/dist/{index-s0n0nnz5.js → index-f103md2v.js} +122 -3
- package/dist/{index-2c5w2d1d.js → index-gyfsh29t.js} +1 -1
- package/dist/{index-kgkevngs.js → index-kadgaw1s.js} +4 -4
- package/dist/{index-ca1v40d3.js → index-kd48gk7d.js} +1 -1
- package/dist/{index-ke6jtxkd.js → index-mr3njw67.js} +1 -1
- package/dist/{index-cmqvf0dz.js → index-ppy23bd2.js} +1 -1
- package/dist/{index-43k180c2.js → index-rnhp7je8.js} +2 -2
- package/dist/{index-2tgmggcm.js → index-smvmnz5y.js} +1 -1
- package/dist/{index-9m1m92rg.js → index-tjhhsnjv.js} +1 -1
- package/dist/{index-64t6pheq.js → index-w161azza.js} +1 -1
- package/dist/{index-mttkdm5a.js → index-xqppqn97.js} +1 -1
- package/dist/{index-sjq4akrx.js → index-xsrma0jd.js} +2 -2
- package/dist/{index-zqc64g69.js → index-ypm85xwe.js} +1 -1
- package/dist/{index-zagc12j1.js → index-zcq3dby3.js} +1 -1
- package/dist/{index-29v1p1f4.js → index-zhngww7q.js} +1 -1
- package/dist/internal/atomic-file-owner.d.ts +91 -0
- package/dist/internal/atomic-file-owner.d.ts.map +1 -0
- package/dist/internal/atomic-file.d.ts +29 -7
- package/dist/internal/atomic-file.d.ts.map +1 -1
- package/dist/internal/bounded-file-read.d.ts +6 -2
- package/dist/internal/bounded-file-read.d.ts.map +1 -1
- package/dist/tools/cli/distribution-config.d.ts +56 -0
- package/dist/tools/cli/distribution-config.d.ts.map +1 -0
- package/dist/tools/cli/distribution-routes.d.ts +20 -0
- package/dist/tools/cli/distribution-routes.d.ts.map +1 -0
- package/dist/tools/cli/publication-source.d.ts +77 -0
- package/dist/tools/cli/publication-source.d.ts.map +1 -0
- package/llms/cli-publish.txt +15 -3
- package/llms/cli.2.txt +84 -63
- package/llms/cli.3.txt +67 -1
- package/llms/cli.txt +1 -1
- package/llms/files.txt +1 -1
- package/llms/process.txt +24 -4
- package/llms/stitchkit.txt +1 -1
- package/llms-full.txt +124 -9
- package/llms.txt +5 -5
- package/package.json +1 -1
- package/dist/index-pp97q86a.js +0 -221
- package/dist/{index-5c4m8zdf.js → index-tjakdpf2.js} +45 -45
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import"../../index-xqhede6x.js";
|
|
2
|
-
import"../../index-6kec3b14.js";
|
|
3
|
-
import"../../index-673drwkn.js";
|
|
4
|
-
import"../../index-jwtmw39p.js";
|
|
5
1
|
import {
|
|
2
|
+
RegularFileError2,
|
|
3
|
+
readRegularFile2,
|
|
4
|
+
parseJsonBytes2
|
|
5
|
+
} from "../../index-ctaxjpa4.js";
|
|
6
|
+
import {
|
|
7
|
+
renderCliInstaller2,
|
|
6
8
|
signCliManifest2,
|
|
7
9
|
verifyCliManifest2,
|
|
8
10
|
cliSignatureAccepted2,
|
|
@@ -15,38 +17,190 @@ import {
|
|
|
15
17
|
gzipCliAsset,
|
|
16
18
|
decodeCliAsset,
|
|
17
19
|
compareCliVersions2
|
|
18
|
-
} from "../../index-
|
|
20
|
+
} from "../../index-f103md2v.js";
|
|
21
|
+
import"../../index-xqhede6x.js";
|
|
22
|
+
import"../../index-6kec3b14.js";
|
|
23
|
+
import"../../index-673drwkn.js";
|
|
24
|
+
import"../../index-2qnqvq11.js";
|
|
25
|
+
import"../../index-tgehj4bp.js";
|
|
26
|
+
import"../../index-tjakdpf2.js";
|
|
27
|
+
import {
|
|
28
|
+
runNativeCommand2
|
|
29
|
+
} from "../../index-afaq0nc4.js";
|
|
19
30
|
import {
|
|
20
31
|
ManagedFileError2,
|
|
21
32
|
createManagedFileBoundary2
|
|
22
|
-
} from "../../index-
|
|
33
|
+
} from "../../index-e4zt2x70.js";
|
|
34
|
+
import {
|
|
35
|
+
isWithinDir2
|
|
36
|
+
} from "../../index-5cc6r990.js";
|
|
23
37
|
import {
|
|
24
38
|
withExclusiveLock2
|
|
25
|
-
} from "../../index-
|
|
26
|
-
import"../../index-
|
|
39
|
+
} from "../../index-zhngww7q.js";
|
|
40
|
+
import"../../index-rnhp7je8.js";
|
|
27
41
|
import {
|
|
28
42
|
writeFileAtomic2
|
|
29
|
-
} from "../../index-
|
|
43
|
+
} from "../../index-2rs7ze0q.js";
|
|
30
44
|
import {
|
|
31
45
|
AtomicFilePublicationError2,
|
|
32
46
|
assertDirectoryDurability,
|
|
33
47
|
syncDirectory
|
|
34
|
-
} from "../../index-
|
|
48
|
+
} from "../../index-gyfsh29t.js";
|
|
49
|
+
import {
|
|
50
|
+
BoundedFileReadError,
|
|
51
|
+
openRegularFile
|
|
52
|
+
} from "../../index-150b1qyw.js";
|
|
35
53
|
import {
|
|
36
54
|
errnoOf
|
|
37
55
|
} from "../../index-jj9228tt.js";
|
|
56
|
+
import {
|
|
57
|
+
assertPositiveSafeInteger
|
|
58
|
+
} from "../../index-gr0kxymw.js";
|
|
59
|
+
import {
|
|
60
|
+
assertTimerMs
|
|
61
|
+
} from "../../index-e1y74yra.js";
|
|
38
62
|
import {
|
|
39
63
|
MAX_TIMER_MS
|
|
40
64
|
} from "../../index-h20qcyh5.js";
|
|
65
|
+
import {
|
|
66
|
+
isRecord
|
|
67
|
+
} from "../../index-ps3djm8d.js";
|
|
41
68
|
|
|
42
|
-
// src/tools/cli/
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
import { join as join2 } from "node:path";
|
|
46
|
-
import { z as z3 } from "zod";
|
|
69
|
+
// src/tools/cli/distribution-routes.ts
|
|
70
|
+
import { realpath } from "node:fs/promises";
|
|
71
|
+
import { join } from "node:path";
|
|
47
72
|
|
|
48
|
-
// src/tools/cli/
|
|
73
|
+
// src/tools/cli/distribution-config.ts
|
|
49
74
|
import { isAbsolute } from "node:path";
|
|
75
|
+
var DEFAULT_CHANNELS = ["stable", "beta"];
|
|
76
|
+
var DEFAULT_BASE_PATH = "/cli";
|
|
77
|
+
var DEFAULT_INSTALL_DIR = "$HOME/.local/bin";
|
|
78
|
+
var DEFAULT_MAX_MANIFEST_BYTES = 256 * 1024;
|
|
79
|
+
var SAFE_COMPONENT = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;
|
|
80
|
+
var SAFE_BINARY_NAME = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;
|
|
81
|
+
var SAFE_ASSET_SEGMENT = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
82
|
+
var CONTROL_CHAR_PATTERN = /[\u0000-\u001f\u007f]/;
|
|
83
|
+
var UNSAFE_INSTALL_DIR_CHARS = /["'`$\\;|&<>(){}!*?[\]]/;
|
|
84
|
+
function normalizeBasePath(value) {
|
|
85
|
+
if (typeof value !== "string" || !value.startsWith("/")) {
|
|
86
|
+
throw new TypeError('basePath must be a path starting with "/"');
|
|
87
|
+
}
|
|
88
|
+
if (CONTROL_CHAR_PATTERN.test(value) || /\s/.test(value) || value.includes("//") || value.includes(":") || value.includes("*") || value.includes("?") || value.includes("#") || value.includes("\\")) {
|
|
89
|
+
throw new TypeError(`basePath contains unsafe characters: ${value}`);
|
|
90
|
+
}
|
|
91
|
+
const trimmed = value === "/" ? "" : value.replace(/\/+$/, "");
|
|
92
|
+
if (trimmed.split("/").some((segment) => segment === "." || segment === "..")) {
|
|
93
|
+
throw new TypeError(`basePath must not contain "." or ".." segments: ${value}`);
|
|
94
|
+
}
|
|
95
|
+
return trimmed;
|
|
96
|
+
}
|
|
97
|
+
function validateChannels(channels) {
|
|
98
|
+
if (!Array.isArray(channels) || channels.length === 0) {
|
|
99
|
+
throw new TypeError("channels must be a non-empty array of channel names");
|
|
100
|
+
}
|
|
101
|
+
const seen = new Set;
|
|
102
|
+
const validated = [];
|
|
103
|
+
for (const entry of channels) {
|
|
104
|
+
if (typeof entry !== "string" || !SAFE_COMPONENT.test(entry)) {
|
|
105
|
+
throw new TypeError(`Invalid CLI distribution channel name: ${String(entry)}`);
|
|
106
|
+
}
|
|
107
|
+
if (seen.has(entry)) {
|
|
108
|
+
throw new TypeError(`Duplicate CLI distribution channel name: ${entry}`);
|
|
109
|
+
}
|
|
110
|
+
seen.add(entry);
|
|
111
|
+
validated.push(entry);
|
|
112
|
+
}
|
|
113
|
+
return validated;
|
|
114
|
+
}
|
|
115
|
+
function validateTrust(trust) {
|
|
116
|
+
if (!isRecord(trust) || !isRecord(trust.keys)) {
|
|
117
|
+
throw new TypeError("trust must be a CliTrustRoot with a keys map");
|
|
118
|
+
}
|
|
119
|
+
const keys = {};
|
|
120
|
+
for (const [keyId, publicKey] of Object.entries(trust.keys)) {
|
|
121
|
+
if (typeof publicKey !== "string") {
|
|
122
|
+
throw new TypeError(`trust.keys.${keyId} must be a PEM or base64 public key string`);
|
|
123
|
+
}
|
|
124
|
+
keys[keyId] = publicKey;
|
|
125
|
+
}
|
|
126
|
+
return { keys };
|
|
127
|
+
}
|
|
128
|
+
function validateInstallDir(value) {
|
|
129
|
+
if (typeof value !== "string" || value.length === 0 || CONTROL_CHAR_PATTERN.test(value)) {
|
|
130
|
+
throw new TypeError("installDir must be a safe POSIX path expression");
|
|
131
|
+
}
|
|
132
|
+
const hasHomePrefix = value === "$HOME" || value.startsWith("$HOME/");
|
|
133
|
+
const remainder = hasHomePrefix ? value.slice("$HOME".length) : value;
|
|
134
|
+
if (!hasHomePrefix && !remainder.startsWith("/")) {
|
|
135
|
+
throw new TypeError('installDir must start with "$HOME" or "/"');
|
|
136
|
+
}
|
|
137
|
+
if (UNSAFE_INSTALL_DIR_CHARS.test(remainder) || remainder.split("/").some((segment) => segment === "..")) {
|
|
138
|
+
throw new TypeError("installDir contains unsafe shell or traversal characters");
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
function resolveDistributionConfig(options) {
|
|
143
|
+
if (typeof options.name !== "string" || !SAFE_COMPONENT.test(options.name)) {
|
|
144
|
+
throw new TypeError(`Invalid CLI distribution name: ${String(options.name)}`);
|
|
145
|
+
}
|
|
146
|
+
if (options.root !== undefined && (typeof options.root !== "string" || !isAbsolute(options.root))) {
|
|
147
|
+
throw new TypeError("root must be an absolute directory path or undefined");
|
|
148
|
+
}
|
|
149
|
+
const trust = validateTrust(options.trust);
|
|
150
|
+
const channels = validateChannels(options.channels ?? DEFAULT_CHANNELS);
|
|
151
|
+
const installerChannel = options.installerChannel ?? channels[0] ?? "stable";
|
|
152
|
+
if (!channels.includes(installerChannel)) {
|
|
153
|
+
throw new TypeError(`installerChannel "${installerChannel}" must be included in channels (${channels.join(", ")})`);
|
|
154
|
+
}
|
|
155
|
+
const basePath = normalizeBasePath(options.basePath ?? DEFAULT_BASE_PATH);
|
|
156
|
+
const binaryName = options.binaryName ?? options.name;
|
|
157
|
+
if (typeof binaryName !== "string" || !SAFE_BINARY_NAME.test(binaryName)) {
|
|
158
|
+
throw new TypeError(`Invalid CLI distribution binaryName: ${String(binaryName)}`);
|
|
159
|
+
}
|
|
160
|
+
const installDir = validateInstallDir(options.installDir ?? DEFAULT_INSTALL_DIR);
|
|
161
|
+
const maxManifestBytes = options.maxManifestBytes ?? DEFAULT_MAX_MANIFEST_BYTES;
|
|
162
|
+
assertPositiveSafeInteger("maxManifestBytes", maxManifestBytes);
|
|
163
|
+
if (options.serviceName !== undefined && (typeof options.serviceName !== "string" || options.serviceName.trim().length === 0)) {
|
|
164
|
+
throw new TypeError("serviceName must be a non-empty string when provided");
|
|
165
|
+
}
|
|
166
|
+
if (options.onUnavailable !== undefined && typeof options.onUnavailable !== "function") {
|
|
167
|
+
throw new TypeError("onUnavailable must be a function when provided");
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
root: options.root,
|
|
171
|
+
name: options.name,
|
|
172
|
+
trust,
|
|
173
|
+
channels,
|
|
174
|
+
installerChannel,
|
|
175
|
+
basePath,
|
|
176
|
+
binaryName,
|
|
177
|
+
installDir,
|
|
178
|
+
maxManifestBytes,
|
|
179
|
+
serviceName: options.serviceName,
|
|
180
|
+
onUnavailable: options.onUnavailable
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function assetMatchesUrl(entryUrl, asset) {
|
|
184
|
+
let pathname;
|
|
185
|
+
try {
|
|
186
|
+
pathname = new URL(entryUrl).pathname;
|
|
187
|
+
} catch {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
if (pathname.endsWith("/"))
|
|
191
|
+
return false;
|
|
192
|
+
const segment = pathname.slice(pathname.lastIndexOf("/") + 1);
|
|
193
|
+
if (segment.length === 0)
|
|
194
|
+
return false;
|
|
195
|
+
try {
|
|
196
|
+
return decodeURIComponent(segment) === asset;
|
|
197
|
+
} catch {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/tools/cli/publication-contract.ts
|
|
203
|
+
import { isAbsolute as isAbsolute2 } from "node:path";
|
|
50
204
|
import { z } from "zod";
|
|
51
205
|
var positive = z.int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
52
206
|
var timer = positive.max(MAX_TIMER_MS);
|
|
@@ -80,7 +234,7 @@ var dataSchema = CliBuildManifestSchema2.pick({
|
|
|
80
234
|
name: component,
|
|
81
235
|
version: PublicationVersionSchema,
|
|
82
236
|
commit: z.string().min(1).max(128),
|
|
83
|
-
storageRoot: z.string().min(1).refine(
|
|
237
|
+
storageRoot: z.string().min(1).refine(isAbsolute2, "storageRoot must be absolute"),
|
|
84
238
|
baseUrl: z.url().refine((raw) => {
|
|
85
239
|
const url = new URL(raw);
|
|
86
240
|
return ["http:", "https:"].includes(url.protocol) && !url.username && !url.password && !url.search && !url.hash;
|
|
@@ -112,9 +266,288 @@ function assetUrl(baseUrl, version, filename) {
|
|
|
112
266
|
return new URL(`${encodeURIComponent(version)}/${encodeURIComponent(filename)}`, `${baseUrl.replace(/\/+$/, "")}/`).toString();
|
|
113
267
|
}
|
|
114
268
|
|
|
269
|
+
// src/tools/cli/distribution-routes.ts
|
|
270
|
+
var STREAM_CHUNK_BYTES = 64 * 1024;
|
|
271
|
+
var UNAVAILABLE_BODY = "No verified CLI build is published";
|
|
272
|
+
function notifyUnavailable(config, event) {
|
|
273
|
+
if (!config.onUnavailable)
|
|
274
|
+
return;
|
|
275
|
+
try {
|
|
276
|
+
config.onUnavailable(event);
|
|
277
|
+
} catch {}
|
|
278
|
+
}
|
|
279
|
+
function unavailableResponse() {
|
|
280
|
+
return new Response(UNAVAILABLE_BODY, {
|
|
281
|
+
status: 503,
|
|
282
|
+
headers: { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store" }
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function notFoundResponse(body) {
|
|
286
|
+
return new Response(body, {
|
|
287
|
+
status: 404,
|
|
288
|
+
headers: { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store" }
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
function mapManifestReadError(error) {
|
|
292
|
+
if (errnoOf(error) === "ENOENT")
|
|
293
|
+
return "missing";
|
|
294
|
+
if (error instanceof RegularFileError2) {
|
|
295
|
+
if (error.reason === "too-large")
|
|
296
|
+
return "too-large";
|
|
297
|
+
if (error.reason === "symbolic-link" || error.reason === "not-regular")
|
|
298
|
+
return "unsafe-path";
|
|
299
|
+
}
|
|
300
|
+
return "io-error";
|
|
301
|
+
}
|
|
302
|
+
async function readVerifiedManifest(config, route, channel, version, asset) {
|
|
303
|
+
const fail = (reason, extra) => {
|
|
304
|
+
notifyUnavailable(config, {
|
|
305
|
+
route,
|
|
306
|
+
channel,
|
|
307
|
+
...version !== undefined && { version },
|
|
308
|
+
...asset !== undefined && { asset },
|
|
309
|
+
reason,
|
|
310
|
+
...extra
|
|
311
|
+
});
|
|
312
|
+
return { ok: false, reason };
|
|
313
|
+
};
|
|
314
|
+
if (config.root === undefined)
|
|
315
|
+
return fail("unconfigured-root");
|
|
316
|
+
if (Object.keys(config.trust.keys).length === 0)
|
|
317
|
+
return fail("empty-trust-root");
|
|
318
|
+
const parts = ["channels", channel, ...version !== undefined ? [version] : []];
|
|
319
|
+
let canonicalRoot;
|
|
320
|
+
let canonicalParent;
|
|
321
|
+
try {
|
|
322
|
+
canonicalRoot = await realpath(config.root);
|
|
323
|
+
canonicalParent = await realpath(join(config.root, ...parts));
|
|
324
|
+
} catch (error) {
|
|
325
|
+
return fail(errnoOf(error) === "ENOENT" ? "missing" : "io-error", { error });
|
|
326
|
+
}
|
|
327
|
+
const expectedParent = join(canonicalRoot, ...parts);
|
|
328
|
+
if (!isWithinDir2(canonicalRoot, canonicalParent) || canonicalParent !== expectedParent) {
|
|
329
|
+
return fail("unsafe-path");
|
|
330
|
+
}
|
|
331
|
+
let bytes;
|
|
332
|
+
try {
|
|
333
|
+
bytes = await readRegularFile2(join(canonicalParent, "manifest.json"), {
|
|
334
|
+
limit: config.maxManifestBytes,
|
|
335
|
+
noFollow: true
|
|
336
|
+
});
|
|
337
|
+
} catch (error) {
|
|
338
|
+
return fail(mapManifestReadError(error), { error });
|
|
339
|
+
}
|
|
340
|
+
let parsedJson;
|
|
341
|
+
try {
|
|
342
|
+
parsedJson = parseJsonBytes2(bytes);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
return fail("invalid-manifest", { error });
|
|
345
|
+
}
|
|
346
|
+
const parsed = CliBuildManifestSchema2.safeParse(parsedJson);
|
|
347
|
+
if (!parsed.success)
|
|
348
|
+
return fail("invalid-manifest", { error: parsed.error });
|
|
349
|
+
const manifest = parsed.data;
|
|
350
|
+
if (manifest.name !== config.name || version !== undefined && manifest.version !== version) {
|
|
351
|
+
return fail("identity-mismatch");
|
|
352
|
+
}
|
|
353
|
+
const verdict = verifyCliManifest2(manifest, manifest.signature, config.trust);
|
|
354
|
+
if (verdict !== "valid")
|
|
355
|
+
return fail("untrusted-signature", { verdict });
|
|
356
|
+
return { ok: true, bytes, manifest, canonicalParent };
|
|
357
|
+
}
|
|
358
|
+
async function streamDescriptorAsset(assetPath, assetName) {
|
|
359
|
+
const { handle, before } = await openRegularFile(assetPath, { rejectSymlinks: true });
|
|
360
|
+
const headers = {
|
|
361
|
+
"Content-Type": "application/octet-stream",
|
|
362
|
+
"Content-Length": String(before.size),
|
|
363
|
+
"Content-Disposition": `attachment; filename="${assetName}"`,
|
|
364
|
+
"Cache-Control": "public, max-age=31536000, immutable"
|
|
365
|
+
};
|
|
366
|
+
if (before.size === 0) {
|
|
367
|
+
await handle.close();
|
|
368
|
+
return new Response(null, { status: 200, headers });
|
|
369
|
+
}
|
|
370
|
+
let closed = false;
|
|
371
|
+
let cancelled = false;
|
|
372
|
+
let bytesSent = 0;
|
|
373
|
+
let closePromise;
|
|
374
|
+
const closeOnce = () => {
|
|
375
|
+
closed = true;
|
|
376
|
+
closePromise ??= handle.close().catch(() => {
|
|
377
|
+
return;
|
|
378
|
+
});
|
|
379
|
+
return closePromise;
|
|
380
|
+
};
|
|
381
|
+
const body = new ReadableStream({
|
|
382
|
+
async pull(controller) {
|
|
383
|
+
if (cancelled || closed)
|
|
384
|
+
return;
|
|
385
|
+
const remaining = before.size - bytesSent;
|
|
386
|
+
if (remaining <= 0) {
|
|
387
|
+
await closeOnce();
|
|
388
|
+
if (!cancelled)
|
|
389
|
+
controller.close();
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const chunk = new Uint8Array(Math.min(STREAM_CHUNK_BYTES, remaining));
|
|
393
|
+
let bytesRead;
|
|
394
|
+
try {
|
|
395
|
+
({ bytesRead } = await handle.read(chunk, 0, chunk.byteLength));
|
|
396
|
+
} catch (error) {
|
|
397
|
+
await closeOnce();
|
|
398
|
+
if (!cancelled)
|
|
399
|
+
controller.error(error);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (cancelled || closed)
|
|
403
|
+
return;
|
|
404
|
+
if (bytesRead === 0) {
|
|
405
|
+
await closeOnce();
|
|
406
|
+
if (!cancelled)
|
|
407
|
+
controller.error(new Error("CLI asset truncated while streaming"));
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
bytesSent += bytesRead;
|
|
411
|
+
controller.enqueue(bytesRead === chunk.byteLength ? chunk : chunk.subarray(0, bytesRead));
|
|
412
|
+
if (bytesSent >= before.size) {
|
|
413
|
+
await closeOnce();
|
|
414
|
+
if (!cancelled)
|
|
415
|
+
controller.close();
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
async cancel() {
|
|
419
|
+
cancelled = true;
|
|
420
|
+
await closeOnce();
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
return new Response(body, { status: 200, headers });
|
|
424
|
+
}
|
|
425
|
+
function isServiceUnavailable(reason) {
|
|
426
|
+
return reason === "unconfigured-root" || reason === "empty-trust-root";
|
|
427
|
+
}
|
|
428
|
+
function routeServiceMeta(config, action) {
|
|
429
|
+
return config.serviceName !== undefined ? { serviceName: config.serviceName, action } : {};
|
|
430
|
+
}
|
|
431
|
+
function buildChannelRoutes(config, channel) {
|
|
432
|
+
return [
|
|
433
|
+
{
|
|
434
|
+
method: "GET",
|
|
435
|
+
...routeServiceMeta(config, "manifest"),
|
|
436
|
+
path: `${config.basePath}/channels/${channel}/manifest.json`,
|
|
437
|
+
handler: async () => {
|
|
438
|
+
const current = await readVerifiedManifest(config, "manifest", channel);
|
|
439
|
+
if (!current.ok)
|
|
440
|
+
return unavailableResponse();
|
|
441
|
+
return new Response(new Uint8Array(current.bytes), {
|
|
442
|
+
status: 200,
|
|
443
|
+
headers: { "Content-Type": "application/json", "Cache-Control": "no-store" }
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
method: "GET",
|
|
449
|
+
...routeServiceMeta(config, "asset"),
|
|
450
|
+
path: `${config.basePath}/channels/${channel}/:version/:asset`,
|
|
451
|
+
handler: async (_req, context) => {
|
|
452
|
+
const { version, asset } = context.params;
|
|
453
|
+
if (version === undefined || asset === undefined || !PublicationVersionSchema.safeParse(version).success || !SAFE_ASSET_SEGMENT.test(asset) || asset === "." || asset === "..") {
|
|
454
|
+
return new Response("Invalid asset path", {
|
|
455
|
+
status: 400,
|
|
456
|
+
headers: {
|
|
457
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
458
|
+
"Cache-Control": "no-store"
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
if (asset === "manifest.json") {
|
|
463
|
+
const record = await readVerifiedManifest(config, "version-manifest", channel, version, asset);
|
|
464
|
+
if (!record.ok) {
|
|
465
|
+
return isServiceUnavailable(record.reason) ? unavailableResponse() : notFoundResponse("CLI build not found");
|
|
466
|
+
}
|
|
467
|
+
return new Response(new Uint8Array(record.bytes), {
|
|
468
|
+
status: 200,
|
|
469
|
+
headers: {
|
|
470
|
+
"Content-Type": "application/json",
|
|
471
|
+
"Cache-Control": "public, max-age=31536000, immutable"
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
const record = await readVerifiedManifest(config, "asset", channel, version, asset);
|
|
476
|
+
if (!record.ok) {
|
|
477
|
+
return isServiceUnavailable(record.reason) ? unavailableResponse() : notFoundResponse("CLI asset not found");
|
|
478
|
+
}
|
|
479
|
+
if (!record.manifest.assets.some((entry) => assetMatchesUrl(entry.url, asset))) {
|
|
480
|
+
notifyUnavailable(config, {
|
|
481
|
+
route: "asset",
|
|
482
|
+
channel,
|
|
483
|
+
version,
|
|
484
|
+
asset,
|
|
485
|
+
reason: "unlisted-asset"
|
|
486
|
+
});
|
|
487
|
+
return notFoundResponse("CLI asset not found");
|
|
488
|
+
}
|
|
489
|
+
try {
|
|
490
|
+
return await streamDescriptorAsset(join(record.canonicalParent, asset), asset);
|
|
491
|
+
} catch (error) {
|
|
492
|
+
const reason = errnoOf(error) === "ENOENT" ? "missing" : error instanceof BoundedFileReadError && (error.code === "FILE_UNSAFE_LINK" || error.code === "FILE_NOT_REGULAR") ? "unsafe-path" : "io-error";
|
|
493
|
+
notifyUnavailable(config, {
|
|
494
|
+
route: "asset",
|
|
495
|
+
channel,
|
|
496
|
+
version,
|
|
497
|
+
asset,
|
|
498
|
+
reason,
|
|
499
|
+
error
|
|
500
|
+
});
|
|
501
|
+
return notFoundResponse("CLI asset not found");
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
];
|
|
506
|
+
}
|
|
507
|
+
function createCliDistributionRoutes(options) {
|
|
508
|
+
const config = resolveDistributionConfig(options);
|
|
509
|
+
return [
|
|
510
|
+
...config.channels.flatMap((channel) => buildChannelRoutes(config, channel)),
|
|
511
|
+
{
|
|
512
|
+
method: "GET",
|
|
513
|
+
...routeServiceMeta(config, "installer"),
|
|
514
|
+
path: `${config.basePath}/install.sh`,
|
|
515
|
+
handler: async () => {
|
|
516
|
+
const current = await readVerifiedManifest(config, "installer", config.installerChannel);
|
|
517
|
+
if (!current.ok)
|
|
518
|
+
return unavailableResponse();
|
|
519
|
+
if (current.manifest.assets.length === 0) {
|
|
520
|
+
notifyUnavailable(config, {
|
|
521
|
+
route: "installer",
|
|
522
|
+
channel: config.installerChannel,
|
|
523
|
+
reason: "invalid-manifest"
|
|
524
|
+
});
|
|
525
|
+
return unavailableResponse();
|
|
526
|
+
}
|
|
527
|
+
return new Response(renderCliInstaller2({
|
|
528
|
+
manifest: current.manifest,
|
|
529
|
+
binaryName: config.binaryName,
|
|
530
|
+
installDir: config.installDir
|
|
531
|
+
}), {
|
|
532
|
+
status: 200,
|
|
533
|
+
headers: {
|
|
534
|
+
"Content-Type": "text/x-shellscript; charset=utf-8",
|
|
535
|
+
"Cache-Control": "no-store"
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
];
|
|
541
|
+
}
|
|
542
|
+
// src/tools/cli/publication.ts
|
|
543
|
+
import { createHash } from "node:crypto";
|
|
544
|
+
import { lstat as lstat2, mkdtemp, rename, rm as rm2 } from "node:fs/promises";
|
|
545
|
+
import { join as join3 } from "node:path";
|
|
546
|
+
import { z as z3 } from "zod";
|
|
547
|
+
|
|
115
548
|
// src/tools/cli/publication-storage.ts
|
|
116
|
-
import { lstat, mkdir, opendir, realpath, rm } from "node:fs/promises";
|
|
117
|
-
import { join, resolve } from "node:path";
|
|
549
|
+
import { lstat, mkdir, opendir, realpath as realpath2, rm } from "node:fs/promises";
|
|
550
|
+
import { join as join2, resolve } from "node:path";
|
|
118
551
|
import { z as z2 } from "zod";
|
|
119
552
|
async function directoryGeneration(path) {
|
|
120
553
|
const info = await lstat(path);
|
|
@@ -138,7 +571,7 @@ async function bindPublicationStorage(data, signal) {
|
|
|
138
571
|
throw error;
|
|
139
572
|
}
|
|
140
573
|
await directoryGeneration(requested);
|
|
141
|
-
const root = await
|
|
574
|
+
const root = await realpath2(requested);
|
|
142
575
|
const generation = await directoryGeneration(root);
|
|
143
576
|
const files = await createManagedFileBoundary2({
|
|
144
577
|
root,
|
|
@@ -214,7 +647,7 @@ function assertPublicationManifest(record, data, exactTargets) {
|
|
|
214
647
|
}
|
|
215
648
|
async function assertStoredLayout(storage, record, expected, data, signal) {
|
|
216
649
|
const version = record.manifest.version;
|
|
217
|
-
const names = await directoryNames(
|
|
650
|
+
const names = await directoryNames(join2(storage.root, version), data.limits.maxDirectoryEntries, signal);
|
|
218
651
|
if (JSON.stringify(names) !== JSON.stringify([...expected, "manifest.json"].sort()))
|
|
219
652
|
throw new Error("CLI version has unknown or missing files");
|
|
220
653
|
const saved = await readPublicationManifest(storage, `${version}/manifest.json`, data, signal);
|
|
@@ -224,7 +657,7 @@ async function assertStoredLayout(storage, record, expected, data, signal) {
|
|
|
224
657
|
async function verifyPublicationVersion(storage, record, data, signal, exactTargets) {
|
|
225
658
|
const { manifest } = record;
|
|
226
659
|
const expected = assertPublicationManifest(record, data, exactTargets);
|
|
227
|
-
const directory =
|
|
660
|
+
const directory = join2(storage.root, manifest.version);
|
|
228
661
|
const generation = await directoryGeneration(directory);
|
|
229
662
|
await assertStoredLayout(storage, record, expected, data, signal);
|
|
230
663
|
for (const asset of manifest.assets) {
|
|
@@ -245,7 +678,7 @@ async function publicationHistory(storage, data, signal) {
|
|
|
245
678
|
for (const name of await directoryNames(storage.root, data.limits.maxDirectoryEntries, signal)) {
|
|
246
679
|
if (!PublicationVersionSchema.safeParse(name).success)
|
|
247
680
|
continue;
|
|
248
|
-
const path =
|
|
681
|
+
const path = join2(storage.root, name);
|
|
249
682
|
const info = await lstat(path);
|
|
250
683
|
if (!info.isDirectory() || info.isSymbolicLink())
|
|
251
684
|
continue;
|
|
@@ -292,7 +725,7 @@ async function reclaimPublicationStaging(storage, signal) {
|
|
|
292
725
|
}
|
|
293
726
|
for (const name of stale) {
|
|
294
727
|
signal.throwIfAborted();
|
|
295
|
-
await rm(
|
|
728
|
+
await rm(join2(storage.root, name), { recursive: true });
|
|
296
729
|
}
|
|
297
730
|
if (stale.length > 0)
|
|
298
731
|
await syncDirectory(storage.root);
|
|
@@ -357,7 +790,7 @@ async function promote(storage, record, prior, data, options, lock, signal) {
|
|
|
357
790
|
if (names.length + 1 > data.limits.maxDirectoryEntries)
|
|
358
791
|
throw new RangeError("CLI publication directory entry cap leaves no pointer space");
|
|
359
792
|
signal.throwIfAborted();
|
|
360
|
-
await writeFileAtomic2(
|
|
793
|
+
await writeFileAtomic2(join3(storage.root, "manifest.json"), record.bytes, {
|
|
361
794
|
mode: 420,
|
|
362
795
|
durability: "directory"
|
|
363
796
|
});
|
|
@@ -369,7 +802,7 @@ async function buildVersion(storage, data, options, lock, prior, signal) {
|
|
|
369
802
|
const names = await directoryNames(storage.root, data.limits.maxDirectoryEntries, signal);
|
|
370
803
|
if (names.length + 2 > data.limits.maxDirectoryEntries)
|
|
371
804
|
throw new RangeError("CLI publication directory entry cap leaves no commit space");
|
|
372
|
-
const staged = await mkdtemp(
|
|
805
|
+
const staged = await mkdtemp(join3(storage.root, ".publish-"));
|
|
373
806
|
const generation = await directoryGeneration(staged);
|
|
374
807
|
let committed = false;
|
|
375
808
|
try {
|
|
@@ -427,14 +860,14 @@ async function buildVersion(storage, data, options, lock, prior, signal) {
|
|
|
427
860
|
await unchanged(storage, prior, data, lock, signal);
|
|
428
861
|
await assertDirectory(staged, generation);
|
|
429
862
|
try {
|
|
430
|
-
await lstat2(
|
|
863
|
+
await lstat2(join3(storage.root, data.version));
|
|
431
864
|
throw new Error("CLI version directory already exists");
|
|
432
865
|
} catch (error) {
|
|
433
866
|
if (errnoOf(error) !== "ENOENT")
|
|
434
867
|
throw error;
|
|
435
868
|
}
|
|
436
869
|
signal.throwIfAborted();
|
|
437
|
-
await rename(staged,
|
|
870
|
+
await rename(staged, join3(storage.root, data.version));
|
|
438
871
|
committed = true;
|
|
439
872
|
await syncDirectory(storage.root);
|
|
440
873
|
return { manifest, bytes };
|
|
@@ -499,7 +932,7 @@ async function publishLocked(storage, data, options, lock, signal) {
|
|
|
499
932
|
stored = await retainVersions(storage, history, protect, data.limits.maxStoredVersions - 1, data, lock, signal);
|
|
500
933
|
record = {
|
|
501
934
|
...await buildVersion(storage, data, options, lock, prior, signal),
|
|
502
|
-
directory:
|
|
935
|
+
directory: join3(storage.root, data.version)
|
|
503
936
|
};
|
|
504
937
|
await verifyPublicationVersion(storage, record, data, signal, true);
|
|
505
938
|
stored = [...stored, record];
|
|
@@ -522,9 +955,231 @@ async function publishCli(options) {
|
|
|
522
955
|
const data = publicationData(options);
|
|
523
956
|
return withPublicationDeadline(data.limits.timeoutMs, options.signal, async (signal) => {
|
|
524
957
|
const storage = await bindPublicationStorage(data, signal);
|
|
525
|
-
return withExclusiveLock2(
|
|
958
|
+
return withExclusiveLock2(join3(storage.root, ".publication.lock"), (lock) => publishLocked(storage, data, options, lock, signal), { timeoutMs: data.limits.lockTimeoutMs, signal, label: "CLI publication" });
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
// src/tools/cli/publication-source.ts
|
|
962
|
+
import { realpath as realpath3 } from "node:fs/promises";
|
|
963
|
+
import { isAbsolute as isAbsolute3 } from "node:path";
|
|
964
|
+
import { z as z4 } from "zod";
|
|
965
|
+
var DEFAULT_GIT_TIMEOUT_MS = 30000;
|
|
966
|
+
var MAX_GIT_OUTPUT_BYTES = 1024 * 1024;
|
|
967
|
+
var COMMIT_SHA_PATTERN = /^[0-9a-f]{40}$/;
|
|
968
|
+
var STRICT_SEMVER_CORE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
969
|
+
var NON_NEGATIVE_INT_PATTERN = /^(0|[1-9]\d*)$/;
|
|
970
|
+
var CONTROL_CHAR_PATTERN2 = /[\u0000-\u001f\u007f]/;
|
|
971
|
+
var GLOB_CHAR_PATTERN = /[*?[\]]/;
|
|
972
|
+
var PackageSeriesSchema = z4.object({
|
|
973
|
+
version: z4.string().regex(STRICT_SEMVER_CORE)
|
|
974
|
+
});
|
|
975
|
+
function assertAbsolutePath(value, label) {
|
|
976
|
+
if (typeof value !== "string" || value.length === 0 || !isAbsolute3(value)) {
|
|
977
|
+
throw new TypeError(`${label} must be a non-empty absolute path`);
|
|
978
|
+
}
|
|
979
|
+
return value;
|
|
980
|
+
}
|
|
981
|
+
function assertCommitSha(value, label) {
|
|
982
|
+
if (typeof value !== "string" || !COMMIT_SHA_PATTERN.test(value)) {
|
|
983
|
+
throw new TypeError(`${label} must be 40 lowercase hex characters`);
|
|
984
|
+
}
|
|
985
|
+
return value;
|
|
986
|
+
}
|
|
987
|
+
function assertRelativeGitPath(value, label, options) {
|
|
988
|
+
if (typeof value !== "string" || value.length === 0 || value.trim() !== value) {
|
|
989
|
+
throw new TypeError(`${label} must be a non-empty trimmed repository-relative path`);
|
|
990
|
+
}
|
|
991
|
+
if (CONTROL_CHAR_PATTERN2.test(value) || value.startsWith("/") || value.startsWith("-") || value.includes(":") || value.includes("\\") || value.includes("//")) {
|
|
992
|
+
throw new TypeError(`${label} contains an unsafe git path or magic pathspec: ${value}`);
|
|
993
|
+
}
|
|
994
|
+
if (!options.allowGlob && (value.endsWith("/") || GLOB_CHAR_PATTERN.test(value))) {
|
|
995
|
+
throw new TypeError(`${label} must be a literal path without globs or trailing slash: ${value}`);
|
|
996
|
+
}
|
|
997
|
+
const segments = value.split("/");
|
|
998
|
+
if (segments.some((segment) => segment === "." || segment === "..")) {
|
|
999
|
+
throw new TypeError(`${label} must not contain "." or ".." path segments: ${value}`);
|
|
1000
|
+
}
|
|
1001
|
+
return value;
|
|
1002
|
+
}
|
|
1003
|
+
function assertGitPathList(paths, label, options) {
|
|
1004
|
+
if (!Array.isArray(paths) || paths.length === 0) {
|
|
1005
|
+
throw new TypeError(`${label} must be a non-empty array of repository-relative paths`);
|
|
1006
|
+
}
|
|
1007
|
+
return paths.map((entry, index) => assertRelativeGitPath(entry, `${label}[${index}]`, options));
|
|
1008
|
+
}
|
|
1009
|
+
function gitCommandEnv() {
|
|
1010
|
+
const env = {
|
|
1011
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
1012
|
+
GIT_OPTIONAL_LOCKS: "0"
|
|
1013
|
+
};
|
|
1014
|
+
if (typeof process.env.PATH === "string" && process.env.PATH.length > 0) {
|
|
1015
|
+
env.PATH = process.env.PATH;
|
|
1016
|
+
}
|
|
1017
|
+
if (typeof process.env.HOME === "string" && process.env.HOME.length > 0) {
|
|
1018
|
+
env.HOME = process.env.HOME;
|
|
1019
|
+
}
|
|
1020
|
+
return env;
|
|
1021
|
+
}
|
|
1022
|
+
var UTF8 = new TextDecoder;
|
|
1023
|
+
async function runGit(repository, args, signal, acceptedExitCodes = [0]) {
|
|
1024
|
+
const result = await runNativeCommand2({
|
|
1025
|
+
executable: "git",
|
|
1026
|
+
args: [...args],
|
|
1027
|
+
cwd: repository,
|
|
1028
|
+
envPolicy: "declared-only",
|
|
1029
|
+
env: gitCommandEnv(),
|
|
1030
|
+
capture: true,
|
|
1031
|
+
maxOutputBytes: MAX_GIT_OUTPUT_BYTES,
|
|
1032
|
+
signal
|
|
1033
|
+
});
|
|
1034
|
+
const rawStdout = result.stdout ?? new Uint8Array(0);
|
|
1035
|
+
const stdout = UTF8.decode(rawStdout).replace(/\r?\n$/, "");
|
|
1036
|
+
if (result.exitCode === null || !acceptedExitCodes.includes(result.exitCode)) {
|
|
1037
|
+
const stderr = UTF8.decode(result.stderr ?? new Uint8Array(0)).trim();
|
|
1038
|
+
const detail = stderr || stdout.trim() || `signal ${result.signal ?? "unknown"}`;
|
|
1039
|
+
throw new Error(`CLI source git ${args[0] ?? ""} failed (exit ${result.exitCode ?? "null"}): ${detail}`);
|
|
1040
|
+
}
|
|
1041
|
+
return { exitCode: result.exitCode, stdout, rawStdout };
|
|
1042
|
+
}
|
|
1043
|
+
async function assertWorktreeRoot(repository, signal) {
|
|
1044
|
+
const inside = await runGit(repository, ["rev-parse", "--is-inside-work-tree"], signal);
|
|
1045
|
+
if (inside.stdout !== "true") {
|
|
1046
|
+
throw new Error(`CLI repository is not a git working tree: ${repository}`);
|
|
1047
|
+
}
|
|
1048
|
+
const toplevel = await runGit(repository, ["rev-parse", "--show-toplevel"], signal);
|
|
1049
|
+
const [realRepo, realTop] = await Promise.all([
|
|
1050
|
+
realpath3(repository),
|
|
1051
|
+
realpath3(toplevel.stdout)
|
|
1052
|
+
]);
|
|
1053
|
+
if (realRepo !== realTop) {
|
|
1054
|
+
throw new Error(`CLI repository must be the git repository root (${realTop}), received subdirectory ${realRepo}`);
|
|
1055
|
+
}
|
|
1056
|
+
return realRepo;
|
|
1057
|
+
}
|
|
1058
|
+
async function assertGitRepositoryRoot(repository, signal) {
|
|
1059
|
+
const inside = await runGit(repository, ["rev-parse", "--is-inside-work-tree"], signal);
|
|
1060
|
+
if (inside.stdout === "true") {
|
|
1061
|
+
const toplevel = await runGit(repository, ["rev-parse", "--show-toplevel"], signal);
|
|
1062
|
+
const [realRepo, realTop] = await Promise.all([
|
|
1063
|
+
realpath3(repository),
|
|
1064
|
+
realpath3(toplevel.stdout)
|
|
1065
|
+
]);
|
|
1066
|
+
if (realRepo !== realTop) {
|
|
1067
|
+
throw new Error(`CLI repository must be the git repository root (${realTop}), received subdirectory ${realRepo}`);
|
|
1068
|
+
}
|
|
1069
|
+
return realRepo;
|
|
1070
|
+
}
|
|
1071
|
+
const bare = await runGit(repository, ["rev-parse", "--is-bare-repository"], signal);
|
|
1072
|
+
if (bare.stdout !== "true") {
|
|
1073
|
+
throw new Error(`CLI repository must be a git worktree root or bare repository root: ${repository}`);
|
|
1074
|
+
}
|
|
1075
|
+
const gitDir = await runGit(repository, ["rev-parse", "--absolute-git-dir"], signal);
|
|
1076
|
+
const [realRepo, realGitDir] = await Promise.all([
|
|
1077
|
+
realpath3(repository),
|
|
1078
|
+
realpath3(gitDir.stdout)
|
|
1079
|
+
]);
|
|
1080
|
+
if (realRepo !== realGitDir) {
|
|
1081
|
+
throw new Error(`CLI repository must be the bare git repository root (${realGitDir}), received subdirectory ${realRepo}`);
|
|
1082
|
+
}
|
|
1083
|
+
return realRepo;
|
|
1084
|
+
}
|
|
1085
|
+
async function assertExactCommit(repository, sha, label, signal) {
|
|
1086
|
+
const commitRef = `${sha}^{commit}`;
|
|
1087
|
+
const verified = await runGit(repository, ["rev-parse", "--verify", commitRef], signal);
|
|
1088
|
+
if (verified.stdout !== sha) {
|
|
1089
|
+
throw new Error(`${label} (${sha}) is not a commit object (resolved to ${verified.stdout})`);
|
|
1090
|
+
}
|
|
1091
|
+
return commitRef;
|
|
1092
|
+
}
|
|
1093
|
+
async function deriveCliVersionFromShippingInputs(options) {
|
|
1094
|
+
const repository = assertAbsolutePath(options.repository, "repository");
|
|
1095
|
+
const commit = assertCommitSha(options.commit, "commit");
|
|
1096
|
+
const packageJsonPath = assertRelativeGitPath(options.packageJsonPath, "packageJsonPath", {
|
|
1097
|
+
allowGlob: false
|
|
1098
|
+
});
|
|
1099
|
+
const shippingPaths = assertGitPathList(options.shippingPaths, "shippingPaths", {
|
|
1100
|
+
allowGlob: false
|
|
1101
|
+
});
|
|
1102
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_GIT_TIMEOUT_MS;
|
|
1103
|
+
assertTimerMs("timeoutMs", timeoutMs);
|
|
1104
|
+
return withPublicationDeadline(timeoutMs, options.signal, async (signal) => {
|
|
1105
|
+
await assertGitRepositoryRoot(repository, signal);
|
|
1106
|
+
const shallow = await runGit(repository, ["rev-parse", "--is-shallow-repository"], signal);
|
|
1107
|
+
if (shallow.stdout !== "false") {
|
|
1108
|
+
throw new Error("CLI version requires the full git history of its shipping inputs (shallow repository refused)");
|
|
1109
|
+
}
|
|
1110
|
+
const commitRef = await assertExactCommit(repository, commit, "commit", signal);
|
|
1111
|
+
const packageFile = await runGit(repository, ["show", `${commitRef}:${packageJsonPath}`], signal);
|
|
1112
|
+
const parsed = PackageSeriesSchema.parse(parseJsonBytes2(packageFile.rawStdout));
|
|
1113
|
+
const [major, minor] = parsed.version.split(".");
|
|
1114
|
+
const count = await runGit(repository, ["rev-list", "--count", commitRef, "--", ...shippingPaths], signal);
|
|
1115
|
+
if (!NON_NEGATIVE_INT_PATTERN.test(count.stdout) || !Number.isSafeInteger(Number(count.stdout))) {
|
|
1116
|
+
throw new Error(`Unexpected git rev-list count: ${count.stdout}`);
|
|
1117
|
+
}
|
|
1118
|
+
return PublicationVersionSchema.parse(`${major}.${minor}.${count.stdout}`);
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
async function cliShippingInputsChanged(options) {
|
|
1122
|
+
const repository = assertAbsolutePath(options.repository, "repository");
|
|
1123
|
+
const previousCommit = assertCommitSha(options.previousCommit, "previousCommit");
|
|
1124
|
+
const nextCommit = assertCommitSha(options.nextCommit, "nextCommit");
|
|
1125
|
+
const shippingPaths = assertGitPathList(options.shippingPaths, "shippingPaths", {
|
|
1126
|
+
allowGlob: false
|
|
1127
|
+
});
|
|
1128
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_GIT_TIMEOUT_MS;
|
|
1129
|
+
assertTimerMs("timeoutMs", timeoutMs);
|
|
1130
|
+
return withPublicationDeadline(timeoutMs, options.signal, async (signal) => {
|
|
1131
|
+
await assertGitRepositoryRoot(repository, signal);
|
|
1132
|
+
const previousRef = await assertExactCommit(repository, previousCommit, "previousCommit", signal);
|
|
1133
|
+
const nextRef = await assertExactCommit(repository, nextCommit, "nextCommit", signal);
|
|
1134
|
+
const diff = await runGit(repository, ["diff", "--no-ext-diff", "--quiet", previousRef, nextRef, "--", ...shippingPaths], signal, [0, 1]);
|
|
1135
|
+
return diff.exitCode === 1;
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
async function assertCleanCliSource(options) {
|
|
1139
|
+
const repository = assertAbsolutePath(options.repository, "repository");
|
|
1140
|
+
const expectedCommit = options.expectedCommit === undefined ? undefined : assertCommitSha(options.expectedCommit, "expectedCommit");
|
|
1141
|
+
const untrackedPaths = options.untrackedPaths === undefined ? undefined : assertGitPathList(options.untrackedPaths, "untrackedPaths", { allowGlob: true });
|
|
1142
|
+
const servingSource = options.servingSource === undefined ? undefined : assertAbsolutePath(options.servingSource, "servingSource");
|
|
1143
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_GIT_TIMEOUT_MS;
|
|
1144
|
+
assertTimerMs("timeoutMs", timeoutMs);
|
|
1145
|
+
return withPublicationDeadline(timeoutMs, options.signal, async (signal) => {
|
|
1146
|
+
const realRepo = await assertWorktreeRoot(repository, signal);
|
|
1147
|
+
const headResult = await runGit(repository, ["rev-parse", "--verify", "HEAD^{commit}"], signal);
|
|
1148
|
+
const head = assertCommitSha(headResult.stdout, "HEAD");
|
|
1149
|
+
if (expectedCommit !== undefined && head !== expectedCommit) {
|
|
1150
|
+
throw new Error(`CLI source HEAD (${head}) does not match expected commit ${expectedCommit}`);
|
|
1151
|
+
}
|
|
1152
|
+
if (untrackedPaths === undefined) {
|
|
1153
|
+
const dirty = await runGit(repository, ["status", "--porcelain=v1", "--untracked-files=normal"], signal);
|
|
1154
|
+
if (dirty.rawStdout.byteLength > 0) {
|
|
1155
|
+
throw new Error(`CLI publication requires a clean working tree:
|
|
1156
|
+
${dirty.stdout}`);
|
|
1157
|
+
}
|
|
1158
|
+
} else {
|
|
1159
|
+
const tracked = await runGit(repository, ["status", "--porcelain=v1", "--untracked-files=no"], signal);
|
|
1160
|
+
if (tracked.rawStdout.byteLength > 0) {
|
|
1161
|
+
throw new Error(`CLI source has tracked changes:
|
|
1162
|
+
${tracked.stdout}`);
|
|
1163
|
+
}
|
|
1164
|
+
const untracked = await runGit(repository, ["ls-files", "--others", "--exclude-standard", "--", ...untrackedPaths], signal);
|
|
1165
|
+
if (untracked.rawStdout.byteLength > 0) {
|
|
1166
|
+
throw new Error(`CLI source has untracked shipping inputs:
|
|
1167
|
+
${untracked.stdout}`);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
if (servingSource !== undefined) {
|
|
1171
|
+
const realServing = await realpath3(servingSource);
|
|
1172
|
+
if (realServing !== realRepo) {
|
|
1173
|
+
throw new Error(`CLI release source (${realRepo}) does not match serving source (${realServing})`);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
return head;
|
|
526
1177
|
});
|
|
527
1178
|
}
|
|
528
1179
|
export {
|
|
1180
|
+
assertCleanCliSource,
|
|
1181
|
+
cliShippingInputsChanged,
|
|
1182
|
+
createCliDistributionRoutes,
|
|
1183
|
+
deriveCliVersionFromShippingInputs,
|
|
529
1184
|
publishCli
|
|
530
1185
|
};
|