@runa-ai/runa-cli 0.7.3 → 0.9.0

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.
Files changed (116) hide show
  1. package/dist/{build-HQMSVN6N.js → build-P2A6345N.js} +2 -2
  2. package/dist/{check-PCSQPYDM.js → check-4TZHNOZU.js} +4 -4
  3. package/dist/{chunk-DRSUEMAK.js → chunk-B7C7CLW2.js} +2 -5
  4. package/dist/{chunk-B3POLMII.js → chunk-BQ336L5T.js} +1 -1
  5. package/dist/{chunk-6FAU4IGR.js → chunk-ELXXQIGW.js} +4 -1
  6. package/dist/{chunk-FWMGC5FP.js → chunk-EXR4J2JT.js} +289 -16
  7. package/dist/{chunk-AO554K3G.js → chunk-GKBE7EIE.js} +1 -1
  8. package/dist/{chunk-JMJP4A47.js → chunk-GT5DMS5R.js} +20 -2
  9. package/dist/{chunk-3JO6YP3T.js → chunk-IEKYTCYA.js} +1 -1
  10. package/dist/{chunk-WPMR7RQ4.js → chunk-IWVXI5O4.js} +2 -2
  11. package/dist/chunk-KUH3G522.js +72 -0
  12. package/dist/{chunk-VSH3IXDQ.js → chunk-MAFJAA2P.js} +1 -1
  13. package/dist/{chunk-CCKG5R4Y.js → chunk-MILCC3B6.js} +1 -1
  14. package/dist/{chunk-5NKWR4FF.js → chunk-OERS32LW.js} +1 -1
  15. package/dist/{chunk-2QX7T24B.js → chunk-QKGL6Q2S.js} +1 -1
  16. package/dist/{chunk-OBYZDT2E.js → chunk-URWDB7YL.js} +15 -78
  17. package/dist/{chunk-CKRLVEIO.js → chunk-WGRVAGSR.js} +16 -11
  18. package/dist/chunk-YRNQEJQW.js +9043 -0
  19. package/dist/chunk-ZWDWFMOX.js +1514 -0
  20. package/dist/{ci-Z4525QW6.js → ci-S5KSBECX.js} +1226 -1207
  21. package/dist/{cli-SVXOSMW6.js → cli-TJZCAMB2.js} +30 -30
  22. package/dist/commands/ci/commands/ci-prod-db-operations.d.ts +12 -17
  23. package/dist/commands/ci/commands/ci-prod-utils.d.ts +7 -0
  24. package/dist/commands/ci/commands/ci-resolvers.d.ts +1 -2
  25. package/dist/commands/ci/commands/layer4-discovery.d.ts +2 -0
  26. package/dist/commands/ci/machine/actors/db/production-preview.d.ts +4 -3
  27. package/dist/commands/ci/machine/actors/db/sync-schema.d.ts +5 -1
  28. package/dist/commands/ci/machine/actors/setup/pr-common.d.ts +1 -1
  29. package/dist/commands/ci/machine/actors/test/capabilities.d.ts +2 -13
  30. package/dist/commands/ci/machine/actors/test/index.d.ts +1 -0
  31. package/dist/commands/ci/machine/actors/test/layer-content.d.ts +11 -0
  32. package/dist/commands/ci/machine/commands/ci-pr-internal-profile.d.ts +7 -0
  33. package/dist/commands/ci/machine/commands/ci-step-registry.d.ts +25 -0
  34. package/dist/commands/ci/machine/commands/step-telemetry.d.ts +1 -2
  35. package/dist/commands/ci/machine/contract.d.ts +9 -1
  36. package/dist/commands/ci/machine/guards.d.ts +19 -10
  37. package/dist/commands/ci/machine/helpers.d.ts +1 -1
  38. package/dist/commands/ci/machine/machine-execution-helpers.d.ts +5 -2
  39. package/dist/commands/ci/machine/machine.d.ts +34 -32
  40. package/dist/commands/ci/machine/selectors.d.ts +6 -0
  41. package/dist/commands/ci/machine/types.d.ts +3 -1
  42. package/dist/commands/ci/utils/ci-logging.d.ts +16 -0
  43. package/dist/commands/ci/utils/rls-verification.d.ts +3 -2
  44. package/dist/commands/db/apply/actors/pg-schema-diff-actors.d.ts +1 -0
  45. package/dist/commands/db/apply/actors/seed-actors.d.ts +1 -0
  46. package/dist/commands/db/apply/contract.d.ts +232 -0
  47. package/dist/commands/db/apply/helpers/fresh-db-handler.d.ts +3 -1
  48. package/dist/commands/db/apply/helpers/hazard-handler.d.ts +19 -8
  49. package/dist/commands/db/apply/helpers/index.d.ts +5 -2
  50. package/dist/commands/db/apply/helpers/no-change-plan.d.ts +2 -0
  51. package/dist/commands/db/apply/helpers/plan-ast-sql-helpers.d.ts +19 -0
  52. package/dist/commands/db/apply/helpers/plan-ast.d.ts +1 -2
  53. package/dist/commands/db/apply/helpers/plan-check-filter.d.ts +11 -14
  54. package/dist/commands/db/apply/helpers/plan-validator.d.ts +34 -0
  55. package/dist/commands/db/apply/helpers/planner-artifact.d.ts +65 -0
  56. package/dist/commands/db/apply/helpers/retry-logic.d.ts +5 -0
  57. package/dist/commands/db/apply/machine.d.ts +100 -14
  58. package/dist/commands/db/commands/db-apply-error.d.ts +6 -1
  59. package/dist/commands/db/commands/db-apply.d.ts +5 -0
  60. package/dist/commands/db/commands/db-plan.d.ts +3 -0
  61. package/dist/commands/db/commands/db-preview-profile.d.ts +23 -0
  62. package/dist/commands/db/commands/db-preview.d.ts +3 -0
  63. package/dist/commands/db/sync/actors.d.ts +1 -0
  64. package/dist/commands/db/sync/contract.d.ts +16 -0
  65. package/dist/commands/db/sync/guardrail-orchestrator.d.ts +15 -0
  66. package/dist/commands/db/sync/guardrail-reporting.d.ts +12 -0
  67. package/dist/commands/db/sync/index.d.ts +4 -0
  68. package/dist/commands/db/sync/machine.d.ts +18 -13
  69. package/dist/commands/db/sync/schema-guardrail-config-test-support.d.ts +15 -0
  70. package/dist/commands/db/sync/schema-guardrail-config.d.ts +11 -0
  71. package/dist/commands/db/sync/schema-guardrail-ddl-order.d.ts +36 -0
  72. package/dist/commands/db/sync/schema-guardrail-graph-guidance.d.ts +15 -0
  73. package/dist/commands/db/sync/schema-guardrail-graph-metadata.d.ts +41 -0
  74. package/dist/commands/db/sync/schema-guardrail-graph-nodes.d.ts +61 -0
  75. package/dist/commands/db/sync/schema-guardrail-graph-sql-helpers.d.ts +31 -0
  76. package/dist/commands/db/sync/schema-guardrail-graph-types.d.ts +56 -0
  77. package/dist/commands/db/sync/schema-guardrail-graph.d.ts +20 -0
  78. package/dist/commands/db/sync/schema-guardrail-local-blockers.d.ts +7 -0
  79. package/dist/commands/db/sync/schema-guardrail-phases.d.ts +26 -0
  80. package/dist/commands/db/sync/schema-guardrail-production-check.d.ts +23 -0
  81. package/dist/commands/db/sync/schema-guardrail-rewrite.d.ts +46 -0
  82. package/dist/commands/db/sync/schema-guardrail-runtime.d.ts +5 -0
  83. package/dist/commands/db/sync/schema-guardrail-semantic-warnings.d.ts +9 -0
  84. package/dist/commands/db/sync/schema-guardrail-types.d.ts +243 -0
  85. package/dist/commands/db/sync/schema-guardrail.d.ts +10 -0
  86. package/dist/commands/db/utils/declarative-dependency-sql-utils.d.ts +1 -1
  87. package/dist/commands/db/utils/duplicate-function-ownership.d.ts +61 -0
  88. package/dist/commands/db/utils/plan-size-guard.d.ts +16 -0
  89. package/dist/commands/db/utils/policy-cross-schema-refs.d.ts +12 -0
  90. package/dist/commands/db/utils/preflight-checks/duplicate-function-ownership-checks.d.ts +4 -0
  91. package/dist/commands/db/utils/sql-table-extractor.d.ts +6 -0
  92. package/dist/commands/test/commands/layer4-prereqs.d.ts +15 -0
  93. package/dist/{config-loader-GT3HAQ7U.js → config-loader-N5ODNMD5.js} +2 -2
  94. package/dist/db-D2OLJDYW.js +12757 -0
  95. package/dist/{dev-MLRKIP7F.js → dev-LGSMDFJN.js} +7 -6
  96. package/dist/{doctor-ROSWSMLH.js → doctor-GYX73IEW.js} +4 -4
  97. package/dist/{env-WNHJVLOT.js → env-KYR6Q7WO.js} +15 -10
  98. package/dist/{env-files-HRNUGZ5O.js → env-files-ONBC47I6.js} +3 -3
  99. package/dist/{hotfix-Z5EGVSMH.js → hotfix-RJIAPLAM.js} +4 -4
  100. package/dist/index.js +3 -3
  101. package/dist/{init-35JLDFHI.js → init-2O6ODG5Z.js} +2 -2
  102. package/dist/{inject-test-attrs-XN4I2AOR.js → inject-test-attrs-F5A346UV.js} +3 -3
  103. package/dist/{manifest-EGCAZ4TK.js → manifest-CI4BRWEB.js} +2 -2
  104. package/dist/{observability-CJA5UFIC.js → observability-WNSCJ5FV.js} +2 -2
  105. package/dist/pg-schema-diff-helpers-7377FS2D.js +7 -0
  106. package/dist/{sdk-XK6HQU7S.js → sdk-BTIVPEE5.js} +1 -1
  107. package/dist/{test-V4KQL574.js → test-QCPN6Z47.js} +74 -46
  108. package/dist/{upgrade-7L4JIE4K.js → upgrade-QZKEI3NJ.js} +2 -2
  109. package/dist/utils/db-url-utils.d.ts +4 -77
  110. package/dist/{vuln-check-D575VXIQ.js → vuln-check-5NUTETPW.js} +1 -1
  111. package/dist/{vuln-checker-QV6XODTJ.js → vuln-checker-UV342N66.js} +1 -1
  112. package/dist/{watch-AL4LCBRM.js → watch-RFVCEQLH.js} +3 -3
  113. package/dist/{workflow-UZIZ2JUS.js → workflow-UOG6ZZMH.js} +3 -3
  114. package/package.json +3 -3
  115. package/dist/chunk-4XHZQRRK.js +0 -215
  116. package/dist/db-S4V4ETDR.js +0 -17556
@@ -0,0 +1,19 @@
1
+ export declare function stripLeadingSetStatements(sql: string): string;
2
+ export declare function extractStringValue(node: Record<string, unknown> | undefined): string | undefined;
3
+ export declare function readIdentifierList(items: unknown[] | undefined): string[];
4
+ export declare function qualifyName(parts: readonly string[], fallbackSchema?: string): string | null;
5
+ export declare function rangeVarToQualifiedName(node: Record<string, unknown> | undefined): string | null;
6
+ export declare function relationRecordToQualifiedName(record: Record<string, unknown> | undefined): string | null;
7
+ export declare function optionDefElems(options: unknown[] | undefined): Array<Record<string, unknown>>;
8
+ export declare function walkPgNode(node: unknown, visit: (record: Record<string, unknown>) => void): void;
9
+ export declare function collectReferencedRelations(node: unknown, exclude: ReadonlySet<string>): string[];
10
+ export declare function collectFunctionNames(node: unknown): string[];
11
+ export declare function normalizeDbProconfig(entries: string[]): string;
12
+ export declare function extractFunctionConfigFromSql(sql: string): string;
13
+ export declare function extractFunctionOptions(createFunction: Record<string, unknown>): {
14
+ language: string;
15
+ body: string;
16
+ config: string;
17
+ };
18
+ export declare function extractFunctionIdentity(createFunction: Record<string, unknown>): string | null;
19
+ //# sourceMappingURL=plan-ast-sql-helpers.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import type { PlanStatement, ValidatedPlan } from './plan-validator.js';
2
+ export { stripLeadingSetStatements } from './plan-ast-sql-helpers.js';
2
3
  export type PlanObjectKind = 'schema' | 'relation' | 'function' | 'function-privilege' | 'type' | 'other';
3
4
  export interface AnalyzedPlanStatement {
4
5
  statement: PlanStatement;
@@ -41,7 +42,6 @@ export interface PlanAnalysisSession {
41
42
  analyzePlpgsqlBody(body: string): Promise<CachedPlpgsqlBodyAnalysis>;
42
43
  }
43
44
  export declare function createPlanAnalysisSession(): PlanAnalysisSession;
44
- export declare function stripLeadingSetStatements(sql: string): string;
45
45
  export declare function analyzePlanStatement(statement: PlanStatement, session?: PlanAnalysisSession): Promise<AnalyzedPlanStatement>;
46
46
  export declare function analyzeValidatedPlan(plan: ValidatedPlan, session?: PlanAnalysisSession): Promise<AnalyzedPlan>;
47
47
  export declare function stabilizeAnalyzedPlanOrder(analyzedPlan: AnalyzedPlan): {
@@ -52,5 +52,4 @@ export declare function normalizeFunctionDefinitionAst(analyzed: Pick<AnalyzedPl
52
52
  normalizedDefinition: string;
53
53
  normalizedConfig: string;
54
54
  } | null;
55
- export {};
56
55
  //# sourceMappingURL=plan-ast.d.ts.map
@@ -1,26 +1,23 @@
1
+ import type { DbApplyPlanSummary } from '../contract.js';
1
2
  import type { IdempotentProtectedObjects } from './idempotent-object-registry.js';
2
3
  import type { PlanStatement, ValidatedPlan } from './plan-validator.js';
3
4
  export interface CheckModeFilterResult {
4
5
  filteredPlan: ValidatedPlan;
5
6
  removedDropStatements: PlanStatement[];
6
7
  removedAuthzStatements: PlanStatement[];
8
+ removedRlsStatements: PlanStatement[];
7
9
  }
8
- declare function parseRolesFromAuthzStatement(sql: string): string[];
9
10
  export declare function stripLeadingSessionStatements(sql: string): string;
10
- type AuthzTarget = {
11
- kind: 'function';
12
- schema: string;
13
- fullName: string;
14
- } | {
15
- kind: 'schema' | 'sequence' | 'table';
16
- schema: string;
17
- fullName: string;
18
- } | null;
19
- declare function parseAuthzTarget(sql: string): AuthzTarget;
20
11
  export declare function isIdempotentManagedAuthzStatement(sql: string, schemasDir?: string): boolean;
12
+ export declare function isIdempotentManagedRlsStatement(sql: string, schemasDir?: string): boolean;
21
13
  export declare function filterCheckModePlanStatements(plan: ValidatedPlan, protectedTables: string[], protectedObjects: IdempotentProtectedObjects, schemasDir?: string): CheckModeFilterResult;
14
+ export declare function buildCheckModePlanSummary(params: {
15
+ rawStatementCount: number;
16
+ filteredPlan: ValidatedPlan;
17
+ removedDropStatements: readonly PlanStatement[];
18
+ removedAuthzStatements: readonly PlanStatement[];
19
+ removedRlsStatements: readonly PlanStatement[];
20
+ suppressedFunctionStatements?: readonly PlanStatement[];
21
+ }): DbApplyPlanSummary;
22
22
  export declare function resetManagedAuthzCache(): void;
23
- export declare const _parseRolesFromAuthzStatement: typeof parseRolesFromAuthzStatement;
24
- export declare const _parseAuthzTarget: typeof parseAuthzTarget;
25
- export {};
26
23
  //# sourceMappingURL=plan-check-filter.d.ts.map
@@ -90,6 +90,40 @@ export declare function validateStatementTypes(plan: ValidatedPlan): void;
90
90
  * @throws Error if unresolved hazards are found
91
91
  */
92
92
  export declare function validatePlanForExecution(plan: ValidatedPlan, allowedHazardTypes: string[]): void;
93
+ /**
94
+ * Validate that plan SQL doesn't have ALTER POLICY referencing a function
95
+ * that is CREATE'd later in the same plan.
96
+ *
97
+ * This catches pg-schema-diff ordering bugs where ALTER POLICY (phase 50)
98
+ * is emitted before CREATE FUNCTION (phase 60), causing "function does not exist"
99
+ * errors at execution time.
100
+ *
101
+ * Called during plan generation (check mode) so issues are caught before deploy.
102
+ */
103
+ /**
104
+ * Validate dependency order from raw SQL string.
105
+ * More reliable than ValidatedPlan-based check because it works regardless
106
+ * of how parsePlanOutput splits statements (marker-based vs SET-based).
107
+ */
108
+ export declare function validateDependencyOrderFromRawSql(rawSql: string): string[];
109
+ /**
110
+ * Reorder raw plan SQL to fix ALTER POLICY before CREATE FUNCTION ordering.
111
+ *
112
+ * Moves policy chunks that reference functions created later in the plan
113
+ * to after those function definitions. This is the actual fix that makes
114
+ * deploy succeed, not just detection.
115
+ */
116
+ export declare function reorderRawSqlDependencies(rawSql: string): {
117
+ sql: string;
118
+ reordered: boolean;
119
+ movedCount: number;
120
+ };
121
+ export declare function validateDependencyOrder(plan: ValidatedPlan): string[];
122
+ /**
123
+ * Determine whether pg-schema-diff plan output represents "no changes needed".
124
+ * Returns true if the output is empty, contains "No changes", or has zero statements.
125
+ */
126
+ export declare function isNoChangePlanOutput(planOutput: string): boolean;
93
127
  export type { FilterResult } from './plan-drop-protection.js';
94
128
  export { filterIdempotentProtectedStatements, isDropStatementForProtectedObject, _isDropStatementForProtected, _extractProtectedSchemas, _isDropSchemaForProtected, } from './plan-drop-protection.js';
95
129
  //# sourceMappingURL=plan-validator.d.ts.map
@@ -0,0 +1,65 @@
1
+ import { z } from 'zod';
2
+ import { type RunaDbEnv } from '../../utils/db-target.js';
3
+ import { type DbApplyInput, type DbApplyOutput, type DbApplyPlanner } from '../contract.js';
4
+ export declare const DbPlanArtifactSchema: z.ZodObject<{
5
+ version: z.ZodLiteral<"1">;
6
+ environment: z.ZodEnum<{
7
+ local: "local";
8
+ preview: "preview";
9
+ production: "production";
10
+ }>;
11
+ mode: z.ZodLiteral<"check">;
12
+ previewProfile: z.ZodEnum<{
13
+ full: "full";
14
+ "compare-only": "compare-only";
15
+ }>;
16
+ createdAt: z.ZodString;
17
+ hasChanges: z.ZodBoolean;
18
+ planSql: z.ZodString;
19
+ filteredPlanSql: z.ZodString;
20
+ planSummary: z.ZodOptional<z.ZodObject<{
21
+ rawStatements: z.ZodNumber;
22
+ effectiveStatements: z.ZodNumber;
23
+ noiseStatements: z.ZodNumber;
24
+ categories: z.ZodObject<{
25
+ idempotentDrop: z.ZodNumber;
26
+ idempotentAuthz: z.ZodNumber;
27
+ idempotentRls: z.ZodNumber;
28
+ suppressedFunction: z.ZodNumber;
29
+ }, z.core.$strict>;
30
+ }, z.core.$strict>>;
31
+ hazards: z.ZodArray<z.ZodString>;
32
+ sourceFingerprint: z.ZodString;
33
+ targetFingerprint: z.ZodString;
34
+ toolMetadata: z.ZodObject<{
35
+ cliVersion: z.ZodString;
36
+ pgSchemaDiffVersion: z.ZodOptional<z.ZodString>;
37
+ nodeVersion: z.ZodString;
38
+ }, z.core.$strict>;
39
+ }, z.core.$strict>;
40
+ export type DbPlanArtifact = z.infer<typeof DbPlanArtifactSchema>;
41
+ export declare function detectPlannerSchemas(repoRoot: string): string[];
42
+ export declare function buildTargetFingerprint(params: {
43
+ databaseUrl: string;
44
+ includeSchemas: string[];
45
+ }): string;
46
+ export declare function getDbPlanArtifactPath(params: {
47
+ repoRoot: string;
48
+ environment: RunaDbEnv;
49
+ previewProfile: 'compare-only' | 'full';
50
+ }): string;
51
+ export declare function persistDbPlanArtifact(params: {
52
+ repoRoot: string;
53
+ input: Pick<DbApplyInput, 'env' | 'check' | 'compareOnly' | 'databaseUrl'>;
54
+ output: Pick<DbApplyOutput, 'planSql' | 'filteredPlanSql' | 'planSummary' | 'hazards'>;
55
+ }): DbApplyPlanner;
56
+ export declare function tryReuseDbPlanArtifact(params: {
57
+ repoRoot: string;
58
+ artifactPath: string;
59
+ input: Pick<DbApplyInput, 'env' | 'databaseUrl'>;
60
+ precomputedTargetFingerprint?: string;
61
+ }): {
62
+ artifact: DbPlanArtifact | null;
63
+ planner: DbApplyPlanner;
64
+ };
65
+ //# sourceMappingURL=planner-artifact.d.ts.map
@@ -84,6 +84,11 @@ export interface PlanSqlRetryConfig extends RetryConfig {
84
84
  * Recommended for production to avoid executing ambiguous SQL plans.
85
85
  */
86
86
  failOnLowParseConfidence?: boolean;
87
+ /**
88
+ * Fail immediately when a retryable lock error occurs but re-planning is not allowed.
89
+ * Used by checked planner artifact reuse to avoid replaying stale SQL after partial execution.
90
+ */
91
+ retryRequiresReplanMessage?: string;
87
92
  }
88
93
  /**
89
94
  * Execute plan SQL via psql with retry logic.
@@ -1,10 +1,44 @@
1
+ /**
2
+ * AI HINT: db apply State Machine (Declarative Schema Management)
3
+ *
4
+ * Purpose: Orchestrate schema application to any DB (local, Branch DB, Production)
5
+ *
6
+ * User Journey (2-pass idempotent):
7
+ * 1. Apply idempotent schemas (1st pass: extensions, roles - may skip dependent tables)
8
+ * 2. Run pg-schema-diff (current DB → desired state)
9
+ * 3. Apply idempotent schemas (2nd pass: dependent tables now succeed)
10
+ * 4. Validate partitions (non-blocking drift detection)
11
+ * 5. Apply seeds
12
+ *
13
+ * Why 2-pass idempotent?
14
+ * - Some idempotent SQL depends on declarative tables (e.g., areas → floors)
15
+ * - 1st pass: extensions/roles succeed, dependent tables are skipped (no error)
16
+ * - 2nd pass: dependent tables succeed because declarative tables now exist
17
+ *
18
+ * Architecture:
19
+ * - No migration files needed
20
+ * - pg-schema-diff runs at runtime against actual DB state
21
+ * - Same logic for all environments
22
+ *
23
+ * E2E Test Mapping (CLI observable behavior):
24
+ * - idle → expect(log).toContain('Starting db apply')
25
+ * - applyingIdempotentPre → expect(log).toContain('Applied idempotent schema')
26
+ * - applyingPgSchemaDiff → expect(log).toContain('pg-schema-diff')
27
+ * - applyingIdempotentPost → expect(log).toContain('Applied idempotent schema')
28
+ * - validatingPartitions → expect(log).toContain('partition')
29
+ * - applyingSeeds → expect(log).toContain('Applying seeds')
30
+ * - done → expect(exitCode).toBe(0)
31
+ * - failed → expect(exitCode).toBe(1)
32
+ */
33
+ import { type CommandWarning } from '@runa-ai/runa';
1
34
  import { type SnapshotFrom } from 'xstate';
2
35
  import * as actors from './actors.js';
3
- import type { DbApplyInput } from './contract.js';
36
+ import type { DbApplyInput, DbApplyPlanner, DbApplyPlanSummary } from './contract.js';
4
37
  interface DbApplyContext {
5
38
  input: DbApplyInput;
6
39
  targetDir: string;
7
40
  lockAcquired: boolean;
41
+ preIdempotentTargetFingerprint: string | null;
8
42
  idempotentPreApplied: number;
9
43
  idempotentPreSkipped: number;
10
44
  idempotentPostApplied: number;
@@ -18,7 +52,10 @@ interface DbApplyContext {
18
52
  error: string | null;
19
53
  planSql: string | null;
20
54
  filteredPlanSql: string | null;
55
+ planSummary: DbApplyPlanSummary | null;
56
+ planner: DbApplyPlanner | null;
21
57
  ssotWarning: string | null;
58
+ nonCriticalWarnings: CommandWarning[];
22
59
  idempotentFiles: string[];
23
60
  idempotentRisks: {
24
61
  high: number;
@@ -35,7 +72,14 @@ interface DbApplyContext {
35
72
  seedStartTime: number | null;
36
73
  seedEndTime: number | null;
37
74
  retryAttempts: number;
75
+ retryWaitMs: number;
38
76
  }
77
+ interface DbApplyFailureMetadata {
78
+ code: string;
79
+ retryable: boolean;
80
+ }
81
+ export declare function classifyDbApplyFailure(errorMessage: string): DbApplyFailureMetadata;
82
+ export declare function createMachineWarning(code: string, message: string, phase: string): CommandWarning;
39
83
  export declare const dbApplyMachine: import("xstate").StateMachine<DbApplyContext, {
40
84
  type: "START";
41
85
  } | {
@@ -43,11 +87,6 @@ export declare const dbApplyMachine: import("xstate").StateMachine<DbApplyContex
43
87
  error: Error;
44
88
  }, {
45
89
  [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
46
- applied: boolean;
47
- }, {
48
- input: DbApplyInput;
49
- targetDir: string;
50
- }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
51
90
  acquired: boolean;
52
91
  }, {
53
92
  input: DbApplyInput;
@@ -63,22 +102,23 @@ export declare const dbApplyMachine: import("xstate").StateMachine<DbApplyContex
63
102
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<actors.PgSchemaDiffResult, {
64
103
  input: DbApplyInput;
65
104
  targetDir: string;
105
+ preIdempotentTargetFingerprint?: string | null;
66
106
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
67
107
  warnings: string[];
68
108
  }, {
69
109
  input: DbApplyInput;
70
110
  targetDir: string;
71
- }, import("xstate").EventObject>> | undefined;
72
- }, {
73
- src: "applySeeds";
74
- logic: import("xstate").PromiseActorLogic<{
111
+ }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
75
112
  applied: boolean;
113
+ warnings: string[];
76
114
  }, {
77
115
  input: DbApplyInput;
78
116
  targetDir: string;
79
- }, import("xstate").EventObject>;
80
- id: string | undefined;
81
- } | {
117
+ }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<string | null, {
118
+ input: DbApplyInput;
119
+ targetDir: string;
120
+ }, import("xstate").EventObject>> | undefined;
121
+ }, {
82
122
  src: "acquireLock";
83
123
  logic: import("xstate").PromiseActorLogic<{
84
124
  acquired: boolean;
@@ -112,6 +152,7 @@ export declare const dbApplyMachine: import("xstate").StateMachine<DbApplyContex
112
152
  logic: import("xstate").PromiseActorLogic<actors.PgSchemaDiffResult, {
113
153
  input: DbApplyInput;
114
154
  targetDir: string;
155
+ preIdempotentTargetFingerprint?: string | null;
115
156
  }, import("xstate").EventObject>;
116
157
  id: string | undefined;
117
158
  } | {
@@ -123,10 +164,30 @@ export declare const dbApplyMachine: import("xstate").StateMachine<DbApplyContex
123
164
  targetDir: string;
124
165
  }, import("xstate").EventObject>;
125
166
  id: string | undefined;
167
+ } | {
168
+ src: "applySeeds";
169
+ logic: import("xstate").PromiseActorLogic<{
170
+ applied: boolean;
171
+ warnings: string[];
172
+ }, {
173
+ input: DbApplyInput;
174
+ targetDir: string;
175
+ }, import("xstate").EventObject>;
176
+ id: string | undefined;
177
+ } | {
178
+ src: "captureTargetFingerprint";
179
+ logic: import("xstate").PromiseActorLogic<string | null, {
180
+ input: DbApplyInput;
181
+ targetDir: string;
182
+ }, import("xstate").EventObject>;
183
+ id: string | undefined;
126
184
  }, {
185
+ type: "assignPgSchemaDiffResult";
186
+ params: import("xstate").NonReducibleUnknown;
187
+ } | {
127
188
  type: "releaseAdvisoryLockOnFailure";
128
189
  params: unknown;
129
- }, never, never, "done" | "failed" | "idle" | "acquiringLock" | "previewingIdempotent" | "applyingIdempotentPre" | "applyingPgSchemaDiff" | "applyingIdempotentPost" | "validatingPartitions" | "releasingLock" | "applyingSeeds", string, {
190
+ }, never, never, "done" | "failed" | "idle" | "acquiringLock" | "previewingIdempotent" | "capturingTargetFingerprint" | "applyingIdempotentPre" | "applyingPgSchemaDiff" | "applyingIdempotentPost" | "validatingPartitions" | "releasingLock" | "applyingSeeds", string, {
130
191
  input: DbApplyInput;
131
192
  targetDir: string;
132
193
  }, {
@@ -196,7 +257,19 @@ export declare const dbApplyMachine: import("xstate").StateMachine<DbApplyContex
196
257
  error?: string | undefined;
197
258
  planSql?: string | undefined;
198
259
  filteredPlanSql?: string | undefined;
260
+ planSummary?: {
261
+ rawStatements: number;
262
+ effectiveStatements: number;
263
+ noiseStatements: number;
264
+ categories: {
265
+ idempotentDrop: number;
266
+ idempotentAuthz: number;
267
+ idempotentRls: number;
268
+ suppressedFunction: number;
269
+ };
270
+ } | undefined;
199
271
  checkOnly?: boolean | undefined;
272
+ previewProfile?: "full" | "compare-only" | undefined;
200
273
  dataViolations?: number | undefined;
201
274
  ssotWarning?: string | undefined;
202
275
  partitionWarnings?: string[] | undefined;
@@ -212,12 +285,25 @@ export declare const dbApplyMachine: import("xstate").StateMachine<DbApplyContex
212
285
  applyMs?: number | undefined;
213
286
  seedMs?: number | undefined;
214
287
  retryAttempts?: number | undefined;
288
+ retryWaitMs?: number | undefined;
289
+ } | undefined;
290
+ planner?: {
291
+ source: "inline" | "artifact";
292
+ path?: string | undefined;
293
+ reuseAttempted?: boolean | undefined;
294
+ reuseReason?: "artifact_missing" | "artifact_invalid" | "profile_ineligible" | "source_fingerprint_mismatch" | "target_fingerprint_unavailable" | "target_fingerprint_mismatch" | "tool_version_mismatch" | undefined;
295
+ reuseMessage?: string | undefined;
296
+ sourceFingerprint?: string | undefined;
297
+ targetFingerprint?: string | undefined;
298
+ targetFingerprintMatched?: boolean | undefined;
299
+ hasChanges?: boolean | undefined;
215
300
  } | undefined;
216
301
  }, import("xstate").EventObject, import("xstate").MetaObject, {
217
302
  id: "dbApply";
218
303
  states: {
219
304
  readonly idle: {};
220
305
  readonly acquiringLock: {};
306
+ readonly capturingTargetFingerprint: {};
221
307
  readonly previewingIdempotent: {};
222
308
  readonly applyingIdempotentPre: {};
223
309
  readonly applyingPgSchemaDiff: {};
@@ -1,5 +1,10 @@
1
1
  import { CLIError } from '@runa-ai/runa';
2
+ import type { DbPreviewProfile } from '../apply/contract.js';
2
3
  type DbApplyEnvironment = 'local' | 'preview' | 'production';
3
- export declare function buildDbApplyCliError(errorMessage: string, environment: DbApplyEnvironment): CLIError;
4
+ interface DbApplyCliErrorOptions {
5
+ previewProfile?: DbPreviewProfile | null;
6
+ fromPlan?: boolean;
7
+ }
8
+ export declare function buildDbApplyCliError(errorMessage: string, environment: DbApplyEnvironment, options?: DbApplyCliErrorOptions): CLIError;
4
9
  export {};
5
10
  //# sourceMappingURL=db-apply-error.d.ts.map
@@ -14,6 +14,11 @@ export interface DbApplyOptions {
14
14
  compareOnly?: boolean;
15
15
  maxLockWaitMs?: number;
16
16
  freshDbCheckSql?: string;
17
+ commandLabel?: string;
18
+ /** Reuse a checked plan artifact generated by `runa db plan`. */
19
+ fromPlan?: string;
20
+ /** Persist the checked plan artifact after a successful full preview. */
21
+ persistPlanArtifact?: boolean;
17
22
  }
18
23
  /**
19
24
  * Run db apply workflow
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare const planCommand: Command;
3
+ //# sourceMappingURL=db-plan.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ import { type DbApplyOutput, type DbPreviewProfile } from '../apply/contract.js';
3
+ export declare const DEFAULT_DB_PREVIEW_PROFILE: DbPreviewProfile;
4
+ export declare const DbPreviewEnvironmentSchema: z.ZodEnum<{
5
+ local: "local";
6
+ preview: "preview";
7
+ production: "production";
8
+ }>;
9
+ export declare const LEGACY_DB_APPLY_CHECK_REMOVAL_TARGET = "the next major CLI release";
10
+ export declare function parseDbPreviewProfile(value: string): DbPreviewProfile;
11
+ export type DbPreviewEnvironment = z.infer<typeof DbPreviewEnvironmentSchema>;
12
+ export declare function resolveDbPreviewEnvironment(value: string): DbPreviewEnvironment | null;
13
+ export declare function resolveDbPreviewProfile(params: {
14
+ check?: boolean;
15
+ compareOnly?: boolean;
16
+ }): DbPreviewProfile | null;
17
+ export declare function isCompareOnlyPreviewProfile(profile: DbPreviewProfile): boolean;
18
+ export declare function getDbPreviewModeLabel(profile: DbPreviewProfile): string;
19
+ export declare function buildDbPreviewCommandLabel(env: string, profile: DbPreviewProfile): string;
20
+ export declare function buildDbPlanCommandLabel(env: string): string;
21
+ export declare function getDbPreviewIdempotentSchemaCount(result: Pick<DbApplyOutput, 'idempotentFiles' | 'idempotentSchemasApplied'>): number;
22
+ export declare function buildLegacyDbApplyCheckWarning(profile: DbPreviewProfile): string;
23
+ //# sourceMappingURL=db-preview-profile.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare const previewCommand: Command;
3
+ //# sourceMappingURL=db-preview.d.ts.map
@@ -74,6 +74,7 @@ export interface SyncInput {
74
74
  export declare const syncSchema: import("xstate").PromiseActorLogic<{
75
75
  applied: boolean;
76
76
  stepsCompleted: string[];
77
+ applyCommitted?: boolean | undefined;
77
78
  error?: string | undefined;
78
79
  }, SyncInput, import("xstate").EventObject>;
79
80
  export interface ReportInput {
@@ -13,6 +13,7 @@
13
13
  * - runa db sync --check # Dry-run mode
14
14
  */
15
15
  import { z } from 'zod';
16
+ import type { BoundaryGuidanceWarning, LocalBlindSpotBlocker, RuntimeContradictionIssue, RuntimeWarningIssue, SchemaGuardrailReport, SchemaManagedBlockKind, SchemaGuardrailFailureCode, SchemaGuardrailPhaseId, SemanticDuplicateCandidate, SemanticDuplicateEvidence, SemanticDuplicateWarning } from './schema-guardrail-types.js';
16
17
  /**
17
18
  * Environment type for db sync
18
19
  */
@@ -89,6 +90,7 @@ export type SnapshotResult = z.infer<typeof SnapshotResultSchema>;
89
90
  */
90
91
  export declare const SyncResultSchema: z.ZodObject<{
91
92
  applied: z.ZodBoolean;
93
+ applyCommitted: z.ZodOptional<z.ZodBoolean>;
92
94
  stepsCompleted: z.ZodArray<z.ZodString>;
93
95
  error: z.ZodOptional<z.ZodString>;
94
96
  }, z.core.$strip>;
@@ -123,6 +125,18 @@ export declare const StepContextSchema: z.ZodObject<{
123
125
  configTimeoutMs: z.ZodOptional<z.ZodNumber>;
124
126
  }, z.core.$strip>;
125
127
  export type StepContext = z.infer<typeof StepContextSchema>;
128
+ export declare const SchemaManagedBlockKindSchema: z.ZodType<SchemaManagedBlockKind>;
129
+ export declare const SchemaGuardrailPhaseIdSchema: z.ZodType<SchemaGuardrailPhaseId>;
130
+ export declare const SchemaGuardrailFailureCodeSchema: z.ZodType<SchemaGuardrailFailureCode>;
131
+ export declare const RuntimeWarningIssueSchema: z.ZodType<RuntimeWarningIssue>;
132
+ export declare const RuntimeContradictionIssueSchema: z.ZodType<RuntimeContradictionIssue>;
133
+ export declare const SemanticDuplicateEvidenceSchema: z.ZodType<SemanticDuplicateEvidence>;
134
+ export declare const SemanticDuplicateCandidateSchema: z.ZodType<SemanticDuplicateCandidate>;
135
+ export declare const SemanticDuplicateWarningSchema: z.ZodType<SemanticDuplicateWarning>;
136
+ export declare const BoundaryGuidanceWarningSchema: z.ZodType<BoundaryGuidanceWarning>;
137
+ export declare const LocalBlindSpotBlockerSchema: z.ZodType<LocalBlindSpotBlocker>;
138
+ export declare const SchemaGuardrailReportSchema: z.ZodType<SchemaGuardrailReport>;
139
+ export type { RuntimeContradictionIssue, RuntimeWarningIssue, SchemaGuardrailReport, SchemaManagedBlockKind, SchemaGuardrailFailureCode, SchemaGuardrailPhaseId, SemanticDuplicateCandidate, SemanticDuplicateEvidence, SemanticDuplicateWarning, } from './schema-guardrail-types.js';
126
140
  /**
127
141
  * DB sync command result
128
142
  */
@@ -137,10 +151,12 @@ export declare const DbSyncOutputSchema: z.ZodObject<{
137
151
  preflightPassed: z.ZodBoolean;
138
152
  snapshotCreated: z.ZodBoolean;
139
153
  applied: z.ZodBoolean;
154
+ applyCommitted: z.ZodOptional<z.ZodBoolean>;
140
155
  stepsCompleted: z.ZodArray<z.ZodString>;
141
156
  reportJsonPath: z.ZodOptional<z.ZodString>;
142
157
  exitCode: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>]>;
143
158
  error: z.ZodOptional<z.ZodString>;
159
+ guardrail: z.ZodOptional<z.ZodType<SchemaGuardrailReport, unknown, z.core.$ZodTypeInternals<SchemaGuardrailReport, unknown>>>;
144
160
  outcome: z.ZodObject<{
145
161
  command: z.ZodString;
146
162
  exitMode: z.ZodEnum<{
@@ -0,0 +1,15 @@
1
+ import type { DbSyncOutput } from './contract.js';
2
+ import type { DbCommandOptions } from '../types.js';
3
+ type GuardrailLogger = {
4
+ info(message: string): void;
5
+ warn(message: string): void;
6
+ error(message: string): void;
7
+ };
8
+ export declare function runDbSyncWithGuardrail(params: {
9
+ env: string;
10
+ options: DbCommandOptions;
11
+ logger: GuardrailLogger;
12
+ runDbSyncMachine: () => Promise<DbSyncOutput>;
13
+ }): Promise<DbSyncOutput>;
14
+ export {};
15
+ //# sourceMappingURL=guardrail-orchestrator.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { DbSyncOutput, SchemaGuardrailReport } from './contract.js';
2
+ export type GuardrailSummaryEntry = {
3
+ level: 'info' | 'warn' | 'error';
4
+ message: string;
5
+ };
6
+ export declare function buildGuardrailSummaryEntries(report: SchemaGuardrailReport): GuardrailSummaryEntry[];
7
+ export declare function buildGuardrailPreApplyEntries(report: SchemaGuardrailReport): GuardrailSummaryEntry[];
8
+ export declare function writeMergedDbSyncReportJson(params: {
9
+ filePath?: string;
10
+ result: DbSyncOutput;
11
+ }): void;
12
+ //# sourceMappingURL=guardrail-reporting.d.ts.map
@@ -6,5 +6,9 @@
6
6
  */
7
7
  export * from './actors.js';
8
8
  export * from './contract.js';
9
+ export * from './guardrail-orchestrator.js';
10
+ export * from './guardrail-reporting.js';
9
11
  export * from './machine.js';
12
+ export type * from './schema-guardrail-types.js';
13
+ export { createGuardrailOutcomePhases, createSyncApplyFailureReport, runSchemaGuardrailRuntime, runSchemaGuardrailStatic, } from './schema-guardrail.js';
10
14
  //# sourceMappingURL=index.d.ts.map
@@ -31,6 +31,7 @@ interface DbSyncContext {
31
31
  preflightPassed: boolean;
32
32
  snapshotCreated: boolean;
33
33
  applied: boolean;
34
+ applyCommitted: boolean;
34
35
  stepsCompleted: string[];
35
36
  reportWritten: boolean;
36
37
  error: string | null;
@@ -51,17 +52,18 @@ export declare const dbSyncMachine: import("xstate").StateMachine<DbSyncContext,
51
52
  }, actors.SnapshotInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
52
53
  applied: boolean;
53
54
  stepsCompleted: string[];
55
+ applyCommitted?: boolean | undefined;
54
56
  error?: string | undefined;
55
57
  }, actors.SyncInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
56
- passed: boolean;
57
- warnings?: string[] | undefined;
58
- error?: string | undefined;
59
- }, actors.PreflightInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
60
58
  passed: boolean;
61
59
  databaseUrl?: string | undefined;
62
60
  dbPackagePath?: string | undefined;
63
61
  error?: string | undefined;
64
- }, actors.ReconcileInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<actors.SetupOutput, actors.SetupInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<actors.ReportOutput, actors.ReportInput, import("xstate").EventObject>> | undefined;
62
+ }, actors.ReconcileInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
63
+ passed: boolean;
64
+ warnings?: string[] | undefined;
65
+ error?: string | undefined;
66
+ }, actors.PreflightInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<actors.SetupOutput, actors.SetupInput, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<actors.ReportOutput, actors.ReportInput, import("xstate").EventObject>> | undefined;
65
67
  }, {
66
68
  src: "snapshot";
67
69
  logic: import("xstate").PromiseActorLogic<{
@@ -76,25 +78,26 @@ export declare const dbSyncMachine: import("xstate").StateMachine<DbSyncContext,
76
78
  logic: import("xstate").PromiseActorLogic<{
77
79
  applied: boolean;
78
80
  stepsCompleted: string[];
81
+ applyCommitted?: boolean | undefined;
79
82
  error?: string | undefined;
80
83
  }, actors.SyncInput, import("xstate").EventObject>;
81
84
  id: string | undefined;
82
85
  } | {
83
- src: "preflight";
86
+ src: "reconcile";
84
87
  logic: import("xstate").PromiseActorLogic<{
85
88
  passed: boolean;
86
- warnings?: string[] | undefined;
89
+ databaseUrl?: string | undefined;
90
+ dbPackagePath?: string | undefined;
87
91
  error?: string | undefined;
88
- }, actors.PreflightInput, import("xstate").EventObject>;
92
+ }, actors.ReconcileInput, import("xstate").EventObject>;
89
93
  id: string | undefined;
90
94
  } | {
91
- src: "reconcile";
95
+ src: "preflight";
92
96
  logic: import("xstate").PromiseActorLogic<{
93
97
  passed: boolean;
94
- databaseUrl?: string | undefined;
95
- dbPackagePath?: string | undefined;
98
+ warnings?: string[] | undefined;
96
99
  error?: string | undefined;
97
- }, actors.ReconcileInput, import("xstate").EventObject>;
100
+ }, actors.PreflightInput, import("xstate").EventObject>;
98
101
  id: string | undefined;
99
102
  } | {
100
103
  src: "setupContext";
@@ -104,7 +107,7 @@ export declare const dbSyncMachine: import("xstate").StateMachine<DbSyncContext,
104
107
  src: "writeReport";
105
108
  logic: import("xstate").PromiseActorLogic<actors.ReportOutput, actors.ReportInput, import("xstate").EventObject>;
106
109
  id: string | undefined;
107
- }, never, never, never, "done" | "failed" | "sync" | "setup" | "idle" | "snapshot" | "report" | "preflight" | "reconcile", string, {
110
+ }, never, never, never, "done" | "failed" | "sync" | "setup" | "idle" | "snapshot" | "reconcile" | "report" | "preflight", string, {
108
111
  env?: "local" | "preview" | "production" | undefined;
109
112
  check?: boolean | undefined;
110
113
  force?: boolean | undefined;
@@ -187,8 +190,10 @@ export declare const dbSyncMachine: import("xstate").StateMachine<DbSyncContext,
187
190
  };
188
191
  nextActions?: string[] | undefined;
189
192
  };
193
+ applyCommitted?: boolean | undefined;
190
194
  reportJsonPath?: string | undefined;
191
195
  error?: string | undefined;
196
+ guardrail?: import("./schema-guardrail-types.js").SchemaGuardrailReport | undefined;
192
197
  }, import("xstate").EventObject, import("xstate").MetaObject, {
193
198
  id: "dbSync";
194
199
  states: {