@ultimat3/cli 31.48.0 → 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 +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-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/index.ts +4 -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-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/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-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 +6 -0
- package/src/messages.ts +54 -4
- 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 +2 -0
- package/src/retain-sweep.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-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-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 +54 -8
- 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 +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-shards.ts +114 -34
- 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 +2 -8
- package/src/verify-coverage-run.ts +4 -1
- 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/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/CI-Parallel-Gate.md +2 -1
- package/wiki/CLI-Reference.md +107 -40
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Client-Navigation.md +1 -1
- package/wiki/Configuration.md +10 -9
- 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 +1 -1
- package/wiki/I18n.md +5 -3
- package/wiki/Installation.md +12 -11
- package/wiki/Jobs-And-Workflows.md +24 -4
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/MCP-And-AI.md +8 -5
- package/wiki/Many-Agents.md +69 -2
- 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 +7 -4
- 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/Upgrading.md +37 -0
package/src/cmd-policy-spec.ts
CHANGED
|
@@ -6,8 +6,16 @@ import type { CommandSpec } from './parse';
|
|
|
6
6
|
export const policySpec: CommandSpec = {
|
|
7
7
|
name: 'policy',
|
|
8
8
|
summary: 'which clause decided a permission, and why',
|
|
9
|
-
usage:
|
|
9
|
+
usage: "x policy [list|explain <subject> [--input '<json>']] [--json]",
|
|
10
10
|
requiresApp: true,
|
|
11
11
|
subcommands: ['list', 'explain'],
|
|
12
12
|
defaultSubcommand: 'list',
|
|
13
|
+
flags: [
|
|
14
|
+
{
|
|
15
|
+
name: 'input',
|
|
16
|
+
type: 'string',
|
|
17
|
+
summary: "the request's input as JSON — what a predicate that reads input is decided on",
|
|
18
|
+
subcommands: ['explain'],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
13
21
|
};
|
package/src/cmd-policy.ts
CHANGED
|
@@ -7,11 +7,13 @@ import { loadApp } from './app-load';
|
|
|
7
7
|
import { requireAppRoot } from './app-root';
|
|
8
8
|
import { policySpec } from './cmd-policy-spec';
|
|
9
9
|
import type { CliCommand, CommandContext } from './command';
|
|
10
|
-
import { DeclarationUnknownError, MissingPositionalError } from './errors';
|
|
10
|
+
import { BadFlagError, DeclarationUnknownError, MissingPositionalError } from './errors';
|
|
11
11
|
import { msg } from './messages';
|
|
12
12
|
import type { CommandResult, Finding, JsonValue } from './output';
|
|
13
|
-
import type { DeclarationExplanation } from './policy-facts';
|
|
13
|
+
import type { DeclarationExplanation, ExplainOptions } from './policy-facts';
|
|
14
14
|
import { explainPolicy, knownPolicySubjects, listPolicy } from './policy-facts';
|
|
15
|
+
import type { ExplainVerdict } from './policy-row';
|
|
16
|
+
import { quoteArg } from './shell-quote';
|
|
15
17
|
import { renderTable } from './table';
|
|
16
18
|
|
|
17
19
|
/** A descriptor is plain JSON by construction — same idiom as `cmd-registries.ts`'s `asJson`. */
|
|
@@ -49,27 +51,68 @@ function runList(findings: readonly Finding[]): CommandResult {
|
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
const VERDICT_KEYS = {
|
|
55
|
+
allow: 'cli.policy.allow',
|
|
56
|
+
deny: 'cli.policy.deny',
|
|
57
|
+
'needs-input': 'cli.policy.needsInput',
|
|
58
|
+
} as const satisfies Record<ExplainVerdict, string>;
|
|
59
|
+
|
|
52
60
|
/** A header naming the declaration and its policy label, then the actor/verdict/deciding table. */
|
|
53
|
-
function declarationLines(
|
|
61
|
+
function declarationLines(
|
|
62
|
+
declaration: DeclarationExplanation,
|
|
63
|
+
withInput: boolean,
|
|
64
|
+
): readonly string[] {
|
|
54
65
|
const header = ` ${msg('cli.policy.declaration', {
|
|
55
66
|
kind: declaration.kind,
|
|
56
67
|
name: declaration.name,
|
|
57
68
|
label: declaration.label,
|
|
58
69
|
})}`;
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
if (!declaration.decidable) return [header, ` ${msg('cli.policy.
|
|
70
|
+
// Undecidable only on an input it was handed and threw on: the caveat instead of a table, never
|
|
71
|
+
// a synthetic deny dressed as one. With no input a predicate that reads one is a `needs input`
|
|
72
|
+
// row — "not decided", which a deny would misreport about an actor the request lets through.
|
|
73
|
+
if (!declaration.decidable) return [header, ` ${msg('cli.policy.undecidableInput')}`];
|
|
63
74
|
const rows = declaration.rows.map((row) => [
|
|
64
75
|
row.actor,
|
|
65
|
-
msg(row.
|
|
76
|
+
msg(VERDICT_KEYS[row.verdict]),
|
|
66
77
|
row.deciding ?? msg('cli.policy.none'),
|
|
67
78
|
row.reason ?? msg('cli.policy.none'),
|
|
68
79
|
]);
|
|
69
80
|
const table = renderTable(['actor', 'verdict', 'deciding', 'reason'], rows).map(
|
|
70
81
|
(line) => ` ${line}`,
|
|
71
82
|
);
|
|
72
|
-
return [
|
|
83
|
+
return [
|
|
84
|
+
header,
|
|
85
|
+
...table,
|
|
86
|
+
` ${msg(withInput ? 'cli.policy.withInput' : 'cli.policy.noInput')}`,
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* `--input '<json>'`: the request's input, for a predicate that reads one. Any JSON value — the
|
|
92
|
+
* action's own schema is not applied, because the question is what the POLICY decides on it.
|
|
93
|
+
*/
|
|
94
|
+
function readInput(ctx: CommandContext): ExplainOptions {
|
|
95
|
+
const raw = ctx.args.flags.get('input');
|
|
96
|
+
if (raw === undefined) return {};
|
|
97
|
+
if (typeof raw !== 'string') {
|
|
98
|
+
throw new BadFlagError({
|
|
99
|
+
flag: 'input',
|
|
100
|
+
command: 'policy explain',
|
|
101
|
+
reason: 'it takes the request input as one JSON argument',
|
|
102
|
+
fix: `x policy explain ${quoteArg(ctx.args.positionals)} --input '{}' --json`,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return { input: { value: JSON.parse(raw) as unknown } };
|
|
107
|
+
} catch {
|
|
108
|
+
throw new BadFlagError({
|
|
109
|
+
flag: 'input',
|
|
110
|
+
command: 'policy explain',
|
|
111
|
+
// The length, never the text: a request body pasted here may carry a credential.
|
|
112
|
+
reason: `its value (${raw.length} characters) is not JSON`,
|
|
113
|
+
fix: `x policy explain ${quoteArg(ctx.args.positionals)} --input '{"id":"<the request field>"}' --json`,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
73
116
|
}
|
|
74
117
|
|
|
75
118
|
function requireSubject(ctx: CommandContext): string {
|
|
@@ -89,7 +132,8 @@ function requireSubject(ctx: CommandContext): string {
|
|
|
89
132
|
|
|
90
133
|
function runExplain(ctx: CommandContext, findings: readonly Finding[]): CommandResult {
|
|
91
134
|
const name = requireSubject(ctx);
|
|
92
|
-
const
|
|
135
|
+
const options = readInput(ctx);
|
|
136
|
+
const explanation = explainPolicy(name, options);
|
|
93
137
|
if (explanation === undefined) {
|
|
94
138
|
const known = knownPolicySubjects();
|
|
95
139
|
const suggestion = nearestName(name, known);
|
|
@@ -102,21 +146,32 @@ function runExplain(ctx: CommandContext, findings: readonly Finding[]): CommandR
|
|
|
102
146
|
// One row per (declaration, actor) pair — a permission two declarations enforce evaluates every
|
|
103
147
|
// actor twice, so this counts evaluations and never roles.
|
|
104
148
|
const rows = explanation.declarations.flatMap((declaration) => declaration.rows);
|
|
105
|
-
const allowed = rows.filter((row) => row.
|
|
149
|
+
const allowed = rows.filter((row) => row.verdict === 'allow').length;
|
|
150
|
+
const pending = rows.filter((row) => row.verdict === 'needs-input').length;
|
|
151
|
+
const counts = { subject: explanation.subject, allowed, evaluations: rows.length };
|
|
152
|
+
const withInput = options.input !== undefined;
|
|
106
153
|
return {
|
|
107
154
|
ok: findings.length === 0,
|
|
108
155
|
command: 'policy',
|
|
109
|
-
summary:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
156
|
+
// The command to run next is in the summary: a count of "not decided" with no way to decide
|
|
157
|
+
// it is the dead end the bare "allowed for 0 of 3" was.
|
|
158
|
+
summary:
|
|
159
|
+
pending === 0
|
|
160
|
+
? msg('cli.policy.explained', counts)
|
|
161
|
+
: msg('cli.policy.explainedPending', {
|
|
162
|
+
...counts,
|
|
163
|
+
pending,
|
|
164
|
+
command: `x policy explain ${quoteArg([name])} --input '<the request input as JSON>'`,
|
|
165
|
+
}),
|
|
166
|
+
lines: explanation.declarations.flatMap((declaration) =>
|
|
167
|
+
declarationLines(declaration, withInput),
|
|
168
|
+
),
|
|
115
169
|
findings,
|
|
116
170
|
data: asJson({
|
|
117
171
|
subject: explanation.subject,
|
|
118
172
|
kind: explanation.kind,
|
|
119
173
|
grantingRoles: explanation.grantingRoles,
|
|
174
|
+
pending,
|
|
120
175
|
declarations: explanation.declarations.map((declaration) => asJson(declaration)),
|
|
121
176
|
}),
|
|
122
177
|
};
|
package/src/cmd-stop.ts
CHANGED
|
@@ -7,7 +7,15 @@ import { parseDuration } from '@ultimat3/time';
|
|
|
7
7
|
import { requireAppRoot } from './app-root';
|
|
8
8
|
import { stopSpec } from './cmd-stop-spec';
|
|
9
9
|
import type { CliCommand, CommandContext } from './command';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
clearLock,
|
|
12
|
+
clearStaleLock,
|
|
13
|
+
isProcessAlive,
|
|
14
|
+
liveDevLock,
|
|
15
|
+
lockPath,
|
|
16
|
+
parseLock,
|
|
17
|
+
reusedPid,
|
|
18
|
+
} from './dev-lock';
|
|
11
19
|
import { BadFlagError } from './errors';
|
|
12
20
|
import { MIN_RELEASE_MS } from './hold';
|
|
13
21
|
import { msg } from './messages';
|
|
@@ -96,15 +104,21 @@ const lockNames = async (stateDir: string, pid: number): Promise<boolean> => {
|
|
|
96
104
|
* Signal the lock's holder and wait for both facts the next boot reads: the pid gone and the lock
|
|
97
105
|
* no longer naming it. A dead pid whose lock survived was terminated without a drain (Windows, or a
|
|
98
106
|
* crash mid-drain), and its lock is cleared here so `x stop` returning means `x dev` boots.
|
|
99
|
-
* No live holder is not a failure: a
|
|
107
|
+
* No live holder is not a failure: a lock naming a dead pid is left for `preflight`'s clear, and
|
|
108
|
+
* one naming a pid the kernel reused is cleared here, with nothing signalled.
|
|
100
109
|
*/
|
|
101
110
|
export async function stopDev(input: StopInput): Promise<StopResult> {
|
|
102
111
|
const alive = input.alive ?? isProcessAlive;
|
|
103
112
|
const lock = liveDevLock(input.stateDir);
|
|
104
113
|
if (lock === undefined || !alive(lock.pid)) return { stopped: false };
|
|
105
114
|
// A pid alone is not the holder: a kill -9 leaves the lock and the kernel reuses the number.
|
|
106
|
-
// Nothing is signalled
|
|
107
|
-
|
|
115
|
+
// Nothing is signalled. The lock is cleared, under `preflight`'s own guard and only while it
|
|
116
|
+
// still holds the bytes judged here (`stealStale`): `x stop` returning means nothing holds the
|
|
117
|
+
// directory, and a lock left behind kept answering "stale" until the next `x dev`.
|
|
118
|
+
if (await reusedPid(lock)) {
|
|
119
|
+
clearStaleLock(input.stateDir, lock);
|
|
120
|
+
return { stopped: false, stale: true };
|
|
121
|
+
}
|
|
108
122
|
const windows = (input.platform ?? process.platform) === 'win32';
|
|
109
123
|
const started = performance.now();
|
|
110
124
|
signal(lock.pid, input.kill ?? ((pid: number) => process.kill(pid, 'SIGTERM')));
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// `x tasks run <name>`: fire a scheduled task now — the jobs its occurrence enqueues, onto the
|
|
2
|
+
// app's queue — so a cron job is exercised in dev without waiting for its cron or editing it.
|
|
3
|
+
// Through the task's own manual-run path (`TaskHandle.enqueue`), the one the admin's run-now uses.
|
|
4
|
+
|
|
5
|
+
import { isProduction, UltimateError } from '@ultimat3/core';
|
|
6
|
+
import type { TaskHandle } from '@ultimat3/jobs';
|
|
7
|
+
import type { CommandContext } from './command';
|
|
8
|
+
import { refuseEmbeddedWriteBesideDev } from './dev-lock-live';
|
|
9
|
+
import { withJobDriver } from './jobs-driver';
|
|
10
|
+
import { msg } from './messages';
|
|
11
|
+
import type { CommandResult, Finding, JsonValue } from './output';
|
|
12
|
+
import { flagBool } from './parse';
|
|
13
|
+
import { quoteArg } from './shell-quote';
|
|
14
|
+
|
|
15
|
+
/** The container's half of the consent: the task this deploy fires, named, as a fixed argv can. */
|
|
16
|
+
export const TASK_RUN_ENV = 'ULTIMATE_TASK_RUN';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Does this environment fire only when asked by name? `x db seed`'s production gate, mirrored: the
|
|
20
|
+
* same predicate (`ULTIMATE_ENV` resolved `production`; staging runs unasked, as a `dev` seed does;
|
|
21
|
+
* an `ULTIMATE_ENV` that is no environment refuses with `X_ENVIRONMENT_INVALID`), and consent is
|
|
22
|
+
* named — `--production` on the command line, or `ULTIMATE_TASK_RUN=<name>` for a container whose
|
|
23
|
+
* command line is fixed, as `--tier` and `ULTIMATE_SEED_TIER` are. Pinned against `seedTiersFor`.
|
|
24
|
+
*/
|
|
25
|
+
export const tasksRunNeedsFlag = (env: Readonly<Record<string, string | undefined>>): boolean =>
|
|
26
|
+
isProduction({ env });
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* `X_SEED_ENVIRONMENT`'s form: its own code, not `X_CLI_BAD_FLAG` — the argv was well formed and
|
|
30
|
+
* the answer is still no. The env var is in the cause, the one pasteable flag line is the fix.
|
|
31
|
+
*/
|
|
32
|
+
export class TaskRunProductionError extends UltimateError {
|
|
33
|
+
constructor(name: string) {
|
|
34
|
+
super({
|
|
35
|
+
code: 'X_TASK_RUN_PRODUCTION',
|
|
36
|
+
cause: `ULTIMATE_ENV resolved production, where firing ${name} enqueues real work beside its next scheduled occurrence — x tasks run fires there only when asked by name; ${TASK_RUN_ENV}=${name} says this deploy takes it`,
|
|
37
|
+
fix: `x tasks run ${quoteArg(name)} --production --json`,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Production fires only when asked. Not a scheduled occurrence: the scheduler's watermark is never
|
|
44
|
+
* moved, so the next real tick still fires — a manual run in production is real work twice.
|
|
45
|
+
*/
|
|
46
|
+
function refuseUnaskedProduction(ctx: CommandContext, name: string): void {
|
|
47
|
+
if (flagBool(ctx.args, 'production') || ctx.env[TASK_RUN_ENV] === name) return;
|
|
48
|
+
if (!tasksRunNeedsFlag(ctx.env)) return;
|
|
49
|
+
throw new TaskRunProductionError(name);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** One job a fire enqueued, as `TaskHandle.enqueue` answers it (`@ultimat3/jobs` exports no name). */
|
|
53
|
+
type Fired = Awaited<ReturnType<TaskHandle['enqueue']>>[number];
|
|
54
|
+
|
|
55
|
+
const asJson = (fired: Fired): JsonValue => ({
|
|
56
|
+
job: fired.job,
|
|
57
|
+
id: fired.result.id,
|
|
58
|
+
runId: fired.result.runId,
|
|
59
|
+
deduped: fired.result.deduped,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* `handle` is already resolved (a typo is refused before any queue opens). Beside an `x dev`
|
|
64
|
+
* holding the embedded database this is a second writer, refused with the stop-run-restart fix.
|
|
65
|
+
*/
|
|
66
|
+
export async function runTask(
|
|
67
|
+
root: string,
|
|
68
|
+
ctx: CommandContext,
|
|
69
|
+
handle: TaskHandle,
|
|
70
|
+
findings: readonly Finding[],
|
|
71
|
+
): Promise<CommandResult> {
|
|
72
|
+
refuseUnaskedProduction(ctx, handle.name);
|
|
73
|
+
await refuseEmbeddedWriteBesideDev(root, ctx.env, ['tasks', 'run', handle.name]);
|
|
74
|
+
return withJobDriver(root, ctx, async () => {
|
|
75
|
+
const fired = await handle.enqueue();
|
|
76
|
+
return {
|
|
77
|
+
ok: findings.length === 0,
|
|
78
|
+
command: 'tasks',
|
|
79
|
+
summary: msg('cli.tasks.ran', { name: handle.name, count: fired.length }),
|
|
80
|
+
lines: fired.map(
|
|
81
|
+
(one) => ` ${one.job} ${one.result.id}${one.result.deduped ? ' (deduped)' : ''}`,
|
|
82
|
+
),
|
|
83
|
+
findings,
|
|
84
|
+
data: { task: handle.name, jobs: fired.map(asJson) },
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
package/src/cmd-tasks-spec.ts
CHANGED
|
@@ -5,10 +5,10 @@ import type { CommandSpec } from './parse';
|
|
|
5
5
|
|
|
6
6
|
export const tasksSpec: CommandSpec = {
|
|
7
7
|
name: 'tasks',
|
|
8
|
-
summary: 'cron tasks, their timezone and their next run',
|
|
9
|
-
usage: 'x tasks [list|show <name>] [--count n] [--json]',
|
|
8
|
+
summary: 'cron tasks, their timezone and their next run; fire one now',
|
|
9
|
+
usage: 'x tasks [list|show <name>|run <name>] [--count n] [--production] [--json]',
|
|
10
10
|
requiresApp: true,
|
|
11
|
-
subcommands: ['list', 'show'],
|
|
11
|
+
subcommands: ['list', 'show', 'run'],
|
|
12
12
|
defaultSubcommand: 'list',
|
|
13
13
|
flags: [
|
|
14
14
|
{
|
|
@@ -17,5 +17,12 @@ export const tasksSpec: CommandSpec = {
|
|
|
17
17
|
summary: 'show: how many upcoming occurrences to list',
|
|
18
18
|
subcommands: ['show'],
|
|
19
19
|
},
|
|
20
|
+
{
|
|
21
|
+
name: 'production',
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
summary:
|
|
24
|
+
'run: fire it where ULTIMATE_ENV resolves production — real work, asked for by name; also ULTIMATE_TASK_RUN=<name>',
|
|
25
|
+
subcommands: ['run'],
|
|
26
|
+
},
|
|
20
27
|
],
|
|
21
28
|
};
|
package/src/cmd-tasks.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// `x tasks [list|show <name>]` — introspect scheduled cron tasks: cadence, timezone,
|
|
2
|
-
// jobs, last dispatch and real next occurrences
|
|
1
|
+
// `x tasks [list|show <name>|run <name>]` — introspect scheduled cron tasks: cadence, timezone,
|
|
2
|
+
// enqueued jobs, last dispatch and real next occurrences; `run` fires one now (`cmd-tasks-run.ts`).
|
|
3
|
+
// CLI wiring only (`tasks-facts.ts`).
|
|
3
4
|
//
|
|
4
5
|
// The last dispatch is read off the queue's own record, and the next occurrences are real instants
|
|
5
6
|
// from `@ultimat3/time`'s cron math instead of an agent reading `0 3 * * *` and guessing. The
|
|
@@ -12,6 +13,7 @@ import type { CronPhrases } from '@ultimat3/time';
|
|
|
12
13
|
import { fromEpochMs, isoInZone } from '@ultimat3/time';
|
|
13
14
|
import { loadApp } from './app-load';
|
|
14
15
|
import { requireAppRoot } from './app-root';
|
|
16
|
+
import { runTask } from './cmd-tasks-run';
|
|
15
17
|
import { tasksSpec } from './cmd-tasks-spec';
|
|
16
18
|
import type { CliCommand, CommandContext } from './command';
|
|
17
19
|
import { BadFlagError, DeclarationUnknownError } from './errors';
|
|
@@ -125,15 +127,15 @@ function runList(
|
|
|
125
127
|
};
|
|
126
128
|
}
|
|
127
129
|
|
|
128
|
-
/** Resolves the `show <name>` positional to a handle, or throws — the two failure paths
|
|
129
|
-
*
|
|
130
|
+
/** Resolves the `show|run <name>` positional to a handle, or throws — the two failure paths: no
|
|
131
|
+
* positional at all, and a positional that names no registered task. */
|
|
130
132
|
function requireHandle(ctx: CommandContext): TaskHandle {
|
|
131
133
|
const name = ctx.args.positionals[0];
|
|
132
134
|
if (name === undefined) {
|
|
133
135
|
throw new BadFlagError({
|
|
134
136
|
flag: 'name',
|
|
135
137
|
command: 'tasks',
|
|
136
|
-
reason:
|
|
138
|
+
reason: `x tasks ${ctx.args.subcommand ?? 'show'} <name> needs a task name`,
|
|
137
139
|
fix: 'x tasks list --json',
|
|
138
140
|
});
|
|
139
141
|
}
|
|
@@ -194,6 +196,7 @@ export const tasksCommand: CliCommand = {
|
|
|
194
196
|
const root = requireAppRoot('tasks', ctx.cwd).dir;
|
|
195
197
|
const { findings } = await loadApp(root);
|
|
196
198
|
const nowMs = systemClock.now().getTime();
|
|
199
|
+
if (ctx.args.subcommand === 'run') return runTask(root, ctx, requireHandle(ctx), findings);
|
|
197
200
|
// Everything argv can get wrong is refused BEFORE the queue is opened: a typo in a task name
|
|
198
201
|
// must not cost a database boot to be told about.
|
|
199
202
|
const shown =
|
package/src/cmd-test.ts
CHANGED
|
@@ -16,7 +16,8 @@ import { appTestScope, narrowToApp } from './affected-tests';
|
|
|
16
16
|
import { testSpec } from './cmd-test-spec';
|
|
17
17
|
import type { CliCommand, CommandContext } from './command';
|
|
18
18
|
import { ok } from './command';
|
|
19
|
-
import { BadFlagError
|
|
19
|
+
import { BadFlagError } from './errors';
|
|
20
|
+
import { NoTestFilesError } from './errors-suite';
|
|
20
21
|
import type { Runner } from './exec';
|
|
21
22
|
import { readIntFlag } from './flag-number';
|
|
22
23
|
import { FREE_RUN_FILES } from './heavy-weights';
|
package/src/cmd-upgrade-spec.ts
CHANGED
|
@@ -11,7 +11,7 @@ export const upgradeSpec: CommandSpec = {
|
|
|
11
11
|
summary:
|
|
12
12
|
'move every @ultimat3/* one major in lockstep, raise the Bun floor, install, apply codemods, gate — and name the section to read',
|
|
13
13
|
usage:
|
|
14
|
-
'x upgrade [--to <version>] [--dry-run] [--json] · x upgrade codemods --from <version> [--to <version>] [--dry-run] [--json]',
|
|
14
|
+
'x upgrade [--to <version>] [--only <step>[,<step>…]] [--dry-run] [--json] · x upgrade codemods --from <version> [--to <version>] [--dry-run] [--json]',
|
|
15
15
|
// The one command a repository with pins and no `app.config.ts` can still use: `upgrade-root.ts`
|
|
16
16
|
// finds its root, and its report says which check it could run. `codemods` needs the app.
|
|
17
17
|
subcommands: UPGRADE_SUBCOMMANDS,
|
|
@@ -30,6 +30,13 @@ export const upgradeSpec: CommandSpec = {
|
|
|
30
30
|
summary:
|
|
31
31
|
'the release the app came from: the codemods whose version lies after it, up to --to, run',
|
|
32
32
|
},
|
|
33
|
+
{
|
|
34
|
+
name: 'only',
|
|
35
|
+
type: 'string',
|
|
36
|
+
subcommands: ['run'],
|
|
37
|
+
summary:
|
|
38
|
+
"the hop's x verify runs only the named step(s), comma-separated, as x verify --only does — NOT THE FULL GATE: data.verify.notRun names the rest, for CI to run (default: the full gate)",
|
|
39
|
+
},
|
|
33
40
|
{
|
|
34
41
|
name: 'dry-run',
|
|
35
42
|
type: 'boolean',
|
package/src/cmd-upgrade.ts
CHANGED
|
@@ -35,6 +35,8 @@ import { publishedVersions, releaseBunRange } from './upgrade-registry';
|
|
|
35
35
|
import type { PlannedWrites } from './upgrade-report';
|
|
36
36
|
import { humanLines, NO_WRITES, report, thenLine } from './upgrade-report';
|
|
37
37
|
import { findUpgradeRoot } from './upgrade-root';
|
|
38
|
+
import type { GateScope } from './upgrade-scope';
|
|
39
|
+
import { readScope } from './upgrade-scope';
|
|
38
40
|
import { stopChildrenOnSignal, tagRunner, upgradeTag } from './upgrade-signals';
|
|
39
41
|
import type { UnfinishedHop } from './upgrade-unfinished';
|
|
40
42
|
import { clearUnfinished, readUnfinished, writeUnfinished } from './upgrade-unfinished';
|
|
@@ -170,6 +172,7 @@ export const createUpgradeCommand = (
|
|
|
170
172
|
root: string,
|
|
171
173
|
app: boolean,
|
|
172
174
|
to: string | undefined,
|
|
175
|
+
scope: GateScope | undefined,
|
|
173
176
|
): Promise<CommandResult> {
|
|
174
177
|
const dryRun = flagBool(ctx.args, 'dry-run');
|
|
175
178
|
const unfinished = await readUnfinished(root);
|
|
@@ -321,6 +324,7 @@ export const createUpgradeCommand = (
|
|
|
321
324
|
onStage: stageReached,
|
|
322
325
|
codemods: { from: resume === undefined ? hop.from : EVERY_RELEASE, to: hop.to },
|
|
323
326
|
...(bunMoved === undefined ? {} : { bunMoved }),
|
|
327
|
+
...(scope === undefined ? {} : { only: scope }),
|
|
324
328
|
});
|
|
325
329
|
return { gate: hopGate, scripts: [] };
|
|
326
330
|
});
|
|
@@ -339,6 +343,15 @@ export const createUpgradeCommand = (
|
|
|
339
343
|
};
|
|
340
344
|
const span = { from: hop.from, to: hop.to };
|
|
341
345
|
if (gate !== undefined) {
|
|
346
|
+
const notRun = gate.verify.notRun ?? [];
|
|
347
|
+
if (done && notRun.length > 0) {
|
|
348
|
+
const scoped = {
|
|
349
|
+
...span,
|
|
350
|
+
only: (gate.verify.only ?? []).join(','),
|
|
351
|
+
notRun: notRun.join(','),
|
|
352
|
+
};
|
|
353
|
+
return ok('upgrade', msg('cli.upgrade.doneScoped', scoped), extra);
|
|
354
|
+
}
|
|
342
355
|
return done
|
|
343
356
|
? ok('upgrade', msg('cli.upgrade.done', span), extra)
|
|
344
357
|
: failed(
|
|
@@ -363,6 +376,7 @@ export const createUpgradeCommand = (
|
|
|
363
376
|
if (ctx.args.subcommand === 'codemods') return runUpgradeCodemods(ctx);
|
|
364
377
|
const { dir: root, app } = await findUpgradeRoot(ctx.cwd);
|
|
365
378
|
const to = readTarget(ctx);
|
|
379
|
+
const scope = readScope(ctx, app);
|
|
366
380
|
// One hop per app at a time, and a stopped hop stops its children: every spawn below is
|
|
367
381
|
// tagged, and SIGINT/SIGTERM kill that tree and release the lock before the signal lands.
|
|
368
382
|
const release = await acquireUpgradeLock(root);
|
|
@@ -371,7 +385,7 @@ export const createUpgradeCommand = (
|
|
|
371
385
|
const undoSignals = stopChildrenOnSignal({ tag, pids, cleanup: release });
|
|
372
386
|
try {
|
|
373
387
|
const runner = tagRunner(ctx.runner, tag, ctx.env, pids);
|
|
374
|
-
return await runHop({ ...ctx, runner }, root, app, to);
|
|
388
|
+
return await runHop({ ...ctx, runner }, root, app, to, scope);
|
|
375
389
|
} finally {
|
|
376
390
|
undoSignals();
|
|
377
391
|
release();
|
package/src/cmd-verify.ts
CHANGED
|
@@ -10,11 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
// why: Bun ships no path-joining primitive: `join`/`isAbsolute` resolve a part path against the cwd.
|
|
12
12
|
import { isAbsolute, join } from 'node:path';
|
|
13
|
-
import { nearestName, renderFixShellArg } from '@ultimat3/core';
|
|
14
13
|
import { requireAppRoot } from './app-root';
|
|
15
14
|
import { verifySpec } from './cmd-verify-spec';
|
|
16
15
|
import type { CliCommand, CommandContext } from './command';
|
|
17
|
-
import {
|
|
16
|
+
import { MissingPositionalError } from './errors';
|
|
18
17
|
import { readIntFlag } from './flag-number';
|
|
19
18
|
import type { CommandResult, JsonValue } from './output';
|
|
20
19
|
import type { ParsedArgs } from './parse';
|
|
@@ -25,6 +24,7 @@ import { VERIFY_STEPS } from './verify-checks';
|
|
|
25
24
|
import { readVerifyFloor } from './verify-floor';
|
|
26
25
|
import type { VerifyPart } from './verify-merge';
|
|
27
26
|
import { coverageRiders, mergeParts, parsePart, VerifyMergeInputError } from './verify-merge';
|
|
27
|
+
import { readStepList } from './verify-only';
|
|
28
28
|
import { measurePace } from './verify-pace';
|
|
29
29
|
import { verifyPlanCommand } from './verify-plan';
|
|
30
30
|
import { withVerifyProgress } from './verify-progress';
|
|
@@ -82,7 +82,10 @@ export const verifyCommand: CliCommand = {
|
|
|
82
82
|
...progress,
|
|
83
83
|
}),
|
|
84
84
|
// A line per step a person reads, JSON only for the `--json` reader that parses stderr.
|
|
85
|
-
{
|
|
85
|
+
{
|
|
86
|
+
render: ctx.args.json ? 'json' : 'human',
|
|
87
|
+
...(ctx.reader === undefined ? {} : { reader: ctx.reader }),
|
|
88
|
+
},
|
|
86
89
|
);
|
|
87
90
|
const sharded = shard === undefined ? result : withShardData(result, shard);
|
|
88
91
|
return changed === undefined ? sharded : withChangedData(sharded, changed);
|
|
@@ -154,44 +157,9 @@ async function mergeCommand(
|
|
|
154
157
|
});
|
|
155
158
|
}
|
|
156
159
|
|
|
157
|
-
/**
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
* order they were typed in. Refused against `VERIFY_STEP_NAMES` — the same constant the runner's
|
|
161
|
-
* list is built from — so a typo can never be read as "narrow to no steps at all", which is a run
|
|
162
|
-
* that passes by checking nothing. An empty item (`lint,,drift`, a trailing comma) is refused for
|
|
163
|
-
* the same reason.
|
|
164
|
-
*
|
|
165
|
-
* A near miss leads with the list as it would be with each typo corrected; an item near NOTHING
|
|
166
|
-
* gets the gate itself rather than an invented lead, which is the rule `parse.ts` already follows
|
|
167
|
-
* for a command that resembles none. Both arms are commands that run.
|
|
168
|
-
*/
|
|
169
|
-
export const readOnlySteps = (args: ParsedArgs): readonly VerifyStepName[] | undefined => {
|
|
170
|
-
const raw = flagString(args, 'only');
|
|
171
|
-
if (raw === undefined) return undefined;
|
|
172
|
-
const items = raw.split(',').map((item) => item.trim());
|
|
173
|
-
const unknown = items.filter((item) => !isStepName(item));
|
|
174
|
-
if (unknown.length === 0) {
|
|
175
|
-
return VERIFY_STEP_NAMES.filter((name) => items.includes(name));
|
|
176
|
-
}
|
|
177
|
-
// An empty item corrects to nothing — never to whichever step is nearest to ''.
|
|
178
|
-
const corrected = items.map((item) =>
|
|
179
|
-
isStepName(item) ? item : item === '' ? undefined : nearestName(item, VERIFY_STEP_NAMES),
|
|
180
|
-
);
|
|
181
|
-
const fix = corrected.every((item) => item !== undefined)
|
|
182
|
-
? `x verify --only ${renderFixShellArg([...new Set(corrected)].join(','), '<step,step>')} --json`
|
|
183
|
-
: 'x verify --json';
|
|
184
|
-
const named = unknown.map((item) => (item === '' ? '(empty)' : `"${item}"`)).join(', ');
|
|
185
|
-
throw new BadFlagError({
|
|
186
|
-
flag: 'only',
|
|
187
|
-
command: 'verify',
|
|
188
|
-
reason: `${named} ${unknown.length === 1 ? 'is not a gate step' : 'are not gate steps'} (${VERIFY_STEP_NAMES.join(', ')})`,
|
|
189
|
-
fix,
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const isStepName = (raw: string): raw is VerifyStepName =>
|
|
194
|
-
(VERIFY_STEP_NAMES as readonly string[]).includes(raw);
|
|
160
|
+
/** `--only`'s list, read by `verify-only.ts` — the one reader `x upgrade --only` shares. */
|
|
161
|
+
export const readOnlySteps = (args: ParsedArgs): readonly VerifyStepName[] | undefined =>
|
|
162
|
+
readStepList(args, 'verify');
|
|
195
163
|
|
|
196
164
|
/**
|
|
197
165
|
* Both bounds are the constants the flag summary already names, so `x help verify` and the reader
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// One row of an app's agent brief, changed by a codemod: found in CLAUDE.md or AGENTS.md, held to
|
|
2
|
+
// the byte budget the manifest step enforces, and reported as a skip with the row itself whenever
|
|
3
|
+
// it cannot be placed. A silent `changed: []` left the row owed with nobody told.
|
|
4
|
+
|
|
5
|
+
import { AGENTS_MD_MAX_BYTES } from '@ultimat3/manifest';
|
|
6
|
+
import { parseVerifyFloor, VERIFY_FLOOR_FILE } from '../verify-floor';
|
|
7
|
+
import type { CodemodApp, CodemodResult } from './codemod';
|
|
8
|
+
import { readText } from './engine-edits';
|
|
9
|
+
|
|
10
|
+
/** Where an app keeps its brief: the scaffold writes CLAUDE.md, and some apps moved it. */
|
|
11
|
+
const BRIEFS = ['CLAUDE.md', 'AGENTS.md'] as const;
|
|
12
|
+
|
|
13
|
+
export interface AgentsDocRow {
|
|
14
|
+
/** The text the row is placed against, and what it becomes: an insert or a swap. */
|
|
15
|
+
readonly from: string;
|
|
16
|
+
readonly to: string;
|
|
17
|
+
/** The row a person adds when it cannot be placed. */
|
|
18
|
+
readonly row: string;
|
|
19
|
+
/** Already said, in the app's own words or the template's: nothing to do. */
|
|
20
|
+
readonly said: (text: string) => boolean;
|
|
21
|
+
/** Why `from` is missing, in the skip a person reads. */
|
|
22
|
+
readonly missing: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** `x.verify.json`'s `agentsMdMaxBytes`, else the manifest's default: the one the gate holds. */
|
|
26
|
+
async function budgetOf(app: CodemodApp): Promise<number> {
|
|
27
|
+
const floor = await app.read(VERIFY_FLOOR_FILE);
|
|
28
|
+
if (floor === undefined) return AGENTS_MD_MAX_BYTES;
|
|
29
|
+
try {
|
|
30
|
+
return parseVerifyFloor(floor).agentsMdMaxBytes ?? AGENTS_MD_MAX_BYTES;
|
|
31
|
+
} catch {
|
|
32
|
+
// An unreadable floor is the gate's own finding (`floorProblemFindings`); the default stands.
|
|
33
|
+
return AGENTS_MD_MAX_BYTES;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const skip = (path: string, reason: string): CodemodResult => ({
|
|
38
|
+
changed: [],
|
|
39
|
+
skipped: [{ path, reason }],
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export async function editAgentsDocRow(
|
|
43
|
+
app: CodemodApp,
|
|
44
|
+
edit: AgentsDocRow,
|
|
45
|
+
): Promise<CodemodResult> {
|
|
46
|
+
const briefs: { path: string; text: string; restore: (text: string) => string }[] = [];
|
|
47
|
+
for (const path of BRIEFS) {
|
|
48
|
+
const file = await readText(app, path);
|
|
49
|
+
if (file !== undefined) briefs.push({ path, ...file });
|
|
50
|
+
}
|
|
51
|
+
if (briefs.length === 0 || briefs.some((brief) => edit.said(brief.text))) {
|
|
52
|
+
return { changed: [], skipped: [] };
|
|
53
|
+
}
|
|
54
|
+
const target = briefs.find((brief) => brief.text.split(edit.from).length === 2);
|
|
55
|
+
if (target === undefined) {
|
|
56
|
+
const path = briefs[0]?.path ?? BRIEFS[0];
|
|
57
|
+
return skip(
|
|
58
|
+
path,
|
|
59
|
+
`${edit.missing}; add this row to the conventions table by hand: ${edit.row}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const next = target.text.replace(edit.from, () => edit.to);
|
|
63
|
+
const bytes = Buffer.byteLength(target.restore(next), 'utf8');
|
|
64
|
+
const budget = await budgetOf(app);
|
|
65
|
+
if (bytes > budget) {
|
|
66
|
+
return skip(
|
|
67
|
+
target.path,
|
|
68
|
+
`the row would take ${target.path} to ${String(bytes)} bytes, over its ${String(budget)}-byte budget (${VERIFY_FLOOR_FILE} agentsMdMaxBytes); make room, then add this row by hand: ${edit.row}`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
await app.write(target.path, target.restore(next));
|
|
72
|
+
return { changed: [target.path], skipped: [] };
|
|
73
|
+
}
|