gencow 0.1.289 → 0.1.291
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/db-push-command.mjs +7 -3
- package/lib/deploy-failure-diagnostic.mjs +13 -2
- package/lib/migration-operation-client.mjs +8 -2
- package/lib/migration-rollback-cause.mjs +8 -0
- package/lib/migration-status-input-error.mjs +47 -0
- package/lib/opencode-command.mjs +2 -2
- package/lib/opencode-config.mjs +16 -4
- package/package.json +4 -4
- package/runtime/server.mjs +690 -407
package/lib/db-push-command.mjs
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
withGenerationMetadataOutcome,
|
|
34
34
|
} from "./migration-client-diagnostic.mjs";
|
|
35
35
|
import { MIGRATION_HINTS_REQUIRED } from "./migration-hints.mjs";
|
|
36
|
+
import { emitMigrationStatusInputError } from "./migration-status-input-error.mjs";
|
|
36
37
|
import { detectConflictingAuthSchemaFiles, formatAuthSchemaConflictMessage } from "./codegen-command.mjs";
|
|
37
38
|
import { BOLD, CYAN, DIM, RESET } from "./output.mjs";
|
|
38
39
|
import { stageMigrationBundleArchive } from "./migration-bundle-staging.mjs";
|
|
@@ -266,9 +267,12 @@ function createDbMigrationCommand(deps, command) {
|
|
|
266
267
|
return;
|
|
267
268
|
}
|
|
268
269
|
|
|
269
|
-
if (statusReceiptId ===
|
|
270
|
-
|
|
271
|
-
|
|
270
|
+
if (statusReceiptId === "missing" || statusReceiptId === "invalid") {
|
|
271
|
+
failureEmitted = true;
|
|
272
|
+
emitMigrationStatusInputError(
|
|
273
|
+
statusReceiptId,
|
|
274
|
+
{ prod: args.includes("--prod"), jsonMode, correlationId: clientCorrelationId() },
|
|
275
|
+
deps,
|
|
272
276
|
);
|
|
273
277
|
return;
|
|
274
278
|
}
|
|
@@ -234,6 +234,17 @@ function appendRootCauseLines(lines, contract, statusCommand) {
|
|
|
234
234
|
);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
// body.diagnostic = { code, scope }: shown only when both values match these strict patterns, never echoed otherwise.
|
|
238
|
+
const DIAGNOSTIC_SCOPE_PATTERN = /^[a-z][a-z0-9_]{2,31}$/u;
|
|
239
|
+
const DIAGNOSTIC_CODE_PATTERNS = [/^[a-z][a-z0-9_]{2,63}$/u, /^[A-Z][A-Z0-9_]{2,99}$/u];
|
|
240
|
+
|
|
241
|
+
function readStructuredDiagnosticLines(responseBody) {
|
|
242
|
+
const { code, scope } = responseBody?.diagnostic ?? {};
|
|
243
|
+
if (typeof code !== "string" || typeof scope !== "string") return [];
|
|
244
|
+
if (!DIAGNOSTIC_SCOPE_PATTERN.test(scope) || !DIAGNOSTIC_CODE_PATTERNS.some((p) => p.test(code))) return [];
|
|
245
|
+
return [`Diagnostic: ${scope}/${code}`];
|
|
246
|
+
}
|
|
247
|
+
|
|
237
248
|
function safeText(value, maxLength) {
|
|
238
249
|
if (typeof value !== "string") return null;
|
|
239
250
|
const normalized = value.trim();
|
|
@@ -660,7 +671,7 @@ export function renderDeployFailureDiagnosticLines(responseBody, statusText, opt
|
|
|
660
671
|
const publicMessage = contract.legacySupportAction
|
|
661
672
|
? PLATFORM_STATUS_MESSAGE
|
|
662
673
|
: (safeText(responseBody.error, 240) ?? fallbackMessage);
|
|
663
|
-
const lines = [`Deploy failed: ${publicMessage}`, `Code: ${contract.code}`, `Stage: ${contract.stage}`];
|
|
674
|
+
const lines = [`Deploy failed: ${publicMessage}`, `Code: ${contract.code}`, ...readStructuredDiagnosticLines(responseBody), `Stage: ${contract.stage}`];
|
|
664
675
|
const phase = formatDeploymentOperationPhase(responseBody);
|
|
665
676
|
if (phase) lines.push(`Phase: ${phase}`);
|
|
666
677
|
const selfService = readSelfServiceDiagnostic(responseBody, contract, options.expectedAppName);
|
|
@@ -744,7 +755,7 @@ export function renderDeployFailureDiagnosticLines(responseBody, statusText, opt
|
|
|
744
755
|
? PLATFORM_STATUS_MESSAGE
|
|
745
756
|
: (safeText(responseBody.error, 240) ?? fallbackMessage);
|
|
746
757
|
const lines = [`Deploy failed: ${publicMessage}`];
|
|
747
|
-
lines.push(`Code: ${contract.code}`, `Stage: ${contract.stage}`);
|
|
758
|
+
lines.push(`Code: ${contract.code}`, ...readStructuredDiagnosticLines(responseBody), `Stage: ${contract.stage}`);
|
|
748
759
|
const selfService = readSelfServiceDiagnostic(responseBody, contract, options.expectedAppName);
|
|
749
760
|
appendSelfServiceState(lines, selfService);
|
|
750
761
|
if (isCliUpgradeContract(contract) && !selfService) {
|
|
@@ -12,10 +12,16 @@ export function isMigrationReceiptId(value) {
|
|
|
12
12
|
return typeof value === "string" && RECEIPT_ID.test(value);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
// Returns the receipt id, null when --status is absent, "missing" when no value follows it
|
|
16
|
+
// (or the next token is another flag), or "invalid" when the value is not a receipt id.
|
|
17
|
+
// Accepts both `--status <id>` and `--status=<id>`.
|
|
15
18
|
export function readMigrationStatusReceiptId(args) {
|
|
19
|
+
const inline = args.find((arg) => arg.startsWith("--status="));
|
|
16
20
|
const index = args.indexOf("--status");
|
|
17
|
-
if (index < 0) return null;
|
|
18
|
-
|
|
21
|
+
if (inline === undefined && index < 0) return null;
|
|
22
|
+
const value = inline !== undefined ? inline.slice("--status=".length) : args[index + 1];
|
|
23
|
+
if (value === undefined || value === "" || value.startsWith("--")) return "missing";
|
|
24
|
+
return isMigrationReceiptId(value) ? value : "invalid";
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
export function buildMigrationStatusCommand({ appId, environment, receiptId, jsonMode }) {
|
|
@@ -21,6 +21,10 @@ const USER_FIXABLE_CAUSES = new Map([
|
|
|
21
21
|
"PostgreSQL does not allow this construct in the statement (for example a bare word instead of a quoted string, a subquery, or a column reference in a DEFAULT)",
|
|
22
22
|
],
|
|
23
23
|
["datatype_mismatch", "a DEFAULT value does not match the column's data type"],
|
|
24
|
+
[
|
|
25
|
+
"foreign_key_type_mismatch",
|
|
26
|
+
"a FOREIGN KEY column's type differs from the referenced column's type",
|
|
27
|
+
],
|
|
24
28
|
["undefined_function", "the statement calls a function that does not exist"],
|
|
25
29
|
["undefined_object", "the statement uses a type that does not exist"],
|
|
26
30
|
]);
|
|
@@ -52,6 +56,10 @@ const TYPE_REASON_CAUSES = new Map([
|
|
|
52
56
|
"datatype_mismatch",
|
|
53
57
|
"A DEFAULT value type does not match its column: use a value of the column's declared type.",
|
|
54
58
|
],
|
|
59
|
+
[
|
|
60
|
+
"foreign_key_type_mismatch",
|
|
61
|
+
"A FOREIGN KEY column type differs from the type of the column it references: make both columns the same type in gencow/schema.ts.",
|
|
62
|
+
],
|
|
55
63
|
[
|
|
56
64
|
"undefined_function",
|
|
57
65
|
"The statement calls a function that does not exist in this database: correct the function name or remove it from the DEFAULT.",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Input error for `db:push --status` when the receipt id is absent or malformed.
|
|
2
|
+
// It is a local argument check: no project config, login, network call or database state is involved,
|
|
3
|
+
// so it is not a migration diagnostic and does not go through the migration contract.
|
|
4
|
+
export const MIGRATION_STATUS_RECEIPT_REQUIRED = "MIGRATION_STATUS_RECEIPT_REQUIRED";
|
|
5
|
+
export const MIGRATION_STATUS_RECEIPT_INVALID = "MIGRATION_STATUS_RECEIPT_INVALID";
|
|
6
|
+
|
|
7
|
+
const RETRY_CONDITION = "rerun with a receipt id";
|
|
8
|
+
const RECEIPT_HINT =
|
|
9
|
+
"Use the Receipt: line printed by the earlier db:push, or receipt.receiptId in its --json output.";
|
|
10
|
+
|
|
11
|
+
// kind: "missing" (no value, or the next token is another flag) or "invalid" (value is not a receipt id).
|
|
12
|
+
// Prints the JSON object (--json) or the plain-text lines through the command's output sinks.
|
|
13
|
+
export function emitMigrationStatusInputError(kind, { prod, jsonMode, correlationId }, { logImpl, errorImpl }) {
|
|
14
|
+
const missing = kind === "missing";
|
|
15
|
+
const code = missing ? MIGRATION_STATUS_RECEIPT_REQUIRED : MIGRATION_STATUS_RECEIPT_INVALID;
|
|
16
|
+
const nextCommand = `gencow db:push${prod ? " --prod" : ""} --status <receipt-id>`;
|
|
17
|
+
if (jsonMode) {
|
|
18
|
+
logImpl(
|
|
19
|
+
JSON.stringify({
|
|
20
|
+
ok: false,
|
|
21
|
+
code,
|
|
22
|
+
failureClass: "USER_FIXABLE",
|
|
23
|
+
phase: "PREFLIGHT",
|
|
24
|
+
databaseState: "UNCHANGED",
|
|
25
|
+
safeToRetryNow: true,
|
|
26
|
+
retryCondition: RETRY_CONDITION,
|
|
27
|
+
nextCommand,
|
|
28
|
+
receiptHint: RECEIPT_HINT,
|
|
29
|
+
correlationId,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const title = missing ? "Migration status needs a receipt id" : "Migration status receipt id is invalid";
|
|
35
|
+
errorImpl(`✗ ${title}`);
|
|
36
|
+
[
|
|
37
|
+
"",
|
|
38
|
+
`Code: ${code}`,
|
|
39
|
+
"Phase: PREFLIGHT",
|
|
40
|
+
"Database state: UNCHANGED",
|
|
41
|
+
"Safe to retry now: YES",
|
|
42
|
+
`Retry condition: ${RETRY_CONDITION}`,
|
|
43
|
+
`Next: ${nextCommand}`,
|
|
44
|
+
`Receipt: ${RECEIPT_HINT}`,
|
|
45
|
+
`Correlation: ${correlationId}`,
|
|
46
|
+
].forEach((line) => logImpl(line));
|
|
47
|
+
}
|
package/lib/opencode-command.mjs
CHANGED
|
@@ -140,8 +140,8 @@ export function createOpencodeCommands(overrides = {}) {
|
|
|
140
140
|
if (hasKeyFileRef(paths)) {
|
|
141
141
|
return { ok: true, code: "ALREADY_CONFIGURED", changed: false, model: `gencow/${GENCOW_MODEL_ID}`, expiresAt: state.expiresAt };
|
|
142
142
|
}
|
|
143
|
-
// A setup from an older CLI
|
|
144
|
-
//
|
|
143
|
+
// A setup from an older CLI lacks the key-file reference (OpenCode Desktop ignores auth.json) or the output
|
|
144
|
+
// limit. The token is still valid, so rewrite the provider block without minting or revoking anything.
|
|
145
145
|
applyOpencodeEdits({ paths, plan: planOpencodeEdits({ paths, baseURL, apiKey: existingKey }) });
|
|
146
146
|
return { ok: true, code: "CONFIGURED", changed: true, repaired: true, model: `gencow/${GENCOW_MODEL_ID}`, expiresAt: state.expiresAt };
|
|
147
147
|
}
|
package/lib/opencode-config.mjs
CHANGED
|
@@ -16,6 +16,12 @@ export const GENCOW_MODEL_ID = "llm/code";
|
|
|
16
16
|
* its own credential store (opencode.db) and ignores auth.json, so a config reference is the one channel both
|
|
17
17
|
* Desktop and the CLI read (verified: Desktop on macOS, CLI 1.19.5 and a current dev build).
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* Without an explicit limit OpenCode Desktop sends no max_tokens, and the gateway then cut every turn at its
|
|
21
|
+
* 5,000-token default (a 13-15KB file write ended mid tool call). 32,000 output matches what the OpenCode CLI sends;
|
|
22
|
+
* 272,000 is the context threshold the gateway already uses for the GPT-6 family.
|
|
23
|
+
*/
|
|
24
|
+
export const GENCOW_MODEL_LIMIT = { context: 272000, output: 32000 };
|
|
19
25
|
export const GENCOW_KEY_FILE_REF = "{file:~/.gencow/opencode.key}";
|
|
20
26
|
|
|
21
27
|
export class OpencodeSetupError extends Error {
|
|
@@ -129,7 +135,7 @@ export function gencowProviderConfig(baseURL) {
|
|
|
129
135
|
npm: "@ai-sdk/openai-compatible",
|
|
130
136
|
name: "Gencow",
|
|
131
137
|
options: { baseURL, apiKey: GENCOW_KEY_FILE_REF },
|
|
132
|
-
models: { [GENCOW_MODEL_ID]: { name: "Gencow Code" } },
|
|
138
|
+
models: { [GENCOW_MODEL_ID]: { name: "Gencow Code", limit: { ...GENCOW_MODEL_LIMIT } } },
|
|
133
139
|
};
|
|
134
140
|
}
|
|
135
141
|
|
|
@@ -236,11 +242,17 @@ export function hasGencowProvider(paths) {
|
|
|
236
242
|
});
|
|
237
243
|
}
|
|
238
244
|
|
|
239
|
-
/** True when the provider block
|
|
245
|
+
/** True when the provider block is the current shape: key-file reference, existing key file, and the output limit. */
|
|
240
246
|
export function hasKeyFileRef(paths) {
|
|
241
247
|
const text = readText(paths.configJson);
|
|
242
|
-
const
|
|
243
|
-
|
|
248
|
+
const provider = text ? parseJsonc(text)?.value?.provider?.[GENCOW_PROVIDER_ID] : null;
|
|
249
|
+
const limit = provider?.models?.[GENCOW_MODEL_ID]?.limit;
|
|
250
|
+
return (
|
|
251
|
+
provider?.options?.apiKey === GENCOW_KEY_FILE_REF &&
|
|
252
|
+
limit?.output === GENCOW_MODEL_LIMIT.output &&
|
|
253
|
+
limit?.context === GENCOW_MODEL_LIMIT.context &&
|
|
254
|
+
Boolean(readText(paths.keyFile)?.trim())
|
|
255
|
+
);
|
|
244
256
|
}
|
|
245
257
|
|
|
246
258
|
export function hasGencowKey(authJsonPath) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gencow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.291",
|
|
4
4
|
"description": "Gencow — AI Backend Engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"ai": "^6.0.326",
|
|
41
41
|
"better-auth": "1.7.11",
|
|
42
42
|
"postgres": "^3.4.9",
|
|
43
|
-
"@gencow/client": "0.2.8",
|
|
44
43
|
"@gencow/core": "0.1.48",
|
|
44
|
+
"@gencow/client": "0.2.8",
|
|
45
45
|
"@gencow/react": "0.2.8",
|
|
46
|
-
"@gencow/
|
|
47
|
-
"@gencow/
|
|
46
|
+
"@gencow/server": "0.1.3",
|
|
47
|
+
"@gencow/shared": "0.0.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-server.mjs",
|