@arcforge/platform 2.0.218 → 2.0.244
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/package.json +27 -19
- package/src/build/blueprint/blueprint.ts +48 -64
- package/src/build/blueprint/cognet/abi.ts +3 -257
- package/src/build/blueprint/cognet/bundle-worker.ts +11 -0
- package/src/build/blueprint/cognet/bundle.ts +294 -89
- package/src/build/blueprint/cognet/cognet.ts +8 -7
- package/src/build/blueprint/cognet/config/config.ts +52 -0
- package/src/build/blueprint/cognet/config/index.ts +4 -0
- package/src/build/blueprint/cognet/config/literal.ts +83 -0
- package/src/build/blueprint/cognet/config/provider.ts +43 -0
- package/src/build/blueprint/cognet/config/shape.ts +183 -0
- package/src/build/blueprint/cognet/index.ts +4 -2
- package/src/build/blueprint/cognet/native/cargo.ts +31 -0
- package/src/build/blueprint/cognet/native/crate.ts +126 -0
- package/src/build/blueprint/cognet/native/index.ts +2 -0
- package/src/build/blueprint/cognet/native/library.ts +125 -0
- package/src/build/blueprint/cognet/native/manifest.ts +137 -0
- package/src/build/blueprint/cognet/python/index.ts +1 -0
- package/src/build/blueprint/cognet/python/project.ts +119 -0
- package/src/build/blueprint/cognet/schema/arrays.ts +23 -0
- package/src/build/blueprint/cognet/schema/authored.ts +273 -0
- package/src/build/blueprint/cognet/schema/compile.ts +78 -0
- package/src/build/blueprint/cognet/schema/components/external.ts +15 -0
- package/src/build/blueprint/cognet/schema/components/index.ts +3 -0
- package/src/build/blueprint/cognet/schema/components/lock.ts +58 -0
- package/src/build/blueprint/cognet/schema/components/model.ts +34 -0
- package/src/build/blueprint/cognet/schema/components/python.ts +15 -0
- package/src/build/blueprint/cognet/schema/components/python_source.py +69 -0
- package/src/build/blueprint/cognet/schema/components/rust.ts +33 -0
- package/src/build/blueprint/cognet/schema/components/rust_source/Cargo.lock +117 -0
- package/src/build/blueprint/cognet/schema/components/rust_source/Cargo.toml +11 -0
- package/src/build/blueprint/cognet/schema/components/rust_source/src/main.rs +104 -0
- package/src/build/blueprint/cognet/schema/components/source.ts +220 -0
- package/src/build/blueprint/cognet/schema/components/tags.ts +66 -0
- package/src/build/blueprint/cognet/schema/components/typescript.ts +157 -0
- package/src/build/blueprint/cognet/schema/index.ts +5 -0
- package/src/build/blueprint/cognet/schema/interfaces/index.ts +3 -0
- package/src/build/blueprint/cognet/schema/interfaces/source.ts +218 -0
- package/src/build/blueprint/cognet/schema/python.ts +260 -0
- package/src/build/blueprint/cognet/schema/rust.ts +316 -0
- package/src/build/blueprint/cognet/schema/schema.ts +248 -0
- package/src/build/blueprint/cognet/schema/typescript.ts +352 -0
- package/src/build/blueprint/index.ts +1 -1
- package/src/build/blueprint/modules/index.ts +7 -5
- package/src/build/blueprint/modules/meta.ts +47 -3
- package/src/build/blueprint/scan/config.ts +22 -16
- package/src/build/blueprint/scan/provider-globals.ts +46 -0
- package/src/build/blueprint/scan/providers.ts +25 -0
- package/src/build/blueprint/scan/tools.ts +21 -15
- package/src/build/extensions/edit.ts +66 -2
- package/src/build/extensions/extensions.ts +16 -3
- package/src/build/extensions/index.ts +1 -1
- package/src/build/project/bundle/agent.ts +26 -17
- package/src/build/project/bundle/source.ts +2 -2
- package/src/build/project/create/cognet.ts +84 -33
- package/src/build/project/create/profile.ts +13 -3
- package/src/build/project/index.ts +1 -1
- package/src/build/project/installer.ts +6 -5
- package/src/build/project/kinds.ts +4 -0
- package/src/build/project/manifest/env.ts +10 -0
- package/src/build/project/models/blobs/blobs.ts +57 -0
- package/src/build/project/models/blobs/index.ts +1 -0
- package/src/build/project/models/fetch.ts +46 -51
- package/src/build/project/models/index.ts +2 -1
- package/src/build/project/models/models.ts +12 -38
- package/src/build/project/models/onnx.ts +82 -0
- package/src/build/project/models/specifier.ts +9 -3
- package/src/build/project/models/storage/index-store.ts +27 -0
- package/src/build/project/models/storage/index.ts +1 -0
- package/src/build/project/models/store.ts +21 -16
- package/src/build/project/prepare.ts +82 -27
- package/src/build/project/project.ts +8 -14
- package/src/build/project/projects.ts +12 -1
- package/src/build/project/tree.ts +13 -3
- package/src/build/project/treecache.ts +8 -4
- package/src/build/project/typegen/axon-dts.ts +18 -0
- package/src/build/project/typegen/cognet-dts.ts +248 -59
- package/src/build/project/typegen/prompt-dts.ts +2 -3
- package/src/build/project/typegen/registry-dts.ts +2 -2
- package/src/build/project/typegen/tsconfig.ts +13 -13
- package/src/build/project/typegen/tui-dts.ts +3 -4
- package/src/build/project/typegen/workspace-scripts.ts +8 -7
- package/src/build/project/typegen/write.ts +15 -2
- package/src/build/project/watcher.ts +27 -0
- package/src/build/runtime/agent.ts +102 -63
- package/src/build/runtime/conformance.ts +25 -0
- package/src/build/runtime/escalations.ts +3 -8
- package/src/build/runtime/index.ts +2 -0
- package/src/build/runtime/instances.ts +7 -4
- package/src/build/runtime/progress.ts +6 -2
- package/src/build/runtime/reload-watch.ts +11 -8
- package/src/debug/README.md +398 -0
- package/src/debug/debug.ts +101 -0
- package/src/debug/events.ts +156 -0
- package/src/debug/graph.ts +94 -0
- package/src/debug/index.ts +5 -0
- package/src/debug/indexer.ts +286 -0
- package/src/debug/inference.ts +53 -0
- package/src/debug/log.ts +68 -0
- package/src/debug/overview.ts +78 -0
- package/src/debug/perf.ts +75 -0
- package/src/debug/resources.ts +125 -0
- package/src/debug/ring.ts +31 -0
- package/src/debug/sessions.ts +90 -0
- package/src/debug/signs.ts +119 -0
- package/src/debug/tally.ts +44 -0
- package/src/debug/types.ts +146 -0
- package/src/index.ts +9 -0
- package/src/link/agent-main.ts +36 -10
- package/src/link/index.ts +1 -1
- package/src/link/services.ts +88 -57
- package/src/platform.ts +17 -25
- package/src/services/cloud.ts +1 -4
- package/src/services/control/client.ts +1 -1
- package/src/services/control/server.ts +1 -1
- package/src/services/index.ts +1 -0
- package/src/services/ollama/daemon.ts +23 -0
- package/src/services/ollama/http.ts +7 -1
- package/src/services/ollama/ollama.ts +8 -14
- package/src/services/probe/ask.ts +139 -0
- package/src/services/probe/index.ts +3 -0
- package/src/services/providers.ts +18 -0
- package/src/services/resources/hardware.ts +15 -18
- package/src/services/resources/resources.ts +4 -5
- package/src/services/store/types.ts +3 -0
- package/src/services/running/index.ts +0 -1
- package/src/services/running/running.ts +0 -216
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcforge/platform",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.244",
|
|
4
|
+
"license": "Apache-2.0",
|
|
4
5
|
"description": "The Axon developer platform — headless project discovery, blueprint scanning, typegen, agent lifecycle, registry, benches and tests. Shared by the CLI/TUI and the Fleet extension.",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"private": false,
|
|
@@ -28,43 +29,50 @@
|
|
|
28
29
|
"./services/control": "./src/services/control/index.ts",
|
|
29
30
|
"./services/mic": "./src/services/mic/index.ts",
|
|
30
31
|
"./services/ollama": "./src/services/ollama/index.ts",
|
|
31
|
-
"./services/
|
|
32
|
+
"./services/probe": "./src/services/probe/index.ts",
|
|
32
33
|
"./store": "./src/services/store/index.ts",
|
|
33
34
|
"./test": "./src/services/test/index.ts",
|
|
34
35
|
"./update": "./src/services/update/index.ts"
|
|
35
36
|
},
|
|
36
37
|
"files": [
|
|
37
|
-
"src"
|
|
38
|
+
"src",
|
|
39
|
+
"!src/**/target"
|
|
38
40
|
],
|
|
39
41
|
"scripts": {
|
|
40
|
-
"test": "bun test
|
|
41
|
-
"test:
|
|
42
|
+
"test": "bun run test:full",
|
|
43
|
+
"test:hot": "bun test --parallel=4 tests/hot",
|
|
44
|
+
"test:full": "bun test",
|
|
45
|
+
"test:serial": "bun run test:full",
|
|
42
46
|
"test:watch": "bun test --watch",
|
|
43
47
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
44
48
|
"deploy": "echo \"This package is published ONLY by apps/tui/scripts/release.ts, which pins workspace:* deps to concrete versions first. Publishing it directly ships an unresolvable dependency.\" && exit 1"
|
|
45
49
|
},
|
|
46
50
|
"dependencies": {
|
|
47
|
-
"@arcforge/
|
|
48
|
-
"@arcforge/
|
|
49
|
-
"@arcforge/
|
|
50
|
-
"@arcforge/
|
|
51
|
-
"@arcforge/
|
|
52
|
-
"@arcforge/
|
|
53
|
-
"@arcforge/
|
|
54
|
-
"@arcforge/
|
|
51
|
+
"@arcforge/capsule": "2.0.244",
|
|
52
|
+
"@arcforge/cloud": "2.0.244",
|
|
53
|
+
"@arcforge/core": "2.0.244",
|
|
54
|
+
"@arcforge/engines": "2.0.244",
|
|
55
|
+
"@arcforge/err": "2.0.244",
|
|
56
|
+
"@arcforge/link": "2.0.244",
|
|
57
|
+
"@arcforge/session": "2.0.244",
|
|
58
|
+
"@arcforge/types": "2.0.244",
|
|
59
|
+
"@arcforge/vstr": "2.0.244",
|
|
60
|
+
"@bufbuild/buf": "^1.73.0",
|
|
61
|
+
"@bufbuild/protobuf": "^2.16.0",
|
|
55
62
|
"fft.js": "^4.0.4",
|
|
56
63
|
"h3": "^1.15.11",
|
|
64
|
+
"proper-lockfile": "4.1.2",
|
|
57
65
|
"semver": "^7.7.4",
|
|
58
66
|
"sharp": "^0.35.3",
|
|
59
|
-
"typescript": "5.9.2"
|
|
60
|
-
"@arcforge/link": "2.0.218"
|
|
67
|
+
"typescript": "5.9.2"
|
|
61
68
|
},
|
|
62
69
|
"devDependencies": {
|
|
63
|
-
"@arcforge/air": "
|
|
64
|
-
"@arcforge/cognet": "
|
|
65
|
-
"@arclabs/repo": "
|
|
70
|
+
"@arcforge/air": "workspace:*",
|
|
71
|
+
"@arcforge/cognet": "workspace:*",
|
|
72
|
+
"@arclabs/repo": "workspace:*",
|
|
66
73
|
"@types/bun": "latest",
|
|
74
|
+
"@types/proper-lockfile": "^4.1.4",
|
|
67
75
|
"@types/semver": "^7.7.1"
|
|
68
76
|
},
|
|
69
|
-
"axonRevision": "
|
|
77
|
+
"axonRevision": "6b7c31b386531c7829eb28a9f00480022cdc01f8"
|
|
70
78
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto"
|
|
2
2
|
import { dirname, join, relative, resolve } from "node:path"
|
|
3
|
-
import type { AxonPartialBlueprint, EngineRequirements } from "@arcforge/types"
|
|
4
|
-
import { err } from "@arcforge/err"
|
|
3
|
+
import type { AxonPartialBlueprint, CognetConfig, EngineRequirements } from "@arcforge/types"
|
|
4
|
+
import { err, errorMap, isAxonError } from "@arcforge/err"
|
|
5
5
|
import { fsx } from "../../utils/fs"
|
|
6
6
|
import { merge } from "./collisions"
|
|
7
7
|
import { workspaceRoot } from "./workspace"
|
|
@@ -14,9 +14,12 @@ import { Knowledge } from "./scan/knowledge"
|
|
|
14
14
|
import { Routes } from "./scan/routes"
|
|
15
15
|
import { Middleware } from "./scan/middleware"
|
|
16
16
|
import { Scripts } from "./scan/scripts"
|
|
17
|
+
import { Providers } from "./scan/providers"
|
|
18
|
+
import { checkGrants } from "@arcforge/core"
|
|
17
19
|
import { Tools } from "./scan/tools"
|
|
18
|
-
import { Cognet, cognetSourceOf,
|
|
20
|
+
import { Cognet, cognetSourceOf, CognetConfigFile } from "./cognet"
|
|
19
21
|
import { Models } from "../project/models"
|
|
22
|
+
import { Manifest } from "../project/manifest"
|
|
20
23
|
import { Frame } from "../frame"
|
|
21
24
|
import type { LoadedConfig } from "./scan/config"
|
|
22
25
|
import type { ScanWarning } from "./types"
|
|
@@ -107,6 +110,16 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
107
110
|
* Absent means no ceiling, which is the honest state for a
|
|
108
111
|
* deployment and for `axon run` outside a profile.
|
|
109
112
|
*/
|
|
113
|
+
/**
|
|
114
|
+
* What the INVOCATION says, over and above the agent's own `.env`.
|
|
115
|
+
*
|
|
116
|
+
* One run's facts, not the agent's: `axon <ref> -c world://…`
|
|
117
|
+
* puts the world address here, so the same agent can be sent to a
|
|
118
|
+
* different world without editing a file. Carried like `models`
|
|
119
|
+
* and `profilePolicy` — this module knows a directory, and whoever
|
|
120
|
+
* invoked knows what they asked for.
|
|
121
|
+
*/
|
|
122
|
+
env?: Readonly<Record<string, string>>
|
|
110
123
|
profilePolicy?: AxonPartialBlueprint["profilePolicy"]
|
|
111
124
|
/**
|
|
112
125
|
* The inference sources the owning profile declares.
|
|
@@ -152,7 +165,7 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
152
165
|
if (loadOpts.compile) await cognet.compile(cognetSourceOf(config))
|
|
153
166
|
|
|
154
167
|
// Agent surfaces + modules, plus workspace prompts/scripts when available.
|
|
155
|
-
const [prompts, scripts, tools, routes, plugins, middleware, knowledge, boot, modules, brain, workspacePrompts, workspaceScripts] = await Promise.all([
|
|
168
|
+
const [prompts, scripts, tools, routes, plugins, middleware, knowledge, boot, modules, brain, workspacePrompts, workspaceScripts, serviceProviders] = await Promise.all([
|
|
156
169
|
Prompts(root),
|
|
157
170
|
|
|
158
171
|
Scripts(root),
|
|
@@ -179,6 +192,7 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
179
192
|
// They remain namespaced so a repo cannot silently replace
|
|
180
193
|
// an agent-owned script with the same filename.
|
|
181
194
|
: Scripts(workspace, { prefix: "workspace", dir: "scripts", required: false }),
|
|
195
|
+
Providers(root),
|
|
182
196
|
])
|
|
183
197
|
for (const scanned of [prompts, scripts, tools, routes, plugins, middleware, knowledge, workspacePrompts, workspaceScripts]) warnings.push(...scanned.warnings)
|
|
184
198
|
warnings.push(...boot.warnings, ...modules.warnings, ...brain.warnings)
|
|
@@ -235,14 +249,19 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
235
249
|
// Weights: whatever the caller resolved, or resolve them here.
|
|
236
250
|
// A brain that declared models and received none is broken in a
|
|
237
251
|
// way that only shows up at first inference.
|
|
238
|
-
const
|
|
252
|
+
const declared = declaredConfig(cognet, config)
|
|
253
|
+
const models = loadOpts.models ?? await resolveDeclaredModels(declared)
|
|
239
254
|
|
|
240
255
|
// The roles this brain needs, read from its own config at build
|
|
241
256
|
// time so the runtime can resolve them BEFORE loading the bundle.
|
|
242
257
|
// A required role nothing can fill has to stop the boot, and a
|
|
243
258
|
// brain that has already loaded is one that will reach for a
|
|
244
259
|
// missing engine mid-wake.
|
|
245
|
-
const engines =
|
|
260
|
+
const engines: EngineRequirements = declared?.engines ?? {}
|
|
261
|
+
|
|
262
|
+
// What can be known of the agent's grants before it runs: each names a use the cognet declares,
|
|
263
|
+
// a provider it wrote, or a route an engine may serve. Whether a route answers is the boot's to find.
|
|
264
|
+
if (brain.entry) checkGrants(brain.entry.uses ?? {}, config.value.services, serviceProviders)
|
|
246
265
|
|
|
247
266
|
const agent = await identity(root)
|
|
248
267
|
|
|
@@ -252,7 +271,7 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
252
271
|
...("bootFilePath" in boot ? { bootFilePath: boot.bootFilePath } : {}),
|
|
253
272
|
config: config.value,
|
|
254
273
|
...(loadOpts.profilePolicy ? { profilePolicy: loadOpts.profilePolicy } : {}),
|
|
255
|
-
...(loadOpts.profileProviders
|
|
274
|
+
...(loadOpts.profileProviders !== undefined ? { profileProviders: loadOpts.profileProviders } : {}),
|
|
256
275
|
// absent = unprepared agent; core's normalizer refuses loudly (NO_COGNET)
|
|
257
276
|
...(brain.entry
|
|
258
277
|
? {
|
|
@@ -263,7 +282,10 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
263
282
|
},
|
|
264
283
|
}
|
|
265
284
|
: {}),
|
|
266
|
-
env
|
|
285
|
+
// The agent's own `.env`, with what this invocation said laid
|
|
286
|
+
// over it — the address an agent was SENT to beats the one it
|
|
287
|
+
// was last configured with.
|
|
288
|
+
env: { ...await Manifest({ root: root }).env.values(), ...loadOpts.env },
|
|
267
289
|
// The supervisor's own credentials — read from the host here,
|
|
268
290
|
// where the CLI legitimately owns process.env, and deliberately
|
|
269
291
|
// NOT merged into `env`, which is what reaches the box.
|
|
@@ -271,6 +293,7 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
271
293
|
tools: mergedTools.merged,
|
|
272
294
|
prompts: mergedPrompts.merged,
|
|
273
295
|
scripts: mergedScripts.merged,
|
|
296
|
+
serviceProviders: serviceProviders,
|
|
274
297
|
knowledge: mergedKnowledge,
|
|
275
298
|
modules: modules.modules,
|
|
276
299
|
server: {
|
|
@@ -295,50 +318,33 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
295
318
|
export type BlueprintT = ReturnType<typeof Blueprint>
|
|
296
319
|
|
|
297
320
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* pure filesystem work — prepare fetched and verified it. A cognet that
|
|
303
|
-
* declares nothing costs one file read.
|
|
321
|
+
* What the agent's cognet declares — null when it has no config, or when the
|
|
322
|
+
* brain isn't installed. That one absence is not raised here: the normalizer
|
|
323
|
+
* raises it, once, and reporting it from two layers only makes the first
|
|
324
|
+
* wrong. Every other failure — a config that won't read — is this layer's.
|
|
304
325
|
*/
|
|
305
|
-
|
|
306
|
-
cognet: CognetT,
|
|
307
|
-
config: LoadedConfig,
|
|
308
|
-
): Promise<Readonly<Record<string, string>>> {
|
|
326
|
+
function declaredConfig(cognet: ReturnType<typeof Cognet>, config: LoadedConfig): CognetConfig | null {
|
|
309
327
|
let sourceDir: string
|
|
310
328
|
try {
|
|
311
329
|
sourceDir = cognet.sourceDir(cognetSourceOf(config))
|
|
312
|
-
} catch {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return {}
|
|
330
|
+
} catch (error) {
|
|
331
|
+
if (isAxonError(error) && error.code === errorMap.COGNET_NOT_FOUND.code) return null
|
|
332
|
+
throw error
|
|
316
333
|
}
|
|
317
|
-
|
|
318
|
-
const declared = await readCognetModels(sourceDir)
|
|
319
|
-
if (Object.keys(declared).length === 0) return {}
|
|
320
|
-
|
|
321
|
-
const { paths } = await Models().resolve(declared)
|
|
322
|
-
return paths
|
|
334
|
+
return CognetConfigFile({ sourceDir: sourceDir }).read()
|
|
323
335
|
}
|
|
324
336
|
|
|
325
337
|
/**
|
|
326
|
-
* The
|
|
338
|
+
* The cognet's declared weights, resolved to absolute paths.
|
|
327
339
|
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
* one wrong.
|
|
340
|
+
* Resolves through the shared cache. In the ordinary case everything is
|
|
341
|
+
* already there and this is pure filesystem work — prepare fetched and
|
|
342
|
+
* verified it.
|
|
332
343
|
*/
|
|
333
|
-
async function
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
try {
|
|
338
|
-
return await readCognetEngines(cognet.sourceDir(cognetSourceOf(config)))
|
|
339
|
-
} catch {
|
|
340
|
-
return {}
|
|
341
|
-
}
|
|
344
|
+
async function resolveDeclaredModels(declared: CognetConfig | null): Promise<Readonly<Record<string, string>>> {
|
|
345
|
+
if (!declared?.models || Object.keys(declared.models).length === 0) return {}
|
|
346
|
+
const { paths } = await Models().resolve(declared.models)
|
|
347
|
+
return paths
|
|
342
348
|
}
|
|
343
349
|
|
|
344
350
|
// ─── Identity ─────────────────────────────────────────────────────────────────
|
|
@@ -424,25 +430,3 @@ function hostEnv(): Record<string, string> {
|
|
|
424
430
|
return out
|
|
425
431
|
}
|
|
426
432
|
|
|
427
|
-
async function resolvedEnv(root: string): Promise<Record<string, string>> {
|
|
428
|
-
const content = await fsx.readText(join(root, ".env"))
|
|
429
|
-
return content ? parseDotenv(content) : {}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/** Parse key=value pairs from a .env file's contents. Comments and blank lines skipped. */
|
|
433
|
-
function parseDotenv(content: string): Record<string, string> {
|
|
434
|
-
const result: Record<string, string> = {}
|
|
435
|
-
for (const line of content.split(/\r?\n/)) {
|
|
436
|
-
const trimmed = line.trim()
|
|
437
|
-
if (!trimmed || trimmed.startsWith("#")) continue
|
|
438
|
-
const eqIdx = trimmed.indexOf("=")
|
|
439
|
-
if (eqIdx < 0) continue
|
|
440
|
-
const key = trimmed.slice(0, eqIdx).trim()
|
|
441
|
-
let val = trimmed.slice(eqIdx + 1).trim()
|
|
442
|
-
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
443
|
-
val = val.slice(1, -1)
|
|
444
|
-
}
|
|
445
|
-
if (key) result[key] = val
|
|
446
|
-
}
|
|
447
|
-
return result
|
|
448
|
-
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { join } from "node:path"
|
|
2
1
|
import { err } from "@arcforge/err"
|
|
3
2
|
import { KERNEL_ABI_VERSION } from "@arcforge/types"
|
|
4
|
-
import
|
|
5
|
-
import { fsx } from "../../../utils/fs"
|
|
3
|
+
import { CognetConfigFile } from "./config"
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Verify an installed cognet does not target an ABI this kernel cannot provide.
|
|
@@ -23,14 +21,10 @@ import { fsx } from "../../../utils/fs"
|
|
|
23
21
|
* so it targets this ABI by construction. A pin exists to make a cognet REFUSE
|
|
24
22
|
* a kernel it has not been validated against — an assertion the author opts
|
|
25
23
|
* into, not a field every cognet must restate.
|
|
26
|
-
*
|
|
27
|
-
* Read with a regex rather than by evaluating the config: this runs before
|
|
28
|
-
* anything has compiled the cognet, and evaluating an arbitrary published
|
|
29
|
-
* config to read one field is a far larger operation than reading the field.
|
|
30
24
|
*/
|
|
31
25
|
export async function cognetAbi(sourceDir: string, specifier: string): Promise<string> {
|
|
32
|
-
const declared =
|
|
33
|
-
if (declared ===
|
|
26
|
+
const declared = CognetConfigFile({ sourceDir: sourceDir }).read()?.abi
|
|
27
|
+
if (declared === undefined) return KERNEL_ABI_VERSION
|
|
34
28
|
|
|
35
29
|
if (declared !== KERNEL_ABI_VERSION) {
|
|
36
30
|
throw err("COGNET_ABI_MISMATCH", {
|
|
@@ -43,251 +37,3 @@ export async function cognetAbi(sourceDir: string, specifier: string): Promise<s
|
|
|
43
37
|
|
|
44
38
|
return declared
|
|
45
39
|
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The ABI a cognet source project PINS, or null when it pins none.
|
|
49
|
-
*
|
|
50
|
-
* Split out from cognetAbi() because three callers need the value for
|
|
51
|
-
* different reasons: prepare compares a pin against this kernel (cognetAbi),
|
|
52
|
-
* the compile step stamps the resolved value into the artifact, and PUBLISH
|
|
53
|
-
* records it on the version row so the registry can answer "newest cognet that
|
|
54
|
-
* fits ABI N" without downloading a tarball.
|
|
55
|
-
*
|
|
56
|
-
* Publishing must not COMPARE against the publishing machine's kernel — a
|
|
57
|
-
* cognet pinning ABI 10 is perfectly publishable from a CLI running ABI 9, and
|
|
58
|
-
* refusing it would make the registry unable to hold anything but the present.
|
|
59
|
-
* It may still fall back to it, because publish compiles from source with this
|
|
60
|
-
* CLI: an unpinned cognet genuinely was validated against this kernel, so
|
|
61
|
-
* stamping that on the row is a fact rather than a guess.
|
|
62
|
-
*
|
|
63
|
-
* Null, never a throw. An absent pin is the ordinary case — see CognetConfig's
|
|
64
|
-
* `abi` — and every caller has a truthful default: this kernel's ABI.
|
|
65
|
-
*/
|
|
66
|
-
export async function readCognetAbi(sourceDir: string): Promise<string | null> {
|
|
67
|
-
const source = await fsx.readText(join(sourceDir, "cognet.config.ts"))
|
|
68
|
-
if (source === null) return null
|
|
69
|
-
|
|
70
|
-
return source.match(/\babi\s*:\s*["'`]([^"'`]+)["'`]/)?.[1] ?? null
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* The `models:` a cognet source project declares.
|
|
75
|
-
*
|
|
76
|
-
* Read textually, for the same reason the ABI is: this runs before anything
|
|
77
|
-
* has compiled the cognet, and evaluating an arbitrary published config to
|
|
78
|
-
* read one field is a far larger operation than reading the field. It also
|
|
79
|
-
* runs on a cognet that has not had its dependencies installed yet, where
|
|
80
|
-
* evaluation would fail outright.
|
|
81
|
-
*
|
|
82
|
-
* Deliberately narrow: it matches the `models: { ... }` object literal and
|
|
83
|
-
* pulls `key: "specifier"` pairs out of it. A computed or imported value is
|
|
84
|
-
* not recognised, and that is the honest limit of a textual read — declaring
|
|
85
|
-
* weights is a static fact about a brain, not something a config should be
|
|
86
|
-
* computing.
|
|
87
|
-
*/
|
|
88
|
-
export async function readCognetModels(sourceDir: string): Promise<Record<string, import("@arcforge/types").ModelRef>> {
|
|
89
|
-
const source = await fsx.readText(join(sourceDir, "cognet.config.ts"))
|
|
90
|
-
if (source === null) return {}
|
|
91
|
-
|
|
92
|
-
const opener = source.match(/\bmodels\s*:\s*\{/)
|
|
93
|
-
if (!opener?.index) return {}
|
|
94
|
-
|
|
95
|
-
const from = opener.index + opener[0].length - 1
|
|
96
|
-
let depth = 0
|
|
97
|
-
let close = -1
|
|
98
|
-
for (let i = from; i < source.length; i++) {
|
|
99
|
-
if (source[i] === "{") depth++
|
|
100
|
-
else if (source[i] === "}") {
|
|
101
|
-
depth--
|
|
102
|
-
if (depth === 0) {
|
|
103
|
-
close = i
|
|
104
|
-
break
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (close < 0) return {}
|
|
109
|
-
|
|
110
|
-
const body = source.slice(from + 1, close)
|
|
111
|
-
const models: Record<string, import("@arcforge/types").ModelRef> = {}
|
|
112
|
-
|
|
113
|
-
// Entries belong to the indentation level immediately inside the models map.
|
|
114
|
-
// Derive it from the authored source rather than assuming a formatter width.
|
|
115
|
-
const lineStart = source.lastIndexOf("\n", opener.index) + 1
|
|
116
|
-
const propertyIndent = source.slice(lineStart, opener.index).match(/^[ \\t]*/)?.[0].length ?? 0
|
|
117
|
-
const header = new RegExp(`^([ \\t]{${propertyIndent + 1},})([A-Za-z_$][\\w$]*)\\s*:\\s*`, "gm")
|
|
118
|
-
|
|
119
|
-
for (let match = header.exec(body); match; match = header.exec(body)) {
|
|
120
|
-
const key = match[2]!
|
|
121
|
-
const rest = body.slice(header.lastIndex).trimStart()
|
|
122
|
-
|
|
123
|
-
if (rest[0] === '"' || rest[0] === "'" || rest[0] === "`") {
|
|
124
|
-
const quote = rest[0]
|
|
125
|
-
const endQuote = rest.indexOf(quote, 1)
|
|
126
|
-
if (endQuote >= 0) models[key] = rest.slice(1, endQuote)
|
|
127
|
-
continue
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (rest[0] !== "{") continue
|
|
131
|
-
let nested = 0
|
|
132
|
-
let endObject = -1
|
|
133
|
-
for (let i = 0; i < rest.length; i++) {
|
|
134
|
-
if (rest[i] === "{") nested++
|
|
135
|
-
else if (rest[i] === "}") {
|
|
136
|
-
nested--
|
|
137
|
-
if (nested === 0) {
|
|
138
|
-
endObject = i
|
|
139
|
-
break
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (endObject < 0) continue
|
|
144
|
-
|
|
145
|
-
const object = rest.slice(0, endObject + 1)
|
|
146
|
-
const hf = object.match(/\bhf\s*:\s*["'`]([^"'`]+)["'`]/)?.[1]
|
|
147
|
-
if (!hf) continue
|
|
148
|
-
|
|
149
|
-
const ref: Record<string, unknown> = { hf }
|
|
150
|
-
const file = object.match(/\bfile\s*:\s*["'`]([^"'`]+)["'`]/)?.[1]
|
|
151
|
-
if (file) ref.file = file
|
|
152
|
-
if (/\bset\s*:\s*true\b/.test(object)) ref.set = true
|
|
153
|
-
const rev = object.match(/\brev\s*:\s*["'`]([^"'`]+)["'`]/)?.[1]
|
|
154
|
-
if (rev) ref.rev = rev
|
|
155
|
-
const sha256 = object.match(/\bsha256\s*:\s*["'`]([^"'`]+)["'`]/)?.[1]
|
|
156
|
-
if (sha256) ref.sha256 = sha256
|
|
157
|
-
const capability = object.match(/\bcapability\s*:\s*["'`]([^"'`]+)["'`]/)?.[1]
|
|
158
|
-
if (capability) ref.capability = capability
|
|
159
|
-
const type = object.match(/\btype\s*:\s*["'`](generate|transform|stream)["'`]/)?.[1]
|
|
160
|
-
if (type) ref.type = type
|
|
161
|
-
for (const field of ["in", "out"] as const) {
|
|
162
|
-
const values = object.match(new RegExp("\\b" + field + "\\s*:\\s*\\[([^\\]]*)\\]"))?.[1]
|
|
163
|
-
if (values) ref[field] = [...values.matchAll(/["'`]([^"'`]+)["'`]/g)].map(item => item[1])
|
|
164
|
-
}
|
|
165
|
-
models[key] = ref as import("@arcforge/types").ModelRef
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return models
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* The `engines:` a cognet source project declares.
|
|
173
|
-
*
|
|
174
|
-
* Read textually, for the same reasons `models:` is: this runs before
|
|
175
|
-
* anything has compiled the cognet and before its dependencies are
|
|
176
|
-
* installed, so evaluating the config is not available even in principle.
|
|
177
|
-
*
|
|
178
|
-
* Unlike `models:`, the value is a map of OBJECTS, so the block cannot be
|
|
179
|
-
* found with a lazy `\{([\s\S]*?)\}` — the first `}` closes the first role,
|
|
180
|
-
* not the map. Braces are matched instead, which is the smallest thing that
|
|
181
|
-
* reads this shape correctly rather than the smallest thing that looks like
|
|
182
|
-
* it does.
|
|
183
|
-
*
|
|
184
|
-
* Declaring inference is a static fact about a brain, exactly like declaring
|
|
185
|
-
* weights: a computed or imported value is not recognised, and that is the
|
|
186
|
-
* honest limit rather than a bug to work around.
|
|
187
|
-
*/
|
|
188
|
-
export async function readCognetEngines(sourceDir: string): Promise<EngineRequirements> {
|
|
189
|
-
const source = await fsx.readText(join(sourceDir, "cognet.config.ts"))
|
|
190
|
-
if (source === null) return {}
|
|
191
|
-
|
|
192
|
-
const body = balanced(source, /\bengines\s*:\s*\{/)
|
|
193
|
-
if (body === null) return {}
|
|
194
|
-
|
|
195
|
-
const engines: EngineRequirements = {}
|
|
196
|
-
for (const [role, block] of roles(body)) {
|
|
197
|
-
const requirement = parseRequirement(block)
|
|
198
|
-
if (requirement) engines[role] = requirement
|
|
199
|
-
}
|
|
200
|
-
return engines
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/** The text inside the first `{...}` following `opener`, with nesting respected. */
|
|
204
|
-
function balanced(source: string, opener: RegExp): string | null {
|
|
205
|
-
const start = source.match(opener)
|
|
206
|
-
if (start?.index === undefined) return null
|
|
207
|
-
|
|
208
|
-
let depth = 0
|
|
209
|
-
const from = start.index + start[0].length - 1
|
|
210
|
-
for (let i = from; i < source.length; i++) {
|
|
211
|
-
if (source[i] === "{") depth++
|
|
212
|
-
else if (source[i] === "}") {
|
|
213
|
-
depth--
|
|
214
|
-
if (depth === 0) return source.slice(from + 1, i)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return null
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** `name: { ... }` pairs at the top level of an engines block. */
|
|
221
|
-
function roles(body: string): Array<[string, string]> {
|
|
222
|
-
const found: Array<[string, string]> = []
|
|
223
|
-
const header = /["'`]?([A-Za-z_$][\w$]*)["'`]?\s*:\s*\{/g
|
|
224
|
-
|
|
225
|
-
for (let match = header.exec(body); match; match = header.exec(body)) {
|
|
226
|
-
const block = balanced(body.slice(match.index), /\{/)
|
|
227
|
-
if (block === null) continue
|
|
228
|
-
found.push([match[1]!, block])
|
|
229
|
-
// Skip past this role's body so a nested key is never read as a role.
|
|
230
|
-
header.lastIndex = match.index + match[0].length + block.length
|
|
231
|
-
}
|
|
232
|
-
return found
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* One role's declaration.
|
|
237
|
-
*
|
|
238
|
-
* `type`, `in` and `out` are required — a requirement missing any of them
|
|
239
|
-
* cannot be matched against a capability, so it is DROPPED rather than
|
|
240
|
-
* defaulted. Guessing `text -> text` here would bind a role to a model that
|
|
241
|
-
* cannot serve it, which is the one failure this layer exists to move to
|
|
242
|
-
* prepare time.
|
|
243
|
-
*/
|
|
244
|
-
function parseRequirement(block: string): EngineRequirement | null {
|
|
245
|
-
const type = block.match(/\btype\s*:\s*["'`](generate|transform|stream)["'`]/)?.[1]
|
|
246
|
-
if (!type) return null
|
|
247
|
-
|
|
248
|
-
const modality = (field: "in" | "out"): Modality[] => {
|
|
249
|
-
const list = block.match(new RegExp(`\\b${field}\\s*:\\s*\\[([^\\]]*)\\]`))
|
|
250
|
-
if (list?.[1]) {
|
|
251
|
-
return [...list[1].matchAll(/["'`]([a-z]+)["'`]/g)].map(m => m[1] as Modality)
|
|
252
|
-
}
|
|
253
|
-
const single = block.match(new RegExp(`\\b${field}\\s*:\\s*["'\`]([a-z]+)["'\`]`))
|
|
254
|
-
return single?.[1] ? [single[1] as Modality] : []
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const inputs = modality("in")
|
|
258
|
-
const outputs = modality("out")
|
|
259
|
-
|
|
260
|
-
const preferred = balanced(block, /\bprefer\s*:\s*\{/)
|
|
261
|
-
const preferredModality = (field: "in" | "out"): Modality[] => {
|
|
262
|
-
if (preferred === null) return []
|
|
263
|
-
const list = preferred.match(new RegExp(`\\b${field}\\s*:\\s*\\[([^\\]]*)\\]`))
|
|
264
|
-
if (list?.[1]) return [...list[1].matchAll(/["'`]([a-z]+)["'`]/g)].map(m => m[1] as Modality)
|
|
265
|
-
const single = preferred.match(new RegExp(`\\b${field}\\s*:\\s*["'\`]([a-z]+)["'\`]`))
|
|
266
|
-
return single?.[1] ? [single[1] as Modality] : []
|
|
267
|
-
}
|
|
268
|
-
const preferIn = preferredModality("in")
|
|
269
|
-
const preferOut = preferredModality("out")
|
|
270
|
-
if (inputs.length === 0 || outputs.length === 0) return null
|
|
271
|
-
|
|
272
|
-
// Numeric separators are ordinary in a config (`100_000`), and a parse
|
|
273
|
-
// that read one as 100 would silently admit a model far too small.
|
|
274
|
-
const context = block.match(/\bcontext\s*:\s*([\d_]+)/)?.[1]
|
|
275
|
-
const flag = (name: string): boolean => new RegExp(`\\b${name}\\s*:\\s*true\\b`).test(block)
|
|
276
|
-
|
|
277
|
-
return {
|
|
278
|
-
type: type as EngineRequirement["type"],
|
|
279
|
-
in: inputs,
|
|
280
|
-
out: outputs,
|
|
281
|
-
...(preferIn.length || preferOut.length
|
|
282
|
-
? { prefer: {
|
|
283
|
-
...(preferIn.length ? { in: preferIn } : {}),
|
|
284
|
-
...(preferOut.length ? { out: preferOut } : {}),
|
|
285
|
-
} }
|
|
286
|
-
: {}),
|
|
287
|
-
...(context ? { context: Number(context.replaceAll("_", "")) } : {}),
|
|
288
|
-
...(flag("structured") ? { structured: true } : {}),
|
|
289
|
-
...(flag("parallel") ? { parallel: true } : {}),
|
|
290
|
-
...(flag("optional") ? { optional: true } : {}),
|
|
291
|
-
...(flag("primary") ? { primary: true } : {}),
|
|
292
|
-
}
|
|
293
|
-
}
|
|
@@ -44,6 +44,8 @@ if (!entryPath) {
|
|
|
44
44
|
* so it is the author's declaration doing the work, not a guess here.
|
|
45
45
|
*/
|
|
46
46
|
const external = (process.argv[3] ?? "").split(",").map(s => s.trim()).filter(Boolean)
|
|
47
|
+
/** Where `#schema/…` imports resolve: the agent frame's generated schema modules. Absent, a `#schema/` import fails to resolve, loudly. */
|
|
48
|
+
const schemaDir = process.argv[4] ?? ""
|
|
47
49
|
|
|
48
50
|
// Bun.build() reports most failures on the result (success:false + logs),
|
|
49
51
|
// but THROWS on others — an unresolvable import being the common one. An
|
|
@@ -60,6 +62,15 @@ try {
|
|
|
60
62
|
sourcemap: "external",
|
|
61
63
|
minify: false,
|
|
62
64
|
...(external.length ? { external } : {}),
|
|
65
|
+
plugins: [{
|
|
66
|
+
name: "cognet-schema",
|
|
67
|
+
setup(builder) {
|
|
68
|
+
builder.onResolve({ filter: /^#schema\// }, args => {
|
|
69
|
+
if (!schemaDir) throw new Error(`${args.path} is a cognet schema module, but this bundle was given no schema directory`)
|
|
70
|
+
return { path: `${schemaDir}/${args.path.slice("#schema/".length)}.ts` }
|
|
71
|
+
})
|
|
72
|
+
},
|
|
73
|
+
}],
|
|
63
74
|
})
|
|
64
75
|
} catch (cause) {
|
|
65
76
|
const detail = cause instanceof AggregateError
|