gencow 0.1.269 → 0.1.271
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/lib/cli-command-runner.mjs +15 -2
- package/lib/cloud-target-environment.mjs +124 -0
- package/lib/cloud-targets.mjs +4 -0
- package/lib/db-command.mjs +15 -11
- package/lib/db-migration-command-steps.mjs +5 -2
- package/lib/db-push-command.mjs +14 -1
- package/lib/deploy-app-target.mjs +2 -0
- package/lib/deploy-command.mjs +11 -3
- package/lib/deploy-prod-target.mjs +1 -1
- package/lib/drizzle-generate.mjs +19 -0
- package/lib/env-command.mjs +45 -9
- package/lib/migration-advisory.mjs +2 -0
- package/lib/migration-diagnostic.mjs +33 -6
- package/lib/migration-rollback-cause.mjs +75 -0
- package/lib/migration-schema-load-failure.mjs +31 -0
- package/lib/prod-create-failure.mjs +9 -1
- package/lib/prod-create-region-diagnostic.mjs +86 -0
- package/lib/static-command.mjs +1 -1
- package/package.json +4 -4
- package/runtime/server.mjs +65 -65
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Plain-language one-liners for the PostgreSQL reason codes the Platform already
|
|
2
|
+
// classifies as user-fixable (migration-execution-outcome.ts). Only static text is
|
|
3
|
+
// printed here; the server never sends SQL, row values, or parameters for these codes.
|
|
4
|
+
const USER_FIXABLE_CAUSES = new Map([
|
|
5
|
+
["string_data_right_truncation", "a value is longer than its column type allows"],
|
|
6
|
+
["invalid_text_representation", "a value does not match the column's data type"],
|
|
7
|
+
["active_sql_transaction", "the statement cannot run inside a transaction block"],
|
|
8
|
+
[
|
|
9
|
+
"not_null_violation",
|
|
10
|
+
"a NOT NULL constraint rejected the statement (a populated table needs a DEFAULT or a nullable column)",
|
|
11
|
+
],
|
|
12
|
+
["foreign_key_violation", "a foreign key constraint rejected existing or new rows"],
|
|
13
|
+
["unique_violation", "a UNIQUE constraint rejected rows with duplicate values"],
|
|
14
|
+
["syntax_error", "PostgreSQL could not parse the statement"],
|
|
15
|
+
["duplicate_column", "the column already exists"],
|
|
16
|
+
["undefined_column", "the statement references a column that does not exist"],
|
|
17
|
+
["undefined_table", "the statement references a table that does not exist"],
|
|
18
|
+
["duplicate_table", "the table already exists"],
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
// Extra guidance for causes whose generic repair advice needs a specific hint.
|
|
22
|
+
const NOT_NULL_REPAIR_HINT =
|
|
23
|
+
"For a NOT NULL failure, give the new column a DEFAULT or make it nullable, or split the change into forward migrations (expand → backfill → contract).";
|
|
24
|
+
|
|
25
|
+
const SAFE_REASON_CODE = /^[a-z0-9_]{1,80}$/u;
|
|
26
|
+
|
|
27
|
+
export function isUserFixableRolledBackDiagnostic(diagnostic) {
|
|
28
|
+
return (
|
|
29
|
+
diagnostic?.code === "MIGRATION_TRANSACTION_ROLLED_BACK" &&
|
|
30
|
+
diagnostic.databaseState === "ROLLED_BACK" &&
|
|
31
|
+
diagnostic.failureClass === "USER_FIXABLE"
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function safeRollbackReasonCode(diagnostic) {
|
|
36
|
+
const code = diagnostic?.reason?.code;
|
|
37
|
+
return typeof code === "string" && SAFE_REASON_CODE.test(code) ? code : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Returns the "Cause:" line for a user-fixable rollback, or null when no safe code exists.
|
|
41
|
+
export function renderRollbackCauseLine(diagnostic) {
|
|
42
|
+
if (!isUserFixableRolledBackDiagnostic(diagnostic)) return null;
|
|
43
|
+
const code = safeRollbackReasonCode(diagnostic);
|
|
44
|
+
if (!code) return null;
|
|
45
|
+
const cause = USER_FIXABLE_CAUSES.get(code);
|
|
46
|
+
return cause ? `Cause: ${code} — ${cause}` : `Cause: ${code}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Honest replacement for the server's "exact statement" wording when the CLI could not
|
|
50
|
+
// verify a local source span. Only the already-safe migration name is shown.
|
|
51
|
+
export function renderUnlocatedRollbackFix(diagnostic) {
|
|
52
|
+
const name = diagnostic?.migration?.name;
|
|
53
|
+
const code = safeRollbackReasonCode(diagnostic);
|
|
54
|
+
const hint = code === "not_null_violation" ? ` ${NOT_NULL_REPAIR_HINT}` : "";
|
|
55
|
+
return {
|
|
56
|
+
title: name
|
|
57
|
+
? `Inspect the unapplied migration file ${name}`
|
|
58
|
+
: "Inspect the pending migrations listed by db:check",
|
|
59
|
+
detail: `Repair only the unapplied migration source for the cause above, review the generated diff, and create a fresh plan. Applied migrations and the journal are not edited.${hint}`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function renderUnlocatedRollbackLocation(diagnostic) {
|
|
64
|
+
const name = diagnostic?.migration?.name;
|
|
65
|
+
return name
|
|
66
|
+
? `Statement location: unavailable — inspect the unapplied migration file ${name}`
|
|
67
|
+
: "Statement location: unavailable — inspect the pending migrations listed by db:check";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const UNLOCATED_ROLLBACK_SUMMARY =
|
|
71
|
+
"PostgreSQL rejected a pending migration statement and rolled back the transaction.";
|
|
72
|
+
export const UNLOCATED_ROLLBACK_RETRY_CONDITION =
|
|
73
|
+
"Fix only the unapplied migration source for the cause above, then create and check a fresh plan.";
|
|
74
|
+
export const UNLOCATED_ROLLBACK_DETAIL =
|
|
75
|
+
"The failed transaction did not commit any migration or journal change.";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Single judgment for a db:generate failure where drizzle-kit throws a JavaScript runtime
|
|
2
|
+
// error AND its output names schema.ts. A runtime error alone is not enough: tooling and
|
|
3
|
+
// environment errors (for example `require is not defined` or `fetch failed`) also surface
|
|
4
|
+
// as TypeError/ReferenceError. Without the schema context those stay on the raw fallback.
|
|
5
|
+
// The construct inside schema.ts is still unknown, so the copy never confirms a cause.
|
|
6
|
+
const RUNTIME_ERROR_PATTERNS = Object.freeze([
|
|
7
|
+
/^\s*(?:TypeError|ReferenceError):\s/mu,
|
|
8
|
+
/\bCannot read properties of (?:undefined|null) \(reading '/u,
|
|
9
|
+
]);
|
|
10
|
+
// Matched against the raw output, because the sanitized text replaces paths and loses the file name.
|
|
11
|
+
const SCHEMA_CONTEXT_PATTERN = /\bschema(?:-auth)?(?:\.gen)?\.[cm]?[jt]sx?\b/u;
|
|
12
|
+
|
|
13
|
+
export const SCHEMA_LOAD_FAILED_REASON_CODE = "schema_load_failed";
|
|
14
|
+
|
|
15
|
+
// Returns { reasonCode } when the output is a runtime error that names the schema, otherwise null.
|
|
16
|
+
export function classifySchemaLoadFailure(rawMessage) {
|
|
17
|
+
const message = String(rawMessage ?? "");
|
|
18
|
+
if (!RUNTIME_ERROR_PATTERNS.some((pattern) => pattern.test(message))) return null;
|
|
19
|
+
if (!SCHEMA_CONTEXT_PATTERN.test(message)) return null;
|
|
20
|
+
return Object.freeze({ reasonCode: SCHEMA_LOAD_FAILED_REASON_CODE });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The raw generator text is never printed; only these fixed sentences reach the user.
|
|
24
|
+
export const SCHEMA_LOAD_FAILURE_CLI_MESSAGE =
|
|
25
|
+
"Migration generation stopped: drizzle-kit failed while generating migrations (possibly while loading your schema), so no migration file was generated.";
|
|
26
|
+
|
|
27
|
+
export const SCHEMA_LOAD_FAILURE_CAUSE_HINT =
|
|
28
|
+
"Possible cause (not confirmed): a table callback (the third argument of pgTable) returns an entry that is not an index, policy, or constraint. If a policy helper returns an array, spread it into the returned array with `...`. The tooling or environment may also be the cause.";
|
|
29
|
+
|
|
30
|
+
export const SCHEMA_LOAD_FAILURE_CLI_ACTION =
|
|
31
|
+
"Retryable: no — check the schema source (schema.ts) and the local tooling or environment, then rerun `gencow db:generate`.";
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { appResponseError } from "./app-response-error.mjs";
|
|
2
|
+
import {
|
|
3
|
+
formatRegionUnavailableMessage,
|
|
4
|
+
readRegionUnavailableDiagnostic,
|
|
5
|
+
} from "./prod-create-region-diagnostic.mjs";
|
|
2
6
|
|
|
3
7
|
/** One rendering of a failed `create-prod` response for every CLI deploy path. */
|
|
4
|
-
export function prodCreateFailureMessage(errData, response) {
|
|
8
|
+
export function prodCreateFailureMessage(errData, response, options = {}) {
|
|
5
9
|
const fallback =
|
|
6
10
|
response.status === 503
|
|
7
11
|
? "Prod app creation is temporarily unavailable."
|
|
8
12
|
: errData?.error || response.statusText || `HTTP ${response.status}`;
|
|
13
|
+
const regionDiagnostic = readRegionUnavailableDiagnostic(errData, response);
|
|
14
|
+
if (regionDiagnostic) {
|
|
15
|
+
return formatRegionUnavailableMessage(regionDiagnostic, fallback, options.requestedRegion ?? null);
|
|
16
|
+
}
|
|
9
17
|
return [
|
|
10
18
|
`Prod app creation failed: ${appResponseError(errData, fallback, response)}`,
|
|
11
19
|
"Retry: run the same command again; if another gencow command is creating this app, wait for it to finish first.",
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders the public REGION_UNAVAILABLE diagnostic from a create-prod 503.
|
|
3
|
+
* Every field is allow-listed: unknown, oversized or malformed values are
|
|
4
|
+
* dropped rather than echoed, and nothing is inferred when the server omits it.
|
|
5
|
+
* Older servers that send only the code keep the legacy rendering (null here).
|
|
6
|
+
*/
|
|
7
|
+
const STAGES = new Set(["prod_app_create_node_selection", "prod_app_create_node_proxy"]);
|
|
8
|
+
const REASON_TEXT = new Map([
|
|
9
|
+
["capacity_exhausted", "all nodes in this region are at app capacity"],
|
|
10
|
+
["no_active_node", "no active node serves this environment and region"],
|
|
11
|
+
["node_unavailable", "the matching node is not reporting healthy right now"],
|
|
12
|
+
["gateway_unavailable", "the target node's gateway is not ready"],
|
|
13
|
+
["node_config_invalid", "the target node has an invalid internal configuration (Platform-owned)"],
|
|
14
|
+
]);
|
|
15
|
+
const RETRY_CLASSES = new Set(["operator-action", "platform-action", "retryable-infra", "terminal-client"]);
|
|
16
|
+
const MAX_RETRY_AFTER_MS = 600_000;
|
|
17
|
+
// Same pattern the server uses for region slugs (apps-deploy-routes.ts create-prod validation).
|
|
18
|
+
const REGION_SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{0,31}$/u;
|
|
19
|
+
// Same shape as the correlation-ID check in app-response-error.mjs.
|
|
20
|
+
const CORRELATION_ID_PATTERN = /^[A-Za-z0-9_-]{8,128}$/u;
|
|
21
|
+
const STATUS_COMMAND = "gencow deploy status --prod";
|
|
22
|
+
|
|
23
|
+
export function readRegionUnavailableDiagnostic(body, response) {
|
|
24
|
+
if (response?.status !== 503) return null;
|
|
25
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return null;
|
|
26
|
+
if (body.code !== "REGION_UNAVAILABLE") return null;
|
|
27
|
+
|
|
28
|
+
const diagnostic = {
|
|
29
|
+
stage: STAGES.has(body.stage) ? body.stage : null,
|
|
30
|
+
reason: REASON_TEXT.has(body.reason) ? body.reason : null,
|
|
31
|
+
stateUnchanged: body.stateChanged === false,
|
|
32
|
+
retryClass: RETRY_CLASSES.has(body.retryClass) ? body.retryClass : null,
|
|
33
|
+
retryAfterMs:
|
|
34
|
+
Number.isSafeInteger(body.retryAfterMs) && body.retryAfterMs >= 0 && body.retryAfterMs <= MAX_RETRY_AFTER_MS
|
|
35
|
+
? body.retryAfterMs
|
|
36
|
+
: null,
|
|
37
|
+
correlationId:
|
|
38
|
+
typeof body.correlationId === "string" && CORRELATION_ID_PATTERN.test(body.correlationId)
|
|
39
|
+
? body.correlationId
|
|
40
|
+
: null,
|
|
41
|
+
};
|
|
42
|
+
const hasAnyField = Object.entries(diagnostic).some(([key, value]) =>
|
|
43
|
+
key === "stateUnchanged" ? value : value !== null,
|
|
44
|
+
);
|
|
45
|
+
return hasAnyField ? diagnostic : null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// The next step follows the server's retryClass; without one the CLI does not guess a retry.
|
|
49
|
+
// The region is echoed only when the user passed a valid --region; otherwise the region came
|
|
50
|
+
// from the dev app, so the user is pointed there.
|
|
51
|
+
function nextStepFor(retryClass, waitHint, requestedRegion) {
|
|
52
|
+
if (retryClass === "retryable-infra") {
|
|
53
|
+
const wait = waitHint ? ` after ${waitHint}` : "";
|
|
54
|
+
return `run \`${STATUS_COMMAND}\` to confirm no prod app was created, then run the same command again${wait}.`;
|
|
55
|
+
}
|
|
56
|
+
if (retryClass === "terminal-client") {
|
|
57
|
+
const regionStep =
|
|
58
|
+
requestedRegion && REGION_SLUG_PATTERN.test(requestedRegion)
|
|
59
|
+
? `check that \`--region ${requestedRegion}\` is available to this account, or pass a different --region`
|
|
60
|
+
: "check the region of your dev app, or pass `--region` with a region available to this account";
|
|
61
|
+
return `${regionStep}, then run the command again. Run \`${STATUS_COMMAND}\` first to see whether a prod app already exists.`;
|
|
62
|
+
}
|
|
63
|
+
if (retryClass === "platform-action") {
|
|
64
|
+
return `do not change your project. Run \`${STATUS_COMMAND}\` to check the current state; if it keeps failing after a few minutes, keep the Correlation ID for a Platform status check.`;
|
|
65
|
+
}
|
|
66
|
+
return `run \`${STATUS_COMMAND}\` to check whether a prod app was created.`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function formatWait(ms) {
|
|
70
|
+
return ms >= 1000 ? `${Math.round(ms / 1000)}s` : `${ms}ms`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function formatRegionUnavailableMessage(diagnostic, fallback, requestedRegion = null) {
|
|
74
|
+
const lines = [`Prod app creation failed: ${fallback}`, "Code: REGION_UNAVAILABLE"];
|
|
75
|
+
if (diagnostic.stage) lines.push(`Stage: ${diagnostic.stage}`);
|
|
76
|
+
if (diagnostic.reason) lines.push(`Reason: ${REASON_TEXT.get(diagnostic.reason)}`);
|
|
77
|
+
if (diagnostic.stateUnchanged) lines.push("Changed: nothing (no prod app was created)");
|
|
78
|
+
const retryable = diagnostic.retryClass === "retryable-infra";
|
|
79
|
+
if (diagnostic.retryClass) lines.push(`Retryable: ${retryable ? "yes" : "no"}`);
|
|
80
|
+
// A wait hint is only meaningful when the server marks the failure retryable.
|
|
81
|
+
const waitHint = retryable && diagnostic.retryAfterMs !== null ? formatWait(diagnostic.retryAfterMs) : null;
|
|
82
|
+
if (waitHint) lines.push(`Retry after: ${waitHint}`);
|
|
83
|
+
lines.push(`Next: ${nextStepFor(diagnostic.retryClass, waitHint, requestedRegion)}`);
|
|
84
|
+
if (diagnostic.correlationId) lines.push(`Correlation ID: ${diagnostic.correlationId}`);
|
|
85
|
+
return lines.join("\n");
|
|
86
|
+
}
|
package/lib/static-command.mjs
CHANGED
|
@@ -135,7 +135,7 @@ async function ensureStaticProductionTarget({
|
|
|
135
135
|
|
|
136
136
|
if (!createProdRes.ok) {
|
|
137
137
|
const errData = await readJsonObjectResponse(createProdRes);
|
|
138
|
-
errorImpl(prodCreateFailureMessage(errData, createProdRes));
|
|
138
|
+
errorImpl(prodCreateFailureMessage(errData, createProdRes, { requestedRegion: region }));
|
|
139
139
|
exitImpl(1);
|
|
140
140
|
return null;
|
|
141
141
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gencow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.271",
|
|
4
4
|
"description": "Gencow — AI Backend Engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dashboard/"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@gencow/migration-contract": "0.1.
|
|
24
|
+
"@gencow/migration-contract": "0.1.22",
|
|
25
25
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
26
26
|
"drizzle-kit": "1.0.0-rc.4",
|
|
27
27
|
"drizzle-orm": "1.0.0-rc.4",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"better-auth": "1.7.11",
|
|
42
42
|
"postgres": "^3.4.9",
|
|
43
43
|
"@gencow/client": "0.2.8",
|
|
44
|
-
"@gencow/react": "0.2.8",
|
|
45
44
|
"@gencow/core": "0.1.47",
|
|
45
|
+
"@gencow/server": "0.1.3",
|
|
46
46
|
"@gencow/shared": "0.0.0",
|
|
47
|
-
"@gencow/
|
|
47
|
+
"@gencow/react": "0.2.8"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-server.mjs",
|