@arcforge/platform 2.0.198 → 2.0.200
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 +10 -10
- package/src/build/blueprint/blueprint.ts +30 -5
- package/src/build/blueprint/cognet/abi.ts +92 -6
- package/src/build/blueprint/cognet/bundle.ts +1 -0
- package/src/build/blueprint/workspace.ts +14 -0
- package/src/build/project/models/fetch.ts +58 -6
- package/src/build/project/models/models.ts +38 -0
- package/src/build/project/models/specifier.ts +20 -2
- package/src/build/project/models/store.ts +2 -1
- package/src/build/project/prepare.ts +4 -2
- package/src/build/project/project.ts +3 -0
- package/src/build/project/projects.ts +3 -0
- package/src/build/project/treecache.ts +41 -2
- package/src/build/project/typegen/cognet-dts.ts +61 -3
- package/src/build/runtime/agent.ts +1 -1
- package/src/link/services.ts +13 -0
- package/src/platform.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcforge/platform",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.200",
|
|
4
4
|
"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
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -44,20 +44,20 @@
|
|
|
44
44
|
"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
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@arcforge/session": "2.0.
|
|
48
|
-
"@arcforge/engines": "2.0.
|
|
49
|
-
"@arcforge/err": "2.0.
|
|
50
|
-
"@arcforge/types": "2.0.
|
|
51
|
-
"@arcforge/cloud": "2.0.
|
|
52
|
-
"@arcforge/capsule": "2.0.
|
|
53
|
-
"@arcforge/core": "2.0.
|
|
54
|
-
"@arcforge/vstr": "2.0.
|
|
47
|
+
"@arcforge/session": "2.0.200",
|
|
48
|
+
"@arcforge/engines": "2.0.200",
|
|
49
|
+
"@arcforge/err": "2.0.200",
|
|
50
|
+
"@arcforge/types": "2.0.200",
|
|
51
|
+
"@arcforge/cloud": "2.0.200",
|
|
52
|
+
"@arcforge/capsule": "2.0.200",
|
|
53
|
+
"@arcforge/core": "2.0.200",
|
|
54
|
+
"@arcforge/vstr": "2.0.200",
|
|
55
55
|
"fft.js": "^4.0.4",
|
|
56
56
|
"h3": "^1.15.11",
|
|
57
57
|
"semver": "^7.7.4",
|
|
58
58
|
"sharp": "^0.35.3",
|
|
59
59
|
"typescript": "5.9.2",
|
|
60
|
-
"@arcforge/link": "2.0.
|
|
60
|
+
"@arcforge/link": "2.0.200"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@arcforge/air": "2.0.187",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createHash } from "node:crypto"
|
|
2
|
-
import { join } from "node:path"
|
|
2
|
+
import { dirname, join, relative, resolve } from "node:path"
|
|
3
3
|
import type { AxonPartialBlueprint, EngineRequirements } from "@arcforge/types"
|
|
4
4
|
import { err } from "@arcforge/err"
|
|
5
5
|
import { fsx } from "../../utils/fs"
|
|
6
6
|
import { merge } from "./collisions"
|
|
7
|
+
import { workspaceRoot } from "./workspace"
|
|
7
8
|
import { Config } from "./scan/config"
|
|
8
9
|
import { Modules } from "./modules"
|
|
9
10
|
import { Boot } from "./scan/boot"
|
|
@@ -23,6 +24,8 @@ import type { ScanWarning } from "./types"
|
|
|
23
24
|
type BlueprintOpts = {
|
|
24
25
|
/** Agent root — the directory containing axon.config.ts. */
|
|
25
26
|
root: string
|
|
27
|
+
/** Invocation directory used to discover the nearest .agents workspace. */
|
|
28
|
+
cwd?: string
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
export type BlueprintResult = {
|
|
@@ -42,6 +45,15 @@ export type BlueprintResult = {
|
|
|
42
45
|
export function Blueprint(opts: BlueprintOpts) {
|
|
43
46
|
const root = opts.root
|
|
44
47
|
const cognet = Cognet({ root: root })
|
|
48
|
+
const discoveredWorkspace = opts.cwd ? workspaceRoot(opts.cwd) : null
|
|
49
|
+
// Only attach a repository workspace to agents inside that repository.
|
|
50
|
+
// The TUI process cwd may be the monorepo while tests or external agents
|
|
51
|
+
// live in temporary/profile directories.
|
|
52
|
+
const workspace = discoveredWorkspace && (() => {
|
|
53
|
+
const repoRoot = dirname(discoveredWorkspace)
|
|
54
|
+
const rel = relative(resolve(repoRoot), resolve(root))
|
|
55
|
+
return rel === "" || (!rel.startsWith(".." + "/") && rel !== "..") ? discoveredWorkspace : null
|
|
56
|
+
})()
|
|
45
57
|
|
|
46
58
|
let current: AxonPartialBlueprint | null = null
|
|
47
59
|
|
|
@@ -136,9 +148,10 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
136
148
|
// what this writes.
|
|
137
149
|
if (loadOpts.compile) await cognet.compile(cognetSourceOf(config))
|
|
138
150
|
|
|
139
|
-
// Agent surfaces + modules,
|
|
140
|
-
const [prompts, scripts, tools, routes, plugins, middleware, knowledge, boot, modules, brain] = await Promise.all([
|
|
151
|
+
// Agent surfaces + modules, plus workspace prompts when available.
|
|
152
|
+
const [prompts, scripts, tools, routes, plugins, middleware, knowledge, boot, modules, brain, workspacePrompts] = await Promise.all([
|
|
141
153
|
Prompts(root),
|
|
154
|
+
|
|
142
155
|
Scripts(root),
|
|
143
156
|
Tools(root),
|
|
144
157
|
Routes(root),
|
|
@@ -148,8 +161,17 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
148
161
|
Boot(root),
|
|
149
162
|
Modules({ root, declared: config.modules, modulePaths: config.modulePaths }),
|
|
150
163
|
cognet.read(),
|
|
164
|
+
!workspace
|
|
165
|
+
? Promise.resolve({ entries: [], warnings: [] })
|
|
166
|
+
: Prompts(workspace, { prefix: "workspace", dir: "prompts" }).then(async scanned => ({
|
|
167
|
+
entries: await Promise.all(scanned.entries.map(async entry => ({
|
|
168
|
+
...entry,
|
|
169
|
+
source: entry.filePath ? await Bun.file(entry.filePath).text() : undefined,
|
|
170
|
+
}))),
|
|
171
|
+
warnings: scanned.warnings,
|
|
172
|
+
})),
|
|
151
173
|
])
|
|
152
|
-
for (const scanned of [prompts, scripts, tools, routes, plugins, middleware, knowledge]) warnings.push(...scanned.warnings)
|
|
174
|
+
for (const scanned of [prompts, scripts, tools, routes, plugins, middleware, knowledge, workspacePrompts]) warnings.push(...scanned.warnings)
|
|
153
175
|
warnings.push(...boot.warnings, ...modules.warnings, ...brain.warnings)
|
|
154
176
|
|
|
155
177
|
// Merge module surfaces under agent-wins precedence.
|
|
@@ -157,7 +179,10 @@ export function Blueprint(opts: BlueprintOpts) {
|
|
|
157
179
|
const mergedPrompts = merge(
|
|
158
180
|
"prompts",
|
|
159
181
|
prompts.entries,
|
|
160
|
-
|
|
182
|
+
[
|
|
183
|
+
...groups.map(g => ({ owner: g.owner, entries: g.entries.prompts })),
|
|
184
|
+
...(workspacePrompts.entries.length ? [{ owner: "workspace", entries: workspacePrompts.entries }] : []),
|
|
185
|
+
],
|
|
161
186
|
)
|
|
162
187
|
const mergedScripts = merge("scripts", scripts.entries, groups.map(g => ({ owner: g.owner, entries: g.entries.scripts })))
|
|
163
188
|
const mergedTools = merge("tools", tools.entries, groups.map(g => ({ owner: g.owner, entries: g.entries.tools })))
|
|
@@ -85,17 +85,86 @@ export async function readCognetAbi(sourceDir: string): Promise<string | null> {
|
|
|
85
85
|
* weights is a static fact about a brain, not something a config should be
|
|
86
86
|
* computing.
|
|
87
87
|
*/
|
|
88
|
-
export async function readCognetModels(sourceDir: string): Promise<Record<string,
|
|
88
|
+
export async function readCognetModels(sourceDir: string): Promise<Record<string, import("@arcforge/types").ModelRef>> {
|
|
89
89
|
const source = await fsx.readText(join(sourceDir, "cognet.config.ts"))
|
|
90
90
|
if (source === null) return {}
|
|
91
91
|
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
92
|
+
const opener = source.match(/\bmodels\s*:\s*\{/)
|
|
93
|
+
if (!opener?.index) return {}
|
|
94
94
|
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
98
166
|
}
|
|
167
|
+
|
|
99
168
|
return models
|
|
100
169
|
}
|
|
101
170
|
|
|
@@ -187,6 +256,17 @@ function parseRequirement(block: string): EngineRequirement | null {
|
|
|
187
256
|
|
|
188
257
|
const inputs = modality("in")
|
|
189
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")
|
|
190
270
|
if (inputs.length === 0 || outputs.length === 0) return null
|
|
191
271
|
|
|
192
272
|
// Numeric separators are ordinary in a config (`100_000`), and a parse
|
|
@@ -198,6 +278,12 @@ function parseRequirement(block: string): EngineRequirement | null {
|
|
|
198
278
|
type: type as EngineRequirement["type"],
|
|
199
279
|
in: inputs,
|
|
200
280
|
out: outputs,
|
|
281
|
+
...(preferIn.length || preferOut.length
|
|
282
|
+
? { prefer: {
|
|
283
|
+
...(preferIn.length ? { in: preferIn } : {}),
|
|
284
|
+
...(preferOut.length ? { out: preferOut } : {}),
|
|
285
|
+
} }
|
|
286
|
+
: {}),
|
|
201
287
|
...(context ? { context: Number(context.replaceAll("_", "")) } : {}),
|
|
202
288
|
...(flag("structured") ? { structured: true } : {}),
|
|
203
289
|
...(flag("parallel") ? { parallel: true } : {}),
|
|
@@ -442,6 +442,7 @@ export async function bundleCognet(opts: {
|
|
|
442
442
|
version: definition.version,
|
|
443
443
|
abi: definition.abi,
|
|
444
444
|
...(definition.wakeOn ? { wakeOn: definition.wakeOn } : {}),
|
|
445
|
+
...(definition.stimuli ? { stimuli: definition.stimuli } : {}),
|
|
445
446
|
path: outFile,
|
|
446
447
|
hash,
|
|
447
448
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { dirname, join, resolve } from "node:path"
|
|
2
|
+
import { fsx } from "../../utils/fs"
|
|
3
|
+
|
|
4
|
+
/** Find the nearest repository workspace layer from an invocation directory. */
|
|
5
|
+
export function workspaceRoot(from: string): string | null {
|
|
6
|
+
let dir = resolve(from)
|
|
7
|
+
while (true) {
|
|
8
|
+
const candidate = join(dir, ".agents")
|
|
9
|
+
if (fsx.exists(candidate)) return candidate
|
|
10
|
+
const parent = dirname(dir)
|
|
11
|
+
if (parent === dir) return null
|
|
12
|
+
dir = parent
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -99,7 +99,10 @@ export async function fetchModel(model: ParsedModel, opts: FetchOpts): Promise<S
|
|
|
99
99
|
// address to look up, and a registry may not publish a usable one either.
|
|
100
100
|
// Skipping this made every prepare re-download every model.
|
|
101
101
|
const remembered = await opts.store.resolved(specifierOf(model))
|
|
102
|
-
if (remembered)
|
|
102
|
+
if (remembered) {
|
|
103
|
+
if (model.traits) await opts.store.describe(specifierOf(model), model.traits)
|
|
104
|
+
return remembered
|
|
105
|
+
}
|
|
103
106
|
|
|
104
107
|
const expected = await expectedHash(model)
|
|
105
108
|
if (expected && opts.store.has(expected, basenameOf(model))) {
|
|
@@ -113,7 +116,10 @@ export async function fetchModel(model: ParsedModel, opts: FetchOpts): Promise<S
|
|
|
113
116
|
// memory it does not fit in.
|
|
114
117
|
bytes: (await stat(path)).size,
|
|
115
118
|
}
|
|
116
|
-
if (opts.remember !== false)
|
|
119
|
+
if (opts.remember !== false) {
|
|
120
|
+
await opts.store.remember(specifierOf(model), hit, basenameOf(model))
|
|
121
|
+
if (model.traits) await opts.store.describe(specifierOf(model), model.traits)
|
|
122
|
+
}
|
|
117
123
|
return hit
|
|
118
124
|
}
|
|
119
125
|
|
|
@@ -147,7 +153,10 @@ export async function fetchModel(model: ParsedModel, opts: FetchOpts): Promise<S
|
|
|
147
153
|
// put() hashes and refuses a mismatch — verification lives at the write,
|
|
148
154
|
// so nothing can reach the cache unverified by any path.
|
|
149
155
|
const stored = await opts.store.put(basenameOf(model), data, expected ?? undefined)
|
|
150
|
-
if (opts.remember !== false)
|
|
156
|
+
if (opts.remember !== false) {
|
|
157
|
+
await opts.store.remember(specifierOf(model), stored, basenameOf(model))
|
|
158
|
+
if (model.traits) await opts.store.describe(specifierOf(model), model.traits)
|
|
159
|
+
}
|
|
151
160
|
return stored
|
|
152
161
|
}
|
|
153
162
|
|
|
@@ -177,20 +186,63 @@ export async function fetchModel(model: ParsedModel, opts: FetchOpts): Promise<S
|
|
|
177
186
|
* are missing hands a caller a directory path into nothing, which surfaces as
|
|
178
187
|
* a runtime error about a config file rather than as "not downloaded".
|
|
179
188
|
*/
|
|
189
|
+
export type ModelTraitsInput = {
|
|
190
|
+
capability?: string
|
|
191
|
+
type?: "generate" | "transform" | "stream"
|
|
192
|
+
in?: string[]
|
|
193
|
+
out?: string[]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function discoverManifest(repo: { host: "hf"; repo: string; rev: string }): Promise<{ files: string[]; primary: string }> {
|
|
197
|
+
const response = await fetch(`https://huggingface.co/api/models/${repo.repo}`)
|
|
198
|
+
if (!response.ok) {
|
|
199
|
+
throw err("MODEL_FETCH_FAILED", {
|
|
200
|
+
detail: `${repo.repo}: could not read repository manifest (${response.status})`,
|
|
201
|
+
context: { repo: repo.repo, status: response.status },
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const raw = await response.json() as { siblings?: Array<{ rfilename?: string }> }
|
|
206
|
+
const names = (raw.siblings ?? [])
|
|
207
|
+
.map(entry => entry.rfilename)
|
|
208
|
+
.filter((name): name is string => typeof name === "string")
|
|
209
|
+
.filter(name => !name.startsWith(".git/") && !/^readme|^license|^\.gitignore$/i.test(name))
|
|
210
|
+
|
|
211
|
+
const runnable = names.filter(name => /\.(onnx|gguf|safetensors|pt|pth)$/i.test(name))
|
|
212
|
+
const primary = runnable.find(name => /(^|\/)model[^/]*\.onnx$/i.test(name))
|
|
213
|
+
?? runnable.find(name => /decoder|encoder/i.test(name))
|
|
214
|
+
?? runnable[0]
|
|
215
|
+
|
|
216
|
+
if (!primary) {
|
|
217
|
+
throw err("MODEL_NO_SINGLE_WEIGHT", {
|
|
218
|
+
detail: `${repo.repo}: set declaration found no runnable model files`,
|
|
219
|
+
context: { repo: repo.repo },
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return { files: names, primary }
|
|
224
|
+
}
|
|
225
|
+
|
|
180
226
|
export async function fetchManifest(
|
|
181
227
|
repo: { host: "hf"; repo: string; rev: string; key: string },
|
|
182
228
|
files: string[],
|
|
183
229
|
primary: string,
|
|
184
230
|
opts: FetchOpts,
|
|
231
|
+
traits?: ModelTraitsInput,
|
|
185
232
|
): Promise<StoredModel> {
|
|
186
233
|
const specifier = `${repo.host}:${repo.repo}@${repo.rev}`
|
|
234
|
+
const manifest = files.length > 0
|
|
235
|
+
? { files, primary }
|
|
236
|
+
: await discoverManifest(repo)
|
|
237
|
+
const resolvedFiles = manifest.files
|
|
238
|
+
const resolvedPrimary = manifest.primary
|
|
187
239
|
|
|
188
240
|
const cached = await opts.store.resolved(specifier)
|
|
189
241
|
if (cached) return cached
|
|
190
242
|
|
|
191
243
|
const collected: { file: { path: string; sha256: string; bytes: number }; stored: StoredModel }[] = []
|
|
192
244
|
|
|
193
|
-
for (const path of
|
|
245
|
+
for (const path of resolvedFiles) {
|
|
194
246
|
// Reuses the whole single-file machine per member — hash expectation,
|
|
195
247
|
// verification at the write, dedup against bytes already held. A set
|
|
196
248
|
// sharing a config file with another set costs nothing twice.
|
|
@@ -202,7 +254,7 @@ export async function fetchManifest(
|
|
|
202
254
|
})
|
|
203
255
|
}
|
|
204
256
|
|
|
205
|
-
await opts.store.rememberSet(specifier, collected,
|
|
257
|
+
await opts.store.rememberSet(specifier, collected, resolvedPrimary, traits)
|
|
206
258
|
|
|
207
259
|
const resolved = await opts.store.resolved(specifier)
|
|
208
260
|
if (!resolved) {
|
|
@@ -210,7 +262,7 @@ export async function fetchManifest(
|
|
|
210
262
|
// user error, and it must not read as "this model is not cached".
|
|
211
263
|
throw err("MODEL_FETCH_FAILED", {
|
|
212
264
|
detail: `${repo.repo}: the set was written but could not be read back`,
|
|
213
|
-
context: { repo: repo.repo, files:
|
|
265
|
+
context: { repo: repo.repo, files: resolvedFiles.length },
|
|
214
266
|
})
|
|
215
267
|
}
|
|
216
268
|
return resolved
|
|
@@ -79,12 +79,14 @@ export function Models(opts: ModelsOpts = {}) {
|
|
|
79
79
|
resolveOpts: {
|
|
80
80
|
onDownload?: (model: ParsedModel) => void
|
|
81
81
|
onProgress?: (progress: { model: ParsedModel; received: number; total: number | null }) => void
|
|
82
|
+
traits?: ParsedModel["traits"]
|
|
82
83
|
} = {},
|
|
83
84
|
): Promise<StoredModel> {
|
|
84
85
|
return await fetchManifest(repo, files, primary, {
|
|
85
86
|
store,
|
|
86
87
|
...(resolveOpts.onDownload ? { onDownload: resolveOpts.onDownload } : {}),
|
|
87
88
|
...(resolveOpts.onProgress ? { onProgress: resolveOpts.onProgress } : {}),
|
|
89
|
+
...(resolveOpts.traits ? { traits: resolveOpts.traits } : {}),
|
|
88
90
|
})
|
|
89
91
|
},
|
|
90
92
|
|
|
@@ -127,6 +129,40 @@ export function Models(opts: ModelsOpts = {}) {
|
|
|
127
129
|
const fetched: string[] = []
|
|
128
130
|
|
|
129
131
|
for (const model of parsed) {
|
|
132
|
+
if (model.set) {
|
|
133
|
+
const stored = await fetchManifest(
|
|
134
|
+
{ host: model.host, repo: model.repo, rev: model.rev, key: model.key },
|
|
135
|
+
[],
|
|
136
|
+
"",
|
|
137
|
+
{
|
|
138
|
+
store,
|
|
139
|
+
...(resolveOpts.onDownload ? { onDownload: resolveOpts.onDownload } : {}),
|
|
140
|
+
...(resolveOpts.onProgress ? { onProgress: resolveOpts.onProgress } : {}),
|
|
141
|
+
},
|
|
142
|
+
model.traits,
|
|
143
|
+
)
|
|
144
|
+
paths[model.key] = stored.path
|
|
145
|
+
if (stored.path) fetched.push(model.key)
|
|
146
|
+
continue
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (model.set) {
|
|
150
|
+
const stored = await fetchManifest(
|
|
151
|
+
{ host: model.host, repo: model.repo, rev: model.rev, key: model.key },
|
|
152
|
+
[],
|
|
153
|
+
"",
|
|
154
|
+
{
|
|
155
|
+
store,
|
|
156
|
+
...(resolveOpts.onDownload ? { onDownload: resolveOpts.onDownload } : {}),
|
|
157
|
+
...(resolveOpts.onProgress ? { onProgress: resolveOpts.onProgress } : {}),
|
|
158
|
+
},
|
|
159
|
+
model.traits,
|
|
160
|
+
)
|
|
161
|
+
paths[model.key] = stored.path
|
|
162
|
+
fetched.push(model.key)
|
|
163
|
+
continue
|
|
164
|
+
}
|
|
165
|
+
|
|
130
166
|
const stored = await fetchModel(model, {
|
|
131
167
|
store,
|
|
132
168
|
onDownload: m => {
|
|
@@ -137,6 +173,8 @@ export function Models(opts: ModelsOpts = {}) {
|
|
|
137
173
|
// they land, and a caller that cannot see them can only show
|
|
138
174
|
// a spinner for a five-gigabyte transfer.
|
|
139
175
|
...(resolveOpts.onProgress ? { onProgress: resolveOpts.onProgress } : {}),
|
|
176
|
+
...(model.traits ? { traits: model.traits } : {}),
|
|
177
|
+
|
|
140
178
|
})
|
|
141
179
|
paths[model.key] = stored.path
|
|
142
180
|
}
|
|
@@ -17,10 +17,19 @@ export type ParsedModel = {
|
|
|
17
17
|
repo: string
|
|
18
18
|
/** Path within the repo. A repo is a directory; big ones hold many weights. */
|
|
19
19
|
file: string
|
|
20
|
+
/** Complete repository layout rather than one file. */
|
|
21
|
+
set?: boolean
|
|
20
22
|
/** Git revision. `main` unless pinned. */
|
|
21
23
|
rev: string
|
|
22
24
|
/** Expected content hash, when the author pinned one. */
|
|
23
25
|
sha256?: string
|
|
26
|
+
/** Optional provider capability metadata carried into the machine cache. */
|
|
27
|
+
traits?: {
|
|
28
|
+
capability?: string
|
|
29
|
+
type?: "generate" | "transform" | "stream"
|
|
30
|
+
in?: string[]
|
|
31
|
+
out?: string[]
|
|
32
|
+
}
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
/** The one place a model's fetch URL is constructed. */
|
|
@@ -45,7 +54,7 @@ export function basenameOf(model: ParsedModel): string {
|
|
|
45
54
|
*/
|
|
46
55
|
export function parseModel(key: string, ref: ModelRef): ParsedModel {
|
|
47
56
|
if (typeof ref !== "string") {
|
|
48
|
-
if (!ref.hf || !ref.file) {
|
|
57
|
+
if (!ref.hf || (!ref.file && !ref.set)) {
|
|
49
58
|
throw err("MODEL_SPECIFIER_INVALID", {
|
|
50
59
|
detail: `models.${key}: the object form needs both "hf" (owner/repo) and "file"`,
|
|
51
60
|
context: { key },
|
|
@@ -55,9 +64,18 @@ export function parseModel(key: string, ref: ModelRef): ParsedModel {
|
|
|
55
64
|
key,
|
|
56
65
|
host: "hf",
|
|
57
66
|
repo: ref.hf,
|
|
58
|
-
file: ref.file,
|
|
67
|
+
file: ref.file ?? "",
|
|
68
|
+
...(ref.set ? { set: true } : {}),
|
|
59
69
|
rev: ref.rev ?? "main",
|
|
60
70
|
...(ref.sha256 ? { sha256: ref.sha256 } : {}),
|
|
71
|
+
...((ref.capability || ref.type || ref.in || ref.out) ? {
|
|
72
|
+
traits: {
|
|
73
|
+
...(ref.capability ? { capability: ref.capability } : {}),
|
|
74
|
+
...(ref.type ? { type: ref.type } : {}),
|
|
75
|
+
...(ref.in ? { in: ref.in } : {}),
|
|
76
|
+
...(ref.out ? { out: ref.out } : {}),
|
|
77
|
+
},
|
|
78
|
+
} : {}),
|
|
61
79
|
}
|
|
62
80
|
}
|
|
63
81
|
|
|
@@ -369,6 +369,7 @@ export function ModelStore(opts: ModelStoreOpts = {}) {
|
|
|
369
369
|
specifier: string,
|
|
370
370
|
files: { file: ModelFile; stored: StoredModel }[],
|
|
371
371
|
primary: string,
|
|
372
|
+
traits?: ModelTraits,
|
|
372
373
|
): Promise<void> {
|
|
373
374
|
const name = treeNameFor(specifier)
|
|
374
375
|
const tree = treeFor(name)
|
|
@@ -397,7 +398,7 @@ export function ModelStore(opts: ModelStoreOpts = {}) {
|
|
|
397
398
|
primary: primary,
|
|
398
399
|
// Traits describe the MODEL, not the bytes — a refetch must
|
|
399
400
|
// not forget what it is.
|
|
400
|
-
...(previous?.traits ? { traits: previous
|
|
401
|
+
...(traits ?? previous?.traits ? { traits: traits ?? previous?.traits } : {}),
|
|
401
402
|
}
|
|
402
403
|
await mkdir(root, { recursive: true })
|
|
403
404
|
await Bun.write(indexPath, JSON.stringify(index, null, 4))
|
|
@@ -28,6 +28,8 @@ export type PrepareResult = {
|
|
|
28
28
|
|
|
29
29
|
type PrepareOpts = {
|
|
30
30
|
root: string
|
|
31
|
+
/** Invocation directory used for workspace discovery. */
|
|
32
|
+
cwd?: string
|
|
31
33
|
kind: ProjectKind
|
|
32
34
|
installer: InstallerT
|
|
33
35
|
manifest: ManifestT
|
|
@@ -122,9 +124,9 @@ export type BuildReporter = (type: string, data: unknown) => void
|
|
|
122
124
|
* the caller decides severity.
|
|
123
125
|
*/
|
|
124
126
|
export function Prepare(opts: PrepareOpts) {
|
|
125
|
-
const { root, kind, installer, manifest, modules, tree, typegen, frameworkVersion, frameworkSource, repoRoot, extend } = opts
|
|
127
|
+
const { root, kind, installer, manifest, modules, tree, typegen, frameworkVersion, frameworkSource, repoRoot, extend, cwd } = opts
|
|
126
128
|
|
|
127
|
-
const blueprint = Blueprint({ root: root })
|
|
129
|
+
const blueprint = Blueprint({ root: root, ...(cwd ? { cwd } : {}) })
|
|
128
130
|
// Named `weights` locally: `modules` is already the source-module
|
|
129
131
|
// manager here, and two different things called models/modules in one
|
|
130
132
|
// function is exactly the kind of near-collision that reads fine and
|
|
@@ -22,6 +22,8 @@ export type { ProjectKind }
|
|
|
22
22
|
|
|
23
23
|
type ProjectOpts = {
|
|
24
24
|
root: string
|
|
25
|
+
/** Invocation directory used for workspace discovery. */
|
|
26
|
+
cwd?: string
|
|
25
27
|
kind: ProjectKind
|
|
26
28
|
name: string
|
|
27
29
|
cloud: AxonCloudClient
|
|
@@ -113,6 +115,7 @@ export function Project(opts: ProjectOpts) {
|
|
|
113
115
|
frameworkVersion: opts.frameworkVersion,
|
|
114
116
|
...(opts.frameworkSource ? { frameworkSource: opts.frameworkSource } : {}),
|
|
115
117
|
...(opts.repoRoot ? { repoRoot: opts.repoRoot } : {}),
|
|
118
|
+
...(opts.cwd ? { cwd: opts.cwd } : {}),
|
|
116
119
|
...(bench ? { extend: async () => { await bench.prepare() } } : {}),
|
|
117
120
|
...(opts.profileProviders ? { profileProviders: opts.profileProviders } : {}),
|
|
118
121
|
})
|
|
@@ -14,6 +14,8 @@ type ProjectsOpts = {
|
|
|
14
14
|
frameworkVersion: string
|
|
15
15
|
frameworkSource?: FrameworkSource
|
|
16
16
|
repoRoot?: string
|
|
17
|
+
/** Invocation directory used for workspace discovery. */
|
|
18
|
+
cwd?: string
|
|
17
19
|
/** Collaborators a bench project needs — the test runner and agent resolution. */
|
|
18
20
|
bench: BenchExtras
|
|
19
21
|
/**
|
|
@@ -54,6 +56,7 @@ export function Projects(opts: ProjectsOpts) {
|
|
|
54
56
|
name: await projectName(absolute),
|
|
55
57
|
cloud: opts.cloud,
|
|
56
58
|
frameworkVersion: opts.frameworkVersion,
|
|
59
|
+
...(opts.cwd ? { cwd: opts.cwd } : {}),
|
|
57
60
|
...(opts.frameworkSource ? { frameworkSource: opts.frameworkSource } : {}),
|
|
58
61
|
...(opts.repoRoot ? { repoRoot: opts.repoRoot } : {}),
|
|
59
62
|
bench: opts.bench,
|
|
@@ -32,9 +32,48 @@ export type TreeCacheOpts = {
|
|
|
32
32
|
export const DEFAULT_TREE_CACHE = join(homedir(), ".axon", "cache", "trees")
|
|
33
33
|
export const DEFAULT_MAX_TREES = 24
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Environment overrides, for the same reason `AXON_STORE_ROOT` exists.
|
|
37
|
+
*
|
|
38
|
+
* `root` being injectable was supposed to keep tests off the developer's real
|
|
39
|
+
* cache — the comment above says so outright — but injection only protects the
|
|
40
|
+
* call sites that remember to inject. The SUITE does not: every fixture builds
|
|
41
|
+
* a `Platform()`, which builds a `Tree()`, which builds a `TreeCache()` with
|
|
42
|
+
* defaults, so a full parallel run resolves into `~/.axon/cache/trees` and
|
|
43
|
+
* evicts from it. Measured on 2026-09-10: thirteen of the developer's
|
|
44
|
+
* twenty-four cached trees were rewritten by test runs, against a cap of
|
|
45
|
+
* twenty-four.
|
|
46
|
+
*
|
|
47
|
+
* That is not only rude, it makes the suite's install behaviour a function of
|
|
48
|
+
* whatever else the machine has built lately. A run whose working set collides
|
|
49
|
+
* with the cap evicts trees other tests in the same run are about to want, and
|
|
50
|
+
* each miss turns a ~1ms graft into a full `bun install` — which is what a
|
|
51
|
+
* 60-second timeout in a test that takes 4.5 seconds alone actually looks like.
|
|
52
|
+
*
|
|
53
|
+
* An env var rather than another option threaded through Platform(), because
|
|
54
|
+
* the escape has to close for call sites that never think about it — exactly
|
|
55
|
+
* the argument `storeRoot()` makes for the store.
|
|
56
|
+
*/
|
|
57
|
+
const ENV_TREE_CACHE_ROOT = "AXON_TREE_CACHE_ROOT"
|
|
58
|
+
const ENV_TREE_CACHE_MAX = "AXON_TREE_CACHE_MAX"
|
|
59
|
+
|
|
60
|
+
/** The cap from the environment, if it names a usable one. */
|
|
61
|
+
function maxFromEnv(): number | null {
|
|
62
|
+
const raw = process.env[ENV_TREE_CACHE_MAX]
|
|
63
|
+
if (raw === undefined) return null
|
|
64
|
+
const parsed = Number(raw)
|
|
65
|
+
// Loud rather than silently falling back: a mistyped cap that quietly
|
|
66
|
+
// reverts to the default would show up only as the eviction thrash this
|
|
67
|
+
// variable exists to remove, months later and with nothing pointing here.
|
|
68
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
69
|
+
throw new Error(`${ENV_TREE_CACHE_MAX} must be a positive integer — got ${JSON.stringify(raw)}`)
|
|
70
|
+
}
|
|
71
|
+
return parsed
|
|
72
|
+
}
|
|
73
|
+
|
|
35
74
|
export function TreeCache(opts: TreeCacheOpts = {}) {
|
|
36
|
-
const cacheRoot = opts.root ?? DEFAULT_TREE_CACHE
|
|
37
|
-
const maxTrees = opts.max ?? DEFAULT_MAX_TREES
|
|
75
|
+
const cacheRoot = opts.root ?? process.env[ENV_TREE_CACHE_ROOT] ?? DEFAULT_TREE_CACHE
|
|
76
|
+
const maxTrees = opts.max ?? maxFromEnv() ?? DEFAULT_MAX_TREES
|
|
38
77
|
|
|
39
78
|
|
|
40
79
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { join } from "node:path"
|
|
2
|
-
import { writeFileSync } from "node:fs"
|
|
2
|
+
import { readFileSync, writeFileSync } from "node:fs"
|
|
3
3
|
import { Frame, type ProjectKind } from "../../frame"
|
|
4
|
+
import type { EngineType } from "@arcforge/types"
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The ambient authoring surface for cognet source — what the compile step's
|
|
@@ -20,6 +21,7 @@ import type {
|
|
|
20
21
|
CognetConfig,
|
|
21
22
|
CognetPlugin,
|
|
22
23
|
KernelAbi,
|
|
24
|
+
EngineType,
|
|
23
25
|
} from "@arcforge/types"
|
|
24
26
|
|
|
25
27
|
declare global {
|
|
@@ -50,7 +52,13 @@ declare global {
|
|
|
50
52
|
}) => Promise<void> | void): void
|
|
51
53
|
|
|
52
54
|
/** the syscall table — live from load() onward; do work inside loop(), not at module top level */
|
|
53
|
-
|
|
55
|
+
/** Engine role names and call shapes generated from cognet.config.ts. */
|
|
56
|
+
interface CognetEngineRequirements {
|
|
57
|
+
[role: string]: { type: EngineType }
|
|
58
|
+
__COGNET_ENGINE_ROLES__
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const kernel: KernelAbi<CognetEngineRequirements>
|
|
54
62
|
|
|
55
63
|
|
|
56
64
|
/** a named stage within a tick — cognet:phase:* telemetry */
|
|
@@ -82,10 +90,60 @@ export const COGNET_GLOBALS = "cognet-globals.d.ts"
|
|
|
82
90
|
* declarations into `.agent/types/` — one brain's authoring surface, reached
|
|
83
91
|
* from whichever frame the source happens to live in.
|
|
84
92
|
*/
|
|
93
|
+
function readCognetEngineTypes(root: string): Array<[string, EngineType, string]> {
|
|
94
|
+
const candidates = [
|
|
95
|
+
join(root, "cognet.config.ts"),
|
|
96
|
+
join(root, "cognet", "cognet.config.ts"),
|
|
97
|
+
]
|
|
98
|
+
const source = candidates.map(path => {
|
|
99
|
+
try { return readFileSync(path, "utf-8") } catch { return null }
|
|
100
|
+
}).find(value => value !== null)
|
|
101
|
+
|
|
102
|
+
if (!source) return []
|
|
103
|
+
|
|
104
|
+
const opener = source.indexOf("engines")
|
|
105
|
+
if (opener < 0) return []
|
|
106
|
+
const open = source.indexOf("{", opener)
|
|
107
|
+
let depth = 0
|
|
108
|
+
let close = -1
|
|
109
|
+
let quote: string | null = null
|
|
110
|
+
for (let i = open; i < source.length; i++) {
|
|
111
|
+
const char = source[i]
|
|
112
|
+
if (quote) {
|
|
113
|
+
if (char === quote && source[i - 1] !== "\\") quote = null
|
|
114
|
+
continue
|
|
115
|
+
}
|
|
116
|
+
if (char === "\"" || char === "'" || char === "`") quote = char
|
|
117
|
+
else if (char === "{") depth++
|
|
118
|
+
else if (char === "}" && --depth === 0) {
|
|
119
|
+
close = i
|
|
120
|
+
break
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (close < 0) return []
|
|
124
|
+
const block = source.slice(open + 1, close)
|
|
125
|
+
|
|
126
|
+
const roles: Array<[string, EngineType, string]> = []
|
|
127
|
+
const rolePattern = new RegExp("(?:^|\\n)\\s*([A-Za-z_$][\\w$]*)\\s*:\\s*\\{([\\s\\S]*?)(?=\\n\\s*[A-Za-z_$][\\w$]*\\s*:\\s*\\{|$)", "g")
|
|
128
|
+
const typePattern = new RegExp("\\btype\\s*:\\s*[\\\"'](generate|transform|stream)[\\\"']")
|
|
129
|
+
for (const match of block.matchAll(rolePattern)) {
|
|
130
|
+
const body = match[2] ?? ""
|
|
131
|
+
const type = typePattern.exec(body)?.[1] as EngineType | undefined
|
|
132
|
+
const output = body.match(/\bout\s*:\s*["'`](text|image|audio|video|vector|score|depth)["'`]/)?.[1]
|
|
133
|
+
if (type && output) roles.push([match[1]!, type, output])
|
|
134
|
+
}
|
|
135
|
+
return roles
|
|
136
|
+
}
|
|
137
|
+
|
|
85
138
|
export function generateCognetDts(root: string, kind: ProjectKind = "cognet"): void {
|
|
139
|
+
const declarations = readCognetEngineTypes(root)
|
|
140
|
+
.map(([name, type, output]) => ` ${name}: { type: "${type}"; out: "${output}" }`)
|
|
141
|
+
.join("\n")
|
|
142
|
+
const generated = COGNET_DTS.replace("__COGNET_ENGINE_ROLES__", declarations)
|
|
143
|
+
|
|
86
144
|
writeFileSync(
|
|
87
145
|
join(Frame({ root: root, kind: kind }).ensure("types"), COGNET_GLOBALS),
|
|
88
|
-
|
|
146
|
+
generated,
|
|
89
147
|
"utf-8",
|
|
90
148
|
)
|
|
91
149
|
}
|
|
@@ -124,7 +124,7 @@ type AgentOpts = {
|
|
|
124
124
|
*/
|
|
125
125
|
export async function Agent(opts: AgentOpts) {
|
|
126
126
|
const { project } = opts
|
|
127
|
-
const blueprint = Blueprint({ root: project.root })
|
|
127
|
+
const blueprint = Blueprint({ root: project.root, cwd: opts.cwd })
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
130
|
* The active profile's policy ceiling, re-read on every load.
|
package/src/link/services.ts
CHANGED
|
@@ -99,6 +99,19 @@ export async function SupervisorSideServices(opts: ServicesOpts) {
|
|
|
99
99
|
return { provider: primary.capability.provider, model: primary.capability.id }
|
|
100
100
|
},
|
|
101
101
|
|
|
102
|
+
/** Sanitized role facts safe to hand into the confined brain. */
|
|
103
|
+
get engineFacts() {
|
|
104
|
+
return Object.fromEntries((engines?.resolution.bound ?? []).map(entry => [
|
|
105
|
+
entry.role,
|
|
106
|
+
{
|
|
107
|
+
type: entry.requirement.type,
|
|
108
|
+
...(entry.capability.context !== undefined ? { context: entry.capability.context } : {}),
|
|
109
|
+
modalities: { in: entry.capability.in, out: entry.capability.out },
|
|
110
|
+
slots: entry.slots,
|
|
111
|
+
},
|
|
112
|
+
]))
|
|
113
|
+
},
|
|
114
|
+
|
|
102
115
|
/** Where a surface watches this agent — the linked counterpart of runtime.bus. */
|
|
103
116
|
bus,
|
|
104
117
|
|
package/src/platform.ts
CHANGED
|
@@ -148,6 +148,7 @@ export function Platform(opts: PlatformOpts) {
|
|
|
148
148
|
// while the process runs, and every agent prepared afterwards must
|
|
149
149
|
// see the new user's providers rather than the boot-time one's.
|
|
150
150
|
profileProviders: () => profileProviders(),
|
|
151
|
+
cwd: cwd,
|
|
151
152
|
frameworkVersion: opts.version,
|
|
152
153
|
...(opts.frameworkSource ? { frameworkSource: opts.frameworkSource } : {}),
|
|
153
154
|
...(opts.repoRoot ? { repoRoot: opts.repoRoot } : {}),
|