gencow 0.1.294 → 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/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/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/jobs-command.mjs +10 -0
- package/lib/opencode-config.mjs +41 -7
- package/lib/procedure-rpc-diagnostic.mjs +6 -0
- package/package.json +3 -3
- package/runtime/server.mjs +214 -197
- package/runtime/tooling.mjs +113 -8
- package/scripts/tooling-codegen-runtime.ts +17 -3
package/README.md
CHANGED
|
@@ -25,6 +25,13 @@ confirming them.
|
|
|
25
25
|
|
|
26
26
|
## Documentation
|
|
27
27
|
|
|
28
|
+
Full `gencow codegen` rejects malformed procedure/CRUD declarations and duplicate
|
|
29
|
+
same-kind names. Correct the declarations, run `gencow codegen`, then rerun deploy.
|
|
30
|
+
Packaging adds no application import solely for this check, so apps requiring cloud
|
|
31
|
+
configuration keep their existing packaging behavior. Configured codegen and cron
|
|
32
|
+
generation keep their existing execution behavior; runtime startup validation remains
|
|
33
|
+
mandatory. Application imports may have side effects.
|
|
34
|
+
|
|
28
35
|
- [Documentation index](docs/README.md)
|
|
29
36
|
- [Command reference](docs/commands.md)
|
|
30
37
|
- [CLI interface and generated artifacts](docs/api.md)
|
package/core/index.js
CHANGED
|
@@ -850,12 +850,30 @@ function verifyRealtimeChannelToken(token, input) {
|
|
|
850
850
|
|
|
851
851
|
// ../core/src/v.ts
|
|
852
852
|
var GencowValidationError = class extends Error {
|
|
853
|
-
|
|
854
|
-
constructor(message) {
|
|
853
|
+
constructor(message, validationPhase = "unknown") {
|
|
855
854
|
super(message);
|
|
855
|
+
this.validationPhase = validationPhase;
|
|
856
856
|
this.name = "GencowValidationError";
|
|
857
857
|
}
|
|
858
|
+
validationPhase;
|
|
859
|
+
statusCode = 400;
|
|
860
|
+
status = 400;
|
|
858
861
|
};
|
|
862
|
+
function isGencowValidationError(error) {
|
|
863
|
+
try {
|
|
864
|
+
return error instanceof Error && error.name === "GencowValidationError" && error.statusCode === 400;
|
|
865
|
+
} catch {
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
function getGencowValidationPhase(error) {
|
|
870
|
+
try {
|
|
871
|
+
const phase = error?.validationPhase;
|
|
872
|
+
return phase === "input" || phase === "output" ? phase : "unknown";
|
|
873
|
+
} catch {
|
|
874
|
+
return "unknown";
|
|
875
|
+
}
|
|
876
|
+
}
|
|
859
877
|
var GENCOW_OPTIONAL_INNER = /* @__PURE__ */ Symbol.for("gencow.v.optionalInner");
|
|
860
878
|
function assertStandardResult(value) {
|
|
861
879
|
return { value };
|
|
@@ -1106,14 +1124,14 @@ function parseArgs(schema, args) {
|
|
|
1106
1124
|
try {
|
|
1107
1125
|
return schema.parse(normalizeMissingOptionalObjectInput(schema, args));
|
|
1108
1126
|
} catch (e) {
|
|
1109
|
-
throw new GencowValidationError(e.message);
|
|
1127
|
+
throw new GencowValidationError(e.message, "input");
|
|
1110
1128
|
}
|
|
1111
1129
|
}
|
|
1112
1130
|
if (typeof schema === "object" && schema !== null) {
|
|
1113
1131
|
const schemaKeys = Object.keys(schema);
|
|
1114
1132
|
if (schemaKeys.length === 0) return args;
|
|
1115
1133
|
if (typeof args !== "object" || args === null) {
|
|
1116
|
-
throw new GencowValidationError("Expected an object for arguments");
|
|
1134
|
+
throw new GencowValidationError("Expected an object for arguments", "input");
|
|
1117
1135
|
}
|
|
1118
1136
|
const result = {};
|
|
1119
1137
|
for (const key of schemaKeys) {
|
|
@@ -1122,7 +1140,7 @@ function parseArgs(schema, args) {
|
|
|
1122
1140
|
try {
|
|
1123
1141
|
result[key] = validator.parse(args[key]);
|
|
1124
1142
|
} catch (e) {
|
|
1125
|
-
throw new GencowValidationError(`Argument "${key}": ${e.message}
|
|
1143
|
+
throw new GencowValidationError(`Argument "${key}": ${e.message}`, "input");
|
|
1126
1144
|
}
|
|
1127
1145
|
} else {
|
|
1128
1146
|
result[key] = args[key];
|
|
@@ -1678,16 +1696,32 @@ function hasStandardSchema3(schema) {
|
|
|
1678
1696
|
}
|
|
1679
1697
|
async function validateWithSchema(schema, value, options) {
|
|
1680
1698
|
if (!schema) return value;
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1699
|
+
let valueToValidate;
|
|
1700
|
+
let standardSchema;
|
|
1701
|
+
try {
|
|
1702
|
+
valueToValidate = options.normalizeMissingOptionalObject ? normalizeMissingOptionalObjectInput(schema, value) : value;
|
|
1703
|
+
if (hasStandardSchema3(schema)) standardSchema = schema;
|
|
1704
|
+
} catch {
|
|
1705
|
+
throw new GencowValidationError("Validation failed", options.phase);
|
|
1706
|
+
}
|
|
1707
|
+
if (standardSchema) {
|
|
1708
|
+
let accepted = false;
|
|
1709
|
+
let validatedValue;
|
|
1710
|
+
let failureMessage = "Validation failed";
|
|
1711
|
+
try {
|
|
1712
|
+
const result = await standardSchema["~standard"].validate(valueToValidate);
|
|
1713
|
+
if (result && typeof result === "object") {
|
|
1714
|
+
if ("issues" in result && result.issues.length > 0) failureMessage = result.issues[0]?.message ?? failureMessage;
|
|
1715
|
+
else if ("value" in result) {
|
|
1716
|
+
accepted = true;
|
|
1717
|
+
validatedValue = result.value;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
} catch {
|
|
1721
|
+
throw new GencowValidationError("Validation failed", options.phase);
|
|
1689
1722
|
}
|
|
1690
|
-
|
|
1723
|
+
if (accepted) return validatedValue;
|
|
1724
|
+
throw new GencowValidationError(failureMessage, options.phase);
|
|
1691
1725
|
}
|
|
1692
1726
|
throw new Error(
|
|
1693
1727
|
"procedure.query / procedure.mutation / procedure.internal only supports Standard Schema v1 validators"
|
|
@@ -1706,13 +1740,14 @@ function composeMiddlewares(middlewares, handler, inputSchema, outputSchema, inp
|
|
|
1706
1740
|
let currentInput = input;
|
|
1707
1741
|
if (currentIdx === boundedInputValidationIndex) {
|
|
1708
1742
|
currentInput = await validateWithSchema(inputSchema, currentInput, {
|
|
1709
|
-
normalizeMissingOptionalObject: true
|
|
1743
|
+
normalizeMissingOptionalObject: true,
|
|
1744
|
+
phase: "input"
|
|
1710
1745
|
});
|
|
1711
1746
|
}
|
|
1712
1747
|
if (currentIdx === middlewares.length) {
|
|
1713
1748
|
const output2 = await handler({ context, input: currentInput });
|
|
1714
1749
|
if (currentIdx === boundedOutputValidationIndex) {
|
|
1715
|
-
return await validateWithSchema(outputSchema, output2);
|
|
1750
|
+
return await validateWithSchema(outputSchema, output2, { phase: "output" });
|
|
1716
1751
|
}
|
|
1717
1752
|
return output2;
|
|
1718
1753
|
}
|
|
@@ -1729,7 +1764,7 @@ function composeMiddlewares(middlewares, handler, inputSchema, outputSchema, inp
|
|
|
1729
1764
|
}
|
|
1730
1765
|
});
|
|
1731
1766
|
if (currentIdx === boundedOutputValidationIndex) {
|
|
1732
|
-
return await validateWithSchema(outputSchema, output);
|
|
1767
|
+
return await validateWithSchema(outputSchema, output, { phase: "output" });
|
|
1733
1768
|
}
|
|
1734
1769
|
return output;
|
|
1735
1770
|
};
|
|
@@ -3985,6 +4020,23 @@ function registerWorkflowsApi() {
|
|
|
3985
4020
|
return definitions;
|
|
3986
4021
|
}
|
|
3987
4022
|
|
|
4023
|
+
// ../core/src/authorization-error.ts
|
|
4024
|
+
var GencowAuthorizationError = class extends Error {
|
|
4025
|
+
code = "APP_AUTHORIZATION_DENIED";
|
|
4026
|
+
status = 403;
|
|
4027
|
+
constructor() {
|
|
4028
|
+
super("The requested operation is not authorized.");
|
|
4029
|
+
this.name = "GencowAuthorizationError";
|
|
4030
|
+
}
|
|
4031
|
+
};
|
|
4032
|
+
function isGencowAuthorizationError(error) {
|
|
4033
|
+
try {
|
|
4034
|
+
return error instanceof Error && error.name === "GencowAuthorizationError" && error.code === "APP_AUTHORIZATION_DENIED" && error.status === 403;
|
|
4035
|
+
} catch {
|
|
4036
|
+
return false;
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
|
|
3988
4040
|
// ../core/src/retry.ts
|
|
3989
4041
|
var DEFAULT_MAX_ATTEMPTS = 3;
|
|
3990
4042
|
var DEFAULT_INITIAL_BACKOFF_MS = 1e3;
|
|
@@ -5408,6 +5460,14 @@ function parseFilterNode2(node, table, allowedFields, depth = 0, opts) {
|
|
|
5408
5460
|
// ../core/src/createCrud.owner.ts
|
|
5409
5461
|
import { getTableName as getTableName2, getTableColumns } from "drizzle-orm";
|
|
5410
5462
|
import { getTableConfig } from "drizzle-orm/pg-core";
|
|
5463
|
+
function independentProperty(table, column, columnName) {
|
|
5464
|
+
try {
|
|
5465
|
+
const other = getTableColumns(table)[columnName];
|
|
5466
|
+
return !!other && other !== column;
|
|
5467
|
+
} catch {
|
|
5468
|
+
return false;
|
|
5469
|
+
}
|
|
5470
|
+
}
|
|
5411
5471
|
function resolvePropertyName(table, columnName) {
|
|
5412
5472
|
try {
|
|
5413
5473
|
const columns = getTableColumns(table);
|
|
@@ -5429,7 +5489,8 @@ function detectOwnerMeta(table) {
|
|
|
5429
5489
|
column: col,
|
|
5430
5490
|
columnName: meta.columnName,
|
|
5431
5491
|
propertyName: propName,
|
|
5432
|
-
readPublic: meta.readPublic
|
|
5492
|
+
readPublic: meta.readPublic,
|
|
5493
|
+
columnNameIsIndependentProperty: independentProperty(table, col, meta.columnName)
|
|
5433
5494
|
};
|
|
5434
5495
|
}
|
|
5435
5496
|
}
|
|
@@ -5440,7 +5501,13 @@ function detectOwnerMeta(table) {
|
|
|
5440
5501
|
const propertyName = resolvePropertyName(table, declared.columnName);
|
|
5441
5502
|
const column = anyTable[propertyName];
|
|
5442
5503
|
if (column)
|
|
5443
|
-
return {
|
|
5504
|
+
return {
|
|
5505
|
+
column,
|
|
5506
|
+
columnName: declared.columnName,
|
|
5507
|
+
propertyName,
|
|
5508
|
+
readPublic: declared.readPublic,
|
|
5509
|
+
columnNameIsIndependentProperty: independentProperty(table, column, declared.columnName)
|
|
5510
|
+
};
|
|
5444
5511
|
}
|
|
5445
5512
|
if (config.policies && config.policies.length > 0) {
|
|
5446
5513
|
const propName = anyTable["userId"] ? "userId" : anyTable["user_id"] ? "user_id" : null;
|
|
@@ -5448,7 +5515,13 @@ function detectOwnerMeta(table) {
|
|
|
5448
5515
|
const userIdCol = anyTable[propName];
|
|
5449
5516
|
const colName = userIdCol.name || "user_id";
|
|
5450
5517
|
registerOwnerRls(table, { columnName: colName, readPublic: false });
|
|
5451
|
-
return {
|
|
5518
|
+
return {
|
|
5519
|
+
column: userIdCol,
|
|
5520
|
+
columnName: colName,
|
|
5521
|
+
propertyName: propName,
|
|
5522
|
+
readPublic: false,
|
|
5523
|
+
columnNameIsIndependentProperty: independentProperty(table, userIdCol, colName)
|
|
5524
|
+
};
|
|
5452
5525
|
}
|
|
5453
5526
|
const tblName = getTableName2(table);
|
|
5454
5527
|
console.warn(
|
|
@@ -5460,6 +5533,30 @@ function detectOwnerMeta(table) {
|
|
|
5460
5533
|
return null;
|
|
5461
5534
|
}
|
|
5462
5535
|
|
|
5536
|
+
// ../core/src/createCrud.authorization.ts
|
|
5537
|
+
async function denyUnless(policy, ctx) {
|
|
5538
|
+
if (policy && !await policy(ctx)) throw new GencowAuthorizationError();
|
|
5539
|
+
}
|
|
5540
|
+
function ownerKeys(owner) {
|
|
5541
|
+
return new Set(
|
|
5542
|
+
owner.columnNameIsIndependentProperty ? [owner.propertyName] : [owner.propertyName, owner.columnName]
|
|
5543
|
+
);
|
|
5544
|
+
}
|
|
5545
|
+
function applyCrudOwner(data, owner, userId) {
|
|
5546
|
+
for (const key of ownerKeys(owner)) {
|
|
5547
|
+
if (data[key] != null && data[key] !== userId) throw new GencowAuthorizationError();
|
|
5548
|
+
}
|
|
5549
|
+
return { ...data, [owner.propertyName]: userId };
|
|
5550
|
+
}
|
|
5551
|
+
function protectCrudOwnerUpdate(data, owner, userId) {
|
|
5552
|
+
const protectedData = { ...data };
|
|
5553
|
+
for (const key of ownerKeys(owner)) {
|
|
5554
|
+
if (protectedData[key] != null && protectedData[key] !== userId) throw new GencowAuthorizationError();
|
|
5555
|
+
if (key !== owner.propertyName || protectedData[key] !== userId) delete protectedData[key];
|
|
5556
|
+
}
|
|
5557
|
+
return protectedData;
|
|
5558
|
+
}
|
|
5559
|
+
|
|
5463
5560
|
// ../core/src/createCrud.realtime.ts
|
|
5464
5561
|
import { getTableConfig as getTableConfig2 } from "drizzle-orm/pg-core";
|
|
5465
5562
|
var CRUD_LIST_BUCKET_QUERY = "__gencow.crud.list";
|
|
@@ -5718,11 +5815,6 @@ function buildTupleComparePredicate(columns, values, direction) {
|
|
|
5718
5815
|
}
|
|
5719
5816
|
|
|
5720
5817
|
// ../core/src/createCrud.ts
|
|
5721
|
-
async function denyUnless(policy, ctx) {
|
|
5722
|
-
if (!policy) return;
|
|
5723
|
-
const ok = await policy(ctx);
|
|
5724
|
-
if (!ok) throw new Error("Forbidden");
|
|
5725
|
-
}
|
|
5726
5818
|
function buildCrud(table, options, procedure) {
|
|
5727
5819
|
const { query: query2, mutation: mutation2 } = procedure;
|
|
5728
5820
|
const anyTable = table;
|
|
@@ -6101,19 +6193,14 @@ function buildCrud(table, options, procedure) {
|
|
|
6101
6193
|
const user = ownerMeta || !allowAnonymous ? context.auth.requireAuth() : null;
|
|
6102
6194
|
let insertData = typeof input === "object" && input !== null ? { ...input } : {};
|
|
6103
6195
|
if (ownerMeta && user) {
|
|
6104
|
-
|
|
6105
|
-
if (requestedOwner != null && requestedOwner !== user.id) {
|
|
6106
|
-
throw new Error("Forbidden: cannot create resource for another user");
|
|
6107
|
-
}
|
|
6108
|
-
}
|
|
6109
|
-
if (ownerMeta && user) {
|
|
6110
|
-
insertData[ownerMeta.propertyName] = user.id;
|
|
6196
|
+
insertData = applyCrudOwner(insertData, ownerMeta, user.id);
|
|
6111
6197
|
} else if (userIdCol && user && !insertData.userId) {
|
|
6112
6198
|
insertData.userId = user.id;
|
|
6113
6199
|
}
|
|
6114
6200
|
if (options?.hooks?.beforeCreate) {
|
|
6115
6201
|
insertData = await options.hooks.beforeCreate(insertData);
|
|
6116
6202
|
}
|
|
6203
|
+
if (ownerMeta && user) insertData = applyCrudOwner(insertData, ownerMeta, user.id);
|
|
6117
6204
|
const { result, realtimeRow } = await inRlsOrPlainTx(context.db, async (tx) => {
|
|
6118
6205
|
if (crudRealtime.explicitScopedList) {
|
|
6119
6206
|
const [insertedFullRow] = await tx.insert(anyTable).values(insertData).returning();
|
|
@@ -6163,6 +6250,7 @@ function buildCrud(table, options, procedure) {
|
|
|
6163
6250
|
if (options?.hooks?.beforeUpdate) {
|
|
6164
6251
|
updateData = await options.hooks.beforeUpdate(updateData);
|
|
6165
6252
|
}
|
|
6253
|
+
if (ownerMeta && user) updateData = protectCrudOwnerUpdate(updateData, ownerMeta, user.id);
|
|
6166
6254
|
const { result, preRealtimeRow, postRealtimeRow } = await inRlsOrPlainTx(
|
|
6167
6255
|
context.db,
|
|
6168
6256
|
async (tx) => {
|
|
@@ -6262,6 +6350,7 @@ export {
|
|
|
6262
6350
|
DEFAULT_WAKE_RETRY_AFTER_SEC,
|
|
6263
6351
|
DEFAULT_WORKFLOW_MAX_DURATION_MS,
|
|
6264
6352
|
DEFAULT_WORKFLOW_MAX_RETRIES,
|
|
6353
|
+
GencowAuthorizationError,
|
|
6265
6354
|
GencowValidationError,
|
|
6266
6355
|
JobAdmissionError,
|
|
6267
6356
|
MAX_FILE_SIZE,
|
|
@@ -6328,6 +6417,7 @@ export {
|
|
|
6328
6417
|
eqRlsContextColumn,
|
|
6329
6418
|
filterTenantRuntimeEnvVars,
|
|
6330
6419
|
formatBytes,
|
|
6420
|
+
getGencowValidationPhase,
|
|
6331
6421
|
getHttpRouteDiscardedResponse,
|
|
6332
6422
|
getHttpRouteDiscardedResponseCause,
|
|
6333
6423
|
getJobAdmissionStatus,
|
|
@@ -6349,6 +6439,8 @@ export {
|
|
|
6349
6439
|
hasMapSessionToContext,
|
|
6350
6440
|
inferTableNameFromColumn,
|
|
6351
6441
|
isCronJobsBuilder,
|
|
6442
|
+
isGencowAuthorizationError,
|
|
6443
|
+
isGencowValidationError,
|
|
6352
6444
|
isHttpRouteOutputValidationFailure,
|
|
6353
6445
|
isJobAdmissionError,
|
|
6354
6446
|
isJobAdmissionKillSwitchActive,
|
package/lib/app-command.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatInactiveStopDetails } from "./app-inactive-stop-format.mjs";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
4
|
import { basename, resolve } from "path";
|
|
@@ -613,6 +614,8 @@ ${dashboardLine}
|
|
|
613
614
|
logImpl(` Status: ${status.colored}`);
|
|
614
615
|
const memoryExceededDetails = formatMemoryExceededDetails(data);
|
|
615
616
|
if (memoryExceededDetails) logImpl(memoryExceededDetails);
|
|
617
|
+
const inactiveStopDetails = formatInactiveStopDetails(data);
|
|
618
|
+
if (inactiveStopDetails) logImpl(inactiveStopDetails);
|
|
616
619
|
const recoveryDetails = formatRecoveryDispositionDetails(data);
|
|
617
620
|
if (recoveryDetails) logImpl(recoveryDetails);
|
|
618
621
|
logImpl(` Port: ${data.port ?? `${DIM}not deployed${RESET}`}`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// `gencow app status` rendering of an app the Platform stopped for inactivity (APP_STOPPED_INACTIVE).
|
|
2
|
+
// Only a fixed, platform-authored shape is rendered; the app name is validated before it is echoed in a command.
|
|
3
|
+
|
|
4
|
+
const SAFE_APP_NAME = /^[a-z0-9][a-z0-9-]{0,62}$/u;
|
|
5
|
+
|
|
6
|
+
export function formatInactiveStopDetails(appRow) {
|
|
7
|
+
const diagnostic = appRow?.stopDiagnostic;
|
|
8
|
+
if (appRow?.status !== "stopped" || diagnostic?.code !== "APP_STOPPED_INACTIVE") return "";
|
|
9
|
+
const name = typeof appRow.name === "string" && SAFE_APP_NAME.test(appRow.name) ? appRow.name : "<app>";
|
|
10
|
+
return [
|
|
11
|
+
" Code: APP_STOPPED_INACTIVE",
|
|
12
|
+
" Reason: stopped automatically because the last deployment is older than the keep period (not a Platform failure)",
|
|
13
|
+
" Data and settings: unchanged",
|
|
14
|
+
" Retry: not needed; the app stays stopped until you resume or redeploy it",
|
|
15
|
+
` Next: gencow app resume ${name} (or redeploy with: gencow deploy)`,
|
|
16
|
+
].join("\n");
|
|
17
|
+
}
|
|
@@ -47,6 +47,13 @@ const SAFE_PLATFORM_ERROR_DETAILS = new Map([
|
|
|
47
47
|
["REQUEST_BODY_SIZE_LIMIT", "The upload is too large. Exclude generated or vendored files from the project source and rerun deploy."],
|
|
48
48
|
]);
|
|
49
49
|
const SAFE_LOCAL_ERROR_CODES = new Map([
|
|
50
|
+
["RUNTIME_APP_DECLARATION_INVALID", {
|
|
51
|
+
message: "Application declaration validation failed before deployment upload.",
|
|
52
|
+
stage: "declaration",
|
|
53
|
+
detail: (caught) => typeof caught.declarationDetail === "string" && /^[\p{L}\p{N}_.:" -]{1,256}$/u.test(caught.declarationDetail) ? caught.declarationDetail : null,
|
|
54
|
+
dataImpact: "UNKNOWN (local application import effects may remain)",
|
|
55
|
+
action: "Retryable: no — correct the procedure/CRUD declarations, run `gencow codegen`, then explicitly rerun `gencow deploy`.",
|
|
56
|
+
}],
|
|
50
57
|
[
|
|
51
58
|
"MIGRATION_GENERATION_FAILED",
|
|
52
59
|
{
|
|
@@ -404,7 +411,7 @@ function commandErrorMessageCore(caught) {
|
|
|
404
411
|
: "Production app: gencow.json does not bind this target, so this output does not say whether a production app was created. Check gencow.json before rerunning.",
|
|
405
412
|
);
|
|
406
413
|
}
|
|
407
|
-
lines.push(
|
|
414
|
+
lines.push(`Database mutation: ${localDiagnostic.dataImpact ?? "NONE"}`, "Incumbent serving: PRESERVED", action);
|
|
408
415
|
if (typeof caught.correlationId === "string" && SAFE_CORRELATION_ID.test(caught.correlationId)) {
|
|
409
416
|
lines.push(`Correlation ID: ${caught.correlationId} (local reference)`);
|
|
410
417
|
}
|
package/lib/codegen-command.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatCommandError } from "./cli-command-runner.mjs";
|
|
1
2
|
import { existsSync } from "fs";
|
|
2
3
|
import { relative, resolve } from "path";
|
|
3
4
|
import {
|
|
@@ -141,7 +142,7 @@ export function logCodegenDiagnostics(logImpl, diagnostics, colors) {
|
|
|
141
142
|
|
|
142
143
|
async function loadCodegenBundleDefault() {
|
|
143
144
|
return loadToolingRuntime({
|
|
144
|
-
required: ["codegen"],
|
|
145
|
+
required: ["codegen", "assertAppDeclarations"],
|
|
145
146
|
label: "tooling runtime",
|
|
146
147
|
});
|
|
147
148
|
}
|
|
@@ -384,7 +385,7 @@ export function createCodegenCommand(deps) {
|
|
|
384
385
|
});
|
|
385
386
|
deps.successImpl("Codegen completed successfully.");
|
|
386
387
|
} catch (error) {
|
|
387
|
-
deps.errorImpl(`Codegen failed: ${error
|
|
388
|
+
deps.errorImpl(`Codegen failed: ${formatCommandError(error)}`);
|
|
388
389
|
deps.exitImpl(1);
|
|
389
390
|
}
|
|
390
391
|
};
|
|
@@ -175,6 +175,7 @@ export async function prepareDeployCodegenArtifacts({
|
|
|
175
175
|
});
|
|
176
176
|
} catch (caught) {
|
|
177
177
|
cleanup();
|
|
178
|
+
if (caught?.code === "RUNTIME_APP_DECLARATION_INVALID") throw caught;
|
|
178
179
|
throw createDeployCodegenFailure(classifyDeployCodegenFailure(caught, { cwd, backendRoot }), {
|
|
179
180
|
correlationId: `deploy_${randomUUIDImpl()}`,
|
|
180
181
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function appendDeclarationFailureState(lines, contract, selfService) {
|
|
2
|
+
const applies =
|
|
3
|
+
!selfService &&
|
|
4
|
+
contract.stage === "candidate" &&
|
|
5
|
+
contract.userAction === "EDIT_AND_CHECK" &&
|
|
6
|
+
["RUNTIME_APP_DECLARATION_INVALID", "RUNTIME_CRON_DECLARATION_INVALID"].includes(contract.code);
|
|
7
|
+
if (applies) {
|
|
8
|
+
lines.push(
|
|
9
|
+
"Database mutation: UNKNOWN",
|
|
10
|
+
"Incumbent serving: UNKNOWN",
|
|
11
|
+
"Retry policy: AFTER_FIX — Correct the application declarations before starting a new deployment; earlier import effects may remain.",
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return applies;
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { loadProjectConfigForDeploy } from "./deploy-project-config-load.mjs";
|
|
2
|
+
import { resolveConfiguredBackendRoot } from "./deploy-codegen-preflight.mjs";
|
|
3
|
+
|
|
4
|
+
export function isExplicitEmptyBackendApi(source) {
|
|
5
|
+
return /\bdefineApi\s*\(\s*\{\s*procedures\s*:\s*\{\s*\}\s*,?\s*\}\s*\)\s*;?\s*$/u.test(source);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function createBackendCapabilityPreflight(deps) {
|
|
9
|
+
return async () => {
|
|
10
|
+
const cwd = deps.cwdImpl();
|
|
11
|
+
const config = await loadProjectConfigForDeploy({ ...deps, cwd, throwOnInvalid: false });
|
|
12
|
+
const entry = deps.resolvePathImpl(cwd, resolveConfiguredBackendRoot(config), "index.ts");
|
|
13
|
+
if (!deps.existsSyncImpl(entry) || !isExplicitEmptyBackendApi(deps.readFileSyncImpl(entry, "utf8")))
|
|
14
|
+
return true;
|
|
15
|
+
deps.errorImpl(
|
|
16
|
+
"Backend deploy stopped before upload because this project registers no query, mutation, or procedure.",
|
|
17
|
+
);
|
|
18
|
+
deps.infoImpl("Code: BACKEND_CAPABILITY_EMPTY");
|
|
19
|
+
deps.infoImpl("Stage: candidate");
|
|
20
|
+
deps.infoImpl(`Correlation ID: deploy_${deps.randomUUIDImpl()}`);
|
|
21
|
+
deps.infoImpl("Next action: EDIT_AND_CHECK");
|
|
22
|
+
deps.infoImpl("Add a backend procedure, or use gencow static <build-directory> for a frontend-only app.");
|
|
23
|
+
deps.exitImpl(1);
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { appendDeclarationFailureState } from "./deploy-declaration-diagnostic.mjs";
|
|
1
2
|
import { MIGRATION_NEXT_ACTION_KINDS, MIGRATION_RETRY_POLICIES } from "@gencow/migration-contract";
|
|
2
3
|
|
|
3
4
|
import { APP_DELETE_OPERATION_PATTERN } from "./app-response-error.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import { formatDeployFailureNextAction } from "./deploy-failure-next-action.mjs";
|
|
5
6
|
import { formatDeployCorrelationId } from "./deploy-correlation-diagnostic.mjs";
|
|
6
7
|
import { formatDeploymentOperationPhase } from "./deployment-operation-poll.mjs";
|
|
7
8
|
import { isPlatformUnavailableStatus, renderPlatformUnavailableLines } from "./deploy-platform-unavailable-diagnostic.mjs";
|
|
@@ -777,6 +778,7 @@ export function renderDeployFailureDiagnosticLines(responseBody, statusText, opt
|
|
|
777
778
|
"Retry policy: AFTER_FIX — Fix the schema/relations source, then deploy again; do not repeat this same deployment unchanged.",
|
|
778
779
|
);
|
|
779
780
|
}
|
|
781
|
+
const declarationWithoutDiagnosis = appendDeclarationFailureState(lines, contract, selfService);
|
|
780
782
|
const correlationLine = formatDeployCorrelationId(contract.correlationId);
|
|
781
783
|
if (correlationLine) lines.push(correlationLine);
|
|
782
784
|
appendRootCauseLines(
|
|
@@ -786,14 +788,12 @@ export function renderDeployFailureDiagnosticLines(responseBody, statusText, opt
|
|
|
786
788
|
? `gencow deploy status --deployment ${contract.operationId}`
|
|
787
789
|
: "gencow deploy status",
|
|
788
790
|
);
|
|
789
|
-
lines.push(
|
|
790
|
-
isCliUpgradeContract(contract)
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
: `Next action: ${contract.userAction}`,
|
|
797
|
-
);
|
|
791
|
+
lines.push(formatDeployFailureNextAction({
|
|
792
|
+
upgradeCli: isCliUpgradeContract(contract),
|
|
793
|
+
selfService,
|
|
794
|
+
sourceSchemaWithoutDiagnosis,
|
|
795
|
+
declarationWithoutDiagnosis,
|
|
796
|
+
userAction: contract.userAction,
|
|
797
|
+
}));
|
|
798
798
|
return lines;
|
|
799
799
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { formatLatestCliInvocation } from "./cli-update-guidance.mjs";
|
|
2
|
+
|
|
3
|
+
export function formatDeployFailureNextAction({
|
|
4
|
+
upgradeCli,
|
|
5
|
+
selfService,
|
|
6
|
+
sourceSchemaWithoutDiagnosis,
|
|
7
|
+
declarationWithoutDiagnosis,
|
|
8
|
+
userAction,
|
|
9
|
+
}) {
|
|
10
|
+
if (upgradeCli) return `Next command: ${formatLatestCliInvocation("deploy")}`;
|
|
11
|
+
if (selfService?.action.command) return `Next command: ${selfService.action.command}`;
|
|
12
|
+
if (sourceSchemaWithoutDiagnosis) return "Next command: gencow deploy logs (add --prod for production)";
|
|
13
|
+
if (declarationWithoutDiagnosis)
|
|
14
|
+
return "Next command: gencow deploy (after correcting the app source; add --prod for production)";
|
|
15
|
+
return `Next action: ${userAction}`;
|
|
16
|
+
}
|
|
@@ -57,9 +57,8 @@ import { writeCanonicalDeployBundle } from "./deploy-bundle-staging.mjs";
|
|
|
57
57
|
import { assertRuntimeAssetsWithinBackendRoot } from "./deploy-runtime-asset-audit.mjs";
|
|
58
58
|
import { formatBundleSummaryLines } from "./deploy-bundle-summary.mjs";
|
|
59
59
|
import { warnRuntimePathsOutsideBackendRoot } from "./deploy-runtime-path-audit.mjs";
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
60
|
+
import { createBackendCapabilityPreflight } from "./deploy-declaration-preflight.mjs";
|
|
61
|
+
export { isExplicitEmptyBackendApi } from "./deploy-declaration-preflight.mjs";
|
|
63
62
|
async function loadInternalToolingDefault() {
|
|
64
63
|
return loadToolingRuntime({
|
|
65
64
|
required: ["analyzerAudit"],
|
|
@@ -311,34 +310,10 @@ export function createDeployPackageRuntime({
|
|
|
311
310
|
}
|
|
312
311
|
return runMigrationGenerate();
|
|
313
312
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
existsSyncImpl,
|
|
319
|
-
readFileSyncImpl,
|
|
320
|
-
resolvePathImpl,
|
|
321
|
-
statSyncImpl,
|
|
322
|
-
warnImpl,
|
|
323
|
-
errorImpl,
|
|
324
|
-
loadConfigImpl,
|
|
325
|
-
throwOnInvalid: false,
|
|
326
|
-
});
|
|
327
|
-
const entryPoint = resolvePathImpl(cwd, resolveConfiguredBackendRoot(projectConfig), "index.ts");
|
|
328
|
-
if (!existsSyncImpl(entryPoint) || !isExplicitEmptyBackendApi(readFileSyncImpl(entryPoint, "utf8"))) {
|
|
329
|
-
return true;
|
|
330
|
-
}
|
|
331
|
-
errorImpl(
|
|
332
|
-
"Backend deploy stopped before upload because this project registers no query, mutation, or procedure.",
|
|
333
|
-
);
|
|
334
|
-
infoImpl("Code: BACKEND_CAPABILITY_EMPTY");
|
|
335
|
-
infoImpl("Stage: candidate");
|
|
336
|
-
infoImpl(`Correlation ID: deploy_${randomUUIDImpl()}`);
|
|
337
|
-
infoImpl("Next action: EDIT_AND_CHECK");
|
|
338
|
-
infoImpl("Add a backend procedure, or use gencow static <build-directory> for a frontend-only app.");
|
|
339
|
-
exitImpl(1);
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
313
|
+
const preflightBackendCapability = createBackendCapabilityPreflight({
|
|
314
|
+
cwdImpl, existsSyncImpl, readFileSyncImpl, resolvePathImpl, statSyncImpl, warnImpl,
|
|
315
|
+
errorImpl, loadConfigImpl, infoImpl, exitImpl, randomUUIDImpl,
|
|
316
|
+
});
|
|
342
317
|
async function packageDeployProject({
|
|
343
318
|
forceDeploy,
|
|
344
319
|
existingBundleMode = false,
|
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
|
}
|