capable-kit 0.0.1-alpha.8 → 0.1.0-alpha.11
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/CHANGELOG.md +385 -0
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/ai-sdk.d.mts +3 -3
- package/dist/ai-sdk.mjs +9 -7
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/app.d.mts +2 -2
- package/dist/app.mjs +2 -2
- package/dist/bin.mjs +19 -15
- package/dist/bin.mjs.map +1 -1
- package/dist/cli.d.mts +9 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +2 -2
- package/dist/eve.d.mts +92 -9
- package/dist/eve.mjs +606 -26
- package/dist/eve.mjs.map +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-_qKFfWV4.d.mts → index-BIO_hbXJ.d.mts} +69 -26
- package/dist/{index-hdH_K5Zc.d.mts → index-C0tU5Y2n.d.mts} +4 -4
- package/dist/{index-Dl4NK9G0.d.mts → index-CwvjDizW.d.mts} +5 -3
- package/dist/{index-F4ba_olD.d.mts → index-F_eaksy8.d.mts} +58 -17
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/mcp.d.mts +19 -4
- package/dist/mcp.mjs +2 -2
- package/dist/{mount-CEFAplR5.mjs → mount-pvIaehZC.mjs} +159 -107
- package/dist/mount-pvIaehZC.mjs.map +1 -0
- package/dist/react-query.d.mts +2 -2
- package/dist/react-query.mjs +1 -1
- package/dist/react-query.mjs.map +1 -1
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +3 -3
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +1 -1
- package/dist/{src-rkr5j_NH.mjs → src-Bk3lEhI7.mjs} +63 -25
- package/dist/src-Bk3lEhI7.mjs.map +1 -0
- package/dist/src-C2OEkZ3c.mjs +760 -0
- package/dist/src-C2OEkZ3c.mjs.map +1 -0
- package/dist/{src-BWxDO2Ua.mjs → src-DFrxQ_S6.mjs} +9 -7
- package/dist/src-DFrxQ_S6.mjs.map +1 -0
- package/dist/{src-D_0PIhqq.mjs → src-DklM1g7V.mjs} +69 -40
- package/dist/src-DklM1g7V.mjs.map +1 -0
- package/dist/{src-D-cm2gQ6.mjs → src-TCQGaWar.mjs} +119 -45
- package/dist/src-TCQGaWar.mjs.map +1 -0
- package/dist/{subscription-B-auXJbm.d.mts → subscription-fVgS4T8P.d.mts} +2 -2
- package/dist/swr.d.mts +2 -2
- package/dist/swr.mjs +1 -1
- package/dist/swr.mjs.map +1 -1
- package/docs/CONTEXT.md +44 -22
- package/docs/README.md +3 -0
- package/docs/internal/README.md +3 -0
- package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +1 -1
- package/docs/internal/adr/0003-capability-reference-customization.md +68 -0
- package/docs/internal/architecture.md +31 -17
- package/docs/internal/capability-first-model.md +126 -17
- package/docs/internal/eve-recovery-validation.md +87 -0
- package/docs/internal/feedback/v-ray/README.md +258 -0
- package/docs/internal/feedback/v-ray/inference.mjs +43 -0
- package/docs/internal/feedback/v-ray/reproduce.mjs +36 -0
- package/docs/internal/implementation-friction.md +445 -1
- package/docs/internal/releases.md +79 -0
- package/docs/site/capable-orpc-and-trpc.mdx +2 -2
- package/docs/site/concepts/apps.mdx +7 -1
- package/docs/site/concepts/architecture.mdx +9 -1
- package/docs/site/concepts/capabilities.mdx +41 -4
- package/docs/site/concepts/errors.mdx +26 -4
- package/docs/site/concepts/presentations.mdx +20 -0
- package/docs/site/hosting/standalone-server.mdx +2 -0
- package/docs/site/patterns/composition.mdx +152 -8
- package/docs/site/patterns/remote-apps.mdx +29 -3
- package/docs/site/patterns/subscriptions.mdx +79 -32
- package/docs/site/quickstart.mdx +3 -2
- package/docs/site/reference/packages-and-entry-points.mdx +52 -4
- package/docs/site/reference/the-cap-cli.mdx +2 -2
- package/docs/site/surfaces/cli.mdx +44 -0
- package/docs/site/surfaces/eve.mdx +67 -18
- package/docs/site/surfaces/mcp.mdx +84 -2
- package/docs/site/surfaces/typescript.mdx +3 -3
- package/package-docs.mjs +3 -0
- package/package.json +17 -12
- package/src/bin.ts +0 -0
- package/src/index.test.ts +2 -1
- package/src/index.ts +8 -1
- package/src/package.test.ts +15 -0
- package/dist/mount-CEFAplR5.mjs.map +0 -1
- package/dist/src-BWxDO2Ua.mjs.map +0 -1
- package/dist/src-D-cm2gQ6.mjs.map +0 -1
- package/dist/src-D_0PIhqq.mjs.map +0 -1
- package/dist/src-betOfnDL.mjs +0 -481
- package/dist/src-betOfnDL.mjs.map +0 -1
- package/dist/src-rkr5j_NH.mjs.map +0 -1
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# v-ray migration feedback review
|
|
2
|
+
|
|
3
|
+
Reviewed 2026-09-09 at Capable commit `88de060ddfec42c2c33b83a8fab25ccb8f9a6a04`.
|
|
4
|
+
The investigation below records the baseline at that commit.
|
|
5
|
+
|
|
6
|
+
## Implemented follow-up
|
|
7
|
+
|
|
8
|
+
The current worktree now forwards markdansi's complete `RenderOptions` through
|
|
9
|
+
`createCli(app, { markdown: { codeBox: false } })`, including watch rendering.
|
|
10
|
+
Root empty/help-only invocations retain the app banner and command listing with
|
|
11
|
+
Capability arguments and options underneath; root `--json`
|
|
12
|
+
and `--watch` select execution, duplicate roots produce a usage error, and error
|
|
13
|
+
hints no longer contain a doubled space.
|
|
14
|
+
|
|
15
|
+
Inferred-output Capability overloads infer the handler return type directly,
|
|
16
|
+
then apply `Awaited` to derive canonical output, preserving mixed synchronous and
|
|
17
|
+
asynchronous return branches. Named
|
|
18
|
+
renderers pass in either property position on TS 5.8.3 and 7.0.1 RC, preserving
|
|
19
|
+
extra handler output fields and rejecting incompatible renderers. Untyped inline
|
|
20
|
+
renderers before `handler` still receive `unknown`; place inline renderers after
|
|
21
|
+
the handler. Explicit output schemas continue to work. The diagnostic script
|
|
22
|
+
therefore now reports success for both named cases against the current build;
|
|
23
|
+
the installed alpha.8 baseline remains unchanged.
|
|
24
|
+
|
|
25
|
+
Dependency restructuring, paragraph spacing, and end-of-options delimiter
|
|
26
|
+
handling remain follow-up work. No v-ray files or published packages changed.
|
|
27
|
+
|
|
28
|
+
## Assessment and evidence
|
|
29
|
+
|
|
30
|
+
The migration demonstrates the intended boundary: one analysis Capability feeds
|
|
31
|
+
a local Next.js Server Component, the legacy HTTP adapter, the `/~capable/`
|
|
32
|
+
protocol, and local/remote CLI. The existing analyzer remains application code.
|
|
33
|
+
Presentation derives from the same result without changing canonical JSON.
|
|
34
|
+
|
|
35
|
+
The integration was inspected read-only in `/Volumes/Development/v-ray`:
|
|
36
|
+
`capable.app.ts`, `capable/presentation.ts`, `scripts/cli.ts`,
|
|
37
|
+
`test/capable.test.ts`, `README.md`, and `app/api/v2/providers/route.ts`.
|
|
38
|
+
Its package is the installed `capable-kit@0.0.1-alpha.8`, not a workspace link.
|
|
39
|
+
The worktree declares the same version; more importantly, the installed source
|
|
40
|
+
maps contain byte-identical copies of current `core/src/capability.ts`,
|
|
41
|
+
`core/src/presentation.ts`, `cli/src/index.ts`, and `cli/src/presentation.ts`.
|
|
42
|
+
Runtime reproductions produced identical output for the installed and locally
|
|
43
|
+
built packages. None of the four reported issues is already fixed here.
|
|
44
|
+
|
|
45
|
+
Reported Next.js production build, migration tests, typecheck, and fixture
|
|
46
|
+
end-to-end success are migration evidence supplied by the integration owner;
|
|
47
|
+
they were not rerun in v-ray during this review. Production deployment remains
|
|
48
|
+
unvalidated. The following findings use focused, deterministic local fixtures.
|
|
49
|
+
|
|
50
|
+
## 1. P1: Route root help through the root Capability
|
|
51
|
+
|
|
52
|
+
Existing API already expresses the desired invocation; no new `root` flag is needed:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
capability({
|
|
56
|
+
id: 'analysis.url',
|
|
57
|
+
input: z.object({ url: z.string() }),
|
|
58
|
+
meta: { cli: { command: [], positional: ['url'] } },
|
|
59
|
+
handler: ({ input }) => analyzeURL(input.url),
|
|
60
|
+
});
|
|
61
|
+
await createCli(app, { invocationName: 'pnpm cli' }).run(process.argv.slice(2));
|
|
62
|
+
// pnpm cli vercel.com
|
|
63
|
+
// pnpm cli --help → proposed: detailed <url> help
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`packages/cli/src/index.ts` removes global flags and returns root/group help
|
|
67
|
+
when no tokens remain, before matching commands. Reproduced behavior:
|
|
68
|
+
|
|
69
|
+
| Arguments | Current result |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `vercel.com` | Executes the root Capability successfully |
|
|
72
|
+
| empty, `--help`, or `-h` | Generic `<command>` help; omits detailed arguments |
|
|
73
|
+
| `--help --` | Detailed root `<url>` help, exit 0 |
|
|
74
|
+
| `--json` alone | Generic help on stdout, exit 0, even with a defaulted URL |
|
|
75
|
+
| `--wat` or excess positional arguments | Useful specific error, exit 2; help hint contains `pnpm cli --help` with two spaces |
|
|
76
|
+
| `-- vercel.com` | `Unknown option --`, exit 2 |
|
|
77
|
+
|
|
78
|
+
The workaround works because help returns before input parsing. `--` is not
|
|
79
|
+
currently a functioning end-of-options delimiter. Global flags are also removed
|
|
80
|
+
regardless of delimiter position. Do not document the workaround as delimiter support.
|
|
81
|
+
|
|
82
|
+
Small first patch: resolve a unique empty command before the empty-argv help
|
|
83
|
+
branch and render its command help for empty/help-only invocation. Keep existing
|
|
84
|
+
group behavior when no root Capability exists. Build command names with a token
|
|
85
|
+
join to remove the doubled space. Add tests for required/defaulted/no-input roots,
|
|
86
|
+
local/remote Apps, mixed root/subcommands, and duplicate root mappings. Reject
|
|
87
|
+
ambiguous roots instead of silently choosing by catalog order; preserve longer
|
|
88
|
+
subcommand precedence.
|
|
89
|
+
|
|
90
|
+
Separate follow-up: decide and document no-argument execution. A conservative
|
|
91
|
+
first patch retains bare invocation as help; explicit `--json` should select
|
|
92
|
+
execution (including schema defaults), or emit a missing-input error when
|
|
93
|
+
required input is absent. It should never return human help as successful JSON.
|
|
94
|
+
Test `--watch` with the same dispatch policy. Implement normal `--` handling in
|
|
95
|
+
the argument parser as a separate bounded fix, including global-flag handling
|
|
96
|
+
after the delimiter. These are dispatch/parser corrections, not a new CLI DSL.
|
|
97
|
+
|
|
98
|
+
## 2. P1: Make output inference independent of renderer form/order
|
|
99
|
+
|
|
100
|
+
The reproduction uses an input schema, an async handler with inferred
|
|
101
|
+
`{ url: string; status: number }` output, and a named presentation function.
|
|
102
|
+
It also assigns the typed App call result to that output type.
|
|
103
|
+
|
|
104
|
+
| Form | TS 5.8.3 | TS 7.0.1 RC |
|
|
105
|
+
| --- | --- | --- |
|
|
106
|
+
| Named renderer before handler | TS2769, renderer expects `unknown` | Same |
|
|
107
|
+
| Named renderer after handler | TS2769 | Same |
|
|
108
|
+
| Inline renderer before handler | TS2345; App output is `unknown` (TS2322) | Same |
|
|
109
|
+
| Inline renderer after handler | Pass | Pass |
|
|
110
|
+
| Explicit output schema, named renderer before handler | Pass | Pass |
|
|
111
|
+
|
|
112
|
+
Results match for installed alpha.8 declarations and freshly built declarations.
|
|
113
|
+
Both runs use workspace Zod 4.4.3 to isolate compiler/package variables; this is
|
|
114
|
+
a minimized reproduction, not a compile of the full FetchResult type with v-ray's
|
|
115
|
+
Zod 4.5.4. The exact reported diagnostic does not require that full type.
|
|
116
|
+
|
|
117
|
+
Working current example:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
capability({
|
|
121
|
+
id: 'analysis.url',
|
|
122
|
+
input: z.object({ url: z.string() }),
|
|
123
|
+
handler: ({ input }) => analyzeURL(input.url),
|
|
124
|
+
toPresentation: result => presentAnalysis(result),
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Target: allow `toPresentation: presentAnalysis` in either property position,
|
|
129
|
+
preserving output inference and rejecting a renderer for an incompatible result.
|
|
130
|
+
Investigate the inferred-output overload's coupling of `THandler` and
|
|
131
|
+
`Awaited<ReturnType<THandler>>`; prototype inference isolation (`NoInfer`) or a
|
|
132
|
+
direct output type parameter before selecting a fix. Neither approach has been
|
|
133
|
+
validated here. Do not solve this with `any`, consumer casts, or a mandatory
|
|
134
|
+
output schema. An explicit schema is a useful contract decision, but adds runtime
|
|
135
|
+
validation and must not be demanded just to make renderer inference work.
|
|
136
|
+
Add compile fixtures for both supported compilers, property orders, named/inline
|
|
137
|
+
renderers, async output, incompatible renderers, and output transforms.
|
|
138
|
+
|
|
139
|
+
## 3. P2: Expose the small renderer controls already available
|
|
140
|
+
|
|
141
|
+
Capable lowers all presentation parts to Markdown, then calls markdansi 0.3.2
|
|
142
|
+
with only `color` and `width` in a TTY. Redirected output is raw Markdown.
|
|
143
|
+
The runtime fixture confirms:
|
|
144
|
+
|
|
145
|
+
- Two Markdown paragraphs become adjacent terminal lines, without a blank line.
|
|
146
|
+
- Fenced code and tables receive boxes by default.
|
|
147
|
+
- markdansi's `codeBox: false` preserves aligned fenced rows without a box.
|
|
148
|
+
- `tableBorder: 'none', tableDense: true` removes the outside box, but retains
|
|
149
|
+
column `|` separators. This is not a complete key/value detail-row layout.
|
|
150
|
+
- Those controls do not fix ordinary paragraph spacing. Its documented
|
|
151
|
+
`spacing` option belongs to streaming, not the whole-document `render()` used here.
|
|
152
|
+
|
|
153
|
+
Start with a small CLI-owned option, not new core parts or a renderer callback.
|
|
154
|
+
Illustrative proposed API (not available today):
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
createCli(app, {
|
|
158
|
+
invocationName: 'pnpm cli',
|
|
159
|
+
markdown: { codeBox: false, tableBorder: 'none', tableDense: true },
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
This permits ordinary fenced text for response headers and duration bars;
|
|
164
|
+
the consumer no longer needs dynamic inline-code delimiters solely to avoid
|
|
165
|
+
terminal boxes. Keep escaping untrusted remote values. Verify narrow terminals,
|
|
166
|
+
long headers, wide Unicode labels, and non-TTY Markdown before changing defaults.
|
|
167
|
+
|
|
168
|
+
Handle paragraph spacing as a focused renderer issue with before/after fixtures;
|
|
169
|
+
do not regex-rewrite arbitrary Markdown. Only if spacing remains unsolved should
|
|
170
|
+
a narrowly scoped detail-row helper be considered, with a portable Markdown
|
|
171
|
+
lowering. Any new core part would also need normalization, HTTP and MCP support,
|
|
172
|
+
which is disproportionate to the first fix. Framework joins (`+`), provider-role
|
|
173
|
+
arrows, duration units, and proportional bar calculations remain v-ray policy.
|
|
174
|
+
The current headings are normal structure; inline-code alignment and the
|
|
175
|
+
` ` footer spacer are the specific workarounds to remove.
|
|
176
|
+
|
|
177
|
+
## 4. P2: Separate installed host dependencies from embedded usage
|
|
178
|
+
|
|
179
|
+
Both package manifests require Nitro `3.0.260610-beta`. The v-ray lockfile
|
|
180
|
+
resolves it with Vite 6.1.0 although its optional peer wants `^7 || ^8`.
|
|
181
|
+
Nitro's unstorage 2.0.0-alpha.7 dependency wants the optional peer
|
|
182
|
+
`@vercel/functions: ^2.2.12 || ^3.0.0`; v-ray resolves 2.2.4. These ranges
|
|
183
|
+
explain the reported warnings. No fresh v-ray install was run during this review.
|
|
184
|
+
|
|
185
|
+
Inspection of emitted module imports in both packages shows that the root,
|
|
186
|
+
`/core`, `/cli`, and `/next` entries do not reach Nitro. `/cli` imports markdansi.
|
|
187
|
+
The `cap` executable statically imports `nitro/builder`, including when invoking
|
|
188
|
+
toolchain CLI functionality. Nitro is external to Capable's emitted bundle but
|
|
189
|
+
installed transitively. Thus installed footprint is real; this evidence does
|
|
190
|
+
not show Nitro in v-ray's Next.js runtime bundle. No Next.js bundle size, cold
|
|
191
|
+
start, or deployment performance measurement was made.
|
|
192
|
+
|
|
193
|
+
Smallest packaging candidate: make Nitro an optional peer and load host code
|
|
194
|
+
lazily only for host commands. `optionalDependencies` alone still installs it
|
|
195
|
+
normally, and lazy imports alone do not reduce installation footprint. A
|
|
196
|
+
separate published host package is a larger alternative; current scoped packages
|
|
197
|
+
are private implementation boundaries and should not be advertised as installable.
|
|
198
|
+
|
|
199
|
+
Proposed install flow (not the current package contract):
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
pnpm add capable-kit # embedded App, Next.js, createCli
|
|
203
|
+
pnpm add -D nitro@3.0.260610-beta # only when using cap dev/build host
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Retain current `createCli(app)` and Next mounting APIs. If choosing this option,
|
|
207
|
+
update generated standalone starters to include Nitro, give missing-host errors
|
|
208
|
+
an exact install command, and test packed installs with and without Nitro. Include
|
|
209
|
+
`cap --help`, local/remote `cap cli`, and `cap dev/build`: the executable must
|
|
210
|
+
remain usable without loading an absent host for unrelated commands. Consider
|
|
211
|
+
MCP's required SDK separately if install measurements justify doing so; do not
|
|
212
|
+
expand the initial packaging change to every surface.
|
|
213
|
+
|
|
214
|
+
## Preserve the migration boundary
|
|
215
|
+
|
|
216
|
+
The legacy adapter owns truthy-flag coercion, deprecated
|
|
217
|
+
`force_browserbase_bypass`, URL normalization, plain-text 400 responses, GET 405,
|
|
218
|
+
and HTTP-200 analysis failures. Its positive fractional body limit floors to zero:
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
const bodyMaxChars = typeof body_max_chars === 'number' && body_max_chars > 0
|
|
222
|
+
? Math.floor(body_max_chars) : undefined;
|
|
223
|
+
const result = await app.analysis.url({ url: normalizedURL.href, body_max_chars: bodyMaxChars });
|
|
224
|
+
return new Response(JSON.stringify(result));
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
That is why the Capability accepts a **nonnegative** integer. A stricter positive
|
|
228
|
+
schema would break compatibility. Returned error data remains canonical output;
|
|
229
|
+
thrown undeclared errors are normalized by Capable. Do not quietly convert one
|
|
230
|
+
into the other. Explicit output/error schemas are future v-ray work requiring
|
|
231
|
+
intentional compatibility decisions. Existing input schema direction/default
|
|
232
|
+
support already works here; the older default-requiredness friction entry should
|
|
233
|
+
not be mistaken for a present bug (defaulted URL help correctly shows optional).
|
|
234
|
+
|
|
235
|
+
MCP, `analyzeResponse()`, and sharing should follow concrete consumer demand.
|
|
236
|
+
The migration gives no reason to replace Next.js, introduce subscriptions, or
|
|
237
|
+
turn analyzer helpers into Capabilities.
|
|
238
|
+
|
|
239
|
+
## Reproduction and validation
|
|
240
|
+
|
|
241
|
+
```sh
|
|
242
|
+
pnpm install --frozen-lockfile
|
|
243
|
+
pnpm build
|
|
244
|
+
node docs/feedback/v-ray/reproduce.mjs
|
|
245
|
+
node docs/feedback/v-ray/reproduce.mjs /Volumes/Development/v-ray/node_modules/capable-kit
|
|
246
|
+
node docs/feedback/v-ray/inference.mjs
|
|
247
|
+
node docs/feedback/v-ray/inference.mjs /Volumes/Development/v-ray/node_modules/typescript/bin/tsc
|
|
248
|
+
node docs/feedback/v-ray/inference.mjs /Volumes/Development/v-ray/node_modules/typescript/bin/tsc /Volumes/Development/v-ray/node_modules/capable-kit
|
|
249
|
+
node docs/feedback/v-ray/inference.mjs node_modules/typescript/bin/tsc /Volumes/Development/v-ray/node_modules/capable-kit
|
|
250
|
+
pnpm exec vitest run packages/cli/src/cli.test.ts packages/core/src/presentation.test.ts
|
|
251
|
+
pnpm typecheck
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Build and typecheck passed; 12 existing focused tests passed. The reproduction
|
|
255
|
+
scripts print observations and compiler diagnostics, including expected current
|
|
256
|
+
failures; they are diagnostic tools, not passing regression assertions. The
|
|
257
|
+
inference script removes only its own temporary fixture directory. No v-ray
|
|
258
|
+
files were edited, no framework implementation changed, and nothing was published.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Current compiler by default; pass an absolute tsc.js path for another compiler.
|
|
2
|
+
// Optional second argument selects an installed capable-kit package directory.
|
|
3
|
+
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
4
|
+
import { resolve, join } from 'node:path';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
|
|
7
|
+
const compiler = process.argv[2] ?? resolve('node_modules/typescript/bin/tsc');
|
|
8
|
+
const packageDirectory = process.argv[3] ?? resolve('packages/capable');
|
|
9
|
+
const temporary = mkdtempSync(resolve('.vray-inference-'));
|
|
10
|
+
try {
|
|
11
|
+
for (const form of ['named-before', 'named-after', 'inline-before', 'inline-after', 'explicit-output']) {
|
|
12
|
+
const handler = 'handler: ({ input }) => Promise.resolve({ url: input.url, status: 200 }),';
|
|
13
|
+
const renderer = form.startsWith('inline') ? 'toPresentation: result => presentAnalysis(result),' : 'toPresentation: presentAnalysis,';
|
|
14
|
+
const source = `
|
|
15
|
+
import { capability, createApp, defineApp, type PresentationValue } from 'capable-kit';
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
type FetchResult = { url: string; status: number };
|
|
18
|
+
function presentAnalysis(result: FetchResult): PresentationValue { return result.url; }
|
|
19
|
+
const analysis = capability({
|
|
20
|
+
id: 'analysis.url',
|
|
21
|
+
input: z.object({ url: z.string() }),
|
|
22
|
+
${form === 'explicit-output' ? 'output: z.object({ url: z.string(), status: z.number() }),' : ''}
|
|
23
|
+
${form.endsWith('after') ? handler + renderer : renderer + handler}
|
|
24
|
+
});
|
|
25
|
+
const app = createApp(defineApp({ name: 'v-ray', capabilities: { analysis } }));
|
|
26
|
+
const result: FetchResult = await app.analysis({ url: 'vercel.com' });
|
|
27
|
+
const status: number = result.status;
|
|
28
|
+
`;
|
|
29
|
+
writeFileSync(join(temporary, 'case.ts'), source);
|
|
30
|
+
writeFileSync(join(temporary, 'tsconfig.json'), JSON.stringify({
|
|
31
|
+
compilerOptions: {
|
|
32
|
+
target: 'ES2022', module: 'Preserve', moduleResolution: 'Bundler',
|
|
33
|
+
strict: true, skipLibCheck: true, noEmit: true,
|
|
34
|
+
paths: { 'capable-kit': [resolve(packageDirectory, 'dist/index.d.mts')] },
|
|
35
|
+
}, files: ['./case.ts'],
|
|
36
|
+
}));
|
|
37
|
+
const result = spawnSync(process.execPath, [compiler, '-p', join(temporary, 'tsconfig.json')], { encoding: 'utf8' });
|
|
38
|
+
console.log(JSON.stringify({ form, exit: result.status, diagnostics: result.stdout + result.stderr }));
|
|
39
|
+
if (result.error) throw result.error;
|
|
40
|
+
}
|
|
41
|
+
} finally {
|
|
42
|
+
rmSync(temporary, { recursive: true, force: true });
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Run after pnpm build. Optional argument: absolute capable-kit package directory.
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { realpathSync } from 'node:fs';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
const directory = process.argv[2] ?? resolve('packages/capable');
|
|
9
|
+
const entry = pathToFileURL(realpathSync(resolve(directory, 'dist/index.mjs')));
|
|
10
|
+
const { capability, defineApp, createApp } = await import(entry.href);
|
|
11
|
+
const { createCli } = await import(new URL('./cli.mjs', entry).href);
|
|
12
|
+
const { render } = await import(createRequire(entry).resolve('markdansi'));
|
|
13
|
+
|
|
14
|
+
for (const required of [true, false]) {
|
|
15
|
+
const app = createApp(defineApp({
|
|
16
|
+
name: 'v-ray',
|
|
17
|
+
capabilities: { analysis: { url: capability({
|
|
18
|
+
id: 'analysis.url',
|
|
19
|
+
description: 'Inspect a URL.',
|
|
20
|
+
input: z.object({ url: required ? z.string() : z.string().default('example.com') }),
|
|
21
|
+
meta: { cli: { command: [], positional: ['url'] } },
|
|
22
|
+
handler: ({ input }) => input,
|
|
23
|
+
}) } },
|
|
24
|
+
}));
|
|
25
|
+
for (const argv of [[], ['--help'], ['-h'], ['--help', '--'], ['vercel.com'], ['--json'], ['--wat'], ['one', 'two'], ['--', 'vercel.com']]) {
|
|
26
|
+
const stdout = [], stderr = [];
|
|
27
|
+
const exit = await createCli(app, { invocationName: 'pnpm cli', isTTY: false, color: false })
|
|
28
|
+
.run(argv, { io: { stdout: text => stdout.push(text), stderr: text => stderr.push(text) } });
|
|
29
|
+
console.log(JSON.stringify({ required, argv, exit, stdout, stderr }));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (const markdown of ['First paragraph\n\nSecond paragraph', '### Headers\n\n```\nserver Vercel\ncache HIT\n```\n\nFooter', '| Header | Value |\n| --- | --- |\n| server | Vercel |']) {
|
|
33
|
+
for (const settings of [{}, { codeBox: false, tableBorder: 'none', tableDense: true }]) {
|
|
34
|
+
console.log(JSON.stringify({ markdown, settings, rendered: render(markdown, { color: false, width: 80, ...settings }) }));
|
|
35
|
+
}
|
|
36
|
+
}
|