@gate-forge/cli 0.7.1 → 0.9.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 +91 -704
- package/dist/adapter-audit.d.ts +208 -0
- package/dist/adapter-audit.d.ts.map +1 -0
- package/dist/adapter-audit.js +579 -0
- package/dist/adapter-audit.js.map +1 -0
- package/dist/adapter-scaffold.d.ts +91 -0
- package/dist/adapter-scaffold.d.ts.map +1 -0
- package/dist/adapter-scaffold.js +474 -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 +61 -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 +751 -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 +355 -0
- package/dist/commands/adapters.js.map +1 -0
- package/dist/commands/adopt.d.ts +7 -0
- package/dist/commands/adopt.d.ts.map +1 -1
- package/dist/commands/adopt.js +44 -2
- 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 +105 -2
- package/dist/commands/blocking.d.ts.map +1 -1
- package/dist/commands/blocking.js +395 -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 +1068 -64
- 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 +188 -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 +880 -33
- package/dist/commands/enforcement.js.map +1 -1
- package/dist/commands/explain.d.ts +1 -1
- package/dist/commands/explain.d.ts.map +1 -1
- package/dist/commands/explain.js +162 -3
- package/dist/commands/explain.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 +155 -0
- package/dist/commands/init-presets.d.ts.map +1 -0
- package/dist/commands/init-presets.js +203 -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 +987 -99
- 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 +846 -19
- 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 +3620 -187
- 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 +264 -29
- package/dist/commands/tests.js.map +1 -1
- package/dist/docs-exclusions.d.ts.map +1 -1
- package/dist/docs-exclusions.js +18 -3
- package/dist/docs-exclusions.js.map +1 -1
- package/dist/endpoint-compiler.d.ts.map +1 -1
- package/dist/endpoint-compiler.js +78 -9
- 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 +105 -1
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +149 -18
- 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/gateforge-owned.d.ts +78 -0
- package/dist/gateforge-owned.d.ts.map +1 -0
- package/dist/gateforge-owned.js +254 -0
- package/dist/gateforge-owned.js.map +1 -0
- package/dist/git-hooks.d.ts +35 -0
- package/dist/git-hooks.d.ts.map +1 -1
- package/dist/git-hooks.js +140 -1
- package/dist/git-hooks.js.map +1 -1
- package/dist/git-ignored.d.ts +27 -0
- package/dist/git-ignored.d.ts.map +1 -0
- package/dist/git-ignored.js +102 -0
- package/dist/git-ignored.js.map +1 -0
- 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/glob.d.ts +33 -14
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +96 -5
- package/dist/glob.js.map +1 -1
- 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/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- 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 +49 -0
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +22 -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 +67 -1
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +164 -6
- package/dist/pipeline.js.map +1 -1
- package/dist/planes-inference.d.ts +12 -5
- package/dist/planes-inference.d.ts.map +1 -1
- package/dist/planes-inference.js +13 -15
- package/dist/planes-inference.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 +15 -1
- package/dist/repo-scan.d.ts.map +1 -1
- package/dist/repo-scan.js +329 -34
- 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/route-plane-proposals.d.ts +100 -0
- package/dist/route-plane-proposals.d.ts.map +1 -0
- package/dist/route-plane-proposals.js +213 -0
- package/dist/route-plane-proposals.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/scope.d.ts +20 -0
- package/dist/scope.d.ts.map +1 -1
- package/dist/scope.js +26 -5
- package/dist/scope.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 +82 -0
- package/dist/singleton-guidance.d.ts.map +1 -0
- package/dist/singleton-guidance.js +138 -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/unmatched-routes.d.ts +60 -0
- package/dist/unmatched-routes.d.ts.map +1 -0
- package/dist/unmatched-routes.js +131 -0
- package/dist/unmatched-routes.js.map +1 -0
- 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 +425 -0
- package/guides/QUICKSTART.md +306 -26
- package/guides/REFERENCE.md +1710 -0
- package/guides/RUNNER-NEUTRAL-EVIDENCE.md +199 -0
- package/guides/TEST-ENVIRONMENT.md +1044 -6
- package/guides/UPGRADE-0.6-to-0.7.md +3 -3
- package/guides/UPGRADE-0.7-to-0.8.md +114 -0
- package/guides/UPGRADE-0.8-to-0.9.md +104 -0
- package/package.json +10 -9
package/dist/commands/next.js
CHANGED
|
@@ -8,23 +8,105 @@
|
|
|
8
8
|
* prints the single highest-ranked item. Exit 0 when clean, 1 when a
|
|
9
9
|
* next action exists, 2 on config/usage errors.
|
|
10
10
|
*/
|
|
11
|
-
import { existsSync } from 'node:fs';
|
|
11
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
12
|
+
import { parse as parseYaml } from 'yaml';
|
|
12
13
|
import { join } from 'node:path';
|
|
13
|
-
import { BLOCKING_VERDICTS, CAUSE_NEXT_ACTIONS, } from '@gate-forge/core';
|
|
14
|
-
import {
|
|
14
|
+
import { BLOCKING_VERDICTS, CAUSE_NEXT_ACTIONS, BEHAVIOR_CASE_DOMAIN, HTTP_ENDPOINT_RESOURCE_KIND, PolicyFileSchema, sha256Canonical, } from '@gate-forge/core';
|
|
15
|
+
import { ENDPOINT_SEMANTICS_UNRESOLVED, FASTAPI_PREFIX_UNRESOLVED, } from '@gate-forge/http-contract';
|
|
16
|
+
import { PLANES_CONFIG_PATH } from '@gate-forge/pack-sqlalchemy';
|
|
17
|
+
import { FASTAPI_SCAN_CONFIG_PATH } from '@gate-forge/pack-fastapi';
|
|
18
|
+
import { discoverTestCatalog, TestDiscoveryError, } from '@gate-forge/pack-playwright';
|
|
15
19
|
import { parseArgs } from '../args.js';
|
|
16
20
|
import { resolveAdoptedBaseline } from '../adopted-baseline.js';
|
|
17
21
|
import { UsageError } from '../errors.js';
|
|
18
22
|
import { writeLine } from '../io.js';
|
|
19
23
|
import { evaluateRun } from '../evaluate.js';
|
|
20
|
-
import { loadOptionalTestMap, mappedCoverageFrom, mappingBlocking, resolveRepositoryMappings, } from '../mapping.js';
|
|
21
|
-
import { collectInputFiles, computeInputSnapshot, diffInputFiles, SnapshotUnavailableError, UnsupportedSnapshotError, } from '../input-snapshot.js';
|
|
24
|
+
import { findRunnerConfigPath, loadOptionalTestMap, mappedCoverageFrom, mappingBlocking, nativeInventoryBlocking, resolveRepositoryMappings, } from '../mapping.js';
|
|
25
|
+
import { collectInputFiles, computeInputSnapshot, diffInputFiles, symlinkNotices, SnapshotUnavailableError, UnsupportedSnapshotError, } from '../input-snapshot.js';
|
|
22
26
|
import { runPipeline, sourcesByResourceId } from '../pipeline.js';
|
|
23
27
|
import { resolveProvider } from '../providers.js';
|
|
24
28
|
import { computeEvaluationScope, detectStagedWorkingTreeMismatches } from '../scope.js';
|
|
25
29
|
import { httpRoutesView, resolveStateDir } from '../state.js';
|
|
30
|
+
import { gateforgeOwnedInputs } from '../gateforge-owned.js';
|
|
31
|
+
import { engineGeneratedStateFileFilter } from '../state-artifacts.js';
|
|
26
32
|
import { loadConfigAt, rejectUnknownFlags, VERIFIER_KEY_ENV } from './common.js';
|
|
33
|
+
import { loadCacheExclusions } from '../cache-exclusions.js';
|
|
34
|
+
import { singletonPerTenantGuidanceLines } from '../singleton-guidance.js';
|
|
35
|
+
import { unmatchedRouteBannerLines } from '../unmatched-routes.js';
|
|
36
|
+
import { buildEndpointDeclaration, loadBehaviorRecipes, renderProofSpec, renderTestMapEntries, } from '../behavior-setup.js';
|
|
37
|
+
import { ENDPOINT_CAPABILITIES, ENDPOINTS_CONFIG_PATH } from '../endpoint-config.js';
|
|
27
38
|
export const NEXT_USAGE = 'usage: gateforge next [--changed] [--json]';
|
|
39
|
+
/**
|
|
40
|
+
* The causes that mean "this repository has no proof yet" rather than
|
|
41
|
+
* "this proof failed". A fresh repository owes all three at once, so the
|
|
42
|
+
* behavior setup is printed for any of them.
|
|
43
|
+
*/
|
|
44
|
+
const SETUP_CAUSES = [
|
|
45
|
+
'ENDPOINT_BEHAVIOR_MISSING',
|
|
46
|
+
'TEST_INVENTORY_INCOMPLETE',
|
|
47
|
+
'TEST_MAPPING_MISSING',
|
|
48
|
+
];
|
|
49
|
+
const ENVIRONMENT_GUIDES = {
|
|
50
|
+
EVIDENCE_STALE: 'packages/cli/guides/TEST-ENVIRONMENT.md#keep-the-repository-unchanged-during-a-run',
|
|
51
|
+
ENFORCEMENT_UNTRUSTED: 'packages/cli/guides/TEST-ENVIRONMENT.md#run-containers-as-your-user',
|
|
52
|
+
RUN_INCOMPLETE: 'packages/cli/guides/TEST-ENVIRONMENT.md#register-the-same-tests-in-every-mode',
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Endpoint identities that carry real application weight.
|
|
56
|
+
*
|
|
57
|
+
* A route the engine LINKED to a business model, or that the frontend
|
|
58
|
+
* statically CONSUMES, is business surface: answering it moves the
|
|
59
|
+
* product forward. A route with neither (a demo endpoint, an internal
|
|
60
|
+
* probe, a leftover script) is still reported — it is never hidden —
|
|
61
|
+
* but it must not be the FIRST thing an agent or an owner is told to
|
|
62
|
+
* do, which is where alphabetical id order used to put it: the top item
|
|
63
|
+
* of a thousand was a fifteen-line demo app's `/api/test`.
|
|
64
|
+
*
|
|
65
|
+
* Both the plane-qualified resource id and the bare resource name are
|
|
66
|
+
* registered, because a plane-unresolved endpoint has no id at all and
|
|
67
|
+
* is reported under its name.
|
|
68
|
+
*
|
|
69
|
+
* Args:
|
|
70
|
+
* graph: the built resource graph.
|
|
71
|
+
*
|
|
72
|
+
* Returns:
|
|
73
|
+
* ReadonlySet<string>: the focused route identities.
|
|
74
|
+
*/
|
|
75
|
+
function focusedRouteKeys(graph) {
|
|
76
|
+
const keys = new Set();
|
|
77
|
+
for (const resource of graph.resources) {
|
|
78
|
+
if (resource.kind !== HTTP_ENDPOINT_RESOURCE_KIND)
|
|
79
|
+
continue;
|
|
80
|
+
const linked = resource.attributes['linkedResourceName'];
|
|
81
|
+
const isLinked = typeof linked === 'string' && linked.length > 0;
|
|
82
|
+
if (!isLinked && resource.attributes['frontendConsumed'] !== true)
|
|
83
|
+
continue;
|
|
84
|
+
if (resource.id !== null)
|
|
85
|
+
keys.add(resource.id);
|
|
86
|
+
keys.add(resource.name);
|
|
87
|
+
}
|
|
88
|
+
return keys;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Whether one ranked item belongs to a focused route — either the route
|
|
92
|
+
* itself or an obligation carried by it (`<resourceId>:<contract>`).
|
|
93
|
+
*
|
|
94
|
+
* Args:
|
|
95
|
+
* focused: the focused route identities.
|
|
96
|
+
* id: the candidate id (resource name/id, or an obligation id).
|
|
97
|
+
*
|
|
98
|
+
* Returns:
|
|
99
|
+
* number: 0 when focused, 1 otherwise.
|
|
100
|
+
*/
|
|
101
|
+
function routeFocus(focused, id) {
|
|
102
|
+
if (focused.has(id))
|
|
103
|
+
return 0;
|
|
104
|
+
for (const key of focused) {
|
|
105
|
+
if (id.startsWith(`${key}:`))
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
return 1;
|
|
109
|
+
}
|
|
28
110
|
/**
|
|
29
111
|
* Ranks a cause per the plan §2 table: capability gaps first, mapping
|
|
30
112
|
* intent last, everything else blocking after that.
|
|
@@ -35,7 +117,7 @@ function rankCause(cause, kind) {
|
|
|
35
117
|
return 1;
|
|
36
118
|
// Complete-behavior setup/declaration problems block before any
|
|
37
119
|
// test-generation advice: an owner document gap is not something a
|
|
38
|
-
// test can fix
|
|
120
|
+
// test can fix.
|
|
39
121
|
case 'ENDPOINT_BEHAVIOR_MISSING':
|
|
40
122
|
case 'BEHAVIOR_REFERENCE_STALE':
|
|
41
123
|
case 'BEHAVIOR_CASE_UNMAPPED':
|
|
@@ -46,6 +128,15 @@ function rankCause(cause, kind) {
|
|
|
46
128
|
case 'BEHAVIOR_UNEXPECTED_EFFECT':
|
|
47
129
|
case 'ENFORCEMENT_BOUNDARY_UNVERIFIED':
|
|
48
130
|
return 2;
|
|
131
|
+
case 'MIGRATION_MISSING':
|
|
132
|
+
case 'MIGRATION_LINEAGE_BROKEN':
|
|
133
|
+
case 'MIGRATION_DOWNGRADE_NOOP':
|
|
134
|
+
case 'MIGRATION_DRIFT':
|
|
135
|
+
case 'MIGRATION_ROUNDTRIP_FAILED':
|
|
136
|
+
case 'MIGRATION_DATA_LOST':
|
|
137
|
+
case 'MIGRATION_CONFLICT':
|
|
138
|
+
case 'MIGRATION_SCRATCH_UNSAFE':
|
|
139
|
+
return 2;
|
|
49
140
|
case 'CRUD_COVERAGE_MISSING':
|
|
50
141
|
return 3;
|
|
51
142
|
case 'CHANGE_UNMAPPED':
|
|
@@ -59,6 +150,8 @@ function rankCause(cause, kind) {
|
|
|
59
150
|
case 'TEST_NOT_EXECUTED':
|
|
60
151
|
case 'TEST_FAILED':
|
|
61
152
|
return 7;
|
|
153
|
+
case 'TEST_INVENTORY_INCOMPLETE':
|
|
154
|
+
return 0;
|
|
62
155
|
case 'TEST_MAPPING_MISSING':
|
|
63
156
|
case 'TEST_MAPPING_AMBIGUOUS':
|
|
64
157
|
case 'TEST_MAPPING_STALE':
|
|
@@ -81,9 +174,24 @@ function rankCause(cause, kind) {
|
|
|
81
174
|
}
|
|
82
175
|
/**
|
|
83
176
|
* Normalizes blocking entries + blocking verdicts into ranked
|
|
84
|
-
* candidates
|
|
177
|
+
* candidates.
|
|
178
|
+
*
|
|
179
|
+
* Order: cause rank first (unchanged — a capability gap still outranks
|
|
180
|
+
* everything), then business weight, then id. The focus tie-break only
|
|
181
|
+
* ever reorders items of the SAME rank, so it cannot demote anything
|
|
182
|
+
* the plan says must come first; it only stops alphabetical id order
|
|
183
|
+
* from putting an unlinked demo route at the top of a thousand-item
|
|
184
|
+
* list.
|
|
185
|
+
*
|
|
186
|
+
* Args:
|
|
187
|
+
* blocking: the run's blocking entries.
|
|
188
|
+
* verdicts: the run's obligation verdicts.
|
|
189
|
+
* focused: endpoint identities with real business weight.
|
|
190
|
+
*
|
|
191
|
+
* Returns:
|
|
192
|
+
* NextCandidate[]: ranked candidates.
|
|
85
193
|
*/
|
|
86
|
-
function rankBlockers(blocking, verdicts) {
|
|
194
|
+
function rankBlockers(blocking, verdicts, focused) {
|
|
87
195
|
const candidates = [];
|
|
88
196
|
for (const entry of blocking) {
|
|
89
197
|
const cause = entry.cause ?? null;
|
|
@@ -92,8 +200,14 @@ function rankBlockers(blocking, verdicts) {
|
|
|
92
200
|
cause: cause ?? 'BLOCKING_FINDING',
|
|
93
201
|
why: entry.detail,
|
|
94
202
|
do: entry.nextAction ??
|
|
95
|
-
(cause !== null
|
|
203
|
+
(cause !== null
|
|
204
|
+
? CAUSE_NEXT_ACTIONS[cause]
|
|
205
|
+
: entry.resourceId !== null && entry.resourceId !== undefined
|
|
206
|
+
? `gateforge explain ${entry.resourceId}`
|
|
207
|
+
: 'gateforge discover --json'),
|
|
208
|
+
kind: entry.kind,
|
|
96
209
|
rank: rankCause(cause, entry.kind),
|
|
210
|
+
focus: routeFocus(focused, entry.resourceId ?? entry.name ?? 'repo'),
|
|
97
211
|
});
|
|
98
212
|
}
|
|
99
213
|
for (const verdict of verdicts) {
|
|
@@ -106,12 +220,594 @@ function rankBlockers(blocking, verdicts) {
|
|
|
106
220
|
why: verdict.reason ?? `obligation '${verdict.obligation.id}' is ${verdict.verdict}`,
|
|
107
221
|
do: verdict.nextAction ??
|
|
108
222
|
(cause !== null ? CAUSE_NEXT_ACTIONS[cause] : CAUSE_NEXT_ACTIONS['EVIDENCE_NOT_COLLECTED']),
|
|
223
|
+
kind: 'verdict',
|
|
109
224
|
rank: rankCause(cause, 'verdict'),
|
|
225
|
+
focus: routeFocus(focused, verdict.obligation.id),
|
|
110
226
|
});
|
|
111
227
|
}
|
|
112
|
-
candidates.sort((a, b) =>
|
|
228
|
+
candidates.sort((a, b) => a.rank !== b.rank
|
|
229
|
+
? a.rank - b.rank
|
|
230
|
+
: a.focus !== b.focus
|
|
231
|
+
? a.focus - b.focus
|
|
232
|
+
: a.id < b.id
|
|
233
|
+
? -1
|
|
234
|
+
: a.id > b.id
|
|
235
|
+
? 1
|
|
236
|
+
: 0);
|
|
113
237
|
return candidates;
|
|
114
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* The state-changing command that clears ONE classifier block. A code
|
|
241
|
+
* with no entry here is never given an invented command.
|
|
242
|
+
*/
|
|
243
|
+
const CLASSIFIER_BLOCK_ANSWERS = {
|
|
244
|
+
ADAPTER_MISSING: '`gateforge adapters scaffold` — run it, then review the adapter it writes for this resource',
|
|
245
|
+
DELETE_SEMANTICS_UNRESOLVED: "declare what the endpoint does in '.gateforge/endpoints.json' — 'crud-archive' or 'crud-delete' on a DELETE endpoint (an ENDPOINT_SEMANTICS_UNRESOLVED block prints the exact entry)",
|
|
246
|
+
PLANE_UNRESOLVED: "gateforge classify plane <file|folder|glob> <tenant|master|global> --reason '<why>' --confirm — or change the existing rule for that source in '.gateforge/planes.json'",
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* The answer for a resource the classifier blocked DEFINITIONALLY: it
|
|
250
|
+
* has no effective classification, so nothing on it can be graded.
|
|
251
|
+
*
|
|
252
|
+
* The block used to be exactly three lines ending in `do: gateforge
|
|
253
|
+
* classify --json` — a read-only dump that writes nothing, so the
|
|
254
|
+
* documented loop (run the printed command, run `next` again) printed
|
|
255
|
+
* the identical block forever, and nothing named the blocks that
|
|
256
|
+
* actually hold the resource. `gateforge explain <id>` shows them, so
|
|
257
|
+
* the id this block prints is the one that resolves.
|
|
258
|
+
*
|
|
259
|
+
* Args:
|
|
260
|
+
* candidate: the ranked next item.
|
|
261
|
+
* decisions: the run's classifier decisions.
|
|
262
|
+
*
|
|
263
|
+
* Returns:
|
|
264
|
+
* { do: string; lines: string[] }: the imperative action and the
|
|
265
|
+
* explanation, or `null` when this candidate is not such a block.
|
|
266
|
+
*/
|
|
267
|
+
function classifierBlockGuidance(candidate, decisions) {
|
|
268
|
+
if (candidate.kind !== 'unclassified')
|
|
269
|
+
return null;
|
|
270
|
+
const decision = decisions.find((row) => row.name === candidate.id || row.resourceId === candidate.id);
|
|
271
|
+
const blocks = decision?.blocks ?? [];
|
|
272
|
+
if (blocks.length === 0)
|
|
273
|
+
return null;
|
|
274
|
+
const first = blocks[0];
|
|
275
|
+
const answer = CLASSIFIER_BLOCK_ANSWERS[first.code];
|
|
276
|
+
return {
|
|
277
|
+
do: answer ?? `read every block on this resource with \`gateforge explain ${shellQuote(candidate.id)}\``,
|
|
278
|
+
lines: [
|
|
279
|
+
'about this block: the classifier refused this resource definitionally, so it carries no effective',
|
|
280
|
+
'classification and nothing on it can be graded. `gateforge classify --json` only LISTS these blocks — it',
|
|
281
|
+
'writes nothing, so running it and running `gateforge next` again prints this identical block. What closes',
|
|
282
|
+
'each one:',
|
|
283
|
+
...blocks.map((block) => ` [${block.code}] — ${CLASSIFIER_BLOCK_ANSWERS[block.code] ?? 'nothing in Gateforge closes this on your behalf; its evidence is below'}`),
|
|
284
|
+
`Read every block and the evidence behind it: gateforge explain ${shellQuote(candidate.id)}`,
|
|
285
|
+
],
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Quotes one shell argument so generated commands can be copied safely.
|
|
290
|
+
*
|
|
291
|
+
* Args:
|
|
292
|
+
* value: the argument text.
|
|
293
|
+
*
|
|
294
|
+
* Returns:
|
|
295
|
+
* string: a POSIX single-quoted argument.
|
|
296
|
+
*/
|
|
297
|
+
function shellQuote(value) {
|
|
298
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Builds owner-directed advice for an endpoint with no resolved plane.
|
|
302
|
+
*
|
|
303
|
+
* Every printed command runs exactly as printed, and no line printed
|
|
304
|
+
* with it is something a user could paste into a shell by mistake: the
|
|
305
|
+
* prerequisite that creates the owner-reviewed planes file is printed
|
|
306
|
+
* FIRST (the plane command below it exits 2 without that file) and ONLY
|
|
307
|
+
* while that file is absent — repeating "run this once" on every route
|
|
308
|
+
* makes the sentence false for everyone but the first.
|
|
309
|
+
*
|
|
310
|
+
* Args:
|
|
311
|
+
* routeName: canonical method and path shown to the user.
|
|
312
|
+
* resourceName: detector identity used by the owner-only policy edit.
|
|
313
|
+
* source: router source file used by the plane writer.
|
|
314
|
+
* cwd: absolute repository root (the planes file is repo-relative).
|
|
315
|
+
*
|
|
316
|
+
* Returns:
|
|
317
|
+
* string[]: ordered question, runnable commands, and exact policy edit.
|
|
318
|
+
*/
|
|
319
|
+
function unresolvedRouteGuidance(routeName, resourceName, source, cwd) {
|
|
320
|
+
const choices = ['tenant', 'master', 'global'];
|
|
321
|
+
const commands = choices.map((plane) => {
|
|
322
|
+
const reason = `Owner review confirms the ${plane} plane for ${routeName}.`;
|
|
323
|
+
return `gateforge classify plane ${shellQuote(source)} ${plane} --reason ${shellQuote(reason)} --confirm`;
|
|
324
|
+
});
|
|
325
|
+
const planesMissing = !existsSync(join(cwd, PLANES_CONFIG_PATH));
|
|
326
|
+
return [
|
|
327
|
+
// One plain line BEFORE the question: a new repo meets this
|
|
328
|
+
// question first, and no shipped document prepares anyone for it.
|
|
329
|
+
// It says what is being asked, why only the owner can answer it,
|
|
330
|
+
// and what each answer does next — so the question is answerable
|
|
331
|
+
// from the output alone.
|
|
332
|
+
'about this question: this route has no data plane, so Gateforge cannot tell whether its records are ' +
|
|
333
|
+
'per-tenant, shared master data, or global — that is an owner decision no detector can read from the ' +
|
|
334
|
+
'code. Answer once, then run only the `classify plane` command for that answer (tenant / master / ' +
|
|
335
|
+
'global), or, if the route is not used by real users, the internal rule printed at the end.',
|
|
336
|
+
`question: ${routeName} — is this route used by real users, and which data plane owns its records?`,
|
|
337
|
+
'This edits a classification input; re-approve any approved policy pin before strict gates run.',
|
|
338
|
+
...(planesMissing
|
|
339
|
+
? [
|
|
340
|
+
`The plane command below needs the owner-reviewed '${PLANES_CONFIG_PATH}' first — run this once to create it:`,
|
|
341
|
+
'gateforge init --planes',
|
|
342
|
+
]
|
|
343
|
+
: []),
|
|
344
|
+
'Then choose only the command for the boundary confirmed by the owner:',
|
|
345
|
+
...commands,
|
|
346
|
+
'Owner-only alternative: only if this route is genuinely internal, edit `.gateforge/classification-policy.yml` under `internalRules`:',
|
|
347
|
+
' - match:',
|
|
348
|
+
' resourceKind: http.endpoint',
|
|
349
|
+
` resourceName: ${JSON.stringify(resourceName)}`,
|
|
350
|
+
' reason: "<owner-written reason and evidence for treating this route as internal>"',
|
|
351
|
+
'An internal rule is certificate-checked; it is not an override.',
|
|
352
|
+
];
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Builds the owner-authored capability declaration for an endpoint whose
|
|
356
|
+
* semantics no detector could prove, so the block that otherwise ends in
|
|
357
|
+
* a read-only `discover --json` dump becomes answerable from the output
|
|
358
|
+
* alone.
|
|
359
|
+
*
|
|
360
|
+
* The printed document IS the schema the compiler reads (see
|
|
361
|
+
* `endpoint-config.ts`): one rule, scoped to THIS endpoint by its exact
|
|
362
|
+
* method and canonical path, with the two owner-chosen fields marked and
|
|
363
|
+
* their allowed values named. Nothing else is invented — the selectors
|
|
364
|
+
* and the rule shape are the product's own, so a declaration copied out
|
|
365
|
+
* of this block parses and applies.
|
|
366
|
+
*
|
|
367
|
+
* Args:
|
|
368
|
+
* detail: the blocking entry's detail (the compiler's own sentence).
|
|
369
|
+
* graph: the run's resource graph (the endpoint identity comes from it).
|
|
370
|
+
*
|
|
371
|
+
* Returns:
|
|
372
|
+
* string[]: the explanation, the exact entry, and the verify command;
|
|
373
|
+
* an empty array when the detail is not an unresolved endpoint or the
|
|
374
|
+
* graph carries no matching identity.
|
|
375
|
+
*/
|
|
376
|
+
function endpointSemanticsGuidance(detail, graph) {
|
|
377
|
+
if (!detail.startsWith(`${ENDPOINT_SEMANTICS_UNRESOLVED}:`))
|
|
378
|
+
return [];
|
|
379
|
+
const route = graph.resources.find((resource) => {
|
|
380
|
+
if (resource.kind !== HTTP_ENDPOINT_RESOURCE_KIND)
|
|
381
|
+
return false;
|
|
382
|
+
const identity = resource.attributes['identity'];
|
|
383
|
+
return typeof identity === 'string' && detail.includes(`endpoint '${identity}'`);
|
|
384
|
+
});
|
|
385
|
+
if (route === undefined)
|
|
386
|
+
return [];
|
|
387
|
+
const method = route.attributes['method'];
|
|
388
|
+
const canonicalPath = route.attributes['canonicalPath'];
|
|
389
|
+
if (typeof method !== 'string' || typeof canonicalPath !== 'string')
|
|
390
|
+
return [];
|
|
391
|
+
// A DELETE is asked one question (archive or really delete); every
|
|
392
|
+
// other verb is asked what the endpoint DOES at all.
|
|
393
|
+
const choices = method === 'DELETE'
|
|
394
|
+
? [
|
|
395
|
+
"'crud-archive' (the record survives — the handler only sets an archived/deactivated state)",
|
|
396
|
+
"'crud-delete' (the record is really removed)",
|
|
397
|
+
]
|
|
398
|
+
: [`one of: ${ENDPOINT_CAPABILITIES.join(', ')}`];
|
|
399
|
+
return [
|
|
400
|
+
`about this block: ${method} ${canonicalPath} is discovered, but nothing Gateforge can read in the code says what it DOES —`,
|
|
401
|
+
'its logic sits behind a service call, and a method alone never decides semantics. Only the owner can',
|
|
402
|
+
`answer, and the answer is one rule in the owner-reviewed '${ENDPOINTS_CONFIG_PATH}'. Add it to that file`,
|
|
403
|
+
'(create the file with exactly these contents if it does not exist yet; append the rule to "rules" if it does):',
|
|
404
|
+
'```json',
|
|
405
|
+
'{',
|
|
406
|
+
' "rules": [',
|
|
407
|
+
' {',
|
|
408
|
+
` "method": ${JSON.stringify(method)},`,
|
|
409
|
+
` "paths": [${JSON.stringify(canonicalPath)}],`,
|
|
410
|
+
' "capability": "<owner choice>",',
|
|
411
|
+
' "reason": "<owner-written reason and evidence: what this handler really does>"',
|
|
412
|
+
' }',
|
|
413
|
+
' ]',
|
|
414
|
+
'}',
|
|
415
|
+
'```',
|
|
416
|
+
`Then replace <owner choice> with the capability the handler really has — ${choices.join(', or ')} —`,
|
|
417
|
+
'and write the reason as the evidence you read (the code, service contract or table that proves it).',
|
|
418
|
+
...(route.id === null
|
|
419
|
+
? []
|
|
420
|
+
: [
|
|
421
|
+
'Then prove the declaration applied — the capabilities line names the capability and the trace says endpoints.json:',
|
|
422
|
+
`gateforge explain ${shellQuote(route.id)}`,
|
|
423
|
+
]),
|
|
424
|
+
];
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Builds the answer for a `FASTAPI_PREFIX_UNRESOLVED` finding: an
|
|
428
|
+
* `include_router(...)` mount the detector cannot follow, so no route
|
|
429
|
+
* fact is emitted for it at all.
|
|
430
|
+
*
|
|
431
|
+
* Gateforge never guesses the effective path (a fabricated path is a
|
|
432
|
+
* route the app does not serve), so the block names the ONE mechanism
|
|
433
|
+
* that closes the reason it is actually reporting. The cause code covers
|
|
434
|
+
* several DISTINCT reasons, and the guidance therefore keys on the
|
|
435
|
+
* REASON in the detail, never on the code:
|
|
436
|
+
*
|
|
437
|
+
* - a COMPUTED prefix (`include_router prefix in <file> is computed`,
|
|
438
|
+
* `router '<x>' in <file> declares a computed prefix`): the value is
|
|
439
|
+
* hidden in an expression, so the fix is a literal at the mount site.
|
|
440
|
+
* Nothing else reaches it, and that is verified, not assumed — a
|
|
441
|
+
* `.gateforge/endpoints.json` capability rule cannot match (no route
|
|
442
|
+
* fact is emitted for this mount, so a rule has no method/path to
|
|
443
|
+
* select on) and `gateforge waive` cannot resolve it (`waive: no
|
|
444
|
+
* obligation resolves for …`, exit 2).
|
|
445
|
+
* - an UNRESOLVABLE or AMBIGUOUS target (`include_router target '<x>' in
|
|
446
|
+
* <file> cannot be resolved in the scanned set`, and the import-alias
|
|
447
|
+
* form of the same thing): the mount names a router the scanner cannot
|
|
448
|
+
* follow, so NO prefix edit can apply — the mount may carry no prefix
|
|
449
|
+
* at all. The remedy is a declaration,
|
|
450
|
+
* `.gateforge/fastapi.json`'s `importRoots`, naming the directory the
|
|
451
|
+
* absolute imports in that file are written relative to. Verified
|
|
452
|
+
* against the real python detector on the canonical template shape
|
|
453
|
+
* (`backend/app/main.py` including `app.api.main.api_router`, which
|
|
454
|
+
* includes `app.api.routes.<module>.router`): with the roots declared
|
|
455
|
+
* the whole mount resolves and every route carries its real prefix,
|
|
456
|
+
* with NO application edit — see
|
|
457
|
+
* `pack-fastapi/test/template-mount.test.ts`.
|
|
458
|
+
* - an include CYCLE: no declaration reaches it, so the block says only
|
|
459
|
+
* that.
|
|
460
|
+
*
|
|
461
|
+
* Args:
|
|
462
|
+
* detail: the finding's `why` line (the reason code and its detail).
|
|
463
|
+
* cwd: the repository root, used to derive the import root from the
|
|
464
|
+
* file the finding names — and to print none when it cannot.
|
|
465
|
+
*
|
|
466
|
+
* Returns:
|
|
467
|
+
* string[]: the explanation and the real fix, or an empty array
|
|
468
|
+
* when the detail is not this cause.
|
|
469
|
+
*/
|
|
470
|
+
function fastapiPrefixGuidance(detail, cwd) {
|
|
471
|
+
if (!detail.startsWith(`${FASTAPI_PREFIX_UNRESOLVED}:`))
|
|
472
|
+
return [];
|
|
473
|
+
// Every detail names the file the unprovable mount is written in, so
|
|
474
|
+
// the owner is pointed at the exact file rather than at a guess.
|
|
475
|
+
const site = /\bin (\S+) (?:is computed|declares a computed prefix|is an import alias)\b/.exec(detail)?.[1] ?? '';
|
|
476
|
+
if (/is computed|declares a computed prefix/.test(detail)) {
|
|
477
|
+
return [
|
|
478
|
+
'about this block: this mount writes its prefix from an expression, so the path every route under it ' +
|
|
479
|
+
'serves cannot be read from the code — a settings attribute, a constant, or a concatenation all ' +
|
|
480
|
+
'hide the value at scan time. Gateforge will not guess it: a made-up path would describe routes the ' +
|
|
481
|
+
'application does not serve, so the whole mount stays unresolved until the prefix is provable.',
|
|
482
|
+
`Fix it in ${site === '' ? 'the file the finding names' : site}: give the mount a literal string prefix ` +
|
|
483
|
+
'(for example `app.include_router(router, prefix="/api/v1")`). A module-level constant does not help ' +
|
|
484
|
+
'— the value must be written at the mount site.',
|
|
485
|
+
'Nothing in Gateforge can close this finding on your behalf: a waiver needs an obligation and this has ' +
|
|
486
|
+
'none, and a declared endpoint rule has no detected route to attach to. Re-run `gateforge next` after ' +
|
|
487
|
+
'the edit — the routes then appear with their real prefix.',
|
|
488
|
+
];
|
|
489
|
+
}
|
|
490
|
+
const ambiguousRoots = ambiguousImportRoots(detail);
|
|
491
|
+
const unresolvedSite = ambiguousRoots !== null
|
|
492
|
+
? site
|
|
493
|
+
: (/\bin (\S+) (?:cannot be resolved in the scanned set|matches multiple scanned files)\b/.exec(detail)?.[1] ?? site);
|
|
494
|
+
if (ambiguousRoots !== null || /cannot be resolved in the scanned set/.test(detail)) {
|
|
495
|
+
const derived = importRootForMountSite(unresolvedSite, cwd);
|
|
496
|
+
const roots = ambiguousRoots ?? (derived === '' ? null : [derived]);
|
|
497
|
+
const file = unresolvedSite === '' ? 'the file the finding names' : unresolvedSite;
|
|
498
|
+
return [
|
|
499
|
+
'about this block: this mount includes a router the scanner cannot follow, so the path every route under it',
|
|
500
|
+
'serves is unknown — the module it names is not one of the scanned files. Gateforge will not guess it: a',
|
|
501
|
+
'made-up path would describe routes the application does not serve. Making the prefix literal cannot help',
|
|
502
|
+
'here: this mount is not written with a computed prefix, so there is no prefix expression to replace.',
|
|
503
|
+
`Fix it with a declaration and NO application edit: the import roots tell the scanner which directory the`,
|
|
504
|
+
`absolute imports in ${file} are written relative to.`,
|
|
505
|
+
`Write this file — '${FASTAPI_SCAN_CONFIG_PATH}' — and run \`gateforge next\` again:`,
|
|
506
|
+
'```json',
|
|
507
|
+
JSON.stringify(roots === null
|
|
508
|
+
? { importRoots: ['<the source directory that file is imported from>'] }
|
|
509
|
+
: { importRoots: roots }, null, 2),
|
|
510
|
+
'```',
|
|
511
|
+
roots === null
|
|
512
|
+
? 'Replace the placeholder with that directory (one entry per import root). A root that does not hold the'
|
|
513
|
+
: 'The routes under this mount then carry their real prefix and this finding is gone. A root that does not hold the',
|
|
514
|
+
'unresolved module changes nothing — the scanned set stays closed, never guessed.',
|
|
515
|
+
];
|
|
516
|
+
}
|
|
517
|
+
if (/include cycle through/.test(detail)) {
|
|
518
|
+
return [
|
|
519
|
+
'about this block: the routers under this mount include each other in a cycle, so no order of mounts gives one',
|
|
520
|
+
`effective path. No declaration reaches this: break the cycle at the include sites in ${site === '' ? 'the file the finding names' : site},`,
|
|
521
|
+
'then re-run `gateforge next`.',
|
|
522
|
+
];
|
|
523
|
+
}
|
|
524
|
+
return [];
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* The one-line `do:` that opens a `FASTAPI_PREFIX_UNRESOLVED` block. It
|
|
528
|
+
* states the action of the reason {@link fastapiPrefixGuidance} explains:
|
|
529
|
+
* a computed prefix is an application edit, an unfollowable target is a
|
|
530
|
+
* declaration. `''` when the detail is not this cause.
|
|
531
|
+
*
|
|
532
|
+
* Args:
|
|
533
|
+
* detail: the finding's `why` line.
|
|
534
|
+
*
|
|
535
|
+
* Returns:
|
|
536
|
+
* string: the `do:` text, or `''`.
|
|
537
|
+
*/
|
|
538
|
+
function fastapiPrefixDo(detail) {
|
|
539
|
+
if (!detail.startsWith(`${FASTAPI_PREFIX_UNRESOLVED}:`))
|
|
540
|
+
return '';
|
|
541
|
+
if (/is computed|declares a computed prefix/.test(detail)) {
|
|
542
|
+
return 'make the mount prefix a literal at the site named below, then run `gateforge next` again';
|
|
543
|
+
}
|
|
544
|
+
if (ambiguousImportRoots(detail) !== null || /cannot be resolved in the scanned set/.test(detail)) {
|
|
545
|
+
return `declare the import roots in '${FASTAPI_SCAN_CONFIG_PATH}' — the exact entry to add is below`;
|
|
546
|
+
}
|
|
547
|
+
return 'break the include cycle at the site named below, then run `gateforge next` again';
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* The import roots an AMBIGUOUS-target detail already names, one per
|
|
551
|
+
* conflicting file, sorted. `null` when the detail is not ambiguous — the
|
|
552
|
+
* roots are then derived from the file the finding names instead.
|
|
553
|
+
*/
|
|
554
|
+
function ambiguousImportRoots(detail) {
|
|
555
|
+
const files = /\(([^)]*)\); the target router cannot be proven uniquely/.exec(detail)?.[1];
|
|
556
|
+
if (files === undefined)
|
|
557
|
+
return null;
|
|
558
|
+
const roots = new Set();
|
|
559
|
+
for (const file of files.split(',')) {
|
|
560
|
+
const trimmed = file.trim();
|
|
561
|
+
const cut = trimmed.lastIndexOf('/');
|
|
562
|
+
if (cut > 0)
|
|
563
|
+
roots.add(trimmed.slice(0, cut));
|
|
564
|
+
}
|
|
565
|
+
return roots.size === 0 ? null : [...roots].sort();
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* The source directory the finding's file is imported from, derived from
|
|
569
|
+
* that file alone: the SHORTEST directory prefix under which one of its
|
|
570
|
+
* own absolute imports is a real path on disk (`backend/app/api/main.py`
|
|
571
|
+
* importing `app.api.routes` → `backend`). `''` when it cannot be
|
|
572
|
+
* derived — the file is absent, has no absolute import, or every
|
|
573
|
+
* candidate is the repository root itself — so the guidance then names
|
|
574
|
+
* the declaration without inventing a directory.
|
|
575
|
+
*
|
|
576
|
+
* Args:
|
|
577
|
+
* file: the repo-relative file the finding names.
|
|
578
|
+
* cwd: the repository root.
|
|
579
|
+
*
|
|
580
|
+
* Returns:
|
|
581
|
+
* string: the repo-relative import root, or `''`.
|
|
582
|
+
*/
|
|
583
|
+
function importRootForMountSite(file, cwd) {
|
|
584
|
+
if (file === '' || file.startsWith('/'))
|
|
585
|
+
return '';
|
|
586
|
+
let source;
|
|
587
|
+
try {
|
|
588
|
+
source = readFileSync(join(cwd, file), 'utf8');
|
|
589
|
+
}
|
|
590
|
+
catch {
|
|
591
|
+
return '';
|
|
592
|
+
}
|
|
593
|
+
const modules = new Set();
|
|
594
|
+
for (const match of source.matchAll(/^\s*from\s+([A-Za-z_][A-Za-z0-9_.]*)\s+import\b/gmu)) {
|
|
595
|
+
const dotted = match[1];
|
|
596
|
+
if (dotted !== '')
|
|
597
|
+
modules.add(dotted);
|
|
598
|
+
}
|
|
599
|
+
if (modules.size === 0)
|
|
600
|
+
return '';
|
|
601
|
+
const segments = file.split('/');
|
|
602
|
+
// Longest prefix first so the FIRST hit is the shortest root.
|
|
603
|
+
for (let depth = segments.length - 1; depth >= 1; depth -= 1) {
|
|
604
|
+
const root = segments.slice(0, depth).join('/');
|
|
605
|
+
const holds = [...modules].some((dotted) => {
|
|
606
|
+
const base = join(cwd, root, dotted.replaceAll('.', '/'));
|
|
607
|
+
return existsSync(`${base}.py`) || existsSync(join(base, '__init__.py'));
|
|
608
|
+
});
|
|
609
|
+
if (holds)
|
|
610
|
+
return root;
|
|
611
|
+
}
|
|
612
|
+
return '';
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* The `http.endpoint.requireObservation` scope note (plan Phase 4c,
|
|
616
|
+
* E60), offered on the ONE item it can explain: an unmapped obligation
|
|
617
|
+
* on a route the frontend never calls, while the pinned option is `all`.
|
|
618
|
+
* That obligation exists only because the owner widened the scope, and
|
|
619
|
+
* narrowing it back is a legitimate answer when the route is out of
|
|
620
|
+
* scope. Anywhere else (option absent, consumed endpoints, other
|
|
621
|
+
* causes) nothing is printed — the surface never adds noise.
|
|
622
|
+
*
|
|
623
|
+
* Args:
|
|
624
|
+
candidate: the ranked next item.
|
|
625
|
+
graph: the run's resource graph.
|
|
626
|
+
* observationScope: the effective pinned option.
|
|
627
|
+
* policiesPath: repo-relative policies document path.
|
|
628
|
+
*
|
|
629
|
+
* Returns:
|
|
630
|
+
* string[]: the note lines, or an empty array when it does not apply.
|
|
631
|
+
*/
|
|
632
|
+
function observationScopeNote(candidate, graph, observationScope, policiesPath) {
|
|
633
|
+
if (observationScope !== 'all' || candidate.cause !== 'TEST_MAPPING_MISSING')
|
|
634
|
+
return [];
|
|
635
|
+
const route = graph.resources.find((resource) => resource.id !== null &&
|
|
636
|
+
resource.kind === HTTP_ENDPOINT_RESOURCE_KIND &&
|
|
637
|
+
candidate.id.startsWith(`${resource.id}:`) &&
|
|
638
|
+
resource.attributes['frontendConsumed'] !== true);
|
|
639
|
+
if (route === undefined)
|
|
640
|
+
return [];
|
|
641
|
+
const method = route.attributes['method'];
|
|
642
|
+
const path = route.attributes['canonicalPath'];
|
|
643
|
+
const name = typeof method === 'string' && typeof path === 'string' ? `${method} ${path}` : route.name;
|
|
644
|
+
return [
|
|
645
|
+
`scope: ${name} is not consumed by the frontend, so it owes this obligation only because the pinned`,
|
|
646
|
+
`policy option 'http.endpoint.requireObservation' is 'all'. Prove it with a test, or set the option`,
|
|
647
|
+
`back to 'consumed' in ${policiesPath} if this route is out of scope.`,
|
|
648
|
+
];
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* The complete behavior setup `gateforge next` prints for a discovered
|
|
652
|
+
* endpoint that has no approved cases yet (plan 2026-09-30 Phase 4).
|
|
653
|
+
*
|
|
654
|
+
* Every block is finished work, not a template: the resource id and
|
|
655
|
+
* route are the ones discovery reported, the effect scope is the
|
|
656
|
+
* repository's own adapter-backed entity, the recipe is the one declared
|
|
657
|
+
* under `fixtures/`, and the case ids are the ids the compiler hashes.
|
|
658
|
+
* When a fact the declaration needs is missing, nothing is printed as if
|
|
659
|
+
* it were known — the reason is printed instead.
|
|
660
|
+
*
|
|
661
|
+
* Args:
|
|
662
|
+
* input: the repository root, the policies document path, the run's
|
|
663
|
+
* graph, and the endpoint's classified resource id.
|
|
664
|
+
*
|
|
665
|
+
* Returns:
|
|
666
|
+
* string[]: the ordered steps, or an empty array when this candidate
|
|
667
|
+
* is not a behavior declaration gap.
|
|
668
|
+
*/
|
|
669
|
+
function behaviorDeclarationGuidance(input) {
|
|
670
|
+
const route = input.graph.resources.find((resource) => resource.id === input.resourceId && resource.kind === HTTP_ENDPOINT_RESOURCE_KIND);
|
|
671
|
+
if (route === undefined)
|
|
672
|
+
return [];
|
|
673
|
+
const method = route.attributes['method'];
|
|
674
|
+
const path = route.attributes['canonicalPath'];
|
|
675
|
+
if (typeof method !== 'string' || typeof path !== 'string')
|
|
676
|
+
return [];
|
|
677
|
+
const effects = input.graph.resources
|
|
678
|
+
.filter((resource) => resource.id !== null &&
|
|
679
|
+
resource.id !== input.resourceId &&
|
|
680
|
+
resource.classification?.evidenceAdapter !== undefined)
|
|
681
|
+
.map((resource) => {
|
|
682
|
+
const writable = resource.attributes['updateableFields'];
|
|
683
|
+
return {
|
|
684
|
+
id: resource.name,
|
|
685
|
+
resourceId: resource.id,
|
|
686
|
+
adapter: resource.classification?.evidenceAdapter,
|
|
687
|
+
identityFields: resource.classification?.primaryKey ?? [],
|
|
688
|
+
fields: Array.isArray(writable) && writable.every((field) => typeof field === 'string')
|
|
689
|
+
? writable
|
|
690
|
+
: (resource.classification?.primaryKey ?? []),
|
|
691
|
+
};
|
|
692
|
+
});
|
|
693
|
+
const endpoint = {
|
|
694
|
+
resourceId: input.resourceId,
|
|
695
|
+
routeName: `${method} ${path}`,
|
|
696
|
+
method,
|
|
697
|
+
path,
|
|
698
|
+
effects,
|
|
699
|
+
};
|
|
700
|
+
const declared = buildEndpointDeclaration({
|
|
701
|
+
endpoint,
|
|
702
|
+
requiredContracts: requiredContractsForEndpoints(input.cwd, input.policiesPath),
|
|
703
|
+
recipe: loadBehaviorRecipes(input.cwd)[0] ?? null,
|
|
704
|
+
caseIdFor: (resourceId, slug) => sha256Canonical({ domain: BEHAVIOR_CASE_DOMAIN, resourceId, id: slug }),
|
|
705
|
+
specFile: 'specs/gateforge-cases.spec.js',
|
|
706
|
+
project: 'chromium',
|
|
707
|
+
runner: input.runner,
|
|
708
|
+
});
|
|
709
|
+
if (declared.entry === null) {
|
|
710
|
+
return [
|
|
711
|
+
`about this gap: ${endpoint.routeName} (${input.resourceId}) has no approved behavior cases, and`,
|
|
712
|
+
'the complete declaration cannot be printed from what this repository declares:',
|
|
713
|
+
` ${declared.incompleteReason ?? 'no reason recorded'}`,
|
|
714
|
+
'next: fix that first, then re-run gateforge next',
|
|
715
|
+
];
|
|
716
|
+
}
|
|
717
|
+
return [
|
|
718
|
+
`about this gap: ${endpoint.routeName} (${input.resourceId}) is discovered but has no approved`,
|
|
719
|
+
'behavior cases, so nothing in this repository can prove what it must do. The steps below are',
|
|
720
|
+
'the whole remaining setup — every block is complete, so paste each one exactly as printed.',
|
|
721
|
+
"step 1 — declare the cases in .gateforge/behavior.yml (add this entry under 'endpoints:'):",
|
|
722
|
+
'```yaml',
|
|
723
|
+
declared.entry,
|
|
724
|
+
'```',
|
|
725
|
+
'step 2 — create specs/gateforge-cases.spec.js with exactly this content (one test per case;',
|
|
726
|
+
'the ENGINE drives each case, and the test only asserts the engine sealed it):',
|
|
727
|
+
'```js',
|
|
728
|
+
renderProofSpec({ resourceId: input.resourceId, cases: declared.cases }),
|
|
729
|
+
'```',
|
|
730
|
+
'step 3 — map every case to its test in .gateforge/test-map.yml (add these entries under',
|
|
731
|
+
"'tests:'; if the file does not exist yet, create it starting with 'schemaVersion: 1' and",
|
|
732
|
+
"'tests:'):",
|
|
733
|
+
'```yaml',
|
|
734
|
+
renderTestMapEntries({
|
|
735
|
+
cases: declared.cases,
|
|
736
|
+
specFile: 'specs/gateforge-cases.spec.js',
|
|
737
|
+
project: 'chromium',
|
|
738
|
+
runner: input.runner,
|
|
739
|
+
}),
|
|
740
|
+
'```',
|
|
741
|
+
'step 4 — run the gate:',
|
|
742
|
+
' npm run gate',
|
|
743
|
+
'then re-run gateforge next to see what, if anything, is still open',
|
|
744
|
+
];
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* The `task` behavior pack, offered under the same rule as every other
|
|
748
|
+
* pack: it is named only when the repository actually shows the
|
|
749
|
+
* machinery AND the engine can grade the claim. The engine's own
|
|
750
|
+
* `queueObserver` is that second half — without it every `task:*` case
|
|
751
|
+
* fails closed, so offering the pack would print a flag whose cases can
|
|
752
|
+
* never be satisfied. Both halves are required, so a repository
|
|
753
|
+
* without an observer is byte-identical to a repository with no
|
|
754
|
+
* background work.
|
|
755
|
+
*
|
|
756
|
+
* Args:
|
|
757
|
+
* graph: the run's resource graph.
|
|
758
|
+
* queueObserverConfigured: whether the loaded config declares one.
|
|
759
|
+
*
|
|
760
|
+
* Returns:
|
|
761
|
+
* string[]: the offer lines, or an empty array when it does not apply.
|
|
762
|
+
*/
|
|
763
|
+
function taskPackOffer(graph, queueObserverConfigured) {
|
|
764
|
+
if (!queueObserverConfigured)
|
|
765
|
+
return [];
|
|
766
|
+
const taskResource = graph.resources.find((resource) => resource.kind === 'task.resource' && resource.id !== null);
|
|
767
|
+
if (taskResource === undefined)
|
|
768
|
+
return [];
|
|
769
|
+
return [
|
|
770
|
+
'the task behavior pack is gradable in this repository (a queueObserver is configured',
|
|
771
|
+
`and '${taskResource.id}' is a discovered task resource), so its cases can be enabled:`,
|
|
772
|
+
' task — the engine reads the delivery queue itself to grade these contracts',
|
|
773
|
+
' gateforge init --behavior-packs task',
|
|
774
|
+
];
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* The contracts the repository's policy document requires of every HTTP
|
|
778
|
+
* endpoint. Unreadable or absent policies yield none, which keeps the
|
|
779
|
+
* guidance quiet on a repository that has approved no behavior yet.
|
|
780
|
+
*
|
|
781
|
+
* Args:
|
|
782
|
+
* cwd: absolute repository root.
|
|
783
|
+
* policiesPath: repo-relative policies document path.
|
|
784
|
+
*
|
|
785
|
+
* Returns:
|
|
786
|
+
* string[]: the required contract names, deduplicated in print order.
|
|
787
|
+
*/
|
|
788
|
+
function requiredContractsForEndpoints(cwd, policiesPath) {
|
|
789
|
+
let text;
|
|
790
|
+
try {
|
|
791
|
+
text = readFileSync(join(cwd, policiesPath), 'utf8');
|
|
792
|
+
}
|
|
793
|
+
catch {
|
|
794
|
+
return [];
|
|
795
|
+
}
|
|
796
|
+
const parsed = PolicyFileSchema.safeParse(parseYaml(text));
|
|
797
|
+
if (!parsed.success)
|
|
798
|
+
return [];
|
|
799
|
+
const contracts = [];
|
|
800
|
+
for (const policy of parsed.data.policies) {
|
|
801
|
+
const coversEndpoints = policy.when?.kind === undefined || policy.when.kind === HTTP_ENDPOINT_RESOURCE_KIND;
|
|
802
|
+
if (!coversEndpoints)
|
|
803
|
+
continue;
|
|
804
|
+
for (const contract of policy.require) {
|
|
805
|
+
if (!contracts.includes(contract))
|
|
806
|
+
contracts.push(contract);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
return contracts;
|
|
810
|
+
}
|
|
115
811
|
/**
|
|
116
812
|
* Runs the `gateforge next` subcommand.
|
|
117
813
|
*
|
|
@@ -137,6 +833,7 @@ export async function nextCommand(io, argv) {
|
|
|
137
833
|
const asJson = options['json'] === true;
|
|
138
834
|
const witnessVerifierKey = io.env[VERIFIER_KEY_ENV];
|
|
139
835
|
const config = loadConfigAt(io.cwd);
|
|
836
|
+
const cacheExclusions = loadCacheExclusions(io.cwd, config);
|
|
140
837
|
const providerIdentity = diffScoped
|
|
141
838
|
? resolveProvider(config.changed.provider, io.cwd, io.env).provider
|
|
142
839
|
: 'all-files';
|
|
@@ -147,7 +844,7 @@ export async function nextCommand(io, argv) {
|
|
|
147
844
|
let preFiles = null;
|
|
148
845
|
let snapshotUnavailable = false;
|
|
149
846
|
try {
|
|
150
|
-
preFiles = collectInputFiles(io.cwd, config, stateDir);
|
|
847
|
+
preFiles = collectInputFiles(io.cwd, config, stateDir, [], [], cacheExclusions);
|
|
151
848
|
}
|
|
152
849
|
catch (error) {
|
|
153
850
|
if (error instanceof SnapshotUnavailableError) {
|
|
@@ -160,6 +857,14 @@ export async function nextCommand(io, argv) {
|
|
|
160
857
|
throw error;
|
|
161
858
|
}
|
|
162
859
|
}
|
|
860
|
+
// A dangling symlink, or one pointing at a directory, is captured by
|
|
861
|
+
// its link text, so the run continues; one plain notice line names what
|
|
862
|
+
// does not resolve and whether an action is needed. In --json mode
|
|
863
|
+
// stdout stays a single JSON document, so the notice goes to stderr
|
|
864
|
+
// there.
|
|
865
|
+
for (const notice of symlinkNotices(preFiles ?? [])) {
|
|
866
|
+
writeLine(asJson ? io.stderr : io.stdout, notice);
|
|
867
|
+
}
|
|
163
868
|
const pipeline = await runPipeline({
|
|
164
869
|
cwd: io.cwd,
|
|
165
870
|
env: io.env,
|
|
@@ -172,7 +877,7 @@ export async function nextCommand(io, argv) {
|
|
|
172
877
|
let changedInputs = false;
|
|
173
878
|
if (!snapshotUnavailable) {
|
|
174
879
|
try {
|
|
175
|
-
const postFiles = collectInputFiles(io.cwd, config, stateDir);
|
|
880
|
+
const postFiles = collectInputFiles(io.cwd, config, stateDir, [], [], cacheExclusions);
|
|
176
881
|
if (preFiles !== null && diffInputFiles(preFiles, postFiles).length > 0) {
|
|
177
882
|
changedInputs = true;
|
|
178
883
|
}
|
|
@@ -188,6 +893,7 @@ export async function nextCommand(io, argv) {
|
|
|
188
893
|
id: plugin.id,
|
|
189
894
|
version: plugin.version,
|
|
190
895
|
})),
|
|
896
|
+
cacheExclusions,
|
|
191
897
|
}).inputDigest;
|
|
192
898
|
}
|
|
193
899
|
}
|
|
@@ -211,14 +917,19 @@ export async function nextCommand(io, argv) {
|
|
|
211
917
|
let discoveryResult;
|
|
212
918
|
if (diffScoped) {
|
|
213
919
|
const sidecar = loadOptionalTestMap(io.cwd);
|
|
214
|
-
const runnerConfig =
|
|
920
|
+
const runnerConfig = findRunnerConfigPath(io.cwd, config.runner);
|
|
215
921
|
let testFiles = [];
|
|
216
922
|
if (runnerConfig !== null) {
|
|
217
923
|
try {
|
|
218
|
-
const discovered = await discoverTestCatalog({
|
|
924
|
+
const discovered = await discoverTestCatalog({
|
|
925
|
+
cwd: io.cwd,
|
|
926
|
+
config,
|
|
927
|
+
collectPytest: true,
|
|
928
|
+
excludeFile: engineGeneratedStateFileFilter(io.cwd, stateDir),
|
|
929
|
+
});
|
|
219
930
|
discoveryResult = discovered;
|
|
220
931
|
testFiles = discovered.catalog.entries
|
|
221
|
-
.filter((entry) => entry.runner ===
|
|
932
|
+
.filter((entry) => entry.runner === config.runner)
|
|
222
933
|
.map((entry) => entry.file);
|
|
223
934
|
}
|
|
224
935
|
catch (error) {
|
|
@@ -238,6 +949,11 @@ export async function nextCommand(io, argv) {
|
|
|
238
949
|
mappingSidecar: sidecar !== null,
|
|
239
950
|
knownSourceFiles,
|
|
240
951
|
strictE2E: config.enforcement?.strictE2E === true,
|
|
952
|
+
// Gateforge's OWN scaffold/policy files are policy inputs (D2),
|
|
953
|
+
// not product changes: without this `next --changed` would keep
|
|
954
|
+
// listing `.gateforge/*.yml`, `GATEFORGE.md` and the CI/pre-commit
|
|
955
|
+
// wiring as CHANGE_UNMAPPED — the exact thing D2 removes.
|
|
956
|
+
policyInputs: [...gateforgeOwnedInputs(io.cwd, pipeline.changedFiles, config).keys()],
|
|
241
957
|
});
|
|
242
958
|
changedFiles = scopeDecision.mode === 'all' ? null : scopeDecision.changedFiles;
|
|
243
959
|
const sidecarCoveredFiles = new Set((sidecar?.tests ?? []).map((entry) => entry.selector.file));
|
|
@@ -278,14 +994,23 @@ export async function nextCommand(io, argv) {
|
|
|
278
994
|
const mapped = await resolveRepositoryMappings({
|
|
279
995
|
cwd: io.cwd,
|
|
280
996
|
config,
|
|
997
|
+
stateDir,
|
|
281
998
|
obligations: pipeline.policy.obligations,
|
|
282
999
|
...(discoveryResult !== undefined
|
|
283
|
-
? {
|
|
1000
|
+
? {
|
|
1001
|
+
catalog: discoveryResult.catalog,
|
|
1002
|
+
nativeClaims: discoveryResult.nativeClaims,
|
|
1003
|
+
nativeErrors: discoveryResult.nativeErrors,
|
|
1004
|
+
nativeInstances: discoveryResult.nativeInstances,
|
|
1005
|
+
}
|
|
284
1006
|
: {}),
|
|
285
1007
|
behaviorCatalog: pipeline.behaviorCatalog,
|
|
286
1008
|
});
|
|
287
1009
|
const claimInventory = mapped.claimInventory;
|
|
288
|
-
const mappingBlockers =
|
|
1010
|
+
const mappingBlockers = [
|
|
1011
|
+
...mappingBlocking(mapped.resolution.problems),
|
|
1012
|
+
...nativeInventoryBlocking(mapped.nativeLoadProblem),
|
|
1013
|
+
];
|
|
289
1014
|
const mappedCoverage = mappedCoverageFrom(mapped.resolution, pipeline.policy.obligations, pipeline.graph);
|
|
290
1015
|
const evaluated = evaluateRun({
|
|
291
1016
|
cwd: io.cwd,
|
|
@@ -296,6 +1021,7 @@ export async function nextCommand(io, argv) {
|
|
|
296
1021
|
blocking: [...pipeline.policy.blocking, ...mismatchBlocking, ...mappingBlockers],
|
|
297
1022
|
stateDir,
|
|
298
1023
|
now: pipeline.now,
|
|
1024
|
+
engineAlembicRecords: pipeline.engineAlembicRecords,
|
|
299
1025
|
changedFiles,
|
|
300
1026
|
claimInventory,
|
|
301
1027
|
mappedCoverage,
|
|
@@ -308,7 +1034,17 @@ export async function nextCommand(io, argv) {
|
|
|
308
1034
|
changedInputs,
|
|
309
1035
|
},
|
|
310
1036
|
});
|
|
311
|
-
const candidates = rankBlockers(evaluated.blocking, evaluated.verdicts);
|
|
1037
|
+
const candidates = rankBlockers(evaluated.blocking, evaluated.verdicts, focusedRouteKeys(pipeline.graph));
|
|
1038
|
+
// Unmatched by-id routes the owner graded as advisory (0.9.0, owner
|
|
1039
|
+
// decision D7): printed near the top whether or not anything blocks,
|
|
1040
|
+
// because `next` is where an owner looks to learn what a run is
|
|
1041
|
+
// reporting. They never block here (they are out of the blocking
|
|
1042
|
+
// channel), so a clean run still prints `next: none — clean` below.
|
|
1043
|
+
if (!asJson) {
|
|
1044
|
+
for (const line of unmatchedRouteBannerLines(pipeline.unmatchedRouteAdvisories, pipeline.unmatchedRoutesMode)) {
|
|
1045
|
+
writeLine(io.stdout, line);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
312
1048
|
if (candidates.length === 0) {
|
|
313
1049
|
if (asJson) {
|
|
314
1050
|
writeLine(io.stdout, JSON.stringify({ next: null, cause: null, why: 'clean', do: null, remainingBlocking: 0 }));
|
|
@@ -319,6 +1055,56 @@ export async function nextCommand(io, argv) {
|
|
|
319
1055
|
return 0;
|
|
320
1056
|
}
|
|
321
1057
|
const first = candidates[0];
|
|
1058
|
+
const unresolvedRoute = pipeline.classification.decisions.find((decision) => decision.name === first.id &&
|
|
1059
|
+
decision.kind === 'http.endpoint' &&
|
|
1060
|
+
decision.classification === null &&
|
|
1061
|
+
decision.blocks.some((block) => block.code === 'PLANE_UNRESOLVED'));
|
|
1062
|
+
const routeResource = unresolvedRoute === undefined
|
|
1063
|
+
? undefined
|
|
1064
|
+
: pipeline.graph.resources.find((resource) => resource.name === unresolvedRoute.name);
|
|
1065
|
+
const method = routeResource?.attributes['method'];
|
|
1066
|
+
const path = routeResource?.attributes['canonicalPath'];
|
|
1067
|
+
const routeName = typeof method === 'string' && typeof path === 'string'
|
|
1068
|
+
? `${method} ${path}`
|
|
1069
|
+
: unresolvedRoute?.name;
|
|
1070
|
+
const routeGuidance = unresolvedRoute === undefined || routeName === undefined
|
|
1071
|
+
? null
|
|
1072
|
+
: unresolvedRouteGuidance(routeName, unresolvedRoute.name, unresolvedRoute.source, io.cwd);
|
|
1073
|
+
// An endpoint whose semantics no detector could prove is answered by
|
|
1074
|
+
// the owner-authored capability rule, so the top item carries the exact
|
|
1075
|
+
// entry instead of the read-only dump the fallback `do:` names. A
|
|
1076
|
+
// FastAPI prefix no detector could read is answered the same way: the
|
|
1077
|
+
// block names the one edit that closes it, never a read-only command.
|
|
1078
|
+
const endpointGuidance = routeGuidance === null ? endpointSemanticsGuidance(first.why, pipeline.graph) : [];
|
|
1079
|
+
const prefixGuidance = routeGuidance === null ? fastapiPrefixGuidance(first.why, io.cwd) : [];
|
|
1080
|
+
const classifierBlocks = classifierBlockGuidance(first, pipeline.classification.decisions);
|
|
1081
|
+
const guide = ENVIRONMENT_GUIDES[first.cause] ?? null;
|
|
1082
|
+
const scopeNote = observationScopeNote(first, pipeline.graph, pipeline.observationScope, config.policies);
|
|
1083
|
+
// The behavior setup is printed whenever the run still owes a behavior
|
|
1084
|
+
// DECLARATION and the top item is one of the three "this repository has
|
|
1085
|
+
// no proof yet" causes. A brand-new repository is usually missing all
|
|
1086
|
+
// three at once (no cases, no tests, no mapping), and answering only
|
|
1087
|
+
// the top one would send the owner back for a second `next` run with
|
|
1088
|
+
// the same answer.
|
|
1089
|
+
const behaviorGap = evaluated.blocking.find((entry) => entry.cause === 'ENDPOINT_BEHAVIOR_MISSING');
|
|
1090
|
+
const behaviorGuidance = behaviorGap !== undefined && SETUP_CAUSES.includes(first.cause)
|
|
1091
|
+
? behaviorDeclarationGuidance({
|
|
1092
|
+
cwd: io.cwd,
|
|
1093
|
+
policiesPath: config.policies,
|
|
1094
|
+
graph: pipeline.graph,
|
|
1095
|
+
resourceId: behaviorGap.resourceId ?? behaviorGap.name ?? '',
|
|
1096
|
+
runner: config.runner,
|
|
1097
|
+
})
|
|
1098
|
+
: [];
|
|
1099
|
+
// The per-tenant singleton guidance (plan 2026-09-25 Phase 4b item 3)
|
|
1100
|
+
// rides the same advisory tail the other owner notes use, and is the
|
|
1101
|
+
// SAME {@link singletonPerTenantGuidanceLines} output `check` renders
|
|
1102
|
+
// as a finding — a graph with no tagged resource yields an empty list
|
|
1103
|
+
// and prints nothing at all, so the next action stays byte-identical.
|
|
1104
|
+
const singletonNote = singletonPerTenantGuidanceLines(pipeline.graph.resources);
|
|
1105
|
+
// The task pack is offered only when the engine could actually grade
|
|
1106
|
+
// it — a configured queueObserver plus a discovered task resource.
|
|
1107
|
+
const taskOffer = taskPackOffer(pipeline.graph, config.queueObserver !== undefined);
|
|
322
1108
|
if (asJson) {
|
|
323
1109
|
writeLine(io.stdout, JSON.stringify({
|
|
324
1110
|
next: first.id,
|
|
@@ -326,13 +1112,54 @@ export async function nextCommand(io, argv) {
|
|
|
326
1112
|
why: first.why,
|
|
327
1113
|
do: first.do,
|
|
328
1114
|
remainingBlocking: candidates.length - 1,
|
|
1115
|
+
guide,
|
|
1116
|
+
...(routeGuidance === null ? {} : { guidance: routeGuidance }),
|
|
1117
|
+
...(behaviorGuidance.length === 0 ? {} : { behaviorGuidance }),
|
|
1118
|
+
...(scopeNote.length === 0 ? {} : { scopeNote }),
|
|
1119
|
+
...(singletonNote.length === 0 ? {} : { singletonGuidance: singletonNote }),
|
|
1120
|
+
...(taskOffer.length === 0 ? {} : { taskPackOffer: taskOffer }),
|
|
1121
|
+
...(endpointGuidance.length === 0 ? {} : { endpointSemanticsGuidance: endpointGuidance }),
|
|
1122
|
+
...(prefixGuidance.length === 0 ? {} : { fastapiPrefixGuidance: prefixGuidance }),
|
|
1123
|
+
...(classifierBlocks === null ? {} : { classifierBlockGuidance: classifierBlocks.lines }),
|
|
329
1124
|
}));
|
|
330
1125
|
}
|
|
331
1126
|
else {
|
|
332
1127
|
writeLine(io.stdout, `next: ${first.id}`);
|
|
333
1128
|
writeLine(io.stdout, `cause: ${first.cause}`);
|
|
334
1129
|
writeLine(io.stdout, `why: ${first.why}`);
|
|
335
|
-
|
|
1130
|
+
if (guide !== null)
|
|
1131
|
+
writeLine(io.stdout, `guide: ${guide}`);
|
|
1132
|
+
if (routeGuidance !== null) {
|
|
1133
|
+
writeLine(io.stdout, 'do: confirm the route owner and run only the matching plane command below');
|
|
1134
|
+
for (const line of routeGuidance)
|
|
1135
|
+
writeLine(io.stdout, line);
|
|
1136
|
+
}
|
|
1137
|
+
else if (endpointGuidance.length > 0) {
|
|
1138
|
+
writeLine(io.stdout, `do: declare what this endpoint does in '${ENDPOINTS_CONFIG_PATH}' — the exact entry to add is below`);
|
|
1139
|
+
for (const line of endpointGuidance)
|
|
1140
|
+
writeLine(io.stdout, line);
|
|
1141
|
+
}
|
|
1142
|
+
else if (prefixGuidance.length > 0) {
|
|
1143
|
+
writeLine(io.stdout, `do: ${fastapiPrefixDo(first.why)}`);
|
|
1144
|
+
for (const line of prefixGuidance)
|
|
1145
|
+
writeLine(io.stdout, line);
|
|
1146
|
+
}
|
|
1147
|
+
else if (classifierBlocks !== null) {
|
|
1148
|
+
writeLine(io.stdout, `do: ${classifierBlocks.do}`);
|
|
1149
|
+
for (const line of classifierBlocks.lines)
|
|
1150
|
+
writeLine(io.stdout, line);
|
|
1151
|
+
}
|
|
1152
|
+
else {
|
|
1153
|
+
writeLine(io.stdout, `do: ${first.do}`);
|
|
1154
|
+
}
|
|
1155
|
+
for (const line of behaviorGuidance)
|
|
1156
|
+
writeLine(io.stdout, line);
|
|
1157
|
+
for (const line of scopeNote)
|
|
1158
|
+
writeLine(io.stdout, line);
|
|
1159
|
+
for (const line of singletonNote)
|
|
1160
|
+
writeLine(io.stdout, line);
|
|
1161
|
+
for (const line of taskOffer)
|
|
1162
|
+
writeLine(io.stdout, line);
|
|
336
1163
|
}
|
|
337
1164
|
return 1;
|
|
338
1165
|
}
|