overvues 0.0.1 → 0.4.10
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/README.md +58 -2
- package/dist/ansi.js +24 -0
- package/dist/attach-client.js +586 -0
- package/dist/auth-connect-browser.js +112 -0
- package/dist/auth-connect.js +306 -0
- package/dist/browser-bootstrap.js +190 -0
- package/dist/browser-loopback.js +289 -0
- package/dist/build-identity.js +6 -0
- package/dist/codex-reviewer-apparmor.json +4 -0
- package/dist/codex-reviewer-seccomp.json +1238 -0
- package/dist/codex-runtime-protocol.js +1 -0
- package/dist/codex-subscription.js +53 -0
- package/dist/config.js +297 -0
- package/dist/connect-comparison-code.js +26 -0
- package/dist/development-runner.js +109 -0
- package/dist/dns-doctor.js +390 -0
- package/dist/docker-names.js +47 -0
- package/dist/doctor.js +114 -0
- package/dist/gadget-job.js +804 -0
- package/dist/health-check.js +112 -0
- package/dist/help.js +71 -0
- package/dist/host-auth.js +22 -0
- package/dist/host-diagnostics.js +20 -0
- package/dist/host-runtime-identity.js +39 -0
- package/dist/host-runtime-metadata.js +56 -0
- package/dist/host-service.js +377 -0
- package/dist/host-stack.js +484 -0
- package/dist/host-supervisor.js +237 -0
- package/dist/host-update.js +387 -0
- package/dist/hub-address.js +100 -0
- package/dist/hub-client.js +459 -0
- package/dist/hub-kind.js +88 -0
- package/dist/identity.js +73 -0
- package/dist/index.js +185 -0
- package/dist/init.js +295 -0
- package/dist/isolated-run-cache.js +116 -0
- package/dist/local-stack.js +685 -0
- package/dist/machine-capacity.js +128 -0
- package/dist/managed-runner-image.js +13 -0
- package/dist/os-acted-record.js +49 -0
- package/dist/os-adapter.js +8190 -0
- package/dist/os-command.js +292 -0
- package/dist/os-handoff.js +274 -0
- package/dist/os-keychain.js +247 -0
- package/dist/os-machine.js +818 -0
- package/dist/os-owner.js +61 -0
- package/dist/os-private-file.js +98 -0
- package/dist/os-protocol.js +468 -0
- package/dist/os-session-store.js +133 -0
- package/dist/os-status.js +102 -0
- package/dist/picker.js +863 -0
- package/dist/portable-workspace-capability.js +60 -0
- package/dist/project-environment-capability.js +62 -0
- package/dist/project-environment.js +28 -0
- package/dist/project-preparation.js +134 -0
- package/dist/readiness.js +28 -0
- package/dist/redaction.js +27 -0
- package/dist/reviewer-isolation-capability.js +61 -0
- package/dist/runner-api-auth.js +80 -0
- package/dist/runner-command-fence.js +536 -0
- package/dist/runner-inspection.js +57 -0
- package/dist/runner-inventory.js +587 -0
- package/dist/runner-server.js +2520 -0
- package/dist/runner-session.js +470 -0
- package/dist/runner-slug-folder.js +39 -0
- package/dist/runner-slug.js +40 -0
- package/dist/setup.js +139 -0
- package/dist/shutdown.js +102 -0
- package/dist/splash.js +65 -0
- package/dist/staged-workspaces.js +441 -0
- package/dist/staging-disk.js +97 -0
- package/dist/terminal-lane.js +339 -0
- package/dist/terminal-recovery.js +502 -0
- package/licenses/capnweb.txt +23 -0
- package/licenses/moby-profiles.txt +212 -0
- package/licenses/ws.txt +22 -0
- package/package.json +28 -7
- package/cli.js +0 -2
package/dist/identity.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The program's own name and everything named after it, in one place.
|
|
2
|
+
//
|
|
3
|
+
// One source builds two programs: `tiller` (`@paperwing-dev/tiller`, for both kinds of hub) and
|
|
4
|
+
// `overvues` (the `overvues` package, for Overvues Dev hubs only). Each keeps its own config folder,
|
|
5
|
+
// background service, Docker names, keychain entries, environment variables and runner port, so
|
|
6
|
+
// both can be installed on one machine, each connected to its own hub, without either reading or
|
|
7
|
+
// touching the other's. Which one a build is comes from `build-identity.ts`, fixed when the package
|
|
8
|
+
// is built; there is no flag or variable that switches it.
|
|
9
|
+
//
|
|
10
|
+
// What does not change with the identity: protocol names the hub, the image or the harness read
|
|
11
|
+
// (`X-Tiller-*` headers, `TILLER_*` variables passed into containers, JWE types, image labels such
|
|
12
|
+
// as `dev.tiller.portable-workspace-restore-protocol`), the published sandbox image, and file
|
|
13
|
+
// names inside the config folder.
|
|
14
|
+
// This module imports nothing from Node: the hub's Worker imports `os-protocol.ts`, which uses it.
|
|
15
|
+
import { BUILD_IDENTITY } from "./build-identity.js";
|
|
16
|
+
export const IDENTITIES = Object.freeze({
|
|
17
|
+
tiller: Object.freeze({
|
|
18
|
+
name: "tiller",
|
|
19
|
+
command: "tiller",
|
|
20
|
+
productName: "Tiller",
|
|
21
|
+
logTag: "[tiller]",
|
|
22
|
+
npmPackage: "@paperwing-dev/tiller",
|
|
23
|
+
configDirName: "tiller",
|
|
24
|
+
envPrefix: "TILLER_",
|
|
25
|
+
hubUrlEnv: "HUB_URL",
|
|
26
|
+
launchdLabel: "dev.tiller.host",
|
|
27
|
+
systemdServiceName: "tiller-host.service",
|
|
28
|
+
hostLogFileName: "tiller-host.log",
|
|
29
|
+
dockerNamePrefix: "tiller",
|
|
30
|
+
keychainService: "dev.paperwing.tiller.os-session",
|
|
31
|
+
keychainAccountPrefix: "tiller",
|
|
32
|
+
defaultRunnerPort: 8789,
|
|
33
|
+
hubKinds: Object.freeze(["tiller", "overvues-dev"]),
|
|
34
|
+
}),
|
|
35
|
+
overvues: Object.freeze({
|
|
36
|
+
name: "overvues",
|
|
37
|
+
command: "overvues",
|
|
38
|
+
productName: "Overvues Dev",
|
|
39
|
+
logTag: "[overvues]",
|
|
40
|
+
npmPackage: "overvues",
|
|
41
|
+
configDirName: "overvues",
|
|
42
|
+
envPrefix: "OVERVUES_",
|
|
43
|
+
hubUrlEnv: "OVERVUES_HUB_URL",
|
|
44
|
+
launchdLabel: "dev.overvues.host",
|
|
45
|
+
systemdServiceName: "overvues-host.service",
|
|
46
|
+
hostLogFileName: "overvues-host.log",
|
|
47
|
+
dockerNamePrefix: "overvues",
|
|
48
|
+
keychainService: "dev.paperwing.overvues.os-session",
|
|
49
|
+
keychainAccountPrefix: "overvues",
|
|
50
|
+
defaultRunnerPort: 8791,
|
|
51
|
+
hubKinds: Object.freeze(["overvues-dev"]),
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
export function identityNamed(name) {
|
|
55
|
+
if (name !== "tiller" && name !== "overvues")
|
|
56
|
+
throw new Error(`Unknown CLI identity ${JSON.stringify(name)}.`);
|
|
57
|
+
return IDENTITIES[name];
|
|
58
|
+
}
|
|
59
|
+
/** This build's identity. */
|
|
60
|
+
export const CLI = identityNamed(BUILD_IDENTITY);
|
|
61
|
+
const OS_WORDS = Object.freeze({
|
|
62
|
+
tiller: Object.freeze({ the: "the OS", The: "The OS", noun: "OS" }),
|
|
63
|
+
overvues: Object.freeze({ the: "Overvues", The: "Overvues", noun: "Overvues" }),
|
|
64
|
+
});
|
|
65
|
+
export function osWords(identity = CLI) {
|
|
66
|
+
return OS_WORDS[identity.name];
|
|
67
|
+
}
|
|
68
|
+
/** This build's words for the OS. */
|
|
69
|
+
export const OS = osWords(CLI);
|
|
70
|
+
/** The name of a setting read from the shell: `envVar("CONFIG_DIR")` is `TILLER_CONFIG_DIR` or `OVERVUES_CONFIG_DIR`. */
|
|
71
|
+
export function envVar(suffix, identity = CLI) {
|
|
72
|
+
return `${identity.envPrefix}${suffix}`;
|
|
73
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { HUB_URL, TILLER_CONFIG_DIR, hubControlHeaders, ensureAuth, ensureHostAuth, } from "./config.js";
|
|
3
|
+
import { fetchHubSetupStatus } from "./codex-subscription.js";
|
|
4
|
+
import { runDnsDoctorCommand } from "./dns-doctor.js";
|
|
5
|
+
import { runAttach } from "./attach-client.js";
|
|
6
|
+
import { runDoctor } from "./doctor.js";
|
|
7
|
+
import { runHostCommand, runHostDownCommand, runHostInstallServiceCommand, runHostSetupCommand, runHostStatusCommand, } from "./host-stack.js";
|
|
8
|
+
import { parseHostUpdateArgs, runHostUpdateCommand } from "./host-update.js";
|
|
9
|
+
import { ensureControlCredential, ensureInteractiveConfig, runInit, } from "./init.js";
|
|
10
|
+
import { shutdownAutoStartedLocalEnvs } from "./picker.js";
|
|
11
|
+
import { playSplash } from "./splash.js";
|
|
12
|
+
import { runSetup } from "./setup.js";
|
|
13
|
+
import { runAuthConnectCommand } from "./auth-connect.js";
|
|
14
|
+
import { osCommandHelp, runOsCommand } from "./os-command.js";
|
|
15
|
+
import { CLI } from "./identity.js";
|
|
16
|
+
import { cliHelp, hostHelp } from "./help.js";
|
|
17
|
+
import { requireHubKind } from "./hub-kind.js";
|
|
18
|
+
function printHelp() {
|
|
19
|
+
console.error(cliHelp());
|
|
20
|
+
}
|
|
21
|
+
function printHostHelp() {
|
|
22
|
+
console.error(hostHelp());
|
|
23
|
+
}
|
|
24
|
+
const args = process.argv.slice(2);
|
|
25
|
+
function extractHubUrlArg(argv) {
|
|
26
|
+
const cleaned = [];
|
|
27
|
+
let hubUrlOverride;
|
|
28
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
29
|
+
const arg = argv[i];
|
|
30
|
+
if (arg === "--hub-url") {
|
|
31
|
+
const value = argv[i + 1];
|
|
32
|
+
if (!value || value.startsWith("--")) {
|
|
33
|
+
throw new Error("--hub-url requires a value");
|
|
34
|
+
}
|
|
35
|
+
hubUrlOverride = value.trim();
|
|
36
|
+
i += 1;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (arg.startsWith("--hub-url=")) {
|
|
40
|
+
const value = arg.slice("--hub-url=".length).trim();
|
|
41
|
+
if (!value) {
|
|
42
|
+
throw new Error("--hub-url requires a value");
|
|
43
|
+
}
|
|
44
|
+
hubUrlOverride = value;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
cleaned.push(arg);
|
|
48
|
+
}
|
|
49
|
+
return { args: cleaned, ...(hubUrlOverride ? { hubUrlOverride } : {}) };
|
|
50
|
+
}
|
|
51
|
+
function extractHostServiceScopeArg(argv) {
|
|
52
|
+
const cleaned = [];
|
|
53
|
+
let hostServiceScope;
|
|
54
|
+
for (const arg of argv) {
|
|
55
|
+
if (arg === "--system") {
|
|
56
|
+
hostServiceScope = "system";
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (arg === "--user") {
|
|
60
|
+
hostServiceScope = "user";
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
cleaned.push(arg);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
args: cleaned,
|
|
67
|
+
...(hostServiceScope ? { hostServiceScope } : {}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const parsedWithHubUrl = extractHubUrlArg(args);
|
|
71
|
+
const parsed = extractHostServiceScopeArg(parsedWithHubUrl.args);
|
|
72
|
+
const command = parsed.args[0];
|
|
73
|
+
const main = async () => {
|
|
74
|
+
switch (command) {
|
|
75
|
+
case "auth":
|
|
76
|
+
if (parsed.args[1] !== "connect") {
|
|
77
|
+
throw new Error("Unknown auth command. Supported auth command: connect.");
|
|
78
|
+
}
|
|
79
|
+
await runAuthConnectCommand(parsed.args.slice(2), {
|
|
80
|
+
hubUrlOverride: parsedWithHubUrl.hubUrlOverride,
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
case "os":
|
|
84
|
+
if (parsed.args[1] === "--help" || parsed.args[1] === "-h" || parsed.args[1] === "help") {
|
|
85
|
+
console.error(osCommandHelp());
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
await runOsCommand(parsed.args.slice(1), {
|
|
89
|
+
configDir: TILLER_CONFIG_DIR,
|
|
90
|
+
// Asked whose Hub this is, so a session for another account is refused. The Hub is told nothing.
|
|
91
|
+
...(HUB_URL ? { hub: { url: HUB_URL, headers: () => hubControlHeaders } } : {}),
|
|
92
|
+
// The `overvues` build asks its hub its kind (refusing any but Overvues Dev) and its
|
|
93
|
+
// Overvues address, the default when the command names none. `tiller` asks nothing more.
|
|
94
|
+
...(HUB_URL && CLI.name === "overvues"
|
|
95
|
+
? { hubOsOrigin: async () => (await requireHubKind(HUB_URL, hubControlHeaders))?.osOrigin ?? null }
|
|
96
|
+
: {}),
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
case "init":
|
|
100
|
+
await runInit(parsed.args.slice(1), {
|
|
101
|
+
hubUrlOverride: parsedWithHubUrl.hubUrlOverride,
|
|
102
|
+
});
|
|
103
|
+
return;
|
|
104
|
+
case "doctor":
|
|
105
|
+
if (parsed.args[1] === "dns") {
|
|
106
|
+
await runDnsDoctorCommand(parsed.args.slice(2), {
|
|
107
|
+
hubUrlOverride: parsedWithHubUrl.hubUrlOverride,
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
await runDoctor();
|
|
112
|
+
return;
|
|
113
|
+
case "host":
|
|
114
|
+
if (parsed.args[1] === "--help" ||
|
|
115
|
+
parsed.args[1] === "-h" ||
|
|
116
|
+
parsed.args[1] === "help") {
|
|
117
|
+
printHostHelp();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (parsed.args[1] === "setup") {
|
|
121
|
+
await runHostSetupCommand({
|
|
122
|
+
hubUrlOverride: parsedWithHubUrl.hubUrlOverride,
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (parsed.args[1] === "install-service") {
|
|
127
|
+
await runHostInstallServiceCommand({
|
|
128
|
+
scope: parsed.hostServiceScope,
|
|
129
|
+
});
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (parsed.args[1] === "update") {
|
|
133
|
+
await ensureControlCredential({
|
|
134
|
+
hubUrlOverride: parsedWithHubUrl.hubUrlOverride,
|
|
135
|
+
});
|
|
136
|
+
await runHostUpdateCommand({
|
|
137
|
+
...parseHostUpdateArgs(parsed.args.slice(2)),
|
|
138
|
+
hubUrlOverride: parsedWithHubUrl.hubUrlOverride,
|
|
139
|
+
});
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (parsed.args[1]) {
|
|
143
|
+
throw new Error(`Unknown host command: ${parsed.args[1]}. Supported host commands: setup, install-service, update. If you expected this command to work, update the ${CLI.command} package first.`);
|
|
144
|
+
}
|
|
145
|
+
ensureHostAuth();
|
|
146
|
+
await runHostCommand();
|
|
147
|
+
return;
|
|
148
|
+
case "setup":
|
|
149
|
+
await ensureInteractiveConfig({
|
|
150
|
+
hubUrlOverride: parsedWithHubUrl.hubUrlOverride,
|
|
151
|
+
});
|
|
152
|
+
ensureAuth();
|
|
153
|
+
await runSetup(parsed.args.slice(1));
|
|
154
|
+
return;
|
|
155
|
+
case "status":
|
|
156
|
+
await runHostStatusCommand();
|
|
157
|
+
return;
|
|
158
|
+
case "down":
|
|
159
|
+
await runHostDownCommand();
|
|
160
|
+
return;
|
|
161
|
+
case "help":
|
|
162
|
+
case "--help":
|
|
163
|
+
case "-h":
|
|
164
|
+
printHelp();
|
|
165
|
+
return;
|
|
166
|
+
case "attach":
|
|
167
|
+
default:
|
|
168
|
+
await ensureInteractiveConfig({
|
|
169
|
+
hubUrlOverride: parsedWithHubUrl.hubUrlOverride,
|
|
170
|
+
});
|
|
171
|
+
ensureAuth();
|
|
172
|
+
await requireHubKind(HUB_URL, hubControlHeaders);
|
|
173
|
+
await playSplash(fetchHubSetupStatus().catch(() => null));
|
|
174
|
+
try {
|
|
175
|
+
await runAttach(parsed.args);
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
await shutdownAutoStartedLocalEnvs(HUB_URL, hubControlHeaders);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
main().catch((err) => {
|
|
183
|
+
console.error(`${CLI.logTag} Fatal: ${err}`);
|
|
184
|
+
process.exit(1);
|
|
185
|
+
});
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
2
|
+
import { createInterface } from "node:readline/promises";
|
|
3
|
+
import { runBrowserBootstrap, } from "./browser-bootstrap.js";
|
|
4
|
+
import { fetchHubSetupStatus, isHubSetupStatusAuthError, } from "./codex-subscription.js";
|
|
5
|
+
import { CONFIG_PATH, DEFAULT_LOCAL_RUNNER_IMAGE, HUB_URL, isLocalHubUrl, loadConfig, reloadConfig, writeConfig, } from "./config.js";
|
|
6
|
+
import { hubParentDomainsText, isAllowedHubUrl } from "./hub-address.js";
|
|
7
|
+
import { CLI, envVar } from "./identity.js";
|
|
8
|
+
import { credentialHeaders, requireHubKind } from "./hub-kind.js";
|
|
9
|
+
function parseArgs(argv) {
|
|
10
|
+
const parsed = {};
|
|
11
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
12
|
+
const arg = argv[i];
|
|
13
|
+
if (!arg.startsWith("--"))
|
|
14
|
+
continue;
|
|
15
|
+
const key = arg.slice(2);
|
|
16
|
+
const next = argv[i + 1];
|
|
17
|
+
if (!next || next.startsWith("--")) {
|
|
18
|
+
parsed[key] = "true";
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
parsed[key] = next;
|
|
22
|
+
i += 1;
|
|
23
|
+
}
|
|
24
|
+
return parsed;
|
|
25
|
+
}
|
|
26
|
+
function normalizeUrl(value) {
|
|
27
|
+
return (value ?? "").trim().replace(/\/+$/, "");
|
|
28
|
+
}
|
|
29
|
+
function printUsage() {
|
|
30
|
+
console.error(`Usage: ${CLI.command} init --hub-url https://<exact-host>.workers.dev [options]`);
|
|
31
|
+
console.error(`The Hub URL is an exact https origin under ${hubParentDomainsText()}.`);
|
|
32
|
+
console.error("");
|
|
33
|
+
console.error(`Run \`${CLI.command} init\` with no flags to update the saved hub URL interactively.`);
|
|
34
|
+
console.error("");
|
|
35
|
+
console.error("This machine's hub credential is delivered only through the encrypted connect page, after you compare its code with this terminal.");
|
|
36
|
+
console.error("");
|
|
37
|
+
console.error("Options:");
|
|
38
|
+
console.error(` --host-pull-image <value> Override sandbox image (defaults to ${DEFAULT_LOCAL_RUNNER_IMAGE})`);
|
|
39
|
+
}
|
|
40
|
+
function unsupportedHubUrlMessage() {
|
|
41
|
+
return (`${CLI.command} requires the exact https hub URL under ${hubParentDomainsText()}. Run ` +
|
|
42
|
+
`\`${CLI.command} host setup --hub-url https://<exact-host>.workers.dev\`.`);
|
|
43
|
+
}
|
|
44
|
+
function isSupportedHubUrl(hubUrl) {
|
|
45
|
+
return isAllowedHubUrl(hubUrl) || isLocalHubUrl(hubUrl);
|
|
46
|
+
}
|
|
47
|
+
function buildSavedConfigFromBootstrap(bootstrap, localRunnerImage) {
|
|
48
|
+
if (!isSupportedHubUrl(bootstrap.hubUrl)) {
|
|
49
|
+
throw new Error(unsupportedHubUrlMessage());
|
|
50
|
+
}
|
|
51
|
+
return buildSavedConfig(loadConfig(), {
|
|
52
|
+
hubUrl: bootstrap.hubUrl,
|
|
53
|
+
clientId: bootstrap.protectionMode === "sign-in" ? bootstrap.clientId : undefined,
|
|
54
|
+
clientSecret: bootstrap.protectionMode === "sign-in"
|
|
55
|
+
? bootstrap.clientSecret
|
|
56
|
+
: undefined,
|
|
57
|
+
controlSecret: bootstrap.protectionMode === "sign-in"
|
|
58
|
+
? bootstrap.controlSecret
|
|
59
|
+
: undefined,
|
|
60
|
+
localRunnerImage,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async function connectAndPersistCredentials(hubUrl, localRunnerImage) {
|
|
64
|
+
// A machine connecting again names its id, so the owner approves this credential for it.
|
|
65
|
+
const bootstrap = await runBrowserBootstrap(hubUrl, { machineId: loadConfig().machineId ?? null });
|
|
66
|
+
const saved = buildSavedConfigFromBootstrap(bootstrap, localRunnerImage);
|
|
67
|
+
// Before it is saved: the `overvues` build connects only to an Overvues Dev hub (hub-kind.ts).
|
|
68
|
+
// The new credential is sent only to the hub that issued it.
|
|
69
|
+
await requireHubKind(saved.hubUrl, credentialHeaders(saved));
|
|
70
|
+
writeConfig(saved);
|
|
71
|
+
reloadConfig();
|
|
72
|
+
return bootstrap;
|
|
73
|
+
}
|
|
74
|
+
async function refreshProtectedHubAccessCredentials(hubUrl, quiet = false) {
|
|
75
|
+
if (!quiet) {
|
|
76
|
+
process.stderr.write(`${CLI.logTag} This machine's saved hub credential no longer works. Reconnecting through the browser...\n`);
|
|
77
|
+
}
|
|
78
|
+
await ensureControlCredential({ hubUrlOverride: hubUrl, force: true, quiet });
|
|
79
|
+
if (!quiet) {
|
|
80
|
+
process.stderr.write(`${CLI.logTag} Refreshed ${CONFIG_PATH}\n`);
|
|
81
|
+
process.stderr.write(`${CLI.logTag} Refreshed this machine's hub credential.\n`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function verifySavedHubAccess(hubUrl, quiet = false) {
|
|
85
|
+
if (!hubUrl)
|
|
86
|
+
return;
|
|
87
|
+
try {
|
|
88
|
+
await fetchHubSetupStatus(hubUrl);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (isHubSetupStatusAuthError(error) && input.isTTY && output.isTTY) {
|
|
93
|
+
try {
|
|
94
|
+
await refreshProtectedHubAccessCredentials(hubUrl, quiet);
|
|
95
|
+
await fetchHubSetupStatus(hubUrl);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
catch (refreshError) {
|
|
99
|
+
error = refreshError;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!quiet) {
|
|
103
|
+
process.stderr.write(`${CLI.logTag} Could not verify saved hub access: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function buildConfig(options) {
|
|
108
|
+
const config = {
|
|
109
|
+
hubUrl: normalizeUrl(options.hubUrl),
|
|
110
|
+
localRunnerImage: options.localRunnerImage || DEFAULT_LOCAL_RUNNER_IMAGE,
|
|
111
|
+
};
|
|
112
|
+
if (options.clientId) {
|
|
113
|
+
config.clientId = options.clientId;
|
|
114
|
+
}
|
|
115
|
+
if (options.clientSecret) {
|
|
116
|
+
config.clientSecret = options.clientSecret;
|
|
117
|
+
}
|
|
118
|
+
if (options.controlSecret)
|
|
119
|
+
config.controlSecret = options.controlSecret;
|
|
120
|
+
return config;
|
|
121
|
+
}
|
|
122
|
+
export function buildSavedConfig(existing, options) {
|
|
123
|
+
const base = buildConfig({
|
|
124
|
+
hubUrl: options.hubUrl,
|
|
125
|
+
clientId: options.clientId,
|
|
126
|
+
clientSecret: options.clientSecret,
|
|
127
|
+
controlSecret: options.controlSecret,
|
|
128
|
+
localRunnerImage: options.localRunnerImage ?? existing.localRunnerImage,
|
|
129
|
+
});
|
|
130
|
+
const next = {
|
|
131
|
+
...existing,
|
|
132
|
+
...base,
|
|
133
|
+
};
|
|
134
|
+
delete next.publicHub;
|
|
135
|
+
if (options.clientId)
|
|
136
|
+
next.clientId = options.clientId;
|
|
137
|
+
else
|
|
138
|
+
delete next.clientId;
|
|
139
|
+
if (options.clientSecret)
|
|
140
|
+
next.clientSecret = options.clientSecret;
|
|
141
|
+
else
|
|
142
|
+
delete next.clientSecret;
|
|
143
|
+
if (options.controlSecret)
|
|
144
|
+
next.controlSecret = options.controlSecret;
|
|
145
|
+
else
|
|
146
|
+
delete next.controlSecret;
|
|
147
|
+
return next;
|
|
148
|
+
}
|
|
149
|
+
export async function ensureInteractiveConfig(options = {}) {
|
|
150
|
+
const overrideHubUrl = normalizeUrl(options.hubUrlOverride || "");
|
|
151
|
+
if (!options.forceHubPrompt && !overrideHubUrl && HUB_URL) {
|
|
152
|
+
await ensureControlCredential();
|
|
153
|
+
await verifySavedHubAccess(HUB_URL, true);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const existing = loadConfig();
|
|
157
|
+
let normalizedHubUrl = overrideHubUrl || HUB_URL;
|
|
158
|
+
let rl = null;
|
|
159
|
+
try {
|
|
160
|
+
if (!normalizedHubUrl || options.forceHubPrompt) {
|
|
161
|
+
if (!input.isTTY || !output.isTTY) {
|
|
162
|
+
console.error(`${CLI.logTag} ${CONFIG_PATH} is missing or incomplete. Run \`${CLI.command}\` interactively or use \`${CLI.command} init --help\`.`);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
const currentHubUrl = normalizeUrl(existing.hubUrl || normalizedHubUrl);
|
|
166
|
+
process.stderr.write(options.forceHubPrompt
|
|
167
|
+
? `${CLI.logTag} Update the hub URL used by ${CLI.command}.\n`
|
|
168
|
+
: `${CLI.logTag} No config found at ${CONFIG_PATH}. Let's connect ${CLI.command} to your hub.\n`);
|
|
169
|
+
rl = createInterface({ input, output });
|
|
170
|
+
const prompt = rl;
|
|
171
|
+
const ask = async (question) => {
|
|
172
|
+
const answer = await prompt.question(question);
|
|
173
|
+
return (answer ?? "").trim();
|
|
174
|
+
};
|
|
175
|
+
const hubUrl = await ask(currentHubUrl ? `Hub URL [${currentHubUrl}]: ` : "Hub URL: ");
|
|
176
|
+
const selectedHubUrl = normalizeUrl(hubUrl || currentHubUrl);
|
|
177
|
+
if (!selectedHubUrl) {
|
|
178
|
+
console.error(`${CLI.logTag} Hub URL is required.`);
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
normalizedHubUrl = selectedHubUrl;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
process.stderr.write(`${CLI.logTag} Connecting ${CLI.command} to ${normalizedHubUrl}\n`);
|
|
185
|
+
}
|
|
186
|
+
if (!normalizedHubUrl) {
|
|
187
|
+
console.error(`${CLI.logTag} Hub URL is required.`);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
if (!isSupportedHubUrl(normalizedHubUrl)) {
|
|
191
|
+
throw new Error(unsupportedHubUrlMessage());
|
|
192
|
+
}
|
|
193
|
+
if (isAllowedHubUrl(normalizedHubUrl)) {
|
|
194
|
+
await ensureControlCredential({
|
|
195
|
+
hubUrlOverride: normalizedHubUrl,
|
|
196
|
+
localRunnerImageOverride: options.localRunnerImageOverride,
|
|
197
|
+
});
|
|
198
|
+
await verifySavedHubAccess(normalizedHubUrl, true);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const bootstrap = await connectAndPersistCredentials(normalizedHubUrl, options.localRunnerImageOverride);
|
|
202
|
+
process.stderr.write(`${CLI.logTag} Wrote ${CONFIG_PATH}\n`);
|
|
203
|
+
process.stderr.write(bootstrap.protectionMode === "sign-in"
|
|
204
|
+
? `${CLI.logTag} Saved this machine's hub credential.\n`
|
|
205
|
+
: `${CLI.logTag} Saved localhost development configuration.\n`);
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
rl?.close();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
export async function ensureControlCredential(options = {}) {
|
|
212
|
+
const existing = loadConfig();
|
|
213
|
+
const hubUrl = normalizeUrl(options.hubUrlOverride || HUB_URL || existing.hubUrl);
|
|
214
|
+
if (isLocalHubUrl(hubUrl))
|
|
215
|
+
return;
|
|
216
|
+
const savedHubUrl = normalizeUrl(existing.hubUrl);
|
|
217
|
+
if (!options.force &&
|
|
218
|
+
isAllowedHubUrl(hubUrl) &&
|
|
219
|
+
savedHubUrl === hubUrl &&
|
|
220
|
+
existing.clientId?.trim() &&
|
|
221
|
+
existing.clientSecret?.trim() &&
|
|
222
|
+
existing.controlSecret?.trim()) {
|
|
223
|
+
if (options.localRunnerImageOverride &&
|
|
224
|
+
options.localRunnerImageOverride !== existing.localRunnerImage) {
|
|
225
|
+
writeConfig({
|
|
226
|
+
...existing,
|
|
227
|
+
localRunnerImage: options.localRunnerImageOverride,
|
|
228
|
+
});
|
|
229
|
+
reloadConfig();
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const instruction = `Run \`${CLI.command} init --hub-url ${hubUrl || "https://<exact-host>.workers.dev"}\` interactively to approve this installation.`;
|
|
234
|
+
if (!input.isTTY || !output.isTTY) {
|
|
235
|
+
throw new Error(`The hub's control credential is missing. ${instruction}`);
|
|
236
|
+
}
|
|
237
|
+
if (!isAllowedHubUrl(hubUrl))
|
|
238
|
+
throw new Error(unsupportedHubUrlMessage());
|
|
239
|
+
if (!options.quiet) {
|
|
240
|
+
process.stderr.write(`${CLI.logTag} This CLI needs one browser-owner approval for installation control.\n`);
|
|
241
|
+
}
|
|
242
|
+
await connectAndPersistCredentials(hubUrl, options.localRunnerImageOverride ?? existing.localRunnerImage);
|
|
243
|
+
if (!options.quiet) {
|
|
244
|
+
process.stderr.write(`${CLI.logTag} Saved the control credential in ${CONFIG_PATH}.\n`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
export async function runInit(argv, options = {}) {
|
|
248
|
+
const args = parseArgs(argv);
|
|
249
|
+
if (args.help === "true" || args.h === "true") {
|
|
250
|
+
printUsage();
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (argv.length === 0 &&
|
|
254
|
+
!options.hubUrlOverride &&
|
|
255
|
+
input.isTTY &&
|
|
256
|
+
output.isTTY) {
|
|
257
|
+
await ensureInteractiveConfig({ forceHubPrompt: true });
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const existing = loadConfig();
|
|
261
|
+
const hubUrl = options.hubUrlOverride ||
|
|
262
|
+
args["hub-url"] ||
|
|
263
|
+
process.env[CLI.hubUrlEnv] ||
|
|
264
|
+
existing.hubUrl;
|
|
265
|
+
const retiredOptions = ["public-hub", "client-id", "client-secret"].filter((key) => args[key] !== undefined);
|
|
266
|
+
if (retiredOptions.length > 0 || process.env[envVar("PUBLIC_HUB")]) {
|
|
267
|
+
console.error(`${CLI.logTag} Public/custom-domain connection options were removed. ` +
|
|
268
|
+
`Use the exact Hub URL under ${hubParentDomainsText()} and complete the encrypted browser connection.`);
|
|
269
|
+
process.exitCode = 1;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (!hubUrl) {
|
|
273
|
+
console.error(`${CLI.logTag} init requires hubUrl.`);
|
|
274
|
+
printUsage();
|
|
275
|
+
process.exitCode = 1;
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const normalizedHubUrl = normalizeUrl(hubUrl);
|
|
279
|
+
if (!isSupportedHubUrl(normalizedHubUrl)) {
|
|
280
|
+
console.error(`${CLI.logTag} ${unsupportedHubUrlMessage()}`);
|
|
281
|
+
process.exitCode = 1;
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
await ensureInteractiveConfig({
|
|
285
|
+
hubUrlOverride: normalizedHubUrl,
|
|
286
|
+
localRunnerImageOverride: args["host-pull-image"] ||
|
|
287
|
+
process.env[envVar("LOCAL_RUNNER_IMAGE")] ||
|
|
288
|
+
existing.localRunnerImage ||
|
|
289
|
+
DEFAULT_LOCAL_RUNNER_IMAGE,
|
|
290
|
+
});
|
|
291
|
+
process.stderr.write(`${CLI.logTag} Next steps:\n`);
|
|
292
|
+
process.stderr.write(`1. Run \`${CLI.command}\`\n`);
|
|
293
|
+
process.stderr.write(`2. Run \`${CLI.command} host setup\` when you want to use Your machine\n`);
|
|
294
|
+
process.stderr.write(`3. Run \`${CLI.command} doctor\` if you need troubleshooting\n`);
|
|
295
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small caches that keep Docker CLI calls off the create path of isolated
|
|
3
|
+
* runs (Scribe plan writers, reviewers). Each Docker CLI call costs about
|
|
4
|
+
* 60–200 ms on a Mac, and these answers rarely change.
|
|
5
|
+
*/
|
|
6
|
+
/** How long "this mirror volume does not exist" is believed. */
|
|
7
|
+
export const MIRROR_NEGATIVE_TTL_MS = 30_000;
|
|
8
|
+
/** How long Docker's reported security options are believed. */
|
|
9
|
+
export const DOCKER_INFO_TTL_MS = 60_000;
|
|
10
|
+
/**
|
|
11
|
+
* One value loaded at most once per `ttlMs`; concurrent callers share the
|
|
12
|
+
* in-flight load. A failed load is not cached, so the next call retries.
|
|
13
|
+
*/
|
|
14
|
+
export class TtlSingleFlight {
|
|
15
|
+
load;
|
|
16
|
+
ttlMs;
|
|
17
|
+
now;
|
|
18
|
+
value = null;
|
|
19
|
+
constructor(load, ttlMs, now = Date.now) {
|
|
20
|
+
this.load = load;
|
|
21
|
+
this.ttlMs = ttlMs;
|
|
22
|
+
this.now = now;
|
|
23
|
+
}
|
|
24
|
+
get() {
|
|
25
|
+
const current = this.value;
|
|
26
|
+
if (current && (current.loadedAt === null || this.now() - current.loadedAt < this.ttlMs))
|
|
27
|
+
return current.promise;
|
|
28
|
+
const promise = this.load().then((value) => {
|
|
29
|
+
if (this.value?.promise === promise)
|
|
30
|
+
this.value.loadedAt = this.now();
|
|
31
|
+
return value;
|
|
32
|
+
}, (error) => {
|
|
33
|
+
if (this.value?.promise === promise)
|
|
34
|
+
this.value = null;
|
|
35
|
+
throw error;
|
|
36
|
+
});
|
|
37
|
+
this.value = { promise, loadedAt: null };
|
|
38
|
+
return promise;
|
|
39
|
+
}
|
|
40
|
+
clear() {
|
|
41
|
+
this.value = null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether a Git mirror volume exists, for the read-only mount of isolated
|
|
46
|
+
* runs. A yes comes from the runner inventory or an earlier inspect and is
|
|
47
|
+
* kept until the runner removes the volume (`forget`); a no is kept for
|
|
48
|
+
* `negativeTtlMs`, so a mirror created later is mounted soon.
|
|
49
|
+
*
|
|
50
|
+
* A stale yes is harmless. The mount is `-v <volume>:<path>:ro`, so Docker
|
|
51
|
+
* creates a missing named volume instead of failing the create; the run sees
|
|
52
|
+
* an empty, read-only mirror, the harness only uses a mirror that has `HEAD`
|
|
53
|
+
* and validates the checkout by commit SHA, so it falls back to GitHub. The
|
|
54
|
+
* mount is read-only either way and names the same runner-owned volume, so
|
|
55
|
+
* nothing about the run's isolation changes. The empty volume is then an
|
|
56
|
+
* ordinary mirror the next environment fills (its bootstrap prepares the
|
|
57
|
+
* mirror's ownership) or the inventory cleanup collects.
|
|
58
|
+
*/
|
|
59
|
+
export class VolumePresenceCache {
|
|
60
|
+
options;
|
|
61
|
+
present = new Set();
|
|
62
|
+
absentAt = new Map();
|
|
63
|
+
inFlight = new Map();
|
|
64
|
+
negativeTtlMs;
|
|
65
|
+
now;
|
|
66
|
+
constructor(options) {
|
|
67
|
+
this.options = options;
|
|
68
|
+
this.negativeTtlMs = options.negativeTtlMs ?? MIRROR_NEGATIVE_TTL_MS;
|
|
69
|
+
this.now = options.now ?? Date.now;
|
|
70
|
+
}
|
|
71
|
+
async exists(volume) {
|
|
72
|
+
if (this.present.has(volume))
|
|
73
|
+
return true;
|
|
74
|
+
let known = false;
|
|
75
|
+
try {
|
|
76
|
+
known = this.options.known?.(volume) ?? false;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// An unreadable inventory only costs the inspect.
|
|
80
|
+
}
|
|
81
|
+
if (known) {
|
|
82
|
+
this.remember(volume);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
const absentAt = this.absentAt.get(volume);
|
|
86
|
+
if (absentAt !== undefined && this.now() - absentAt < this.negativeTtlMs)
|
|
87
|
+
return false;
|
|
88
|
+
const pending = this.inFlight.get(volume);
|
|
89
|
+
if (pending)
|
|
90
|
+
return pending;
|
|
91
|
+
const inspection = this.options.inspect(volume).then((exists) => {
|
|
92
|
+
if (this.inFlight.get(volume) === inspection) {
|
|
93
|
+
this.inFlight.delete(volume);
|
|
94
|
+
if (exists)
|
|
95
|
+
this.remember(volume);
|
|
96
|
+
else
|
|
97
|
+
this.absentAt.set(volume, this.now());
|
|
98
|
+
}
|
|
99
|
+
return exists;
|
|
100
|
+
});
|
|
101
|
+
this.inFlight.set(volume, inspection);
|
|
102
|
+
return inspection;
|
|
103
|
+
}
|
|
104
|
+
/** The runner removed these volumes (or found them gone). */
|
|
105
|
+
forget(volumes) {
|
|
106
|
+
for (const volume of volumes) {
|
|
107
|
+
this.present.delete(volume);
|
|
108
|
+
this.absentAt.delete(volume);
|
|
109
|
+
this.inFlight.delete(volume);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
remember(volume) {
|
|
113
|
+
this.present.add(volume);
|
|
114
|
+
this.absentAt.delete(volume);
|
|
115
|
+
}
|
|
116
|
+
}
|