@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
package/src/dev-policy.ts
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
import { listActions } from '@ultimat3/action';
|
|
7
7
|
import type { PolicyFact } from '@ultimat3/admin/dev';
|
|
8
8
|
import type { NamedActor, Policy } from '@ultimat3/policy';
|
|
9
|
-
import {
|
|
9
|
+
import { roleDefinitions, testActor } from '@ultimat3/policy';
|
|
10
10
|
import { listQueries } from '@ultimat3/query';
|
|
11
|
+
import { rowWithoutInput } from './policy-row';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* One capability and the policy that decides it. A primitive's `capability` IS its policy's own
|
|
@@ -56,21 +57,23 @@ export function devPolicyGates(): readonly PolicyGate[] {
|
|
|
56
57
|
/**
|
|
57
58
|
* The matrix, actor by actor and capability by capability.
|
|
58
59
|
*
|
|
59
|
-
* Evaluated with no row on purpose: `/_x` asks whether an actor may reach a
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* Evaluated with no row and no input on purpose: `/_x` asks whether an actor may reach a
|
|
61
|
+
* capability at all, and outside a real request there is neither. A row-level rule shows its
|
|
62
|
+
* no-row verdict and the trace says so; a predicate that reads the input is `needs input` — the
|
|
63
|
+
* row `x policy explain` draws (`policy-row.ts`), never the deny `input: {}` used to produce.
|
|
62
64
|
*/
|
|
63
65
|
export function devPolicyMatrix(): readonly PolicyFact[] {
|
|
64
66
|
const actors = devActors();
|
|
65
67
|
return devPolicyGates().flatMap((gate) => {
|
|
66
|
-
const
|
|
67
|
-
return
|
|
68
|
+
const rows = actors.map((actor) => rowWithoutInput(gate.policy, actor));
|
|
69
|
+
return rows.map(
|
|
68
70
|
(row): PolicyFact => ({
|
|
69
71
|
permission: gate.permission,
|
|
70
72
|
actorId: row.actor,
|
|
71
|
-
allowed: row.allowed,
|
|
73
|
+
allowed: row.allowed === true,
|
|
74
|
+
verdict: row.verdict,
|
|
72
75
|
trace: [
|
|
73
|
-
`${gate.policy.label}: ${row.
|
|
76
|
+
`${gate.policy.label}: ${row.verdict === 'needs-input' ? 'needs input' : row.verdict}`,
|
|
74
77
|
...(row.deciding === null ? [] : [`deciding rule: ${row.deciding}`]),
|
|
75
78
|
...(row.reason === null ? [] : [`reason: ${row.reason}`]),
|
|
76
79
|
`enforced in: ${gate.usedBy.join(', ')}`,
|
|
@@ -1,30 +1,133 @@
|
|
|
1
|
-
// The schema half of an `x dev` generation: entities ahead of the migrations,
|
|
2
|
-
// generation is built — at the boot a restart makes, and
|
|
3
|
-
// `X_DB_SCHEMA_STALE` on the page that queries the new column.
|
|
1
|
+
// The schema half of an `x dev` generation: entities ahead of the migrations, and migrations ahead
|
|
2
|
+
// of the database's ledger, said when the generation is built — at the boot a restart makes, and
|
|
3
|
+
// at a save — instead of first as `X_DB_SCHEMA_STALE` on the page that queries the new column.
|
|
4
4
|
|
|
5
|
+
import type { Migration } from '@ultimat3/db';
|
|
6
|
+
import { db, dbClientInstalled, isLedgerMissing, readLedger } from '@ultimat3/db';
|
|
7
|
+
import { AppMigrationsUnappliedError } from './app-migrations-verdict';
|
|
8
|
+
import { type AppliedRow, refuseEdited } from './db-applied-edits';
|
|
9
|
+
import { devCanMigrate, MIGRATE_ALONE_FIX } from './dev-db-migrate';
|
|
5
10
|
import { checkSourceDrift } from './drift';
|
|
11
|
+
import { readMigrations } from './migrations';
|
|
6
12
|
import type { Finding } from './output';
|
|
7
13
|
import { findingFrom } from './output';
|
|
14
|
+
import { resolveServices } from './runtime-bindings';
|
|
8
15
|
|
|
9
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The migrate half too: `x dev` applies no migration unasked, so `x db gen` alone leaves the page
|
|
18
|
+
* red. Beside this process `x db migrate` is applied BY it (`dev-db-migrate.ts`), embedded or not.
|
|
19
|
+
*/
|
|
10
20
|
export const SCHEMA_AHEAD_FIX = 'x db gen "describe the change" && x db migrate';
|
|
11
21
|
|
|
22
|
+
/** Where this process cannot apply the pass itself: the embedded database, to the command alone. */
|
|
23
|
+
export const SCHEMA_AHEAD_FIX_ALONE = `x db gen "describe the change" && ${MIGRATE_ALONE_FIX}`;
|
|
24
|
+
|
|
25
|
+
/** Whether `x db migrate` works while this `x dev` runs: any external database, or a pass it takes. */
|
|
26
|
+
export async function migratesBesideDev(root: string): Promise<boolean> {
|
|
27
|
+
return resolveServices(root, Bun.env).db.mode !== 'embedded' || (await devCanMigrate(root));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** What `ledgerFindings` asks — the seam a test hands rows through. */
|
|
31
|
+
export interface LedgerReads {
|
|
32
|
+
readonly migrations: (root: string) => Promise<readonly Migration[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Whether this process holds a database at all. `x dev`'s boot installs its client before the
|
|
35
|
+
* first generation; a caller that built one with none (a test, a tool) has nothing to compare
|
|
36
|
+
* against, and `db()` would dial a default for it.
|
|
37
|
+
*/
|
|
38
|
+
readonly database: () => boolean;
|
|
39
|
+
/** `undefined` when the ledger table does not exist: nothing was ever applied. */
|
|
40
|
+
readonly ledger: () => Promise<readonly AppliedRow[] | undefined>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const READS: LedgerReads = {
|
|
44
|
+
migrations: readMigrations,
|
|
45
|
+
database: dbClientInstalled,
|
|
46
|
+
ledger: async () => {
|
|
47
|
+
try {
|
|
48
|
+
return await readLedger(db());
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (!isLedgerMissing(error)) throw error;
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The migrations on disk against the ledger of the database this process serves. `x db gen` beside
|
|
58
|
+
* a running `x dev` writes a file the database has not applied: every read of the new column is a
|
|
59
|
+
* 500, so the generation is not green until `x db migrate` — which this process applies itself
|
|
60
|
+
* (`dev-db-migrate.ts`) and then rebuilds for (`dev-db-settled.ts`). An applied migration edited
|
|
61
|
+
* since is the other half of the same read: `X_MIGRATION_CONFLICT`, as the migrator would refuse.
|
|
62
|
+
*/
|
|
63
|
+
export async function ledgerFindings(
|
|
64
|
+
root: string,
|
|
65
|
+
beside: (root: string) => Promise<boolean> = migratesBesideDev,
|
|
66
|
+
reads: LedgerReads = READS,
|
|
67
|
+
): Promise<readonly Finding[]> {
|
|
68
|
+
const migrations = await reads.migrations(root);
|
|
69
|
+
if (migrations.length === 0 || !reads.database()) return [];
|
|
70
|
+
const ledger = await reads.ledger();
|
|
71
|
+
const applied = new Set((ledger ?? []).map((row) => row.id));
|
|
72
|
+
const missing = migrations.map((migration) => migration.id).filter((id) => !applied.has(id));
|
|
73
|
+
const findings: Finding[] = [];
|
|
74
|
+
if (missing.length > 0) {
|
|
75
|
+
const behind = findingFrom(
|
|
76
|
+
new AppMigrationsUnappliedError({ missing, ledger: ledger !== undefined }),
|
|
77
|
+
);
|
|
78
|
+
findings.push((await beside(root)) ? behind : { ...behind, fix: MIGRATE_ALONE_FIX });
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
refuseEdited(ledger ?? [], migrations);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
findings.push(findingFrom(error));
|
|
84
|
+
}
|
|
85
|
+
return findings;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Every finding this module handed a generation — by identity, since any code may be one. */
|
|
89
|
+
const schemaFindings = new WeakSet<Finding>();
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Whether `finding` is about the schema, not about what this process loaded or mounted. A schema
|
|
93
|
+
* finding appearing or clearing never needs a new process (`dev-rebuild.ts`): the modules and the
|
|
94
|
+
* route table are the same, and this process is the one that applies the migration.
|
|
95
|
+
*/
|
|
96
|
+
export const isSchemaFinding = (finding: Finding): boolean => schemaFindings.has(finding);
|
|
97
|
+
|
|
98
|
+
function marked(findings: readonly Finding[]): readonly Finding[] {
|
|
99
|
+
for (const finding of findings) schemaFindings.add(finding);
|
|
100
|
+
return findings;
|
|
101
|
+
}
|
|
102
|
+
|
|
12
103
|
/**
|
|
13
|
-
* `checkSourceDrift`'s answer with the whole instruction. Asked only of a
|
|
14
|
-
* clean: a module that would not import leaves the registry short, which
|
|
15
|
-
* there. Never rejects — a failed check is a finding, never a dev
|
|
104
|
+
* `checkSourceDrift`'s answer with the whole instruction, then the ledger's. Asked only of a
|
|
105
|
+
* generation that loaded clean: a module that would not import leaves the registry short, which
|
|
106
|
+
* hashes as drift that is not there. Never rejects — a failed check is a finding, never a dev
|
|
107
|
+
* server that will not boot.
|
|
16
108
|
*/
|
|
17
109
|
export async function schemaAheadFindings(
|
|
18
110
|
root: string,
|
|
19
111
|
check: (root: string) => Promise<readonly Finding[]> = checkSourceDrift,
|
|
112
|
+
beside: (root: string) => Promise<boolean> = migratesBesideDev,
|
|
113
|
+
ledger: (
|
|
114
|
+
root: string,
|
|
115
|
+
beside: (root: string) => Promise<boolean>,
|
|
116
|
+
) => Promise<readonly Finding[]> = ledgerFindings,
|
|
20
117
|
): Promise<readonly Finding[]> {
|
|
21
118
|
try {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
119
|
+
const drifted = await check(root);
|
|
120
|
+
const fix =
|
|
121
|
+
drifted.length === 0 || (await beside(root)) ? SCHEMA_AHEAD_FIX : SCHEMA_AHEAD_FIX_ALONE;
|
|
122
|
+
return marked([
|
|
123
|
+
...drifted.map((finding) => ({
|
|
124
|
+
...finding,
|
|
125
|
+
cause: `entities are ahead of the migrations: ${finding.cause}`,
|
|
126
|
+
fix,
|
|
127
|
+
})),
|
|
128
|
+
...(await ledger(root, beside)),
|
|
129
|
+
]);
|
|
27
130
|
} catch (error) {
|
|
28
|
-
return [findingFrom(error)];
|
|
131
|
+
return marked([findingFrom(error)]);
|
|
29
132
|
}
|
|
30
133
|
}
|
package/src/dev-rebuild.ts
CHANGED
|
@@ -12,9 +12,10 @@ import type { AppManifest } from './app-manifest';
|
|
|
12
12
|
import { appManifest } from './app-manifest';
|
|
13
13
|
import type { StalePin } from './app-reload-graph';
|
|
14
14
|
import { takeStalePins } from './app-reload-graph';
|
|
15
|
+
import { onLedgerMoved } from './dev-db-settled';
|
|
15
16
|
import { clearIsrForRebuild } from './dev-rebuild-isr';
|
|
16
17
|
import { remountFinding, remountLine, remountReason } from './dev-rebuild-remount';
|
|
17
|
-
import { schemaAheadFindings } from './dev-rebuild-schema';
|
|
18
|
+
import { isSchemaFinding, schemaAheadFindings } from './dev-rebuild-schema';
|
|
18
19
|
import type { ReloadTrigger } from './dev-reload';
|
|
19
20
|
import { coalesceReloads } from './dev-reload';
|
|
20
21
|
import { restartFinding, restartReason } from './dev-supervisor';
|
|
@@ -127,7 +128,12 @@ export function devRebuilder(
|
|
|
127
128
|
): ReloadTrigger {
|
|
128
129
|
// What the route table was built from: the boot's generation, for the life of this process. Each
|
|
129
130
|
// save is compared with IT, not with the save before — a route added two saves ago is still a 404.
|
|
130
|
-
|
|
131
|
+
// The LOAD findings only: a schema finding (entities ahead, the ledger behind) appears and clears
|
|
132
|
+
// with no module or route moving, and a restart for one is a dead port for the `x db migrate`
|
|
133
|
+
// that clears it — measured with two processes, a 30 s boot refused the pass it was waiting for.
|
|
134
|
+
const loaded = (findings: readonly Finding[]): readonly Finding[] =>
|
|
135
|
+
findings.filter((finding) => !isSchemaFinding(finding));
|
|
136
|
+
const mounted = { manifest: state.manifest, findings: loaded(state.appFindings) };
|
|
131
137
|
// What this process still holds stale, for the life of it — the same rule as `mounted`. A pinned
|
|
132
138
|
// module keeps the old instance until a new process, so a LATER rebuild that changed nothing
|
|
133
139
|
// (the watcher's second event for one write, a no-op save) is still a restart: it reported
|
|
@@ -141,12 +147,12 @@ export function devRebuilder(
|
|
|
141
147
|
};
|
|
142
148
|
// One rebuild at a time, and the last save wins: a tick arriving mid-build coalesces into ONE
|
|
143
149
|
// trailing rebuild instead of racing the one in flight for `state.manifest` and `state.islands`.
|
|
144
|
-
|
|
150
|
+
const trigger = coalesceReloads(
|
|
145
151
|
async (file) => {
|
|
146
152
|
const started = performance.now();
|
|
147
153
|
beginDeviceSocketGeneration();
|
|
148
154
|
const { manifest, findings, islands } = await buildGeneration(options.root, build);
|
|
149
|
-
const remount = remountReason(mounted, { manifest, findings });
|
|
155
|
+
const remount = remountReason(mounted, { manifest, findings: loaded(findings) });
|
|
150
156
|
state.manifest = manifest;
|
|
151
157
|
state.appFindings = findings;
|
|
152
158
|
state.islands = islands;
|
|
@@ -189,4 +195,7 @@ export function devRebuilder(
|
|
|
189
195
|
state.reloadFinding = { ...findingFrom(error), at: file };
|
|
190
196
|
},
|
|
191
197
|
);
|
|
198
|
+
// A migrate or rollback applied through `/_x/db` changes no file: it asks for its generation here.
|
|
199
|
+
onLedgerMoved(trigger);
|
|
200
|
+
return trigger;
|
|
192
201
|
}
|
package/src/dev-route-table.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { clientErrorsSurface } from './client-errors-routes';
|
|
|
17
17
|
import { clientScriptHeads, clientVitalsSurface } from './client-vitals-route';
|
|
18
18
|
import type { DevDashboardInput } from './dev-dashboard';
|
|
19
19
|
import { devDashboardRoutes } from './dev-dashboard';
|
|
20
|
+
import { devMigrateRoutes } from './dev-db-migrate';
|
|
20
21
|
import { errorPageStyleBodies } from './error-page-csp';
|
|
21
22
|
import type { IslandBundle } from './island-bundle';
|
|
22
23
|
import { islandHarnessRoutes } from './island-harness-route';
|
|
@@ -151,6 +152,12 @@ export async function devRouteTable(input: DevRouteTableInput): Promise<DevRoute
|
|
|
151
152
|
const vitals = clientVitalsSurface(reporting?.vitals);
|
|
152
153
|
const routes: readonly Route[] = [
|
|
153
154
|
...devDashboardRoutes(input.dashboard),
|
|
155
|
+
// `x db migrate` beside this process: applied here, by the one holder of the embedded database.
|
|
156
|
+
...devMigrateRoutes({
|
|
157
|
+
root: input.root,
|
|
158
|
+
env: input.env,
|
|
159
|
+
devUrl: () => input.dashboard.status().url,
|
|
160
|
+
}),
|
|
154
161
|
// The same API table the container serves: a read that answers here and 404s in production
|
|
155
162
|
// is exactly the drift one composition exists to prevent.
|
|
156
163
|
...apiRoutes(),
|
package/src/dispatch.ts
CHANGED
|
@@ -93,6 +93,23 @@ const errorResult = (command: string, error: unknown): CommandResult => ({
|
|
|
93
93
|
* Returns the exit code instead of calling process.exit, so a test can drive the whole CLI end to
|
|
94
94
|
* end without terminating the test runner.
|
|
95
95
|
*/
|
|
96
|
+
/**
|
|
97
|
+
* `argv` as a refusal's fix pastes it back: every word typed, less `--cwd` (the fix names the
|
|
98
|
+
* directory itself) and the JSON switch (it ends with one). Rebuilt from the command's name alone,
|
|
99
|
+
* `x db migrate` came back as `x db`, a second refusal. Cut at a bare `--`: the fix appends its
|
|
100
|
+
* `--json` last, and behind a passthrough tail that switch would be the other tool's.
|
|
101
|
+
*/
|
|
102
|
+
export function typedWords(argv: readonly string[]): readonly string[] {
|
|
103
|
+
const words: string[] = [];
|
|
104
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
105
|
+
const word = argv[index] as string;
|
|
106
|
+
if (word === '--') break;
|
|
107
|
+
if (word === '--cwd') index += 1;
|
|
108
|
+
else if (word !== '--json' && word !== '-j' && !word.startsWith('--cwd=')) words.push(word);
|
|
109
|
+
}
|
|
110
|
+
return words;
|
|
111
|
+
}
|
|
112
|
+
|
|
96
113
|
export async function dispatch(options: DispatchOptions): Promise<number> {
|
|
97
114
|
const earlyReader = readerFor(options.cwd, options.invocation);
|
|
98
115
|
// Its own branch, ahead of the parse: an unsupported Bun is a fact about the environment and
|
|
@@ -155,6 +172,7 @@ export async function dispatch(options: DispatchOptions): Promise<number> {
|
|
|
155
172
|
env,
|
|
156
173
|
bunVersion: options.bunVersion,
|
|
157
174
|
...(options.invocation === undefined ? {} : { invocation: options.invocation }),
|
|
175
|
+
reader,
|
|
158
176
|
};
|
|
159
177
|
|
|
160
178
|
// Put back in the `finally`: the stream is process-wide, so a dispatch that left `stderr` behind
|
|
@@ -179,7 +197,9 @@ export async function dispatch(options: DispatchOptions): Promise<number> {
|
|
|
179
197
|
// (`env init`, `secrets set`) — but the DECLARATION is now what decides, ahead of any check a
|
|
180
198
|
// command makes about its own arguments. `--help` is exempt because `target` is then the help
|
|
181
199
|
// command, which declares nothing: usage for a command must be readable from anywhere.
|
|
182
|
-
if (target.spec.requiresApp === true)
|
|
200
|
+
if (target.spec.requiresApp === true) {
|
|
201
|
+
requireAppRoot(target.spec.name, ctx.cwd, typedWords(options.argv));
|
|
202
|
+
}
|
|
183
203
|
const result = await target.run(ctx);
|
|
184
204
|
sinkFor(result, options)(render(result, args.json, args.flags.get('verbose') === true, reader));
|
|
185
205
|
// `x dev` and `x mcp serve --transport http` are still listening here: report first, so the
|
|
@@ -79,6 +79,35 @@ async function lockPackages(root: string): Promise<Readonly<Record<string, unkno
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/** What `bun.lock` resolves for this row below its floor, lowest first. */
|
|
83
|
+
function versionsBelow(
|
|
84
|
+
packages: Readonly<Record<string, unknown>>,
|
|
85
|
+
row: AdvisoryFloor,
|
|
86
|
+
): readonly string[] {
|
|
87
|
+
// A git, tarball or `file:` head is no release on npm's line, so no advisory range reads it:
|
|
88
|
+
// skipped rather than ordered, because `Bun.semver.order` throws on it and would take every
|
|
89
|
+
// other `x doctor` check down with this warning.
|
|
90
|
+
return resolvedVersions(packages, row.name)
|
|
91
|
+
.filter((version) => RELEASE.test(version))
|
|
92
|
+
.filter((version) => Bun.semver.order(version, row.floor) < 0)
|
|
93
|
+
.sort((a, b) => Bun.semver.order(a, b));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The transitive packages `bun.lock` holds under a floor: `bun install` honours the lockfile, so
|
|
98
|
+
* `x upgrade` names these to `bun update`, and an upgraded app is not left to `x doctor`'s warning.
|
|
99
|
+
*/
|
|
100
|
+
export async function staleTransitiveFloors(
|
|
101
|
+
root: string,
|
|
102
|
+
floors: readonly AdvisoryFloor[] = ADVISORY_FLOORS,
|
|
103
|
+
): Promise<readonly string[]> {
|
|
104
|
+
const packages = await lockPackages(root);
|
|
105
|
+
if (packages === undefined) return [];
|
|
106
|
+
return floors
|
|
107
|
+
.filter((row) => row.via === 'transitive' && versionsBelow(packages, row).length > 0)
|
|
108
|
+
.map((row) => row.name);
|
|
109
|
+
}
|
|
110
|
+
|
|
82
111
|
/** One warning per floor the lockfile resolves under, lowest resolved version named. */
|
|
83
112
|
export async function advisoryFloorFindings(
|
|
84
113
|
root: string,
|
|
@@ -88,14 +117,7 @@ export async function advisoryFloorFindings(
|
|
|
88
117
|
if (packages === undefined) return [];
|
|
89
118
|
const transitive = floors.filter((f) => f.via === 'transitive').map((f) => quoteArg(f.name));
|
|
90
119
|
return floors.flatMap((row) => {
|
|
91
|
-
|
|
92
|
-
// skipped rather than ordered, because `Bun.semver.order` throws on it and would take every
|
|
93
|
-
// other `x doctor` check down with this warning.
|
|
94
|
-
const below = resolvedVersions(packages, row.name)
|
|
95
|
-
.filter((version) => RELEASE.test(version))
|
|
96
|
-
.filter((version) => Bun.semver.order(version, row.floor) < 0)
|
|
97
|
-
.sort((a, b) => Bun.semver.order(a, b));
|
|
98
|
-
const lowest = below[0];
|
|
120
|
+
const lowest = versionsBelow(packages, row)[0];
|
|
99
121
|
if (lowest === undefined) return [];
|
|
100
122
|
return [
|
|
101
123
|
{
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// `x doctor`'s warning for an action or query no `defineApi()` lists in an app whose `defineApi()`
|
|
2
|
+
// lists others: the scan still serves it (never refused), but the typed client's `Api` lacks it. An
|
|
3
|
+
// app that lists none registers by the scan alone, and is told nothing.
|
|
4
|
+
|
|
5
|
+
// why: Bun has no synchronous exists check and no path API; `posix` because the fix prints an
|
|
6
|
+
// import specifier on every OS.
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import { join, posix } from 'node:path';
|
|
9
|
+
import { isAction } from '@ultimat3/action';
|
|
10
|
+
import { isQuery } from '@ultimat3/query';
|
|
11
|
+
import { loadApp } from './app-load';
|
|
12
|
+
import { API_INDEX } from './app-root';
|
|
13
|
+
import type { Finding } from './output';
|
|
14
|
+
import { camel } from './templates/naming';
|
|
15
|
+
|
|
16
|
+
/** The load and the modules it imported — the seam a test drives without a scan. */
|
|
17
|
+
type ListingLoader = (
|
|
18
|
+
root: string,
|
|
19
|
+
) => Promise<{ readonly findings: readonly Finding[]; readonly files?: readonly string[] }>;
|
|
20
|
+
|
|
21
|
+
type ListKey = 'actions' | 'queries';
|
|
22
|
+
|
|
23
|
+
/** One primitive a module exports, under the name it serves by. */
|
|
24
|
+
interface Exported {
|
|
25
|
+
readonly key: ListKey;
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly file: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* What `defineApi()` returns: a frozen plain object, one name-keyed map per list. Read by shape,
|
|
32
|
+
* and only once it IS a plain object — an index also exports typed clients, whose property reads
|
|
33
|
+
* are a proxy's and build a transport (one threw X_ENV_MISSING for an unset APP_URL).
|
|
34
|
+
*/
|
|
35
|
+
const listedIn = (value: unknown, key: ListKey): readonly string[] => {
|
|
36
|
+
if (typeof value !== 'object' || value === null || !Object.isFrozen(value)) return [];
|
|
37
|
+
if (Object.getPrototypeOf(value) !== Object.prototype) return [];
|
|
38
|
+
const api = value as Readonly<Record<string, unknown>>;
|
|
39
|
+
if (!['actions', 'queries', 'jobs', 'tasks'].every((one) => Object.hasOwn(api, one))) return [];
|
|
40
|
+
const list = api[key];
|
|
41
|
+
return typeof list === 'object' && list !== null ? Object.keys(list) : [];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** `refund-ticket.ts` → `refundTicket`: the namespace the index binds, as `x g` names it. */
|
|
45
|
+
const aliasOf = (file: string): string => {
|
|
46
|
+
const alias = camel(posix.basename(file).replace(/\.tsx?$/, ''));
|
|
47
|
+
return /^[A-Za-z_]/.test(alias) ? alias : `module${alias}`;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** The import the API index needs, relative to it and without the extension. */
|
|
51
|
+
const importLine = (file: string, alias: string): string => {
|
|
52
|
+
const path = posix.relative(posix.dirname(API_INDEX), file).replace(/\.tsx?$/, '');
|
|
53
|
+
return `import * as ${alias} from '${path.startsWith('.') ? path : `./${path}`}';`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** Pure: one warning per exported primitive whose name no list carries. */
|
|
57
|
+
export function unlistedFinding(primitive: Exported): Finding {
|
|
58
|
+
const alias = aliasOf(primitive.file);
|
|
59
|
+
const kind = primitive.key === 'actions' ? 'action' : 'query';
|
|
60
|
+
return {
|
|
61
|
+
code: primitive.key === 'actions' ? 'X_ACTION_UNREGISTERED' : 'X_QUERY_UNREGISTERED',
|
|
62
|
+
cause: `${primitive.name} declared in ${primitive.file} is an ${kind} no defineApi() lists: the module scan still serves it and the manifest carries it, but the typed client's Api does not, and a ${kind === 'action' ? 'job' : 'module'} left off the same list is refused`,
|
|
63
|
+
fix: `${importLine(primitive.file, alias)} // in ${API_INDEX}, and ${alias} added to ${primitive.key}: [...] there — then x manifest`,
|
|
64
|
+
at: primitive.file,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Every action and query the loaded modules export, once each, first declaring file kept. */
|
|
69
|
+
async function exportedPrimitives(root: string, files: readonly string[]): Promise<Exported[]> {
|
|
70
|
+
const seen = new Set<unknown>();
|
|
71
|
+
const found: Exported[] = [];
|
|
72
|
+
for (const file of files) {
|
|
73
|
+
const module = (await import(join(root, file))) as Readonly<Record<string, unknown>>;
|
|
74
|
+
for (const [exportName, value] of Object.entries(module)) {
|
|
75
|
+
const key: ListKey | undefined = isAction(value)
|
|
76
|
+
? 'actions'
|
|
77
|
+
: isQuery(value)
|
|
78
|
+
? 'queries'
|
|
79
|
+
: undefined;
|
|
80
|
+
if (key === undefined || seen.has(value)) continue;
|
|
81
|
+
seen.add(value);
|
|
82
|
+
// The scan names a primitive after its export; one it never reached keeps `''`.
|
|
83
|
+
const name = (value as { readonly name: string }).name || exportName;
|
|
84
|
+
found.push({ key, name, file });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return found;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The warnings. Loads the app as every gate step does and says nothing when the load failed (a short
|
|
92
|
+
* registry is the load's finding) or there is no index (nothing to list into). What the index
|
|
93
|
+
* exports from `defineApi()` is the list; a module it imports from a package is listed there too.
|
|
94
|
+
*/
|
|
95
|
+
export async function unlistedPrimitiveFindings(
|
|
96
|
+
root: string,
|
|
97
|
+
load: ListingLoader = loadApp,
|
|
98
|
+
): Promise<readonly Finding[]> {
|
|
99
|
+
const app = await load(root);
|
|
100
|
+
if (app.findings.length > 0 || !existsSync(join(root, API_INDEX))) return [];
|
|
101
|
+
const index = (await import(join(root, API_INDEX))) as Readonly<Record<string, unknown>>;
|
|
102
|
+
const listed = { actions: new Set<string>(), queries: new Set<string>() };
|
|
103
|
+
for (const value of Object.values(index)) {
|
|
104
|
+
for (const key of ['actions', 'queries'] as const) {
|
|
105
|
+
for (const name of listedIn(value, key)) listed[key].add(name);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Inconsistency only: an app that lists nothing registers by the scan alone, a supported shape
|
|
109
|
+
// (dummy/social-media-clone), and every warning there would be noise about it.
|
|
110
|
+
if (listed.actions.size === 0 && listed.queries.size === 0) return [];
|
|
111
|
+
return (await exportedPrimitives(root, app.files ?? []))
|
|
112
|
+
.filter((primitive) => !listed[primitive.key].has(primitive.name))
|
|
113
|
+
.map(unlistedFinding);
|
|
114
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// One `x doctor` check that throws costs that check, never the report. The whole command used to
|
|
2
|
+
// die as `X_CLI_UNEXPECTED`, whose fix is `x doctor --json`: the diagnostic told you to run itself.
|
|
3
|
+
|
|
4
|
+
import { ERROR_DOCS_URL, renderThrowable } from '@ultimat3/core';
|
|
5
|
+
import type { Finding } from './output';
|
|
6
|
+
|
|
7
|
+
export const probeFailedFinding = (check: string, error: unknown): Finding => ({
|
|
8
|
+
code: 'X_DOCTOR_PROBE_FAILED',
|
|
9
|
+
cause: `the ${check} check could not run: ${renderThrowable(error)}`,
|
|
10
|
+
// `x manifest` loads the app the same way and names the module that fails.
|
|
11
|
+
fix: 'bunx x manifest --json',
|
|
12
|
+
docs: ERROR_DOCS_URL,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/** Runs `check`, recording a throw on `findings` as that check's own finding. */
|
|
16
|
+
export async function guardedCheck(
|
|
17
|
+
name: string,
|
|
18
|
+
findings: Finding[],
|
|
19
|
+
check: () => Promise<void>,
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
try {
|
|
22
|
+
await check();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
findings.push(probeFailedFinding(name, error));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A listing beside the verdict: its value, or `otherwise` with the failure on `warnings`. */
|
|
29
|
+
export async function guardedListing<T>(
|
|
30
|
+
name: string,
|
|
31
|
+
warnings: Finding[],
|
|
32
|
+
read: () => Promise<T>,
|
|
33
|
+
otherwise: T,
|
|
34
|
+
): Promise<T> {
|
|
35
|
+
try {
|
|
36
|
+
return await read();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
warnings.push(probeFailedFinding(name, error));
|
|
39
|
+
return otherwise;
|
|
40
|
+
}
|
|
41
|
+
}
|