gencow 0.1.293 → 0.1.295
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 +7 -0
- package/bin/gencow.mjs +1 -0
- package/core/index.js +124 -32
- package/lib/app-command.mjs +3 -0
- package/lib/app-inactive-stop-format.mjs +17 -0
- package/lib/cli-command-runner.mjs +8 -1
- package/lib/codegen-command.mjs +3 -2
- package/lib/confirm-gate.mjs +2 -1
- package/lib/deploy-codegen-preflight.mjs +1 -0
- package/lib/deploy-declaration-diagnostic.mjs +15 -0
- package/lib/deploy-declaration-preflight.mjs +26 -0
- package/lib/deploy-failure-diagnostic.mjs +10 -10
- package/lib/deploy-failure-next-action.mjs +16 -0
- package/lib/deploy-package-runtime.mjs +6 -31
- package/lib/domain-command.mjs +76 -10
- package/lib/domain-set-failure.mjs +45 -0
- package/lib/domain-txt-records.mjs +57 -0
- package/lib/domain-zone-token.mjs +280 -0
- package/lib/jobs-command.mjs +10 -0
- package/lib/opencode-config.mjs +41 -7
- package/lib/procedure-rpc-diagnostic.mjs +6 -0
- package/package.json +2 -2
- package/runtime/server.mjs +248 -224
- package/runtime/tooling.mjs +113 -8
- package/scripts/tooling-codegen-runtime.ts +17 -3
package/lib/domain-command.mjs
CHANGED
|
@@ -2,6 +2,9 @@ import { resolveCloudAppTarget } from "./cloud-targets.mjs";
|
|
|
2
2
|
import { cloudTargetRejectionMessage, prodRetryCommandLine } from "./deploy-app-target.mjs";
|
|
3
3
|
import { BOLD, CYAN, DIM, GREEN, RESET, error, info, log, success, warn } from "./output.mjs";
|
|
4
4
|
import { platformFetch, requireCreds } from "./platform-client.mjs";
|
|
5
|
+
import { domainSetFailureReport } from "./domain-set-failure.mjs";
|
|
6
|
+
import { awaitingStatusLines, txtRecordLines } from "./domain-txt-records.mjs";
|
|
7
|
+
import { runDomainZoneToken, zoneTokenHelpLines } from "./domain-zone-token.mjs";
|
|
5
8
|
|
|
6
9
|
export function resolveDomainAppId(restArgs, gencowJson = null) {
|
|
7
10
|
let appId = null;
|
|
@@ -78,22 +81,51 @@ function printCustomDomainUpgrade(data, { errorImpl, infoImpl }) {
|
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
84
|
+
// A non-JSON body (for example a gateway HTML page) must not throw out of the command. Returns null when unreadable.
|
|
85
|
+
async function readDomainResponseBody(response) {
|
|
86
|
+
try {
|
|
87
|
+
const value = await response.json();
|
|
88
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function reportUnreadableDomainResponse(response, { errorImpl, infoImpl }) {
|
|
95
|
+
const status = Number.isInteger(response?.status) ? ` (HTTP ${response.status})` : "";
|
|
96
|
+
errorImpl(`Domain registration failed: the Platform returned an unreadable response${status}.`);
|
|
97
|
+
infoImpl("Code: CLI_DOMAIN_RESPONSE_UNREADABLE");
|
|
98
|
+
infoImpl("State impact: unknown; the domain may or may not have changed.");
|
|
99
|
+
infoImpl(`Next action: run ${DIM}gencow domain status --prod${RESET} before retrying.`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function printDomainSetFailure(report, { errorImpl, infoImpl }) {
|
|
103
|
+
errorImpl(report.headline);
|
|
104
|
+
for (const line of report.details) infoImpl(line);
|
|
105
|
+
}
|
|
106
|
+
|
|
81
107
|
function renderDomainHelp(logImpl = log) {
|
|
82
108
|
logImpl(`\n${BOLD}${CYAN}gencow domain${RESET} — Custom domain management\n`);
|
|
83
109
|
logImpl(` ${BOLD}Usage:${RESET} gencow domain <command> [options]\n`);
|
|
84
110
|
logImpl(` ${BOLD}Commands:${RESET}`);
|
|
85
111
|
logImpl(` ${CYAN}set${RESET} <domain> Connect custom domain (e.g. myapp.com)`);
|
|
86
112
|
logImpl(` ${CYAN}status${RESET} Check ownership/TLS status`);
|
|
87
|
-
logImpl(` ${CYAN}remove${RESET} Disconnect custom domain
|
|
113
|
+
logImpl(` ${CYAN}remove${RESET} Disconnect custom domain`);
|
|
114
|
+
for (const line of zoneTokenHelpLines()) logImpl(line);
|
|
115
|
+
logImpl("");
|
|
88
116
|
logImpl(` ${BOLD}Options:${RESET}`);
|
|
89
117
|
logImpl(` ${DIM}--prod${RESET} Target production app`);
|
|
90
118
|
logImpl(` ${DIM}--app, -a${RESET} Target specific app`);
|
|
91
119
|
logImpl(` ${DIM}--dry-run${RESET} Preview set/rebind without writing`);
|
|
92
|
-
logImpl(` ${DIM}--
|
|
120
|
+
logImpl(` ${DIM}--check${RESET} status: verify a waiting DNS TXT record now (read-only otherwise)`);
|
|
121
|
+
logImpl(` ${DIM}--yes, -y${RESET} Confirm related app rebind, or a zone TXT rotation, in non-TTY scripts\n`);
|
|
93
122
|
logImpl(` ${BOLD}Examples:${RESET}`);
|
|
94
123
|
logImpl(` gencow domain set myapp.com --prod`);
|
|
95
124
|
logImpl(` gencow domain set myapp.com --prod --dry-run`);
|
|
96
|
-
logImpl(` gencow domain status --prod
|
|
125
|
+
logImpl(` gencow domain status --prod`);
|
|
126
|
+
logImpl(` gencow domain status --prod --check`);
|
|
127
|
+
logImpl(` gencow domain zone-token example.com`);
|
|
128
|
+
logImpl(` gencow domain zone-token example.com --rotate --yes\n`);
|
|
97
129
|
}
|
|
98
130
|
|
|
99
131
|
export function createDomainCommand({
|
|
@@ -121,6 +153,19 @@ export function createDomainCommand({
|
|
|
121
153
|
return;
|
|
122
154
|
}
|
|
123
155
|
|
|
156
|
+
// The zone token is account-level, so it runs before any app target is resolved.
|
|
157
|
+
if (subCmd === "zone-token") {
|
|
158
|
+
return runDomainZoneToken(restArgs, {
|
|
159
|
+
creds: requireCredsImpl(),
|
|
160
|
+
platformFetchImpl,
|
|
161
|
+
errorImpl,
|
|
162
|
+
infoImpl,
|
|
163
|
+
logImpl,
|
|
164
|
+
successImpl,
|
|
165
|
+
warnImpl,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
124
169
|
const creds = requireCredsImpl();
|
|
125
170
|
|
|
126
171
|
const target = resolveCloudAppTargetImpl(restArgs, {
|
|
@@ -161,7 +206,8 @@ export function createDomainCommand({
|
|
|
161
206
|
headers: { "Content-Type": "application/json" },
|
|
162
207
|
body: JSON.stringify(requestBody),
|
|
163
208
|
});
|
|
164
|
-
let data = await response
|
|
209
|
+
let data = await readDomainResponseBody(response);
|
|
210
|
+
if (data === null) return reportUnreadableDomainResponse(response, { errorImpl, infoImpl });
|
|
165
211
|
|
|
166
212
|
if (!response.ok && data.code === "DOMAIN_BOUND_TO_RELATED_APP" && data.sourceAppName) {
|
|
167
213
|
if (!flags.yes) {
|
|
@@ -181,15 +227,17 @@ export function createDomainCommand({
|
|
|
181
227
|
rebindFromAppName: data.sourceAppName,
|
|
182
228
|
}),
|
|
183
229
|
});
|
|
184
|
-
data = await response
|
|
230
|
+
data = await readDomainResponseBody(response);
|
|
231
|
+
if (data === null) return reportUnreadableDomainResponse(response, { errorImpl, infoImpl });
|
|
185
232
|
}
|
|
186
233
|
|
|
187
|
-
|
|
234
|
+
// A refused answer is never success: a non-2xx status, or a 2xx body with success:false (defensive).
|
|
235
|
+
if (!response.ok || data.success === false) {
|
|
188
236
|
if (isCustomDomainPlanLimit(data)) {
|
|
189
237
|
printCustomDomainUpgrade(data, { errorImpl, infoImpl });
|
|
190
238
|
return;
|
|
191
239
|
}
|
|
192
|
-
|
|
240
|
+
printDomainSetFailure(domainSetFailureReport(data, { dryRun: flags.dryRun === true }), { errorImpl, infoImpl });
|
|
193
241
|
return;
|
|
194
242
|
}
|
|
195
243
|
|
|
@@ -198,6 +246,10 @@ export function createDomainCommand({
|
|
|
198
246
|
printCustomDomainUpgrade(data, { errorImpl, infoImpl });
|
|
199
247
|
return;
|
|
200
248
|
}
|
|
249
|
+
if (data.allowed === false) {
|
|
250
|
+
printDomainSetFailure(domainSetFailureReport(data, { dryRun: true }), { errorImpl, infoImpl });
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
201
253
|
logImpl(
|
|
202
254
|
`\n${BOLD}${CYAN}Custom Domain Dry Run${RESET} — ${formatDomainEnv(envTarget)}: ${appId}\n`,
|
|
203
255
|
);
|
|
@@ -282,10 +334,20 @@ export function createDomainCommand({
|
|
|
282
334
|
|
|
283
335
|
case "status":
|
|
284
336
|
default: {
|
|
285
|
-
|
|
286
|
-
const
|
|
337
|
+
// Status is read-only by default. --check asks the Platform to verify a waiting TXT record now.
|
|
338
|
+
const check = restArgs.includes("--check") ? "&check=1" : "";
|
|
339
|
+
const response = await platformFetchImpl(creds, `/platform/domain/status?appName=${appId}${check}`);
|
|
340
|
+
const data = await readDomainResponseBody(response);
|
|
341
|
+
if (data === null) {
|
|
342
|
+
errorImpl("Domain status check failed: the Platform returned an unreadable response.");
|
|
343
|
+
infoImpl("Code: CLI_DOMAIN_RESPONSE_UNREADABLE");
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
287
346
|
if (!response.ok) {
|
|
288
|
-
|
|
347
|
+
printDomainSetFailure(domainSetFailureReport(data, { prefix: "Domain status check failed" }), {
|
|
348
|
+
errorImpl,
|
|
349
|
+
infoImpl,
|
|
350
|
+
});
|
|
289
351
|
return;
|
|
290
352
|
}
|
|
291
353
|
|
|
@@ -314,6 +376,10 @@ export function createDomainCommand({
|
|
|
314
376
|
} else if (data.status === "pending_http") {
|
|
315
377
|
warnImpl(`Ownership: ⏳ HTTP verification pending`);
|
|
316
378
|
infoImpl(`TLS: Auto-provisioned after ownership verification`);
|
|
379
|
+
} else if (data.status === "awaiting_dns_txt") {
|
|
380
|
+
warnImpl(`DNS: ⏳ Add one TXT record to prove control of this domain`);
|
|
381
|
+
for (const line of txtRecordLines(data.verification)) infoImpl(line);
|
|
382
|
+
for (const line of awaitingStatusLines(data)) infoImpl(line);
|
|
317
383
|
} else {
|
|
318
384
|
errorImpl(`Status: ${data.status}`);
|
|
319
385
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Renders a refused Platform response (a `domain set` failure, a dry run with allowed:false, or a zone-token failure) as a
|
|
2
|
+
// headline plus detail lines. Only validated, public fields are shown; a missing field is omitted, never printed as "undefined".
|
|
3
|
+
import { txtRecordLines } from "./domain-txt-records.mjs";
|
|
4
|
+
|
|
5
|
+
const CODE_PATTERN = /^[A-Za-z][A-Za-z0-9_]{2,127}$/u;
|
|
6
|
+
// Public stage names use lowercase words joined by hyphens or underscores (for example dns_proof, domain-route-baseline).
|
|
7
|
+
const STAGE_PATTERN = /^[a-z][a-z0-9_-]{2,63}$/u;
|
|
8
|
+
const CORRELATION_PATTERN = /^[A-Za-z0-9_-]{8,128}$/u;
|
|
9
|
+
const MAX_TEXT_LENGTH = 400;
|
|
10
|
+
|
|
11
|
+
function safeText(value) {
|
|
12
|
+
if (typeof value !== "string") return null;
|
|
13
|
+
const text = value.trim();
|
|
14
|
+
return text ? text.slice(0, MAX_TEXT_LENGTH) : null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function domainSetFailureReport(data, { dryRun = false, prefix: customPrefix } = {}) {
|
|
18
|
+
const body = data && typeof data === "object" ? data : {};
|
|
19
|
+
const reason = safeText(body.error) ?? safeText(body.message);
|
|
20
|
+
const code = typeof body.code === "string" && CODE_PATTERN.test(body.code) ? body.code : null;
|
|
21
|
+
const prefix = customPrefix ?? (dryRun ? "Domain dry run blocked" : "Domain registration failed");
|
|
22
|
+
const headline = reason
|
|
23
|
+
? `${prefix}: ${reason}`
|
|
24
|
+
: `${prefix}${code ? ` (${code})` : ""}`;
|
|
25
|
+
|
|
26
|
+
const details = [];
|
|
27
|
+
const message = safeText(body.message);
|
|
28
|
+
if (message && message !== reason) details.push(message);
|
|
29
|
+
if (code) details.push(`Code: ${code}`);
|
|
30
|
+
if (typeof body.stage === "string" && STAGE_PATTERN.test(body.stage)) details.push(`Stage: ${body.stage}`);
|
|
31
|
+
const stateImpact = safeText(body.stateImpact);
|
|
32
|
+
if (stateImpact) {
|
|
33
|
+
details.push(`State impact: ${stateImpact}`);
|
|
34
|
+
} else if (typeof body.stateChanged === "boolean") {
|
|
35
|
+
details.push(`Changed: ${body.stateChanged ? "yes" : "nothing"}`);
|
|
36
|
+
}
|
|
37
|
+
if (typeof body.retryable === "boolean") details.push(`Retryable: ${body.retryable ? "yes" : "no"}`);
|
|
38
|
+
details.push(...txtRecordLines(body.verification));
|
|
39
|
+
const nextAction = safeText(body.nextAction) ?? safeText(body.action);
|
|
40
|
+
if (nextAction) details.push(`Next action: ${nextAction}`);
|
|
41
|
+
if (typeof body.correlationId === "string" && CORRELATION_PATTERN.test(body.correlationId)) {
|
|
42
|
+
details.push(`Correlation ID: ${body.correlationId}`);
|
|
43
|
+
}
|
|
44
|
+
return { headline, details };
|
|
45
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Lines that tell the user which DNS TXT records to add, from a platform `verification` block (#3525). Only the public
|
|
2
|
+
// fields are read: type, name, value and expiry. A missing value prints a next step instead of "undefined".
|
|
3
|
+
|
|
4
|
+
const MAX_TEXT_LENGTH = 400;
|
|
5
|
+
const NAME_PATTERN = /^[A-Za-z0-9._-]{1,253}$/u;
|
|
6
|
+
|
|
7
|
+
function text(value) {
|
|
8
|
+
if (typeof value !== "string") return null;
|
|
9
|
+
const trimmed = value.trim();
|
|
10
|
+
return trimmed ? trimmed.slice(0, MAX_TEXT_LENGTH) : null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const RECORD_LABELS = {
|
|
14
|
+
host: "Host record (this domain only)",
|
|
15
|
+
zone: "Zone record (covers every subdomain of the zone)",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Returns printable lines for the host and zone TXT records. Empty when the body carries no records. */
|
|
19
|
+
export function txtRecordLines(verification) {
|
|
20
|
+
const options = verification && typeof verification === "object" ? verification.options : null;
|
|
21
|
+
if (!options || typeof options !== "object") return [];
|
|
22
|
+
const lines = [];
|
|
23
|
+
for (const key of ["host", "zone"]) {
|
|
24
|
+
const record = options[key];
|
|
25
|
+
if (!record || typeof record !== "object") continue;
|
|
26
|
+
const name = text(record.name);
|
|
27
|
+
if (!name || !NAME_PATTERN.test(name)) continue;
|
|
28
|
+
const type = text(record.type) ?? "TXT";
|
|
29
|
+
const value = text(record.value);
|
|
30
|
+
const expiresAt = text(record.expiresAt);
|
|
31
|
+
lines.push(`${RECORD_LABELS[key]}:`);
|
|
32
|
+
lines.push(` Type: ${type}`);
|
|
33
|
+
lines.push(` Name: ${name}`);
|
|
34
|
+
lines.push(` Value: ${value ?? "not shown in a dry run; run `gencow domain set` to get the value"}`);
|
|
35
|
+
lines.push(` Expires: ${expiresAt ?? "none"}`);
|
|
36
|
+
}
|
|
37
|
+
return lines;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Stage, state, retry and next-action lines for an awaiting status body. The status body keeps retry, the next action and
|
|
42
|
+
* the check result under `verification` (not at the top level), so both places are read. Missing fields are omitted.
|
|
43
|
+
*/
|
|
44
|
+
export function awaitingStatusLines(data) {
|
|
45
|
+
const body = data && typeof data === "object" ? data : {};
|
|
46
|
+
const verification = body.verification && typeof body.verification === "object" ? body.verification : {};
|
|
47
|
+
const lines = ["Stage: dns_proof", "State impact: inactive awaiting record; serving and data unchanged."];
|
|
48
|
+
if (typeof verification.retryable === "boolean") lines.push(`Retryable: ${verification.retryable ? "yes" : "no"}`);
|
|
49
|
+
if (verification.checked === true) {
|
|
50
|
+
lines.push("Last check: the TXT record was not accepted yet. Wait for DNS to update, then check again.");
|
|
51
|
+
} else if (typeof verification.retryAfterSeconds === "number") {
|
|
52
|
+
lines.push(`Last check: skipped, checked recently. Check again in ${verification.retryAfterSeconds} seconds.`);
|
|
53
|
+
}
|
|
54
|
+
const nextAction = text(body.nextAction) ?? text(verification.nextAction);
|
|
55
|
+
if (nextAction) lines.push(`Next action: ${nextAction}`);
|
|
56
|
+
return lines;
|
|
57
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// `gencow domain zone-token <zone> [--rotate] [--yes] [--json]` (#3525 slice D). The account-level zone TXT record lets
|
|
2
|
+
// one record cover every subdomain of a zone. Rotation replaces that value: the old value stops working at once, waiting
|
|
3
|
+
// registrations proven with it are closed, and the server allows rotation only from an interactive session.
|
|
4
|
+
import { createInterface } from "node:readline";
|
|
5
|
+
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
askConfirmation,
|
|
10
|
+
buildConfirmationRequiredDiagnostic,
|
|
11
|
+
CONFIRMATION_MODE,
|
|
12
|
+
renderConfirmationRequired,
|
|
13
|
+
resolveConfirmationMode,
|
|
14
|
+
} from "./confirm-gate.mjs";
|
|
15
|
+
import { domainSetFailureReport } from "./domain-set-failure.mjs";
|
|
16
|
+
import { BOLD, CYAN, DIM, RESET, error, info, log, success, warn } from "./output.mjs";
|
|
17
|
+
import { platformFetch } from "./platform-client.mjs";
|
|
18
|
+
|
|
19
|
+
export const ZONE_TOKEN_USAGE = "Usage: gencow domain zone-token <zone> [--rotate] [--yes] [--json]";
|
|
20
|
+
const ZONE_TOKEN_STAGE = "zone_proof";
|
|
21
|
+
|
|
22
|
+
/** Positional zone and flags. Values after --app/-a are not the zone. The zone is lowercased, with no trailing dot. */
|
|
23
|
+
export function parseZoneTokenArgs(restArgs) {
|
|
24
|
+
let zone = null;
|
|
25
|
+
for (let i = 0; i < restArgs.length; i++) {
|
|
26
|
+
const arg = restArgs[i];
|
|
27
|
+
if (arg === "--app" || arg === "-a") {
|
|
28
|
+
i++;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (!arg.startsWith("-") && zone === null) zone = arg;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
zone: zone ? zone.trim().toLowerCase().replace(/\.+$/u, "") : null,
|
|
35
|
+
rotate: restArgs.includes("--rotate"),
|
|
36
|
+
yes: restArgs.includes("--yes") || restArgs.includes("-y"),
|
|
37
|
+
json: restArgs.includes("--json"),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function text(value) {
|
|
42
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// A non-JSON body (for example a gateway page) returns null. The command reports it as a typed failure, never a throw.
|
|
46
|
+
async function readBody(response) {
|
|
47
|
+
try {
|
|
48
|
+
const value = await response.json();
|
|
49
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The failure as a typed body. Responses without a public code (an unreadable body, an unauthenticated 401, or another
|
|
57
|
+
* HTTP error) get a CLI-side code, so the report never prints "undefined" and never guesses the server state.
|
|
58
|
+
*/
|
|
59
|
+
export function zoneTokenFailureBody(status, data, { rotate, zone }) {
|
|
60
|
+
if (data && typeof data.code === "string") return data;
|
|
61
|
+
const retryCommand = `gencow domain zone-token ${zone}`;
|
|
62
|
+
// An older Platform has no zone-token route. Its 404/405 is not a fault in the zone or the account.
|
|
63
|
+
if (status === 404 || status === 405) {
|
|
64
|
+
return {
|
|
65
|
+
code: "CLI_ZONE_TOKEN_UNSUPPORTED",
|
|
66
|
+
stage: ZONE_TOKEN_STAGE,
|
|
67
|
+
error:
|
|
68
|
+
"This Platform does not support account zone tokens yet. Use the host TXT record that `domain set` shows.",
|
|
69
|
+
stateImpact: "No state was changed.",
|
|
70
|
+
retryable: false,
|
|
71
|
+
nextAction: "Run `gencow domain set <domain>` and add the host TXT record it shows.",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (data === null) {
|
|
75
|
+
return {
|
|
76
|
+
code: "CLI_ZONE_TOKEN_RESPONSE_UNREADABLE",
|
|
77
|
+
stage: ZONE_TOKEN_STAGE,
|
|
78
|
+
error: `the Platform returned an unreadable response${Number.isInteger(status) ? ` (HTTP ${status})` : ""}.`,
|
|
79
|
+
stateImpact: rotate ? "unknown; the zone TXT value may or may not have rotated." : "No state was changed.",
|
|
80
|
+
retryable: true,
|
|
81
|
+
nextAction: `Run \`${retryCommand}\` to see the current record before retrying.`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (Number.isInteger(status) && status >= 200 && status < 300) {
|
|
85
|
+
return {
|
|
86
|
+
code: "CLI_ZONE_TOKEN_RESPONSE_INVALID",
|
|
87
|
+
stage: ZONE_TOKEN_STAGE,
|
|
88
|
+
error: "the Platform answered without a usable zone record.",
|
|
89
|
+
stateImpact: rotate ? "unknown; the zone TXT value may or may not have rotated." : "No state was changed.",
|
|
90
|
+
retryable: true,
|
|
91
|
+
nextAction: `Run \`${retryCommand}\` to see the current record before retrying.`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (status === 401) {
|
|
95
|
+
return {
|
|
96
|
+
code: "CLI_AUTH_REQUIRED",
|
|
97
|
+
stage: "authentication",
|
|
98
|
+
error: "your sign-in is missing or has expired.",
|
|
99
|
+
stateImpact: "No state was changed.",
|
|
100
|
+
retryable: true,
|
|
101
|
+
nextAction: "Run `gencow login`, then rerun this command.",
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
...data,
|
|
106
|
+
code: `CLI_HTTP_${Number.isInteger(status) ? status : "ERROR"}`,
|
|
107
|
+
stage: ZONE_TOKEN_STAGE,
|
|
108
|
+
error: `the Platform returned HTTP ${Number.isInteger(status) ? status : "error"}.`,
|
|
109
|
+
stateImpact: rotate ? "unknown; the zone TXT value may or may not have rotated." : "No state was changed.",
|
|
110
|
+
retryable: true,
|
|
111
|
+
nextAction: `Wait a minute, then run \`${retryCommand}\`.`,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function printFailure(body, { prefix, json, logImpl, errorImpl, infoImpl }) {
|
|
116
|
+
if (json) {
|
|
117
|
+
logImpl(JSON.stringify({ success: false, ...body }, null, 2));
|
|
118
|
+
return 1;
|
|
119
|
+
}
|
|
120
|
+
const report = domainSetFailureReport(body, { prefix });
|
|
121
|
+
errorImpl(report.headline);
|
|
122
|
+
for (const line of report.details) infoImpl(line);
|
|
123
|
+
return 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The record block: type, name, value, and what the record covers. Shared by GET and the rotate follow-up. */
|
|
127
|
+
function printZoneRecord(zone, data, { logImpl, infoImpl }) {
|
|
128
|
+
logImpl(`\n${BOLD}${CYAN}Zone TXT record${RESET} — ${zone}\n`);
|
|
129
|
+
infoImpl(`Type: ${data.type ?? "TXT"}`);
|
|
130
|
+
infoImpl(`Name: ${data.recordName}`);
|
|
131
|
+
infoImpl(`Value: ${data.value}`);
|
|
132
|
+
infoImpl(`Token version: ${data.tokenVersion ?? "unknown"}`);
|
|
133
|
+
logImpl("");
|
|
134
|
+
infoImpl("One TXT record at the account level lets you connect any subdomain of this zone with");
|
|
135
|
+
infoImpl(`${DIM}gencow domain set <subdomain> --prod${RESET}, with no record per subdomain.`);
|
|
136
|
+
infoImpl("Deleting this record blocks NEW registrations only. Domains that are already active are unaffected.");
|
|
137
|
+
logImpl("");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function isZoneRecord(data) {
|
|
141
|
+
return data && data.success === true && text(data.recordName) && text(data.value);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function showZoneToken({ zone, json }, deps) {
|
|
145
|
+
const { creds, platformFetchImpl, logImpl, infoImpl, errorImpl } = deps;
|
|
146
|
+
const response = await platformFetchImpl(creds, `/platform/domain/zone-token?zone=${encodeURIComponent(zone)}`);
|
|
147
|
+
const data = await readBody(response);
|
|
148
|
+
if (!response.ok || !isZoneRecord(data)) {
|
|
149
|
+
const body = zoneTokenFailureBody(response.status, data, { rotate: false, zone });
|
|
150
|
+
return printFailure(body, { prefix: "Zone token request failed", json, logImpl, errorImpl, infoImpl });
|
|
151
|
+
}
|
|
152
|
+
if (json) {
|
|
153
|
+
logImpl(JSON.stringify(data, null, 2));
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
printZoneRecord(zone, data, { logImpl, infoImpl });
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const ROTATE_IMPACT = [
|
|
161
|
+
"Rotating the zone TXT value:",
|
|
162
|
+
" - The current value stops working immediately. There is no grace period.",
|
|
163
|
+
" - Registrations that are still waiting for zone proof and were proven with the old value are closed.",
|
|
164
|
+
" - Connected (active) domains are unchanged.",
|
|
165
|
+
" - You must replace the TXT record at each zone with the new value.",
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
// Uses the shared confirmation gate: --yes/-y bypasses, a non-TTY shell refuses (never waits on a prompt), and only an
|
|
169
|
+
// interactive terminal is prompted. EOF before an answer is reported as input_ended, not as a silent decline.
|
|
170
|
+
async function confirmRotation({ restArgs, deps }) {
|
|
171
|
+
const interactive = deps.interactive ?? Boolean(deps.createInterfaceImpl || process.stdin.isTTY);
|
|
172
|
+
const mode = resolveConfirmationMode({ args: restArgs, stdinIsTTY: interactive });
|
|
173
|
+
if (mode === CONFIRMATION_MODE.BYPASS) return "confirmed";
|
|
174
|
+
if (mode === CONFIRMATION_MODE.NON_INTERACTIVE) return "non_interactive";
|
|
175
|
+
for (const line of ROTATE_IMPACT) deps.infoImpl(line);
|
|
176
|
+
const answer = await askConfirmation({
|
|
177
|
+
createInterface: deps.createInterfaceImpl ?? createInterface,
|
|
178
|
+
prompt: "Type yes to rotate the zone TXT value: ",
|
|
179
|
+
output: process.stdout,
|
|
180
|
+
});
|
|
181
|
+
if (answer === null) return "input_ended";
|
|
182
|
+
return ["y", "yes"].includes(answer.trim().toLowerCase()) ? "confirmed" : "declined";
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function printNonInteractiveRefusal({ zone, json, deps }) {
|
|
186
|
+
const diagnostic = buildConfirmationRequiredDiagnostic({
|
|
187
|
+
correlationId: `zone_${randomUUID().replaceAll("-", "")}`,
|
|
188
|
+
retryCommand: `gencow domain zone-token ${zone} --rotate --yes`,
|
|
189
|
+
subject: `Rotating the zone TXT value for ${zone} needs confirmation.`,
|
|
190
|
+
});
|
|
191
|
+
if (json) {
|
|
192
|
+
deps.logImpl(JSON.stringify({ success: false, stateChanged: false, ...diagnostic }, null, 2));
|
|
193
|
+
} else {
|
|
194
|
+
renderConfirmationRequired(diagnostic, { errorImpl: deps.errorImpl, logImpl: deps.logImpl });
|
|
195
|
+
}
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Declined or cancelled at the prompt: nothing changed. With --json the answer is a typed body, not an empty success.
|
|
200
|
+
function printDeclined({ json, deps }) {
|
|
201
|
+
if (json) {
|
|
202
|
+
deps.logImpl(
|
|
203
|
+
JSON.stringify({ success: false, code: "ROTATION_DECLINED", stage: "confirm", stateChanged: false, error: "Rotation was not confirmed. Nothing was changed.", retryable: true, nextAction: "Rerun with --yes to rotate without a prompt." }, null, 2),
|
|
204
|
+
);
|
|
205
|
+
return 1;
|
|
206
|
+
}
|
|
207
|
+
deps.infoImpl("Rotation cancelled. Nothing was changed.");
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function rotateZoneToken({ zone, json, restArgs }, deps) {
|
|
212
|
+
const { creds, platformFetchImpl, logImpl, infoImpl, warnImpl, successImpl, errorImpl } = deps;
|
|
213
|
+
const failureOptions = { prefix: "Zone token rotation failed", json, logImpl, errorImpl, infoImpl };
|
|
214
|
+
const decision = await confirmRotation({ restArgs, deps });
|
|
215
|
+
if (decision === "non_interactive") return printNonInteractiveRefusal({ zone, json, deps });
|
|
216
|
+
if (decision === "declined" || decision === "input_ended") return printDeclined({ json, deps });
|
|
217
|
+
|
|
218
|
+
const response = await platformFetchImpl(creds, `/platform/domain/zone-token/rotate`, {
|
|
219
|
+
method: "POST",
|
|
220
|
+
headers: { "Content-Type": "application/json" },
|
|
221
|
+
body: "{}",
|
|
222
|
+
});
|
|
223
|
+
const data = await readBody(response);
|
|
224
|
+
if (!response.ok || !data || data.success !== true) {
|
|
225
|
+
return printFailure(zoneTokenFailureBody(response.status, data, { rotate: true, zone }), failureOptions);
|
|
226
|
+
}
|
|
227
|
+
if (json) {
|
|
228
|
+
logImpl(JSON.stringify(data, null, 2));
|
|
229
|
+
return 0;
|
|
230
|
+
}
|
|
231
|
+
const affected = Array.isArray(data.affectedZones) ? data.affectedZones.filter((item) => typeof item === "string") : [];
|
|
232
|
+
successImpl(`Zone TXT token rotated: version ${data.previousTokenVersion ?? "?"} → ${data.tokenVersion ?? "?"}`);
|
|
233
|
+
infoImpl(
|
|
234
|
+
`Closed: ${data.closedBindings ?? 0} waiting registration(s) that were proven with the old value. Connected domains are unchanged.`,
|
|
235
|
+
);
|
|
236
|
+
infoImpl(`Affected zones: ${affected.length > 0 ? affected.join(", ") : "none"}`);
|
|
237
|
+
if (text(data.nextAction)) infoImpl(`Next action: ${data.nextAction.trim()}`);
|
|
238
|
+
warnImpl("The old TXT value has stopped working. Replace the TXT record at each affected zone with the value below.");
|
|
239
|
+
|
|
240
|
+
// Show the new value for the zone the user asked about, so the replacement is one copy away.
|
|
241
|
+
const fresh = await platformFetchImpl(creds, `/platform/domain/zone-token?zone=${encodeURIComponent(zone)}`);
|
|
242
|
+
const freshData = await readBody(fresh);
|
|
243
|
+
if (fresh.ok && isZoneRecord(freshData)) {
|
|
244
|
+
printZoneRecord(zone, freshData, { logImpl, infoImpl });
|
|
245
|
+
} else {
|
|
246
|
+
warnImpl(`The new value could not be loaded. Run ${DIM}gencow domain zone-token ${zone}${RESET} to see it.`);
|
|
247
|
+
}
|
|
248
|
+
return 0;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Entry point for `gencow domain zone-token`. Account-level: no app target, and it runs before any app resolution. */
|
|
252
|
+
export async function runDomainZoneToken(restArgs, overrides = {}) {
|
|
253
|
+
const deps = {
|
|
254
|
+
creds: overrides.creds,
|
|
255
|
+
platformFetchImpl: overrides.platformFetchImpl ?? platformFetch,
|
|
256
|
+
createInterfaceImpl: overrides.createInterfaceImpl,
|
|
257
|
+
interactive: overrides.interactive,
|
|
258
|
+
logImpl: overrides.logImpl ?? log,
|
|
259
|
+
infoImpl: overrides.infoImpl ?? info,
|
|
260
|
+
warnImpl: overrides.warnImpl ?? warn,
|
|
261
|
+
successImpl: overrides.successImpl ?? success,
|
|
262
|
+
errorImpl: overrides.errorImpl ?? error,
|
|
263
|
+
};
|
|
264
|
+
const args = parseZoneTokenArgs(restArgs);
|
|
265
|
+
if (!args.zone) {
|
|
266
|
+
deps.errorImpl(ZONE_TOKEN_USAGE);
|
|
267
|
+
deps.infoImpl(" Example: gencow domain zone-token example.com");
|
|
268
|
+
return 1;
|
|
269
|
+
}
|
|
270
|
+
const context = { zone: args.zone, json: args.json, restArgs };
|
|
271
|
+
return args.rotate ? rotateZoneToken(context, deps) : showZoneToken(context, deps);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export function zoneTokenHelpLines() {
|
|
275
|
+
return [
|
|
276
|
+
` ${CYAN}zone-token <zone>${RESET} Show the account zone TXT record (one record covers all subdomains)`,
|
|
277
|
+
` ${DIM}--rotate${RESET} replace the value (interactive login only)`,
|
|
278
|
+
` ${DIM}--yes, -y${RESET} skip the rotation prompt; ${DIM}--json${RESET} print the server body`,
|
|
279
|
+
];
|
|
280
|
+
}
|
package/lib/jobs-command.mjs
CHANGED
|
@@ -34,6 +34,16 @@ export function formatScheduledJobFailure(errorMessage) {
|
|
|
34
34
|
`Correlation ID: ${diagnostic.correlationId}`,
|
|
35
35
|
].join("\n ");
|
|
36
36
|
}
|
|
37
|
+
if (diagnostic.code === "RUNTIME_SCHEDULER_ACTION_NOT_FOUND") {
|
|
38
|
+
const state = diagnostic.dataImpact === "none" ? "app data unchanged" : "state impact unknown";
|
|
39
|
+
return [
|
|
40
|
+
`${diagnostic.code} at ${diagnostic.stage}; ${state}.`,
|
|
41
|
+
diagnostic.retryable ? "Retryable after the stated condition." : "This failure is not retryable.",
|
|
42
|
+
`Retry condition: ${diagnostic.retryPrecondition}`,
|
|
43
|
+
`Next: ${diagnostic.nextAction}`,
|
|
44
|
+
`Job ID: ${diagnostic.correlationId}`,
|
|
45
|
+
].join("\n ");
|
|
46
|
+
}
|
|
37
47
|
if (diagnostic.code === "SCHEDULED_ACTION_NOT_REGISTERED") {
|
|
38
48
|
const state = diagnostic.stateChanged === false ? "app data unchanged" : "state impact unknown";
|
|
39
49
|
const retry = diagnostic.retryable
|
package/lib/opencode-config.mjs
CHANGED
|
@@ -22,6 +22,12 @@ export const GENCOW_MODEL_ID = "llm/code";
|
|
|
22
22
|
* 272,000 is the context threshold the gateway already uses for the GPT-6 family.
|
|
23
23
|
*/
|
|
24
24
|
export const GENCOW_MODEL_LIMIT = { context: 272000, output: 32000 };
|
|
25
|
+
/**
|
|
26
|
+
* OpenCode attaches an image only when the model declares image input; otherwise it drops the image before the request
|
|
27
|
+
* leaves the machine (verified on OpenCode 1.19.5). The gateway accepts images for llm/code on the streaming path.
|
|
28
|
+
* `modalities.input` alone is enough; no separate `attachment` flag is needed.
|
|
29
|
+
*/
|
|
30
|
+
export const GENCOW_MODEL_MODALITIES = { input: ["text", "image"], output: ["text"] };
|
|
25
31
|
export const GENCOW_KEY_FILE_REF = "{file:~/.gencow/opencode.key}";
|
|
26
32
|
|
|
27
33
|
export class OpencodeSetupError extends Error {
|
|
@@ -130,12 +136,31 @@ function atomicWrite(path, text, mode) {
|
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
138
|
|
|
133
|
-
|
|
139
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The Gencow provider block. Managed fields (package, base URL, key reference, output/context limit, modalities) always
|
|
143
|
+
* take our value; anything the user added to this block (other options, headers, renamed labels, variants, extra
|
|
144
|
+
* models) is kept, so a repair never discards their edits. Other providers are never touched.
|
|
145
|
+
*/
|
|
146
|
+
export function gencowProviderConfig(baseURL, existing) {
|
|
147
|
+
const previous = isPlainObject(existing) ? existing : {};
|
|
148
|
+
const previousModels = isPlainObject(previous.models) ? previous.models : {};
|
|
149
|
+
const previousModel = isPlainObject(previousModels[GENCOW_MODEL_ID]) ? previousModels[GENCOW_MODEL_ID] : {};
|
|
134
150
|
return {
|
|
151
|
+
...previous,
|
|
135
152
|
npm: "@ai-sdk/openai-compatible",
|
|
136
|
-
name: "Gencow",
|
|
137
|
-
options: { baseURL, apiKey: GENCOW_KEY_FILE_REF },
|
|
138
|
-
models: {
|
|
153
|
+
name: typeof previous.name === "string" && previous.name ? previous.name : "Gencow",
|
|
154
|
+
options: { ...(isPlainObject(previous.options) ? previous.options : {}), baseURL, apiKey: GENCOW_KEY_FILE_REF },
|
|
155
|
+
models: {
|
|
156
|
+
...previousModels,
|
|
157
|
+
[GENCOW_MODEL_ID]: {
|
|
158
|
+
...previousModel,
|
|
159
|
+
name: typeof previousModel.name === "string" && previousModel.name ? previousModel.name : "Gencow Code",
|
|
160
|
+
limit: { ...GENCOW_MODEL_LIMIT },
|
|
161
|
+
modalities: { input: [...GENCOW_MODEL_MODALITIES.input], output: [...GENCOW_MODEL_MODALITIES.output] },
|
|
162
|
+
},
|
|
163
|
+
},
|
|
139
164
|
};
|
|
140
165
|
}
|
|
141
166
|
|
|
@@ -171,7 +196,10 @@ export function planOpencodeEdits({ paths, baseURL, apiKey }) {
|
|
|
171
196
|
const nextConfig = {
|
|
172
197
|
...(config.$schema ? {} : { $schema: "https://opencode.ai/config.json" }),
|
|
173
198
|
...config,
|
|
174
|
-
provider: {
|
|
199
|
+
provider: {
|
|
200
|
+
...(config.provider ?? {}),
|
|
201
|
+
[GENCOW_PROVIDER_ID]: gencowProviderConfig(baseURL, config.provider?.[GENCOW_PROVIDER_ID]),
|
|
202
|
+
},
|
|
175
203
|
...(userHasModel ? {} : { model: `${GENCOW_PROVIDER_ID}/${GENCOW_MODEL_ID}` }),
|
|
176
204
|
};
|
|
177
205
|
|
|
@@ -242,15 +270,21 @@ export function hasGencowProvider(paths) {
|
|
|
242
270
|
});
|
|
243
271
|
}
|
|
244
272
|
|
|
245
|
-
/**
|
|
273
|
+
/**
|
|
274
|
+
* True when the provider block is the current shape: key-file reference, existing key file, the output limit and
|
|
275
|
+
* image input. An older shape is rewritten in place (no new token) by `setup`.
|
|
276
|
+
*/
|
|
246
277
|
export function hasKeyFileRef(paths) {
|
|
247
278
|
const text = readText(paths.configJson);
|
|
248
279
|
const provider = text ? parseJsonc(text)?.value?.provider?.[GENCOW_PROVIDER_ID] : null;
|
|
249
|
-
const
|
|
280
|
+
const model = provider?.models?.[GENCOW_MODEL_ID];
|
|
281
|
+
const limit = model?.limit;
|
|
250
282
|
return (
|
|
251
283
|
provider?.options?.apiKey === GENCOW_KEY_FILE_REF &&
|
|
252
284
|
limit?.output === GENCOW_MODEL_LIMIT.output &&
|
|
253
285
|
limit?.context === GENCOW_MODEL_LIMIT.context &&
|
|
286
|
+
Array.isArray(model?.modalities?.input) &&
|
|
287
|
+
model.modalities.input.includes("image") &&
|
|
254
288
|
Boolean(readText(paths.keyFile)?.trim())
|
|
255
289
|
);
|
|
256
290
|
}
|
|
@@ -39,6 +39,12 @@ export function formatProcedureRpcDiagnostic(caught) {
|
|
|
39
39
|
if (caught.retryPrecondition !== undefined)
|
|
40
40
|
lines.push(`Retry precondition: ${safeDetail(caught.retryPrecondition)}`);
|
|
41
41
|
if (caught.nextAction !== undefined) lines.push(`Next action: ${safeDetail(caught.nextAction)}`);
|
|
42
|
+
if (caught.scheduler && ["accepted", "pending", "rejected", "mixed"].includes(caught.scheduler.state) &&
|
|
43
|
+
Array.isArray(caught.scheduler.operationIds) && caught.scheduler.operationIds.length <= 64 &&
|
|
44
|
+
Array.from(caught.scheduler.operationIds).every((id) => typeof id === "string" && /^[A-Za-z0-9._:-]{1,256}$/u.test(id))) {
|
|
45
|
+
lines.push(`Scheduler state: ${caught.scheduler.state}`);
|
|
46
|
+
for (const id of caught.scheduler.operationIds) lines.push(`Scheduler operation: ${id}`);
|
|
47
|
+
}
|
|
42
48
|
if (Number.isInteger(caught.status) && caught.status >= 400 && caught.status <= 599)
|
|
43
49
|
lines.push(`HTTP status: ${caught.status}`);
|
|
44
50
|
if (typeof caught.correlationId === "string" && SAFE_CORRELATION.test(caught.correlationId))
|