@gate-forge/cli 0.7.0 → 0.8.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 +511 -51
- package/dist/adapter-audit.d.ts +154 -0
- package/dist/adapter-audit.d.ts.map +1 -0
- package/dist/adapter-audit.js +531 -0
- package/dist/adapter-audit.js.map +1 -0
- package/dist/adapter-scaffold.d.ts +66 -0
- package/dist/adapter-scaffold.d.ts.map +1 -0
- package/dist/adapter-scaffold.js +353 -0
- package/dist/adapter-scaffold.js.map +1 -0
- package/dist/adopted-baseline.d.ts +10 -0
- package/dist/adopted-baseline.d.ts.map +1 -1
- package/dist/adopted-baseline.js +18 -1
- package/dist/adopted-baseline.js.map +1 -1
- package/dist/args.d.ts +15 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +59 -2
- package/dist/args.js.map +1 -1
- package/dist/behavior-setup.d.ts +239 -0
- package/dist/behavior-setup.d.ts.map +1 -0
- package/dist/behavior-setup.js +738 -0
- package/dist/behavior-setup.js.map +1 -0
- package/dist/broker.d.ts.map +1 -1
- package/dist/broker.js +28 -2
- package/dist/broker.js.map +1 -1
- package/dist/cache-exclusions.d.ts +45 -0
- package/dist/cache-exclusions.d.ts.map +1 -0
- package/dist/cache-exclusions.js +205 -0
- package/dist/cache-exclusions.js.map +1 -0
- package/dist/candidate-tree.d.ts +86 -14
- package/dist/candidate-tree.d.ts.map +1 -1
- package/dist/candidate-tree.js +236 -62
- package/dist/candidate-tree.js.map +1 -1
- package/dist/ci-witnessed-template.d.ts +43 -0
- package/dist/ci-witnessed-template.d.ts.map +1 -0
- package/dist/ci-witnessed-template.js +283 -0
- package/dist/ci-witnessed-template.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +31 -4
- package/dist/cli.js.map +1 -1
- package/dist/commands/adapters.d.ts +15 -0
- package/dist/commands/adapters.d.ts.map +1 -0
- package/dist/commands/adapters.js +284 -0
- package/dist/commands/adapters.js.map +1 -0
- package/dist/commands/adopt.d.ts.map +1 -1
- package/dist/commands/adopt.js +9 -1
- package/dist/commands/adopt.js.map +1 -1
- package/dist/commands/baseline.d.ts.map +1 -1
- package/dist/commands/baseline.js +42 -1
- package/dist/commands/baseline.js.map +1 -1
- package/dist/commands/blocking.d.ts +81 -2
- package/dist/commands/blocking.d.ts.map +1 -1
- package/dist/commands/blocking.js +336 -53
- package/dist/commands/blocking.js.map +1 -1
- package/dist/commands/check.d.ts +36 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +1008 -62
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/classify.d.ts +2 -1
- package/dist/commands/classify.d.ts.map +1 -1
- package/dist/commands/classify.js +143 -5
- package/dist/commands/classify.js.map +1 -1
- package/dist/commands/enforce.d.ts +4 -4
- package/dist/commands/enforce.d.ts.map +1 -1
- package/dist/commands/enforce.js +41 -9
- package/dist/commands/enforce.js.map +1 -1
- package/dist/commands/enforcement.d.ts +13 -1
- package/dist/commands/enforcement.d.ts.map +1 -1
- package/dist/commands/enforcement.js +800 -30
- package/dist/commands/enforcement.js.map +1 -1
- package/dist/commands/history.d.ts +12 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +45 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/init-presets.d.ts +148 -0
- package/dist/commands/init-presets.d.ts.map +1 -0
- package/dist/commands/init-presets.js +194 -0
- package/dist/commands/init-presets.js.map +1 -0
- package/dist/commands/init.d.ts +7 -12
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +610 -69
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/keys.d.ts.map +1 -1
- package/dist/commands/keys.js +29 -13
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/next.d.ts.map +1 -1
- package/dist/commands/next.js +744 -15
- package/dist/commands/next.js.map +1 -1
- package/dist/commands/pre-commit.d.ts +25 -0
- package/dist/commands/pre-commit.d.ts.map +1 -1
- package/dist/commands/pre-commit.js +91 -6
- package/dist/commands/pre-commit.js.map +1 -1
- package/dist/commands/quarantine.d.ts +16 -0
- package/dist/commands/quarantine.d.ts.map +1 -0
- package/dist/commands/quarantine.js +213 -0
- package/dist/commands/quarantine.js.map +1 -0
- package/dist/commands/run.d.ts +39 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +196 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/test-gates.d.ts +284 -2
- package/dist/commands/test-gates.d.ts.map +1 -1
- package/dist/commands/test-gates.js +3619 -186
- package/dist/commands/test-gates.js.map +1 -1
- package/dist/commands/tests.d.ts +1 -1
- package/dist/commands/tests.d.ts.map +1 -1
- package/dist/commands/tests.js +225 -22
- package/dist/commands/tests.js.map +1 -1
- package/dist/endpoint-compiler.d.ts.map +1 -1
- package/dist/endpoint-compiler.js +29 -8
- package/dist/endpoint-compiler.js.map +1 -1
- package/dist/engine-browser.d.ts +183 -0
- package/dist/engine-browser.d.ts.map +1 -0
- package/dist/engine-browser.js +381 -0
- package/dist/engine-browser.js.map +1 -0
- package/dist/engine-identity.d.ts +100 -0
- package/dist/engine-identity.d.ts.map +1 -0
- package/dist/engine-identity.js +182 -0
- package/dist/engine-identity.js.map +1 -0
- package/dist/evaluate.d.ts +89 -0
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +137 -16
- package/dist/evaluate.js.map +1 -1
- package/dist/execution.d.ts +253 -9
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +309 -12
- package/dist/execution.js.map +1 -1
- package/dist/git-hooks.d.ts +17 -0
- package/dist/git-hooks.d.ts.map +1 -1
- package/dist/git-hooks.js +119 -0
- package/dist/git-hooks.js.map +1 -1
- package/dist/git-objects.d.ts +60 -0
- package/dist/git-objects.d.ts.map +1 -0
- package/dist/git-objects.js +152 -0
- package/dist/git-objects.js.map +1 -0
- package/dist/history.d.ts +52 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +116 -0
- package/dist/history.js.map +1 -0
- package/dist/host-load.d.ts +49 -0
- package/dist/host-load.d.ts.map +1 -0
- package/dist/host-load.js +78 -0
- package/dist/host-load.js.map +1 -0
- package/dist/input-snapshot.d.ts +63 -9
- package/dist/input-snapshot.d.ts.map +1 -1
- package/dist/input-snapshot.js +195 -17
- package/dist/input-snapshot.js.map +1 -1
- package/dist/io.d.ts +36 -0
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +21 -0
- package/dist/io.js.map +1 -1
- package/dist/mapping.d.ts +84 -1
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +276 -5
- package/dist/mapping.js.map +1 -1
- package/dist/native-freeze.d.ts +217 -0
- package/dist/native-freeze.d.ts.map +1 -0
- package/dist/native-freeze.js +332 -0
- package/dist/native-freeze.js.map +1 -0
- package/dist/pipeline.d.ts +52 -1
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +141 -3
- package/dist/pipeline.js.map +1 -1
- package/dist/playwright-browsers.d.ts +210 -0
- package/dist/playwright-browsers.d.ts.map +1 -0
- package/dist/playwright-browsers.js +364 -0
- package/dist/playwright-browsers.js.map +1 -0
- package/dist/plugins.d.ts +15 -5
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +59 -9
- package/dist/plugins.js.map +1 -1
- package/dist/progress.d.ts +148 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +263 -0
- package/dist/progress.js.map +1 -0
- package/dist/providers.d.ts +26 -1
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +39 -0
- package/dist/providers.js.map +1 -1
- package/dist/receipts.d.ts +1 -0
- package/dist/receipts.d.ts.map +1 -1
- package/dist/receipts.js +35 -7
- package/dist/receipts.js.map +1 -1
- package/dist/repo-scan.d.ts +8 -1
- package/dist/repo-scan.d.ts.map +1 -1
- package/dist/repo-scan.js +221 -27
- package/dist/repo-scan.js.map +1 -1
- package/dist/reseal-chain.d.ts +184 -0
- package/dist/reseal-chain.d.ts.map +1 -0
- package/dist/reseal-chain.js +735 -0
- package/dist/reseal-chain.js.map +1 -0
- package/dist/reseal-evidence.d.ts +241 -0
- package/dist/reseal-evidence.d.ts.map +1 -0
- package/dist/reseal-evidence.js +319 -0
- package/dist/reseal-evidence.js.map +1 -0
- package/dist/reseal.d.ts +181 -0
- package/dist/reseal.d.ts.map +1 -0
- package/dist/reseal.js +1620 -0
- package/dist/reseal.js.map +1 -0
- package/dist/response-field-guidance.d.ts +82 -0
- package/dist/response-field-guidance.d.ts.map +1 -0
- package/dist/response-field-guidance.js +184 -0
- package/dist/response-field-guidance.js.map +1 -0
- package/dist/run-cache.d.ts +260 -0
- package/dist/run-cache.d.ts.map +1 -0
- package/dist/run-cache.js +771 -0
- package/dist/run-cache.js.map +1 -0
- package/dist/run-preflight.d.ts +77 -0
- package/dist/run-preflight.d.ts.map +1 -0
- package/dist/run-preflight.js +774 -0
- package/dist/run-preflight.js.map +1 -0
- package/dist/run-recipe.d.ts +107 -0
- package/dist/run-recipe.d.ts.map +1 -0
- package/dist/run-recipe.js +295 -0
- package/dist/run-recipe.js.map +1 -0
- package/dist/run-reliability.d.ts +126 -0
- package/dist/run-reliability.d.ts.map +1 -0
- package/dist/run-reliability.js +221 -0
- package/dist/run-reliability.js.map +1 -0
- package/dist/runtime.d.ts +15 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +11 -1
- package/dist/runtime.js.map +1 -1
- package/dist/secret-guard.d.ts +36 -0
- package/dist/secret-guard.d.ts.map +1 -0
- package/dist/secret-guard.js +63 -0
- package/dist/secret-guard.js.map +1 -0
- package/dist/singleton-guidance.d.ts +73 -0
- package/dist/singleton-guidance.d.ts.map +1 -0
- package/dist/singleton-guidance.js +118 -0
- package/dist/singleton-guidance.js.map +1 -0
- package/dist/staged-candidate.d.ts +17 -0
- package/dist/staged-candidate.d.ts.map +1 -1
- package/dist/staged-candidate.js +50 -0
- package/dist/staged-candidate.js.map +1 -1
- package/dist/state-artifacts.d.ts +70 -0
- package/dist/state-artifacts.d.ts.map +1 -0
- package/dist/state-artifacts.js +215 -0
- package/dist/state-artifacts.js.map +1 -0
- package/dist/state.d.ts +170 -2
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +248 -8
- package/dist/state.js.map +1 -1
- package/dist/verifier-keys.d.ts +33 -2
- package/dist/verifier-keys.d.ts.map +1 -1
- package/dist/verifier-keys.js +95 -9
- package/dist/verifier-keys.js.map +1 -1
- package/guides/CONNECT-YOUR-PROJECT.md +367 -0
- package/guides/QUICKSTART.md +404 -0
- package/guides/RUNNER-NEUTRAL-EVIDENCE.md +199 -0
- package/guides/TEST-ENVIRONMENT.md +1226 -0
- package/guides/UPGRADE-0.6-to-0.7.md +65 -0
- package/guides/UPGRADE-0.7-to-0.8.md +114 -0
- package/package.json +12 -10
package/dist/commands/init.js
CHANGED
|
@@ -19,29 +19,36 @@ import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileS
|
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
20
|
import { createInterface } from 'node:readline/promises';
|
|
21
21
|
import { join } from 'node:path';
|
|
22
|
-
import { parse as parseYaml } from 'yaml';
|
|
22
|
+
import { parse as parseYaml, parseDocument, isSeq as isYamlSeq, isMap as isYamlMap } from 'yaml';
|
|
23
23
|
import { ClassificationPolicySchema, PolicyFileSchema, loadConfig, parseConfig, serializeBaseline, strictCapabilityGaps, } from '@gate-forge/core';
|
|
24
24
|
import { DEFAULT_PLANES_CONFIG, PLANES_CONFIG_PATH, createSqlalchemyDetector, parsePlanesConfigText, PACK_VERSION as PACK_SQLALCHEMY_VERSION, } from '@gate-forge/pack-sqlalchemy';
|
|
25
25
|
import { PACK_VERSION as PACK_FASTAPI_VERSION } from '@gate-forge/pack-fastapi';
|
|
26
26
|
import { PACK_VERSION as PACK_HTTP_VERSION } from '@gate-forge/pack-http';
|
|
27
27
|
import { PACK_VERSION as PACK_TASK_VERSION } from '@gate-forge/pack-task';
|
|
28
|
+
import { renderAlembicOptIn } from '@gate-forge/pack-alembic';
|
|
28
29
|
import { parseArgs, stringFlag } from '../args.js';
|
|
29
|
-
import { writeLine } from '../io.js';
|
|
30
|
+
import { recordInitPath, writeLine } from '../io.js';
|
|
30
31
|
import { UsageError } from '../errors.js';
|
|
31
32
|
import { languageDefaultPlugins, recommendPlugins, renderScanBlock, scanRepo } from '../repo-scan.js';
|
|
32
33
|
import { rejectUnknownFlags } from './common.js';
|
|
33
34
|
import { expandIncludePaths } from '../glob.js';
|
|
34
35
|
import { inferPlanesConfig } from '../planes-inference.js';
|
|
35
|
-
import { hasGateforgeMarker, installCommitHook, writeStandaloneGateScript } from '../git-hooks.js';
|
|
36
|
-
import { appendPreCommitHook, ensureHookScript, engineRootFromInvocation, writeGitlabCiTemplate as writeSharedGitlabCiTemplate, } from './blocking.js';
|
|
36
|
+
import { hasGateforgeMarker, installCommitHook, installPrePushHook, writeStandaloneGateScript } from '../git-hooks.js';
|
|
37
|
+
import { appendPreCommitHook, ensureHookScript, engineRootFromInvocation, writeGitlabCiTemplate as writeSharedGitlabCiTemplate, writeServerProtectionInstructions, } from './blocking.js';
|
|
37
38
|
import { trustedPolicyDigestForConfig } from '../execution.js';
|
|
38
39
|
import { DOCS_EXCLUSIONS_GUARANTEE, DOCS_EXCLUSIONS_PATH, loadDocsExclusions, renderDocsExclusions, validateRequestedDocsFolders, } from '../docs-exclusions.js';
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
import { CACHE_EXCLUSIONS_GUARANTEE, CACHE_EXCLUSIONS_PATH, loadCacheExclusions, renderCacheExclusions, validateRequestedCacheFiles, } from '../cache-exclusions.js';
|
|
41
|
+
import { CHOOSE_ANOTHER_GOAL_ADVICE, INIT_PRESETS, isInitPresetName, parseGoalAnswer, renderGoalQuestion, renderPresetTable, renderPresetSummary, } from './init-presets.js';
|
|
42
|
+
import { BEHAVIOR_NAMESPACES, behaviorPackEvidence, behaviorSkeletonExamples, detectBehaviorPacks, parseBehaviorPacks, } from '../behavior-setup.js';
|
|
43
|
+
export const INIT_USAGE = '[--preset light|normal|strict] [--explain-presets] [--no-scan] [--proof overlay|observe] ' +
|
|
44
|
+
'[--blocking] [--no-blocking] [--pre-commit] [--no-pre-commit] [--mode changed|staged] ' +
|
|
45
|
+
'[--witnessed staged|full] [--ci] [--no-ci] ' +
|
|
46
|
+
'[--docs-exclude <folder,...> [--confirm-doc-exclusions]] [--cache-exclude <file,...> ' +
|
|
47
|
+
'[--confirm-cache-exclusions]] [--strict-e2e] [--planes] [--no-planes] ' +
|
|
48
|
+
'[--behavior] [--no-behavior] [--behavior-packs <pack,...>]';
|
|
42
49
|
/** Template for the complete-behavior owner document (plan §4.1). */
|
|
43
50
|
export const BEHAVIOR_TEMPLATE = `\
|
|
44
|
-
# Complete-behavior owner document
|
|
51
|
+
# Complete-behavior owner document.
|
|
45
52
|
# Presence of this file enables the complete-behavior profile: every
|
|
46
53
|
# discovered endpoint must have an approved declaration (cases or an
|
|
47
54
|
# owner disposition). There is no warnOnly or silent fallback.
|
|
@@ -83,16 +90,20 @@ const BUNDLED_PLUGIN_VERSIONS = Object.freeze({
|
|
|
83
90
|
});
|
|
84
91
|
/**
|
|
85
92
|
* The bundled plugin ids init may write (the four trusted detector
|
|
86
|
-
* packs). `gateforge.pack-task`
|
|
87
|
-
*
|
|
93
|
+
* packs). `gateforge.pack-task` is opt-in only via `--plugins` — never
|
|
94
|
+
* recommended, never defaulted — because the `task:*` contracts it
|
|
95
|
+
* discovers are gradable ONLY once the owner configures a
|
|
96
|
+
* `queueObserver` (the engine's own queue read); without one every one
|
|
97
|
+
* of them stays `VERIFIER_UNSUPPORTED`/fail-closed.
|
|
88
98
|
*/
|
|
89
99
|
const KNOWN_BUNDLED_PLUGIN_IDS = new Set(Object.keys(BUNDLED_PLUGIN_MODULES));
|
|
90
100
|
/**
|
|
91
101
|
* Selects the bundled detectors required by the generated coverage and
|
|
92
102
|
* trusted-entry-point rules for the requested source languages.
|
|
93
|
-
* `gateforge.pack-task` is NEVER included: it
|
|
94
|
-
*
|
|
95
|
-
*
|
|
103
|
+
* `gateforge.pack-task` is NEVER included: it is opt-in only via
|
|
104
|
+
* `--plugins`, because its contracts grade only with a configured
|
|
105
|
+
* `queueObserver` and a generated default would promise coverage the
|
|
106
|
+
* repository cannot produce.
|
|
96
107
|
*
|
|
97
108
|
* Args:
|
|
98
109
|
* languages (readonly string[]): Languages selected by `gateforge init`.
|
|
@@ -109,6 +120,63 @@ function pluginsTemplate(pluginIds) {
|
|
|
109
120
|
.map((id) => ` - id: ${id}\n version: '${BUNDLED_PLUGIN_VERSIONS[id]}'\n transport: in-process\n module: '${BUNDLED_PLUGIN_MODULES[id]}'`)
|
|
110
121
|
.join('\n');
|
|
111
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Adds the requested bundled detectors to an existing `.gateforge.yml`
|
|
125
|
+
* without touching anything else in the owner's file.
|
|
126
|
+
*
|
|
127
|
+
* The merge is ADDITIVE: an id already present keeps its owner's entry
|
|
128
|
+
* (version pin, transport, module) byte for byte, an id that is absent
|
|
129
|
+
* is appended with the bundled module/version, and no entry is ever
|
|
130
|
+
* removed — `--plugins` chooses what to ADD, and the plugin list is the
|
|
131
|
+
* one config section the product's own tip tells a user to change.
|
|
132
|
+
* Everything outside the `plugins:` sequence (keys, comments, the
|
|
133
|
+
* owner's own edits) is preserved exactly.
|
|
134
|
+
*
|
|
135
|
+
* Args:
|
|
136
|
+
* existingText: the current `.gateforge.yml` contents.
|
|
137
|
+
* pluginIds: the bundled detector ids to ensure are present.
|
|
138
|
+
*
|
|
139
|
+
* Returns:
|
|
140
|
+
* string | null: the merged document, or null when every requested id
|
|
141
|
+
* is already present (nothing to write).
|
|
142
|
+
*
|
|
143
|
+
* Throws:
|
|
144
|
+
* UsageError: the merged document would not satisfy the pinned
|
|
145
|
+
* config schema (a broken merge must fail here, not at the next run).
|
|
146
|
+
*/
|
|
147
|
+
function mergePluginsIntoConfig(existingText, pluginIds) {
|
|
148
|
+
const document = parseDocument(existingText);
|
|
149
|
+
const pluginsNode = document.get('plugins');
|
|
150
|
+
if (!isYamlSeq(pluginsNode)) {
|
|
151
|
+
throw new UsageError('init --plugins: the existing .gateforge.yml has no `plugins:` list to add to; ' +
|
|
152
|
+
'add the entry by hand (one block per detector: `id`, `version`, `transport`, `module`)');
|
|
153
|
+
}
|
|
154
|
+
const present = new Set();
|
|
155
|
+
for (const item of pluginsNode.items) {
|
|
156
|
+
// A `plugins:` entry is a YAML mapping node, not a plain object.
|
|
157
|
+
if (!isYamlMap(item))
|
|
158
|
+
continue;
|
|
159
|
+
const id = item.get('id');
|
|
160
|
+
if (typeof id === 'string')
|
|
161
|
+
present.add(id);
|
|
162
|
+
}
|
|
163
|
+
const missing = pluginIds.filter((id) => !present.has(id));
|
|
164
|
+
if (missing.length === 0)
|
|
165
|
+
return null;
|
|
166
|
+
for (const id of missing) {
|
|
167
|
+
pluginsNode.add({
|
|
168
|
+
id,
|
|
169
|
+
version: BUNDLED_PLUGIN_VERSIONS[id],
|
|
170
|
+
transport: 'in-process',
|
|
171
|
+
module: BUNDLED_PLUGIN_MODULES[id],
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const merged = document.toString();
|
|
175
|
+
// Self-check against the pinned schema BEFORE writing (the same
|
|
176
|
+
// contract the fresh-config path keeps).
|
|
177
|
+
parseConfig(parseYaml(merged), { file: '.gateforge.yml' });
|
|
178
|
+
return merged;
|
|
179
|
+
}
|
|
112
180
|
/**
|
|
113
181
|
* Selects source-only include globs so AST detectors do not parse
|
|
114
182
|
* dependencies, caches, lockfiles, or arbitrary repository assets.
|
|
@@ -132,27 +200,21 @@ function sourceIncludePatterns(languages) {
|
|
|
132
200
|
return patterns.length > 0 ? patterns : ['**/*'];
|
|
133
201
|
}
|
|
134
202
|
/**
|
|
135
|
-
* The starter policies
|
|
136
|
-
*
|
|
137
|
-
* UI-semantic `crud:*` stays opt-in and visibly fail-closed until a
|
|
138
|
-
* trusted UI observer exists (ADR 0003 §3).
|
|
203
|
+
* The starter policies preserve available persistence evidence and use
|
|
204
|
+
* only transport-level proof for consumed HTTP endpoints.
|
|
139
205
|
*/
|
|
140
206
|
/**
|
|
141
|
-
*
|
|
207
|
+
* Transport-only endpoint policy example (plan §8 / D1): proves only that
|
|
142
208
|
* the witness observed a matching HTTP exchange in the bound run. Test
|
|
143
209
|
* attribution is suite-claimed — it does not prove which browser, UI
|
|
144
|
-
* action, or test produced the exchange.
|
|
145
|
-
* changes the guarantee: it is a SEPARATE opt-in policy, never an
|
|
146
|
-
* automatic migration of the default frontend requirement, baselines,
|
|
147
|
-
* or waivers.
|
|
210
|
+
* action, or test produced the exchange.
|
|
148
211
|
*/
|
|
149
212
|
export const TRANSPORT_ONLY_POLICY_EXAMPLE = `\
|
|
150
|
-
# Transport-only endpoint policy
|
|
213
|
+
# Transport-only endpoint policy.
|
|
151
214
|
# Each obligation proves only that the witness observed a matching HTTP
|
|
152
215
|
# exchange in the bound run ("witness observed an HTTP exchange");
|
|
153
216
|
# test attribution is suite-claimed ("suite-claimed"), never proven
|
|
154
|
-
# browser-issued by an independent channel.
|
|
155
|
-
# guarantee relative to the default frontend requirement below.
|
|
217
|
+
# browser-issued by an independent channel.
|
|
156
218
|
schemaVersion: 1
|
|
157
219
|
policies:
|
|
158
220
|
- id: frontend-consumed-endpoints-transport-only
|
|
@@ -170,10 +232,17 @@ export const POLICIES_TEMPLATE = `\
|
|
|
170
232
|
# and are graded on the witness's own engine-side observation.
|
|
171
233
|
# UI-semantic crud:* contracts intentionally fail closed (no
|
|
172
234
|
# witness-controlled UI observation channel exists yet) — add them only
|
|
173
|
-
# deliberately.
|
|
174
|
-
#
|
|
175
|
-
#
|
|
176
|
-
#
|
|
235
|
+
# deliberately. Consumed HTTP endpoints use transport-only proof;
|
|
236
|
+
# 'http:frontend-request-observed' has no independent browser/test channel
|
|
237
|
+
# and is never included in a new-install starter.
|
|
238
|
+
#
|
|
239
|
+
# A route no UI calls owes nothing below, so a NEW endpoint with no test is
|
|
240
|
+
# invisible until it is consumed. To make every discovered route owe the
|
|
241
|
+
# observation contracts (only NEW debt blocks; run 'gateforge adopt' to
|
|
242
|
+
# forgive what already exists), uncomment the options section below:
|
|
243
|
+
#
|
|
244
|
+
# options:
|
|
245
|
+
# 'http.endpoint.requireObservation': all
|
|
177
246
|
schemaVersion: 1
|
|
178
247
|
policies:
|
|
179
248
|
# Capability-scoped endpoint policies (workflow/validation/...) may be added
|
|
@@ -187,6 +256,13 @@ policies:
|
|
|
187
256
|
- persistence:read
|
|
188
257
|
- persistence:update
|
|
189
258
|
- persistence:delete
|
|
259
|
+
- id: frontend-consumed-endpoints-transport-only
|
|
260
|
+
when:
|
|
261
|
+
kind: http.endpoint
|
|
262
|
+
consumed: true
|
|
263
|
+
require:
|
|
264
|
+
- http:request-observed
|
|
265
|
+
- http:response-status-ok
|
|
190
266
|
`;
|
|
191
267
|
/**
|
|
192
268
|
* The classification policy (plan phase 5, ADR 0003 D4/D5): scan roots
|
|
@@ -204,8 +280,8 @@ policies:
|
|
|
204
280
|
* Task-scoped rules (the `linkage.task` coverage rule and the worker
|
|
205
281
|
* entry-point detector binding) are emitted ONLY when `pack-task` is in
|
|
206
282
|
* the selected plugin set: a coverage rule or detector binding naming an
|
|
207
|
-
* unconfigured detector fails every run closed, and task is opt-in
|
|
208
|
-
*
|
|
283
|
+
* unconfigured detector fails every run closed, and task is opt-in —
|
|
284
|
+
* its contracts grade only with a configured `queueObserver`.
|
|
209
285
|
*/
|
|
210
286
|
function classificationPolicyTemplate(languages, pluginIds) {
|
|
211
287
|
const selected = new Set(pluginIds);
|
|
@@ -277,17 +353,48 @@ volatileFields:
|
|
|
277
353
|
- created_at
|
|
278
354
|
`;
|
|
279
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* The runner names the repository scan can detect, in the order the scan
|
|
358
|
+
* reports its signals. `playwright` is the frozen default: it is never
|
|
359
|
+
* written into a new config.
|
|
360
|
+
*/
|
|
361
|
+
const DETECTABLE_RUNNERS = ['playwright', 'vitest', 'cypress', 'pytest'];
|
|
280
362
|
/** Builds the `.gateforge.yml` document for the requested languages. */
|
|
281
|
-
function configTemplate(languages, pluginIds,
|
|
282
|
-
|
|
363
|
+
function configTemplate(languages, pluginIds,
|
|
364
|
+
/** `strictnessMode` writes the owner-owned `mode:` key; undefined writes NO key, which is today's byte-identical config. */
|
|
365
|
+
options = {}) {
|
|
366
|
+
const enforcementBlock = options.enforcement === true
|
|
283
367
|
? `# Enforcement: standard mode combines the local hook with a mandatory
|
|
284
368
|
# trusted server check. strictE2E makes waived/baselined in-scope E2E
|
|
285
369
|
# obligations NOT proof (they block with ENFORCEMENT_UNTRUSTED).
|
|
286
370
|
enforcement:
|
|
287
371
|
mode: standard
|
|
288
|
-
strictE2E: true
|
|
372
|
+
strictE2E: ${String(options.strictE2E === true)}
|
|
373
|
+
receiptStage: pre-push
|
|
289
374
|
`
|
|
290
375
|
: '';
|
|
376
|
+
// The owner-owned strictness key. Only written when a preset named it:
|
|
377
|
+
// without a preset the config stays byte-identical to today's, and an
|
|
378
|
+
// ABSENT key means `strict` (the frozen behavior).
|
|
379
|
+
const strictnessBlock = options.strictnessMode === undefined
|
|
380
|
+
? ''
|
|
381
|
+
: `# How hard the gate blocks: strict = block everything, changed = block
|
|
382
|
+
# only the debt this change touches, warn = report everything and block
|
|
383
|
+
# nothing. This softens the GATE, never the evidence.
|
|
384
|
+
mode: ${options.strictnessMode}
|
|
385
|
+
`;
|
|
386
|
+
// The owner-owned runner key: only written when the scan detected a
|
|
387
|
+
// single non-Playwright runner. An absent key means `playwright`, the
|
|
388
|
+
// frozen default, so an existing/ambiguous setup is byte-identical.
|
|
389
|
+
const runnerBlock = options.runner === undefined
|
|
390
|
+
? ''
|
|
391
|
+
: `# The test runner the supervised gate drives. Playwright is the default when
|
|
392
|
+
# this key is absent; the scan detected another runner in this repository.
|
|
393
|
+
runner: ${options.runner}
|
|
394
|
+
`;
|
|
395
|
+
const historyBlock = options.historyRetentionDays === undefined
|
|
396
|
+
? ''
|
|
397
|
+
: `history:\n retentionDays: ${String(options.historyRetentionDays)}\n`;
|
|
291
398
|
return `\
|
|
292
399
|
# gateforge project configuration (schemaVersion 1)
|
|
293
400
|
schemaVersion: 1
|
|
@@ -323,7 +430,7 @@ witness:
|
|
|
323
430
|
maxDurationSeconds: 5
|
|
324
431
|
clock:
|
|
325
432
|
mode: system
|
|
326
|
-
${enforcementBlock}\
|
|
433
|
+
${runnerBlock}${historyBlock}${strictnessBlock}${enforcementBlock}\
|
|
327
434
|
`;
|
|
328
435
|
}
|
|
329
436
|
/**
|
|
@@ -374,7 +481,12 @@ You are gated by Gateforge. Work one blocking item at a time.
|
|
|
374
481
|
2. Read the single \`next:\` block: \`cause\`, \`why\`, and exactly one \`do:\` line.
|
|
375
482
|
3. Do the single \`do:\` line. Stop. Re-run \`gateforge next\`.
|
|
376
483
|
|
|
377
|
-
|
|
484
|
+
|
|
485
|
+
## Setup guides
|
|
486
|
+
|
|
487
|
+
- Environment rules: \`node_modules/@gate-forge/cli/guides/TEST-ENVIRONMENT.md\`.
|
|
488
|
+
- Quickstart: \`node_modules/@gate-forge/cli/guides/QUICKSTART.md\`.
|
|
489
|
+
(both ship with the installed CLI package)
|
|
378
490
|
|
|
379
491
|
## Proof lives in the overlay
|
|
380
492
|
|
|
@@ -417,8 +529,10 @@ with a surface map — they do NOT rewrite existing journeys.
|
|
|
417
529
|
- New proof tests go here: \`tests/e2e/gateforge/<resource>.<op>.spec.js\`.
|
|
418
530
|
- Do not rewrite existing \`tests/e2e/**\` journeys into \`evidence.ui\`.
|
|
419
531
|
- Do not use \`gateforge tests mark\` as proof: mappings are intent, not proof.
|
|
420
|
-
- Fixture shape: \`
|
|
421
|
-
|
|
532
|
+
- Fixture shape: \`node_modules/@gate-forge/pack-playwright/examples/overlay-proof.spec.js\`
|
|
533
|
+
(a complete, runnable proof test shipped with the pack you installed —
|
|
534
|
+
copy it here and change the surface). Journey-writing rules:
|
|
535
|
+
\`node_modules/@gate-forge/pack-playwright/README.md\`.
|
|
422
536
|
`;
|
|
423
537
|
/**
|
|
424
538
|
* The Observe proof checklist init prints (never writes) for
|
|
@@ -446,7 +560,7 @@ async function resolveRecommended(io, options) {
|
|
|
446
560
|
if (options['accept-recommended'] === true)
|
|
447
561
|
return true;
|
|
448
562
|
if (!process.stdin.isTTY) {
|
|
449
|
-
writeLine(io.stdout, 'tip: re-run with --plugins <comma,list> to
|
|
563
|
+
writeLine(io.stdout, 'tip: re-run with --plugins <comma,list> to add detectors (entries already in .gateforge.yml are kept; nothing else in the file changes)');
|
|
450
564
|
return true;
|
|
451
565
|
}
|
|
452
566
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -458,6 +572,70 @@ async function resolveRecommended(io, options) {
|
|
|
458
572
|
rl.close();
|
|
459
573
|
}
|
|
460
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* Resolves the goal `init` should set up. Three paths, in order:
|
|
577
|
+
*
|
|
578
|
+
* 1. `--preset light|normal|strict` — an agent or CI run picks the goal
|
|
579
|
+
* explicitly.
|
|
580
|
+
* 2. A real terminal — ONE question ("What should Gateforge do for
|
|
581
|
+
* you?") with three choices, each explained in one line.
|
|
582
|
+
* 3. No terminal and no `--preset` — light only, stated ONCE on the
|
|
583
|
+
* line that also names `--preset <light|normal|strict>`. Gateforge
|
|
584
|
+
* never guesses normal or strict for someone who is not there:
|
|
585
|
+
* guessing strict blocks a team, guessing normal pretends a gate
|
|
586
|
+
* nobody asked for.
|
|
587
|
+
*
|
|
588
|
+
* A run that already carries explicit enforcement flags (`--blocking`,
|
|
589
|
+
* `--strict-e2e`, …) has chosen for itself: no preset is applied and the
|
|
590
|
+
* generated config keeps today's exact bytes.
|
|
591
|
+
*
|
|
592
|
+
* Args:
|
|
593
|
+
* io: process context (prompt + informational output).
|
|
594
|
+
* options: parsed init flags.
|
|
595
|
+
* enforcementFlagGiven (boolean): true when an enforcement flag was
|
|
596
|
+
* passed and therefore wins over any preset.
|
|
597
|
+
*
|
|
598
|
+
* Returns:
|
|
599
|
+
* Promise<{ name: InitPresetName; settings: InitPresetSettings;
|
|
600
|
+
* autoChosen?: boolean } | null>: the applied goal (with
|
|
601
|
+
* `autoChosen` when no human chose it), or null when the run kept
|
|
602
|
+
* today's behavior.
|
|
603
|
+
*/
|
|
604
|
+
async function resolveGoal(io, options, enforcementFlagGiven, configExisted) {
|
|
605
|
+
const explicit = options['preset'];
|
|
606
|
+
if (explicit !== undefined && isInitPresetName(explicit)) {
|
|
607
|
+
if (!enforcementFlagGiven)
|
|
608
|
+
return { name: explicit, settings: INIT_PRESETS[explicit] };
|
|
609
|
+
writeLine(io.stdout, `note: --preset ${explicit} is ignored because an enforcement flag decides the wiring; the preset's meaning: ${INIT_PRESETS[explicit].explanation}`);
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
if (enforcementFlagGiven)
|
|
613
|
+
return null;
|
|
614
|
+
const interactive = process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
615
|
+
if (!interactive) {
|
|
616
|
+
// ONE line: which goal this run applied, and the flag that changes
|
|
617
|
+
// it. The closing summary used to state the same choice a second
|
|
618
|
+
// time, twenty lines later, in different words.
|
|
619
|
+
writeLine(io.stdout, configExisted
|
|
620
|
+
? 'no terminal: keeping your existing .gateforge.yml — its `mode:` still decides how hard the gate blocks (the light goal wrote nothing here); ' +
|
|
621
|
+
CHOOSE_ANOTHER_GOAL_ADVICE
|
|
622
|
+
: `no terminal: writing the light preset (report everything, block nothing) — ${CHOOSE_ANOTHER_GOAL_ADVICE}`);
|
|
623
|
+
return { name: 'light', settings: INIT_PRESETS.light, autoChosen: true };
|
|
624
|
+
}
|
|
625
|
+
writeLine(io.stdout, renderGoalQuestion());
|
|
626
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
627
|
+
let name;
|
|
628
|
+
try {
|
|
629
|
+
name = parseGoalAnswer(await rl.question(' '));
|
|
630
|
+
}
|
|
631
|
+
catch (error) {
|
|
632
|
+
throw new UsageError(error instanceof Error ? error.message : String(error));
|
|
633
|
+
}
|
|
634
|
+
finally {
|
|
635
|
+
rl.close();
|
|
636
|
+
}
|
|
637
|
+
return { name, settings: INIT_PRESETS[name] };
|
|
638
|
+
}
|
|
461
639
|
/**
|
|
462
640
|
* Asks (TTY only) whether gateforge should be a blocking gate. Flags win:
|
|
463
641
|
* --blocking forces yes, --no-blocking forces no, and non-interactive
|
|
@@ -481,6 +659,92 @@ async function resolveBlocking(io, options) {
|
|
|
481
659
|
rl.close();
|
|
482
660
|
}
|
|
483
661
|
}
|
|
662
|
+
/** Asks how long to retain supervised run history in a new interactive setup.
|
|
663
|
+
*
|
|
664
|
+
* Args:
|
|
665
|
+
* io: process context used for the prompt and informational output.
|
|
666
|
+
*
|
|
667
|
+
* Returns:
|
|
668
|
+
* Promise<number | 'off' | undefined>: selected retention; undefined leaves the feature off.
|
|
669
|
+
*/
|
|
670
|
+
async function resolveHistoryRetention(io) {
|
|
671
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
672
|
+
return undefined;
|
|
673
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
674
|
+
try {
|
|
675
|
+
const answer = (await rl.question('Keep supervised run history? [14 days/off] (default 14): ')).trim().toLowerCase();
|
|
676
|
+
if (answer === '')
|
|
677
|
+
return 14;
|
|
678
|
+
if (answer === 'off')
|
|
679
|
+
return 'off';
|
|
680
|
+
const days = Number(answer);
|
|
681
|
+
if (Number.isInteger(days) && days >= 1 && days <= 90)
|
|
682
|
+
return days;
|
|
683
|
+
throw new UsageError("init: history retention must be an integer from 1 to 90, or 'off'");
|
|
684
|
+
}
|
|
685
|
+
finally {
|
|
686
|
+
rl.close();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Resolves which behavior packs' cases `init` enables (plan 2026-09-30
|
|
691
|
+
* Phase 4). Flags win, then the terminal question, then nothing.
|
|
692
|
+
*
|
|
693
|
+
* A non-interactive run — an agent, a CI job, a test — NEVER enables a
|
|
694
|
+
* pack silently: it prints what it found and the exact flag that
|
|
695
|
+
* enables each pack, and returns none. `--no-behavior` prints nothing at
|
|
696
|
+
* all, so a repository that shows no behavior pack keeps `init`
|
|
697
|
+
* byte-identical.
|
|
698
|
+
*
|
|
699
|
+
* Args:
|
|
700
|
+
* io: process context (the question is asked on the real terminal).
|
|
701
|
+
* input: the detected packs and the owner's explicit flags.
|
|
702
|
+
*
|
|
703
|
+
* Returns:
|
|
704
|
+
* Promise<BehaviorNamespace[]>: the enabled namespaces, in print order.
|
|
705
|
+
*/
|
|
706
|
+
async function resolveBehaviorPacks(io, input) {
|
|
707
|
+
if (input.disabled)
|
|
708
|
+
return [];
|
|
709
|
+
if (input.explicit.length > 0)
|
|
710
|
+
return [...input.explicit];
|
|
711
|
+
if (input.detectedPacks.length === 0)
|
|
712
|
+
return [];
|
|
713
|
+
if (input.enableAll)
|
|
714
|
+
return input.detectedPacks.map((pack) => pack.namespace);
|
|
715
|
+
if (!process.stdin.isTTY) {
|
|
716
|
+
writeLine(io.stdout, 'behavior packs detected in this repository (nothing is enabled without a flag):');
|
|
717
|
+
for (const pack of input.detectedPacks) {
|
|
718
|
+
writeLine(io.stdout, ` ${pack.namespace} — ${behaviorPackEvidence(pack)}`);
|
|
719
|
+
}
|
|
720
|
+
writeLine(io.stdout, 'enable their cases, then re-run init:');
|
|
721
|
+
for (const pack of input.detectedPacks) {
|
|
722
|
+
writeLine(io.stdout, ` gateforge init --behavior-packs ${pack.namespace}`);
|
|
723
|
+
}
|
|
724
|
+
if (input.detectedPacks.length > 1) {
|
|
725
|
+
const all = input.detectedPacks.map((pack) => pack.namespace).join(',');
|
|
726
|
+
writeLine(io.stdout, ` gateforge init --behavior-packs ${all}`);
|
|
727
|
+
}
|
|
728
|
+
return [];
|
|
729
|
+
}
|
|
730
|
+
const enabled = [];
|
|
731
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
732
|
+
try {
|
|
733
|
+
writeLine(io.stdout, 'behavior packs detected in this repository — enable the cases for the ones this app really has:');
|
|
734
|
+
for (const pack of input.detectedPacks) {
|
|
735
|
+
writeLine(io.stdout, ` ${pack.namespace} — ${behaviorPackEvidence(pack)}`);
|
|
736
|
+
const answer = (await rl.question(`enable ${pack.namespace} behavior cases? [y/N] `))
|
|
737
|
+
.trim()
|
|
738
|
+
.toLowerCase();
|
|
739
|
+
if (answer === 'y' || answer === 'yes')
|
|
740
|
+
enabled.push(pack.namespace);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
finally {
|
|
744
|
+
rl.close();
|
|
745
|
+
}
|
|
746
|
+
return BEHAVIOR_NAMESPACES.filter((namespace) => enabled.includes(namespace));
|
|
747
|
+
}
|
|
484
748
|
/**
|
|
485
749
|
* Asks (TTY only) whether init should propose `.gateforge/planes.json`
|
|
486
750
|
* from the discovered model directories. Flags win: --planes forces
|
|
@@ -550,6 +814,46 @@ async function resolveDocsExclusionsForInit(io, options, config) {
|
|
|
550
814
|
writeLine(io.stdout, 'tip: non-interactive init keeps full evidence identity; use --docs-exclude <folder,...> to opt in');
|
|
551
815
|
return { folders: [], changed: false };
|
|
552
816
|
}
|
|
817
|
+
/**
|
|
818
|
+
* Resolves the init owner's explicit Python bytecode exclusion list.
|
|
819
|
+
*
|
|
820
|
+
* Args:
|
|
821
|
+
* io: process context.
|
|
822
|
+
* options: parsed init flags.
|
|
823
|
+
* config: validated Gateforge configuration.
|
|
824
|
+
*
|
|
825
|
+
* Returns:
|
|
826
|
+
* object: validated files and whether the declaration must be written.
|
|
827
|
+
*
|
|
828
|
+
* Throws:
|
|
829
|
+
* UsageError: invalid flags or an unconfirmed owner-list change.
|
|
830
|
+
*/
|
|
831
|
+
function resolveCacheExclusionsForInit(io, options, config) {
|
|
832
|
+
const current = loadCacheExclusions(io.cwd, config);
|
|
833
|
+
const declarationExists = existsSync(join(io.cwd, ...CACHE_EXCLUSIONS_PATH.split('/')));
|
|
834
|
+
const requestedValue = stringFlag(options, 'cache-exclude');
|
|
835
|
+
const confirmUpdate = options['confirm-cache-exclusions'] === true;
|
|
836
|
+
if (typeof options['confirm-cache-exclusions'] !== 'boolean' &&
|
|
837
|
+
options['confirm-cache-exclusions'] !== undefined) {
|
|
838
|
+
throw new UsageError("init: '--confirm-cache-exclusions' must be a boolean flag");
|
|
839
|
+
}
|
|
840
|
+
if (requestedValue === undefined) {
|
|
841
|
+
if (confirmUpdate)
|
|
842
|
+
throw new UsageError('init: --confirm-cache-exclusions requires --cache-exclude');
|
|
843
|
+
return { files: current, changed: false };
|
|
844
|
+
}
|
|
845
|
+
const requested = requestedValue.trim() === ''
|
|
846
|
+
? []
|
|
847
|
+
: validateRequestedCacheFiles(io.cwd, requestedValue.split(',').map((file) => file.trim()).filter((file) => file.length > 0), config);
|
|
848
|
+
const changed = JSON.stringify(requested) !== JSON.stringify(current);
|
|
849
|
+
if (declarationExists && changed && !confirmUpdate) {
|
|
850
|
+
throw new UsageError(`init: changing ${CACHE_EXCLUSIONS_PATH} needs explicit owner review; repeat with --confirm-cache-exclusions`);
|
|
851
|
+
}
|
|
852
|
+
if (declarationExists && !changed && confirmUpdate) {
|
|
853
|
+
throw new UsageError('init: --confirm-cache-exclusions requires a changed --cache-exclude list');
|
|
854
|
+
}
|
|
855
|
+
return { files: requested, changed };
|
|
856
|
+
}
|
|
553
857
|
/**
|
|
554
858
|
* Runs discovery over the repo's own include/exclude config, infers a
|
|
555
859
|
* planes proposal from the discovered table directories, self-checks
|
|
@@ -587,15 +891,21 @@ async function proposePlanesConfig(cwd, io) {
|
|
|
587
891
|
if (inference.skippedTestTables > 0) {
|
|
588
892
|
writeLine(io.stdout, `note: ${inference.skippedTestTables} table(s) under test directories were excluded from plane inference (fixtures are not business surface)`);
|
|
589
893
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
894
|
+
// A reviewed file with zero rules is a real answer, not a failure:
|
|
895
|
+
// it declares no plane, which is exactly what the classifier already
|
|
896
|
+
// assumes while the file is absent. Writing it anyway is what makes
|
|
897
|
+
// `gateforge init --planes` the runnable prerequisite the
|
|
898
|
+
// `gateforge next` guidance prints for an unresolved route.
|
|
899
|
+
const serialized = `${JSON.stringify(inference.config ?? { rules: [] }, null, 2)}\n`;
|
|
595
900
|
// Self-check the draft against the runtime's strict reader contract
|
|
596
901
|
// BEFORE writing (a broken proposal must fail here, not at the next run).
|
|
597
902
|
parsePlanesConfigText(serialized, planesPath);
|
|
598
903
|
writeFileSync(planesPath, serialized, 'utf8');
|
|
904
|
+
if (inference.config === null) {
|
|
905
|
+
writeLine(io.stdout, `created: ${planesPath} (no rule could be inferred — ${inference.note ?? 'nothing to propose'}; ` +
|
|
906
|
+
'the file declares no plane, so every table still blocks until you add a reviewed rule)');
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
599
909
|
writeLine(io.stdout, `created: ${planesPath} (${inference.config.rules.length} rule(s) inferred from model directories — review the reasons before the next gateforge run)`);
|
|
600
910
|
}
|
|
601
911
|
/**
|
|
@@ -609,12 +919,18 @@ async function proposePlanesConfig(cwd, io) {
|
|
|
609
919
|
* number: exit code (0).
|
|
610
920
|
*/
|
|
611
921
|
export async function initCommand(io, argv) {
|
|
922
|
+
// The ledger every writer below fills: the closing summary names only
|
|
923
|
+
// what THIS run created or kept, so it can never offer to delete the
|
|
924
|
+
// owner's pre-existing config, baselines, waivers, hooks or CI file.
|
|
925
|
+
io.initPaths ??= { created: [], preserved: [] };
|
|
612
926
|
const { options } = parseArgs(argv);
|
|
613
927
|
if (options['help'] === true) {
|
|
614
928
|
writeLine(io.stdout, INIT_USAGE);
|
|
615
929
|
return 0;
|
|
616
930
|
}
|
|
617
931
|
rejectUnknownFlags(options, [
|
|
932
|
+
'preset',
|
|
933
|
+
'explain-presets',
|
|
618
934
|
'languages',
|
|
619
935
|
'plugins',
|
|
620
936
|
'accept-recommended',
|
|
@@ -632,10 +948,28 @@ export async function initCommand(io, argv) {
|
|
|
632
948
|
'planes',
|
|
633
949
|
'no-planes',
|
|
634
950
|
'behavior',
|
|
951
|
+
'no-behavior',
|
|
952
|
+
'behavior-packs',
|
|
635
953
|
'docs-exclude',
|
|
636
954
|
'confirm-doc-exclusions',
|
|
955
|
+
'cache-exclude',
|
|
956
|
+
'confirm-cache-exclusions',
|
|
637
957
|
'help',
|
|
638
958
|
], INIT_USAGE);
|
|
959
|
+
// --explain-presets prints the ONE mapping table and exits: it must
|
|
960
|
+
// never scan, prompt or write, so an agent can read what a preset
|
|
961
|
+
// means before choosing one.
|
|
962
|
+
if (options['explain-presets'] === true) {
|
|
963
|
+
writeLine(io.stdout, renderPresetTable());
|
|
964
|
+
return 0;
|
|
965
|
+
}
|
|
966
|
+
if (typeof options['explain-presets'] !== 'boolean' && options['explain-presets'] !== undefined) {
|
|
967
|
+
throw new UsageError("flag '--explain-presets' must be a boolean flag");
|
|
968
|
+
}
|
|
969
|
+
const presetValue = options['preset'];
|
|
970
|
+
if (presetValue !== undefined && !isInitPresetName(presetValue)) {
|
|
971
|
+
throw new UsageError(`flag '--preset' must be 'light', 'normal' or 'strict' (got '${String(presetValue)}')`);
|
|
972
|
+
}
|
|
639
973
|
// --proof validation BEFORE any writes: the selected proof path
|
|
640
974
|
// (overlay default, observe reuses the existing suite).
|
|
641
975
|
const proofValue = options['proof'];
|
|
@@ -683,10 +1017,24 @@ export async function initCommand(io, argv) {
|
|
|
683
1017
|
if (explicitLanguages !== null && explicitLanguages.length === 0) {
|
|
684
1018
|
throw new UsageError(`flag '--languages' requires at least one language`);
|
|
685
1019
|
}
|
|
686
|
-
const strictE2E = options['strict-e2e'] === true;
|
|
687
1020
|
if (typeof options['strict-e2e'] !== 'boolean' && options['strict-e2e'] !== undefined) {
|
|
688
|
-
throw new UsageError(
|
|
1021
|
+
throw new UsageError("flag '--strict-e2e' must be a boolean flag");
|
|
689
1022
|
}
|
|
1023
|
+
// Goal resolution (plan Phase 1/2): --preset wins, then the one goal
|
|
1024
|
+
// question in a terminal, then light with a loud note. A run that
|
|
1025
|
+
// already carries explicit enforcement flags has chosen for itself, so
|
|
1026
|
+
// no preset is applied and today's byte-identical behavior is kept.
|
|
1027
|
+
const enforcementFlagGiven = options['blocking'] === true ||
|
|
1028
|
+
options['no-blocking'] === true ||
|
|
1029
|
+
options['pre-commit'] === true ||
|
|
1030
|
+
options['no-pre-commit'] === true ||
|
|
1031
|
+
options['witnessed'] !== undefined ||
|
|
1032
|
+
options['mode'] !== undefined ||
|
|
1033
|
+
options['ci'] === true ||
|
|
1034
|
+
options['no-ci'] === true ||
|
|
1035
|
+
options['strict-e2e'] === true;
|
|
1036
|
+
const goal = await resolveGoal(io, options, enforcementFlagGiven, existsSync(join(io.cwd, '.gateforge.yml')));
|
|
1037
|
+
const strictE2E = goal !== null ? goal.settings.strictE2E : options['strict-e2e'] === true;
|
|
690
1038
|
// Strict-setup preflight (plan Phase 0 item 4): BEFORE anything is
|
|
691
1039
|
// written — a strict setup demanding an unavailable proof channel
|
|
692
1040
|
// stays visibly incomplete instead of shipping a false green. The
|
|
@@ -705,6 +1053,18 @@ export async function initCommand(io, argv) {
|
|
|
705
1053
|
signals: noScan ? [] : scanRepo(io.cwd).signals,
|
|
706
1054
|
}
|
|
707
1055
|
: scanRepo(io.cwd);
|
|
1056
|
+
// Which runner the scan saw. The `runner:` key is owner-owned, so it
|
|
1057
|
+
// is written ONLY when exactly one non-Playwright runner was detected:
|
|
1058
|
+
// Playwright stays the frozen default, and an ambiguous repository
|
|
1059
|
+
// (Playwright + something else, or several others) keeps today's
|
|
1060
|
+
// behavior plus one plain line naming the choice it left to the owner.
|
|
1061
|
+
const detectedRunners = DETECTABLE_RUNNERS.filter((runner) => scan.signals.includes(runner));
|
|
1062
|
+
const otherRunners = detectedRunners.filter((runner) => runner !== 'playwright');
|
|
1063
|
+
const detectedRunner = detectedRunners.includes('playwright') || otherRunners.length !== 1 ? undefined : otherRunners[0];
|
|
1064
|
+
if (otherRunners.length > 0 && detectedRunner === undefined) {
|
|
1065
|
+
writeLine(io.stdout, `note: other test runners detected (${otherRunners.join(', ')}); the new config keeps the default runner — ` +
|
|
1066
|
+
"set `runner: <playwright|pytest|vitest|cypress>` in .gateforge.yml to pick one");
|
|
1067
|
+
}
|
|
708
1068
|
const recommended = explicitPlugins ?? recommendPlugins(scan);
|
|
709
1069
|
writeLine(io.stdout, renderScanBlock(scan, recommended, proofMode));
|
|
710
1070
|
// Flags win: an explicit --plugins choice skips the prompt entirely.
|
|
@@ -713,9 +1073,26 @@ export async function initCommand(io, argv) {
|
|
|
713
1073
|
return 0;
|
|
714
1074
|
}
|
|
715
1075
|
const cwd = io.cwd;
|
|
1076
|
+
// Whether `.gateforge.yml` was already there BEFORE this run: the
|
|
1077
|
+
// preset summary must tell the truth about what changed.
|
|
1078
|
+
const existedConfigAtStart = existsSync(join(io.cwd, '.gateforge.yml'));
|
|
1079
|
+
const historyRetentionDays = existsSync(join(cwd, '.gateforge.yml')) ? undefined : await resolveHistoryRetention(io);
|
|
716
1080
|
const languages = scan.languages;
|
|
717
1081
|
const pluginIds = recommended;
|
|
718
|
-
const
|
|
1082
|
+
const configOptions = {
|
|
1083
|
+
strictE2E,
|
|
1084
|
+
enforcement: strictE2E ||
|
|
1085
|
+
options['blocking'] === true ||
|
|
1086
|
+
options['pre-commit'] === true ||
|
|
1087
|
+
(options['witnessed'] === 'staged' || options['witnessed'] === 'full'),
|
|
1088
|
+
historyRetentionDays,
|
|
1089
|
+
// A preset names the owner-owned strictness key; without one the key
|
|
1090
|
+
// stays absent, which means `strict` (today's frozen behavior).
|
|
1091
|
+
strictnessMode: goal?.settings.strictnessMode,
|
|
1092
|
+
// The scanned runner, when it is unambiguous and not Playwright.
|
|
1093
|
+
runner: detectedRunner,
|
|
1094
|
+
};
|
|
1095
|
+
const generatedDraftConfig = () => parseConfig(parseYaml(configTemplate(languages, pluginIds, configOptions)), { file: '.gateforge.yml' });
|
|
719
1096
|
let draftConfig;
|
|
720
1097
|
if (existsSync(join(cwd, '.gateforge.yml'))) {
|
|
721
1098
|
try {
|
|
@@ -723,8 +1100,11 @@ export async function initCommand(io, argv) {
|
|
|
723
1100
|
}
|
|
724
1101
|
catch (error) {
|
|
725
1102
|
const docsChoiceRequested = stringFlag(options, 'docs-exclude') !== undefined;
|
|
1103
|
+
const cacheChoiceRequested = stringFlag(options, 'cache-exclude') !== undefined;
|
|
726
1104
|
if (docsChoiceRequested ||
|
|
1105
|
+
cacheChoiceRequested ||
|
|
727
1106
|
existsSync(join(cwd, ...DOCS_EXCLUSIONS_PATH.split('/'))) ||
|
|
1107
|
+
existsSync(join(cwd, ...CACHE_EXCLUSIONS_PATH.split('/'))) ||
|
|
728
1108
|
(process.stdin.isTTY === true && process.stdout.isTTY === true)) {
|
|
729
1109
|
throw error;
|
|
730
1110
|
}
|
|
@@ -735,6 +1115,7 @@ export async function initCommand(io, argv) {
|
|
|
735
1115
|
draftConfig = generatedDraftConfig();
|
|
736
1116
|
}
|
|
737
1117
|
const docsExclusionChoice = await resolveDocsExclusionsForInit(io, options, draftConfig);
|
|
1118
|
+
const cacheExclusionChoice = resolveCacheExclusionsForInit(io, options, draftConfig);
|
|
738
1119
|
const gateforgeDir = join(cwd, '.gateforge');
|
|
739
1120
|
const targets = [
|
|
740
1121
|
{
|
|
@@ -744,8 +1125,8 @@ export async function initCommand(io, argv) {
|
|
|
744
1125
|
// Self-check the template against the pinned schema before
|
|
745
1126
|
// writing anything (a broken template must fail here, not in
|
|
746
1127
|
// every later command).
|
|
747
|
-
parseConfig(parseYaml(configTemplate(languages, pluginIds,
|
|
748
|
-
writeFileSync(join(cwd, '.gateforge.yml'), configTemplate(languages, pluginIds,
|
|
1128
|
+
parseConfig(parseYaml(configTemplate(languages, pluginIds, configOptions)), { file: '.gateforge.yml' });
|
|
1129
|
+
writeFileSync(join(cwd, '.gateforge.yml'), configTemplate(languages, pluginIds, configOptions), 'utf8');
|
|
749
1130
|
},
|
|
750
1131
|
},
|
|
751
1132
|
{
|
|
@@ -809,27 +1190,94 @@ export async function initCommand(io, argv) {
|
|
|
809
1190
|
},
|
|
810
1191
|
});
|
|
811
1192
|
}
|
|
1193
|
+
if (cacheExclusionChoice.changed) {
|
|
1194
|
+
const exclusionPath = join(cwd, ...CACHE_EXCLUSIONS_PATH.split('/'));
|
|
1195
|
+
const exclusionText = renderCacheExclusions(cacheExclusionChoice.files);
|
|
1196
|
+
targets.push({
|
|
1197
|
+
path: exclusionPath,
|
|
1198
|
+
label: 'owner-declared Python bytecode exclusions',
|
|
1199
|
+
write: () => {
|
|
1200
|
+
const temporaryPath = join(gateforgeDir, `.cache-exclusions-${randomUUID()}.tmp`);
|
|
1201
|
+
try {
|
|
1202
|
+
writeFileSync(temporaryPath, exclusionText, { flag: 'wx', encoding: 'utf8' });
|
|
1203
|
+
renameSync(temporaryPath, exclusionPath);
|
|
1204
|
+
}
|
|
1205
|
+
catch (error) {
|
|
1206
|
+
if (existsSync(temporaryPath))
|
|
1207
|
+
unlinkSync(temporaryPath);
|
|
1208
|
+
throw error;
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
812
1213
|
mkdirSync(join(gateforgeDir, 'adapters'), { recursive: true });
|
|
813
1214
|
mkdirSync(join(gateforgeDir, 'waivers'), { recursive: true });
|
|
814
1215
|
mkdirSync(join(gateforgeDir, 'baselines'), { recursive: true });
|
|
815
|
-
// Behavior-
|
|
816
|
-
// .gateforge/behavior.yml
|
|
817
|
-
//
|
|
818
|
-
//
|
|
819
|
-
// `--
|
|
820
|
-
|
|
1216
|
+
// Behavior-case setup (plan 2026-09-19 §4.11, Phase 4 of
|
|
1217
|
+
// 2026-09-25): `--behavior` scaffolds .gateforge/behavior.yml
|
|
1218
|
+
// (scaffold only — never real approval) and wires `behaviorPolicy`
|
|
1219
|
+
// into a NEW .gateforge.yml; an existing config is left untouched with
|
|
1220
|
+
// the exact line to add. `--behavior-packs <pack,...>` enables the
|
|
1221
|
+
// named packs' example cases; `--no-behavior` skips.
|
|
1222
|
+
//
|
|
1223
|
+
// Detection decides what init OFFERS, never what it enables: flags
|
|
1224
|
+
// win, then the terminal question, then nothing. A non-interactive
|
|
1225
|
+
// (agent/CI) run prints the exact flag for each pack it found and
|
|
1226
|
+
// enables none of them.
|
|
821
1227
|
const noBehavior = options['no-behavior'] === true;
|
|
822
|
-
const
|
|
1228
|
+
const behaviorFlag = options['behavior'] === true;
|
|
1229
|
+
const packsValue = options['behavior-packs'];
|
|
1230
|
+
if (typeof packsValue === 'boolean' || Array.isArray(packsValue)) {
|
|
1231
|
+
throw new UsageError("flag '--behavior-packs' may only be given once");
|
|
1232
|
+
}
|
|
1233
|
+
if (typeof packsValue !== 'string' && packsValue !== undefined) {
|
|
1234
|
+
throw new UsageError("flag '--behavior-packs' must be a comma-separated list of pack names");
|
|
1235
|
+
}
|
|
1236
|
+
let requestedNamespaces = [];
|
|
1237
|
+
if (packsValue !== undefined) {
|
|
1238
|
+
try {
|
|
1239
|
+
requestedNamespaces = parseBehaviorPacks(packsValue);
|
|
1240
|
+
}
|
|
1241
|
+
catch (cause) {
|
|
1242
|
+
throw new UsageError(`flag '--behavior-packs': ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
1243
|
+
}
|
|
1244
|
+
if (requestedNamespaces.length === 0) {
|
|
1245
|
+
throw new UsageError("flag '--behavior-packs' requires at least one pack name");
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
// The `task` pack is offered ONLY when the owner's config declares a
|
|
1249
|
+
// `queueObserver`: without the engine's own queue read every `task:*`
|
|
1250
|
+
// case fails closed, so recommending it would print a flag whose cases
|
|
1251
|
+
// can never be satisfied. Absent the block the offer is byte-identical
|
|
1252
|
+
// to a repository that has no background work at all.
|
|
1253
|
+
const detectedPacks = noScan || noBehavior
|
|
1254
|
+
? []
|
|
1255
|
+
: detectBehaviorPacks(cwd, draftConfig.queueObserver !== undefined);
|
|
1256
|
+
const enabledNamespaces = await resolveBehaviorPacks(io, {
|
|
1257
|
+
detectedPacks,
|
|
1258
|
+
explicit: requestedNamespaces,
|
|
1259
|
+
enableAll: behaviorFlag && requestedNamespaces.length === 0,
|
|
1260
|
+
disabled: noBehavior,
|
|
1261
|
+
});
|
|
1262
|
+
const wantBehavior = enabledNamespaces.length > 0 || (behaviorFlag && !noBehavior);
|
|
823
1263
|
if (wantBehavior) {
|
|
824
1264
|
const behaviorPath = join(gateforgeDir, 'behavior.yml');
|
|
1265
|
+
const enabledPacks = detectedPacks.filter((pack) => enabledNamespaces.includes(pack.namespace));
|
|
1266
|
+
const template = `${BEHAVIOR_TEMPLATE}${behaviorSkeletonExamples(enabledPacks)}`;
|
|
825
1267
|
if (existsSync(behaviorPath)) {
|
|
826
1268
|
writeLine(io.stdout, `exists, leaving untouched: ${behaviorPath}`);
|
|
1269
|
+
for (const pack of enabledPacks) {
|
|
1270
|
+
writeLine(io.stdout, ` the ${pack.namespace} example case for this repository — add it under 'endpoints:' in ${behaviorPath}:`);
|
|
1271
|
+
for (const line of behaviorSkeletonExamples([pack]).split('\n').slice(1)) {
|
|
1272
|
+
writeLine(io.stdout, ` ${line}`);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
827
1275
|
}
|
|
828
1276
|
else {
|
|
829
1277
|
targets.push({
|
|
830
1278
|
path: behaviorPath,
|
|
831
1279
|
label: 'complete-behavior document (SCAFFOLD — not approval)',
|
|
832
|
-
write: () => writeFileSync(behaviorPath,
|
|
1280
|
+
write: () => writeFileSync(behaviorPath, template, 'utf8'),
|
|
833
1281
|
});
|
|
834
1282
|
}
|
|
835
1283
|
if (!existsSync(join(cwd, '.gateforge.yml'))) {
|
|
@@ -837,7 +1285,7 @@ export async function initCommand(io, argv) {
|
|
|
837
1285
|
path: join(cwd, '.gateforge.yml'),
|
|
838
1286
|
label: 'config (with behaviorPolicy)',
|
|
839
1287
|
write: () => {
|
|
840
|
-
const text = configTemplate(languages, pluginIds,
|
|
1288
|
+
const text = configTemplate(languages, pluginIds, configOptions);
|
|
841
1289
|
const withBehavior = text.replace(/^policies:/m, 'behaviorPolicy: .gateforge/behavior.yml\npolicies:');
|
|
842
1290
|
parseConfig(parseYaml(withBehavior), { file: '.gateforge.yml' });
|
|
843
1291
|
writeFileSync(join(cwd, '.gateforge.yml'), withBehavior, 'utf8');
|
|
@@ -845,20 +1293,47 @@ export async function initCommand(io, argv) {
|
|
|
845
1293
|
});
|
|
846
1294
|
}
|
|
847
1295
|
else {
|
|
848
|
-
writeLine(io.stdout, 'note: existing .gateforge.yml left untouched — add
|
|
1296
|
+
writeLine(io.stdout, 'note: existing .gateforge.yml left untouched — add this line to it to enable the profile:');
|
|
1297
|
+
writeLine(io.stdout, ' behaviorPolicy: .gateforge/behavior.yml');
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
// An EXPLICIT `--plugins` on an initialized repository ADDS the
|
|
1301
|
+
// requested detectors to the owner's config instead of being ignored.
|
|
1302
|
+
// The merge is additive (an existing entry keeps the owner's version
|
|
1303
|
+
// pin; nothing is removed) and touches only the `plugins:` list, so
|
|
1304
|
+
// the product's own tip — "re-run with --plugins … to change
|
|
1305
|
+
// detectors" — is finally true. Every other key, comment, and edit in
|
|
1306
|
+
// the file is preserved byte for byte, and the schema is checked
|
|
1307
|
+
// before anything is written.
|
|
1308
|
+
if (explicitPlugins !== null && existsSync(join(cwd, '.gateforge.yml'))) {
|
|
1309
|
+
const configPath = join(cwd, '.gateforge.yml');
|
|
1310
|
+
const merged = mergePluginsIntoConfig(readFileSync(configPath, 'utf8'), explicitPlugins);
|
|
1311
|
+
if (merged === null) {
|
|
1312
|
+
writeLine(io.stdout, `${explicitPlugins.join(', ')} already configured in ${configPath}; leaving it untouched`);
|
|
1313
|
+
}
|
|
1314
|
+
else {
|
|
1315
|
+
writeFileSync(configPath, merged, 'utf8');
|
|
1316
|
+
const added = loadConfig(configPath).plugins
|
|
1317
|
+
.map((plugin) => plugin.id)
|
|
1318
|
+
.filter((id) => explicitPlugins.includes(id));
|
|
1319
|
+
recordInitPath(io, cwd, configPath, 'preserved');
|
|
1320
|
+
writeLine(io.stdout, `updated: ${configPath} (added detector(s): ${added.join(', ')} — every other key left as it was)`);
|
|
849
1321
|
}
|
|
850
1322
|
}
|
|
851
1323
|
for (const target of targets) {
|
|
852
1324
|
if (existsSync(target.path)) {
|
|
853
|
-
if (target.label === 'owner-declared documentation exclusions' && docsExclusionChoice.changed)
|
|
1325
|
+
if ((target.label === 'owner-declared documentation exclusions' && docsExclusionChoice.changed) ||
|
|
1326
|
+
(target.label === 'owner-declared Python bytecode exclusions' && cacheExclusionChoice.changed)) {
|
|
854
1327
|
target.write();
|
|
855
1328
|
writeLine(io.stdout, `updated: ${target.path}`);
|
|
856
1329
|
continue;
|
|
857
1330
|
}
|
|
1331
|
+
recordInitPath(io, cwd, target.path, 'preserved');
|
|
858
1332
|
writeLine(io.stdout, `exists, leaving untouched: ${target.path}`);
|
|
859
1333
|
continue;
|
|
860
1334
|
}
|
|
861
1335
|
target.write();
|
|
1336
|
+
recordInitPath(io, cwd, target.path, 'created');
|
|
862
1337
|
writeLine(io.stdout, `created: ${target.path}`);
|
|
863
1338
|
}
|
|
864
1339
|
// Observe proof checklist (observe proof only): the work no scaffold
|
|
@@ -880,6 +1355,14 @@ export async function initCommand(io, argv) {
|
|
|
880
1355
|
writeLine(io.stdout, `candidate policy digest to approve outside the repository: ${approvalDigest}`);
|
|
881
1356
|
writeLine(io.stdout, 'set GATEFORGE_APPROVED_POLICY_DIGEST in a protected owner environment to this exact digest; without a matching pin, Gateforge refuses to use the exclusions');
|
|
882
1357
|
}
|
|
1358
|
+
if (cacheExclusionChoice.files.length > 0) {
|
|
1359
|
+
const writtenConfig = loadConfig(join(cwd, '.gateforge.yml'));
|
|
1360
|
+
const approvalDigest = trustedPolicyDigestForConfig(cwd, writtenConfig);
|
|
1361
|
+
writeLine(io.stdout, `owner-declared Python bytecode files: ${cacheExclusionChoice.files.join(', ')}`);
|
|
1362
|
+
writeLine(io.stdout, `warning: ${CACHE_EXCLUSIONS_GUARANTEE}`);
|
|
1363
|
+
writeLine(io.stdout, `candidate policy digest to approve outside the repository: ${approvalDigest}`);
|
|
1364
|
+
writeLine(io.stdout, 'set GATEFORGE_APPROVED_POLICY_DIGEST in a protected owner environment to this exact digest; without a matching pin, Gateforge refuses to use the exclusions');
|
|
1365
|
+
}
|
|
883
1366
|
// Plane-config proposal (flags win; TTY prompt fills the gap;
|
|
884
1367
|
// non-interactive defaults to scaffold-only, like every granular step):
|
|
885
1368
|
// --planes / --no-planes
|
|
@@ -887,7 +1370,14 @@ export async function initCommand(io, argv) {
|
|
|
887
1370
|
// discovered tables live in — a review artifact with a reason on
|
|
888
1371
|
// every rule, written only when absent, never silently applied
|
|
889
1372
|
// (the next run reads it and the user reviews first).
|
|
890
|
-
|
|
1373
|
+
//
|
|
1374
|
+
// An EXPLICIT `--planes` is always honored: it is the runnable
|
|
1375
|
+
// prerequisite the `gateforge next` guidance prints for an unresolved
|
|
1376
|
+
// route, and a language gate would make that printed command a no-op
|
|
1377
|
+
// on exactly the repositories that need it. The proposal itself is
|
|
1378
|
+
// conservative — no discovered table means no inferred rule.
|
|
1379
|
+
const planesRequested = options['planes'] === true;
|
|
1380
|
+
if (planesRequested || languages.includes('python')) {
|
|
891
1381
|
if (await resolvePlanes(io, options)) {
|
|
892
1382
|
await proposePlanesConfig(cwd, io);
|
|
893
1383
|
}
|
|
@@ -925,14 +1415,23 @@ export async function initCommand(io, argv) {
|
|
|
925
1415
|
if (witnessedValue !== undefined && modeValue !== undefined) {
|
|
926
1416
|
throw new UsageError("init: --witnessed selects the pre-commit execution mode and cannot be combined with '--mode'");
|
|
927
1417
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1418
|
+
// The goal decides the wiring; explicit flags already short-circuited
|
|
1419
|
+
// goal resolution above, so nothing here can contradict a flag. When
|
|
1420
|
+
// there is no goal, today's granular behavior is unchanged.
|
|
1421
|
+
const blocking = goal !== null ? goal.settings.wiring === 'blocking' : await resolveBlocking(io, options);
|
|
1422
|
+
const preCommit = options['pre-commit'] === true ||
|
|
1423
|
+
blocking ||
|
|
1424
|
+
witnessedValue !== undefined ||
|
|
1425
|
+
(goal !== null && goal.settings.wiring === 'pre-commit');
|
|
1426
|
+
const ci = options['ci'] === true || blocking || (goal !== null && goal.settings.ci);
|
|
1427
|
+
const receiptStage = preCommit ? loadConfig(join(cwd, '.gateforge.yml')).enforcement?.receiptStage : undefined;
|
|
931
1428
|
const mode = typeof modeValue === 'string'
|
|
932
1429
|
? modeValue
|
|
933
|
-
:
|
|
934
|
-
?
|
|
935
|
-
:
|
|
1430
|
+
: goal !== null
|
|
1431
|
+
? goal.settings.mode
|
|
1432
|
+
: blocking
|
|
1433
|
+
? 'staged'
|
|
1434
|
+
: 'changed';
|
|
936
1435
|
if (preCommit) {
|
|
937
1436
|
const hookDir = join(gateforgeDir, 'hooks');
|
|
938
1437
|
mkdirSync(hookDir, { recursive: true });
|
|
@@ -944,8 +1443,12 @@ export async function initCommand(io, argv) {
|
|
|
944
1443
|
: witnessedValue === 'full'
|
|
945
1444
|
? ['pre-commit', '--scope', 'full']
|
|
946
1445
|
: mode === 'staged'
|
|
947
|
-
?
|
|
948
|
-
|
|
1446
|
+
? receiptStage === 'pre-push' || receiptStage === 'ci'
|
|
1447
|
+
? ['check', '--staged']
|
|
1448
|
+
: ['check', '--staged', '--require-e2e']
|
|
1449
|
+
: receiptStage === 'pre-commit'
|
|
1450
|
+
? ['check', '--changed', '--require-e2e']
|
|
1451
|
+
: ['check', '--changed'];
|
|
949
1452
|
ensureHookScript(io, engineRootFromInvocation(), gateArgs);
|
|
950
1453
|
// The ACTIVE hook (plan Phase 5 item 1): install into the resolved
|
|
951
1454
|
// hooks directory AND verify activation — never merely write a
|
|
@@ -972,6 +1475,11 @@ export async function initCommand(io, argv) {
|
|
|
972
1475
|
// integrates through the framework config instead (appendPreCommitHook
|
|
973
1476
|
// below) — the hook block runs on every commit like any other.
|
|
974
1477
|
const frameworkManaged = outcome.status === 'framework';
|
|
1478
|
+
// The undo list must name the hook this run installed and NOT name
|
|
1479
|
+
// one that was already there.
|
|
1480
|
+
if (outcome.hookPath !== null) {
|
|
1481
|
+
recordInitPath(io, cwd, outcome.hookPath, outcome.status === 'installed' ? 'created' : 'preserved');
|
|
1482
|
+
}
|
|
975
1483
|
switch (outcome.status) {
|
|
976
1484
|
case 'installed':
|
|
977
1485
|
writeLine(io.stdout, `installed: ${outcome.detail}`);
|
|
@@ -998,8 +1506,41 @@ export async function initCommand(io, argv) {
|
|
|
998
1506
|
'Honest limit: `git commit --no-verify` bypasses the local hook (ADR 0005 D1) — standard enforcement also requires the trusted server check.'
|
|
999
1507
|
: `blocking gate wired: active pre-commit hook (${gateArgs.join(' ')}) + .gitlab-ci.yml include. ` +
|
|
1000
1508
|
'Honest limit: `git commit --no-verify` bypasses the local hook (ADR 0005 D1) — standard enforcement also requires the trusted server check.');
|
|
1509
|
+
if (receiptStage === 'pre-push') {
|
|
1510
|
+
const pushHook = installPrePushHook(cwd, io.env);
|
|
1511
|
+
if (pushHook.status === 'conflict' || pushHook.status === 'incomplete') {
|
|
1512
|
+
throw new UsageError(`${pushHook.detail}\nRequired action:\n${pushHook.action}`);
|
|
1513
|
+
}
|
|
1514
|
+
if (pushHook.hookPath !== null) {
|
|
1515
|
+
recordInitPath(io, cwd, pushHook.hookPath, pushHook.status === 'installed' ? 'created' : 'preserved');
|
|
1516
|
+
}
|
|
1517
|
+
writeLine(io.stdout, `${pushHook.status}: ${pushHook.detail}`);
|
|
1518
|
+
}
|
|
1519
|
+
writeServerProtectionInstructions(io);
|
|
1520
|
+
}
|
|
1521
|
+
// A preset can ask for the CI job without a local hook (`normal`):
|
|
1522
|
+
// the server check is then the only place the gate runs, which is a
|
|
1523
|
+
// real choice, not a fallback.
|
|
1524
|
+
if (ci && !preCommit) {
|
|
1525
|
+
writeSharedGitlabCiTemplate(io, 'strict');
|
|
1526
|
+
}
|
|
1527
|
+
// What the goal wrote, in plain words, plus the command that undoes it.
|
|
1528
|
+
if (goal !== null) {
|
|
1529
|
+
const ledger = io.initPaths;
|
|
1530
|
+
for (const line of renderPresetSummary(goal.name, {
|
|
1531
|
+
configExisted: existedConfigAtStart,
|
|
1532
|
+
autoChosen: goal.autoChosen === true,
|
|
1533
|
+
created: [...(ledger?.created ?? [])],
|
|
1534
|
+
repoHasCommitHook: existsSync(join(cwd, '.git/hooks/pre-commit')),
|
|
1535
|
+
repoHasCi: existsSync(join(cwd, '.gitlab-ci.yml')) || existsSync(join(cwd, '.github/workflows/gateforge.yml')),
|
|
1536
|
+
})) {
|
|
1537
|
+
writeLine(io.stdout, line);
|
|
1538
|
+
}
|
|
1001
1539
|
}
|
|
1002
1540
|
writeLine(io.stdout, 'skeleton ready: .gateforge/adapters, .gateforge/waivers, .gateforge/baselines');
|
|
1541
|
+
const alembicOptIn = renderAlembicOptIn(cwd);
|
|
1542
|
+
if (alembicOptIn !== null)
|
|
1543
|
+
writeLine(io.stdout, alembicOptIn);
|
|
1003
1544
|
return 0;
|
|
1004
1545
|
}
|
|
1005
1546
|
//# sourceMappingURL=init.js.map
|