@ultimat3/cli 31.36.0 → 31.38.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 +1 -1
- package/package.json +29 -29
- package/src/cmd-planned.ts +5 -28
- package/src/generate-sign-in-runtime.ts +70 -0
- package/src/generate-sign-in.ts +19 -6
- package/src/generate-write.ts +12 -0
- package/src/island-plugin-path.ts +35 -0
- package/src/island-realtime.ts +11 -8
- package/src/island-runtime.ts +4 -1
- package/src/new-shapes.ts +10 -1
- package/src/templates/shapes/agent-actions.ts +224 -0
- package/src/templates/shapes/agent-job.ts +171 -0
- package/src/templates/shapes/agent-model.ts +271 -0
- package/src/templates/shapes/agent-prompt.ts +254 -0
- package/src/templates/shapes/agent-scripted.ts +56 -0
- package/src/templates/shapes/agent.ts +138 -0
- package/src/templates/shapes/content-admin-es.ts +95 -0
- package/src/templates/shapes/content-pages.ts +221 -0
- package/src/templates/shapes/content-site.ts +343 -0
- package/src/templates/shapes/content.ts +133 -0
- package/src/templates/shapes/index.ts +10 -0
- package/src/templates/shapes/offline-e2e.ts +123 -0
- package/src/templates/shapes/offline-form.ts +334 -0
- package/src/templates/shapes/offline.ts +118 -0
- package/src/templates/shapes/realtime-mutator.ts +136 -0
- package/src/templates/shapes/realtime-nodes.ts +203 -0
- package/src/templates/shapes/realtime-slice.ts +166 -0
- package/src/templates/shapes/realtime.ts +162 -0
- package/src/templates/shapes/saas-billing-tests.ts +135 -0
- package/src/templates/shapes/saas-billing.ts +137 -0
- package/src/templates/shapes/saas-receiver.ts +136 -0
- package/src/templates/shapes/saas.ts +112 -0
- package/src/templates/sign-in-oidc.ts +2 -4
- package/src/templates/sign-in-runtime.ts +172 -0
- package/src/templates/sign-in-shared.ts +5 -36
- package/wiki/Building-Your-Own-Base.md +339 -0
- package/wiki/CI-Parallel-Gate.md +18 -8
- package/wiki/CLI-Reference.md +4 -15
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Entities-And-Migrations.md +2 -2
- package/wiki/Known-Gaps.md +8 -2
- package/wiki/MCP-And-AI.md +3 -3
- package/wiki/Money.md +1 -1
- package/wiki/Shapes.md +18 -9
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/Upgrading.md +1 -1
package/CLAUDE.md
CHANGED
|
@@ -88,7 +88,7 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
88
88
|
| `job-budget.ts` | `X_JOB_OUTLASTS_DRAIN` (`manifest`): `timeout` vs `workerBudgetMs(drain)`, from the registry † |
|
|
89
89
|
| `output-findings.ts` | render layer only: `runnableFix` (`bunx x`, decided by `dispatch.ts`'s `readerFor`) and `collapseFindings`. Throw sites keep `x …` |
|
|
90
90
|
| `app-load-unresolved.ts` | `X_APP_IMPORT_UNRESOLVED`, read by the scan, `findingFrom` and `x doctor`'s `snapshots` probe |
|
|
91
|
-
| `fix-truth
|
|
91
|
+
| `fix-truth*.ts` / `db-fix-truth.job.test.ts` | a printed fix, executed against a broken scaffold † |
|
|
92
92
|
|
|
93
93
|
### Generators (`x g`, `x new`)
|
|
94
94
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.38.0",
|
|
4
4
|
"description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -53,34 +53,34 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/core": "^8.0.10",
|
|
56
|
-
"@ultimat3/action": "31.
|
|
57
|
-
"@ultimat3/admin": "31.
|
|
58
|
-
"@ultimat3/ai": "31.
|
|
59
|
-
"@ultimat3/auth": "31.
|
|
60
|
-
"@ultimat3/cache": "31.
|
|
61
|
-
"@ultimat3/core": "31.
|
|
62
|
-
"@ultimat3/db": "31.
|
|
63
|
-
"@ultimat3/entity": "31.
|
|
64
|
-
"@ultimat3/flags": "31.
|
|
65
|
-
"@ultimat3/http": "31.
|
|
66
|
-
"@ultimat3/i18n": "31.
|
|
67
|
-
"@ultimat3/jobs": "31.
|
|
68
|
-
"@ultimat3/mail": "31.
|
|
69
|
-
"@ultimat3/manifest": "31.
|
|
70
|
-
"@ultimat3/mcp": "31.
|
|
71
|
-
"@ultimat3/money": "31.
|
|
72
|
-
"@ultimat3/notify": "31.
|
|
73
|
-
"@ultimat3/policy": "31.
|
|
74
|
-
"@ultimat3/pwa": "31.
|
|
75
|
-
"@ultimat3/query": "31.
|
|
76
|
-
"@ultimat3/realtime": "31.
|
|
77
|
-
"@ultimat3/render": "31.
|
|
78
|
-
"@ultimat3/schema": "31.
|
|
79
|
-
"@ultimat3/scraping": "31.
|
|
80
|
-
"@ultimat3/seo": "31.
|
|
81
|
-
"@ultimat3/storage": "31.
|
|
82
|
-
"@ultimat3/testing": "31.
|
|
83
|
-
"@ultimat3/time": "31.
|
|
56
|
+
"@ultimat3/action": "31.38.0",
|
|
57
|
+
"@ultimat3/admin": "31.38.0",
|
|
58
|
+
"@ultimat3/ai": "31.38.0",
|
|
59
|
+
"@ultimat3/auth": "31.38.0",
|
|
60
|
+
"@ultimat3/cache": "31.38.0",
|
|
61
|
+
"@ultimat3/core": "31.38.0",
|
|
62
|
+
"@ultimat3/db": "31.38.0",
|
|
63
|
+
"@ultimat3/entity": "31.38.0",
|
|
64
|
+
"@ultimat3/flags": "31.38.0",
|
|
65
|
+
"@ultimat3/http": "31.38.0",
|
|
66
|
+
"@ultimat3/i18n": "31.38.0",
|
|
67
|
+
"@ultimat3/jobs": "31.38.0",
|
|
68
|
+
"@ultimat3/mail": "31.38.0",
|
|
69
|
+
"@ultimat3/manifest": "31.38.0",
|
|
70
|
+
"@ultimat3/mcp": "31.38.0",
|
|
71
|
+
"@ultimat3/money": "31.38.0",
|
|
72
|
+
"@ultimat3/notify": "31.38.0",
|
|
73
|
+
"@ultimat3/policy": "31.38.0",
|
|
74
|
+
"@ultimat3/pwa": "31.38.0",
|
|
75
|
+
"@ultimat3/query": "31.38.0",
|
|
76
|
+
"@ultimat3/realtime": "31.38.0",
|
|
77
|
+
"@ultimat3/render": "31.38.0",
|
|
78
|
+
"@ultimat3/schema": "31.38.0",
|
|
79
|
+
"@ultimat3/scraping": "31.38.0",
|
|
80
|
+
"@ultimat3/seo": "31.38.0",
|
|
81
|
+
"@ultimat3/storage": "31.38.0",
|
|
82
|
+
"@ultimat3/testing": "31.38.0",
|
|
83
|
+
"@ultimat3/time": "31.38.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/cmd-planned.ts
CHANGED
|
@@ -23,34 +23,11 @@ export interface PlannedCommand {
|
|
|
23
23
|
* build actually ships — a fix line pointing at another unbuilt command is the failure mode this
|
|
24
24
|
* table exists to close, and `cmd-planned.test.ts` asserts the whole set against the registry.
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
fix: 'x db branch list --json # the database half: list, create <name>, delete <name>',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: 'ai',
|
|
35
|
-
summary: 'eval scores, semantic-cache stats, vector reindex',
|
|
36
|
-
usage: 'x ai [eval <name>|cache|reindex] [--json]',
|
|
37
|
-
subcommands: ['eval', 'cache', 'reindex'],
|
|
38
|
-
fix: 'x test eval --json # every eval, scored against its committed baseline',
|
|
39
|
-
},
|
|
40
|
-
// `registerCurrency()` ships `As of 2026-08`, and this row is deliberately NOT deleted with it.
|
|
41
|
-
// What is planned is a GENERATOR — the one thing a process that exits can contribute, since a
|
|
42
|
-
// registration has to land in the app's own source to survive the run — and a generator that
|
|
43
|
-
// emits the one call is not a second path any more than `x g route` is a second way to declare a
|
|
44
|
-
// route (axiom 1). The whole table is shaped this way: `x branch` beside `x db branch`, `x ai`
|
|
45
|
-
// beside `x test eval`. What changed is only that the `fix:` is now true.
|
|
46
|
-
{
|
|
47
|
-
name: 'money',
|
|
48
|
-
summary: 'extend the currency table',
|
|
49
|
-
usage: 'x money add-currency <ISO> --exponent <n> [--json]',
|
|
50
|
-
subcommands: ['add-currency'],
|
|
51
|
-
fix: "x errors explain X_CURRENCY_UNKNOWN --json # extend it in code: registerCurrency({ code: 'GHS', exponent: 2, name: 'Ghana Cedi' }) at boot",
|
|
52
|
-
},
|
|
53
|
-
];
|
|
26
|
+
// Empty `As of 2026-11-16` (plan 101b slice 13): `x branch`, `x ai` and `x money` left the
|
|
27
|
+
// registry, each with its decision and extension point in wiki/Known-Gaps.md, and the parser now
|
|
28
|
+
// refuses each with `X_CLI_UNKNOWN_COMMAND`. Finished means this list is empty, not that every idea
|
|
29
|
+
// was built; a row returns only with a plan that builds it.
|
|
30
|
+
export const PLANNED_COMMANDS: readonly PlannedCommand[] = [];
|
|
54
31
|
|
|
55
32
|
/**
|
|
56
33
|
* The planned command a resolved command NAME belongs to, if any. Exported for `dispatch.ts`'s
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// `x g sign-in`'s two runtime files, rebased onto what the app has: the template's pair replaces
|
|
2
|
+
// `x new`'s bytes, and an edited copy gets only the sign-in delta spliced in
|
|
3
|
+
// (`templates/sign-in-runtime.ts`). The spliced file is handed to the one writer as a replacement
|
|
4
|
+
// of the exact bytes read here, so a file changed between this read and the write still conflicts.
|
|
5
|
+
|
|
6
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
7
|
+
import type { GenerateDisk } from './generate-disk';
|
|
8
|
+
import type { Finding } from './output';
|
|
9
|
+
import type { GeneratedFile } from './templates/naming';
|
|
10
|
+
import { RUNTIME_MODULE, RUNTIME_TEST } from './templates/scaffold-runtime-ports';
|
|
11
|
+
import {
|
|
12
|
+
type RuntimeRoutes,
|
|
13
|
+
type RuntimeSplice,
|
|
14
|
+
spliceSignInRuntime,
|
|
15
|
+
spliceSignInRuntimeTest,
|
|
16
|
+
} from './templates/sign-in-runtime';
|
|
17
|
+
|
|
18
|
+
export interface RebasedRuntime {
|
|
19
|
+
readonly files: readonly GeneratedFile[];
|
|
20
|
+
/** A runtime file the splice could not read: the run is refused, naming the line to edit. */
|
|
21
|
+
readonly refusals: readonly Finding[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const unrecognisedFinding = (
|
|
25
|
+
path: string,
|
|
26
|
+
splice: Extract<RuntimeSplice, { kind: 'unrecognised' }>,
|
|
27
|
+
invocation: string,
|
|
28
|
+
): Finding => ({
|
|
29
|
+
code: 'X_GENERATE_CONFLICT',
|
|
30
|
+
cause: `${path} is the author's, and x g sign-in found no place in it to add what sign-in needs, so nothing was written`,
|
|
31
|
+
fix: `edit ${path}:${splice.line} — ${splice.edit}; then: ${invocation}`,
|
|
32
|
+
docs: ERROR_DOCS_URL,
|
|
33
|
+
at: path,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `files` with each runtime entry spliced over the copy on disk. A file already holding the
|
|
38
|
+
* sign-in delta is left as the template's entry, so the writer reports the conflict a second run
|
|
39
|
+
* always was; a test the shape adds nothing to is dropped from the run.
|
|
40
|
+
*/
|
|
41
|
+
export async function rebaseSignInRuntime(
|
|
42
|
+
disk: GenerateDisk,
|
|
43
|
+
files: readonly GeneratedFile[],
|
|
44
|
+
routes: RuntimeRoutes | undefined,
|
|
45
|
+
invocation: string,
|
|
46
|
+
): Promise<RebasedRuntime> {
|
|
47
|
+
const out: GeneratedFile[] = [];
|
|
48
|
+
const refusals: Finding[] = [];
|
|
49
|
+
for (const file of files) {
|
|
50
|
+
const isRuntime = file.path === RUNTIME_MODULE || file.path === RUNTIME_TEST;
|
|
51
|
+
const now = isRuntime ? await disk.read(file.path) : undefined;
|
|
52
|
+
if (now === undefined || file.merge !== 'replaces-pristine') {
|
|
53
|
+
out.push(file);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const splice =
|
|
57
|
+
file.path === RUNTIME_MODULE
|
|
58
|
+
? spliceSignInRuntime(now, routes)
|
|
59
|
+
: spliceSignInRuntimeTest(now, routes);
|
|
60
|
+
if (splice.kind === 'unrecognised') {
|
|
61
|
+
refusals.push(unrecognisedFinding(file.path, splice, invocation));
|
|
62
|
+
out.push(file);
|
|
63
|
+
} else if (splice.kind === 'present') {
|
|
64
|
+
out.push(file);
|
|
65
|
+
} else if (splice.source !== now) {
|
|
66
|
+
out.push({ ...file, contents: splice.source, pristine: now });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { files: out, refusals };
|
|
70
|
+
}
|
package/src/generate-sign-in.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { formatWritten } from './generate-format-written';
|
|
|
17
17
|
import { APP_CONFIG, type SignInEnvKey, signInConfigEdit } from './generate-sign-in-config';
|
|
18
18
|
import { appManifestIfAny, existingArtifacts } from './generate-sign-in-manifest';
|
|
19
19
|
import { readSignInMode, type SignInMode, signInLabel } from './generate-sign-in-mode';
|
|
20
|
+
import { rebaseSignInRuntime } from './generate-sign-in-runtime';
|
|
20
21
|
import { planWrites, writeFiles } from './generate-write';
|
|
21
22
|
import { resolveDbModule } from './handle-registration';
|
|
22
23
|
import { resolveCatalogModule } from './i18n-audit';
|
|
@@ -28,6 +29,7 @@ import { names, resolveLocales } from './templates';
|
|
|
28
29
|
import { authFiles } from './templates/scaffold-auth';
|
|
29
30
|
import { DEV_ACTOR_FILES, signedInAuthenticatorFiles } from './templates/sign-in-authenticator';
|
|
30
31
|
import { oidcEnvPrefix } from './templates/sign-in-oidc';
|
|
32
|
+
import { OIDC_RUNTIME_ROUTES } from './templates/sign-in-runtime';
|
|
31
33
|
import { SIGN_IN_PATH } from './templates/sign-in-shared';
|
|
32
34
|
|
|
33
35
|
/** The env keys an OIDC sign-in adds to `envSchema`; `SESSION_SECRET` and `APP_URL` exist already. */
|
|
@@ -112,7 +114,7 @@ export async function runSignIn(ctx: CommandContext, root: string): Promise<Comm
|
|
|
112
114
|
// Every catalog the app keeps, as every other generator seeds them: `en` alone renders ⟦key⟧
|
|
113
115
|
// for a reader of any other locale the app ships.
|
|
114
116
|
const locales = resolveLocales(await namedOrAppLocales(root, flagList(ctx.args, 'locales')));
|
|
115
|
-
const
|
|
117
|
+
const generated = await localiseCatalogs(
|
|
116
118
|
root,
|
|
117
119
|
generate({
|
|
118
120
|
kind: 'sign-in',
|
|
@@ -124,6 +126,14 @@ export async function runSignIn(ctx: CommandContext, root: string): Promise<Comm
|
|
|
124
126
|
);
|
|
125
127
|
const flags = reproducedFlags(generateSpec, ctx.args);
|
|
126
128
|
const invocation = [invocationOf(ctx, 'g'), 'sign-in', ...flags].join(' ');
|
|
129
|
+
// `runtime.ts` is the file every app edits: the sign-in delta is spliced into the author's copy.
|
|
130
|
+
const runtime = await rebaseSignInRuntime(
|
|
131
|
+
appDisk(root),
|
|
132
|
+
generated,
|
|
133
|
+
mode.kind === 'oidc' ? OIDC_RUNTIME_ROUTES : undefined,
|
|
134
|
+
invocation,
|
|
135
|
+
);
|
|
136
|
+
const files = runtime.files;
|
|
127
137
|
const force = flagBool(ctx.args, 'force');
|
|
128
138
|
const swap =
|
|
129
139
|
mode.kind === 'oidc'
|
|
@@ -140,11 +150,14 @@ export async function runSignIn(ctx: CommandContext, root: string): Promise<Comm
|
|
|
140
150
|
const configEdited = configSource !== undefined && config.contents !== configSource;
|
|
141
151
|
// The three actions are listed in the API index under their file names, so an app already
|
|
142
152
|
// binding `createSession` there is refused before anything lands — `cmd-generate.ts`'s preflight.
|
|
143
|
-
const bindings =
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
153
|
+
const bindings = [
|
|
154
|
+
...runtime.refusals,
|
|
155
|
+
...(await indexBindingFindings(
|
|
156
|
+
root,
|
|
157
|
+
files.map((file) => file.path),
|
|
158
|
+
`${invocation} # after renaming what apps/web/api/index.ts already binds under that name`,
|
|
159
|
+
)),
|
|
160
|
+
];
|
|
148
161
|
|
|
149
162
|
// The pass's half: what the written actions cannot run as generated, turned off with a reason.
|
|
150
163
|
const exerciseSource = await appDisk(root).read(EXERCISE_FILE);
|
package/src/generate-write.ts
CHANGED
|
@@ -172,6 +172,12 @@ type WritePlan =
|
|
|
172
172
|
* The author's rules live in a slice's `entity.ts` and `policy.ts`: `--force` as the first thing
|
|
173
173
|
* offered deleted them, when an existing slice almost always means the next primitive belongs in it.
|
|
174
174
|
*/
|
|
175
|
+
/** Files the app owns and a generator splices into, never replaces (`sign-in-runtime.ts`). */
|
|
176
|
+
const APP_OWNED_SPLICED: ReadonlySet<string> = new Set([
|
|
177
|
+
'apps/web/runtime.ts',
|
|
178
|
+
'apps/web/runtime.test.ts',
|
|
179
|
+
]);
|
|
180
|
+
|
|
175
181
|
const conflictFix = (
|
|
176
182
|
path: string,
|
|
177
183
|
absolute: string,
|
|
@@ -179,6 +185,12 @@ const conflictFix = (
|
|
|
179
185
|
name: string | undefined,
|
|
180
186
|
): string => {
|
|
181
187
|
const [slice, module] = path.split('/').slice(-2);
|
|
188
|
+
// An app-owned file a generator splices into (the port wiring): it already carries this
|
|
189
|
+
// generator's lines, and `--force` would replace it with the template, dropping every port and
|
|
190
|
+
// line the app added. The fix inspects it; it never overwrites it.
|
|
191
|
+
if (APP_OWNED_SPLICED.has(path)) {
|
|
192
|
+
return `git diff -- ${quoteArg(path)} # already wired by this generator; forcing it would replace the app's own lines with the template`;
|
|
193
|
+
}
|
|
182
194
|
// The caller's own name, never `<name>`: a placeholder pasted into a shell is a redirect. With no
|
|
183
195
|
// name to hand back, the one line that needs none.
|
|
184
196
|
if (
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The one way an island plugin answers `onResolve` with a file on disk: the path itself where
|
|
2
|
+
// `Bun.build` takes it, and a one-line re-export of it where `Bun.build` refuses the path.
|
|
3
|
+
|
|
4
|
+
import type { OnResolveResult, PluginBuilder } from 'bun';
|
|
5
|
+
|
|
6
|
+
/** Where a refused path is served from; the prefix keeps the re-export from resolving to itself. */
|
|
7
|
+
const NAMESPACE = 'ultimate-file';
|
|
8
|
+
const PREFIX = 'file:';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* why: Bun 1.4.4's `Bun.build` throws `onResolve plugin "path" must be absolute when the namespace
|
|
12
|
+
* is "file"` for ANY returned path holding the substring `..` — not only a `..` segment
|
|
13
|
+
* `path.normalize` would fold: `/a+..+b/m.js`, `/b..c/m.js` and `/d../m.js` are refused alike,
|
|
14
|
+
* realpath or not (measured 2026-11-16, a one-plugin probe). Bun's isolated store names a `file:`
|
|
15
|
+
* install `node_modules/.bun/@ultimat3+realtime@file+..+..+…/`, so a realtime resolved there
|
|
16
|
+
* could not be handed back. Bun's OWN resolver takes such a path as an import specifier, so the
|
|
17
|
+
* refused path is served as `export * from '<path>'`: the file still loads under its own path
|
|
18
|
+
* string — the module key every relative import inside it gets — so nothing ships twice. Every
|
|
19
|
+
* other path is answered as before, so a build that never meets `..` emits the same bytes.
|
|
20
|
+
*/
|
|
21
|
+
export function fileResult(path: string): OnResolveResult {
|
|
22
|
+
return path.includes('..') ? { path: `${PREFIX}${path}`, namespace: NAMESPACE } : { path };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The loader `fileResult`'s refused paths need, set up by every plugin that calls it. `export *`
|
|
27
|
+
* carries every name but `default`, and each module these plugins resolve exports named bindings
|
|
28
|
+
* only (the repo's rule: no default exports).
|
|
29
|
+
*/
|
|
30
|
+
export function serveRefusedPaths(build: PluginBuilder): void {
|
|
31
|
+
build.onLoad({ filter: /.*/, namespace: NAMESPACE }, (args) => ({
|
|
32
|
+
contents: `export * from ${JSON.stringify(args.path.slice(PREFIX.length))};\n`,
|
|
33
|
+
loader: 'js',
|
|
34
|
+
}));
|
|
35
|
+
}
|
package/src/island-realtime.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// core's transport found beside the core module importing it.
|
|
12
12
|
import { basename, dirname, join } from 'node:path';
|
|
13
13
|
import type { BunPlugin } from 'bun';
|
|
14
|
+
import { fileResult, serveRefusedPaths } from './island-plugin-path';
|
|
14
15
|
import { followsOnly, type IslandRealtime } from './island-realtime-state';
|
|
15
16
|
import { RUNTIME_CHUNK_SPECIFIER, type RuntimeChunk } from './island-runtime';
|
|
16
17
|
import { firstInGraph } from './live-routes';
|
|
@@ -187,9 +188,9 @@ export function islandRealtimePlugin(
|
|
|
187
188
|
}
|
|
188
189
|
: undefined,
|
|
189
190
|
);
|
|
190
|
-
build.onResolve({ filter: /^ultimate:island-core-transport$/ }, (args) =>
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
build.onResolve({ filter: /^ultimate:island-core-transport$/ }, (args) =>
|
|
192
|
+
fileResult(args.importer.slice(TRANSPORT_MODULE.length)),
|
|
193
|
+
);
|
|
193
194
|
}
|
|
194
195
|
build.onResolve({ filter: /^ultimate:island-entry:/ }, (args) => ({
|
|
195
196
|
path: `entry:${args.path.slice(REALTIME_ISLAND_ENTRY.length)}`,
|
|
@@ -203,12 +204,12 @@ export function islandRealtimePlugin(
|
|
|
203
204
|
path: 'restore',
|
|
204
205
|
namespace: NAMESPACE,
|
|
205
206
|
}));
|
|
206
|
-
build.onResolve({ filter: /^ultimate:island-module:/ }, (args) =>
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
build.onResolve({ filter: /^ultimate:island-module:/ }, (args) =>
|
|
208
|
+
fileResult(join(root, args.path.slice(MODULE.length))),
|
|
209
|
+
);
|
|
209
210
|
// The wait is realtime's, from the copy the hooks are bundled from; the runtime chunk is
|
|
210
211
|
// another file of this build's output, fetched by the browser and never bundled in.
|
|
211
|
-
build.onResolve({ filter: /^ultimate:island-page-wait$/ }, () => (
|
|
212
|
+
build.onResolve({ filter: /^ultimate:island-page-wait$/ }, () => fileResult(runtime.wait));
|
|
212
213
|
build.onResolve({ filter: RUNTIME_CHUNK_SPECIFIER }, (args) => ({
|
|
213
214
|
path: args.path,
|
|
214
215
|
external: true,
|
|
@@ -216,7 +217,7 @@ export function islandRealtimePlugin(
|
|
|
216
217
|
// Every bare `@ultimat3/realtime` in this build, the virtual install's included — a virtual
|
|
217
218
|
// module has no directory to resolve from. The island's directory for all of them, which is
|
|
218
219
|
// what the island itself would get.
|
|
219
|
-
build.onResolve({ filter: /^@ultimat3\/realtime$/ }, () => (
|
|
220
|
+
build.onResolve({ filter: /^@ultimat3\/realtime$/ }, () => fileResult(runtime.realtime));
|
|
220
221
|
build.onLoad({ filter: /.*/, namespace: NAMESPACE }, (args) => ({
|
|
221
222
|
contents: args.path.startsWith('entry:')
|
|
222
223
|
? entrySource(
|
|
@@ -230,6 +231,8 @@ export function islandRealtimePlugin(
|
|
|
230
231
|
: installSource(runtime.url),
|
|
231
232
|
loader: 'js',
|
|
232
233
|
}));
|
|
234
|
+
// A path `Bun.build` refuses is served through a re-export (`island-plugin-path.ts`).
|
|
235
|
+
serveRefusedPaths(build);
|
|
233
236
|
},
|
|
234
237
|
};
|
|
235
238
|
}
|
package/src/island-runtime.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { inputFiles } from './island-cache-inputs';
|
|
|
13
13
|
import { realSpelling } from './island-duplicates';
|
|
14
14
|
import { describeBuildError, stableChunk, stripDebugId } from './island-identity';
|
|
15
15
|
import { frameworkDedupePlugins } from './island-package-dedupe';
|
|
16
|
+
import { fileResult, serveRefusedPaths } from './island-plugin-path';
|
|
16
17
|
import type { SourcePaths } from './island-sources';
|
|
17
18
|
import { sourcesOnDisk } from './island-sources';
|
|
18
19
|
|
|
@@ -192,11 +193,13 @@ function runtimeEntryPlugin(file: string): BunPlugin {
|
|
|
192
193
|
path: 'entry',
|
|
193
194
|
namespace: NAMESPACE,
|
|
194
195
|
}));
|
|
195
|
-
build.onResolve({ filter: /^ultimate:realtime-runtime-module$/ }, () => (
|
|
196
|
+
build.onResolve({ filter: /^ultimate:realtime-runtime-module$/ }, () => fileResult(file));
|
|
196
197
|
build.onLoad({ filter: /.*/, namespace: NAMESPACE }, () => ({
|
|
197
198
|
contents: `import { installPageRuntime } from '${MODULE}';\ninstallPageRuntime();\n`,
|
|
198
199
|
loader: 'js',
|
|
199
200
|
}));
|
|
201
|
+
// A path `Bun.build` refuses is served through a re-export (`island-plugin-path.ts`).
|
|
202
|
+
serveRefusedPaths(build);
|
|
200
203
|
},
|
|
201
204
|
};
|
|
202
205
|
}
|
package/src/new-shapes.ts
CHANGED
|
@@ -7,7 +7,16 @@ import { flagString } from './parse';
|
|
|
7
7
|
import { quoteArg } from './shell-quote';
|
|
8
8
|
|
|
9
9
|
/** Every shape `x new` writes. A name here and no overlay in `templates/shapes/` fails its test. */
|
|
10
|
-
export const NEW_SHAPES = [
|
|
10
|
+
export const NEW_SHAPES = [
|
|
11
|
+
'api',
|
|
12
|
+
'blog',
|
|
13
|
+
'dashboard',
|
|
14
|
+
'saas',
|
|
15
|
+
'agent',
|
|
16
|
+
'realtime',
|
|
17
|
+
'content',
|
|
18
|
+
'offline',
|
|
19
|
+
] as const;
|
|
11
20
|
|
|
12
21
|
export type NewShape = (typeof NEW_SHAPES)[number];
|
|
13
22
|
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// The `agent` shape's actions: the read the agent calls as a tool (`postTitles`), the agent itself
|
|
2
|
+
// (`suggestTitle`, an `agent()` — a factory returning an action, so a route and an MCP tool like
|
|
3
|
+
// any other), and `draftPost`, the code that keeps what the agent suggested. Each with its test.
|
|
4
|
+
|
|
5
|
+
import type { GeneratedFile } from '../naming';
|
|
6
|
+
import { ASSISTANT_DIR } from './agent-model';
|
|
7
|
+
|
|
8
|
+
const DIR = `${ASSISTANT_DIR}/actions`;
|
|
9
|
+
const ORG = '00000000-0000-4000-8000-000000000002';
|
|
10
|
+
const OTHER_ORG = '00000000-0000-4000-8000-000000000009';
|
|
11
|
+
|
|
12
|
+
const postTitles =
|
|
13
|
+
(): string => `// postTitles: the titles of the caller's newest posts. The read the assistant's agent calls as a
|
|
14
|
+
// tool, and an MCP client calls as the same tool — one declaration, one policy, both doors.
|
|
15
|
+
|
|
16
|
+
import { action, t } from '@ultimat3/action';
|
|
17
|
+
import { canPostRead } from '../../post/policy';
|
|
18
|
+
import * as repo from '../../post/repo';
|
|
19
|
+
|
|
20
|
+
export const postTitles = action({
|
|
21
|
+
input: t.object({ limit: t.number.int().min(1).max(50).default(20) }),
|
|
22
|
+
output: t.object({ titles: t.array(t.string) }),
|
|
23
|
+
policy: canPostRead,
|
|
24
|
+
mcp: {
|
|
25
|
+
expose: true,
|
|
26
|
+
description: "The titles of your organisation's newest posts, newest first",
|
|
27
|
+
},
|
|
28
|
+
async handle({ input }) {
|
|
29
|
+
const rows = await repo.list(input.limit);
|
|
30
|
+
return { titles: rows.map((row) => row.title) };
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
const postTitlesTest =
|
|
36
|
+
(): string => `// postTitles against the in-memory driver: who may read, and what the agent is handed.
|
|
37
|
+
import { driver } from '@APP/db';
|
|
38
|
+
import { ctxOf, frozenClock, runWithContext } from '@ultimat3/core';
|
|
39
|
+
import { testActor } from '@ultimat3/policy';
|
|
40
|
+
import { afterEach, expect, unitTest } from '@ultimat3/testing';
|
|
41
|
+
import * as repo from '../../post/repo';
|
|
42
|
+
import { postTitles } from './post-titles';
|
|
43
|
+
|
|
44
|
+
const orgId = '${ORG}';
|
|
45
|
+
const target = postTitles.named('postTitles');
|
|
46
|
+
const reader = testActor('reader', { orgId, permissions: ['post:read'] }).actor;
|
|
47
|
+
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
driver.reset?.();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
unitTest('a caller without the read grant is refused', async () => {
|
|
53
|
+
const stranger = testActor('stranger', { orgId }).actor;
|
|
54
|
+
await expect(target.as(stranger, {})).rejects.toBeUltimateError('X_FORBIDDEN');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
unitTest("the org's titles, newest first, as many as asked", async () => {
|
|
58
|
+
const at = (instant: string) => ctxOf({ actor: reader, clock: frozenClock(instant) });
|
|
59
|
+
for (const [title, instant] of [
|
|
60
|
+
['older', '2026-01-01T00:00:00.000Z'],
|
|
61
|
+
['newer', '2026-01-02T00:00:00.000Z'],
|
|
62
|
+
] as const) {
|
|
63
|
+
const draft = { orgId, title, price: { minor: 0, currency: 'USD' } };
|
|
64
|
+
await runWithContext(at(instant), () => repo.insert(draft));
|
|
65
|
+
}
|
|
66
|
+
expect(await target.as(reader, {})).toEqual({ titles: ['newer', 'older'] });
|
|
67
|
+
expect(await target.as(reader, { limit: 1 })).toEqual({ titles: ['newer'] });
|
|
68
|
+
});
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
const suggestTitle =
|
|
72
|
+
(): string => `// suggestTitle: the assistant. An \`agent()\` — a factory that RETURNS an action, so it has a route,
|
|
73
|
+
// an MCP tool and a job (\`../jobs/draft-post-later.ts\`) like any other. Its one tool is an action
|
|
74
|
+
// too, run under the SAME actor through its own policy: the model reads what the caller may read.
|
|
75
|
+
// It writes nothing: what it suggests is kept by \`draftPost\`, under an id the CODE was given.
|
|
76
|
+
|
|
77
|
+
import { t } from '@ultimat3/action';
|
|
78
|
+
import { agent } from '@ultimat3/ai';
|
|
79
|
+
import { canPostWrite } from '../../post/policy';
|
|
80
|
+
import { suggestTitlePrompt } from '../prompts/suggest-title';
|
|
81
|
+
import { postTitles } from './post-titles';
|
|
82
|
+
|
|
83
|
+
export const suggestTitle = agent({
|
|
84
|
+
input: t.object({ orgId: t.uuid, topic: t.string.min(1).max(200) }),
|
|
85
|
+
output: t.object({ title: t.string.min(1).max(200) }),
|
|
86
|
+
prompt: suggestTitlePrompt,
|
|
87
|
+
// The topic verbatim: the prompt fences it as \`<topic>\` DATA, never instructions.
|
|
88
|
+
vars: ({ input, ctx }) => ({ topic: input.topic, locale: ctx.locale }),
|
|
89
|
+
tools: [postTitles],
|
|
90
|
+
// A read, then an answer — and one turn of slack. Reaching the ceiling is X_AGENT_MAX_TURNS.
|
|
91
|
+
maxTurns: 3,
|
|
92
|
+
maxToolResultChars: 4000,
|
|
93
|
+
maxTokens: 512,
|
|
94
|
+
budget: { tokensPerRun: 16_000 },
|
|
95
|
+
// A suggestion is for a post the caller may write, in the org the input names.
|
|
96
|
+
policy: canPostWrite,
|
|
97
|
+
mcp: {
|
|
98
|
+
expose: true,
|
|
99
|
+
description:
|
|
100
|
+
'Suggest a title for a new post about a topic, unlike every title your organisation has',
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
const suggestTitleTest =
|
|
106
|
+
(): string => `// suggestTitle on the scripted model: the tool it calls, the answer parsed into its schema, and a
|
|
107
|
+
// refusal decided before a single token is spent.
|
|
108
|
+
import { driver } from '@APP/db';
|
|
109
|
+
import { testActor } from '@ultimat3/policy';
|
|
110
|
+
import { afterEach, expect, swapAdapter, unitTest } from '@ultimat3/testing';
|
|
111
|
+
import { api } from '../../../api/index';
|
|
112
|
+
import { scriptedGateway } from '../scripted-model';
|
|
113
|
+
|
|
114
|
+
const orgId = '${ORG}';
|
|
115
|
+
const writer = testActor('writer', { orgId, permissions: ['post:read', 'post:write'] }).actor;
|
|
116
|
+
const input = { orgId, topic: 'How we review a pull request' };
|
|
117
|
+
|
|
118
|
+
afterEach(() => {
|
|
119
|
+
driver.reset?.();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
unitTest('it reads the titles through its tool, then answers one', async () => {
|
|
123
|
+
const { model, gateway } = scriptedGateway([
|
|
124
|
+
{ call: 'postTitles', input: {} },
|
|
125
|
+
{ answer: { title: 'Two readers, one diff' } },
|
|
126
|
+
]);
|
|
127
|
+
await swapAdapter('aiGateway', gateway);
|
|
128
|
+
expect(await api.actions.suggestTitle.as(writer, input)).toEqual({
|
|
129
|
+
title: 'Two readers, one diff',
|
|
130
|
+
});
|
|
131
|
+
// The topic reached the model, and the tool's answer reached its second turn.
|
|
132
|
+
expect(JSON.stringify(model.seen[0]?.messages)).toContain(input.topic);
|
|
133
|
+
expect(JSON.stringify(model.seen[1]?.messages)).toContain('titles');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
unitTest('a writer of another org is refused, at no cost', async () => {
|
|
137
|
+
const { model, gateway } = scriptedGateway([]);
|
|
138
|
+
await swapAdapter('aiGateway', gateway);
|
|
139
|
+
const stranger = testActor('stranger', {
|
|
140
|
+
orgId: '${OTHER_ORG}',
|
|
141
|
+
permissions: ['post:write'],
|
|
142
|
+
});
|
|
143
|
+
await expect(api.actions.suggestTitle.as(stranger.actor, input)).rejects.toBeUltimateError(
|
|
144
|
+
'X_FORBIDDEN',
|
|
145
|
+
);
|
|
146
|
+
expect(model.seen).toEqual([]);
|
|
147
|
+
});
|
|
148
|
+
`;
|
|
149
|
+
|
|
150
|
+
const draftPost =
|
|
151
|
+
(): string => `// draftPost: the assistant's suggestion, kept. \`suggestTitle\` runs as the caller, and the post is
|
|
152
|
+
// written by this code under the id the CALLER chose — never one the model names. Idempotent by
|
|
153
|
+
// that id: a queued attempt replayed after its worker died finds the post and answers it, and the
|
|
154
|
+
// model is not asked twice.
|
|
155
|
+
|
|
156
|
+
import { action, t } from '@ultimat3/action';
|
|
157
|
+
import { PostView } from '../../post/entity';
|
|
158
|
+
import { canPostWrite, postTag } from '../../post/policy';
|
|
159
|
+
import * as repo from '../../post/repo';
|
|
160
|
+
import * as service from '../../post/service';
|
|
161
|
+
import { suggestTitle } from './suggest-title';
|
|
162
|
+
|
|
163
|
+
export const draftPost = action({
|
|
164
|
+
input: t.object({ id: t.uuid, orgId: t.uuid, topic: t.string.min(1).max(200), price: t.money }),
|
|
165
|
+
output: PostView,
|
|
166
|
+
policy: canPostWrite,
|
|
167
|
+
cache: { invalidates: [postTag] },
|
|
168
|
+
async handle({ input, ctx }) {
|
|
169
|
+
const kept = await repo.byId(input.id);
|
|
170
|
+
if (kept !== undefined) return kept;
|
|
171
|
+
const { orgId, topic } = input;
|
|
172
|
+
const { output } = await suggestTitle.run({ orgId, topic }, { actor: ctx.actor });
|
|
173
|
+
return service.create({ id: input.id, orgId, title: output.title, price: input.price });
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
`;
|
|
177
|
+
|
|
178
|
+
const draftPostTest =
|
|
179
|
+
(): string => `// draftPost: the post written under the caller's id with the agent's title — and once only.
|
|
180
|
+
import { driver } from '@APP/db';
|
|
181
|
+
import { testActor } from '@ultimat3/policy';
|
|
182
|
+
import { afterEach, expect, swapAdapter, unitTest } from '@ultimat3/testing';
|
|
183
|
+
import { api } from '../../../api/index';
|
|
184
|
+
import { scriptedGateway } from '../scripted-model';
|
|
185
|
+
|
|
186
|
+
const orgId = '${ORG}';
|
|
187
|
+
const writer = testActor('writer', { orgId, permissions: ['post:read', 'post:write'] }).actor;
|
|
188
|
+
const input = {
|
|
189
|
+
id: '00000000-0000-4000-8000-0000000000d1',
|
|
190
|
+
orgId,
|
|
191
|
+
topic: 'How we review a pull request',
|
|
192
|
+
price: { minor: 0, currency: 'USD' },
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
afterEach(() => {
|
|
196
|
+
driver.reset?.();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
unitTest('the suggested title is kept under the id the caller chose, once', async () => {
|
|
200
|
+
// Two turns: one run. A second run would be X_AI_SCRIPT_EXHAUSTED, never a second post.
|
|
201
|
+
const { model, gateway } = scriptedGateway([
|
|
202
|
+
{ call: 'postTitles', input: {} },
|
|
203
|
+
{ answer: { title: 'Two readers, one diff' } },
|
|
204
|
+
]);
|
|
205
|
+
await swapAdapter('aiGateway', gateway);
|
|
206
|
+
const first = await api.actions.draftPost.as(writer, input);
|
|
207
|
+
expect(first).toMatchObject({ id: input.id, title: 'Two readers, one diff', price: input.price });
|
|
208
|
+
expect(await api.actions.draftPost.as(writer, input)).toEqual(first);
|
|
209
|
+
expect(model.seen).toHaveLength(2);
|
|
210
|
+
});
|
|
211
|
+
`;
|
|
212
|
+
|
|
213
|
+
/** `apps/web/app/assistant/actions/`: the tool, the agent, the keeper, and their tests. */
|
|
214
|
+
export function actionFiles(scope: string): readonly GeneratedFile[] {
|
|
215
|
+
const own = (text: string): string => text.replaceAll('@APP/', `@${scope}/`);
|
|
216
|
+
return [
|
|
217
|
+
{ path: `${DIR}/post-titles.ts`, contents: postTitles() },
|
|
218
|
+
{ path: `${DIR}/post-titles.test.ts`, contents: own(postTitlesTest()) },
|
|
219
|
+
{ path: `${DIR}/suggest-title.ts`, contents: suggestTitle() },
|
|
220
|
+
{ path: `${DIR}/suggest-title.test.ts`, contents: own(suggestTitleTest()) },
|
|
221
|
+
{ path: `${DIR}/draft-post.ts`, contents: draftPost() },
|
|
222
|
+
{ path: `${DIR}/draft-post.test.ts`, contents: own(draftPostTest()) },
|
|
223
|
+
];
|
|
224
|
+
}
|