@mycompbox/compbox-mcp 1.21.6 → 1.21.8

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 (2) hide show
  1. package/index.js +327 -26
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -69,6 +69,9 @@ var init_session_events = __esm({
69
69
  });
70
70
 
71
71
  // ../shared/dist/types/mailbox.js
72
+ function isTerminalJobStatus(status) {
73
+ return TERMINAL_JOB_STATUSES.includes(status);
74
+ }
72
75
  function isMachineStatus(value) {
73
76
  return MACHINE_STATUSES.includes(value);
74
77
  }
@@ -110,7 +113,7 @@ function normalizeGitRemote(raw) {
110
113
  path4 = path4.replace(/^\/+/, "").replace(/\/+$/, "").replace(/\.git$/, "");
111
114
  return `https://${host}/${path4}`;
112
115
  }
113
- var MACHINE_STATUSES, JOB_TYPES, JOB_STATUSES, TURN_ROLES, START_EXECUTION_KINDS;
116
+ var MACHINE_STATUSES, JOB_TYPES, JOB_STATUSES, TERMINAL_JOB_STATUSES, TURN_ROLES, START_EXECUTION_KINDS;
114
117
  var init_mailbox = __esm({
115
118
  "../shared/dist/types/mailbox.js"() {
116
119
  "use strict";
@@ -126,9 +129,12 @@ var init_mailbox = __esm({
126
129
  "claimed",
127
130
  "running",
128
131
  "awaiting_input",
132
+ "cancelling",
129
133
  "done",
130
- "failed"
134
+ "failed",
135
+ "cancelled"
131
136
  ];
137
+ TERMINAL_JOB_STATUSES = ["done", "failed", "cancelled"];
132
138
  TURN_ROLES = ["agent", "user"];
133
139
  START_EXECUTION_KINDS = ["plan", "orchestrate", "refine"];
134
140
  }
@@ -206,6 +212,15 @@ var init_deployment = __esm({
206
212
  }
207
213
  });
208
214
 
215
+ // ../shared/dist/types/database.js
216
+ var CLOUD_SQL_MONTHLY_ESTIMATE_USD;
217
+ var init_database = __esm({
218
+ "../shared/dist/types/database.js"() {
219
+ "use strict";
220
+ CLOUD_SQL_MONTHLY_ESTIMATE_USD = 10;
221
+ }
222
+ });
223
+
209
224
  // ../shared/dist/types/index.js
210
225
  var init_types = __esm({
211
226
  "../shared/dist/types/index.js"() {
@@ -222,6 +237,7 @@ var init_types = __esm({
222
237
  init_cloud();
223
238
  init_stack();
224
239
  init_deployment();
240
+ init_database();
225
241
  }
226
242
  });
227
243
 
@@ -542,6 +558,12 @@ var init_pxpipe = __esm({
542
558
  });
543
559
 
544
560
  // ../shared/dist/interview-definition.js
561
+ function normalizeDatabaseChoice(raw) {
562
+ if (typeof raw !== "string")
563
+ return void 0;
564
+ const candidate = raw.trim().toLowerCase().replace(/[\s-]+/g, "_");
565
+ return DATABASE_CHOICE_VALUES.includes(candidate) ? candidate : void 0;
566
+ }
545
567
  function interviewSectionKeys() {
546
568
  return INTERVIEW_DEFINITION.map((s) => s.key);
547
569
  }
@@ -562,7 +584,7 @@ function buildInterviewSystemPrompt(definition = INTERVIEW_DEFINITION, seedConte
562
584
  const requiredSections = definition.filter((s) => s.required);
563
585
  const optionalSections = definition.filter((s) => !s.required);
564
586
  const renderSection2 = (s) => {
565
- const tag = s.required ? "REQUIRED" : "OPTIONAL \u2014 ask, but the user may decline";
587
+ const tag = s.required ? "REQUIRED" : s.askOnlyWhen ? `OPTIONAL \u2014 ask ONLY if ${s.askOnlyWhen}` : "OPTIONAL \u2014 ask, but the user may decline";
566
588
  const followUps = s.followUps.map((q) => ` - ${q}`).join("\n");
567
589
  return `- ${s.title} (${tag}) [json keys: ${s.fields.join(", ")}]
568
590
  ${s.purpose}
@@ -576,7 +598,7 @@ ${followUps}`;
576
598
  const completionShape = completionKeys.map((k) => `"${k}": "..."`).join(", ");
577
599
  const base = `You are the CompBox request-formulator, interviewing an employee to turn their idea into a well-formed Epic Request. Ask exactly ONE short, focused question at a time \u2014 never multiple questions in one message, never preamble or explanation.
578
600
 
579
- Work through these interview sections in order. Cover EVERY required section; for optional sections, ask about them too, but if the employee has nothing to add or declines, move on and leave that field out (never invent or pad it):
601
+ Work through these interview sections in order. Cover EVERY required section; for optional sections, ask about them too, but if the employee has nothing to add or declines, move on and leave that field out (never invent or pad it). A section marked "ask ONLY if" is conditional: when its condition does not hold, skip it without asking and leave its fields out:
580
602
 
581
603
  REQUIRED sections (an Epic Request cannot omit these):
582
604
  ${requiredSections.map(renderSection2).join("\n")}
@@ -631,10 +653,11 @@ function interviewFieldKeysFor(definition) {
631
653
  }
632
654
  return out;
633
655
  }
634
- var INTERVIEW_DEFINITION, INTERVIEW_FIELD_MIN_WORDS;
656
+ var DATABASE_CHOICE_VALUES, INTERVIEW_DEFINITION, INTERVIEW_FIELD_MIN_WORDS;
635
657
  var init_interview_definition = __esm({
636
658
  "../shared/dist/interview-definition.js"() {
637
659
  "use strict";
660
+ DATABASE_CHOICE_VALUES = ["free_hosted", "cloud_paid", "existing", "none"];
638
661
  INTERVIEW_DEFINITION = [
639
662
  {
640
663
  key: "problemStatement",
@@ -721,6 +744,17 @@ var init_interview_definition = __esm({
721
744
  "Why were those alternatives not chosen?"
722
745
  ],
723
746
  fields: ["alternatives"]
747
+ },
748
+ {
749
+ key: "database",
750
+ title: "Database",
751
+ purpose: "Record what kind of database the work should use, as databaseChoice set to exactly one of: free_hosted, cloud_paid, existing, none. Put any extra detail the employee gives in databaseNote. Never ask for, suggest, or record credentials, connection strings, or a specific vendor.",
752
+ required: false,
753
+ followUps: [
754
+ "Will this need a database: a free hosted one, a paid cloud one, an existing one your team already has, or none?"
755
+ ],
756
+ fields: ["databaseChoice", "databaseNote"],
757
+ askOnlyWhen: "the idea involves storing or persisting data. Ask this at most once, and skip it entirely for ideas that store nothing"
724
758
  }
725
759
  ];
726
760
  INTERVIEW_FIELD_MIN_WORDS = {
@@ -820,6 +854,9 @@ function toDraft(parsed) {
820
854
  draft[key] = raw;
821
855
  }
822
856
  }
857
+ const databaseChoice = normalizeDatabaseChoice(parsed.databaseChoice);
858
+ if (databaseChoice)
859
+ draft.databaseChoice = databaseChoice;
823
860
  return draft;
824
861
  }
825
862
  function extractCompletionJson(text) {
@@ -850,13 +887,15 @@ var TARGET_COMPLIANCE_TIER, OPTIONAL_DRAFT_KEYS, COMPLETION_REPAIR_INSTRUCTION;
850
887
  var init_interview_completion = __esm({
851
888
  "../shared/dist/interview-completion.js"() {
852
889
  "use strict";
890
+ init_interview_definition();
853
891
  TARGET_COMPLIANCE_TIER = "pass";
854
892
  OPTIONAL_DRAFT_KEYS = [
855
893
  "successMetrics",
856
894
  "targetAudience",
857
895
  "alternatives",
858
896
  "dependencies",
859
- "estimatedEffort"
897
+ "estimatedEffort",
898
+ "databaseNote"
860
899
  ];
861
900
  COMPLETION_REPAIR_INSTRUCTION = 'Your last message looked like a completion but I could NOT parse it as a valid JSON object with all required fields. Re-emit ONLY a single valid JSON object inside a ```json code fence \u2014 no other text \u2014 with every string value properly escaped (escape any internal double-quotes as \\" and any line breaks as \\n), and make sure title, problemStatement, proposedSolution, impactAssessment, and description are all present and non-empty:\n```json\n{"done": true, "title": "...", "problemStatement": "...", "proposedSolution": "...", "impactAssessment": "...", "description": "..."}\n```';
862
901
  }
@@ -1147,8 +1186,7 @@ REGION=${input.region}
1147
1186
  SA=${gcpServiceAccountEmail(input.projectId)}
1148
1187
 
1149
1188
  gcloud config set project "$PROJECT"
1150
- gcloud services enable run.googleapis.com artifactregistry.googleapis.com iam.googleapis.com \\
1151
- iamcredentials.googleapis.com sts.googleapis.com cloudresourcemanager.googleapis.com
1189
+ gcloud services enable ${GCP_SERVICES.join(" ")}
1152
1190
  NUMBER=$(gcloud projects describe "$PROJECT" --format='value(projectNumber)')
1153
1191
 
1154
1192
  # The account deploys run as.
@@ -1157,6 +1195,16 @@ gcloud iam service-accounts describe "$SA" >/dev/null 2>&1 || \\
1157
1195
  for ROLE in ${GCP_DEPLOY_ROLES.join(" ")}; do
1158
1196
  gcloud projects add-iam-policy-binding "$PROJECT" --member="serviceAccount:$SA" --role="$ROLE" --condition=None --quiet >/dev/null
1159
1197
  done
1198
+ # Lets deploys grant Cloud SQL Client to an environment's runtime account, and nothing else.
1199
+ CONDITION=$(mktemp)
1200
+ cat > "$CONDITION" <<'EOF'
1201
+ title: ${GCP_DEPLOY_CONDITIONAL_ROLE.condition.title}
1202
+ description: ${GCP_DEPLOY_CONDITIONAL_ROLE.condition.description}
1203
+ expression: "${GCP_DEPLOY_CONDITIONAL_ROLE.condition.expression}"
1204
+ EOF
1205
+ gcloud projects add-iam-policy-binding "$PROJECT" --member="serviceAccount:$SA" \\
1206
+ --role="${GCP_DEPLOY_CONDITIONAL_ROLE.role}" --condition-from-file="$CONDITION" --quiet >/dev/null
1207
+ rm -f "$CONDITION"
1160
1208
 
1161
1209
  # Trust GitHub Actions from your GitHub only: ${owners.join(", ")}.
1162
1210
  gcloud iam workload-identity-pools describe ${GCP_IDENTITY_POOL} --location=global >/dev/null 2>&1 || \\
@@ -1180,7 +1228,7 @@ echo "Done. Your project number is: $NUMBER"
1180
1228
  echo "Paste it into CompBox to finish."
1181
1229
  `;
1182
1230
  }
1183
- var GCP_REGIONS, GCP_DEPLOY_ACCOUNT, GCP_IDENTITY_POOL, GCP_IDENTITY_PROVIDER, GCP_DEPLOY_ROLES, PROJECT_ID, PROJECT_NUMBER, GITHUB_LOGIN, GCP_CONNECT_STEPS, GCP_CONNECT_STEP_LABELS;
1231
+ var GCP_REGIONS, GCP_DEPLOY_ACCOUNT, GCP_IDENTITY_POOL, GCP_IDENTITY_PROVIDER, GCP_DEPLOY_ROLES, GCP_SERVICES, GCP_DEPLOY_CONDITIONAL_ROLE, PROJECT_ID, PROJECT_NUMBER, GITHUB_LOGIN, GCP_CONNECT_STEPS, GCP_CONNECT_STEP_LABELS;
1184
1232
  var init_cloud_setup = __esm({
1185
1233
  "../shared/dist/cloud-setup.js"() {
1186
1234
  "use strict";
@@ -1209,8 +1257,31 @@ var init_cloud_setup = __esm({
1209
1257
  "roles/iam.serviceAccountUser",
1210
1258
  "roles/iam.serviceAccountAdmin",
1211
1259
  "roles/storage.admin",
1212
- "roles/serviceusage.serviceUsageConsumer"
1260
+ "roles/serviceusage.serviceUsageConsumer",
1261
+ // Keeps each environment's DATABASE_URL in Secret Manager and lets its runtime account read it.
1262
+ "roles/secretmanager.admin",
1263
+ // Creates each environment's Cloud SQL database (ENG-316) and connects the migrate job to it.
1264
+ "roles/cloudsql.admin"
1265
+ ];
1266
+ GCP_SERVICES = [
1267
+ "run.googleapis.com",
1268
+ "artifactregistry.googleapis.com",
1269
+ "iam.googleapis.com",
1270
+ "iamcredentials.googleapis.com",
1271
+ "sts.googleapis.com",
1272
+ "cloudresourcemanager.googleapis.com",
1273
+ "storage.googleapis.com",
1274
+ "secretmanager.googleapis.com",
1275
+ "sqladmin.googleapis.com"
1213
1276
  ];
1277
+ GCP_DEPLOY_CONDITIONAL_ROLE = {
1278
+ role: "roles/resourcemanager.projectIamAdmin",
1279
+ condition: {
1280
+ title: "compbox-cloudsql-client-only",
1281
+ description: "CompBox deploys may only grant Cloud SQL Client.",
1282
+ expression: "api.getAttribute('iam.googleapis.com/modifiedGrantsByRole', []).hasOnly(['roles/cloudsql.client'])"
1283
+ }
1284
+ };
1214
1285
  PROJECT_ID = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
1215
1286
  PROJECT_NUMBER = /^\d{6,20}$/;
1216
1287
  GITHUB_LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;
@@ -1649,11 +1720,21 @@ function stackAppName(repoName) {
1649
1720
  slug = `app${slug}`.slice(0, 20);
1650
1721
  return slug;
1651
1722
  }
1723
+ function cloudSqlInstanceName(app, environment) {
1724
+ return `${app}-${environment}-db`;
1725
+ }
1726
+ function databaseSecretName(app, environment, database) {
1727
+ return `${app}-${environment}-${database === "cloudsql" ? "cloudsql-url" : "database-url"}`;
1728
+ }
1652
1729
  function envSettings(env) {
1653
1730
  return env === "prod" ? { min: 0, max: 10 } : { min: 0, max: 2 };
1654
1731
  }
1655
1732
  function buildStackFiles(input) {
1656
1733
  const { tier, app, defaultBranch, cloud } = input;
1734
+ const cloudSql = input.database === "cloudsql";
1735
+ if (input.database != null && !cloudSql)
1736
+ throw new Error("Not a supported database.");
1737
+ const secretSuffix = cloudSql ? "cloudsql-url" : "database-url";
1657
1738
  if (!APP.test(app))
1658
1739
  throw new Error("Not a valid app name.");
1659
1740
  if (!BRANCH.test(defaultBranch))
@@ -1670,7 +1751,11 @@ terraform {
1670
1751
  google = {
1671
1752
  source = "hashicorp/google"
1672
1753
  version = "~> 6.0"
1673
- }
1754
+ }${cloudSql ? `
1755
+ random = {
1756
+ source = "hashicorp/random"
1757
+ version = "~> 3.6"
1758
+ }` : ""}
1674
1759
  }
1675
1760
  # Bucket and prefix are passed by the deploy workflow.
1676
1761
  backend "gcs" {}
@@ -1754,10 +1839,20 @@ resource "google_cloud_run_v2_service" "app" {
1754
1839
  }
1755
1840
  }
1756
1841
 
1757
- # Deploys change the image; Terraform owns everything else.
1842
+ ${cloudSql ? ` # Deploys set the image, DATABASE_URL and the Cloud SQL connection; Terraform owns everything else.
1843
+ lifecycle {
1844
+ ignore_changes = [
1845
+ template[0].containers[0].image,
1846
+ template[0].containers[0].env,
1847
+ template[0].containers[0].volume_mounts,
1848
+ template[0].volumes,
1849
+ client,
1850
+ client_version,
1851
+ ]
1852
+ }` : ` # Deploys change the image; Terraform owns everything else.
1758
1853
  lifecycle {
1759
1854
  ignore_changes = [template[0].containers[0].image, client, client_version]
1760
- }
1855
+ }`}
1761
1856
  }
1762
1857
 
1763
1858
  # Anyone with the link can open it. Remove this to keep the app private.
@@ -1773,6 +1868,86 @@ output "url" {
1773
1868
  }
1774
1869
  `
1775
1870
  });
1871
+ if (cloudSql) {
1872
+ files.push({
1873
+ path: "infra/database.tf",
1874
+ content: `# Managed by CompBox: a Cloud SQL for PostgreSQL database for this environment.
1875
+ # Estimated cost: a db-f1-micro instance with 10 GB of SSD, per environment.
1876
+ # The password is generated here and kept only in Terraform state and Secret Manager.
1877
+ resource "google_sql_database_instance" "db" {
1878
+ name = "\${local.service}-db"
1879
+ database_version = "POSTGRES_16"
1880
+ region = var.region
1881
+ # Terraform refuses to delete it; turn this off first if you really mean to.
1882
+ deletion_protection = true
1883
+
1884
+ settings {
1885
+ edition = "ENTERPRISE"
1886
+ tier = "db-f1-micro"
1887
+ availability_type = "ZONAL"
1888
+ disk_type = "PD_SSD"
1889
+ disk_size = 10
1890
+ deletion_protection_enabled = true
1891
+
1892
+ backup_configuration {
1893
+ enabled = true
1894
+ }
1895
+
1896
+ # A public IP with no authorized networks: only IAM-authorized connectors
1897
+ # (Cloud Run's Cloud SQL connection, the Cloud SQL Auth Proxy) can reach it.
1898
+ ip_configuration {
1899
+ ipv4_enabled = true
1900
+ }
1901
+ }
1902
+ }
1903
+
1904
+ resource "google_sql_database" "app" {
1905
+ name = var.app
1906
+ instance = google_sql_database_instance.db.name
1907
+ }
1908
+
1909
+ resource "random_password" "db" {
1910
+ length = 32
1911
+ special = false
1912
+ }
1913
+
1914
+ resource "google_sql_user" "app" {
1915
+ name = var.app
1916
+ instance = google_sql_database_instance.db.name
1917
+ password = random_password.db.result
1918
+ }
1919
+
1920
+ # Cloud Run (and the migrate job's proxy) reach the database over a Unix socket in /cloudsql.
1921
+ resource "google_secret_manager_secret" "database_url" {
1922
+ secret_id = "\${local.service}-${secretSuffix}"
1923
+ replication {
1924
+ auto {}
1925
+ }
1926
+ }
1927
+
1928
+ resource "google_secret_manager_secret_version" "database_url" {
1929
+ secret = google_secret_manager_secret.database_url.id
1930
+ secret_data = "postgresql://\${google_sql_user.app.name}:\${random_password.db.result}@localhost/\${google_sql_database.app.name}?host=/cloudsql/\${google_sql_database_instance.db.connection_name}"
1931
+ }
1932
+
1933
+ resource "google_secret_manager_secret_iam_member" "runtime" {
1934
+ secret_id = google_secret_manager_secret.database_url.id
1935
+ role = "roles/secretmanager.secretAccessor"
1936
+ member = "serviceAccount:\${google_service_account.runtime.email}"
1937
+ }
1938
+
1939
+ resource "google_project_iam_member" "runtime_cloudsql" {
1940
+ project = var.project_id
1941
+ role = "roles/cloudsql.client"
1942
+ member = "serviceAccount:\${google_service_account.runtime.email}"
1943
+ }
1944
+
1945
+ output "database_instance" {
1946
+ value = google_sql_database_instance.db.connection_name
1947
+ }
1948
+ `
1949
+ });
1950
+ }
1776
1951
  for (const env of envs) {
1777
1952
  const s = envSettings(env);
1778
1953
  files.push({
@@ -1814,11 +1989,19 @@ jobs:
1814
1989
  uses: ./.github/workflows/compbox-deploy.yml
1815
1990
  with:
1816
1991
  environment: \${{ inputs.environment || 'dev' }}
1992
+ secrets: inherit
1817
1993
  `
1818
1994
  });
1819
1995
  files.push({
1820
1996
  path: ".github/workflows/compbox-deploy.yml",
1821
1997
  content: `# Managed by CompBox. Signs in to Google Cloud without stored keys (Workload Identity).
1998
+ #
1999
+ # 1. build \u2014 runs in the environment (prod waits for its approval): applies the
2000
+ # Terraform, ${cloudSql ? "including the Cloud SQL database and its DATABASE_URL" : "keeps DATABASE_URL in Secret Manager"}, builds the image.
2001
+ # 2. migrate \u2014 only when the environment has a DATABASE_URL: runs the app's own
2002
+ # "db:migrate" (or "migrate") script. It runs in the "<environment>-migrations"
2003
+ # GitHub environment, so you can require an approval before migrations.
2004
+ # 3. release \u2014 deploys the image to Cloud Run once migrations have succeeded.
1822
2005
  name: CompBox deploy
1823
2006
 
1824
2007
  on:
@@ -1836,19 +2019,22 @@ concurrency:
1836
2019
  group: compbox-\${{ inputs.environment }}
1837
2020
  cancel-in-progress: false
1838
2021
 
2022
+ env:
2023
+ ENVIRONMENT: \${{ inputs.environment }}
2024
+ PROJECT_ID: ${cloud.projectId}
2025
+ REGION: ${cloud.region}
2026
+ APP: ${app}
2027
+ IMAGE: ${registry}/app:\${{ github.sha }}
2028
+ STATE_BUCKET: ${gcpStateBucket(cloud.projectId)}
2029
+
1839
2030
  jobs:
1840
- deploy:
2031
+ build:
1841
2032
  runs-on: ubuntu-latest
1842
- environment:
1843
- name: \${{ inputs.environment }}
1844
- url: \${{ steps.deploy.outputs.url }}
2033
+ environment: \${{ inputs.environment }}
2034
+ outputs:
2035
+ database: \${{ steps.database.outputs.configured }}
1845
2036
  env:
1846
- ENVIRONMENT: \${{ inputs.environment }}
1847
- PROJECT_ID: ${cloud.projectId}
1848
- REGION: ${cloud.region}
1849
- APP: ${app}
1850
- IMAGE: ${registry}/app:\${{ github.sha }}
1851
- STATE_BUCKET: ${gcpStateBucket(cloud.projectId)}
2037
+ HAS_DATABASE_URL: \${{ secrets.DATABASE_URL != '' }}
1852
2038
  steps:
1853
2039
  - uses: actions/checkout@v4
1854
2040
 
@@ -1867,6 +2053,31 @@ jobs:
1867
2053
  terraform init -input=false -backend-config="bucket=$STATE_BUCKET" -backend-config="prefix=$APP/$ENVIRONMENT"
1868
2054
  terraform apply -input=false -auto-approve -var-file="envs/$ENVIRONMENT.tfvars"
1869
2055
 
2056
+ ${cloudSql ? ` - name: Database secret
2057
+ id: database
2058
+ # Terraform created the Cloud SQL database and keeps its DATABASE_URL.
2059
+ run: echo "configured=true" >> "$GITHUB_OUTPUT"
2060
+ ` : ` - name: Database secret
2061
+ id: database
2062
+ env:
2063
+ DATABASE_URL: \${{ secrets.DATABASE_URL }}
2064
+ run: |
2065
+ if [ "$HAS_DATABASE_URL" != "true" ]; then
2066
+ echo "configured=false" >> "$GITHUB_OUTPUT"
2067
+ exit 0
2068
+ fi
2069
+ SECRET="$APP-$ENVIRONMENT-database-url"
2070
+ RUNTIME="serviceAccount:$APP-$ENVIRONMENT@$PROJECT_ID.iam.gserviceaccount.com"
2071
+ gcloud secrets describe "$SECRET" --project "$PROJECT_ID" >/dev/null 2>&1 || \\
2072
+ gcloud secrets create "$SECRET" --project "$PROJECT_ID" --replication-policy=automatic --quiet
2073
+ CURRENT=$(gcloud secrets versions access latest --secret "$SECRET" --project "$PROJECT_ID" 2>/dev/null || true)
2074
+ if [ "$CURRENT" != "$DATABASE_URL" ]; then
2075
+ printf '%s' "$DATABASE_URL" | gcloud secrets versions add "$SECRET" --project "$PROJECT_ID" --data-file=- --quiet
2076
+ fi
2077
+ gcloud secrets add-iam-policy-binding "$SECRET" --project "$PROJECT_ID" --member="$RUNTIME" \\
2078
+ --role=roles/secretmanager.secretAccessor --condition=None --quiet >/dev/null
2079
+ echo "configured=true" >> "$GITHUB_OUTPUT"
2080
+ `}
1870
2081
  - name: Build
1871
2082
  run: |
1872
2083
  if [ ! -f Dockerfile ]; then
@@ -1877,11 +2088,89 @@ jobs:
1877
2088
  docker build -t "$IMAGE" .
1878
2089
  docker push "$IMAGE"
1879
2090
 
2091
+ migrate:
2092
+ needs: build
2093
+ if: needs.build.outputs.database == 'true'
2094
+ runs-on: ubuntu-latest
2095
+ environment: \${{ inputs.environment }}-migrations
2096
+ steps:
2097
+ - uses: actions/checkout@v4
2098
+
2099
+ - uses: google-github-actions/auth@v2
2100
+ with:
2101
+ workload_identity_provider: ${cloud.workloadProvider}
2102
+ service_account: ${cloud.serviceAccountEmail}
2103
+
2104
+ - uses: google-github-actions/setup-gcloud@v2
2105
+
2106
+ - uses: actions/setup-node@v4
2107
+ with:
2108
+ node-version: lts/*
2109
+
2110
+ - name: Migrate
2111
+ run: |
2112
+ if [ ! -f package.json ]; then
2113
+ echo "::notice::No package.json, so there is no migrate script to run. Skipping migrations."
2114
+ exit 0
2115
+ fi
2116
+ SCRIPT=$(node -e 'const s = require("./package.json").scripts || {}; process.stdout.write(s["db:migrate"] ? "db:migrate" : s.migrate ? "migrate" : "")')
2117
+ if [ -z "$SCRIPT" ]; then
2118
+ echo "::notice::package.json has no \\"db:migrate\\" or \\"migrate\\" script. Skipping migrations."
2119
+ exit 0
2120
+ fi
2121
+ DATABASE_URL=$(gcloud secrets versions access latest --secret "$APP-$ENVIRONMENT-${secretSuffix}" --project "$PROJECT_ID")
2122
+ echo "::add-mask::$DATABASE_URL"
2123
+ export DATABASE_URL${cloudSql ? `
2124
+ # Reach the Cloud SQL database through the Cloud SQL Auth Proxy, on the same /cloudsql socket Cloud Run uses.
2125
+ curl -fsSL -o cloud-sql-proxy "https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/${CLOUD_SQL_PROXY_VERSION}/cloud-sql-proxy.linux.amd64"
2126
+ chmod +x cloud-sql-proxy
2127
+ sudo mkdir -p /cloudsql && sudo chown "$(id -u)" /cloudsql
2128
+ INSTANCE="$PROJECT_ID:$REGION:$APP-$ENVIRONMENT-db"
2129
+ ./cloud-sql-proxy --unix-socket /cloudsql "$INSTANCE" &
2130
+ for _ in $(seq 1 30); do
2131
+ [ -S "/cloudsql/$INSTANCE/.s.PGSQL.5432" ] && break
2132
+ sleep 1
2133
+ done
2134
+ if [ ! -S "/cloudsql/$INSTANCE/.s.PGSQL.5432" ]; then
2135
+ echo "::error::Couldn't reach the Cloud SQL database $INSTANCE."
2136
+ exit 1
2137
+ fi` : ""}
2138
+ if [ -f pnpm-lock.yaml ]; then
2139
+ corepack enable
2140
+ pnpm install --frozen-lockfile
2141
+ pnpm run "$SCRIPT"
2142
+ elif [ -f yarn.lock ]; then
2143
+ corepack enable
2144
+ yarn install --immutable || yarn install --frozen-lockfile
2145
+ yarn run "$SCRIPT"
2146
+ else
2147
+ if [ -f package-lock.json ]; then npm ci; else npm install; fi
2148
+ npm run "$SCRIPT"
2149
+ fi
2150
+
2151
+ release:
2152
+ needs: [build, migrate]
2153
+ if: \${{ !cancelled() && needs.build.result == 'success' && (needs.migrate.result == 'success' || needs.migrate.result == 'skipped') }}
2154
+ runs-on: ubuntu-latest
2155
+ steps:
2156
+ - uses: google-github-actions/auth@v2
2157
+ with:
2158
+ workload_identity_provider: ${cloud.workloadProvider}
2159
+ service_account: ${cloud.serviceAccountEmail}
2160
+
2161
+ - uses: google-github-actions/setup-gcloud@v2
2162
+
1880
2163
  - name: Deploy
1881
2164
  id: deploy
2165
+ env:
2166
+ DATABASE: \${{ needs.build.outputs.database }}
1882
2167
  run: |
1883
2168
  SERVICE="$APP-$ENVIRONMENT"
1884
- gcloud run deploy "$SERVICE" --image "$IMAGE" --region "$REGION" --project "$PROJECT_ID" --quiet
2169
+ SECRETS=()
2170
+ if [ "$DATABASE" = "true" ]; then
2171
+ SECRETS=(--set-secrets "DATABASE_URL=$APP-$ENVIRONMENT-${secretSuffix}:latest"${cloudSql ? ` --add-cloudsql-instances "$PROJECT_ID:$REGION:$APP-$ENVIRONMENT-db"` : ""})
2172
+ fi
2173
+ gcloud run deploy "$SERVICE" --image "$IMAGE" --region "$REGION" --project "$PROJECT_ID" "\${SECRETS[@]}" --quiet
1885
2174
  URL=$(gcloud run services describe "$SERVICE" --region "$REGION" --project "$PROJECT_ID" --format='value(status.url)')
1886
2175
  echo "url=$URL" >> "$GITHUB_OUTPUT"
1887
2176
  echo "### Live at $URL" >> "$GITHUB_STEP_SUMMARY"
@@ -1895,13 +2184,14 @@ This project deploys to Google Cloud project \`${cloud.projectId}\` (${cloud.reg
1895
2184
 
1896
2185
  - **Dev:** every push to \`${defaultBranch}\` deploys it.${envs.length > 1 ? "\n- **Stage and prod:** in GitHub, Actions \u2192 CompBox \u2192 Run workflow, then pick the environment. Add required reviewers to the `prod` environment (Settings \u2192 Environments) so prod waits for approval." : ""}
1897
2186
  - **The app:** a \`Dockerfile\` at the repository root, for a container that listens on \`$PORT\` (8080).
2187
+ - **Database:** ${cloudSql ? `each environment has a Cloud SQL for PostgreSQL database (\`${app}-<environment>-db\`, in \`database.tf\`), created by the first deploy. Terraform keeps its \`DATABASE_URL\` in Secret Manager (\`${app}-<environment>-cloudsql-url\`) and the deploy gives it to the service as \`DATABASE_URL\`. Deletion protection is on: Terraform won't delete the database. The database password is in the Terraform state (the \`${app}\` prefix of the state bucket), so keep that bucket private.` : `when the environment has a \`DATABASE_URL\` secret, the deploy keeps it in Secret Manager (\`${app}-<environment>-database-url\`) and gives it to the service as \`DATABASE_URL\`.`} Before the new version goes live, it runs the app's \`db:migrate\` script (or \`migrate\`) with npm, pnpm or yarn, matching the lockfile; with neither script, migrations are skipped. Migrations run in the \`<environment>-migrations\` GitHub environment: add required reviewers there to approve them before they run. CompBox never runs a reset or a data-loss migration.
1898
2188
  - **Sign-in:** GitHub Actions sign in to Google Cloud through Workload Identity \u2014 there are no keys to store or rotate.
1899
2189
  - **Changes:** edit the Terraform here; the next deploy applies it. Services are public by default; remove the \`public\` resource in \`main.tf\` to keep one private.
1900
2190
  `
1901
2191
  });
1902
2192
  return files;
1903
2193
  }
1904
- var STACK_TIERS, STACK_WORKFLOW, APP, BRANCH;
2194
+ var STACK_TIERS, STACK_WORKFLOW, CLOUD_SQL_PROXY_VERSION, APP, BRANCH;
1905
2195
  var init_stack_files = __esm({
1906
2196
  "../shared/dist/stack-files.js"() {
1907
2197
  "use strict";
@@ -1911,6 +2201,7 @@ var init_stack_files = __esm({
1911
2201
  full: { label: "Dev, stage and prod", environments: ["dev", "stage", "prod"] }
1912
2202
  };
1913
2203
  STACK_WORKFLOW = "compbox.yml";
2204
+ CLOUD_SQL_PROXY_VERSION = "v2.14.1";
1914
2205
  APP = /^[a-z][a-z0-9-]{1,19}$/;
1915
2206
  BRANCH = /^[A-Za-z0-9._/-]{1,200}$/;
1916
2207
  }
@@ -1980,17 +2271,22 @@ __export(dist_exports, {
1980
2271
  APPEND_DESCRIPTION_MAX: () => APPEND_DESCRIPTION_MAX,
1981
2272
  AWS_REGIONS: () => AWS_REGIONS,
1982
2273
  AZURE_DEPLOY_IDENTITY: () => AZURE_DEPLOY_IDENTITY,
2274
+ CLOUD_SQL_MONTHLY_ESTIMATE_USD: () => CLOUD_SQL_MONTHLY_ESTIMATE_USD,
2275
+ CLOUD_SQL_PROXY_VERSION: () => CLOUD_SQL_PROXY_VERSION,
1983
2276
  COMPLETION_REPAIR_INSTRUCTION: () => COMPLETION_REPAIR_INSTRUCTION,
1984
2277
  CONVERSATION_QUALITY_ROUNDS: () => CONVERSATION_QUALITY_ROUNDS,
2278
+ DATABASE_CHOICE_VALUES: () => DATABASE_CHOICE_VALUES,
1985
2279
  DESCRIPTION_MAX: () => DESCRIPTION_MAX,
1986
2280
  EMPTY_ARM_TEMPLATE: () => EMPTY_ARM_TEMPLATE,
1987
2281
  GCP_CONNECT_STEPS: () => GCP_CONNECT_STEPS,
1988
2282
  GCP_CONNECT_STEP_LABELS: () => GCP_CONNECT_STEP_LABELS,
1989
2283
  GCP_DEPLOY_ACCOUNT: () => GCP_DEPLOY_ACCOUNT,
2284
+ GCP_DEPLOY_CONDITIONAL_ROLE: () => GCP_DEPLOY_CONDITIONAL_ROLE,
1990
2285
  GCP_DEPLOY_ROLES: () => GCP_DEPLOY_ROLES,
1991
2286
  GCP_IDENTITY_POOL: () => GCP_IDENTITY_POOL,
1992
2287
  GCP_IDENTITY_PROVIDER: () => GCP_IDENTITY_PROVIDER,
1993
2288
  GCP_REGIONS: () => GCP_REGIONS,
2289
+ GCP_SERVICES: () => GCP_SERVICES,
1994
2290
  INTERVIEW_DEFINITION: () => INTERVIEW_DEFINITION,
1995
2291
  INTERVIEW_FIELD_MIN_WORDS: () => INTERVIEW_FIELD_MIN_WORDS,
1996
2292
  INTERVIEW_STATUSES: () => INTERVIEW_STATUSES,
@@ -2008,6 +2304,7 @@ __export(dist_exports, {
2008
2304
  SUMMARY_MAX: () => SUMMARY_MAX,
2009
2305
  SessionEventType: () => SessionEventType,
2010
2306
  TARGET_COMPLIANCE_TIER: () => TARGET_COMPLIANCE_TIER,
2307
+ TERMINAL_JOB_STATUSES: () => TERMINAL_JOB_STATUSES,
2011
2308
  TURN_ROLES: () => TURN_ROLES,
2012
2309
  agentSchema: () => agentSchema,
2013
2310
  aiProviderValues: () => aiProviderValues,
@@ -2023,7 +2320,9 @@ __export(dist_exports, {
2023
2320
  buildInterviewSystemPrompt: () => buildInterviewSystemPrompt,
2024
2321
  buildStackFiles: () => buildStackFiles,
2025
2322
  cloudRunUrl: () => cloudRunUrl,
2323
+ cloudSqlInstanceName: () => cloudSqlInstanceName,
2026
2324
  complianceFromRecord: () => complianceFromRecord,
2325
+ databaseSecretName: () => databaseSecretName,
2027
2326
  deployRunTitle: () => deployRunTitle,
2028
2327
  err: () => err,
2029
2328
  extractCompletionJson: () => extractCompletionJson,
@@ -2063,6 +2362,7 @@ __export(dist_exports, {
2063
2362
  isSessionTaskEvent: () => isSessionTaskEvent,
2064
2363
  isSessionTaskProgressEvent: () => isSessionTaskProgressEvent,
2065
2364
  isSubscriptionStatus: () => isSubscriptionStatus,
2365
+ isTerminalJobStatus: () => isTerminalJobStatus,
2066
2366
  isTurnRole: () => isTurnRole,
2067
2367
  isValidModelId: () => isValidModelId,
2068
2368
  lockedRequestMessage: () => lockedRequestMessage,
@@ -2071,6 +2371,7 @@ __export(dist_exports, {
2071
2371
  mcpServerConfigSchema: () => mcpServerConfigSchema,
2072
2372
  meetsComplianceTarget: () => meetsComplianceTarget,
2073
2373
  modelRecommendationSourceValues: () => modelRecommendationSourceValues,
2374
+ normalizeDatabaseChoice: () => normalizeDatabaseChoice,
2074
2375
  normalizeGitRemote: () => normalizeGitRemote,
2075
2376
  ok: () => ok,
2076
2377
  probeProxyHealth: () => probeProxyHealth,
@@ -12335,7 +12636,7 @@ function withLegacyToolCallRewrite(transport) {
12335
12636
  var SERVER_NAME = "compbox-mcp";
12336
12637
  function resolveServerVersion() {
12337
12638
  if (true) {
12338
- return "1.21.6";
12639
+ return "1.21.8";
12339
12640
  }
12340
12641
  const require2 = createRequire(import.meta.url);
12341
12642
  for (const candidate of ["../package.json", "./package.json"]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycompbox/compbox-mcp",
3
- "version": "1.21.6",
3
+ "version": "1.21.8",
4
4
  "description": "CompBox MCP server - Uses HTTP API client (no direct database access)",
5
5
  "license": "MIT",
6
6
  "type": "module",