@ultimat3/cli 31.48.0 → 31.50.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 +30 -30
- package/src/api-registration.ts +45 -14
- package/src/api-routes.ts +1 -0
- package/src/app-load.ts +7 -3
- package/src/app-openapi.ts +7 -1
- package/src/app-root.ts +7 -1
- package/src/budgets.ts +2 -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 +80 -18
- 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 +9 -1
- package/src/cmd-heavy.ts +111 -27
- package/src/cmd-i18n.ts +33 -1
- 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 +2 -1
- package/src/cmd-upgrade-spec.ts +8 -1
- package/src/cmd-upgrade.ts +15 -1
- 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 +11 -15
- package/src/codemods/docs-worker-commands.ts +26 -0
- package/src/codemods/engine-fs.ts +9 -2
- package/src/codemods/index.ts +4 -0
- package/src/codemods/merge-drivers.ts +147 -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-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 +2 -0
- package/src/error-codes.ts +12 -13
- package/src/errors-suite.ts +27 -0
- package/src/errors.ts +18 -22
- package/src/exercise-registration.ts +4 -3
- package/src/exercise-services.ts +13 -3
- package/src/framework-env.ts +7 -3
- package/src/framework-schema.ts +15 -5
- 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/guard-sources.ts +1 -2
- package/src/guards.ts +2 -2
- package/src/heavy-env.ts +2 -0
- package/src/heavy-errors.ts +18 -0
- package/src/heavy-holders.ts +78 -0
- package/src/heavy-ledger.ts +56 -14
- package/src/heavy-pressure.ts +104 -0
- package/src/heavy.ts +31 -13
- 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/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 +15 -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 +10 -0
- package/src/messages.ts +54 -4
- package/src/output-findings.ts +48 -21
- package/src/page-navigation.ts +5 -2
- 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/pwa-artifacts.ts +1 -1
- package/src/registry-lines.ts +110 -0
- package/src/registry.ts +2 -0
- package/src/retain-sweep.ts +1 -1
- package/src/retained-assets-boot.ts +1 -1
- package/src/role-replicator.ts +4 -1
- package/src/role-select.ts +86 -0
- package/src/role-start.ts +13 -55
- package/src/role-sync.ts +10 -5
- package/src/runtime-assets-site.ts +2 -2
- package/src/runtime-assets.ts +1 -1
- package/src/runtime-cache-frame.ts +46 -0
- package/src/runtime-cache-ttl.ts +23 -0
- package/src/runtime-cache.ts +33 -16
- 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-queue.ts +18 -3
- package/src/runtime-render-document.ts +1 -2
- 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/site-asset-routes.ts +2 -2
- package/src/site-assets.ts +5 -158
- 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/sw-precache-plan.ts +1 -1
- 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 +97 -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 +58 -9
- 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-commands.ts +6 -0
- package/src/templates/scaffold-claude.ts +4 -4
- package/src/templates/scaffold-container-compose.ts +47 -7
- package/src/templates/scaffold-docs.ts +7 -3
- package/src/templates/scaffold-gitattributes.ts +18 -1
- package/src/templates/scaffold-helm-templates.ts +9 -0
- package/src/templates/scaffold-repo.ts +5 -2
- 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-only-shipped.ts +29 -2
- package/src/test-shards.ts +134 -42
- package/src/test-verdict.ts +79 -0
- package/src/test-workers.ts +15 -0
- package/src/upgrade-coverage-ratchet.ts +95 -0
- package/src/upgrade-gate-codemods.ts +5 -3
- package/src/upgrade-gate.ts +42 -4
- package/src/upgrade-merge-drivers.ts +25 -0
- package/src/upgrade-report.ts +32 -4
- package/src/upgrade-scope.ts +62 -0
- package/src/verify-checks.ts +2 -8
- package/src/verify-coverage-run.ts +4 -1
- package/src/verify-e2e.ts +21 -3
- 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 +6 -7
- package/src/verify-tests.ts +8 -2
- package/src/verify-typecheck.ts +25 -2
- package/src/workspace-checks.ts +4 -1
- package/wiki/Actions.md +66 -3
- package/wiki/Admin-Dashboard.md +2 -2
- package/wiki/Agents.md +5 -5
- package/wiki/Auth.md +20 -6
- package/wiki/Bare-VM.md +1 -1
- package/wiki/CI-Parallel-Gate.md +2 -1
- package/wiki/CLI-Reference.md +115 -42
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Client-Navigation.md +35 -5
- package/wiki/Configuration.md +12 -10
- package/wiki/Deployment.md +44 -4
- package/wiki/Entities-And-Migrations.md +17 -3
- package/wiki/FAQ.md +1 -1
- package/wiki/Getting-Started.md +2 -2
- package/wiki/Home.md +3 -3
- package/wiki/I18n.md +6 -4
- package/wiki/Installation.md +12 -11
- package/wiki/Interface-Rules.md +3 -1
- package/wiki/Jobs-And-Workflows.md +24 -4
- package/wiki/Known-Gaps.md +2 -2
- package/wiki/MCP-And-AI.md +48 -13
- package/wiki/Many-Agents.md +69 -2
- package/wiki/Migrations-And-Backfills.md +18 -0
- package/wiki/Notify.md +5 -3
- package/wiki/Observability.md +13 -0
- package/wiki/Outbound-HTTP.md +53 -2
- package/wiki/Policies-And-Authz.md +1 -1
- package/wiki/Queries-And-Live-Queries.md +2 -2
- package/wiki/Realtime.md +24 -7
- package/wiki/Routes-And-Render-Modes.md +2 -2
- package/wiki/Scheduled-Tasks.md +4 -1
- package/wiki/Static-Assets.md +5 -3
- package/wiki/Testing.md +64 -7
- package/wiki/Theming.md +6 -3
- package/wiki/Timezones-And-Dates.md +5 -1
- package/wiki/Troubleshooting.md +1 -0
- package/wiki/Tutorial-01-First-App.md +3 -3
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
- package/wiki/UI-Components.md +1 -0
- package/wiki/Upgrading.md +38 -0
package/src/cmd-errors.ts
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
// invented should come back refused: "no such code", never a plausible-sounding explanation.
|
|
4
4
|
|
|
5
5
|
import { nearestName, singleLine } from '@ultimat3/core';
|
|
6
|
+
import { definedErrorStatus } from '@ultimat3/core/internal/error-status';
|
|
6
7
|
import type { ErrorExplanation } from '@ultimat3/mcp';
|
|
8
|
+
import { findAppRoot } from './app-root';
|
|
9
|
+
import { type AppCodeExplanation, AppCodeUnknownError, explainAppCode } from './cmd-errors-app';
|
|
7
10
|
import { explainGuardCode } from './cmd-errors-guards';
|
|
8
11
|
import { withRecent } from './cmd-errors-recent';
|
|
9
12
|
import { errorsSpec } from './cmd-errors-spec';
|
|
@@ -15,6 +18,8 @@ import { ErrorCodeUnknownError, MissingPositionalError } from './errors';
|
|
|
15
18
|
import { explainErrorCode, explainEveryErrorCode } from './mcp-errors';
|
|
16
19
|
import { msg } from './messages';
|
|
17
20
|
import type { CommandResult, JsonValue } from './output';
|
|
21
|
+
import type { ReaderOptions } from './output-findings';
|
|
22
|
+
import { fixForReader } from './output-findings';
|
|
18
23
|
import { flagBool } from './parse';
|
|
19
24
|
|
|
20
25
|
export { ERRORS_SUBCOMMANDS } from './cmd-errors-spec';
|
|
@@ -25,21 +30,21 @@ export { ERRORS_SUBCOMMANDS } from './cmd-errors-spec';
|
|
|
25
30
|
* caller that has to regex `packages/x/src/y.ts:80` back out of an English sentence is a caller the
|
|
26
31
|
* machine-readable surface failed. `null` when the installed framework raises the code nowhere.
|
|
27
32
|
*/
|
|
28
|
-
const asJson = (explanation: ErrorExplanation): JsonValue => {
|
|
33
|
+
const asJson = (explanation: ErrorExplanation, reader?: ReaderOptions): JsonValue => {
|
|
29
34
|
const site = codeFixes().get(explanation.code)?.[0];
|
|
30
35
|
return {
|
|
31
36
|
code: explanation.code,
|
|
32
37
|
cause: explanation.cause,
|
|
33
|
-
fix: explanation.fix,
|
|
38
|
+
fix: fixForReader(explanation.fix, reader),
|
|
34
39
|
docs: explanation.docs,
|
|
35
40
|
site: site === undefined ? null : { at: site.at, line: site.line },
|
|
36
41
|
};
|
|
37
42
|
};
|
|
38
43
|
|
|
39
44
|
/** The 3-line contract format, minus the leading blank code line `renderFinding` would add. */
|
|
40
|
-
const detailLines = (explanation: ErrorExplanation): readonly string[] => [
|
|
45
|
+
const detailLines = (explanation: ErrorExplanation, reader?: ReaderOptions): readonly string[] => [
|
|
41
46
|
` cause: ${singleLine(explanation.cause)}`,
|
|
42
|
-
` fix: ${singleLine(explanation.fix)}`,
|
|
47
|
+
` fix: ${singleLine(fixForReader(explanation.fix, reader))}`,
|
|
43
48
|
` docs: ${singleLine(explanation.docs)}`,
|
|
44
49
|
];
|
|
45
50
|
|
|
@@ -47,30 +52,61 @@ const detailLines = (explanation: ErrorExplanation): readonly string[] => [
|
|
|
47
52
|
* A registered code, else a guard's — a shipped guard's or this app's own (`cmd-errors-guards.ts`):
|
|
48
53
|
* the gate prints both, and the app's `CLAUDE.md` sends every printed code here.
|
|
49
54
|
*/
|
|
50
|
-
async function explainOne(
|
|
51
|
-
|
|
55
|
+
async function explainOne(
|
|
56
|
+
code: string,
|
|
57
|
+
cwd: string,
|
|
58
|
+
reader?: ReaderOptions,
|
|
59
|
+
): Promise<CommandResult> {
|
|
60
|
+
// A `defineError()` code is an app's, even once this process has loaded the app (`x mcp serve`, a
|
|
61
|
+
// test rerun): the registry then knows it, and it was answered as a framework code with no throw
|
|
62
|
+
// site in the installed framework, never from the app that declares it.
|
|
63
|
+
const appDeclared = definedErrorStatus(code) !== undefined;
|
|
64
|
+
const explanation = appDeclared
|
|
65
|
+
? undefined
|
|
66
|
+
: (explainErrorCode(code) ?? (await explainGuardCode(code, cwd)));
|
|
52
67
|
if (explanation === undefined) {
|
|
68
|
+
// Before the app loads, so the near miss is a framework code the caller mistyped.
|
|
53
69
|
const suggestion = nearestName(
|
|
54
70
|
code,
|
|
55
71
|
explainEveryErrorCode().map((entry) => entry.code),
|
|
56
72
|
);
|
|
57
|
-
|
|
73
|
+
const declared = await explainAppCode(code, cwd);
|
|
74
|
+
if (declared !== undefined) return appCodeResult(declared);
|
|
75
|
+
if (suggestion !== undefined) throw new ErrorCodeUnknownError({ code, suggestion });
|
|
76
|
+
throw new AppCodeUnknownError({ code, inApp: findAppRoot(cwd) !== undefined });
|
|
58
77
|
}
|
|
59
78
|
return {
|
|
60
79
|
ok: true,
|
|
61
80
|
command: 'errors',
|
|
62
81
|
summary: msg('cli.errors.explained', { code: explanation.code, title: explanation.cause }),
|
|
63
|
-
lines: detailLines(explanation),
|
|
64
|
-
data: asJson(explanation),
|
|
82
|
+
lines: detailLines(explanation, reader),
|
|
83
|
+
data: asJson(explanation, reader),
|
|
65
84
|
};
|
|
66
85
|
}
|
|
67
86
|
|
|
87
|
+
/**
|
|
88
|
+
* An app's own code: what the registry holds (title, status) and the declaring line. No `cause:` or
|
|
89
|
+
* `fix:` line — the registry keeps neither for a `defineError` code, and the declaration is one open
|
|
90
|
+
* file away.
|
|
91
|
+
*/
|
|
92
|
+
const appCodeResult = (declared: AppCodeExplanation): CommandResult => ({
|
|
93
|
+
ok: true,
|
|
94
|
+
command: 'errors',
|
|
95
|
+
summary: msg('cli.errors.explained', { code: declared.code, title: declared.title }),
|
|
96
|
+
lines: [
|
|
97
|
+
` status: ${declared.status ?? 'off-socket'}`,
|
|
98
|
+
...(declared.site === null ? [] : [` declared: ${declared.site.at}:${declared.site.line}`]),
|
|
99
|
+
` docs: ${singleLine(declared.docs)}`,
|
|
100
|
+
],
|
|
101
|
+
data: { ...declared },
|
|
102
|
+
});
|
|
103
|
+
|
|
68
104
|
/**
|
|
69
105
|
* A package that resolved and then threw is a defect, not a host gap: its codes are missing from
|
|
70
106
|
* this answer and something is broken that a `fix:` can address. Reported as findings — and `ok`
|
|
71
107
|
* goes false — so the incomplete catalog cannot read as a complete one.
|
|
72
108
|
*/
|
|
73
|
-
function listAll(catalog: ErrorCatalog): CommandResult {
|
|
109
|
+
function listAll(catalog: ErrorCatalog, reader?: ReaderOptions): CommandResult {
|
|
74
110
|
const all = explainEveryErrorCode();
|
|
75
111
|
return {
|
|
76
112
|
ok: catalog.failed.length === 0,
|
|
@@ -79,7 +115,7 @@ function listAll(catalog: ErrorCatalog): CommandResult {
|
|
|
79
115
|
lines: all.map((entry) => ` ${entry.code.padEnd(30)} ${singleLine(entry.cause)}`),
|
|
80
116
|
findings: catalog.failed,
|
|
81
117
|
data: {
|
|
82
|
-
codes: all.map(asJson),
|
|
118
|
+
codes: all.map((entry) => asJson(entry, reader)),
|
|
83
119
|
unavailable: [...catalog.unavailable],
|
|
84
120
|
failed: catalog.failed.map((finding) => ({
|
|
85
121
|
code: finding.code,
|
|
@@ -100,7 +136,7 @@ export const errorsCommand: CliCommand = {
|
|
|
100
136
|
// and the fix index is what each one instructs. `x errors list` answering 397 codes with the
|
|
101
137
|
// fallback line would be a complete-looking table of shrugs.
|
|
102
138
|
const [catalog] = await Promise.all([loadErrorCatalog(), loadCodeFixes()]);
|
|
103
|
-
if (ctx.args.subcommand === 'list') return listAll(catalog);
|
|
139
|
+
if (ctx.args.subcommand === 'list') return listAll(catalog, ctx.reader);
|
|
104
140
|
const code = ctx.args.positionals[0];
|
|
105
141
|
if (code === undefined) {
|
|
106
142
|
// Not a `BadFlagError`: naming `--code` invented a flag that does not exist, so an agent
|
|
@@ -114,8 +150,8 @@ export const errorsCommand: CliCommand = {
|
|
|
114
150
|
}
|
|
115
151
|
// `--recent`: what THIS app has seen of the code — groups and the bundles `x repro` replays.
|
|
116
152
|
if (flagBool(ctx.args, 'recent')) {
|
|
117
|
-
return withRecent(ctx, code, await explainOne(code, ctx.cwd));
|
|
153
|
+
return withRecent(ctx, code, await explainOne(code, ctx.cwd, ctx.reader));
|
|
118
154
|
}
|
|
119
|
-
return explainOne(code, ctx.cwd);
|
|
155
|
+
return explainOne(code, ctx.cwd, ctx.reader);
|
|
120
156
|
},
|
|
121
157
|
};
|
package/src/cmd-generate.ts
CHANGED
|
@@ -77,7 +77,10 @@ export const generateCommand: CliCommand = {
|
|
|
77
77
|
spec: generateSpec,
|
|
78
78
|
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
79
79
|
const root = requireAppRoot('g', ctx.cwd).dir;
|
|
80
|
-
const kind = readKind(ctx.args.positionals[0]
|
|
80
|
+
const kind = readKind(ctx.args.positionals[0], {
|
|
81
|
+
name: ctx.args.positionals[1],
|
|
82
|
+
feature: flagString(ctx.args, 'feature'),
|
|
83
|
+
});
|
|
81
84
|
refuseSignInFlags(kind, ctx.args);
|
|
82
85
|
refuseChartAlertsFlags(kind, ctx.args);
|
|
83
86
|
// One sign-in per app, named by a flag rather than a `<name>`, and edits no other kind makes.
|
|
@@ -301,7 +304,9 @@ export const generateCommand: CliCommand = {
|
|
|
301
304
|
const written = [...report.written, ...edited, ...artifacts];
|
|
302
305
|
// Named only over a clean run: with a finding, the finding's own `fix:` is the next command.
|
|
303
306
|
const table = names(isEntityKind(kind) ? name : (featureFlag ?? name)).table;
|
|
304
|
-
|
|
307
|
+
// `cronJob()` pins its schedule as `<kebab name>.schedule` (`templates/generate-cron-job.ts`).
|
|
308
|
+
const schedule = kind === 'cron-job' ? `${kebab(name)}.schedule` : undefined;
|
|
309
|
+
const next = findings.length === 0 ? nextSteps(report.written, edited, table, schedule) : [];
|
|
305
310
|
return {
|
|
306
311
|
ok: findings.length === 0,
|
|
307
312
|
command: 'g',
|
|
@@ -340,9 +345,13 @@ export function nextSteps(
|
|
|
340
345
|
written: readonly string[],
|
|
341
346
|
edited: readonly string[],
|
|
342
347
|
table: string,
|
|
348
|
+
/** A schedule this run declared (`x g cron-job`): fired now, so its first run is not its cron. */
|
|
349
|
+
task?: string,
|
|
343
350
|
): readonly string[] {
|
|
344
|
-
|
|
351
|
+
const fire = task === undefined ? [] : [`bunx x tasks run ${quoteArg(task)}`];
|
|
352
|
+
if (!written.some(isEntityModule)) return fire;
|
|
345
353
|
return [
|
|
354
|
+
...fire,
|
|
346
355
|
...(edited.some((path) => path.endsWith('package.json')) ? ['bun install'] : []),
|
|
347
356
|
`bunx x db gen "create ${table}"`,
|
|
348
357
|
'bunx x db migrate',
|
|
@@ -373,7 +382,11 @@ async function readSliceErrors(
|
|
|
373
382
|
slice: string,
|
|
374
383
|
name: 'errors.ts' | 'policy.ts' = 'errors.ts',
|
|
375
384
|
): Promise<string | undefined> {
|
|
376
|
-
|
|
385
|
+
// A read imports its rule from `policy.ts` too (`can<Feature>Read`), and throws nothing of the
|
|
386
|
+
// slice's — so `query` reads the policy and never the errors.
|
|
387
|
+
const reads =
|
|
388
|
+
kind === 'action' || kind === 'mutator' || (kind === 'query' && name === 'policy.ts');
|
|
389
|
+
if (!reads) return undefined;
|
|
377
390
|
const file = containedPath(root, `${slice}/${name}`);
|
|
378
391
|
return existsSync(file) ? await Bun.file(file).text() : undefined;
|
|
379
392
|
}
|
package/src/cmd-heavy-spec.ts
CHANGED
|
@@ -7,7 +7,8 @@ export const heavySpec: CommandSpec = {
|
|
|
7
7
|
name: 'heavy',
|
|
8
8
|
summary:
|
|
9
9
|
"the machine's shared memory ledger: who is running, who is queued, and any command run inside it",
|
|
10
|
-
usage:
|
|
10
|
+
usage:
|
|
11
|
+
'x heavy [status] [--json] · x heavy run [--label s] [--mb n] [--max-wait s] [--json] -- <command…>',
|
|
11
12
|
subcommands: ['status', 'run'],
|
|
12
13
|
defaultSubcommand: 'status',
|
|
13
14
|
passthrough: true,
|
|
@@ -24,5 +25,12 @@ export const heavySpec: CommandSpec = {
|
|
|
24
25
|
summary: 'the memory to reserve, its measured peak (default: a whole-repo typecheck)',
|
|
25
26
|
subcommands: ['run'],
|
|
26
27
|
},
|
|
28
|
+
{
|
|
29
|
+
name: 'max-wait',
|
|
30
|
+
type: 'string',
|
|
31
|
+
summary:
|
|
32
|
+
'seconds to stay queued before giving up with X_HEAVY_WAIT_EXPIRED, exit 75 (default: wait)',
|
|
33
|
+
subcommands: ['run'],
|
|
34
|
+
},
|
|
27
35
|
],
|
|
28
36
|
};
|
package/src/cmd-heavy.ts
CHANGED
|
@@ -10,9 +10,12 @@ import { MissingPositionalError } from './errors';
|
|
|
10
10
|
import { readIntFlag } from './flag-number';
|
|
11
11
|
import { describeEntry, heavyState, withHeavy } from './heavy';
|
|
12
12
|
import { coreCap, runnableTasks } from './heavy-cores';
|
|
13
|
-
import { HeavyCommandNotFoundError } from './heavy-errors';
|
|
13
|
+
import { HeavyCommandNotFoundError, HeavyWaitExpiredError } from './heavy-errors';
|
|
14
|
+
import { holderPids, isProcessRunning } from './heavy-holders';
|
|
15
|
+
import type { LedgerEntry, LedgerHold } from './heavy-ledger';
|
|
14
16
|
import { readLedger } from './heavy-ledger';
|
|
15
17
|
import { availableMemoryBytes, usableMemoryBytes } from './heavy-memory';
|
|
18
|
+
import { cpuGateOn, cpuText, readCpuPressure } from './heavy-pressure';
|
|
16
19
|
import { DEFAULT_RUN_MB } from './heavy-weights';
|
|
17
20
|
import type { HandOffChild } from './local-cli-handoff';
|
|
18
21
|
import { handOff } from './local-cli-handoff';
|
|
@@ -21,8 +24,35 @@ import type { CommandResult, JsonValue } from './output';
|
|
|
21
24
|
import { findingFrom } from './output';
|
|
22
25
|
import { flagString } from './parse';
|
|
23
26
|
|
|
27
|
+
/** Read through `readIntFlag`, which refuses `5m`, `NaN` and a fraction with the flag's name. */
|
|
28
|
+
const MAX_WAIT_FLAG = 'max-wait';
|
|
29
|
+
|
|
24
30
|
const gb = (bytes: number): string => (bytes / 2 ** 30).toFixed(1);
|
|
25
31
|
const MAX_RUN_MB = 1024 * 1024;
|
|
32
|
+
const MAX_WAIT_SECONDS = 7 * 24 * 60 * 60;
|
|
33
|
+
/** `EX_TEMPFAIL`: never the command's own answer, because the command never ran. */
|
|
34
|
+
const WAIT_EXPIRED_EXIT = 75;
|
|
35
|
+
|
|
36
|
+
/** A reservation by the processes keeping it: its wrapper may be gone while its command runs on. */
|
|
37
|
+
async function holdProcesses(hold: LedgerHold, ctx: CommandContext) {
|
|
38
|
+
const pids = await holderPids(hold.file, ctx.runner, ctx.cwd);
|
|
39
|
+
return {
|
|
40
|
+
wrapperAlive: pids === undefined ? isProcessRunning(hold.pid) : pids.includes(hold.pid),
|
|
41
|
+
childPids: (pids ?? []).filter((pid) => pid !== hold.pid),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type HoldProcesses = Awaited<ReturnType<typeof holdProcesses>>;
|
|
46
|
+
|
|
47
|
+
const pidsText = (hold: LedgerHold, processes: HoldProcesses): string =>
|
|
48
|
+
[
|
|
49
|
+
msg(processes.wrapperAlive ? 'cli.heavy.status.wrapper' : 'cli.heavy.status.wrapperGone', {
|
|
50
|
+
pid: hold.pid,
|
|
51
|
+
}),
|
|
52
|
+
...(processes.childPids.length === 0
|
|
53
|
+
? []
|
|
54
|
+
: [msg('cli.heavy.status.command', { pids: processes.childPids.join(', ') })]),
|
|
55
|
+
].join(', ');
|
|
26
56
|
|
|
27
57
|
async function status(ctx: CommandContext): Promise<CommandResult> {
|
|
28
58
|
const state = await heavyState({ ...ctx.env, ULTIMATE_HEAVY_HOLD: undefined });
|
|
@@ -32,14 +62,21 @@ async function status(ctx: CommandContext): Promise<CommandResult> {
|
|
|
32
62
|
const coreText = cores === undefined ? String(availableParallelism()) : String(cores);
|
|
33
63
|
const usedMb = view.holds.reduce((sum, entry) => sum + entry.mb, 0);
|
|
34
64
|
const [one = 0, five = 0, fifteen = 0] = loadavg();
|
|
65
|
+
const cpu = readCpuPressure();
|
|
66
|
+
// The gate applies where admission does; the reading is shown either way.
|
|
67
|
+
const cpuGate = state.on && cpuGateOn(ctx.env);
|
|
35
68
|
const machine = {
|
|
36
69
|
cores: availableParallelism(),
|
|
37
70
|
runnable: runnableTasks(),
|
|
38
71
|
load: { one, five, fifteen },
|
|
39
72
|
totalBytes: usableMemoryBytes(totalmem()),
|
|
40
73
|
availableBytes: availableMemoryBytes(),
|
|
74
|
+
cpu: { ...cpu },
|
|
41
75
|
};
|
|
42
|
-
const
|
|
76
|
+
const processes = await Promise.all(view.holds.map((hold) => holdProcesses(hold, ctx)));
|
|
77
|
+
const processesOf = (at: number): HoldProcesses =>
|
|
78
|
+
processes[at] ?? { wrapperAlive: false, childPids: [] };
|
|
79
|
+
const entryJson = (entry: LedgerEntry): JsonValue => ({
|
|
43
80
|
pid: entry.pid,
|
|
44
81
|
mb: entry.mb,
|
|
45
82
|
label: entry.label,
|
|
@@ -66,8 +103,17 @@ async function status(ctx: CommandContext): Promise<CommandResult> {
|
|
|
66
103
|
free: gb(machine.availableBytes),
|
|
67
104
|
total: gb(machine.totalBytes),
|
|
68
105
|
}),
|
|
69
|
-
|
|
70
|
-
msg('cli.heavy.status.
|
|
106
|
+
cpuGate
|
|
107
|
+
? msg('cli.heavy.status.cpu', { cpu: cpuText(cpu) })
|
|
108
|
+
: msg('cli.heavy.status.cpuOff', {
|
|
109
|
+
cpu: cpuText(cpu),
|
|
110
|
+
reason: state.on ? 'a test run, or ULTIMATE_HEAVY_CPU=0' : state.off,
|
|
111
|
+
}),
|
|
112
|
+
...view.holds.map((entry, at) =>
|
|
113
|
+
msg('cli.heavy.status.hold', {
|
|
114
|
+
entry: describeEntry(entry, now),
|
|
115
|
+
pids: pidsText(entry, processesOf(at)),
|
|
116
|
+
}),
|
|
71
117
|
),
|
|
72
118
|
...view.queue.map((entry, at) =>
|
|
73
119
|
msg('cli.heavy.status.queued', { position: at + 1, entry: describeEntry(entry, now) }),
|
|
@@ -79,8 +125,16 @@ async function status(ctx: CommandContext): Promise<CommandResult> {
|
|
|
79
125
|
? { dir: state.dir, capacityMb: state.capacityMb, usedMb }
|
|
80
126
|
: { off: state.off, ...(state.detail === undefined ? {} : { detail: state.detail }) }),
|
|
81
127
|
coreCap: cores ?? null,
|
|
128
|
+
cpuGate,
|
|
82
129
|
machine,
|
|
83
|
-
holds: view.holds.map(
|
|
130
|
+
holds: view.holds.map((entry, at): JsonValue => {
|
|
131
|
+
const { wrapperAlive, childPids } = processesOf(at);
|
|
132
|
+
return {
|
|
133
|
+
...(entryJson(entry) as Record<string, JsonValue>),
|
|
134
|
+
wrapperAlive,
|
|
135
|
+
childPids: [...childPids],
|
|
136
|
+
};
|
|
137
|
+
}),
|
|
84
138
|
queue: view.queue.map(entryJson),
|
|
85
139
|
},
|
|
86
140
|
};
|
|
@@ -113,31 +167,61 @@ async function run(ctx: CommandContext): Promise<CommandResult> {
|
|
|
113
167
|
max: MAX_RUN_MB,
|
|
114
168
|
example: 'x heavy run --mb 4096 -- bun test',
|
|
115
169
|
});
|
|
170
|
+
const maxWait = readIntFlag(ctx.args, {
|
|
171
|
+
name: MAX_WAIT_FLAG,
|
|
172
|
+
command: 'heavy',
|
|
173
|
+
min: 0,
|
|
174
|
+
max: MAX_WAIT_SECONDS,
|
|
175
|
+
example: 'x heavy run --max-wait 300 -- bun test',
|
|
176
|
+
});
|
|
116
177
|
const label = flagString(ctx.args, 'label') ?? command.slice(0, 3).join(' ');
|
|
117
178
|
const queued = performance.now();
|
|
118
179
|
let startedAt = queued;
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
180
|
+
const request = {
|
|
181
|
+
label,
|
|
182
|
+
cwd: ctx.cwd,
|
|
183
|
+
env: ctx.env,
|
|
184
|
+
unitMb: mb ?? DEFAULT_RUN_MB,
|
|
185
|
+
...(maxWait === undefined ? {} : { maxWaitMs: maxWait * 1000 }),
|
|
186
|
+
};
|
|
187
|
+
const admitted = withHeavy(request, (child) => {
|
|
188
|
+
startedAt = performance.now();
|
|
189
|
+
return handOff(
|
|
190
|
+
command,
|
|
191
|
+
{ ...ctx.env, ...child.env },
|
|
192
|
+
{
|
|
193
|
+
spawn: (argv, env): HandOffChild =>
|
|
194
|
+
// Untimed: the child is the command the caller asked to run, and its stop signals are
|
|
195
|
+
// forwarded by `handOff`. Counted under `cli`'s spawn-timeout pin with that hand-off.
|
|
196
|
+
Bun.spawn([...argv], {
|
|
197
|
+
cwd: ctx.cwd,
|
|
198
|
+
env,
|
|
199
|
+
// The reservation's lock goes with it: killing this wrapper frees nothing the
|
|
200
|
+
// command is still using.
|
|
201
|
+
stdio: ['inherit', ctx.args.json ? 2 : 'inherit', 'inherit', ...child.fds],
|
|
202
|
+
}),
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
let code: number;
|
|
207
|
+
try {
|
|
208
|
+
code = await admitted;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
if (!(error instanceof HeavyWaitExpiredError)) throw error;
|
|
211
|
+
const finding = findingFrom(error);
|
|
212
|
+
return {
|
|
213
|
+
...envelope,
|
|
214
|
+
ok: false,
|
|
215
|
+
summary: finding.cause,
|
|
216
|
+
findings: [finding],
|
|
217
|
+
exitCode: WAIT_EXPIRED_EXIT,
|
|
218
|
+
data: {
|
|
219
|
+
exitCode: WAIT_EXPIRED_EXIT,
|
|
220
|
+
started: false,
|
|
221
|
+
waitedMs: Math.round(performance.now() - queued),
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
141
225
|
const ranMs = performance.now() - startedAt;
|
|
142
226
|
const waitedMs = startedAt - queued;
|
|
143
227
|
return {
|
package/src/cmd-i18n.ts
CHANGED
|
@@ -308,6 +308,32 @@ async function adminCatalog(locale: string, seeded: boolean): Promise<Catalog> {
|
|
|
308
308
|
return Object.fromEntries(keys.map((key) => [key, label(key)]));
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
+
/**
|
|
312
|
+
* The admin keys just written to a second locale that the default locale's FILE lacks, written
|
|
313
|
+
* there too. The default locale answers them already — the framework's own `en` holds the admin
|
|
314
|
+
* chrome (`admin.brand.name`, `admin.x_jobs.title`), so its registry is green with no such key in
|
|
315
|
+
* the app's catalog — and syncing only the second locale left the app's catalogs with two key sets,
|
|
316
|
+
* the scaffold's own "same keys as the default" test red on the command the gate prescribed. The
|
|
317
|
+
* value is the string the default locale already renders, never a marker, so its page is unchanged.
|
|
318
|
+
*/
|
|
319
|
+
async function backfillDefault(
|
|
320
|
+
root: string,
|
|
321
|
+
catalogs: Readonly<Record<string, Catalog>>,
|
|
322
|
+
from: string,
|
|
323
|
+
adminKeys: readonly string[],
|
|
324
|
+
): Promise<readonly string[]> {
|
|
325
|
+
const target = catalogs[from] ?? {};
|
|
326
|
+
const rendered = catalogFor(from);
|
|
327
|
+
const real = (key: string): string => {
|
|
328
|
+
const value = rendered[key];
|
|
329
|
+
return value === undefined || isLoudMiss(value) ? adminKeyLabel(key) : value;
|
|
330
|
+
};
|
|
331
|
+
const source = Object.fromEntries(adminKeys.map((key) => [key, real(key)]));
|
|
332
|
+
const { merged, added } = syncCatalog(target, source);
|
|
333
|
+
if (added.length > 0) await Bun.write(join(root, catalogPath(from)), serializeCatalog(merged));
|
|
334
|
+
return added;
|
|
335
|
+
}
|
|
336
|
+
|
|
311
337
|
async function runSync(root: string, ctx: CommandContext): Promise<CommandResult> {
|
|
312
338
|
const locale = resolveOneLocale(ctx, 'sync');
|
|
313
339
|
const catalogs = await loadCatalogs(root);
|
|
@@ -330,14 +356,17 @@ async function runSync(root: string, ctx: CommandContext): Promise<CommandResult
|
|
|
330
356
|
const seeded = from === undefined || from === locale;
|
|
331
357
|
// The admin's keys first, so a value the default locale already carries for one (copied, marked)
|
|
332
358
|
// wins over a label read off the key.
|
|
359
|
+
const admin = await adminCatalog(locale, seeded);
|
|
333
360
|
const source = {
|
|
334
|
-
...
|
|
361
|
+
...admin,
|
|
335
362
|
...(seeded
|
|
336
363
|
? placeholderCatalog(await untranslatedKeys(root, catalogs, locale))
|
|
337
364
|
: seedCatalog(catalogs[from] ?? {})),
|
|
338
365
|
};
|
|
339
366
|
const { merged, added } = syncCatalog(target, source);
|
|
340
367
|
if (added.length > 0) await Bun.write(join(root, catalogPath(locale)), serializeCatalog(merged));
|
|
368
|
+
const adminAdded = added.filter((key) => Object.hasOwn(admin, key));
|
|
369
|
+
const defaultAdded = seeded ? [] : await backfillDefault(root, catalogs, from, adminAdded);
|
|
341
370
|
// Unconditional, and not only when keys moved: a catalog that reached disk some other way — a
|
|
342
371
|
// hand-created file, a `git merge` — is exactly the unregistered locale the gate refuses, and
|
|
343
372
|
// this is the command its `fix:` names. Re-deriving an index that is already correct writes the
|
|
@@ -367,6 +396,9 @@ async function runSync(root: string, ctx: CommandContext): Promise<CommandResult
|
|
|
367
396
|
// both are what `x i18n check` counts as missing until replaced, so `--json` never reports a
|
|
368
397
|
// copy as a translation.
|
|
369
398
|
placeholders: added.filter((key) => isLoudMiss(merged[key])),
|
|
399
|
+
// The admin keys also written to the default locale's catalog, so every app catalog keeps one
|
|
400
|
+
// key set (`backfillDefault`). Empty when the default locale is the one synced.
|
|
401
|
+
defaultAdded,
|
|
370
402
|
},
|
|
371
403
|
};
|
|
372
404
|
}
|
package/src/cmd-jobs.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { requireAppRoot } from './app-root';
|
|
|
20
20
|
import { runResolveStep } from './cmd-jobs-resolve';
|
|
21
21
|
import { jobsSpec } from './cmd-jobs-spec';
|
|
22
22
|
import type { CliCommand, CommandContext } from './command';
|
|
23
|
+
import { refuseEmbeddedWriteBesideDev } from './dev-lock-live';
|
|
23
24
|
import { BadFlagError, JobUnknownError, MissingPositionalError } from './errors';
|
|
24
25
|
import { withJobDriver } from './jobs-driver';
|
|
25
26
|
import {
|
|
@@ -31,6 +32,7 @@ import {
|
|
|
31
32
|
pausedToJson,
|
|
32
33
|
workerToJson,
|
|
33
34
|
} from './jobs-json';
|
|
35
|
+
import { assertQueueServed } from './jobs-queue-known';
|
|
34
36
|
import { listJobs, retryJob, showJob } from './jobs-report';
|
|
35
37
|
import { renderJobTable } from './jobs-table';
|
|
36
38
|
import { msg } from './messages';
|
|
@@ -239,8 +241,16 @@ async function runPause(
|
|
|
239
241
|
driver: JobDriver,
|
|
240
242
|
ctx: CommandContext,
|
|
241
243
|
sub: 'pause' | 'resume',
|
|
244
|
+
root: string,
|
|
242
245
|
): Promise<CommandResult> {
|
|
243
246
|
const queue = requireQueuePositional(ctx, sub);
|
|
247
|
+
const before = (await driver.introspect?.pausedQueues()) ?? [];
|
|
248
|
+
await assertQueueServed(
|
|
249
|
+
root,
|
|
250
|
+
sub,
|
|
251
|
+
queue,
|
|
252
|
+
before.map((one) => one.name),
|
|
253
|
+
);
|
|
244
254
|
const paused = await (sub === 'pause' ? pauseQueue(driver, queue) : resumeQueue(driver, queue));
|
|
245
255
|
return {
|
|
246
256
|
ok: true,
|
|
@@ -253,6 +263,17 @@ async function runPause(
|
|
|
253
263
|
/** The subcommands that answer a `JobTrace`. `list`, `delete`, `promote` and the rest read rows only. */
|
|
254
264
|
const TRACE_SUBCOMMANDS: ReadonlySet<string> = new Set(['show', 'retry', 'cancel', 'resolve-step']);
|
|
255
265
|
|
|
266
|
+
/** Every verb but `list` and `show`: each changes a row the workers read. */
|
|
267
|
+
const WRITING_SUBCOMMANDS: ReadonlySet<string> = new Set([
|
|
268
|
+
'retry',
|
|
269
|
+
'cancel',
|
|
270
|
+
'delete',
|
|
271
|
+
'promote',
|
|
272
|
+
'resolve-step',
|
|
273
|
+
'pause',
|
|
274
|
+
'resume',
|
|
275
|
+
]);
|
|
276
|
+
|
|
256
277
|
export const jobsCommand: CliCommand = {
|
|
257
278
|
spec: jobsSpec,
|
|
258
279
|
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
@@ -264,6 +285,11 @@ export const jobsCommand: CliCommand = {
|
|
|
264
285
|
// every app. The findings are deliberately dropped: a trace is read to debug a stuck queue,
|
|
265
286
|
// so an app that half-loads degrades those two fields and still answers.
|
|
266
287
|
if (TRACE_SUBCOMMANDS.has(sub)) await loadApp(root);
|
|
288
|
+
// A verb that writes a queue row, through this command's own boot: beside an `x dev` holding
|
|
289
|
+
// the embedded database it is a second PGlite writer, and the holder's next write undoes it.
|
|
290
|
+
if (WRITING_SUBCOMMANDS.has(sub)) {
|
|
291
|
+
await refuseEmbeddedWriteBesideDev(root, ctx.env, ['jobs', sub, ...ctx.args.positionals]);
|
|
292
|
+
}
|
|
267
293
|
return withJobDriver(root, ctx, (driver) => {
|
|
268
294
|
if (sub === 'show') return runShow(driver, ctx);
|
|
269
295
|
if (sub === 'retry') return runRetry(driver, ctx);
|
|
@@ -273,7 +299,7 @@ export const jobsCommand: CliCommand = {
|
|
|
273
299
|
if (sub === 'resolve-step') {
|
|
274
300
|
return runResolveStep(driver, ctx, requireIdPositional(ctx, sub, driver));
|
|
275
301
|
}
|
|
276
|
-
if (sub === 'pause' || sub === 'resume') return runPause(driver, ctx, sub);
|
|
302
|
+
if (sub === 'pause' || sub === 'resume') return runPause(driver, ctx, sub, root);
|
|
277
303
|
return runList(driver, ctx);
|
|
278
304
|
});
|
|
279
305
|
},
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// `x merge-driver`'s declaration, apart from its body: the parser, `x help` and the `errors` step
|
|
2
|
+
// read it without loading `cmd-merge-driver.ts`, which `registry.ts` imports only when it runs.
|
|
3
|
+
|
|
4
|
+
import type { CommandSpec } from './parse';
|
|
5
|
+
|
|
6
|
+
export const mergeDriverSpec: CommandSpec = {
|
|
7
|
+
name: 'merge-driver',
|
|
8
|
+
summary: 'merges what parallel branches added to the registries; git runs it, setup installs it',
|
|
9
|
+
usage: 'x merge-driver install [--json] · x merge-driver run <base> <ours> <theirs> <path>',
|
|
10
|
+
subcommands: ['install', 'run'],
|
|
11
|
+
flags: [],
|
|
12
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// `x merge-driver`: `install` writes the two git drivers into this clone, `run` is the one git
|
|
2
|
+
// calls for a registry both sides changed. Exit 0 is "merged"; anything else leaves the file holding
|
|
3
|
+
// its remaining conflict markers and git reporting it as conflicted, as for any text merge.
|
|
4
|
+
|
|
5
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
6
|
+
import { mergeDriverSpec } from './cmd-merge-driver-spec';
|
|
7
|
+
import type { CliCommand, CommandContext } from './command';
|
|
8
|
+
import { failed, ok } from './command';
|
|
9
|
+
import { MissingPositionalError } from './errors';
|
|
10
|
+
import { mergeCatalogText } from './merge-driver-catalog';
|
|
11
|
+
import { driverConfig, gitPrefix } from './merge-driver-config';
|
|
12
|
+
import { conflictsLeft, resolveAdditions } from './merge-driver-lines';
|
|
13
|
+
import { UNMERGED_FIX } from './merge-state';
|
|
14
|
+
import type { CommandResult, Finding } from './output';
|
|
15
|
+
|
|
16
|
+
const NAME = mergeDriverSpec.name;
|
|
17
|
+
|
|
18
|
+
async function install(ctx: CommandContext): Promise<CommandResult> {
|
|
19
|
+
const prefix = await gitPrefix(ctx.cwd, ctx.runner);
|
|
20
|
+
if (prefix === undefined) {
|
|
21
|
+
return ok(NAME, 'not a git checkout: no merge drivers to install', {
|
|
22
|
+
data: { installed: false },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
for (const [key, value] of driverConfig(prefix)) {
|
|
26
|
+
const set = await ctx.runner(['git', 'config', '--local', key, value], { cwd: ctx.cwd });
|
|
27
|
+
if (!set.ok) {
|
|
28
|
+
return failed(NAME, `could not set ${key}`, {
|
|
29
|
+
findings: [
|
|
30
|
+
{
|
|
31
|
+
code: 'X_MERGE_DRIVER_UNSET',
|
|
32
|
+
cause: `git config refused ${key}: ${set.stderr.trim()}`,
|
|
33
|
+
fix: 'bunx x merge-driver install',
|
|
34
|
+
docs: ERROR_DOCS_URL,
|
|
35
|
+
at: '.git/config',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return ok(NAME, 'merge drivers installed for this clone', { data: { installed: true } });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const conflictFinding = (path: string, cause: string): Finding => ({
|
|
45
|
+
code: 'X_MERGE_UNRESOLVED',
|
|
46
|
+
cause,
|
|
47
|
+
fix: UNMERGED_FIX,
|
|
48
|
+
docs: ERROR_DOCS_URL,
|
|
49
|
+
at: path,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
async function run(ctx: CommandContext): Promise<CommandResult> {
|
|
53
|
+
const [base, ours, theirs, path] = ctx.args.positionals;
|
|
54
|
+
if (base === undefined || ours === undefined || theirs === undefined || path === undefined) {
|
|
55
|
+
throw new MissingPositionalError({
|
|
56
|
+
command: 'merge-driver run',
|
|
57
|
+
positional: 'base> <ours> <theirs> <path',
|
|
58
|
+
example: 'bunx x merge-driver install # git passes these four itself, once installed',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const text = (file: string): Promise<string> => Bun.file(file).text();
|
|
62
|
+
if (path.endsWith('.json')) {
|
|
63
|
+
const merged = mergeCatalogText(await text(base), await text(ours), await text(theirs));
|
|
64
|
+
if (merged !== undefined) {
|
|
65
|
+
await Bun.write(ours, merged);
|
|
66
|
+
return ok(NAME, `${path}: merged both sides' keys`, { data: { path, conflicts: 0 } });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const labels = ['-L', 'ours', '-L', 'base', '-L', 'theirs'];
|
|
70
|
+
const argv = ['git', 'merge-file', '-p', '--diff3', ...labels, ours, base, theirs];
|
|
71
|
+
const merge = await ctx.runner(argv, { cwd: ctx.cwd });
|
|
72
|
+
// A positive exit is how many conflicts it left; git's own failures are negative, so 255 here.
|
|
73
|
+
if (merge.code < 0 || merge.code > 127) {
|
|
74
|
+
return failed(NAME, `${path}: git merge-file failed`, {
|
|
75
|
+
findings: [conflictFinding(path, `git merge-file refused ${path}: ${merge.stderr.trim()}`)],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const resolved = path.endsWith('.json')
|
|
79
|
+
? { text: merge.stdout, conflicts: merge.code }
|
|
80
|
+
: resolveAdditions(merge.stdout);
|
|
81
|
+
const result = resolved.text;
|
|
82
|
+
// Never exit 0 over a marker: git then records a clean merge of a file that still holds one.
|
|
83
|
+
const conflicts = conflictsLeft(result, resolved.conflicts, merge.code);
|
|
84
|
+
await Bun.write(ours, result);
|
|
85
|
+
if (conflicts === 0) {
|
|
86
|
+
return ok(NAME, `${path}: merged both sides' additions`, { data: { path, conflicts } });
|
|
87
|
+
}
|
|
88
|
+
const cause = `${path}: both branches changed the same existing lines (${conflicts} conflict(s))`;
|
|
89
|
+
return failed(NAME, cause, { findings: [conflictFinding(path, cause)] });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const mergeDriverCommand: CliCommand = {
|
|
93
|
+
spec: mergeDriverSpec,
|
|
94
|
+
run: (ctx) => (ctx.args.subcommand === 'install' ? install(ctx) : run(ctx)),
|
|
95
|
+
};
|