@gate-forge/cli 0.9.0 → 0.10.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.
- package/README.md +12 -5
- package/dist/cache-exclusions.d.ts +20 -13
- package/dist/cache-exclusions.d.ts.map +1 -1
- package/dist/cache-exclusions.js +47 -33
- package/dist/cache-exclusions.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +11 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/adopt.d.ts +3 -2
- package/dist/commands/adopt.d.ts.map +1 -1
- package/dist/commands/adopt.js +38 -5
- package/dist/commands/adopt.js.map +1 -1
- package/dist/commands/blocking.d.ts +20 -1
- package/dist/commands/blocking.d.ts.map +1 -1
- package/dist/commands/blocking.js +105 -10
- package/dist/commands/blocking.js.map +1 -1
- package/dist/commands/check.d.ts +34 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +93 -7
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/classify.d.ts +1 -0
- package/dist/commands/classify.d.ts.map +1 -1
- package/dist/commands/classify.js +230 -14
- package/dist/commands/classify.js.map +1 -1
- package/dist/commands/common.d.ts +6 -1
- package/dist/commands/common.d.ts.map +1 -1
- package/dist/commands/common.js +8 -1
- package/dist/commands/common.js.map +1 -1
- package/dist/commands/enforcement.d.ts +9 -1
- package/dist/commands/enforcement.d.ts.map +1 -1
- package/dist/commands/enforcement.js +448 -13
- package/dist/commands/enforcement.js.map +1 -1
- package/dist/commands/init.d.ts +20 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +296 -93
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/migrate.d.ts +14 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +177 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/next.d.ts.map +1 -1
- package/dist/commands/next.js +7 -2
- package/dist/commands/next.js.map +1 -1
- package/dist/commands/pre-commit.d.ts.map +1 -1
- package/dist/commands/pre-commit.js +62 -19
- package/dist/commands/pre-commit.js.map +1 -1
- package/dist/commands/tests.d.ts.map +1 -1
- package/dist/commands/tests.js +54 -24
- package/dist/commands/tests.js.map +1 -1
- package/dist/docs-exclusions.d.ts +32 -5
- package/dist/docs-exclusions.d.ts.map +1 -1
- package/dist/docs-exclusions.js +60 -26
- package/dist/docs-exclusions.js.map +1 -1
- package/dist/evidence-config-text.d.ts +57 -0
- package/dist/evidence-config-text.d.ts.map +1 -0
- package/dist/evidence-config-text.js +263 -0
- package/dist/evidence-config-text.js.map +1 -0
- package/dist/execution.d.ts +51 -8
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +61 -29
- package/dist/execution.js.map +1 -1
- package/dist/gateforge-owned.d.ts +30 -5
- package/dist/gateforge-owned.d.ts.map +1 -1
- package/dist/gateforge-owned.js +136 -18
- package/dist/gateforge-owned.js.map +1 -1
- package/dist/git-hooks.d.ts.map +1 -1
- package/dist/git-hooks.js +15 -0
- package/dist/git-hooks.js.map +1 -1
- package/dist/input-snapshot.d.ts.map +1 -1
- package/dist/input-snapshot.js +2 -6
- package/dist/input-snapshot.js.map +1 -1
- package/dist/legacy-exclusion-paths.d.ts +28 -0
- package/dist/legacy-exclusion-paths.d.ts.map +1 -0
- package/dist/legacy-exclusion-paths.js +48 -0
- package/dist/legacy-exclusion-paths.js.map +1 -0
- package/dist/providers.d.ts +54 -0
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +101 -0
- package/dist/providers.js.map +1 -1
- package/dist/staged-candidate.d.ts.map +1 -1
- package/dist/staged-candidate.js +2 -1
- package/dist/staged-candidate.js.map +1 -1
- package/dist/trusted-policy.d.ts.map +1 -1
- package/dist/trusted-policy.js +3 -2
- package/dist/trusted-policy.js.map +1 -1
- package/guides/CONNECT-YOUR-PROJECT.md +64 -0
- package/guides/QUICKSTART.md +68 -15
- package/guides/REFERENCE.md +229 -33
- package/guides/TEST-ENVIRONMENT.md +36 -0
- package/guides/UPGRADE-0.8-to-0.9.md +9 -1
- package/guides/UPGRADE-0.9-to-0.10.md +137 -0
- package/package.json +10 -10
package/dist/commands/init.js
CHANGED
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
* classification file to fill in. Effective classifications are computed
|
|
16
16
|
* from detector signals on every run.
|
|
17
17
|
*/
|
|
18
|
+
import { spawnSync } from 'node:child_process';
|
|
18
19
|
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
19
20
|
import { randomUUID } from 'node:crypto';
|
|
20
21
|
import { createInterface } from 'node:readline/promises';
|
|
21
22
|
import { isAbsolute, join } from 'node:path';
|
|
22
23
|
import { parse as parseYaml, parseDocument, isSeq as isYamlSeq, isMap as isYamlMap } from 'yaml';
|
|
23
|
-
import { ClassificationPolicySchema, PolicyFileSchema, loadConfig, parseConfig, serializeBaseline, strictCapabilityGaps, } from '@gate-forge/core';
|
|
24
|
+
import { ClassificationPolicySchema, PolicyFileSchema, loadConfig, parseConfig, resolveStrictnessMode, serializeBaseline, strictCapabilityGaps, } from '@gate-forge/core';
|
|
24
25
|
import { DEFAULT_PLANES_CONFIG, PLANES_CONFIG_PATH, createSqlalchemyDetector, parsePlanesConfigText, PACK_VERSION as PACK_SQLALCHEMY_VERSION, } from '@gate-forge/pack-sqlalchemy';
|
|
25
26
|
import { collectRoutePlaneFacts, proposeRouteFolderPlanes, } from '../route-plane-proposals.js';
|
|
26
27
|
import { PACK_VERSION as PACK_FASTAPI_VERSION } from '@gate-forge/pack-fastapi';
|
|
@@ -31,16 +32,18 @@ import { parseArgs, stringFlag } from '../args.js';
|
|
|
31
32
|
import { recordInitPath, writeLine } from '../io.js';
|
|
32
33
|
import { UsageError } from '../errors.js';
|
|
33
34
|
import { languageDefaultPlugins, recommendPlugins, renderScanBlock, scanRepo } from '../repo-scan.js';
|
|
34
|
-
import { rejectUnknownFlags } from './common.js';
|
|
35
|
+
import { rejectUnknownFlags, VERSION } from './common.js';
|
|
35
36
|
import { expandScanPaths } from '../glob.js';
|
|
36
37
|
import { gitIgnoredPaths } from '../git-ignored.js';
|
|
37
38
|
import { inferPlanesConfig } from '../planes-inference.js';
|
|
38
39
|
import { hasGateforgeMarker, installCommitHook, installPrePushHook, writeStandaloneGateScript } from '../git-hooks.js';
|
|
39
40
|
import { appendPreCommitHook, ensureHookScript, engineRootFromInvocation, detectCiProvider, writeGitlabCiTemplate as writeSharedGitlabCiTemplate, writeServerProtectionInstructions, } from './blocking.js';
|
|
40
41
|
import { trustedPolicyDigestForConfig } from '../execution.js';
|
|
41
|
-
import { DOCS_EXCLUSIONS_GUARANTEE,
|
|
42
|
-
import { CACHE_EXCLUSIONS_GUARANTEE,
|
|
43
|
-
import {
|
|
42
|
+
import { DOCS_EXCLUSIONS_GUARANTEE, DOCS_EXCLUSIONS_SOURCE, loadDocsExclusions, validateRequestedDocsFolders, } from '../docs-exclusions.js';
|
|
43
|
+
import { CACHE_EXCLUSIONS_GUARANTEE, CACHE_EXCLUSIONS_SOURCE, loadCacheExclusions, validateRequestedCacheFiles, } from '../cache-exclusions.js';
|
|
44
|
+
import { setEvidenceExclude, declaresEvidenceExclude } from '../evidence-config-text.js';
|
|
45
|
+
import { legacyExclusionPathsPresent, rejectLegacyExclusions } from '../legacy-exclusion-paths.js';
|
|
46
|
+
import { ENGINE_STATE_IGNORE_COMMENT, ENGINE_STATE_IGNORE_ENTRIES, } from '../gateforge-owned.js';
|
|
44
47
|
import { CHOOSE_ANOTHER_GOAL_ADVICE, INIT_PRESETS, isInitPresetName, parseGoalAnswer, renderGoalQuestion, renderPresetTable, renderPresetSummary, } from './init-presets.js';
|
|
45
48
|
import { BEHAVIOR_NAMESPACES, behaviorPackEvidence, behaviorSkeletonExamples, detectBehaviorPacks, parseBehaviorPacks, } from '../behavior-setup.js';
|
|
46
49
|
export const INIT_USAGE = '[--preset light|normal|strict] [--explain-presets] [--no-scan] [--proof overlay|observe] ' +
|
|
@@ -123,6 +126,49 @@ function pluginsTemplate(pluginIds) {
|
|
|
123
126
|
.map((id) => ` - id: ${id}\n version: '${BUNDLED_PLUGIN_VERSIONS[id]}'\n transport: in-process\n module: '${BUNDLED_PLUGIN_MODULES[id]}'`)
|
|
124
127
|
.join('\n');
|
|
125
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* The ONE line that tells the owner how to install the enabled bundled
|
|
131
|
+
* packs, or null when there is nothing left to install.
|
|
132
|
+
*
|
|
133
|
+
* init writes `plugins:` entries for packs that are only resolvable from
|
|
134
|
+
* the repository's own `node_modules`, and the setup guide asks for them
|
|
135
|
+
* as direct dependencies AT THE CLI'S OWN VERSION — so init, which
|
|
136
|
+
* decided which packs to enable, is the only place that knows the exact
|
|
137
|
+
* list. It never runs npm: the owner decides when the install happens
|
|
138
|
+
* (and commits it on its own, before the setup files).
|
|
139
|
+
*
|
|
140
|
+
* Args:
|
|
141
|
+
* cwd: absolute repository root.
|
|
142
|
+
* pluginIds: the bundled plugin ids init enabled.
|
|
143
|
+
*
|
|
144
|
+
* Returns:
|
|
145
|
+
* string | null: the install line, or null when every enabled pack is
|
|
146
|
+
* already declared (or nothing bundled was enabled).
|
|
147
|
+
*/
|
|
148
|
+
function packInstallLine(cwd, pluginIds) {
|
|
149
|
+
const manifestPath = join(cwd, 'package.json');
|
|
150
|
+
const declared = new Set();
|
|
151
|
+
if (existsSync(manifestPath)) {
|
|
152
|
+
try {
|
|
153
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
154
|
+
for (const section of [manifest.dependencies, manifest.devDependencies]) {
|
|
155
|
+
for (const name of Object.keys(section ?? {}))
|
|
156
|
+
declared.add(name);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// An unreadable manifest is not init's to fix; the line still names
|
|
161
|
+
// exactly what the config now expects the owner to install.
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const missing = pluginIds
|
|
165
|
+
.map((id) => BUNDLED_PLUGIN_MODULES[id])
|
|
166
|
+
.filter((moduleName) => moduleName !== undefined && !declared.has(moduleName));
|
|
167
|
+
if (missing.length === 0)
|
|
168
|
+
return null;
|
|
169
|
+
const targets = missing.map((moduleName) => `${moduleName}@${VERSION}`).join(' ');
|
|
170
|
+
return `install the enabled packs as direct dependencies (same version as the CLI): npm i -D ${targets}`;
|
|
171
|
+
}
|
|
126
172
|
/**
|
|
127
173
|
* Adds the requested bundled detectors to an existing `.gateforge.yml`
|
|
128
174
|
* without touching anything else in the owner's file.
|
|
@@ -286,7 +332,7 @@ policies:
|
|
|
286
332
|
* unconfigured detector fails every run closed, and task is opt-in —
|
|
287
333
|
* its contracts grade only with a configured `queueObserver`.
|
|
288
334
|
*/
|
|
289
|
-
function classificationPolicyTemplate(languages, pluginIds) {
|
|
335
|
+
export function classificationPolicyTemplate(languages, pluginIds) {
|
|
290
336
|
const selected = new Set(pluginIds);
|
|
291
337
|
const taskSelected = selected.has('gateforge.pack-task');
|
|
292
338
|
const httpSelected = selected.has('gateforge.pack-http');
|
|
@@ -613,42 +659,158 @@ async function resolveRecommended(io, options) {
|
|
|
613
659
|
rl.close();
|
|
614
660
|
}
|
|
615
661
|
}
|
|
662
|
+
/**
|
|
663
|
+
* The wiring flags each preset already implies (R1-1): a flag the
|
|
664
|
+
* preset implies is a no-op — the preset the owner named is the
|
|
665
|
+
* goal that applies. `light` wires nothing, so it implies no flag
|
|
666
|
+
* and no `--no-*` flag can contradict it.
|
|
667
|
+
*/
|
|
668
|
+
const PRESET_IMPLIED_FLAGS = {
|
|
669
|
+
light: [],
|
|
670
|
+
normal: ['pre-commit', 'ci'],
|
|
671
|
+
strict: ['blocking', 'pre-commit', 'ci', 'strict-e2e'],
|
|
672
|
+
};
|
|
673
|
+
/** What one wiring flag decides, named in the contradiction error. */
|
|
674
|
+
const PRESET_FLAG_THING = {
|
|
675
|
+
blocking: 'the gate wiring',
|
|
676
|
+
'pre-commit': 'the pre-commit hook',
|
|
677
|
+
ci: 'the CI job',
|
|
678
|
+
'strict-e2e': 'strict E2E',
|
|
679
|
+
};
|
|
680
|
+
/**
|
|
681
|
+
* The preset/flag contradiction (R1-1): null when every given flag
|
|
682
|
+
* is consistent with the preset (implied by it, or a `--no-*` for
|
|
683
|
+
* something the preset does not wire — both are no-ops); the
|
|
684
|
+
* conflicting flag otherwise: a positive wiring flag the preset
|
|
685
|
+
* does NOT wire, or a `--no-*` flag for something it DOES wire.
|
|
686
|
+
* Both spellings ask for two different goals at once, so the owner
|
|
687
|
+
* must drop one of them — silently overriding the named preset
|
|
688
|
+
* (the old "is ignored" note) hid the choice instead.
|
|
689
|
+
*/
|
|
690
|
+
function presetFlagConflict(preset, options) {
|
|
691
|
+
const implied = PRESET_IMPLIED_FLAGS[preset];
|
|
692
|
+
for (const flag of ['blocking', 'pre-commit', 'ci', 'strict-e2e']) {
|
|
693
|
+
const wired = implied.includes(flag);
|
|
694
|
+
if (options[flag] === true && !wired)
|
|
695
|
+
return flag;
|
|
696
|
+
if (wired && options[`no-${flag}`] === true)
|
|
697
|
+
return `no-${flag}`;
|
|
698
|
+
}
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* The config settings a run REQUESTS that an existing
|
|
703
|
+
* `.gateforge.yml` already owns with a different value
|
|
704
|
+
* (R1-2): a chosen preset's strictness `mode` and
|
|
705
|
+
* `enforcement.strictE2E`, plus the `--strict-e2e` and
|
|
706
|
+
* `--unmatched-routes` flags. init never rewrites an
|
|
707
|
+
* existing config, so a differing request is a usage error
|
|
708
|
+
* the owner resolves by setting the key in the file — one
|
|
709
|
+
* line per differing key, BEFORE anything is written.
|
|
710
|
+
*
|
|
711
|
+
* Absent keys compare as their effective values (`mode`
|
|
712
|
+
* defaults to `strict`, `strictE2E` to false, absent
|
|
713
|
+
* `unmatchedRoutes` grades advisories — `warn`), so a
|
|
714
|
+
* request that matches what the file already does is not a
|
|
715
|
+
* conflict. Only an explicit `--preset` names a request:
|
|
716
|
+
* the non-interactive auto-chosen light goal and a
|
|
717
|
+
* terminal answer to the goal question are default
|
|
718
|
+
* behavior paths, not requests — a headless re-run of
|
|
719
|
+
* `init` on an initialized repository must keep working.
|
|
720
|
+
*/
|
|
721
|
+
function requestedConfigConflicts(cwd, options, goal) {
|
|
722
|
+
const conflicts = [];
|
|
723
|
+
if (!existsSync(join(cwd, '.gateforge.yml')))
|
|
724
|
+
return conflicts;
|
|
725
|
+
// An unparseable document is today's path (the draft load
|
|
726
|
+
// below rethrows or falls back); there is no value to
|
|
727
|
+
// compare a request against, so nothing is a conflict.
|
|
728
|
+
let existing;
|
|
729
|
+
try {
|
|
730
|
+
existing = loadConfig(join(cwd, '.gateforge.yml'));
|
|
731
|
+
}
|
|
732
|
+
catch {
|
|
733
|
+
return conflicts;
|
|
734
|
+
}
|
|
735
|
+
const requests = [];
|
|
736
|
+
if (goal !== null && options['preset'] !== undefined) {
|
|
737
|
+
requests.push({
|
|
738
|
+
key: 'mode',
|
|
739
|
+
current: resolveStrictnessMode(existing),
|
|
740
|
+
requested: goal.settings.strictnessMode,
|
|
741
|
+
}, {
|
|
742
|
+
key: 'enforcement.strictE2E',
|
|
743
|
+
current: existing.enforcement?.strictE2E === true ? 'true' : 'false',
|
|
744
|
+
requested: goal.settings.strictE2E ? 'true' : 'false',
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
if (options['strict-e2e'] === true) {
|
|
748
|
+
requests.push({
|
|
749
|
+
key: 'enforcement.strictE2E',
|
|
750
|
+
current: existing.enforcement?.strictE2E === true ? 'true' : 'false',
|
|
751
|
+
requested: 'true',
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
const unmatchedRoutes = stringFlag(options, 'unmatched-routes');
|
|
755
|
+
if (unmatchedRoutes !== undefined) {
|
|
756
|
+
requests.push({
|
|
757
|
+
key: 'endpoints.unmatchedRoutes',
|
|
758
|
+
current: existing.endpoints?.unmatchedRoutes ?? 'warn',
|
|
759
|
+
requested: unmatchedRoutes.trim().toLowerCase(),
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
for (const request of requests) {
|
|
763
|
+
if (request.current !== request.requested)
|
|
764
|
+
conflicts.push(request);
|
|
765
|
+
}
|
|
766
|
+
return conflicts;
|
|
767
|
+
}
|
|
616
768
|
/**
|
|
617
769
|
* Resolves the goal `init` should set up. Three paths, in order:
|
|
618
770
|
*
|
|
619
|
-
* 1. `--preset light|normal|strict` — an agent or CI run picks
|
|
620
|
-
* explicitly.
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
*
|
|
771
|
+
* 1. `--preset light|normal|strict` — an agent or CI run picks
|
|
772
|
+
* the goal explicitly. An enforcement flag the preset already
|
|
773
|
+
* implies is a no-op (the preset applies); one that
|
|
774
|
+
* contradicts it throws (R1-1) before any file is written.
|
|
775
|
+
* 2. A real terminal — ONE question ("What should Gateforge do
|
|
776
|
+
* for you?") with three choices, each explained in one line.
|
|
777
|
+
* 3. No terminal and no `--preset` — light only, stated ONCE on
|
|
778
|
+
* the line that also names `--preset <light|normal|strict>`.
|
|
779
|
+
* Gateforge never guesses normal or strict for someone who is
|
|
780
|
+
* not there: guessing strict blocks a team, guessing normal
|
|
781
|
+
* pretends a gate nobody asked for.
|
|
628
782
|
*
|
|
629
|
-
* A run that
|
|
630
|
-
* `--strict-e2e`, …) has chosen for itself: no
|
|
631
|
-
* generated config keeps today's
|
|
783
|
+
* A run WITHOUT a preset that carries explicit enforcement flags
|
|
784
|
+
* (`--blocking`, `--strict-e2e`, …) has chosen for itself: no
|
|
785
|
+
* preset is applied and the generated config keeps today's
|
|
786
|
+
* exact bytes.
|
|
632
787
|
*
|
|
633
788
|
* Args:
|
|
634
789
|
* io: process context (prompt + informational output).
|
|
635
790
|
* options: parsed init flags.
|
|
636
|
-
* enforcementFlagGiven (boolean): true when an enforcement flag
|
|
637
|
-
* passed and therefore wins over any preset.
|
|
791
|
+
* enforcementFlagGiven (boolean): true when an enforcement flag
|
|
792
|
+
* was passed and therefore wins over any preset.
|
|
638
793
|
*
|
|
639
794
|
* Returns:
|
|
640
795
|
* Promise<{ name: InitPresetName; settings: InitPresetSettings;
|
|
641
796
|
* autoChosen?: boolean } | null>: the applied goal (with
|
|
642
|
-
* `autoChosen` when no human chose it), or null when the run
|
|
643
|
-
* today's behavior.
|
|
797
|
+
* `autoChosen` when no human chose it), or null when the run
|
|
798
|
+
* kept today's behavior.
|
|
799
|
+
* @throws UsageError (exit 2): a flag contradicts the named
|
|
800
|
+
* preset (R1-1) — nothing is written.
|
|
644
801
|
*/
|
|
645
802
|
async function resolveGoal(io, options, enforcementFlagGiven, configExisted) {
|
|
646
803
|
const explicit = options['preset'];
|
|
647
804
|
if (explicit !== undefined && isInitPresetName(explicit)) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
805
|
+
const conflict = presetFlagConflict(explicit, options);
|
|
806
|
+
if (conflict !== null) {
|
|
807
|
+
throw new UsageError(`--preset ${explicit} already decides ${PRESET_FLAG_THING[conflict.replace(/^no-/, '')]}; ` +
|
|
808
|
+
`--${conflict} contradicts it — drop one of them`);
|
|
809
|
+
}
|
|
810
|
+
// Every given flag is one the preset already implies (or a
|
|
811
|
+
// `--no-*` for something it does not wire): a no-op. The
|
|
812
|
+
// goal the owner named is the one that applies.
|
|
813
|
+
return { name: explicit, settings: INIT_PRESETS[explicit] };
|
|
652
814
|
}
|
|
653
815
|
if (enforcementFlagGiven)
|
|
654
816
|
return null;
|
|
@@ -921,7 +1083,7 @@ async function resolveDocsExclusionsForInit(io, options, config) {
|
|
|
921
1083
|
];
|
|
922
1084
|
const requested = [...new Set(declared)];
|
|
923
1085
|
if (current.length > 0 && JSON.stringify(requested) !== JSON.stringify(current) && !confirmUpdate) {
|
|
924
|
-
throw new UsageError(`init: changing ${
|
|
1086
|
+
throw new UsageError(`init: changing ${DOCS_EXCLUSIONS_SOURCE} needs explicit owner review; repeat with --confirm-doc-exclusions`);
|
|
925
1087
|
}
|
|
926
1088
|
if (current.length === 0 && requested.length === 0 && confirmUpdate) {
|
|
927
1089
|
throw new UsageError('init: --confirm-doc-exclusions requires a non-empty --docs-exclude update');
|
|
@@ -968,7 +1130,8 @@ async function resolveDocsExclusionsForInit(io, options, config) {
|
|
|
968
1130
|
*/
|
|
969
1131
|
function resolveCacheExclusionsForInit(io, options, config) {
|
|
970
1132
|
const current = loadCacheExclusions(io.cwd, config);
|
|
971
|
-
const
|
|
1133
|
+
const configPath = join(io.cwd, '.gateforge.yml');
|
|
1134
|
+
const declarationExists = existsSync(configPath) && declaresEvidenceExclude(readFileSync(configPath, 'utf8'), 'cache');
|
|
972
1135
|
const requestedValue = stringFlag(options, 'cache-exclude');
|
|
973
1136
|
const confirmUpdate = options['confirm-cache-exclusions'] === true;
|
|
974
1137
|
if (typeof options['confirm-cache-exclusions'] !== 'boolean' &&
|
|
@@ -985,7 +1148,7 @@ function resolveCacheExclusionsForInit(io, options, config) {
|
|
|
985
1148
|
: validateRequestedCacheFiles(io.cwd, requestedValue.split(',').map((file) => file.trim()).filter((file) => file.length > 0), config);
|
|
986
1149
|
const changed = JSON.stringify(requested) !== JSON.stringify(current);
|
|
987
1150
|
if (declarationExists && changed && !confirmUpdate) {
|
|
988
|
-
throw new UsageError(`init: changing ${
|
|
1151
|
+
throw new UsageError(`init: changing ${CACHE_EXCLUSIONS_SOURCE} needs explicit owner review; repeat with --confirm-cache-exclusions`);
|
|
989
1152
|
}
|
|
990
1153
|
if (declarationExists && !changed && confirmUpdate) {
|
|
991
1154
|
throw new UsageError('init: --confirm-cache-exclusions requires a changed --cache-exclude list');
|
|
@@ -1131,19 +1294,6 @@ async function proposePlanesConfig(cwd, io, routeRules = []) {
|
|
|
1131
1294
|
writeLine(io.stdout, `created: ${planesPath} (${combined.length} rule(s) — ${inference.config?.rules.length ?? 0} inferred from model directories, ` +
|
|
1132
1295
|
`${routeRules.length} answered for route folders — review the reasons before the next gateforge run)`);
|
|
1133
1296
|
}
|
|
1134
|
-
/**
|
|
1135
|
-
* The engine-owned state directories that must never be committed.
|
|
1136
|
-
*
|
|
1137
|
-
* `.gateforge/test-gates/` holds everything a supervised run caches and
|
|
1138
|
-
* seals: the test catalog, plugin caches, receipts, records, spool and
|
|
1139
|
-
* history. The engine writes it on every `check`/`test-gates`/`next`,
|
|
1140
|
-
* so after `init` the very next `git add -A` staged it — and then the
|
|
1141
|
-
* gate, quite correctly, reported the engine's own cache as unmapped
|
|
1142
|
-
* product changes. Nothing else under `.gateforge/` is engine state:
|
|
1143
|
-
* policies, adapters, waivers, baselines, hooks and the CI template are
|
|
1144
|
-
* owner-reviewed files that MUST be committed.
|
|
1145
|
-
*/
|
|
1146
|
-
const ENGINE_STATE_IGNORE_ENTRIES = [`${DEFAULT_STATE_DIR}/`];
|
|
1147
1297
|
/**
|
|
1148
1298
|
* Whether a `.gitignore` already covers one engine-state entry.
|
|
1149
1299
|
*
|
|
@@ -1191,7 +1341,7 @@ function ignoreEngineState(io, cwd) {
|
|
|
1191
1341
|
return;
|
|
1192
1342
|
}
|
|
1193
1343
|
const block = [
|
|
1194
|
-
|
|
1344
|
+
ENGINE_STATE_IGNORE_COMMENT,
|
|
1195
1345
|
...missing,
|
|
1196
1346
|
'',
|
|
1197
1347
|
].join('\n');
|
|
@@ -1201,6 +1351,47 @@ function ignoreEngineState(io, cwd) {
|
|
|
1201
1351
|
writeLine(io.stdout, `${existed ? 'updated' : 'created'}: ${path} (gateforge engine state ignored: ${missing.join(', ')} — ` +
|
|
1202
1352
|
'without this, `git add -A` stages the run cache and the gate blocks on its own files)');
|
|
1203
1353
|
}
|
|
1354
|
+
/** The dependency files whose uncommitted state the install note names. */
|
|
1355
|
+
const INSTALL_MANIFEST_FILES = [
|
|
1356
|
+
'package.json',
|
|
1357
|
+
'package-lock.json',
|
|
1358
|
+
'npm-shrinkwrap.json',
|
|
1359
|
+
'pnpm-lock.yaml',
|
|
1360
|
+
'yarn.lock',
|
|
1361
|
+
'bun.lockb',
|
|
1362
|
+
'bun.lock',
|
|
1363
|
+
];
|
|
1364
|
+
/** The one line an init run prints while the install is uncommitted. */
|
|
1365
|
+
const INSTALL_COMMIT_NOTE = 'note: commit the Gateforge install (package.json and lockfile) on its own BEFORE committing the setup files — a setup commit that also changes dependencies is a product change, and under strictE2E it re-grades the adopted E2E debt as blocking. Commit it now, before the commit gate is wired.';
|
|
1366
|
+
/**
|
|
1367
|
+
* Prints the install-commit note when the install itself (the
|
|
1368
|
+
* dependency change that brought Gateforge into the repository)
|
|
1369
|
+
* is still uncommitted: the setup commit must stay
|
|
1370
|
+
* product-behavior-neutral, so the install belongs in its own
|
|
1371
|
+
* commit BEFORE the setup files are committed.
|
|
1372
|
+
*
|
|
1373
|
+
* Args:
|
|
1374
|
+
* io: process context.
|
|
1375
|
+
*
|
|
1376
|
+
* Returns:
|
|
1377
|
+
* void: a non-repository, a repository without commits, or a
|
|
1378
|
+
* clean install prints nothing; the run always proceeds
|
|
1379
|
+
* exactly as before (never refuses, never changes the exit
|
|
1380
|
+
* code).
|
|
1381
|
+
*/
|
|
1382
|
+
function noteUncommittedInstall(io) {
|
|
1383
|
+
const head = spawnSync('git', ['rev-parse', '--verify', '-q', 'HEAD'], {
|
|
1384
|
+
cwd: io.cwd,
|
|
1385
|
+
env: io.env,
|
|
1386
|
+
encoding: 'utf8',
|
|
1387
|
+
});
|
|
1388
|
+
if (head.status !== 0)
|
|
1389
|
+
return;
|
|
1390
|
+
const status = spawnSync('git', ['status', '--porcelain', '--', ...INSTALL_MANIFEST_FILES], { cwd: io.cwd, env: io.env, encoding: 'utf8' });
|
|
1391
|
+
if (status.status !== 0 || (status.stdout ?? '').trim().length === 0)
|
|
1392
|
+
return;
|
|
1393
|
+
writeLine(io.stdout, INSTALL_COMMIT_NOTE);
|
|
1394
|
+
}
|
|
1204
1395
|
/**
|
|
1205
1396
|
* Runs `gateforge init` in the io cwd.
|
|
1206
1397
|
*
|
|
@@ -1315,6 +1506,12 @@ export async function initCommand(io, argv) {
|
|
|
1315
1506
|
if (typeof options['strict-e2e'] !== 'boolean' && options['strict-e2e'] !== undefined) {
|
|
1316
1507
|
throw new UsageError("flag '--strict-e2e' must be a boolean flag");
|
|
1317
1508
|
}
|
|
1509
|
+
// The install-commit note (0.9.1): the dependency change that
|
|
1510
|
+
// brought Gateforge in belongs in its own commit BEFORE the
|
|
1511
|
+
// setup files — a setup commit that also changes dependencies
|
|
1512
|
+
// is a product change. Printed at the START of the run; never
|
|
1513
|
+
// refuses and never changes the exit code.
|
|
1514
|
+
noteUncommittedInstall(io);
|
|
1318
1515
|
// Goal resolution (plan Phase 1/2): --preset wins, then the one goal
|
|
1319
1516
|
// question in a terminal, then light with a loud note. A run that
|
|
1320
1517
|
// already carries explicit enforcement flags has chosen for itself, so
|
|
@@ -1330,6 +1527,21 @@ export async function initCommand(io, argv) {
|
|
|
1330
1527
|
options['strict-e2e'] === true;
|
|
1331
1528
|
const goal = await resolveGoal(io, options, enforcementFlagGiven, existsSync(join(io.cwd, '.gateforge.yml')));
|
|
1332
1529
|
const strictE2E = goal !== null ? goal.settings.strictE2E : options['strict-e2e'] === true;
|
|
1530
|
+
// An existing config is never rewritten (R1-2): a run that
|
|
1531
|
+
// REQUESTS a setting the file already owns with a different
|
|
1532
|
+
// value — a chosen preset's `mode`/`enforcement.strictE2E`,
|
|
1533
|
+
// or the `--strict-e2e` / `--unmatched-routes` flags — exits
|
|
1534
|
+
// 2 BEFORE anything is written, one line per differing key,
|
|
1535
|
+
// naming the key, both values, and the edit that fixes it.
|
|
1536
|
+
// Same value (or no such request) behaves exactly as today.
|
|
1537
|
+
const configConflicts = requestedConfigConflicts(io.cwd, options, goal);
|
|
1538
|
+
if (configConflicts.length > 0) {
|
|
1539
|
+
throw new UsageError(configConflicts
|
|
1540
|
+
.map((conflict) => `.gateforge.yml exists and has ${conflict.key}: ${conflict.current}; ` +
|
|
1541
|
+
`you asked for ${conflict.requested}. init never rewrites an existing config — ` +
|
|
1542
|
+
`set ${conflict.key}: ${conflict.requested} in .gateforge.yml yourself.`)
|
|
1543
|
+
.join('\n'));
|
|
1544
|
+
}
|
|
1333
1545
|
// Strict-setup preflight (plan Phase 0 item 4): BEFORE anything is
|
|
1334
1546
|
// written — a strict setup demanding an unavailable proof channel
|
|
1335
1547
|
// stays visibly incomplete instead of shipping a false green. The
|
|
@@ -1406,6 +1618,10 @@ export async function initCommand(io, argv) {
|
|
|
1406
1618
|
unmatchedRoutes: unmatchedRoutes.mode,
|
|
1407
1619
|
};
|
|
1408
1620
|
const generatedDraftConfig = () => parseConfig(parseYaml(configTemplate(languages, pluginIds, configOptions)), { file: '.gateforge.yml' });
|
|
1621
|
+
// A pre-0.10 exclusion declaration is never silently ignored, not even
|
|
1622
|
+
// by init: the owner is told to migrate instead of losing the list.
|
|
1623
|
+
if (legacyExclusionPathsPresent(cwd).length > 0)
|
|
1624
|
+
rejectLegacyExclusions(cwd);
|
|
1409
1625
|
let draftConfig;
|
|
1410
1626
|
if (existsSync(join(cwd, '.gateforge.yml'))) {
|
|
1411
1627
|
try {
|
|
@@ -1416,8 +1632,6 @@ export async function initCommand(io, argv) {
|
|
|
1416
1632
|
const cacheChoiceRequested = stringFlag(options, 'cache-exclude') !== undefined;
|
|
1417
1633
|
if (docsChoiceRequested ||
|
|
1418
1634
|
cacheChoiceRequested ||
|
|
1419
|
-
existsSync(join(cwd, ...DOCS_EXCLUSIONS_PATH.split('/'))) ||
|
|
1420
|
-
existsSync(join(cwd, ...CACHE_EXCLUSIONS_PATH.split('/'))) ||
|
|
1421
1635
|
(process.stdin.isTTY === true && process.stdout.isTTY === true)) {
|
|
1422
1636
|
throw error;
|
|
1423
1637
|
}
|
|
@@ -1500,46 +1714,6 @@ export async function initCommand(io, argv) {
|
|
|
1500
1714
|
}
|
|
1501
1715
|
targets[existing] = target;
|
|
1502
1716
|
};
|
|
1503
|
-
if (docsExclusionChoice.changed) {
|
|
1504
|
-
const exclusionPath = join(cwd, ...DOCS_EXCLUSIONS_PATH.split('/'));
|
|
1505
|
-
const exclusionText = renderDocsExclusions(docsExclusionChoice.folders);
|
|
1506
|
-
pushTarget({
|
|
1507
|
-
path: exclusionPath,
|
|
1508
|
-
label: 'owner-declared documentation exclusions',
|
|
1509
|
-
write: () => {
|
|
1510
|
-
const temporaryPath = join(gateforgeDir, `.docs-exclusions-${randomUUID()}.tmp`);
|
|
1511
|
-
try {
|
|
1512
|
-
writeFileSync(temporaryPath, exclusionText, { flag: 'wx', encoding: 'utf8' });
|
|
1513
|
-
renameSync(temporaryPath, exclusionPath);
|
|
1514
|
-
}
|
|
1515
|
-
catch (error) {
|
|
1516
|
-
if (existsSync(temporaryPath))
|
|
1517
|
-
unlinkSync(temporaryPath);
|
|
1518
|
-
throw error;
|
|
1519
|
-
}
|
|
1520
|
-
},
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
|
-
if (cacheExclusionChoice.changed) {
|
|
1524
|
-
const exclusionPath = join(cwd, ...CACHE_EXCLUSIONS_PATH.split('/'));
|
|
1525
|
-
const exclusionText = renderCacheExclusions(cacheExclusionChoice.files);
|
|
1526
|
-
pushTarget({
|
|
1527
|
-
path: exclusionPath,
|
|
1528
|
-
label: 'owner-declared Python bytecode exclusions',
|
|
1529
|
-
write: () => {
|
|
1530
|
-
const temporaryPath = join(gateforgeDir, `.cache-exclusions-${randomUUID()}.tmp`);
|
|
1531
|
-
try {
|
|
1532
|
-
writeFileSync(temporaryPath, exclusionText, { flag: 'wx', encoding: 'utf8' });
|
|
1533
|
-
renameSync(temporaryPath, exclusionPath);
|
|
1534
|
-
}
|
|
1535
|
-
catch (error) {
|
|
1536
|
-
if (existsSync(temporaryPath))
|
|
1537
|
-
unlinkSync(temporaryPath);
|
|
1538
|
-
throw error;
|
|
1539
|
-
}
|
|
1540
|
-
},
|
|
1541
|
-
});
|
|
1542
|
-
}
|
|
1543
1717
|
mkdirSync(join(gateforgeDir, 'adapters'), { recursive: true });
|
|
1544
1718
|
mkdirSync(join(gateforgeDir, 'waivers'), { recursive: true });
|
|
1545
1719
|
mkdirSync(join(gateforgeDir, 'baselines'), { recursive: true });
|
|
@@ -1650,15 +1824,9 @@ export async function initCommand(io, argv) {
|
|
|
1650
1824
|
writeLine(io.stdout, `updated: ${configPath} (added detector(s): ${added.join(', ')} — every other key left as it was)`);
|
|
1651
1825
|
}
|
|
1652
1826
|
}
|
|
1827
|
+
const configExistedBefore = existsSync(join(cwd, '.gateforge.yml'));
|
|
1653
1828
|
for (const target of targets) {
|
|
1654
1829
|
if (existsSync(target.path)) {
|
|
1655
|
-
if ((target.label === 'owner-declared documentation exclusions' && docsExclusionChoice.changed) ||
|
|
1656
|
-
(target.label === 'owner-declared Python bytecode exclusions' && cacheExclusionChoice.changed)) {
|
|
1657
|
-
target.write();
|
|
1658
|
-
recordInitPath(io, cwd, target.path, 'modified');
|
|
1659
|
-
writeLine(io.stdout, `updated: ${target.path}`);
|
|
1660
|
-
continue;
|
|
1661
|
-
}
|
|
1662
1830
|
recordInitPath(io, cwd, target.path, 'preserved');
|
|
1663
1831
|
writeLine(io.stdout, `exists, leaving untouched: ${target.path}`);
|
|
1664
1832
|
continue;
|
|
@@ -1667,6 +1835,36 @@ export async function initCommand(io, argv) {
|
|
|
1667
1835
|
recordInitPath(io, cwd, target.path, 'created');
|
|
1668
1836
|
writeLine(io.stdout, `created: ${target.path}`);
|
|
1669
1837
|
}
|
|
1838
|
+
// Evidence exclusions live in `.gateforge.yml` (0.10.0), so they are
|
|
1839
|
+
// written AFTER the scaffold loop: the config is on disk by now (the
|
|
1840
|
+
// loop created it or preserved the owner's), and the declaration is
|
|
1841
|
+
// spliced into that exact text — comments, key order and quoting stay
|
|
1842
|
+
// byte for byte, and only the `evidence.exclude` block is new.
|
|
1843
|
+
if (docsExclusionChoice.changed || cacheExclusionChoice.changed) {
|
|
1844
|
+
const configPath = join(cwd, '.gateforge.yml');
|
|
1845
|
+
const before = readFileSync(configPath, 'utf8');
|
|
1846
|
+
const after = setEvidenceExclude(before, {
|
|
1847
|
+
...(docsExclusionChoice.changed ? { docs: docsExclusionChoice.folders } : {}),
|
|
1848
|
+
...(cacheExclusionChoice.changed ? { cache: cacheExclusionChoice.files } : {}),
|
|
1849
|
+
}, '.gateforge.yml');
|
|
1850
|
+
const temporaryPath = join(gateforgeDir, `.evidence-exclusions-${randomUUID()}.tmp`);
|
|
1851
|
+
try {
|
|
1852
|
+
writeFileSync(temporaryPath, after, { flag: 'wx', encoding: 'utf8' });
|
|
1853
|
+
renameSync(temporaryPath, configPath);
|
|
1854
|
+
}
|
|
1855
|
+
catch (error) {
|
|
1856
|
+
if (existsSync(temporaryPath))
|
|
1857
|
+
unlinkSync(temporaryPath);
|
|
1858
|
+
throw error;
|
|
1859
|
+
}
|
|
1860
|
+
recordInitPath(io, cwd, configPath, configExistedBefore ? 'modified' : 'created');
|
|
1861
|
+
writeLine(io.stdout, `${configExistedBefore ? 'updated' : 'created'}: ${configPath} (evidence.exclude)`);
|
|
1862
|
+
}
|
|
1863
|
+
// The config is written: name the install it now expects (once, and only
|
|
1864
|
+
// for packs this repository has not declared yet). The owner runs it.
|
|
1865
|
+
const installLine = packInstallLine(cwd, pluginIds);
|
|
1866
|
+
if (installLine !== null)
|
|
1867
|
+
writeLine(io.stdout, installLine);
|
|
1670
1868
|
// Engine-owned state is never a product change: without this the
|
|
1671
1869
|
// first `git add -A` stages the run cache the gate just wrote, and the
|
|
1672
1870
|
// gate then blocks on its own files.
|
|
@@ -1830,7 +2028,12 @@ export async function initCommand(io, argv) {
|
|
|
1830
2028
|
writeLine(io.stdout, `verified: ${outcome.detail}`);
|
|
1831
2029
|
break;
|
|
1832
2030
|
case 'framework':
|
|
1833
|
-
|
|
2031
|
+
if (outcome.hookPath !== null && !existsSync(outcome.hookPath)) {
|
|
2032
|
+
writeLine(io.stdout, 'pre-commit framework config found: gateforge-check added to .pre-commit-config.yaml — run `pre-commit install` to activate the gate');
|
|
2033
|
+
}
|
|
2034
|
+
else {
|
|
2035
|
+
writeLine(io.stdout, `framework-managed pre-commit hook detected: wiring through .pre-commit-config.yaml`);
|
|
2036
|
+
}
|
|
1834
2037
|
break;
|
|
1835
2038
|
case 'conflict':
|
|
1836
2039
|
case 'incomplete':
|