dawnfix 0.3.1 → 0.4.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 (3) hide show
  1. package/README.md +11 -4
  2. package/dist/cli.js +225 -38
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,32 +1,39 @@
1
1
  # dawnfix (npm)
2
2
 
3
- Set up [Dawnfix](https://dawnfix.dev), the AI SRE that runs in your own GitHub Actions, in a
4
- repo; check the setup; and run Dawnfix Flare. One bundled file, no dependencies, Node 20 or
3
+ Set up [Dawnfix](https://dawnfix.dev), the AI SRE that runs in your own GitHub Actions or GitLab CI,
4
+ in a repo; check the setup; and run Dawnfix Flare. One bundled file, no dependencies, Node 20 or
5
5
  newer. Source available under FSL-1.1-ALv2 (the `LICENSE` in this package).
6
6
 
7
7
  ```sh
8
8
  npx dawnfix init # shows .dawnfix.yml and a 15-line workflow, writes them when you say yes
9
9
  npx dawnfix init --dry-run # only shows them, and the next steps
10
+ npx dawnfix init --host gitlab # GitLab: .dawnfix.yml and a .gitlab-ci.yml include (default when origin is GitLab)
10
11
  npx dawnfix doctor # config, pinned workflow, secret and variable names, Free or Enterprise
11
12
  npx dawnfix flare --help # read-only Cloudflare audit
12
13
  ```
13
14
 
14
15
  `init` never asks for a secret and never writes one. It prints the commands you run: the
15
16
  read-only cloud role (AWS CloudFormation or GCP Workload Identity Federation) and
16
- `gh secret set ANTHROPIC_API_KEY`.
17
+ `gh secret set DAWNFIX_AI_API_KEY` (your AI API key, Claude today).
17
18
 
18
19
  The workflow it writes calls the reusable workflow
19
20
  `dawnfix/dawnfix/.github/workflows/dawnfix.yml@v0`. The Python tools (`dawnfix`, `logbill`,
20
21
  `parity`, `sweeper`, `leastpriv`, `receipt`, `fleet`) are the PyPI package `dawnfix` of the
21
22
  same version.
22
23
 
24
+ On GitLab, `.gitlab-ci.yml` includes `templates/gitlab/dawnfix.gitlab-ci.yml` of the
25
+ release, pinned with its `integrity:` (sha256) hash. An existing `.gitlab-ci.yml` is never
26
+ changed: `init` writes `.dawnfix.yml` and prints the include lines to paste. The next steps
27
+ are `glab variable set` lines (each secret masked, protected and scoped to one environment)
28
+ and `glab schedule create`.
29
+
23
30
  Docs and source: https://github.com/dawnfix/dawnfix
24
31
 
25
32
  ## Development (in the repo, `cli/`)
26
33
 
27
34
  ```sh
28
35
  npm ci
29
- npm run build # writes dist/cli.js from src/ and ../flare/src/; commit it
36
+ npm run build # writes dist/cli.js from src/, ../flare/src/ and ../templates/gitlab/; commit it
30
37
  npm run build:check # exit 1 if dist/cli.js is stale
31
38
  npm test # node --test: init, doctor, flare, the bundle, npm pack + install
32
39
  ```
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // Dawnfix 0.3.1: npx dawnfix init | doctor | flare.
2
+ // Dawnfix 0.4.0: npx dawnfix init | doctor | flare.
3
3
  // Source available under FSL-1.1-ALv2 (see LICENSE in this package).
4
4
  // GENERATED from cli/src/ and flare/src/ by `npm run build` (esbuild, one file, no dependencies). Do not edit.
5
5
  import { createRequire as __dawnfixRequire } from 'node:module';
@@ -39,6 +39,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
39
39
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
40
  mod
41
41
  ));
42
+ var __toBinaryNode = Uint8Array.fromBase64 || ((base64) => new Uint8Array(Buffer.from(base64, "base64")));
42
43
 
43
44
  // node_modules/yaml/dist/nodes/identity.js
44
45
  var require_identity = __commonJS({
@@ -9327,7 +9328,7 @@ var config_schema_default = {
9327
9328
  type: "object",
9328
9329
  additionalProperties: false,
9329
9330
  properties: {
9330
- issues: { enum: ["github", "linear", "jira", "none"] },
9331
+ issues: { enum: ["github", "host", "linear", "jira", "none"] },
9331
9332
  digest: { type: "array", items: { type: "string", pattern: "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$" } }
9332
9333
  }
9333
9334
  },
@@ -9437,6 +9438,119 @@ var config_schema_default = {
9437
9438
  }
9438
9439
  };
9439
9440
 
9441
+ // src/gitlab.mjs
9442
+ import { createHash } from "node:crypto";
9443
+
9444
+ // ../templates/gitlab/dawnfix.gitlab-ci.yml
9445
+ var dawnfix_gitlab_ci_default = __toBinaryNode("IyBTUERYLUxpY2Vuc2UtSWRlbnRpZmllcjogRlNMLTEuMS1BTHYyCiMgRGF3bmZpeCBmb3IgR2l0TGFiIENJIChodHRwczovL2dpdGh1Yi5jb20vZGF3bmZpeC9kYXduZml4KS4gQ29weSB0aGlzIGZpbGUsIG9yIGluY2x1ZGUgaXQgYXQgYQojIHBpbm5lZCByZWxlYXNlIHRhZyB3aXRoIGl0cyBoYXNoIChgbnB4IGRhd25maXggaW5pdCAtLWhvc3QgZ2l0bGFiYCB3cml0ZXMgdGhpcyBmb3IgeW91KToKIwojICAgaW5jbHVkZToKIyAgICAgLSByZW1vdGU6IGh0dHBzOi8vcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbS9kYXduZml4L2Rhd25maXgvdjxWRVJTSU9OPi90ZW1wbGF0ZXMvZ2l0bGFiL2Rhd25maXguZ2l0bGFiLWNpLnltbAojICAgICAgIGludGVncml0eTogc2hhMjU2LTxiYXNlNjQgU0hBLTI1NiBvZiB0aGlzIGZpbGU+CiMKIyBUaGUgaGFzaDogY3VybCAtZnNTTCA8dGhhdCBVUkw+IHwgb3BlbnNzbCBkZ3N0IC1zaGEyNTYgLWJpbmFyeSB8IG9wZW5zc2wgYmFzZTY0IC1BCiMKIyBGb3VyIGpvYnMsIGVhY2ggYSBmcmVzaCBjb250YWluZXIgaG9sZGluZyBvbmUgc2VjcmV0IG9ubHk6CiMgICBkYXduZml4LXJlYWQgICAgIHRoZSBjbG91ZCBPSURDIHRva2VuIChpZF90b2tlbnM6KSwgcmVhZC1vbmx5OyB3cml0ZXMgdGhlIGZpbmRpbmdzCiMgICBkYXduZml4LWFnZW50ICAgIHRoZSBBSSBrZXkgb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zOgogICAgLSBkYXduZml4LXJlYWQKICAgIC0geyBqb2I6IGRhd25maXgtcHVibGlzaCwgb3B0aW9uYWw6IHRydWUgfQogIGVudmlyb25tZW50OiB7IG5hbWU6IGRhd25maXgtcmVwb3J0LCBhY3Rpb246IHByZXBhcmUgfQogIGFsbG93X2ZhaWx1cmU6IHRydWUKICBzY3JpcHQ6CiAgICAjIFdpdGhvdXQgREFXTkZJWF9FTlRFUlBSSVNFX0tFWSB0aGUgcmVwb3J0IHN0YWdlIHByaW50cyBvbmUgbGluZSBhbmQgc2VuZHMgbm90aGluZy4KICAgIC0gKmRhd25maXgtaW5zdGFsbAogICAgLSB8CiAgICAgIHNldCAtLQogICAgICBbICEgLWYgLmRhd25maXgtb3V0L3JlYWQvaW5nZXN0Lmpzb24gXSB8fCBzZXQgLS0gIiRAIiAtLWluZ2VzdCAuZGF3bmZpeC1vdXQvcmVhZC9pbmdlc3QuanNvbgogICAgICBbICEgLWYgLmRhd25maXgtb3V0L3B1Ymxpc2gvb3BlbmVkLmpzb24gXSB8fCBzZXQgLS0gIiRAIiAtLW9wZW5lZCAuZGF3bmZpeC1vdXQvcHVibGlzaC9vcGVuZWQuanNvbgogICAgICBkYXduZml4IHJ1biByZXBvcnQgIiRAIgo=");
9446
+
9447
+ // src/version.mjs
9448
+ var VERSION = true ? "0.4.0" : "0.0.0-dev";
9449
+ var TAG = `v${VERSION}`;
9450
+ var MAJOR_REF = `v${VERSION.split(".")[0]}`;
9451
+ var REPO_URL = "https://github.com/dawnfix/dawnfix";
9452
+ var RAW = `https://raw.githubusercontent.com/dawnfix/dawnfix/${TAG}`;
9453
+
9454
+ // src/gitlab.mjs
9455
+ var TEMPLATE_PATH = "templates/gitlab/dawnfix.gitlab-ci.yml";
9456
+ var TEMPLATE_URL = `${RAW}/${TEMPLATE_PATH}`;
9457
+ var INTEGRITY = `sha256-${createHash("sha256").update(dawnfix_gitlab_ci_default).digest("base64")}`;
9458
+ var JOBS = ["dawnfix-read", "dawnfix-agent", "dawnfix-publish", "dawnfix-report"];
9459
+ var SECRETS = [
9460
+ ["DAWNFIX_AI_API_KEY", "dawnfix-agent", "your AI API key (Claude today)"],
9461
+ ["DAWNFIX_HOST_TOKEN", "dawnfix-publish", "a project access token: role Developer, scopes api and write_repository"],
9462
+ ["DAWNFIX_ENTERPRISE_KEY", "dawnfix-report", "optional, Enterprise only"]
9463
+ ];
9464
+ function includeSnippet() {
9465
+ return ["include:", ` - remote: ${TEMPLATE_URL}`, ` integrity: ${INTEGRITY}`, ""].join("\n");
9466
+ }
9467
+ function hasDawnfix(text) {
9468
+ return /templates\/gitlab\/dawnfix\.gitlab-ci\.yml/.test(text) || new RegExp(`^(${JOBS.join("|")}):`, "m").test(text);
9469
+ }
9470
+ function renderGitlabCi(a) {
9471
+ const cloudVars = a.cloud === "aws" ? " DAWNFIX_AWS_ROLE_ARN, DAWNFIX_AWS_REGION" : " DAWNFIX_GCP_WIF_PROVIDER";
9472
+ return [
9473
+ `# Dawnfix (${REPO_URL}), written by \`npx dawnfix init --host gitlab\`.`,
9474
+ `# The jobs (${JOBS.join(", ")}) are in the template`,
9475
+ `# below, at release ${TAG}.`,
9476
+ "# integrity: GitLab fetches the template and refuses to run the pipeline unless the",
9477
+ "# sha256 of its bytes equals this hash, so you run exactly what was published at that tag.",
9478
+ "# To upgrade, take the new include lines from `npx dawnfix@latest init --host gitlab --dry-run`.",
9479
+ "# The jobs run only in pipelines with DAWNFIX_RUN=true (the schedule); other pipelines are untouched.",
9480
+ "#",
9481
+ "# CI/CD variables (Settings > CI/CD > Variables; `npx dawnfix init` prints the glab lines):",
9482
+ ...SECRETS.map(([name, env, what]) => `# ${name.padEnd(23)} masked, protected, environment ${env}:
9483
+ # ${"".padEnd(23)} ${what}`),
9484
+ `# Not secret:${cloudVars.slice(1)}`,
9485
+ "# Optional: DAWNFIX_AUTONOMY, DAWNFIX_AI_MODEL, DAWNFIX_INSTALL_COMMAND",
9486
+ includeSnippet()
9487
+ ].join("\n");
9488
+ }
9489
+ function gitlabNextSteps(a, repo, { wroteCi }) {
9490
+ const gl = repo.gitlab || { host: "gitlab.com", path: "GROUP/PROJECT" };
9491
+ const name = gl.path.split("/").pop();
9492
+ const selfManaged = gl.host !== "gitlab.com";
9493
+ const b = repo.branch;
9494
+ const out = ["Next steps. You run these; dawnfix never asks for or stores a secret.", ""];
9495
+ let n = 1;
9496
+ if (a.cloud === "aws") {
9497
+ out.push(
9498
+ `${n++}. The read-only AWS role (CloudFormation; logs and alarms read only, trusts only ${gl.path} on ${b}):`,
9499
+ ` ${REPO_URL}/blob/${TAG}/infra/aws/dawnfix-read-role-gitlab.yaml`,
9500
+ ` curl -fsSLO ${RAW}/infra/aws/dawnfix-read-role-gitlab.yaml`,
9501
+ " aws cloudformation deploy --template-file dawnfix-read-role-gitlab.yaml \\",
9502
+ ` --stack-name dawnfix-read-${name} --capabilities CAPABILITY_NAMED_IAM \\`,
9503
+ ` --parameter-overrides ProjectPath=${gl.path} Branch=${b} \\`,
9504
+ ` CreateOIDCProvider=true RoleName=dawnfix-read-${name} LogGroupPrefix='*'${selfManaged ? ` GitLabUrl=https://${gl.host}` : ""}`,
9505
+ " (The account has the GitLab OIDC provider already? CreateOIDCProvider=false and",
9506
+ ` ExistingOIDCProviderArn=<its ARN>: ${REPO_URL}/blob/${TAG}/infra/aws/README.md)`
9507
+ );
9508
+ if (a.awsRoleArn) out.push(` glab variable set DAWNFIX_AWS_ROLE_ARN --value "${a.awsRoleArn}"`);
9509
+ else {
9510
+ out.push(
9511
+ ` glab variable set DAWNFIX_AWS_ROLE_ARN --value "$(aws cloudformation describe-stacks --stack-name dawnfix-read-${name} \\`,
9512
+ ` --query "Stacks[0].Outputs[?OutputKey=='RoleArn'].OutputValue" --output text)"`
9513
+ );
9514
+ }
9515
+ out.push(` glab variable set DAWNFIX_AWS_REGION --value ${a.awsRegion}`);
9516
+ } else {
9517
+ out.push(
9518
+ `${n++}. Workload Identity Federation (roles/logging.viewer only, trusts only ${gl.path} on ${b}):`,
9519
+ ` ${REPO_URL}/blob/${TAG}/infra/gcp/setup-wif-gitlab.sh`,
9520
+ ` curl -fsSLO ${RAW}/infra/gcp/setup-wif-gitlab.sh`,
9521
+ ` bash setup-wif-gitlab.sh --branch ${b}${selfManaged ? ` --gitlab-url https://${gl.host}` : ""} ${a.gcpProject} ${gl.path}`,
9522
+ ` glab variable set DAWNFIX_GCP_WIF_PROVIDER --value "${a.gcpWifProvider || "<the provider name setup-wif-gitlab.sh prints>"}"`
9523
+ );
9524
+ }
9525
+ const [ai, host, ent] = SECRETS;
9526
+ const set = ([v, env]) => `glab variable set ${v} --masked --protected --scope ${env}`;
9527
+ out.push(
9528
+ `${n++}. Secrets: masked, protected, each scoped to the one environment (job) that uses it, so no`,
9529
+ " other job ever holds it. glab reads each value from stdin: `read -rs` keeps it off the screen and",
9530
+ " out of your shell history, and the access token goes from glab to glab without being shown.",
9531
+ ` read -rs V && printf %s "$V" | ${set(ai)}; unset V # ${ai[2]}`,
9532
+ ` glab token create dawnfix --access-level developer --scope api --scope write_repository --duration 365d \\`,
9533
+ ` | tr -d '\\n' | ${set(host)}`,
9534
+ " # the project access token (role Developer, scopes api and write_repository). Or create it in",
9535
+ " # Settings > Access tokens and set it with a read -rs line like the first.",
9536
+ ` read -rs V && printf %s "$V" | ${set(ent)}; unset V # ${ent[2]}`,
9537
+ ` Protected variables reach protected branches only: keep ${b} protected (the default).`,
9538
+ " Recommended: the runner feature flag FF_GIT_URLS_WITHOUT_TOKENS, and the job token limited",
9539
+ " (Settings > CI/CD > Job token permissions). The agent job never clones and unsets every CI token.",
9540
+ `${n++}. ${wroteCi ? "Commit .dawnfix.yml and .gitlab-ci.yml" : "Add the include to .gitlab-ci.yml, commit it with .dawnfix.yml"} on a branch, open a merge request and merge it.`,
9541
+ `${n++}. The schedule (the jobs run only when DAWNFIX_RUN is true; keep the cron equal to .dawnfix.yml):`,
9542
+ " New projects block pipeline variables, which the schedule needs for DAWNFIX_RUN. Allow them for maintainers",
9543
+ " (Settings > CI/CD > Variables > Minimum role to use pipeline variables), or:",
9544
+ ` glab api --method PUT "projects/:fullpath" --field ci_pipeline_variables_minimum_override_role=maintainer`,
9545
+ ` glab schedule create --cron "${a.schedule}" --ref ${b} --description dawnfix --variable "DAWNFIX_RUN:true"`,
9546
+ `${n++}. A first run by hand (or Build > Pipelines > Run pipeline with these variables):`,
9547
+ ` glab ci run --branch ${b} --variables DAWNFIX_RUN:true --variables DAWNFIX_DRY_RUN:true # prints exactly what would leave your account`,
9548
+ ` glab ci run --branch ${b} --variables DAWNFIX_RUN:true --variables DAWNFIX_BASELINE:true # records what is already failing, opens nothing`,
9549
+ `${n++}. npx dawnfix doctor`
9550
+ );
9551
+ return out.join("\n") + "\n";
9552
+ }
9553
+
9440
9554
  // src/repo.mjs
9441
9555
  import { execFileSync } from "node:child_process";
9442
9556
  import { existsSync as existsSync2 } from "node:fs";
@@ -9452,13 +9566,25 @@ function slugFromRemote(url) {
9452
9566
  const m = /github\.com[:/]+([A-Za-z0-9][A-Za-z0-9-]*)\/([A-Za-z0-9_.-]+?)(?:\.git)?\/?$/.exec(url || "");
9453
9567
  return m ? `${m[1]}/${m[2]}` : "";
9454
9568
  }
9569
+ function gitlabFromRemote(url) {
9570
+ const u = String(url || "").trim();
9571
+ const m = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/(.+)$/i.exec(u) || /^(?:[^@/]+@)?([^/:]+):(?!\/\/)(.+)$/.exec(u);
9572
+ if (!m) return null;
9573
+ const host = m[1].toLowerCase();
9574
+ if (host !== "gitlab.com" && !host.includes("gitlab")) return null;
9575
+ const path = m[2].replace(/\/+$/, "").replace(/\.git$/, "").replace(/^\/+/, "");
9576
+ if (!/^[A-Za-z0-9_.][A-Za-z0-9_.-]*(\/[A-Za-z0-9_.][A-Za-z0-9_.-]*)+$/.test(path)) return null;
9577
+ return { host, path };
9578
+ }
9455
9579
  function detectRepo(cwd) {
9456
9580
  const root = git(cwd, "rev-parse", "--show-toplevel");
9457
9581
  if (!root) return null;
9458
- const slug = slugFromRemote(git(root, "remote", "get-url", "origin"));
9582
+ const origin = git(root, "remote", "get-url", "origin");
9583
+ const slug = slugFromRemote(origin);
9584
+ const gitlab = slug ? null : gitlabFromRemote(origin);
9459
9585
  const head = git(root, "symbolic-ref", "--short", "refs/remotes/origin/HEAD").replace(/^origin\//, "");
9460
9586
  const branch = head || git(root, "symbolic-ref", "--short", "HEAD") || "main";
9461
- return { root, slug, branch };
9587
+ return { root, slug, gitlab, branch };
9462
9588
  }
9463
9589
  function detectCommands(root) {
9464
9590
  const has = (f) => existsSync2(join3(root, f));
@@ -9587,13 +9713,6 @@ function validate(schema, value, root = schema, path = "") {
9587
9713
  return errs;
9588
9714
  }
9589
9715
 
9590
- // src/version.mjs
9591
- var VERSION = true ? "0.3.1" : "0.0.0-dev";
9592
- var TAG = `v${VERSION}`;
9593
- var MAJOR_REF = `v${VERSION.split(".")[0]}`;
9594
- var REPO_URL = "https://github.com/dawnfix/dawnfix";
9595
- var RAW = `https://raw.githubusercontent.com/dawnfix/dawnfix/${TAG}`;
9596
-
9597
9716
  // src/doctor.mjs
9598
9717
  var DOCTOR_HELP = `Usage: dawnfix doctor [--dir DIR] [--no-gh]
9599
9718
 
@@ -9601,7 +9720,8 @@ Checks the Dawnfix setup of the repo you are in:
9601
9720
  - .dawnfix.yml is valid (core's schema)
9602
9721
  - .github/workflows/ calls dawnfix/dawnfix/.github/workflows/dawnfix.yml at a pinned
9603
9722
  release (a tag such as v0 or v${VERSION}, or a commit SHA), or holds the copy-it-yourself
9604
- template, with the permissions its jobs need and the cron of .dawnfix.yml
9723
+ template, with the permissions its jobs need and the cron of .dawnfix.yml;
9724
+ on GitLab, .gitlab-ci.yml includes the Dawnfix template (pinned, with integrity)
9605
9725
  - the secrets and variables it uses exist (names only, through gh; --no-gh lists them)
9606
9726
  - Free or Enterprise: whether an Enterprise key is set
9607
9727
  Exit 0 when nothing failed, 1 otherwise.
@@ -9609,6 +9729,8 @@ Exit 0 when nothing failed, 1 otherwise.
9609
9729
  var NEEDED_PERMISSIONS = { contents: "write", "pull-requests": "write", issues: "write", "id-token": "write" };
9610
9730
  var USES = /^dawnfix\/dawnfix\/\.github\/workflows\/dawnfix\.yml(?:@(.*))?$/;
9611
9731
  var ENTERPRISE = ["DAWNFIX_ENTERPRISE_KEY"];
9732
+ var AI_SECRET = "DAWNFIX_AI_API_KEY";
9733
+ var FALLBACK_AI_SECRET = "ANTHROPIC_API_KEY";
9612
9734
  function readYaml(path) {
9613
9735
  return (0, import_yaml.parse)(readFileSync(path, "utf8"));
9614
9736
  }
@@ -9684,7 +9806,7 @@ ${DOCTOR_HELP}`);
9684
9806
  io2.stderr("dawnfix doctor: not inside a git repository\n");
9685
9807
  return 2;
9686
9808
  }
9687
- io2.stdout(`Dawnfix doctor ${VERSION}: ${repo.slug || repo.root}
9809
+ io2.stdout(`Dawnfix doctor ${VERSION}: ${repo.slug || repo.gitlab?.path || repo.root}
9688
9810
 
9689
9811
  `);
9690
9812
  const cfgPath = join4(repo.root, ".dawnfix.yml");
@@ -9709,10 +9831,33 @@ ${DOCTOR_HELP}`);
9709
9831
  }
9710
9832
  }
9711
9833
  const wf = findWorkflow(repo.root);
9712
- let needs = { secrets: ["ANTHROPIC_API_KEY"], vars: [] };
9834
+ const ciPath = join4(repo.root, ".gitlab-ci.yml");
9835
+ const ci = !wf && existsSync3(ciPath) ? readFileSync(ciPath, "utf8") : "";
9836
+ if (ci && hasDawnfix(ci)) {
9837
+ const tag = /dawnfix\/dawnfix\/(v\d+\.\d+\.\d+)\/templates\/gitlab\//.exec(ci)?.[1];
9838
+ const integrity = /integrity:\s*["']?(sha256-[A-Za-z0-9+/=]+)/.exec(ci)?.[1];
9839
+ if (!/templates\/gitlab\/dawnfix\.gitlab-ci\.yml/.test(ci)) ok(".gitlab-ci.yml defines the Dawnfix jobs (a copy of the template)");
9840
+ else if (!tag) bad(".gitlab-ci.yml includes the Dawnfix template but not at a release tag: use the include lines of npx dawnfix init --host gitlab --dry-run");
9841
+ else if (!integrity) warn(`.gitlab-ci.yml includes the Dawnfix template of ${tag} without integrity: (GitLab then runs whatever that URL serves)`);
9842
+ else if (tag === `v${VERSION}` && integrity !== INTEGRITY) bad(`.gitlab-ci.yml: the integrity of the ${tag} template is ${INTEGRITY}, not ${integrity}`);
9843
+ else ok(`.gitlab-ci.yml includes the Dawnfix template of ${tag}, pinned with its integrity`);
9844
+ const sources = (config?.sources || []).map((s) => Object.keys(s)[0]);
9845
+ const vars = [...sources.includes("aws") ? ["DAWNFIX_AWS_ROLE_ARN", "DAWNFIX_AWS_REGION"] : [], ...sources.includes("gcp") ? ["DAWNFIX_GCP_WIF_PROVIDER"] : []];
9846
+ warn("GitLab: check by hand in Settings > CI/CD > Variables (and a pipeline schedule with DAWNFIX_RUN=true):");
9847
+ for (const [name, env, what] of SECRETS) io2.stdout(` secret ${name} (masked, protected, environment ${env}): ${what}
9848
+ `);
9849
+ for (const name of vars) io2.stdout(` variable ${name}
9850
+ `);
9851
+ ok("plan: Free & source available, unless DAWNFIX_ENTERPRISE_KEY is set (hosted reporting, Enterprise)");
9852
+ io2.stdout(failed ? `
9853
+ ${failed} check(s) failed.
9854
+ ` : "\nAll checks passed.\n");
9855
+ return failed ? 1 : 0;
9856
+ }
9857
+ let needs = { secrets: [AI_SECRET], vars: [] };
9713
9858
  let passesKey = false;
9714
9859
  if (!wf) {
9715
- bad("no Dawnfix workflow in .github/workflows/: run npx dawnfix init");
9860
+ bad(`no Dawnfix workflow in .github/workflows/${ci ? " and no Dawnfix include in .gitlab-ci.yml" : ""}: run npx dawnfix init`);
9716
9861
  } else {
9717
9862
  const text = readFileSync(join4(repo.root, wf.file), "utf8");
9718
9863
  if (wf.kind === "caller") {
@@ -9725,16 +9870,19 @@ ${DOCTOR_HELP}`);
9725
9870
  if (perms === "write-all" || missing.length === 0) ok("permissions cover every job (each job narrows them)");
9726
9871
  else bad(`${wf.file} must grant ${missing.join(", ")} (GitHub refuses to start a run whose jobs ask for more than the caller grants)`);
9727
9872
  const wfNeeds = referenced(JSON.stringify(wf.jobDoc.with || {}) + JSON.stringify(wf.jobDoc.secrets || {}));
9728
- needs = { secrets: [.../* @__PURE__ */ new Set(["ANTHROPIC_API_KEY", ...wfNeeds.secrets])], vars: wfNeeds.vars };
9873
+ if (wfNeeds.secrets.includes(FALLBACK_AI_SECRET) && !wfNeeds.secrets.includes(AI_SECRET)) {
9874
+ warn(`${wf.file} passes the deprecated ${FALLBACK_AI_SECRET} (fallback for this release only): pass ${AI_SECRET}: \${{ secrets.${AI_SECRET} }} instead`);
9875
+ }
9876
+ needs = { secrets: [.../* @__PURE__ */ new Set([AI_SECRET, ...wfNeeds.secrets.filter((x) => x !== FALLBACK_AI_SECRET)])], vars: wfNeeds.vars.filter((x) => x !== "DAWNFIX_AI_MODEL") };
9729
9877
  if (wf.jobDoc.secrets === "inherit") {
9730
- warn("secrets: inherit passes every secret of the repo to the workflow; pass ANTHROPIC_API_KEY (and DAWNFIX_ENTERPRISE_KEY) by name");
9731
- needs.secrets = ["ANTHROPIC_API_KEY"];
9878
+ warn(`secrets: inherit passes every secret of the repo to the workflow; pass ${AI_SECRET} (and DAWNFIX_ENTERPRISE_KEY) by name`);
9879
+ needs.secrets = [AI_SECRET];
9732
9880
  }
9733
9881
  passesKey = wf.jobDoc.secrets === "inherit" || ENTERPRISE.some((k) => wfNeeds.secrets.includes(k));
9734
9882
  } else {
9735
9883
  ok(`${wf.file} is the copy-it-yourself template of ${wf.ref}`);
9736
9884
  const r = referenced(text);
9737
- needs = { secrets: ["ANTHROPIC_API_KEY"], vars: r.vars.filter((x) => /ROLE_ARN|WIF_PROVIDER/.test(x)) };
9885
+ needs = { secrets: [AI_SECRET], vars: r.vars.filter((x) => /ROLE_ARN|WIF_PROVIDER/.test(x)) };
9738
9886
  passesKey = true;
9739
9887
  }
9740
9888
  const cron = cronOf(wf.doc);
@@ -9759,7 +9907,8 @@ ${DOCTOR_HELP}`);
9759
9907
  secretNames = s.names;
9760
9908
  for (const name of required) {
9761
9909
  if (s.names.includes(name)) ok(`secret ${name} is set`);
9762
- else bad(`secret ${name} is not set: gh secret set ${name}${name === "ANTHROPIC_API_KEY" ? " (an organization secret works too)" : ""}`);
9910
+ else if (name === AI_SECRET && s.names.includes(FALLBACK_AI_SECRET)) warn(`secret ${FALLBACK_AI_SECRET} is set but deprecated (read as a fallback for this release only): gh secret set ${AI_SECRET} (your AI API key, Claude today)`);
9911
+ else bad(`secret ${name} is not set: gh secret set ${name}${name === AI_SECRET ? " (your AI API key, Claude today; an organization secret works too)" : ""}`);
9763
9912
  }
9764
9913
  for (const name of needs.vars) {
9765
9914
  if (vars.names.includes(name)) ok(`variable ${name} is set`);
@@ -9792,6 +9941,8 @@ ${failed} check(s) failed.
9792
9941
 
9793
9942
  // src/init.mjs
9794
9943
  var import_yaml2 = __toESM(require_dist(), 1);
9944
+ import { readFileSync as readFileSync2 } from "node:fs";
9945
+ import { join as join6 } from "node:path";
9795
9946
  import { createInterface } from "node:readline/promises";
9796
9947
  import { parseArgs as parseArgs3 } from "node:util";
9797
9948
 
@@ -9859,11 +10010,18 @@ function safeWrite(root, rel, text, { overwrite = false } = {}) {
9859
10010
  var INIT_HELP = `Usage: dawnfix init [options]
9860
10011
 
9861
10012
  Sets Dawnfix up in the git repo you are in: shows .dawnfix.yml and
9862
- .github/workflows/dawnfix.yml in full, writes them when you confirm (or with --yes),
9863
- and prints the commands you run next (the read-only cloud role, gh secret set).
9864
- It never asks for a secret and never writes one.
10013
+ .github/workflows/dawnfix.yml (GitHub) or .gitlab-ci.yml (GitLab) in full, writes them
10014
+ when you confirm (or with --yes), and prints the commands you run next (the read-only
10015
+ cloud role, gh secret set or glab variable set). It never asks for a secret and never
10016
+ writes one.
10017
+
10018
+ GitLab: .gitlab-ci.yml includes the template of this release, pinned with its sha256
10019
+ integrity. An existing .gitlab-ci.yml is never changed (not even with --force): init
10020
+ writes .dawnfix.yml and prints the include lines to paste.
9865
10021
 
9866
10022
  Options:
10023
+ --host github|gitlab Where the repo and CI are (default github; gitlab when
10024
+ origin is a GitLab remote)
9867
10025
  --cloud aws|gcp Where the logs are (asked if missing; default aws)
9868
10026
  --aws-region REGION Region of the log groups (default us-east-1)
9869
10027
  --log-group NAME CloudWatch log group to watch (repeatable)
@@ -9875,8 +10033,8 @@ Options:
9875
10033
  --test-command CMD The one command the fix agent may run (plan, draft-pr)
9876
10034
  --install-command CMD Installs dependencies before the fix agent runs (plan, draft-pr)
9877
10035
  --schedule CRON When the read job runs (default "17 * * * *", hourly)
9878
- --ref REF Ref of dawnfix/dawnfix to call (default ${MAJOR_REF}; a tag or commit SHA)
9879
- --enterprise Also send closed-PR events (hosted PR tracking, Enterprise key)
10036
+ --ref REF Ref of dawnfix/dawnfix to call (default ${MAJOR_REF}; a tag or commit SHA; GitHub)
10037
+ --enterprise Also send closed-PR events (hosted PR tracking, Enterprise key; GitHub)
9880
10038
  --dir DIR The repo (default: the current directory)
9881
10039
  --yes, -y Write without asking
9882
10040
  --dry-run Show the files and the next steps; write nothing
@@ -9884,6 +10042,7 @@ Options:
9884
10042
  -h, --help This help
9885
10043
  `;
9886
10044
  var OPTIONS = {
10045
+ host: { type: "string" },
9887
10046
  cloud: { type: "string" },
9888
10047
  "aws-region": { type: "string" },
9889
10048
  "log-group": { type: "string", multiple: true },
@@ -9915,7 +10074,7 @@ function renderConfig(a) {
9915
10074
  "# diagnose: an issue per new error | plan: an issue with the planned fix | draft-pr: draft PRs.",
9916
10075
  `autonomy: ${a.autonomy}`,
9917
10076
  "",
9918
- "# Keep it equal to the cron in .github/workflows/dawnfix.yml. Off the hour.",
10077
+ a.host === "gitlab" ? "# Keep it equal to the cron of the GitLab pipeline schedule. Off the hour." : "# Keep it equal to the cron in .github/workflows/dawnfix.yml. Off the hour.",
9919
10078
  `schedule: ${q(a.schedule)}`,
9920
10079
  "",
9921
10080
  "sources:"
@@ -9935,7 +10094,7 @@ function renderConfig(a) {
9935
10094
  ` command: ${q(a.testCommand)}`
9936
10095
  );
9937
10096
  }
9938
- lines.push("", "report:", " issues: github", "");
10097
+ lines.push("", "report:", ` issues: ${a.host === "gitlab" ? "host" : "github"}`, "");
9939
10098
  return lines.join("\n");
9940
10099
  }
9941
10100
  function renderCaller(a) {
@@ -9958,7 +10117,7 @@ function renderCaller(a) {
9958
10117
  " with:",
9959
10118
  ...withLines.map((l) => ` ${l}`),
9960
10119
  " secrets:",
9961
- " ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}",
10120
+ " DAWNFIX_AI_API_KEY: ${{ secrets.DAWNFIX_AI_API_KEY }} # your AI API key (Claude today)",
9962
10121
  " DAWNFIX_ENTERPRISE_KEY: ${{ secrets.DAWNFIX_ENTERPRISE_KEY }} # optional",
9963
10122
  ""
9964
10123
  ].join("\n");
@@ -9996,7 +10155,7 @@ function nextSteps(a, repo) {
9996
10155
  }
9997
10156
  out.push(
9998
10157
  `${n++}. Secrets (gh asks for the value and does not echo it):`,
9999
- " gh secret set ANTHROPIC_API_KEY",
10158
+ " gh secret set DAWNFIX_AI_API_KEY # your AI API key (Claude today)",
10000
10159
  " gh secret set DAWNFIX_ENTERPRISE_KEY # optional, Enterprise only: turns on hosted reporting",
10001
10160
  `${n++}. Commit both files on a branch, open a pull request and merge it.`,
10002
10161
  `${n++}. gh workflow run dawnfix.yml -f dry_run=true # prints exactly what would leave your account`,
@@ -10025,7 +10184,14 @@ ${INIT_HELP}`);
10025
10184
  }
10026
10185
  const repo = detectRepo(v.dir || io2.cwd);
10027
10186
  if (!repo) return fail(io2, "not inside a git repository: run it at the root of the repo Dawnfix should watch");
10028
- if (!repo.slug) io2.stderr("dawnfix init: no GitHub remote named origin; the next steps say OWNER/REPO\n");
10187
+ const host = v.host || (repo.gitlab ? "gitlab" : "github");
10188
+ if (host === "bitbucket") return fail(io2, "Bitbucket support is coming soon. --host takes github or gitlab today");
10189
+ if (!["github", "gitlab"].includes(host)) return fail(io2, `--host must be github or gitlab, not ${q(host)}`);
10190
+ const gitlab = host === "gitlab";
10191
+ if (gitlab && v.ref) return fail(io2, `--ref is for GitHub; on GitLab the include is pinned to ${TAG} with its integrity hash`);
10192
+ if (gitlab && v.enterprise) return fail(io2, "--enterprise (closed-PR events) is for GitHub; on GitLab the Enterprise key alone turns hosted reporting on");
10193
+ if (gitlab && !repo.gitlab) io2.stderr("dawnfix init: no GitLab remote named origin; the next steps say GROUP/PROJECT\n");
10194
+ if (!gitlab && !repo.slug) io2.stderr("dawnfix init: no GitHub remote named origin; the next steps say OWNER/REPO\n");
10029
10195
  const ask = io2.isTTY && !v.yes ? createInterface({ input: io2.stdin, output: io2.stdoutStream }) : null;
10030
10196
  const prompt = async (text, dflt) => {
10031
10197
  if (!ask) return dflt;
@@ -10034,7 +10200,7 @@ ${INIT_HELP}`);
10034
10200
  };
10035
10201
  try {
10036
10202
  const guess = detectCommands(repo.root);
10037
- const a = { ref: v.ref || MAJOR_REF, enterprise: Boolean(v.enterprise), schedule: v.schedule || "17 * * * *" };
10203
+ const a = { host, ref: v.ref || MAJOR_REF, enterprise: Boolean(v.enterprise), schedule: v.schedule || "17 * * * *" };
10038
10204
  a.cloud = v.cloud || (v["gcp-project"] ? "gcp" : await prompt("Where are the logs: aws or gcp", "aws"));
10039
10205
  if (!["aws", "gcp"].includes(a.cloud)) return fail(io2, `--cloud must be aws or gcp, not ${q(a.cloud)}`);
10040
10206
  a.logGroups = [];
@@ -10064,9 +10230,9 @@ ${INIT_HELP}`);
10064
10230
  const errors = validate(config_schema_default, (0, import_yaml2.parse)(config));
10065
10231
  if (errors.length) return fail(io2, `these settings make an invalid .dawnfix.yml:
10066
10232
  ${errors.map((e) => ` ${e.path}: ${e.message}`).join("\n")}`);
10067
- const files = [
10233
+ let files = [
10068
10234
  [".dawnfix.yml", config],
10069
- [".github/workflows/dawnfix.yml", renderCaller(a)]
10235
+ gitlab ? [".gitlab-ci.yml", renderGitlabCi(a)] : [".github/workflows/dawnfix.yml", renderCaller(a)]
10070
10236
  ];
10071
10237
  let exists;
10072
10238
  try {
@@ -10075,7 +10241,25 @@ ${errors.map((e) => ` ${e.path}: ${e.message}`).join("\n")}`);
10075
10241
  if (e instanceof UnsafePath) return fail(io2, e.message);
10076
10242
  throw e;
10077
10243
  }
10078
- io2.stdout(`Dawnfix ${VERSION} in ${repo.slug || repo.root}. ${v["dry-run"] ? "Dry run: nothing is written." : "These files will be written:"}
10244
+ const keepCi = gitlab && exists.includes(".gitlab-ci.yml");
10245
+ let ciNote = "";
10246
+ if (keepCi) {
10247
+ files = files.filter(([p]) => p !== ".gitlab-ci.yml");
10248
+ exists = exists.filter((p) => p !== ".gitlab-ci.yml");
10249
+ const current = readFileSync2(join6(repo.root, ".gitlab-ci.yml"), "utf8");
10250
+ ciNote = hasDawnfix(current) ? `.gitlab-ci.yml exists and already includes the Dawnfix template (or defines its jobs); it is left as it is.
10251
+ To move it to ${TAG}, replace that include with these lines:
10252
+
10253
+ ${includeSnippet()}
10254
+ ` : `.gitlab-ci.yml exists, so dawnfix does not change it (not even with --force). Paste these lines
10255
+ into it (with a top-level include: already there, add the list item under it):
10256
+
10257
+ ${includeSnippet()}
10258
+ Then set the CI/CD variables below. The jobs run only in pipelines with DAWNFIX_RUN=true.
10259
+ `;
10260
+ }
10261
+ const steps = () => gitlab ? gitlabNextSteps(a, repo, { wroteCi: !keepCi }) : nextSteps(a, repo);
10262
+ io2.stdout(`Dawnfix ${VERSION} in ${(gitlab ? repo.gitlab?.path : repo.slug) || repo.root}. ${v["dry-run"] ? "Dry run: nothing is written." : "These files will be written:"}
10079
10263
  `);
10080
10264
  for (const [p, text] of files) {
10081
10265
  io2.stdout(`
@@ -10083,8 +10267,10 @@ ${errors.map((e) => ` ${e.path}: ${e.message}`).join("\n")}`);
10083
10267
  ${text}`);
10084
10268
  }
10085
10269
  io2.stdout("---\n\n");
10270
+ if (ciNote) io2.stdout(`${ciNote}
10271
+ `);
10086
10272
  if (v["dry-run"]) {
10087
- io2.stdout(nextSteps(a, repo));
10273
+ io2.stdout(steps());
10088
10274
  return 0;
10089
10275
  }
10090
10276
  if (exists.length && !v.force) return fail(io2, `${exists.join(" and ")} exist already; re-run with --force to replace, or run npx dawnfix doctor`);
@@ -10107,7 +10293,7 @@ ${text}`);
10107
10293
  `);
10108
10294
  }
10109
10295
  io2.stdout(`
10110
- ${nextSteps(a, repo)}`);
10296
+ ${steps()}`);
10111
10297
  return 0;
10112
10298
  } finally {
10113
10299
  ask?.close();
@@ -10115,14 +10301,15 @@ ${nextSteps(a, repo)}`);
10115
10301
  }
10116
10302
 
10117
10303
  // src/cli.mjs
10118
- var HELP2 = `Dawnfix ${VERSION}: the AI SRE that runs in your own GitHub Actions.
10304
+ var HELP2 = `Dawnfix ${VERSION}: the AI SRE that runs in your own GitHub Actions or GitLab CI.
10119
10305
  Source available under FSL-1.1-ALv2. https://dawnfix.dev
10120
10306
 
10121
10307
  Usage: npx dawnfix <command> [options]
10122
10308
 
10123
10309
  Commands:
10124
10310
  init Set Dawnfix up in this repo: .dawnfix.yml and a 15-line workflow that calls
10125
- dawnfix/dawnfix/.github/workflows/dawnfix.yml. Shows both before writing.
10311
+ dawnfix/dawnfix/.github/workflows/dawnfix.yml (or, with --host gitlab, a
10312
+ .gitlab-ci.yml that includes the pinned template). Shows both before writing.
10126
10313
  doctor Check the setup: the config, the pinned workflow, secret and variable
10127
10314
  names, Free or Enterprise.
10128
10315
  flare ... Dawnfix Flare: read-only audit of Cloudflare accounts and Workers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dawnfix",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Dawnfix, the AI SRE that runs in your own GitHub Actions: `npx dawnfix init` sets it up in a repo, `npx dawnfix doctor` checks the setup, `npx dawnfix flare` audits Cloudflare. One file, no dependencies.",
5
5
  "keywords": [
6
6
  "ai-sre",