flagdoctor 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -147
- package/dist/index.js +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,181 +1,103 @@
|
|
|
1
1
|
# FlagDoctor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Check that your code agrees with your [Flagsmith](https://flagsmith.com) feature-flag configuration — and see exactly where it doesn't.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
FlagDoctor scans your source code (statically, read-only; it never runs your code), compares the flags it finds with a Flagsmith project and environment, and reports problems with file, line and column. It also maps which files, classes and functions each flag affects.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Planned capabilities
|
|
12
|
-
|
|
13
|
-
- Find code references to Flagsmith feature flags and remote configuration values.
|
|
14
|
-
- Report references missing from the selected Flagsmith project/environment.
|
|
15
|
-
- Detect references to archived flags and statically identifiable type mismatches.
|
|
16
|
-
- Identify unresolved/dynamic references without guessing.
|
|
17
|
-
- Compare flag presence and values across explicitly mapped environments.
|
|
18
|
-
- Identify possible stale flags, with clear warnings about incomplete repository coverage.
|
|
19
|
-
- Produce terminal, JSON and SARIF reports.
|
|
20
|
-
- Visualize repository → file → flag → environment relationships.
|
|
21
|
-
- Later integrate with GitHub/GitLab and CI pull-request checks.
|
|
22
|
-
|
|
23
|
-
## Architecture at a glance
|
|
24
|
-
|
|
25
|
-
- `packages/core` — framework-independent scanning, Flagsmith adapter, snapshot normalization, diagnostic rules and reporters.
|
|
26
|
-
- `packages/shared-types` — shared Zod schemas and TypeScript contracts.
|
|
27
|
-
- `packages/cli` — local developer CLI built with Commander and Ink (`init` and `scan`).
|
|
28
|
-
- `packages/api` — Fastify server, persistence and background scan orchestration (planned).
|
|
29
|
-
- `packages/web` — React + TypeScript dashboard (planned).
|
|
30
|
-
|
|
31
|
-
The CLI, dashboard and CI must share the same core engine. See `docs/ARCHITECTURE.md`.
|
|
32
|
-
|
|
33
|
-
## Development status
|
|
34
|
-
|
|
35
|
-
Phase 0 (Project Foundation) is complete: the npm workspace, strict shared TypeScript configuration, thin package scaffolds, foundational shared contracts, quality tooling and safe environment conventions are in place. See `docs/ROADMAP.md` and `docs/phases/PHASE_0_FOUNDATION.md`.
|
|
36
|
-
|
|
37
|
-
Phase 1A (local source provider + Flagsmith snapshot foundation) is complete: `@flagdoctor/core` provides a read-only `LocalProvider` and a Flagsmith Management API adapter that returns normalized snapshots.
|
|
38
|
-
|
|
39
|
-
Phase 1B (static scanner) is complete: `@flagdoctor/core` exposes `scanSources()`, a keyword prefilter plus Tree-sitter AST extractors for JavaScript/TypeScript and Java, producing canonical `FlagReference` records.
|
|
40
|
-
|
|
41
|
-
Phase 1C (Diagnostic rules, CLI and reports) is complete: `flagdoctor init` and `flagdoctor scan` are available; FD001, FD002, FD004 and FD006 are evaluated deterministically in core; terminal and JSON reporters consume the same `Finding[]` data. Dashboard, server, persistence and later-phase rules remain out of scope.
|
|
42
|
-
|
|
43
|
-
Every scan also builds a flag dependency map — the files, classes and functions each flag affects — independent of whether a finding was raised. `flagdoctor graph` visualizes it in the terminal (or as JSON); the web dashboard's **Flag Dependencies** page (`/dependencies`) visualizes the same data from an imported report. `flagdoctor analyze` compiles the dependency map and findings into a compact context and sends it to an LLM via Groq to look for misconfigurations a deterministic rule cannot catch; its findings come back tagged `FDLLM` and merge into the same report.
|
|
44
|
-
|
|
45
|
-
## Prerequisites
|
|
46
|
-
|
|
47
|
-
- Node.js 22.12 or newer (validated on Node.js 24).
|
|
48
|
-
- npm 10 or newer (validated on npm 11). npm ships with Node.js; no global package-manager tooling is required.
|
|
49
|
-
|
|
50
|
-
## Local development
|
|
51
|
-
|
|
52
|
-
Run these commands from the repository root:
|
|
9
|
+
Requires Node.js 22.12 or newer.
|
|
53
10
|
|
|
54
11
|
```bash
|
|
55
|
-
npm install
|
|
56
|
-
|
|
57
|
-
npm run typecheck # typecheck every package without emitting files
|
|
58
|
-
npm run lint # lint TypeScript sources with ESLint
|
|
59
|
-
npm run test # run all Vitest smoke tests
|
|
60
|
-
npm run format:check # check formatting with Prettier
|
|
61
|
-
npm run format # apply Prettier formatting
|
|
62
|
-
npm run clean # remove build outputs
|
|
12
|
+
npm install -g flagdoctor
|
|
13
|
+
flagdoctor --help
|
|
63
14
|
```
|
|
64
15
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
npm run flagdoctor -- init
|
|
69
|
-
npm run flagdoctor -- scan --env development
|
|
70
|
-
npm run flagdoctor -- scan --env production
|
|
71
|
-
npm run flagdoctor -- scan --env production --format json
|
|
72
|
-
|
|
73
|
-
# Which files, classes and functions each flag affects (ASCII tree, or --format json)
|
|
74
|
-
npm run flagdoctor -- graph --env production
|
|
75
|
-
npm run flagdoctor -- graph --env production --flag some_flag_name
|
|
76
|
-
|
|
77
|
-
# Ask an LLM (Groq) to review the dependency map + findings for misconfigurations
|
|
78
|
-
# Requires GROQ_API_KEY in the environment or .env; see .env.example.
|
|
79
|
-
npm run flagdoctor -- analyze --env production
|
|
80
|
-
```
|
|
16
|
+
Or run it without installing: `npx flagdoctor scan --env production`.
|
|
81
17
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
### CLI, API and dashboard stay in sync
|
|
85
|
-
|
|
86
|
-
Run the API (`npm run api:migrate`, then `npm run api:dev`) and the web app (`npm run web:dev`), then:
|
|
18
|
+
## Quick start
|
|
87
19
|
|
|
88
20
|
```bash
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
npm run flagdoctor -- scan --env production # report is uploaded; the dashboard shows it
|
|
92
|
-
npm run flagdoctor -- graph --env production # flag dependency map is uploaded too
|
|
93
|
-
npm run flagdoctor -- analyze --env production
|
|
94
|
-
npm run flagdoctor -- scan --env production --no-sync # skip the upload
|
|
95
|
-
```
|
|
21
|
+
# 1. Sign in to your FlagDoctor dashboard (opens the browser; approve the code shown)
|
|
22
|
+
flagdoctor login --api-url https://your-flagdoctor.example.com
|
|
96
23
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
- **What is stored.** Each upload is one row in `scans` (summary columns plus the full report as JSONB: findings, diagnostics and the flag dependency map). Tokens and source snippets are never included.
|
|
101
|
-
- **Web pages read the API.** Dashboard, Scan History, Scan Results (with delete), FlagRadar (the flag dependency graph and list; `/dependencies` redirects there), Environment Comparison, Repositories and Settings load from the active project. New Scan can import a report file or run a scan on the server against a saved local codebase (`FLAGDOCTOR_SCAN_ROOT` bounds which directories the API may read; the Flagsmith token stays server-side).
|
|
24
|
+
# 2. In your repository: create flagdoctor.yaml (guided; picks your Flagsmith project and environments)
|
|
25
|
+
cd my-app
|
|
26
|
+
flagdoctor init
|
|
102
27
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
| CLI (bearer) | `POST /api/v1/cli/scans`, `GET`/`PUT /api/v1/cli/project-config` |
|
|
106
|
-
| Web (session + CSRF) | `GET /api/v1/workspaces/:w/projects/:p/scans`, `GET`/`DELETE .../scans/:id`, `POST .../scans/import`, `POST .../scans/run`, `GET .../dependencies`, `DELETE .../codebases/:id` |
|
|
28
|
+
# 3. Provide your Flagsmith Organisation API token (never written to flagdoctor.yaml)
|
|
29
|
+
export FLAGSMITH_TOKEN=... # PowerShell: $env:FLAGSMITH_TOKEN = "..."
|
|
107
30
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
31
|
+
# 4. Scan
|
|
32
|
+
flagdoctor scan --env production
|
|
33
|
+
```
|
|
111
34
|
|
|
112
|
-
|
|
35
|
+
The report is uploaded to your dashboard automatically after `login`. Without `login`, FlagDoctor works fully offline from the dashboard: it just prints the report.
|
|
113
36
|
|
|
114
|
-
|
|
37
|
+
## Commands
|
|
115
38
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
-
|
|
39
|
+
| Command | What it does |
|
|
40
|
+
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------- |
|
|
41
|
+
| `flagdoctor login [--api-url <url>]` | Authorize this machine through the browser. Stores a project-scoped credential outside your repo. |
|
|
42
|
+
| `flagdoctor whoami` | Show the signed-in project. |
|
|
43
|
+
| `flagdoctor init [--ci] [--force]` | Create `flagdoctor.yaml`. `--ci` writes a starter file without prompts. |
|
|
44
|
+
| `flagdoctor scan --env <alias>` | Scan the repository and report findings. |
|
|
45
|
+
| `flagdoctor graph --env <alias> [--flag <name>]` | Show which files, classes and functions each flag affects. |
|
|
46
|
+
| `flagdoctor analyze --env <alias>` | AI review of the findings and dependency map (needs `GROQ_API_KEY`). |
|
|
120
47
|
|
|
121
|
-
|
|
48
|
+
Common options: `--format json` (machine-readable report), `--root <path>` (scan another directory), `-c, --config <path>`, `--ci` (plain output), `--no-sync` (don't upload).
|
|
122
49
|
|
|
123
|
-
|
|
50
|
+
## What it reports
|
|
124
51
|
|
|
125
|
-
|
|
52
|
+
| Rule | Meaning |
|
|
53
|
+
| ----- | ------------------------------------------------------------------------------- |
|
|
54
|
+
| FD001 | Code references a flag that doesn't exist in the Flagsmith environment (error). |
|
|
55
|
+
| FD002 | Code references an archived flag (error). |
|
|
56
|
+
| FD004 | A flag's value type doesn't match how the code reads it (warning). |
|
|
57
|
+
| FD006 | A flag name can't be resolved statically — reported, never guessed (info). |
|
|
58
|
+
| FDLLM | AI-suggested hints from `analyze`; low confidence, never fail a build. |
|
|
126
59
|
|
|
127
|
-
|
|
60
|
+
A disabled flag is not an error. JavaScript/TypeScript and Java are supported (Flagsmith JS and Java SDKs).
|
|
128
61
|
|
|
129
|
-
##
|
|
62
|
+
## Use in CI
|
|
130
63
|
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
├── core/ # @flagdoctor/core — scanner, adapter, rules and reporters
|
|
134
|
-
├── shared-types/ # @flagdoctor/shared-types — canonical schemas/types
|
|
135
|
-
├── cli/ # @flagdoctor/cli — Commander + Ink CLI
|
|
136
|
-
├── api/ # @flagdoctor/api — placeholder (Phase 2)
|
|
137
|
-
└── web/ # @flagdoctor/web — placeholder (Phase 2)
|
|
64
|
+
```bash
|
|
65
|
+
flagdoctor scan --env production --ci --format json > flagdoctor-report.json
|
|
138
66
|
```
|
|
139
67
|
|
|
140
|
-
|
|
68
|
+
Exit codes: `0` clean (warnings/info only), `1` confirmed errors, `2` configuration, credential or API failure, or an incomplete scan.
|
|
141
69
|
|
|
142
|
-
##
|
|
70
|
+
## Configuration
|
|
143
71
|
|
|
144
|
-
|
|
145
|
-
- `FlagsmithAdapter` reads only Management API GET routes (`/projects/`, `/environments/`, `/projects/{id}/features/`, `/environments/{api_key}/featurestates/`) and normalizes them into `FlagSnapshot`.
|
|
146
|
-
- `flagdoctor.yaml` accepts only `repository.root/include/exclude` and `flagsmith.baseUrl/project` plus an explicit `flagsmith.environments` alias map (or a single `environment`). Secret-looking keys are rejected; supply the Organisation API token through `FLAGSMITH_TOKEN` in the environment only.
|
|
147
|
-
- Raw API DTOs stay private to the adapter. Errors are typed and token values are redacted from messages and serialized errors.
|
|
72
|
+
`flagdoctor.yaml` (created by `init`) holds only non-secret settings:
|
|
148
73
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
74
|
+
```yaml
|
|
75
|
+
version: 1
|
|
76
|
+
repository:
|
|
77
|
+
root: .
|
|
78
|
+
include: []
|
|
79
|
+
exclude: []
|
|
80
|
+
flagsmith:
|
|
81
|
+
baseUrl: https://api.flagsmith.com/api/v1
|
|
82
|
+
project: 12345
|
|
83
|
+
environments:
|
|
84
|
+
production: <environment-api-key>
|
|
85
|
+
development: <environment-api-key>
|
|
86
|
+
```
|
|
157
87
|
|
|
158
|
-
|
|
159
|
-
- FD004 is SDK-aware: it is evaluated only for the verified pairs `flagsmith-js-client + getValue` and `flagsmith-java-client + getFeatureValue`. Enabled-state checks (`hasFeature`, `isFeatureEnabled`), object-returning `getFlag`, registered wrappers and unknown SDK/method pairs never produce type-mismatch findings; wrapper configs cannot claim a reserved built-in SDK identity.
|
|
160
|
-
- A failed, partial or malformed snapshot produces exit code `2` with **no** rule findings, so missing-flag findings cannot be inferred from absent data.
|
|
161
|
-
- Source parse/read errors mark the report `status: "partial"` (preserving diagnostics) and return exit code `2`; a clean completed scan is required for exit code `0`.
|
|
162
|
-
- `--env` selects a configured environment alias and resolves it through `flagsmith.environments`; branch names are never assumed to equal Flagsmith environments.
|
|
163
|
-
- `formatJsonReport()` and `formatTerminalReport()` both consume the same schema-validated `ScanReport`/`Finding[]`; JSON is versioned (`schemaVersion: 1`) and includes stable finding IDs.
|
|
164
|
-
- `--ci`, JSON output and non-TTY execution never prompt; Ink is used only for interactive TTY terminal output.
|
|
88
|
+
Secrets come from the environment only:
|
|
165
89
|
|
|
166
|
-
|
|
90
|
+
| Variable | Used for |
|
|
91
|
+
| ------------------------ | -------------------------------------------------------------------------------------------- |
|
|
92
|
+
| `FLAGSMITH_TOKEN` | Flagsmith Organisation API token (required for `scan`, `graph`, `analyze`). |
|
|
93
|
+
| `GROQ_API_KEY` | Optional, enables `analyze`. Only findings and the dependency map are sent — no source code. |
|
|
94
|
+
| `FLAGDOCTOR_API_URL` | Dashboard server to sync with (alternative to `login --api-url`). |
|
|
95
|
+
| `FLAGDOCTOR_NO_SPLASH=1` | Turn off the welcome animation. |
|
|
167
96
|
|
|
168
|
-
|
|
97
|
+
A `.env` file in the working directory is also read.
|
|
169
98
|
|
|
170
|
-
##
|
|
99
|
+
## Privacy and safety
|
|
171
100
|
|
|
172
|
-
-
|
|
173
|
-
-
|
|
174
|
-
-
|
|
175
|
-
- `docs/ARCHITECTURE.md` — architecture and package responsibilities.
|
|
176
|
-
- `docs/ROADMAP.md` — delivery phases.
|
|
177
|
-
- `docs/DECISIONS.md` — important engineering decisions.
|
|
178
|
-
- `docs/phases/PHASE_0_FOUNDATION.md` — Phase 0 acceptance criteria.
|
|
179
|
-
- `docs/MANUAL_SMOKE_TEST.md` — optional real-Flagsmith-account smoke test (no tokens included).
|
|
180
|
-
- `docs/phases/PHASE_1_CLI_MVP.md` — Phase 1 CLI MVP specification.
|
|
181
|
-
- `prompts/` — phase implementation prompts (1A complete; 1B and 1C planned).
|
|
101
|
+
- Scans are static and read-only; repository code is never executed.
|
|
102
|
+
- Tokens are never printed, logged, or written to `flagdoctor.yaml`.
|
|
103
|
+
- Nothing in Flagsmith is modified.
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createRequire as __cr } from 'node:module'; const require = __cr(import
|
|
|
4
4
|
// packages/cli/dist/index.js
|
|
5
5
|
import { jsx as _jsx8 } from "react/jsx-runtime";
|
|
6
6
|
import { spawn as spawn2 } from "node:child_process";
|
|
7
|
-
import { readFileSync } from "node:fs";
|
|
7
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
8
8
|
import { access as access2, writeFile as writeFile4 } from "node:fs/promises";
|
|
9
9
|
import path4 from "node:path";
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
@@ -4219,7 +4219,17 @@ ${formatTerminalReport(enriched)}
|
|
|
4219
4219
|
return 2;
|
|
4220
4220
|
}
|
|
4221
4221
|
}
|
|
4222
|
-
|
|
4222
|
+
function isEntryPoint() {
|
|
4223
|
+
const entry = process.argv[1];
|
|
4224
|
+
if (entry === void 0)
|
|
4225
|
+
return false;
|
|
4226
|
+
try {
|
|
4227
|
+
return import.meta.url === pathToFileURL(realpathSync(entry)).href;
|
|
4228
|
+
} catch {
|
|
4229
|
+
return import.meta.url === pathToFileURL(entry).href;
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
var invokedDirectly = isEntryPoint();
|
|
4223
4233
|
if (invokedDirectly) {
|
|
4224
4234
|
runCli(process.argv.slice(2)).then((code) => {
|
|
4225
4235
|
process.exitCode = code;
|