@arcforge/platform 2.0.166
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/README.md +31 -0
- package/package.json +69 -0
- package/src/bin/supervisor.ts +102 -0
- package/src/bin/test-api.ts +30 -0
- package/src/bin/test-preload.ts +308 -0
- package/src/bin/update-helper.ts +32 -0
- package/src/build/bench/CLAUDE.md +106 -0
- package/src/build/bench/SPEC.md +209 -0
- package/src/build/bench/agents.ts +105 -0
- package/src/build/bench/axes.ts +84 -0
- package/src/build/bench/bench.ts +96 -0
- package/src/build/bench/discover.ts +147 -0
- package/src/build/bench/index.ts +7 -0
- package/src/build/bench/log.ts +47 -0
- package/src/build/bench/matrix.ts +23 -0
- package/src/build/bench/preload.ts +440 -0
- package/src/build/bench/prepare.ts +61 -0
- package/src/build/bench/projection.ts +112 -0
- package/src/build/bench/resolve.ts +54 -0
- package/src/build/bench/runner.ts +309 -0
- package/src/build/bench/schema/extract.ts +148 -0
- package/src/build/bench/schema/index.ts +2 -0
- package/src/build/bench/schema/schema.ts +95 -0
- package/src/build/bench/schema/worker.ts +30 -0
- package/src/build/bench/typegen.ts +119 -0
- package/src/build/bench/workspace/files.ts +139 -0
- package/src/build/bench/workspace/handle.ts +133 -0
- package/src/build/bench/workspace/index.ts +11 -0
- package/src/build/bench/workspace/workspace.ts +14 -0
- package/src/build/blueprint/blueprint.ts +398 -0
- package/src/build/blueprint/cognet/abi.ts +207 -0
- package/src/build/blueprint/cognet/bundle-worker.ts +93 -0
- package/src/build/blueprint/cognet/bundle.ts +664 -0
- package/src/build/blueprint/cognet/cognet.ts +249 -0
- package/src/build/blueprint/cognet/index.ts +10 -0
- package/src/build/blueprint/cognet/manifest.ts +38 -0
- package/src/build/blueprint/cognet/resolve.ts +113 -0
- package/src/build/blueprint/collisions.ts +51 -0
- package/src/build/blueprint/index.ts +29 -0
- package/src/build/blueprint/modules/entries.ts +117 -0
- package/src/build/blueprint/modules/index.ts +300 -0
- package/src/build/blueprint/modules/meta.ts +174 -0
- package/src/build/blueprint/scan/boot.ts +34 -0
- package/src/build/blueprint/scan/cognetImports.ts +56 -0
- package/src/build/blueprint/scan/components.ts +45 -0
- package/src/build/blueprint/scan/config.ts +234 -0
- package/src/build/blueprint/scan/configImports.ts +232 -0
- package/src/build/blueprint/scan/declare-worker.ts +61 -0
- package/src/build/blueprint/scan/declare.ts +393 -0
- package/src/build/blueprint/scan/h3-globals.ts +137 -0
- package/src/build/blueprint/scan/knowledge.ts +101 -0
- package/src/build/blueprint/scan/middleware.ts +110 -0
- package/src/build/blueprint/scan/moduleImports.ts +79 -0
- package/src/build/blueprint/scan/plugins.ts +93 -0
- package/src/build/blueprint/scan/promptPackages.ts +45 -0
- package/src/build/blueprint/scan/prompts.ts +164 -0
- package/src/build/blueprint/scan/published.ts +131 -0
- package/src/build/blueprint/scan/resolve.ts +398 -0
- package/src/build/blueprint/scan/routes.ts +109 -0
- package/src/build/blueprint/scan/scripts.ts +119 -0
- package/src/build/blueprint/scan/tool-bundle-worker.ts +69 -0
- package/src/build/blueprint/scan/tools.ts +610 -0
- package/src/build/blueprint/types.ts +28 -0
- package/src/build/extensions/config.ts +261 -0
- package/src/build/extensions/edit.ts +684 -0
- package/src/build/extensions/extensions.ts +731 -0
- package/src/build/extensions/index.ts +10 -0
- package/src/build/extensions/load.ts +350 -0
- package/src/build/extensions/registrations.ts +189 -0
- package/src/build/extensions/store.ts +200 -0
- package/src/build/frame/frame.ts +145 -0
- package/src/build/frame/index.ts +5 -0
- package/src/build/frame/migrate.ts +246 -0
- package/src/build/project/bundle/agent.ts +382 -0
- package/src/build/project/bundle/artifacts.ts +88 -0
- package/src/build/project/bundle/assets.ts +385 -0
- package/src/build/project/bundle/bundle.ts +160 -0
- package/src/build/project/bundle/imports.ts +102 -0
- package/src/build/project/bundle/index.ts +16 -0
- package/src/build/project/bundle/module.ts +130 -0
- package/src/build/project/bundle/source.ts +136 -0
- package/src/build/project/bundle/stage.ts +97 -0
- package/src/build/project/bundle/types.ts +111 -0
- package/src/build/project/cognet.ts +156 -0
- package/src/build/project/create/agent.ts +52 -0
- package/src/build/project/create/bench.ts +81 -0
- package/src/build/project/create/cognet.ts +102 -0
- package/src/build/project/create/extension.ts +63 -0
- package/src/build/project/create/module.ts +43 -0
- package/src/build/project/create/profile.ts +102 -0
- package/src/build/project/create/prompt.ts +68 -0
- package/src/build/project/create/templates.ts +88 -0
- package/src/build/project/deploy.ts +96 -0
- package/src/build/project/index.ts +40 -0
- package/src/build/project/installer.ts +616 -0
- package/src/build/project/kinds.ts +374 -0
- package/src/build/project/links.ts +33 -0
- package/src/build/project/manifest/bunfig.ts +139 -0
- package/src/build/project/manifest/config.ts +246 -0
- package/src/build/project/manifest/env.ts +184 -0
- package/src/build/project/manifest/index.ts +9 -0
- package/src/build/project/manifest/manifest.ts +49 -0
- package/src/build/project/manifest/model.ts +124 -0
- package/src/build/project/manifest/package.ts +386 -0
- package/src/build/project/manifest/text.ts +19 -0
- package/src/build/project/models/fetch.ts +123 -0
- package/src/build/project/models/index.ts +8 -0
- package/src/build/project/models/models.ts +111 -0
- package/src/build/project/models/specifier.ts +106 -0
- package/src/build/project/models/store.ts +202 -0
- package/src/build/project/modules/hash.ts +31 -0
- package/src/build/project/modules/index.ts +5 -0
- package/src/build/project/modules/lock.ts +78 -0
- package/src/build/project/modules/modules.ts +155 -0
- package/src/build/project/prepare.ts +709 -0
- package/src/build/project/project.ts +253 -0
- package/src/build/project/projects.ts +164 -0
- package/src/build/project/propagation.ts +120 -0
- package/src/build/project/publish/verify.ts +312 -0
- package/src/build/project/publish.ts +155 -0
- package/src/build/project/reconcile.ts +93 -0
- package/src/build/project/specifier.ts +42 -0
- package/src/build/project/tree.ts +615 -0
- package/src/build/project/treecache.ts +356 -0
- package/src/build/project/typegen/axon-dts.ts +362 -0
- package/src/build/project/typegen/cognet-dts.ts +91 -0
- package/src/build/project/typegen/components.ts +45 -0
- package/src/build/project/typegen/env.ts +59 -0
- package/src/build/project/typegen/generators.ts +108 -0
- package/src/build/project/typegen/hooks.ts +71 -0
- package/src/build/project/typegen/index.ts +137 -0
- package/src/build/project/typegen/prompt-dts.ts +40 -0
- package/src/build/project/typegen/prompts.ts +36 -0
- package/src/build/project/typegen/registry-dts.ts +109 -0
- package/src/build/project/typegen/scripts.ts +37 -0
- package/src/build/project/typegen/tools.ts +31 -0
- package/src/build/project/typegen/tsconfig.ts +243 -0
- package/src/build/project/typegen/tui-dts.ts +120 -0
- package/src/build/project/typegen/write.ts +40 -0
- package/src/build/project/verify.ts +268 -0
- package/src/build/project/watcher.ts +266 -0
- package/src/build/runtime/agent.ts +550 -0
- package/src/build/runtime/escalations.ts +159 -0
- package/src/build/runtime/index.ts +15 -0
- package/src/build/runtime/instances.ts +604 -0
- package/src/build/runtime/profile.ts +91 -0
- package/src/build/runtime/progress.ts +143 -0
- package/src/build/runtime/requests.ts +167 -0
- package/src/build/runtime/resolve.ts +159 -0
- package/src/build/runtime/runtime.ts +233 -0
- package/src/build/runtime/sessions/index.ts +5 -0
- package/src/build/runtime/sessions/record.ts +145 -0
- package/src/build/runtime/sessions/sessions.ts +240 -0
- package/src/build/runtime/zeno.ts +120 -0
- package/src/index.ts +11 -0
- package/src/link/agent-main.ts +395 -0
- package/src/link/index.ts +70 -0
- package/src/link/services.ts +120 -0
- package/src/platform.ts +293 -0
- package/src/procs/index.ts +15 -0
- package/src/procs/tree.ts +177 -0
- package/src/services/cloud.ts +419 -0
- package/src/services/control/client.ts +126 -0
- package/src/services/control/dispatch.ts +156 -0
- package/src/services/control/index.ts +17 -0
- package/src/services/control/protocol.ts +179 -0
- package/src/services/control/server.ts +241 -0
- package/src/services/deployments.ts +81 -0
- package/src/services/files.ts +329 -0
- package/src/services/index.ts +5 -0
- package/src/services/mic/capture.ts +248 -0
- package/src/services/mic/config.ts +109 -0
- package/src/services/mic/fft.ts +93 -0
- package/src/services/mic/index.ts +139 -0
- package/src/services/mic/visualizer.ts +46 -0
- package/src/services/ollama/catalog.ts +122 -0
- package/src/services/ollama/http.ts +124 -0
- package/src/services/ollama/index.ts +13 -0
- package/src/services/ollama/models.ts +153 -0
- package/src/services/ollama/ollama.ts +89 -0
- package/src/services/ollama/registry.ts +112 -0
- package/src/services/ollama/types.ts +72 -0
- package/src/services/prompts.ts +76 -0
- package/src/services/registry.ts +220 -0
- package/src/services/resources/hardware.ts +125 -0
- package/src/services/resources/index.ts +6 -0
- package/src/services/resources/reservations.ts +162 -0
- package/src/services/resources/resources.ts +156 -0
- package/src/services/running/index.ts +1 -0
- package/src/services/running/running.ts +200 -0
- package/src/services/store/disk.ts +97 -0
- package/src/services/store/index.ts +15 -0
- package/src/services/store/store.ts +729 -0
- package/src/services/store/types.ts +303 -0
- package/src/services/test/child.ts +150 -0
- package/src/services/test/events.ts +102 -0
- package/src/services/test/files.ts +26 -0
- package/src/services/test/frames.ts +39 -0
- package/src/services/test/index.ts +7 -0
- package/src/services/test/runner.ts +122 -0
- package/src/services/test/types.ts +26 -0
- package/src/services/update/contract.ts +77 -0
- package/src/services/update/index.ts +12 -0
- package/src/services/update/installer.ts +139 -0
- package/src/services/update/updates.ts +137 -0
- package/src/utils/fs.ts +148 -0
- package/src/utils/tsast.ts +102 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { join } from "node:path"
|
|
2
|
+
import { readFile, writeFile } from "node:fs/promises"
|
|
3
|
+
import { err } from "@arcforge/err"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The framework packages every agent needs on disk, and where each lives in
|
|
7
|
+
* this repo.
|
|
8
|
+
*
|
|
9
|
+
* The paths are the reason this is a map rather than a list: a test fixture
|
|
10
|
+
* resolves them from the WORKING TREE instead of npm (see
|
|
11
|
+
* `frameworkSpecifier`), and that requires knowing where each package is.
|
|
12
|
+
*/
|
|
13
|
+
const FRAMEWORK_PACKAGES = {
|
|
14
|
+
"@arcforge/types": "libs/axon/types",
|
|
15
|
+
"@arcforge/engines": "libs/axon/packages/engines",
|
|
16
|
+
// The cognet runtime the compiled brain fuses to. Every agent needs it
|
|
17
|
+
// installed, because the generated entry imports it by bare specifier
|
|
18
|
+
// and the bundler resolves that from the agent's own node_modules.
|
|
19
|
+
"@arcforge/cognet": "libs/axon/cognet",
|
|
20
|
+
// The grammar a cognet renders with, for the same reason: the bundle
|
|
21
|
+
// marks it external (it is one of the cognet's own declared deps) and
|
|
22
|
+
// then resolves it from HERE. It is framework rather than a carried
|
|
23
|
+
// dependency because the kernel parses with the same package — two
|
|
24
|
+
// copies would be two grammars that could disagree.
|
|
25
|
+
"@arcforge/air": "libs/axon/packages/air",
|
|
26
|
+
} as const
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Framework packages an agent never imports directly, but which the linked
|
|
30
|
+
* ones depend on.
|
|
31
|
+
*
|
|
32
|
+
* In "published" mode npm resolves these transitively and they never need
|
|
33
|
+
* naming. A `file:` link cannot: the linked package declares them
|
|
34
|
+
* `workspace:*`, which only resolves inside a workspace, and a fixture in
|
|
35
|
+
* /tmp is not one. So the whole framework graph is linked, not just its
|
|
36
|
+
* roots — otherwise `bun install` fails with "Workspace dependency not
|
|
37
|
+
* found" on a package the agent has no idea exists.
|
|
38
|
+
*/
|
|
39
|
+
const FRAMEWORK_TRANSITIVE = {
|
|
40
|
+
"@arcforge/err": "libs/axon/packages/err",
|
|
41
|
+
} as const
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* How a framework dependency is spelled in a scaffolded project.
|
|
45
|
+
*
|
|
46
|
+
* "published" — the exact CLI version. What a real user gets: the generated
|
|
47
|
+
* .agent/*.d.ts comes from this CLI, so the installed types must match it
|
|
48
|
+
* exactly or they drift from what the editor was told.
|
|
49
|
+
*
|
|
50
|
+
* "workspace" — a `file:` link into this repo. What the TEST SUITE gets, and
|
|
51
|
+
* the reason this option exists at all.
|
|
52
|
+
*
|
|
53
|
+
* A suite that installs the framework from npm is not testing the commit, it
|
|
54
|
+
* is testing the last release — so a change to a published package could not
|
|
55
|
+
* pass until it was published, and could not be published until it passed.
|
|
56
|
+
* Every symptom of that followed: a green gate on broken code, a barrel
|
|
57
|
+
* export that pulled the TypeScript compiler into every agent bundle and was
|
|
58
|
+
* invisible until an agent installed it, and a release cycle where the only
|
|
59
|
+
* way through was to force a deploy and find out afterwards.
|
|
60
|
+
*
|
|
61
|
+
* Linking makes the fixture resolve the code under test, so those fail here
|
|
62
|
+
* rather than in a user's first-run. `manifest.framework.ensure()` already
|
|
63
|
+
* treats a `file:`/`workspace:` range as deliberate and leaves it alone,
|
|
64
|
+
* which is what lets a linked fixture survive a prepare.
|
|
65
|
+
*/
|
|
66
|
+
export type FrameworkSource = "published" | "workspace"
|
|
67
|
+
|
|
68
|
+
function frameworkSpecifier(
|
|
69
|
+
name: keyof typeof FRAMEWORK_PACKAGES,
|
|
70
|
+
frameworkVersion: string,
|
|
71
|
+
source: FrameworkSource,
|
|
72
|
+
repoRoot: string | undefined,
|
|
73
|
+
): string {
|
|
74
|
+
if (source === "published" || !repoRoot) return frameworkVersion
|
|
75
|
+
return `file:${join(repoRoot, FRAMEWORK_PACKAGES[name])}`
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The subset of the framework a kind actually needs.
|
|
80
|
+
*
|
|
81
|
+
* "types" is @arcforge/types alone — enough to resolve
|
|
82
|
+
* `tsconfig.base.json` and, through its own dependency on @types/bun, the Bun
|
|
83
|
+
* globals a generated frame assumes. That is the whole requirement of a
|
|
84
|
+
* profile or an extension: neither runs an agent, so neither has any use for
|
|
85
|
+
* the engine registry, the cognet host or the AIR grammar.
|
|
86
|
+
*
|
|
87
|
+
* "all" is the agent set — every package a booting agent resolves by bare
|
|
88
|
+
* specifier out of its own node_modules.
|
|
89
|
+
*
|
|
90
|
+
* Split because a profile declaring the agent framework is not merely
|
|
91
|
+
* wasteful: under `file:` linking the extra links change how the tree hoists,
|
|
92
|
+
* and @types/bun stopped resolving — so a user's plugin lost `Bun` and
|
|
93
|
+
* `process` and every symbol degraded to any.
|
|
94
|
+
*/
|
|
95
|
+
export type FrameworkSet = "all" | "types"
|
|
96
|
+
|
|
97
|
+
function frameworkDependencies(
|
|
98
|
+
frameworkVersion: string,
|
|
99
|
+
source: FrameworkSource = "published",
|
|
100
|
+
repoRoot?: string,
|
|
101
|
+
set: FrameworkSet = "all",
|
|
102
|
+
): Record<string, string> {
|
|
103
|
+
const deps: Record<string, string> = {}
|
|
104
|
+
|
|
105
|
+
if (set === "types") {
|
|
106
|
+
deps["@arcforge/types"] = frameworkSpecifier("@arcforge/types", frameworkVersion, source, repoRoot)
|
|
107
|
+
|
|
108
|
+
// Declared OUTRIGHT, not inherited.
|
|
109
|
+
//
|
|
110
|
+
// tsconfig.base.json sets `"types": ["bun"]`, and an explicit `types`
|
|
111
|
+
// field disables automatic @types discovery — so the package making
|
|
112
|
+
// that claim has to guarantee it resolves. @arcforge/types declares
|
|
113
|
+
// @types/bun as a real dependency for exactly this reason, and an
|
|
114
|
+
// AGENT inherits it transitively through a registry package.
|
|
115
|
+
//
|
|
116
|
+
// A profile has no such package. Its only framework dependency is
|
|
117
|
+
// linked with `file:`, and a `file:` link does not install the linked
|
|
118
|
+
// package's own dependencies — Bun expects the surrounding workspace
|
|
119
|
+
// to provide them, and ~/.axon is not one. The result was a frame
|
|
120
|
+
// whose tsconfig named a type library that was not on disk: `Bun`,
|
|
121
|
+
// `process` and `fetch` all unresolved in a user's plugin.
|
|
122
|
+
deps["@types/bun"] = "^1.2.0"
|
|
123
|
+
|
|
124
|
+
// A `file:` link resolves the linked package's own `workspace:*`
|
|
125
|
+
// ranges from a directory that is not a workspace, so anything it
|
|
126
|
+
// depends on has to be linked alongside it — same as the agent set.
|
|
127
|
+
if (source === "workspace" && repoRoot) {
|
|
128
|
+
for (const [name, path] of Object.entries(FRAMEWORK_TRANSITIVE)) {
|
|
129
|
+
deps[name] = `file:${join(repoRoot, path)}`
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return deps
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
for (const name of Object.keys(FRAMEWORK_PACKAGES) as (keyof typeof FRAMEWORK_PACKAGES)[]) {
|
|
136
|
+
deps[name] = frameworkSpecifier(name, frameworkVersion, source, repoRoot)
|
|
137
|
+
}
|
|
138
|
+
// Only when linking: published mode resolves these transitively.
|
|
139
|
+
if (source === "workspace" && repoRoot) {
|
|
140
|
+
for (const [name, path] of Object.entries(FRAMEWORK_TRANSITIVE)) {
|
|
141
|
+
deps[name] = `file:${join(repoRoot, path)}`
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// h3 is a real npm dependency in every mode — it is not ours, so there is
|
|
145
|
+
// no working tree to point at.
|
|
146
|
+
deps.h3 = "^1.13.0"
|
|
147
|
+
return deps
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type PackageJson = {
|
|
151
|
+
name?: string
|
|
152
|
+
version?: string
|
|
153
|
+
description?: string
|
|
154
|
+
private?: boolean
|
|
155
|
+
dependencies?: Record<string, string>
|
|
156
|
+
/**
|
|
157
|
+
* Axon's own bookkeeping, namespaced so it cannot collide with npm's
|
|
158
|
+
* fields or another tool's.
|
|
159
|
+
*
|
|
160
|
+
* `trackedFrom` maps a dependency name to the registry base URL its range
|
|
161
|
+
* was AUTO-RESOLVED against. Only ranges Axon wrote itself appear here —
|
|
162
|
+
* a user's pin is their claim and carries no origin.
|
|
163
|
+
*/
|
|
164
|
+
axon?: {
|
|
165
|
+
trackedFrom?: Record<string, string>
|
|
166
|
+
}
|
|
167
|
+
} & Record<string, unknown>
|
|
168
|
+
|
|
169
|
+
type PackageOpts = {
|
|
170
|
+
root: string
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* package.json — the project's identity and declared dependencies.
|
|
175
|
+
*
|
|
176
|
+
* The single reader and writer of this file. There used to be four
|
|
177
|
+
* implementations of "parse the project's package.json" (dependencies.ts,
|
|
178
|
+
* version.ts, installer.ts, bundle/manifest.ts), each with slightly different
|
|
179
|
+
* error behaviour.
|
|
180
|
+
*/
|
|
181
|
+
export function Package(opts: PackageOpts) {
|
|
182
|
+
const path = join(opts.root, "package.json")
|
|
183
|
+
|
|
184
|
+
async function read(): Promise<PackageJson> {
|
|
185
|
+
return JSON.parse(await readFile(path, "utf-8")) as PackageJson
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function write(pkg: PackageJson): Promise<void> {
|
|
189
|
+
await writeFile(path, JSON.stringify(pkg, null, 2) + "\n")
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Increment a semver patch component. Published versions are immutable. */
|
|
193
|
+
function bumpPatch(version: string): string {
|
|
194
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.exec(version)
|
|
195
|
+
if (!match) {
|
|
196
|
+
throw err("VERSION_INVALID", {
|
|
197
|
+
detail: `expected semver, received "${version}"`,
|
|
198
|
+
context: { version: version },
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
return `${match[1]}.${match[2]}.${Number(match[3]) + 1}`
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The declared dependency map.
|
|
206
|
+
*
|
|
207
|
+
* Every mutation of it goes through here, because several callers edit it
|
|
208
|
+
* for unrelated reasons — Installer adds registry ranges, source modules
|
|
209
|
+
* add and prune `file:` specifiers, framework pinning corrects @arcforge
|
|
210
|
+
* versions. Each used to read-modify-write package.json itself, which is a
|
|
211
|
+
* lost update waiting to happen the moment two of them run in one prepare.
|
|
212
|
+
*/
|
|
213
|
+
const dependencies = {
|
|
214
|
+
async all(): Promise<Record<string, string>> {
|
|
215
|
+
return (await read()).dependencies ?? {}
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Set several dependencies at once. Returns true when the manifest
|
|
220
|
+
* actually changed — the caller's signal that an install is needed.
|
|
221
|
+
*
|
|
222
|
+
* `origins` records which REGISTRY an auto-resolved range came from,
|
|
223
|
+
* under `axon.trackedFrom`. Written in this same read-modify-write
|
|
224
|
+
* rather than beside it, for the reason the block comment above gives:
|
|
225
|
+
* two sequential writes are a lost update.
|
|
226
|
+
*
|
|
227
|
+
* Why it must be recorded at all: a range like "^1.0.5" is derived
|
|
228
|
+
* from whichever registry answered at the time, but it is stored in a
|
|
229
|
+
* manifest read by every later install against whatever registry is
|
|
230
|
+
* configured THEN. Without the origin the two are indistinguishable,
|
|
231
|
+
* and a range resolved against local staging permanently breaks
|
|
232
|
+
* installs against production — which is exactly what happened to
|
|
233
|
+
* @axon/zero@^1.0.5, a version that only ever existed on localhost.
|
|
234
|
+
*/
|
|
235
|
+
async set(entries: Record<string, string>, origins?: Record<string, string>): Promise<boolean> {
|
|
236
|
+
const pkg = await read()
|
|
237
|
+
const declared = { ...(pkg.dependencies ?? {}) }
|
|
238
|
+
|
|
239
|
+
let changed = false
|
|
240
|
+
for (const [name, specifier] of Object.entries(entries)) {
|
|
241
|
+
if (declared[name] === specifier) continue
|
|
242
|
+
declared[name] = specifier
|
|
243
|
+
changed = true
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const axon = { ...(pkg.axon ?? {}) } as { trackedFrom?: Record<string, string> }
|
|
247
|
+
if (origins && Object.keys(origins).length > 0) {
|
|
248
|
+
const trackedFrom = { ...(axon.trackedFrom ?? {}) }
|
|
249
|
+
for (const [name, origin] of Object.entries(origins)) {
|
|
250
|
+
if (trackedFrom[name] === origin) continue
|
|
251
|
+
trackedFrom[name] = origin
|
|
252
|
+
changed = true
|
|
253
|
+
}
|
|
254
|
+
axon.trackedFrom = trackedFrom
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (changed) {
|
|
258
|
+
await write({
|
|
259
|
+
...pkg,
|
|
260
|
+
dependencies: declared,
|
|
261
|
+
...(axon.trackedFrom ? { axon } : {}),
|
|
262
|
+
})
|
|
263
|
+
}
|
|
264
|
+
return changed
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Which registry an auto-resolved range was derived from, if recorded.
|
|
269
|
+
*
|
|
270
|
+
* Absent for every range the USER pinned — those are their claim about
|
|
271
|
+
* what they want, not ours about what a registry answered, and must
|
|
272
|
+
* never be re-resolved out from under them.
|
|
273
|
+
*/
|
|
274
|
+
async trackedFrom(): Promise<Record<string, string>> {
|
|
275
|
+
const pkg = await read()
|
|
276
|
+
return (pkg.axon as { trackedFrom?: Record<string, string> } | undefined)?.trackedFrom ?? {}
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
/** Drop dependencies by name. Returns the names that were actually present. */
|
|
280
|
+
async remove(names: string[]): Promise<string[]> {
|
|
281
|
+
const pkg = await read()
|
|
282
|
+
const declared = { ...(pkg.dependencies ?? {}) }
|
|
283
|
+
|
|
284
|
+
const removed = names.filter(name => name in declared)
|
|
285
|
+
if (removed.length === 0) return []
|
|
286
|
+
|
|
287
|
+
for (const name of removed) delete declared[name]
|
|
288
|
+
await write({ ...pkg, dependencies: declared })
|
|
289
|
+
return removed
|
|
290
|
+
},
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const framework = {
|
|
294
|
+
dependencies: frameworkDependencies,
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Ensure package.json declares the framework deps at the pinned
|
|
298
|
+
* version, adding or correcting them in place. Returns true when it
|
|
299
|
+
* changed anything — the caller's signal that an install is needed.
|
|
300
|
+
* This is what self-heals agents scaffolded before the npm-deps model
|
|
301
|
+
* (they had these types injected via machine-local tsconfig paths, and
|
|
302
|
+
* declare none of them).
|
|
303
|
+
*/
|
|
304
|
+
async ensure(frameworkVersion: string, source: FrameworkSource = "published", repoRoot?: string, set: FrameworkSet = "all"): Promise<boolean> {
|
|
305
|
+
const declared = await dependencies.all()
|
|
306
|
+
|
|
307
|
+
// h3 is a range the user may legitimately widen; only add it if
|
|
308
|
+
// absent. The @arcforge packages are exact-pinned to the CLI and
|
|
309
|
+
// corrected if they drift, since a mismatch against the generated
|
|
310
|
+
// .d.ts is a bug.
|
|
311
|
+
//
|
|
312
|
+
// A `workspace:`/`file:` range is exempt, because it is not drift
|
|
313
|
+
// — it is someone deliberately pointing at a local checkout, which
|
|
314
|
+
// is how the framework itself is developed. Correcting it made
|
|
315
|
+
// that impossible: every prepare rewrote the link back to the
|
|
316
|
+
// published version, so a change to the cognet host could never be
|
|
317
|
+
// exercised by an agent without hand-patching node_modules after
|
|
318
|
+
// every single run.
|
|
319
|
+
const isLocal = (range: string | undefined) =>
|
|
320
|
+
range !== undefined && (range.startsWith("workspace:") || range.startsWith("file:"))
|
|
321
|
+
|
|
322
|
+
const required = Object.entries(frameworkDependencies(frameworkVersion, source, repoRoot, set))
|
|
323
|
+
.filter(([name, version]) =>
|
|
324
|
+
declared[name] === undefined
|
|
325
|
+
|| (name.startsWith("@arcforge/") && !isLocal(declared[name]) && declared[name] !== version))
|
|
326
|
+
|
|
327
|
+
// Linked packages declare their OWN deps as `workspace:*`, which
|
|
328
|
+
// resolves only inside a workspace — and a fixture in /tmp is not
|
|
329
|
+
// one. `overrides` redirects those at the same links, which is
|
|
330
|
+
// what makes the whole framework graph resolve from the tree.
|
|
331
|
+
//
|
|
332
|
+
// Written in the SAME read-modify-write as the dependencies, not
|
|
333
|
+
// beside it. Two sequential writes are a lost update: the second
|
|
334
|
+
// read happens before the first has landed, so whichever wrote
|
|
335
|
+
// last silently discarded the other's change — which is exactly
|
|
336
|
+
// what happened, leaving a manifest with overrides and no
|
|
337
|
+
// framework dependencies at all.
|
|
338
|
+
const links = source === "workspace" && repoRoot
|
|
339
|
+
? Object.fromEntries(
|
|
340
|
+
Object.entries(frameworkDependencies(frameworkVersion, source, repoRoot, set))
|
|
341
|
+
.filter(([, spec]) => spec.startsWith("file:")),
|
|
342
|
+
)
|
|
343
|
+
: {}
|
|
344
|
+
|
|
345
|
+
if (required.length === 0 && Object.keys(links).length === 0) return false
|
|
346
|
+
|
|
347
|
+
const pkg = await read()
|
|
348
|
+
const nextDeps = { ...(pkg.dependencies ?? {}), ...Object.fromEntries(required) }
|
|
349
|
+
const nextOverrides = { ...((pkg.overrides ?? {}) as Record<string, string>), ...links }
|
|
350
|
+
|
|
351
|
+
const changed = JSON.stringify(pkg.dependencies) !== JSON.stringify(nextDeps)
|
|
352
|
+
|| JSON.stringify(pkg.overrides) !== JSON.stringify(nextOverrides)
|
|
353
|
+
if (!changed) return false
|
|
354
|
+
|
|
355
|
+
await write({
|
|
356
|
+
...pkg,
|
|
357
|
+
dependencies: nextDeps,
|
|
358
|
+
...(Object.keys(nextOverrides).length > 0 ? { overrides: nextOverrides } : {}),
|
|
359
|
+
})
|
|
360
|
+
return true
|
|
361
|
+
},
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return {
|
|
365
|
+
path: path,
|
|
366
|
+
read: read,
|
|
367
|
+
write: write,
|
|
368
|
+
bumpPatch: bumpPatch,
|
|
369
|
+
dependencies: dependencies,
|
|
370
|
+
framework: framework,
|
|
371
|
+
|
|
372
|
+
/** Merge fields into package.json, preserving everything else. */
|
|
373
|
+
async update(fields: Partial<PackageJson>): Promise<void> {
|
|
374
|
+
await write({ ...(await read()), ...fields })
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
/** Persist the next patch version; callers rebuild so every artifact agrees. */
|
|
378
|
+
async bump(version: string): Promise<string> {
|
|
379
|
+
const next = bumpPatch(version)
|
|
380
|
+
await write({ ...(await read()), version: next })
|
|
381
|
+
return next
|
|
382
|
+
},
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export type PackageT = ReturnType<typeof Package>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surgical text editing primitives.
|
|
3
|
+
*
|
|
4
|
+
* The manifest files an agent owns — axon.config.ts, bunfig.toml — are files a
|
|
5
|
+
* HUMAN wrote and reads. Every edit here is deliberately textual rather than an
|
|
6
|
+
* AST or TOML round-trip: reprinting from a parse tree would reformat their
|
|
7
|
+
* code and lose their comments. The edits are narrow enough to be exact, and
|
|
8
|
+
* refuse to guess when they are not.
|
|
9
|
+
*
|
|
10
|
+
* That makes regex construction a shared concern of every editor, which is why
|
|
11
|
+
* this exists — `escape` was previously copied byte-for-byte into both
|
|
12
|
+
* config.ts and bunfig.ts.
|
|
13
|
+
*/
|
|
14
|
+
export const text = {
|
|
15
|
+
/** Escape a value for literal use inside a RegExp. */
|
|
16
|
+
escape(value: string): string {
|
|
17
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
18
|
+
},
|
|
19
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { err } from "@arcforge/err"
|
|
2
|
+
import { basenameOf, downloadUrl, type ParsedModel } from "./specifier"
|
|
3
|
+
import type { ModelStoreT, StoredModel } from "./store"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetching weights from Hugging Face.
|
|
7
|
+
*
|
|
8
|
+
* No SDK: the raw-file endpoint is a stable, documented URL and public repos
|
|
9
|
+
* need no auth. A dependency on `@huggingface/hub` would buy a nicer API for
|
|
10
|
+
* an operation that is one GET.
|
|
11
|
+
*
|
|
12
|
+
* VERIFICATION IS NOT OPTIONAL, but what can be verified varies:
|
|
13
|
+
*
|
|
14
|
+
* - a `sha256` pinned in the ref is authoritative and always checked
|
|
15
|
+
* - LFS-backed files carry their real sha256 in `x-linked-etag`, which is
|
|
16
|
+
* the registry's own claim about the bytes and is checked before caching
|
|
17
|
+
* - small non-LFS files carry only a git blob sha, which is NOT a content
|
|
18
|
+
* hash — so those are trust-on-first-use, hashed on arrival and remembered
|
|
19
|
+
*
|
|
20
|
+
* The difference is stated rather than hidden. An author who wants certainty
|
|
21
|
+
* pins `sha256`, and then a changed upstream is an error instead of a
|
|
22
|
+
* surprise. Whatever the source, the bytes are hashed before they are stored,
|
|
23
|
+
* so the cache is content-addressed either way.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** The hash HF claims for this file, when it can be known before downloading. */
|
|
27
|
+
async function expectedHash(model: ParsedModel): Promise<string | null> {
|
|
28
|
+
if (model.sha256) return model.sha256
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const response = await fetch(downloadUrl(model), { method: "HEAD", redirect: "follow" })
|
|
32
|
+
if (!response.ok) return null
|
|
33
|
+
|
|
34
|
+
// ONLY `x-linked-etag`. That header is the LFS object's sha256 — the
|
|
35
|
+
// hash of the bytes actually served.
|
|
36
|
+
//
|
|
37
|
+
// The plain `etag` is NOT usable, even though it is also 64 hex
|
|
38
|
+
// characters and looks identical. For non-LFS files it is the git
|
|
39
|
+
// BLOB sha, which hashes `blob <len>\0<content>` rather than the
|
|
40
|
+
// content, so it never matches and every download would be rejected
|
|
41
|
+
// as corrupt. A hash that looks right and is wrong is worse than no
|
|
42
|
+
// hash at all.
|
|
43
|
+
const linked = response.headers.get("x-linked-etag")?.replace(/"/g, "").trim()
|
|
44
|
+
return linked && /^[0-9a-f]{64}$/i.test(linked) ? linked.toLowerCase() : null
|
|
45
|
+
} catch {
|
|
46
|
+
// A HEAD that fails is not itself a failure — the GET below reports
|
|
47
|
+
// the real problem with a better message.
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type FetchOpts = {
|
|
53
|
+
store: ModelStoreT
|
|
54
|
+
/** Called before a download actually starts — nothing is emitted for a cache hit. */
|
|
55
|
+
onDownload?: (model: ParsedModel) => void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Resolve one model to a stored file, downloading only if needed.
|
|
60
|
+
*
|
|
61
|
+
* Fails loudly on every invalid state: an unreachable registry, a 404, a hash
|
|
62
|
+
* that disagrees. A brain whose weights are missing is not degraded, it is
|
|
63
|
+
* broken, and discovering that at first inference is far worse than at
|
|
64
|
+
* prepare.
|
|
65
|
+
*/
|
|
66
|
+
export async function fetchModel(model: ParsedModel, opts: FetchOpts): Promise<StoredModel> {
|
|
67
|
+
// A pinned model is answerable from its own address, with no network.
|
|
68
|
+
const cached = await opts.store.find(model)
|
|
69
|
+
if (cached) return cached
|
|
70
|
+
|
|
71
|
+
// An unpinned one needs the index: without a declared hash there is no
|
|
72
|
+
// address to look up, and a registry may not publish a usable one either.
|
|
73
|
+
// Skipping this made every prepare re-download every model.
|
|
74
|
+
const remembered = await opts.store.resolved(specifierOf(model))
|
|
75
|
+
if (remembered) return remembered
|
|
76
|
+
|
|
77
|
+
const expected = await expectedHash(model)
|
|
78
|
+
if (expected && opts.store.has(expected, basenameOf(model))) {
|
|
79
|
+
const hit = {
|
|
80
|
+
path: opts.store.pathFor(expected, basenameOf(model)),
|
|
81
|
+
sha256: expected,
|
|
82
|
+
bytes: 0,
|
|
83
|
+
}
|
|
84
|
+
await opts.store.remember(specifierOf(model), hit, basenameOf(model))
|
|
85
|
+
return hit
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
opts.onDownload?.(model)
|
|
89
|
+
|
|
90
|
+
let response: Response
|
|
91
|
+
try {
|
|
92
|
+
response = await fetch(downloadUrl(model), { redirect: "follow" })
|
|
93
|
+
} catch (cause) {
|
|
94
|
+
throw err("MODEL_FETCH_FAILED", {
|
|
95
|
+
detail: `${model.key}: could not reach huggingface.co for ${model.repo}/${model.file}`,
|
|
96
|
+
context: { key: model.key, repo: model.repo, file: model.file },
|
|
97
|
+
cause,
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
throw err("MODEL_FETCH_FAILED", {
|
|
103
|
+
detail:
|
|
104
|
+
response.status === 404
|
|
105
|
+
? `${model.key}: ${model.repo}/${model.file} not found at revision ${model.rev} `
|
|
106
|
+
+ `— check the repo and file path`
|
|
107
|
+
: `${model.key}: huggingface.co answered ${response.status} for ${model.repo}/${model.file}`,
|
|
108
|
+
context: { key: model.key, repo: model.repo, file: model.file, status: response.status },
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const data = new Uint8Array(await response.arrayBuffer())
|
|
113
|
+
// put() hashes and refuses a mismatch — verification lives at the write,
|
|
114
|
+
// so nothing can reach the cache unverified by any path.
|
|
115
|
+
const stored = await opts.store.put(basenameOf(model), data, expected ?? undefined)
|
|
116
|
+
await opts.store.remember(specifierOf(model), stored, basenameOf(model))
|
|
117
|
+
return stored
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The index key: what was declared, including the revision it was declared at. */
|
|
121
|
+
function specifierOf(model: ParsedModel): string {
|
|
122
|
+
return `${model.host}:${model.repo}@${model.rev}/${model.file}`
|
|
123
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// models — a cognet's declared weights, from specifier to absolute path.
|
|
2
|
+
//
|
|
3
|
+
// External code uses Models(); the leaves below it are its own.
|
|
4
|
+
|
|
5
|
+
export { Models, type ModelsT, type ResolveResult } from "./models"
|
|
6
|
+
export { ModelStore, type ModelStoreT, type StoredModel } from "./store"
|
|
7
|
+
export { parseModel, parseModels, downloadUrl, basenameOf, type ParsedModel } from "./specifier"
|
|
8
|
+
export { fetchModel } from "./fetch"
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { err } from "@arcforge/err"
|
|
2
|
+
import type { ModelRef } from "@arcforge/types"
|
|
3
|
+
import { fetchModel } from "./fetch"
|
|
4
|
+
import { parseModels, type ParsedModel } from "./specifier"
|
|
5
|
+
import { ModelStore, type ModelStoreT } from "./store"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Models — a cognet's declared weights, from specifier to absolute path.
|
|
9
|
+
*
|
|
10
|
+
* Owns the whole small toolchain: parse what was declared, reconcile it
|
|
11
|
+
* against the machine's cache, fetch what is missing, and hand back the map
|
|
12
|
+
* the kernel gives the brain.
|
|
13
|
+
*
|
|
14
|
+
* It knows nothing about ML. A weight is a file with a hash and a name the
|
|
15
|
+
* cognet chose; whether those bytes are a VAD, a language model or a lookup
|
|
16
|
+
* table is the cognet's business, and the runtime that executes them is an
|
|
17
|
+
* ordinary npm dependency the cognet imports. This is an asset store that
|
|
18
|
+
* happens to be used for models.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
type ModelsOpts = {
|
|
22
|
+
/** Override the cache root — tests and deployment images both use this. */
|
|
23
|
+
store?: ModelStoreT
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ResolveResult = {
|
|
27
|
+
/** Local name → absolute path. What the blueprint carries and the kernel hands over. */
|
|
28
|
+
paths: Record<string, string>
|
|
29
|
+
/** Models actually downloaded this run — everything else was already cached. */
|
|
30
|
+
fetched: string[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function Models(opts: ModelsOpts = {}) {
|
|
34
|
+
const store = opts.store ?? ModelStore()
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
get store() {
|
|
38
|
+
return store
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/** Parse without touching the network — what `--frozen` inspects. */
|
|
42
|
+
parse(models: Record<string, ModelRef> | undefined): ParsedModel[] {
|
|
43
|
+
return parseModels(models)
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Which declared models are NOT already on this machine.
|
|
48
|
+
*
|
|
49
|
+
* Only decidable without the network for PINNED refs, whose hash is
|
|
50
|
+
* their address. An unpinned model has to ask the registry what its
|
|
51
|
+
* hash is before the cache can be consulted, so it always counts as
|
|
52
|
+
* missing here — conservative in the safe direction: the worst case
|
|
53
|
+
* is a HEAD request that finds it cached after all.
|
|
54
|
+
*/
|
|
55
|
+
missing(models: ParsedModel[]): ParsedModel[] {
|
|
56
|
+
return models.filter(model => {
|
|
57
|
+
if (!model.sha256) return true
|
|
58
|
+
return !store.has(model.sha256, model.file.split("/").pop()!)
|
|
59
|
+
})
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Resolve every declared model to an absolute path, fetching what is
|
|
64
|
+
* absent.
|
|
65
|
+
*
|
|
66
|
+
* Sequential rather than parallel: these are large files, and ten
|
|
67
|
+
* concurrent 150MB downloads is a worse experience than ten in a row
|
|
68
|
+
* on every connection that is not a datacentre.
|
|
69
|
+
*/
|
|
70
|
+
async resolve(
|
|
71
|
+
models: Record<string, ModelRef> | undefined,
|
|
72
|
+
resolveOpts: { frozen?: boolean; onDownload?: (model: ParsedModel) => void } = {},
|
|
73
|
+
): Promise<ResolveResult> {
|
|
74
|
+
const parsed = parseModels(models)
|
|
75
|
+
if (parsed.length === 0) return { paths: {}, fetched: [] }
|
|
76
|
+
|
|
77
|
+
if (resolveOpts.frozen) {
|
|
78
|
+
// --frozen asserts the machine is already provisioned. It
|
|
79
|
+
// must not become the thing that provisions it, or the check
|
|
80
|
+
// could never fail.
|
|
81
|
+
const absent = parsed.filter(m => !m.sha256 || !store.has(m.sha256, m.file.split("/").pop()!))
|
|
82
|
+
if (absent.length > 0) {
|
|
83
|
+
throw err("MODEL_NOT_CACHED", {
|
|
84
|
+
detail:
|
|
85
|
+
`${absent.map(m => m.key).join(", ")} not in the model cache — `
|
|
86
|
+
+ `run \`axon prepare\` without --frozen to fetch`,
|
|
87
|
+
context: { keys: absent.map(m => m.key) },
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const paths: Record<string, string> = {}
|
|
93
|
+
const fetched: string[] = []
|
|
94
|
+
|
|
95
|
+
for (const model of parsed) {
|
|
96
|
+
const stored = await fetchModel(model, {
|
|
97
|
+
store,
|
|
98
|
+
onDownload: m => {
|
|
99
|
+
fetched.push(m.key)
|
|
100
|
+
resolveOpts.onDownload?.(m)
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
paths[model.key] = stored.path
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { paths, fetched }
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type ModelsT = ReturnType<typeof Models>
|