@ultimat3/cli 31.47.1 → 31.49.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/CLAUDE.md +30 -23
- package/README.md +96 -4
- package/package.json +29 -29
- package/src/api-registration.ts +28 -14
- package/src/app-load.ts +6 -1
- package/src/app-root.ts +7 -1
- package/src/clean-services.ts +142 -0
- package/src/cmd-auth.ts +3 -0
- package/src/cmd-clean-spec.ts +10 -3
- package/src/cmd-clean.ts +23 -9
- package/src/cmd-db-backfill.ts +6 -0
- package/src/cmd-db-branch.ts +10 -4
- package/src/cmd-db-recount.ts +5 -12
- package/src/cmd-db-rollback.ts +77 -0
- package/src/cmd-db-spec.ts +18 -2
- package/src/cmd-db-status.ts +5 -10
- package/src/cmd-db.ts +105 -33
- package/src/cmd-deploy-verify.ts +14 -6
- package/src/cmd-docs-topic.ts +94 -0
- package/src/cmd-docs.ts +15 -1
- package/src/cmd-doctor.ts +109 -41
- package/src/cmd-drill.ts +100 -19
- package/src/cmd-env.ts +30 -8
- package/src/cmd-errors-app.ts +63 -0
- package/src/cmd-errors.ts +50 -14
- package/src/cmd-generate.ts +17 -4
- package/src/cmd-heavy-spec.ts +36 -0
- package/src/cmd-heavy.ts +244 -0
- package/src/cmd-jobs.ts +27 -1
- package/src/cmd-merge-driver-spec.ts +12 -0
- package/src/cmd-merge-driver.ts +95 -0
- package/src/cmd-new.ts +23 -3
- package/src/cmd-policy-spec.ts +9 -1
- package/src/cmd-policy.ts +72 -17
- package/src/cmd-stop.ts +18 -4
- package/src/cmd-tasks-run.ts +87 -0
- package/src/cmd-tasks-spec.ts +10 -3
- package/src/cmd-tasks.ts +8 -5
- package/src/cmd-test.ts +15 -4
- package/src/cmd-upgrade-spec.ts +8 -1
- package/src/cmd-upgrade.ts +32 -5
- package/src/cmd-verify.ts +9 -41
- package/src/codemods/agents-doc-row.ts +73 -0
- package/src/codemods/define-error-leaf.ts +37 -12
- package/src/codemods/docs-many-agents.ts +26 -0
- package/src/codemods/docs-worker-commands.ts +26 -0
- package/src/codemods/index.ts +6 -0
- package/src/codemods/merge-drivers.ts +66 -0
- package/src/command.ts +3 -0
- package/src/db-applied-edits.ts +117 -0
- package/src/db-dev-wire.ts +18 -0
- package/src/db-diagnostics.ts +5 -10
- package/src/db-generate.ts +82 -7
- package/src/db-migrate-pass.ts +51 -0
- package/src/db-migrate-through-dev.ts +209 -0
- package/src/db-rollback-consent.ts +128 -0
- package/src/db-rollback-pass.ts +76 -0
- package/src/db-seed-generate.ts +5 -1
- package/src/db-seed.ts +7 -1
- package/src/deploy-verify-findings.ts +3 -0
- package/src/deploy-verify-grade.ts +3 -0
- package/src/deploy-verify-processes.ts +32 -0
- package/src/dev-boot.ts +3 -0
- package/src/dev-db-migrate.ts +155 -0
- package/src/dev-db-rollback.ts +33 -0
- package/src/dev-db-settled.ts +22 -0
- package/src/dev-lock-errors.ts +78 -0
- package/src/dev-lock-holder-dir.ts +64 -0
- package/src/dev-lock-live.ts +44 -0
- package/src/dev-lock.ts +59 -84
- package/src/dev-policy.ts +11 -8
- package/src/dev-rebuild-schema.ts +116 -13
- package/src/dev-rebuild.ts +13 -4
- package/src/dev-route-table.ts +7 -0
- package/src/dispatch.ts +21 -1
- package/src/doctor-advisory-floors.ts +30 -8
- package/src/doctor-api-listing.ts +114 -0
- package/src/doctor-guarded.ts +41 -0
- package/src/doctor-port.ts +90 -17
- package/src/doctor-probe.ts +36 -5
- package/src/doctor-processes-probe.ts +127 -0
- package/src/doctor-processes.ts +136 -0
- package/src/doctor-warnings.ts +17 -0
- package/src/error-codes-agents.ts +35 -0
- package/src/error-codes-processes.ts +30 -0
- package/src/error-codes-tooling.ts +11 -3
- package/src/error-codes.ts +12 -13
- package/src/errors-suite.ts +27 -0
- package/src/errors.ts +18 -22
- package/src/exec.ts +11 -3
- package/src/exercise-registration.ts +4 -3
- package/src/framework-env.ts +7 -3
- package/src/generate-files.ts +1 -0
- package/src/generate-grant-findings.ts +7 -5
- package/src/generate-grants.ts +9 -8
- package/src/generate-kinds.ts +30 -6
- package/src/generate-roles-file.ts +30 -0
- package/src/generate-slice-policy.ts +3 -3
- package/src/guards.ts +2 -2
- package/src/heavy-cores.ts +51 -0
- package/src/heavy-env.ts +21 -0
- package/src/heavy-errors.ts +54 -0
- package/src/heavy-flock.ts +73 -0
- package/src/heavy-holders.ts +78 -0
- package/src/heavy-ledger.ts +400 -0
- package/src/heavy-memory.ts +67 -0
- package/src/heavy-pressure.ts +104 -0
- package/src/heavy-weights.ts +47 -0
- package/src/heavy.ts +308 -0
- package/src/i18n-registration.ts +22 -2
- package/src/island-harness.ts +2 -2
- package/src/job-budget.ts +4 -2
- package/src/job-registration.ts +64 -8
- package/src/jobs-queue-known.ts +43 -0
- package/src/local-cli.ts +6 -5
- package/src/mcp-errors-agents.ts +20 -0
- package/src/mcp-errors-doctor.ts +27 -0
- package/src/mcp-errors-processes.ts +23 -0
- package/src/mcp-errors.ts +18 -29
- package/src/mcp-host.ts +2 -2
- package/src/merge-driver-catalog.ts +58 -0
- package/src/merge-driver-config.ts +43 -0
- package/src/merge-driver-lines.ts +140 -0
- package/src/merge-state.ts +105 -0
- package/src/messages-db.ts +22 -1
- package/src/messages-processes.ts +13 -0
- package/src/messages-upgrade.ts +6 -0
- package/src/messages.ts +62 -1
- package/src/output-findings.ts +48 -21
- package/src/parse.ts +37 -6
- package/src/policy-facts.ts +38 -21
- package/src/policy-row.ts +99 -0
- package/src/port-pair-free.ts +28 -0
- package/src/registry-lines.ts +110 -0
- package/src/registry.ts +4 -0
- package/src/retain-sweep.ts +1 -1
- package/src/role-replicator.ts +9 -4
- package/src/role-select.ts +86 -0
- package/src/role-start.ts +13 -55
- package/src/role-sync.ts +10 -5
- package/src/runtime-cache-frame.ts +46 -0
- package/src/runtime-cache-ttl.ts +23 -0
- package/src/runtime-cache.ts +56 -18
- package/src/runtime-database-ssl.ts +84 -0
- package/src/runtime-idempotency-scope.ts +16 -2
- package/src/runtime-jobs-share.ts +52 -0
- package/src/runtime-jobs.ts +43 -12
- package/src/runtime-overrides.ts +4 -2
- package/src/runtime-queue.ts +18 -3
- package/src/runtime-services.ts +8 -1
- package/src/schema-drift.ts +19 -2
- package/src/schema-dump-drift.ts +4 -1
- package/src/serve-boot-probe.ts +30 -2
- package/src/serve-boot.ts +11 -1
- package/src/serve-env.ts +39 -3
- package/src/serve.ts +61 -10
- package/src/stop-run-start.ts +12 -0
- package/src/supervise-boot.ts +61 -0
- package/src/supervise-cgroup.ts +84 -0
- package/src/supervise-child.ts +206 -0
- package/src/supervise-count.ts +244 -0
- package/src/supervise-errors.ts +83 -0
- package/src/supervise-facts.ts +40 -0
- package/src/supervise-messages.ts +84 -0
- package/src/supervise-policy.ts +46 -0
- package/src/supervise-pool.ts +10 -0
- package/src/supervise-probe.ts +158 -0
- package/src/supervise-run.ts +54 -0
- package/src/supervise.ts +383 -0
- package/src/templates/generate-purge.ts +6 -6
- package/src/templates/guard-animated-layout-property.ts +2 -2
- package/src/templates/guard-bare-error.ts +1 -1
- package/src/templates/guard-error-declared.ts +2 -2
- package/src/templates/guard-focus-visible.ts +1 -1
- package/src/templates/guard-image-dimensions.ts +2 -2
- package/src/templates/guard-island-mount-clears.ts +1 -1
- package/src/templates/guard-native-confirm.ts +1 -1
- package/src/templates/guard-raw-breakpoint.ts +2 -2
- package/src/templates/guard-raw-colour.ts +2 -2
- package/src/templates/guard-raw-fetch.ts +1 -1
- package/src/templates/guard-raw-interval.ts +1 -1
- package/src/templates/guard-raw-length.ts +3 -3
- package/src/templates/guard-raw-motion.ts +1 -1
- package/src/templates/guard-raw-shadow.ts +1 -1
- package/src/templates/guard-raw-z-index.ts +1 -1
- package/src/templates/guard-released-forms.ts +59 -13
- package/src/templates/guard-repo-await-in-loop.ts +1 -1
- package/src/templates/guard-repo-raw-sql.ts +4 -4
- package/src/templates/guard-repo-unbounded.ts +1 -1
- package/src/templates/guard-runtime-pin.ts +1 -1
- package/src/templates/guard-semantic-interactive.ts +2 -2
- package/src/templates/guard-unbounded-fanout.ts +1 -1
- package/src/templates/guard-undeclared-custom-property.ts +3 -3
- package/src/templates/guard-undefined-style-class.ts +3 -3
- package/src/templates/guard-unzoned-date.ts +3 -3
- package/src/templates/query-slice.ts +82 -0
- package/src/templates/query.ts +76 -30
- package/src/templates/resource-page.ts +3 -2
- package/src/templates/scaffold-bin.ts +2 -0
- package/src/templates/scaffold-claude-agents.ts +9 -6
- package/src/templates/scaffold-claude-commands.ts +7 -1
- package/src/templates/scaffold-claude.ts +4 -4
- package/src/templates/scaffold-container-compose.ts +47 -7
- package/src/templates/scaffold-docs.ts +11 -6
- package/src/templates/scaffold-gitattributes.ts +18 -1
- package/src/templates/scaffold-helm-templates.ts +9 -0
- package/src/templates/scaffold-repo.ts +4 -1
- package/src/templates/scaffold-test-services.ts +33 -11
- package/src/templates/shapes/offline.ts +0 -7
- package/src/templates/shapes/realtime.ts +2 -6
- package/src/templates/sign-in-action-tests.ts +6 -4
- package/src/templates/sign-in-challenge.ts +62 -0
- package/src/templates/sign-in-oidc-mfa.ts +31 -0
- package/src/templates/sign-in-oidc.ts +11 -3
- package/src/templates/sign-in-password.ts +18 -56
- package/src/test-batches.ts +9 -3
- package/src/test-shards.ts +117 -37
- package/src/test-slots.ts +35 -161
- package/src/test-verdict.ts +79 -0
- package/src/test-workers.ts +15 -0
- package/src/upgrade-gate-codemods.ts +5 -3
- package/src/upgrade-gate.ts +19 -1
- package/src/upgrade-merge-drivers.ts +25 -0
- package/src/upgrade-report.ts +18 -4
- package/src/upgrade-scope.ts +62 -0
- package/src/verify-checks.ts +6 -11
- package/src/verify-coverage-run.ts +9 -5
- package/src/verify-deadline.ts +18 -2
- package/src/verify-heavy-steps.ts +26 -0
- package/src/verify-live.ts +38 -14
- package/src/verify-only.ts +67 -0
- package/src/verify-progress.ts +7 -3
- package/src/verify-run.ts +20 -2
- package/src/verify-services-stack.ts +165 -0
- package/src/verify-services.ts +84 -2
- package/src/verify-test-run.ts +9 -9
- package/src/verify-tests.ts +35 -22
- package/src/verify-typecheck.ts +25 -2
- package/wiki/Actions.md +2 -1
- package/wiki/Admin-Dashboard.md +2 -2
- package/wiki/Agents.md +5 -5
- package/wiki/Auth.md +15 -5
- package/wiki/Bare-VM.md +1 -1
- package/wiki/Building-Your-Own-Base.md +15 -2
- package/wiki/CI-Parallel-Gate.md +4 -4
- package/wiki/CLI-Reference.md +127 -48
- package/wiki/Caching-And-Invalidation.md +2 -2
- package/wiki/Client-Navigation.md +1 -1
- package/wiki/Configuration.md +32 -13
- package/wiki/Deployment.md +44 -4
- package/wiki/Entities-And-Migrations.md +5 -1
- package/wiki/FAQ.md +1 -1
- package/wiki/Getting-Started.md +2 -2
- package/wiki/Home.md +2 -1
- package/wiki/I18n.md +5 -3
- package/wiki/Installation.md +12 -11
- package/wiki/Interface-Rules.md +1 -1
- package/wiki/Jobs-And-Workflows.md +24 -4
- package/wiki/Known-Gaps.md +2 -2
- package/wiki/MCP-And-AI.md +8 -5
- package/wiki/Mail.md +1 -1
- package/wiki/Many-Agents.md +127 -0
- package/wiki/Migrations-And-Backfills.md +18 -0
- package/wiki/Notify.md +1 -1
- package/wiki/Observability.md +13 -0
- package/wiki/Queries-And-Live-Queries.md +2 -2
- package/wiki/Realtime.md +10 -1
- package/wiki/Routes-And-Render-Modes.md +1 -1
- package/wiki/Scheduled-Tasks.md +4 -1
- package/wiki/Testing.md +12 -9
- package/wiki/Timezones-And-Dates.md +5 -1
- package/wiki/Troubleshooting.md +1 -0
- package/wiki/Tutorial-01-First-App.md +5 -5
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
- package/wiki/Upgrading.md +37 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// `x jobs pause|resume <queue>` names a queue this app serves. A typo paused nothing and reported
|
|
2
|
+
// success, and the runbook's next step (poll the queue until it is empty) then passed at once
|
|
3
|
+
// while the real queue kept claiming. The set is `x deploy verify`'s: config plus registered jobs.
|
|
4
|
+
|
|
5
|
+
import { nearestName, renderCauseValue, UltimateError } from '@ultimat3/core';
|
|
6
|
+
import { expectedQueues } from './deploy-verify-queues';
|
|
7
|
+
import { quoteArg } from './shell-quote';
|
|
8
|
+
|
|
9
|
+
/** The queue positional names nothing this app's workers claim from. */
|
|
10
|
+
export class JobsQueueUnknownError extends UltimateError {
|
|
11
|
+
constructor(input: { sub: 'pause' | 'resume'; queue: string; known: readonly string[] }) {
|
|
12
|
+
const nearest = nearestName(input.queue, input.known);
|
|
13
|
+
super({
|
|
14
|
+
code: 'X_CLI_BAD_FLAG',
|
|
15
|
+
cause: `"x jobs ${input.sub}" was given queue ${renderCauseValue(input.queue)}, which is not a queue of this app (${input.known.map((queue) => renderCauseValue(queue)).join(', ')}) — no worker claims from it, so the ${input.sub} would change nothing`,
|
|
16
|
+
fix:
|
|
17
|
+
nearest === undefined
|
|
18
|
+
? 'x jobs list --json # data.depth.queues names what each queue holds'
|
|
19
|
+
: ['x', 'jobs', input.sub, quoteArg(nearest), '--json'].join(' '),
|
|
20
|
+
meta: { queue: input.queue, known: [...input.known] },
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Refuses before the pause row is written. An app that will not load is "cannot tell" — its jobs'
|
|
27
|
+
* queues are the half of the set a broken module hides — and is never refused on a guess. `resume`
|
|
28
|
+
* of a queue that IS paused always passes: that row is what the command exists to clear.
|
|
29
|
+
*/
|
|
30
|
+
export async function assertQueueServed(
|
|
31
|
+
root: string,
|
|
32
|
+
sub: 'pause' | 'resume',
|
|
33
|
+
queue: string,
|
|
34
|
+
paused: readonly string[],
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
if (sub === 'resume' && paused.includes(queue)) return;
|
|
37
|
+
const expected = await expectedQueues(root);
|
|
38
|
+
// An app with no module at all hides nothing: its set is the configured queues, whole.
|
|
39
|
+
if (expected.findings.some((finding) => finding.code !== 'X_APP_EMPTY')) return;
|
|
40
|
+
// Nothing configured and nothing registered is the worker's own `default`.
|
|
41
|
+
const known = expected.queues.length === 0 ? ['default'] : expected.queues;
|
|
42
|
+
if (!known.includes(queue)) throw new JobsQueueUnknownError({ sub, queue, known });
|
|
43
|
+
}
|
package/src/local-cli.ts
CHANGED
|
@@ -45,12 +45,13 @@ const nodeIo: LocalCliIo = {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* The
|
|
48
|
+
* The commands the app's own CLI must not answer when it is the older of the two. An app with no
|
|
49
49
|
* `x upgrade` yet is told `bunx @ultimat3/cli@latest upgrade`, and handing that to the app's CLI
|
|
50
|
-
* answers `X_NOT_IMPLEMENTED` from the very version it exists to move off
|
|
51
|
-
*
|
|
50
|
+
* answers `X_NOT_IMPLEMENTED` from the very version it exists to move off; `x heavy` is run from any
|
|
51
|
+
* directory on the machine, an app pinned before it included. Safe because of what they do not do:
|
|
52
|
+
* neither loads an app, so there is no second registry.
|
|
52
53
|
*/
|
|
53
|
-
const OUTLIVES_THE_APP_CLI = 'upgrade';
|
|
54
|
+
const OUTLIVES_THE_APP_CLI: readonly (string | undefined)[] = ['upgrade', 'heavy'];
|
|
54
55
|
|
|
55
56
|
const versionOfBin = (bin: string, io: LocalCliIo): string | undefined => {
|
|
56
57
|
const parsed: unknown = JSON.parse(io.read(join(dirname(dirname(bin)), 'package.json')));
|
|
@@ -93,7 +94,7 @@ export function resolveLocalCli(
|
|
|
93
94
|
if (!io.exists(local)) return undefined;
|
|
94
95
|
try {
|
|
95
96
|
if (io.realpath(local) === io.realpath(input.selfPath)) return undefined;
|
|
96
|
-
if (input.command
|
|
97
|
+
if (OUTLIVES_THE_APP_CLI.includes(input.command) && appCliIsOlder(local, input.selfPath, io)) {
|
|
97
98
|
return undefined;
|
|
98
99
|
}
|
|
99
100
|
return local;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// `errors.explain`'s rows for the codes of agents sharing a machine and a repository (`error-codes-
|
|
2
|
+
// agents.ts`), split out of `mcp-errors.ts` under the 500-line ceiling. Spread into `CLI_FIXES`
|
|
3
|
+
// there, whose `Record<CliErrorCode, string>` is still what makes a code without a row a build error.
|
|
4
|
+
|
|
5
|
+
import type { CliErrorCode } from './error-codes';
|
|
6
|
+
|
|
7
|
+
export const AGENTS_FIXES = {
|
|
8
|
+
X_PORT_IN_USE: 'x dev --port 3001 --json',
|
|
9
|
+
X_DEV_ALREADY_RUNNING:
|
|
10
|
+
'x dev --json # after stopping the x dev that already owns this checkout',
|
|
11
|
+
// The path, not `x dev`: the boot has already refused and rerunning it refuses again. The
|
|
12
|
+
// error's own `fix:` carries the resolved `.x/dev.lock`; this table cannot know the state dir.
|
|
13
|
+
X_DEV_LOCK_UNREADABLE: 'rm .x/dev.lock # then: x dev --json',
|
|
14
|
+
X_UPGRADE_LOCKED: 'cat .x/upgrade.lock',
|
|
15
|
+
X_HEAVY_WAIT_EXPIRED: 'x heavy status --json',
|
|
16
|
+
X_MERGE_UNRESOLVED: 'git diff --name-only --diff-filter=U',
|
|
17
|
+
X_MERGE_DRIVER_UNSET: 'bunx x merge-driver install',
|
|
18
|
+
X_CATALOG_UNPARSEABLE: 'bunx biome check packages/i18n/catalogs',
|
|
19
|
+
X_DOCTOR_PROBE_FAILED: 'bunx x manifest --json',
|
|
20
|
+
} as const satisfies Partial<Record<CliErrorCode, string>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// `errors.explain`'s rows for the codes `error-codes-doctor.ts` owns: `x doctor`'s warnings and
|
|
2
|
+
// the upgrade's, split out of `mcp-errors.ts` under the 500-line ceiling. Spread into `CLI_FIXES`
|
|
3
|
+
// there, whose `Record<CliErrorCode, string>` makes a code without a row a build error.
|
|
4
|
+
|
|
5
|
+
import type { CliErrorCode } from './error-codes';
|
|
6
|
+
|
|
7
|
+
export const DOCTOR_FIXES = {
|
|
8
|
+
X_EXERCISE_UNPROVEN_ABOVE_FLOOR:
|
|
9
|
+
'x exercise --json # re-measures at the constant seed the gate runs (a floor from before 31.47.0 was measured under random seeds); each unproven record in .x/exercise.json names the proof and its reason: fix the seed helper or override it names, assuming no order between sized calls; the floor only falls',
|
|
10
|
+
X_ENV_NAME_RESERVED:
|
|
11
|
+
'edit app.config.ts: add an APP_ prefix to the envSchema name the finding cites (or delete it where the value is meant for the framework); then: x env example --json && x doctor --json',
|
|
12
|
+
X_FRAMEWORK_PIN_RANGE:
|
|
13
|
+
'x doctor --json # each X_FRAMEWORK_PIN_RANGE names a package.json line and the exact version: write it there, then: bun install',
|
|
14
|
+
X_VERIFY_STEP_UNFLOORED:
|
|
15
|
+
'x doctor --json # its X_VERIFY_STEP_UNFLOORED fix names the steps: run that x verify --only, then add each step that passed, not skipped, to "steps" in x.verify.json',
|
|
16
|
+
X_DB_ROW_SECURITY_OFF:
|
|
17
|
+
'database: { rowSecurity: true } # in defineConfig, app.config.ts; then: x db gen "row security" --json && x db migrate --json && x doctor --json',
|
|
18
|
+
X_DB_INDEX_UNDECLARED:
|
|
19
|
+
'x verify --only drift --json # each X_DB_INDEX_UNDECLARED warning names the index: its DROP INDEX CONCURRENTLY IF EXISTS "<name>"; goes in a new hand-written migration (-- transaction: false), or declare it in the entity\'s indexes: [...] and x db gen "<change>"',
|
|
20
|
+
X_SHIPPED_GUARD_MISSING:
|
|
21
|
+
"x doctor --json # each X_SHIPPED_GUARD_MISSING warning's fix is the command that writes its guard, then x verify --only boundaries --json",
|
|
22
|
+
X_SUPERSEDED_WORKAROUND:
|
|
23
|
+
'x doctor --json # each finding names the file, the release that retired the workaround and its replacement',
|
|
24
|
+
X_GUARD_VENDORED: 'x upgrade --json',
|
|
25
|
+
X_ADVISORY_FLOOR_UNMET: 'bun update source-map-js immutable',
|
|
26
|
+
X_UPGRADE_CODEMODS_PENDING: 'x upgrade codemods --from 0.0.0 --json',
|
|
27
|
+
} as const satisfies Partial<Record<CliErrorCode, string>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// `errors.explain`'s rows for processes per container (`ULTIMATE_PROCESSES`) — the supervisor's
|
|
2
|
+
// family, split out of `mcp-errors.ts` under the 500-line ceiling. Spread into `CLI_FIXES` there,
|
|
3
|
+
// whose `Record<CliErrorCode, string>` is still what makes a code without a row a build error.
|
|
4
|
+
|
|
5
|
+
import type { CliErrorCode } from './error-codes';
|
|
6
|
+
|
|
7
|
+
export const PROCESSES_FIXES = {
|
|
8
|
+
X_PROCESSES_INVALID:
|
|
9
|
+
'export ULTIMATE_PROCESSES=auto # in the deploy environment of this service, or a positive whole number such as 2',
|
|
10
|
+
X_PROCESSES_ROLE_SINGLETON:
|
|
11
|
+
'export ULTIMATE_PROCESSES=1 # in the environment of the scheduler, replicator and migrate services',
|
|
12
|
+
X_PROCESSES_UNSHARED_STATE:
|
|
13
|
+
"export ULTIMATE_PROCESSES=1 # or share the state: set NATS_URL (REDIS_URL or VALKEY_URL for the cache) and drop the per-process store from the app's runtime.ts; the error lists each",
|
|
14
|
+
X_PROCESSES_OVER_POOL:
|
|
15
|
+
'export ULTIMATE_PROCESSES=1 # or raise DATABASE_POOL_MAX to at least the count; the error names both numbers',
|
|
16
|
+
X_PROCESSES_UNBALANCED: 'export ULTIMATE_PROCESSES=1 # or run the image in a Linux container',
|
|
17
|
+
X_PROCESS_CRASH_LOOP:
|
|
18
|
+
'docker compose logs --tail 200 # the last error line with the crashing child index names the boot error to fix',
|
|
19
|
+
X_PROCESSES_CPU_UNDECLARED:
|
|
20
|
+
"cpus: '2' # on the role's service in docker/docker-compose.prod.yml",
|
|
21
|
+
X_PROCESSES_MIGRATE_REQ_OFF:
|
|
22
|
+
'sysctls: { net.ipv4.tcp_migrate_req: 1 } # uncomment it on web and sync in docker/docker-compose.prod.yml; Linux >= 5.14 only, an older kernel refuses to create the container',
|
|
23
|
+
} as const satisfies Partial<Record<CliErrorCode, string>>;
|
package/src/mcp-errors.ts
CHANGED
|
@@ -7,6 +7,9 @@ import type { ErrorExplanation } from '@ultimat3/mcp';
|
|
|
7
7
|
import type { CliErrorCode } from './error-codes';
|
|
8
8
|
import { CLI_ERROR_CODES } from './error-codes';
|
|
9
9
|
import { codeFixes, codeFixScan } from './error-fixes';
|
|
10
|
+
import { AGENTS_FIXES } from './mcp-errors-agents';
|
|
11
|
+
import { DOCTOR_FIXES } from './mcp-errors-doctor';
|
|
12
|
+
import { PROCESSES_FIXES } from './mcp-errors-processes';
|
|
10
13
|
import { SHOT_FIXES } from './mcp-errors-shot';
|
|
11
14
|
import { VERIFY_FIXES } from './mcp-errors-verify';
|
|
12
15
|
|
|
@@ -61,7 +64,12 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
61
64
|
X_PACKAGE_DUPLICATED:
|
|
62
65
|
'x i18n check --json # the finding names both copies and the package.json to pin',
|
|
63
66
|
// `x shot` and the `ui.*` tools: their own family, in `mcp-errors-shot.ts`.
|
|
67
|
+
...AGENTS_FIXES,
|
|
64
68
|
...SHOT_FIXES,
|
|
69
|
+
// `x doctor`'s warnings and `x upgrade`'s: their own family, in `mcp-errors-doctor.ts`.
|
|
70
|
+
...DOCTOR_FIXES,
|
|
71
|
+
// `ULTIMATE_PROCESSES`: their own family, in `mcp-errors-processes.ts`.
|
|
72
|
+
...PROCESSES_FIXES,
|
|
65
73
|
// The gate's floor, run and split: their own family, in `mcp-errors-verify.ts`.
|
|
66
74
|
...VERIFY_FIXES,
|
|
67
75
|
X_GH_UNAVAILABLE: 'gh auth login # install first from https://cli.github.com',
|
|
@@ -77,8 +85,8 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
77
85
|
'x verify --json # the finding names the file, the line and the name it could not resolve',
|
|
78
86
|
X_ERROR_CODE_UNTHROWN: 'x errors explain X_ERROR_CODE_UNTHROWN --json',
|
|
79
87
|
X_CLI_UNEXPECTED: 'x doctor --json',
|
|
80
|
-
//
|
|
81
|
-
X_TYPECHECK_FAILED: '
|
|
88
|
+
// The step and not raw `tsc`: it queues in the machine ledger and takes the compiler lock.
|
|
89
|
+
X_TYPECHECK_FAILED: 'x verify --only typecheck --json',
|
|
82
90
|
X_LINT_FAILED: 'bunx @biomejs/biome check .',
|
|
83
91
|
X_TEST_FAILED: 'x test --json # the finding carries the exact bun test invocation that failed',
|
|
84
92
|
X_FILE_TOO_LONG: 'x verify --json # the finding names the file to split',
|
|
@@ -137,12 +145,6 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
137
145
|
'x new my-app --json # a name with letters or digits; it becomes the directory',
|
|
138
146
|
X_APP_EMPTY:
|
|
139
147
|
'x doctor --json # then check the app root: no module under apps/ or packages/ loaded',
|
|
140
|
-
X_PORT_IN_USE: 'x dev --port 3001 --json',
|
|
141
|
-
X_DEV_ALREADY_RUNNING:
|
|
142
|
-
'x dev --json # after stopping the x dev that already owns this checkout',
|
|
143
|
-
// The path, not `x dev`: the boot has already refused and rerunning it refuses again. The
|
|
144
|
-
// error's own `fix:` carries the resolved `.x/dev.lock`; this table cannot know the state dir.
|
|
145
|
-
X_DEV_LOCK_UNREADABLE: 'rm .x/dev.lock # then: x dev --json',
|
|
146
148
|
// `x doctor`, not `x db status`: generation failing is a reachability question, and `x db status`
|
|
147
149
|
// reads the migration ledger only. `x doctor` is already this table's answer for
|
|
148
150
|
// X_DB_STUDIO_FAILED.
|
|
@@ -327,7 +329,7 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
327
329
|
X_REPRO_CAPTURE_OFF:
|
|
328
330
|
'x jobs list --json # a job id replays with capture off; for requests set failureCapture: { enabled: true } in app.config.ts',
|
|
329
331
|
X_ENTITY_RETAIN_UNSWEPT:
|
|
330
|
-
"add export const retention = purge({ entities: 'declared' }) to a jobs module named in jobs: [...] in apps/web/api/index.ts, then x
|
|
332
|
+
"add export const retention = purge({ entities: 'declared' }) to a jobs module named in jobs: [...] in apps/web/api/index.ts, then x manifest",
|
|
331
333
|
X_NEW_SHAPE_UNKNOWN: 'bunx @ultimat3/cli help new',
|
|
332
334
|
X_NEW_SHAPE_CONFLICT: 'bunx @ultimat3/cli new myapp --shape blog',
|
|
333
335
|
X_SEO_CARD_ROUTE_UNKNOWN:
|
|
@@ -368,24 +370,10 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
368
370
|
"native: { success: (output) => '/where-it-lands' } in the action's declaration, then x verify --only manifest",
|
|
369
371
|
X_ASSET_RETAIN_UNDECLARED:
|
|
370
372
|
"edit app.config.ts: add assets: { retain: { disk: 'assets', builds: 3 } }, naming a disk your defineStorage({ disks }) declares that every web pod reads",
|
|
371
|
-
X_EXERCISE_UNPROVEN_ABOVE_FLOOR:
|
|
372
|
-
'x exercise --json # re-measures at the constant seed the gate runs (a floor from before 31.47.0 was measured under random seeds); each unproven record in .x/exercise.json names the proof and its reason: fix the seed helper or override it names, assuming no order between sized calls; the floor only falls',
|
|
373
|
-
X_ENV_NAME_RESERVED:
|
|
374
|
-
'edit app.config.ts: add an APP_ prefix to the envSchema name the finding cites (or delete it where the value is meant for the framework); then: x env example --json && x doctor --json',
|
|
375
|
-
X_FRAMEWORK_PIN_RANGE:
|
|
376
|
-
'x doctor --json # each X_FRAMEWORK_PIN_RANGE names a package.json line and the exact version: write it there, then: bun install',
|
|
377
|
-
X_VERIFY_STEP_UNFLOORED:
|
|
378
|
-
'x doctor --json # its X_VERIFY_STEP_UNFLOORED fix names the steps: run that x verify --only, then add each step that passed, not skipped, to "steps" in x.verify.json',
|
|
379
|
-
X_DB_ROW_SECURITY_OFF:
|
|
380
|
-
'database: { rowSecurity: true } # in defineConfig, app.config.ts; then: x db gen "row security" --json && x db migrate --json && x doctor --json',
|
|
381
373
|
X_DEV_DATA_UNOPENABLE:
|
|
382
374
|
'x db migrate --json # the fresh database has no tables yet; then x db seed --json if the app declares a seed. The moved directory (meta.aside) is kept: delete it once its rows are not needed',
|
|
383
375
|
X_EXPLAIN_PRODUCTION_DATABASE:
|
|
384
376
|
'env -u DATABASE_URL x queries list --json # then the same prefix on x explain <query> --json: it plans on the embedded dev database; for a copy of production data, point DATABASE_URL at a staging restore with ULTIMATE_ENV=staging',
|
|
385
|
-
X_DB_INDEX_UNDECLARED:
|
|
386
|
-
'x verify --only drift --json # each X_DB_INDEX_UNDECLARED warning names the index: its DROP INDEX CONCURRENTLY IF EXISTS "<name>"; goes in a new hand-written migration (-- transaction: false), or declare it in the entity\'s indexes: [...] and x db gen "<change>"',
|
|
387
|
-
X_SHIPPED_GUARD_MISSING:
|
|
388
|
-
"x doctor --json # each X_SHIPPED_GUARD_MISSING warning's fix is the command that writes its guard, then x verify --only boundaries --json",
|
|
389
377
|
X_DEV_LOG_ABSENT:
|
|
390
378
|
'x dev --json # the dev server writes the dev log as it boots; then: x logs tail --json',
|
|
391
379
|
X_DEV_PEER_REFUSED:
|
|
@@ -393,17 +381,18 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
393
381
|
X_PROFILE_ROUTE_FAILED: 'x routes --json',
|
|
394
382
|
X_ROWS_SLICE_ENTITY:
|
|
395
383
|
'x help g --json # then generate a job with the name and feature the finding names, and declare exportRows/importRows in it over the table that entity.ts declares',
|
|
396
|
-
X_SUPERSEDED_WORKAROUND:
|
|
397
|
-
'x doctor --json # each finding names the file, the release that retired the workaround and its replacement',
|
|
398
|
-
X_GUARD_VENDORED: 'x upgrade --json',
|
|
399
384
|
X_GUARD_BUILT_IN:
|
|
400
385
|
'x verify --only boundaries --json # set its severity in guards/shipped.json, or generate an app guard under another name',
|
|
401
386
|
X_REPRO_BUNDLE_INVALID:
|
|
402
387
|
'x repro --json # lists the failing jobs and error groups; then run it again with one id and --bundle, and attach the file it writes',
|
|
403
|
-
X_ADVISORY_FLOOR_UNMET: 'bun update source-map-js immutable',
|
|
404
|
-
X_UPGRADE_CODEMODS_PENDING: 'x upgrade codemods --from 0.0.0 --json',
|
|
405
|
-
X_UPGRADE_LOCKED: 'cat .x/upgrade.lock',
|
|
406
388
|
X_APP_MIGRATIONS_UNAPPLIED: 'x db migrate --json',
|
|
389
|
+
X_HEAVY_LEDGER_UNAVAILABLE: 'x heavy status --json',
|
|
390
|
+
X_HEAVY_MEMORY_INVALID: 'export ULTIMATE_HEAVY_MEMORY=8g',
|
|
391
|
+
X_HEAVY_COMMAND_NOT_FOUND: 'x heavy run --json -- bun test',
|
|
392
|
+
// `X_SEED_ENVIRONMENT`'s form: which task to consent to is what this table cannot know, and the
|
|
393
|
+
// raised error's own `fix:` carries the named invocation; `ULTIMATE_TASK_RUN` stays in the cause.
|
|
394
|
+
X_TASK_RUN_PRODUCTION:
|
|
395
|
+
'x tasks list --json # then name the task: x tasks run <name> --production --json',
|
|
407
396
|
};
|
|
408
397
|
|
|
409
398
|
const isCliCode = (code: string): code is CliErrorCode =>
|
package/src/mcp-host.ts
CHANGED
|
@@ -40,7 +40,7 @@ import { appManifest, policyFacts } from './app-manifest';
|
|
|
40
40
|
import { loadAppRuntime } from './app-runtime';
|
|
41
41
|
import { loadAppGraph, resolveNode } from './cmd-graph-load';
|
|
42
42
|
import { declareDevEnvironment, needsDevEnvironmentDeclaration } from './dev-environment';
|
|
43
|
-
import {
|
|
43
|
+
import { liveDevLockChecked } from './dev-lock-live';
|
|
44
44
|
import { loadCodeFixes } from './error-fixes';
|
|
45
45
|
import type { Runner } from './exec';
|
|
46
46
|
import { assertExplainTarget, devNotRunning, narrowVerify, searchDocs } from './mcp-agent-host';
|
|
@@ -253,7 +253,7 @@ function capabilities(
|
|
|
253
253
|
|
|
254
254
|
async requestStatements(ask) {
|
|
255
255
|
// The lock `x dev` writes names its URL; a missing or stale one is no server to ask.
|
|
256
|
-
const lock =
|
|
256
|
+
const lock = await liveDevLockChecked(lazy.services.stateDir);
|
|
257
257
|
if (lock === undefined) throw devNotRunning();
|
|
258
258
|
return requestStatements({ devUrl: lock.url, ...ask });
|
|
259
259
|
},
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// The catalog half of `x merge-driver`: a three-way merge of the JSON, key by key. Lines cannot do
|
|
2
|
+
// it — the entry before an addition gains a comma on both sides. Two values for one key stay a
|
|
3
|
+
// conflict: which wording ships is a decision, and this file does not make decisions.
|
|
4
|
+
|
|
5
|
+
import { isJsonObject } from '@ultimat3/core';
|
|
6
|
+
import type { JsonObject } from './json-merge';
|
|
7
|
+
import { sortJsonDeep } from './json-merge';
|
|
8
|
+
|
|
9
|
+
const CONFLICT = Symbol('conflict');
|
|
10
|
+
const ABSENT = Symbol('absent');
|
|
11
|
+
|
|
12
|
+
const same = (a: unknown, b: unknown): boolean => Bun.deepEquals(a, b, true);
|
|
13
|
+
|
|
14
|
+
function mergeValue(base: unknown, ours: unknown, theirs: unknown): unknown {
|
|
15
|
+
if (same(ours, theirs) || same(theirs, base)) return ours;
|
|
16
|
+
if (same(ours, base)) return theirs;
|
|
17
|
+
if (!isJsonObject(ours) || !isJsonObject(theirs)) return CONFLICT;
|
|
18
|
+
return mergeObject(isJsonObject(base) ? base : {}, ours, theirs);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function mergeObject(base: JsonObject, ours: JsonObject, theirs: JsonObject): unknown {
|
|
22
|
+
const merged: [string, unknown][] = [];
|
|
23
|
+
for (const key of new Set([...Object.keys(ours), ...Object.keys(theirs)])) {
|
|
24
|
+
const read = (side: JsonObject): unknown => (Object.hasOwn(side, key) ? side[key] : ABSENT);
|
|
25
|
+
const value = mergeValue(read(base), read(ours), read(theirs));
|
|
26
|
+
if (value === CONFLICT) return CONFLICT;
|
|
27
|
+
if (value !== ABSENT) merged.push([key, value]);
|
|
28
|
+
}
|
|
29
|
+
return Object.fromEntries(merged);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const parsed = (text: string): JsonObject | undefined => {
|
|
33
|
+
try {
|
|
34
|
+
const value: unknown = JSON.parse(text.trim() === '' ? '{}' : text);
|
|
35
|
+
return isJsonObject(value) ? value : undefined;
|
|
36
|
+
} catch {
|
|
37
|
+
// Not JSON is an answer here: the caller falls back to a text merge, with markers.
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const isSortedDeep = (value: unknown): boolean =>
|
|
43
|
+
JSON.stringify(value) === JSON.stringify(sortJsonDeep(value));
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The merged catalog as `x g` prints one, or `undefined` when a side is not JSON or two sides
|
|
47
|
+
* disagree on a key. Sorted where both sides were, which is every catalog a generator wrote, so
|
|
48
|
+
* the merge order leaves no trace; a hand-grouped catalog keeps its order, the other side's new
|
|
49
|
+
* keys after it.
|
|
50
|
+
*/
|
|
51
|
+
export function mergeCatalogText(base: string, ours: string, theirs: string): string | undefined {
|
|
52
|
+
const [b, o, t] = [parsed(base), parsed(ours), parsed(theirs)];
|
|
53
|
+
if (b === undefined || o === undefined || t === undefined) return undefined;
|
|
54
|
+
const merged = mergeObject(b, o, t);
|
|
55
|
+
if (merged === CONFLICT) return undefined;
|
|
56
|
+
const value = isSortedDeep(o) && isSortedDeep(t) ? sortJsonDeep(merged) : merged;
|
|
57
|
+
return `${JSON.stringify(value, null, 2)}\n`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The two git merge drivers `.gitattributes` names, and whether this clone has them. Git keeps a
|
|
2
|
+
// driver's command in `.git/config`, which no clone inherits, so `x merge-driver install` (a step
|
|
3
|
+
// of `bun run setup`) writes it; an attribute naming an unknown driver is an ordinary text merge.
|
|
4
|
+
|
|
5
|
+
import type { Runner } from './exec';
|
|
6
|
+
import { quoteArg } from './shell-quote';
|
|
7
|
+
|
|
8
|
+
export const GENERATED_DRIVER = 'x-generated';
|
|
9
|
+
export const REGISTRY_DRIVER = 'x-registry';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Through the installed binary, never `bunx x`: a clone with no install would fetch an unrelated
|
|
13
|
+
* npm package named `x` and run it on the merge. With none, this is git's own text merge.
|
|
14
|
+
*/
|
|
15
|
+
export const registryDriverCommand = (prefix: string): string => {
|
|
16
|
+
const bin = quoteArg(`${prefix}node_modules/.bin/x`);
|
|
17
|
+
return `if [ -x ${bin} ]; then ${bin} merge-driver run %O %A %B %P; else git merge-file -L ours -L base -L theirs %A %O %B; fi`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Every `git config` key and value, in the order they are written. */
|
|
21
|
+
export const driverConfig = (prefix: string): readonly (readonly [string, string])[] => [
|
|
22
|
+
[`merge.${GENERATED_DRIVER}.name`, 'keep ours: x manifest rebuilds this file'],
|
|
23
|
+
// `true` exits 0 and leaves our side in place: the file is a projection, rebuilt after the merge.
|
|
24
|
+
[`merge.${GENERATED_DRIVER}.driver`, 'true'],
|
|
25
|
+
[`merge.${REGISTRY_DRIVER}.name`, 'keep what both sides added to an x registry'],
|
|
26
|
+
[`merge.${REGISTRY_DRIVER}.driver`, registryDriverCommand(prefix)],
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/** `undefined` outside a git checkout. */
|
|
30
|
+
export async function gitPrefix(root: string, runner: Runner): Promise<string | undefined> {
|
|
31
|
+
const found = await runner(['git', 'rev-parse', '--show-prefix'], { cwd: root });
|
|
32
|
+
return found.ok ? found.stdout.trim() : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether `.gitattributes` names the driver and this clone does not define it. */
|
|
36
|
+
export async function driverUnset(root: string, runner: Runner): Promise<boolean> {
|
|
37
|
+
const attributes = Bun.file(`${root}/.gitattributes`);
|
|
38
|
+
if (!(await attributes.exists())) return false;
|
|
39
|
+
if (!(await attributes.text()).includes(`merge=${REGISTRY_DRIVER}`)) return false;
|
|
40
|
+
if ((await gitPrefix(root, runner)) === undefined) return false;
|
|
41
|
+
const key = `merge.${REGISTRY_DRIVER}.driver`;
|
|
42
|
+
return !(await runner(['git', 'config', '--get', key], { cwd: root })).ok;
|
|
43
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// The registry half of `x merge-driver`: conflicts that are only "both sides ADDED here" keep both.
|
|
2
|
+
// Not `merge=union`, which also keeps a line one side deleted (a revoked grant in `roles.ts` comes
|
|
3
|
+
// back) and splices multi-line entries together. A conflict touching an existing line stays one.
|
|
4
|
+
|
|
5
|
+
import { maskOf } from './source-list-edit';
|
|
6
|
+
|
|
7
|
+
export const OURS_MARKER = '<<<<<<< ours';
|
|
8
|
+
const BASE_MARKER = '||||||| base';
|
|
9
|
+
const SPLIT_MARKER = '=======';
|
|
10
|
+
const THEIRS_MARKER = '>>>>>>> theirs';
|
|
11
|
+
|
|
12
|
+
export interface LineMerge {
|
|
13
|
+
readonly text: string;
|
|
14
|
+
/** The conflicts left in `text`, each still between its markers. */
|
|
15
|
+
readonly conflicts: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const indentOf = (line: string): number => /^[ \t]*/.exec(line)?.[0].length ?? 0;
|
|
19
|
+
|
|
20
|
+
const depthOf = (masked: string): number => {
|
|
21
|
+
let depth = 0;
|
|
22
|
+
for (const ch of masked) {
|
|
23
|
+
if ('([{'.includes(ch)) depth += 1;
|
|
24
|
+
else if (')]}'.includes(ch)) depth -= 1;
|
|
25
|
+
}
|
|
26
|
+
return depth;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** Brackets balanced and the last code a `,` or `;`: nothing a neighbour could be spliced into. */
|
|
30
|
+
const isWhole = (lines: readonly string[]): boolean => {
|
|
31
|
+
const masked = maskOf(lines.join('\n')).trimEnd();
|
|
32
|
+
return depthOf(masked) === 0 && /[,;]$/.test(masked);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The added lines as whole entries — an entry starts at the block's own indent and runs until it
|
|
37
|
+
* is complete, so `foo: {`…`},` is one and a comment joins what it precedes. `undefined` when they
|
|
38
|
+
* do not divide that way: such a hunk is not a list of additions.
|
|
39
|
+
*/
|
|
40
|
+
function entriesOf(lines: readonly string[]): readonly string[] | undefined {
|
|
41
|
+
if (lines.some((line) => line.trim() === '')) return undefined;
|
|
42
|
+
const indent = Math.min(...lines.map(indentOf));
|
|
43
|
+
const entries: string[][] = [];
|
|
44
|
+
for (const line of lines) {
|
|
45
|
+
const last = entries.at(-1);
|
|
46
|
+
if (last === undefined || (indentOf(line) === indent && isWhole(last))) entries.push([line]);
|
|
47
|
+
else last.push(line);
|
|
48
|
+
}
|
|
49
|
+
return entries.every(isWhole) ? entries.map((entry) => entry.join('\n')) : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const SPECIFIER = /\bfrom\s+'([^']+)';\s*$/;
|
|
53
|
+
|
|
54
|
+
/** What may appear once: an import's binding or module, an object entry's key. */
|
|
55
|
+
function identityOf(entry: string): string | undefined {
|
|
56
|
+
const code = entry.trimStart();
|
|
57
|
+
if (code.startsWith('import ')) {
|
|
58
|
+
const namespace = /^import \* as ([\w$]+)/.exec(code)?.[1];
|
|
59
|
+
return namespace === undefined ? `from:${SPECIFIER.exec(code)?.[1]}` : `as:${namespace}`;
|
|
60
|
+
}
|
|
61
|
+
const key = /^(?:([\w$]+)|'([^']+)'|"([^"]+)")\s*:/.exec(code);
|
|
62
|
+
return key === null ? undefined : `key:${key[1] ?? key[2] ?? key[3]}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const sortKeyOf = (entry: string): string => SPECIFIER.exec(entry)?.[1] ?? entry.trimStart();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Both sides' entries, each once, in one order. Sorted so that merging A into B and B into A write
|
|
69
|
+
* the same bytes, and so an import block stays in the order Biome requires. `undefined` when the
|
|
70
|
+
* two sides declare one name differently, which is a real conflict.
|
|
71
|
+
*/
|
|
72
|
+
function bothSides(ours: readonly string[], theirs: readonly string[]): string[] | undefined {
|
|
73
|
+
const left = entriesOf(ours);
|
|
74
|
+
const right = entriesOf(theirs);
|
|
75
|
+
if (left === undefined || right === undefined) return undefined;
|
|
76
|
+
const entries = [...new Set([...left, ...right])];
|
|
77
|
+
const identities = entries.flatMap((entry) => identityOf(entry) ?? []);
|
|
78
|
+
if (new Set(identities).size !== identities.length) return undefined;
|
|
79
|
+
return entries
|
|
80
|
+
.sort((a, b) => {
|
|
81
|
+
const [x, y] = [sortKeyOf(a), sortKeyOf(b)];
|
|
82
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
83
|
+
})
|
|
84
|
+
.flatMap((entry) => entry.split('\n'));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A marker line, with or without the `\r` git ends it with on a CRLF file. The `\r` stays on every
|
|
89
|
+
* line this module passes through or reorders, so the merged file keeps its own line ending.
|
|
90
|
+
*/
|
|
91
|
+
const isMarker = (line: string | undefined, marker: string): boolean =>
|
|
92
|
+
line === marker || line === `${marker}\r`;
|
|
93
|
+
|
|
94
|
+
/** The first `marker` line at or after `from`; -1 when there is none, or no `from` to start at. */
|
|
95
|
+
export const markerAt = (lines: readonly string[], marker: string, from: number): number => {
|
|
96
|
+
if (from < 0) return -1;
|
|
97
|
+
for (let at = from; at < lines.length; at += 1) {
|
|
98
|
+
if (isMarker(lines[at], marker)) return at;
|
|
99
|
+
}
|
|
100
|
+
return -1;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** `text` — `git merge-file --diff3 -L ours -L base -L theirs` output — with additions resolved. */
|
|
104
|
+
export function resolveAdditions(text: string): LineMerge {
|
|
105
|
+
const lines = text.split('\n');
|
|
106
|
+
const out: string[] = [];
|
|
107
|
+
let conflicts = 0;
|
|
108
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
109
|
+
const line = lines[index] as string;
|
|
110
|
+
if (!isMarker(line, OURS_MARKER)) {
|
|
111
|
+
out.push(line);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const baseAt = markerAt(lines, BASE_MARKER, index);
|
|
115
|
+
const splitAt = markerAt(lines, SPLIT_MARKER, baseAt);
|
|
116
|
+
const endAt = markerAt(lines, THEIRS_MARKER, splitAt);
|
|
117
|
+
if (baseAt === -1 || splitAt === -1 || endAt === -1) {
|
|
118
|
+
out.push(line);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const merged =
|
|
122
|
+
splitAt === baseAt + 1
|
|
123
|
+
? bothSides(lines.slice(index + 1, baseAt), lines.slice(splitAt + 1, endAt))
|
|
124
|
+
: undefined;
|
|
125
|
+
if (merged === undefined) conflicts += 1;
|
|
126
|
+
out.push(...(merged ?? lines.slice(index, endAt + 1)));
|
|
127
|
+
index = endAt;
|
|
128
|
+
}
|
|
129
|
+
return { text: out.join('\n'), conflicts };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The count the driver exits on. `resolved` is `resolveAdditions`' own; the rest is a backstop for
|
|
134
|
+
* a marker it did not recognise: when git reported conflicts and a line of the result still opens
|
|
135
|
+
* one, the file is not merged whatever was counted, and git's number stands.
|
|
136
|
+
*/
|
|
137
|
+
export function conflictsLeft(text: string, resolved: number, gitReported: number): number {
|
|
138
|
+
if (resolved > 0 || gitReported <= 0) return resolved;
|
|
139
|
+
return /^<{7} /m.test(text) ? gitReported : 0;
|
|
140
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// What a merge left behind, as findings: paths git still holds unmerged, and i18n catalogs that do
|
|
2
|
+
// not parse. A catalog is imported by nearly every page, so one stray marker used to surface as a
|
|
3
|
+
// SyntaxError blamed on each importer, with the catalog itself named nowhere.
|
|
4
|
+
|
|
5
|
+
// why: `Bun.Glob.scan` throws on a missing directory, and an app need not have any catalog.
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { ERROR_DOCS_URL, renderThrowable } from '@ultimat3/core';
|
|
8
|
+
import type { Runner } from './exec';
|
|
9
|
+
import { exec } from './exec';
|
|
10
|
+
import type { Finding } from './output';
|
|
11
|
+
import { quoteArg } from './shell-quote';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `templates/locales.ts`'s `CATALOG_ROOT`, restated: `loadApp` reaches this module, and the serve
|
|
15
|
+
* graph carries no template (`serve-graph.test.ts`). `merge-state.test.ts` holds the two equal.
|
|
16
|
+
*/
|
|
17
|
+
export const CATALOG_ROOT = 'packages/i18n/catalogs';
|
|
18
|
+
|
|
19
|
+
export const UNMERGED_FIX = 'git diff --name-only --diff-filter=U';
|
|
20
|
+
|
|
21
|
+
const MARKER = /^(?:<{7}|\|{7}|={7}|>{7})(?: |$)/m;
|
|
22
|
+
|
|
23
|
+
const finding = (code: string, cause: string, fix: string, at: string): Finding => ({
|
|
24
|
+
code,
|
|
25
|
+
cause,
|
|
26
|
+
fix,
|
|
27
|
+
docs: ERROR_DOCS_URL,
|
|
28
|
+
at,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/** Every path git holds unmerged, relative to `root`; none outside a checkout. */
|
|
32
|
+
export async function unmergedPaths(
|
|
33
|
+
root: string,
|
|
34
|
+
runner: Runner = exec,
|
|
35
|
+
): Promise<readonly string[]> {
|
|
36
|
+
const argv = ['git', 'diff', '--name-only', '--relative', '--diff-filter=U'];
|
|
37
|
+
const found = await runner(argv, { cwd: root }).catch(() => undefined);
|
|
38
|
+
if (found?.ok !== true) return [];
|
|
39
|
+
return found.stdout.split('\n').filter((path) => path !== '');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function unmergedFindings(root: string, runner?: Runner): Promise<readonly Finding[]> {
|
|
43
|
+
return (await unmergedPaths(root, runner)).map((path) =>
|
|
44
|
+
finding(
|
|
45
|
+
'X_MERGE_UNRESOLVED',
|
|
46
|
+
`${path} is still unmerged: git holds conflicting versions of it`,
|
|
47
|
+
UNMERGED_FIX,
|
|
48
|
+
path,
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** One finding per catalog that will not load, naming the file every importer failed on. */
|
|
54
|
+
export async function catalogFileFindings(root: string): Promise<readonly Finding[]> {
|
|
55
|
+
const findings: Finding[] = [];
|
|
56
|
+
const directory = `${root}/${CATALOG_ROOT}`;
|
|
57
|
+
if (!existsSync(directory)) return findings;
|
|
58
|
+
for await (const name of new Bun.Glob('*.json').scan(directory)) {
|
|
59
|
+
const at = `${CATALOG_ROOT}/${name}`;
|
|
60
|
+
const text = await Bun.file(`${root}/${at}`).text();
|
|
61
|
+
if (MARKER.test(text)) {
|
|
62
|
+
findings.push(
|
|
63
|
+
finding(
|
|
64
|
+
'X_MERGE_UNRESOLVED',
|
|
65
|
+
`${at} holds conflict markers, so it is not JSON and no page importing it loads`,
|
|
66
|
+
`grep -nE '^(<{7}|={7}|>{7})' ${quoteArg(at)} # keep the right side of each, delete the markers`,
|
|
67
|
+
at,
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
JSON.parse(text);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
findings.push(
|
|
76
|
+
finding(
|
|
77
|
+
'X_CATALOG_UNPARSEABLE',
|
|
78
|
+
`${at} is not valid JSON (${renderThrowable(error)}), so no page importing it loads`,
|
|
79
|
+
`bunx biome check ${quoteArg(at)} # names the line to correct`,
|
|
80
|
+
at,
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return findings;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const isCatalogSymptom = (one: Finding): boolean =>
|
|
89
|
+
one.code === 'X_CLI_UNEXPECTED' && one.cause.includes('JSON Parse error');
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A failed app load, its causes first: an unparseable catalog replaces the parse errors it caused
|
|
93
|
+
* in every importer, and an unmerged path leads, because it explains whatever else failed. Asked
|
|
94
|
+
* only once the load has already failed, so a healthy app pays nothing.
|
|
95
|
+
*/
|
|
96
|
+
export async function withMergeCauses(
|
|
97
|
+
root: string,
|
|
98
|
+
findings: readonly Finding[],
|
|
99
|
+
): Promise<readonly Finding[]> {
|
|
100
|
+
const catalogs = await catalogFileFindings(root);
|
|
101
|
+
const held = new Set(catalogs.map((one) => one.at));
|
|
102
|
+
const unmerged = (await unmergedFindings(root)).filter((one) => !held.has(one.at));
|
|
103
|
+
const rest = catalogs.length > 0 ? findings.filter((one) => !isCatalogSymptom(one)) : findings;
|
|
104
|
+
return [...unmerged, ...catalogs, ...rest];
|
|
105
|
+
}
|