@arcforge/platform 2.0.219 → 2.0.245

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.
Files changed (127) hide show
  1. package/package.json +27 -19
  2. package/src/build/blueprint/blueprint.ts +48 -64
  3. package/src/build/blueprint/cognet/abi.ts +3 -257
  4. package/src/build/blueprint/cognet/bundle-worker.ts +11 -0
  5. package/src/build/blueprint/cognet/bundle.ts +294 -89
  6. package/src/build/blueprint/cognet/cognet.ts +8 -7
  7. package/src/build/blueprint/cognet/config/config.ts +52 -0
  8. package/src/build/blueprint/cognet/config/index.ts +4 -0
  9. package/src/build/blueprint/cognet/config/literal.ts +83 -0
  10. package/src/build/blueprint/cognet/config/provider.ts +43 -0
  11. package/src/build/blueprint/cognet/config/shape.ts +183 -0
  12. package/src/build/blueprint/cognet/index.ts +4 -2
  13. package/src/build/blueprint/cognet/native/cargo.ts +31 -0
  14. package/src/build/blueprint/cognet/native/crate.ts +126 -0
  15. package/src/build/blueprint/cognet/native/index.ts +2 -0
  16. package/src/build/blueprint/cognet/native/library.ts +125 -0
  17. package/src/build/blueprint/cognet/native/manifest.ts +137 -0
  18. package/src/build/blueprint/cognet/python/index.ts +1 -0
  19. package/src/build/blueprint/cognet/python/project.ts +119 -0
  20. package/src/build/blueprint/cognet/schema/arrays.ts +23 -0
  21. package/src/build/blueprint/cognet/schema/authored.ts +273 -0
  22. package/src/build/blueprint/cognet/schema/compile.ts +78 -0
  23. package/src/build/blueprint/cognet/schema/components/external.ts +15 -0
  24. package/src/build/blueprint/cognet/schema/components/index.ts +3 -0
  25. package/src/build/blueprint/cognet/schema/components/lock.ts +58 -0
  26. package/src/build/blueprint/cognet/schema/components/model.ts +34 -0
  27. package/src/build/blueprint/cognet/schema/components/python.ts +15 -0
  28. package/src/build/blueprint/cognet/schema/components/python_source.py +69 -0
  29. package/src/build/blueprint/cognet/schema/components/rust.ts +33 -0
  30. package/src/build/blueprint/cognet/schema/components/rust_source/Cargo.lock +117 -0
  31. package/src/build/blueprint/cognet/schema/components/rust_source/Cargo.toml +11 -0
  32. package/src/build/blueprint/cognet/schema/components/rust_source/src/main.rs +104 -0
  33. package/src/build/blueprint/cognet/schema/components/source.ts +220 -0
  34. package/src/build/blueprint/cognet/schema/components/tags.ts +66 -0
  35. package/src/build/blueprint/cognet/schema/components/typescript.ts +157 -0
  36. package/src/build/blueprint/cognet/schema/index.ts +5 -0
  37. package/src/build/blueprint/cognet/schema/interfaces/index.ts +3 -0
  38. package/src/build/blueprint/cognet/schema/interfaces/source.ts +218 -0
  39. package/src/build/blueprint/cognet/schema/python.ts +260 -0
  40. package/src/build/blueprint/cognet/schema/rust.ts +316 -0
  41. package/src/build/blueprint/cognet/schema/schema.ts +248 -0
  42. package/src/build/blueprint/cognet/schema/typescript.ts +352 -0
  43. package/src/build/blueprint/index.ts +1 -1
  44. package/src/build/blueprint/modules/index.ts +7 -5
  45. package/src/build/blueprint/modules/meta.ts +47 -3
  46. package/src/build/blueprint/scan/config.ts +22 -16
  47. package/src/build/blueprint/scan/provider-globals.ts +46 -0
  48. package/src/build/blueprint/scan/providers.ts +25 -0
  49. package/src/build/blueprint/scan/tools.ts +21 -15
  50. package/src/build/extensions/edit.ts +66 -2
  51. package/src/build/extensions/extensions.ts +16 -3
  52. package/src/build/extensions/index.ts +1 -1
  53. package/src/build/project/bundle/agent.ts +26 -17
  54. package/src/build/project/bundle/source.ts +2 -2
  55. package/src/build/project/create/cognet.ts +84 -33
  56. package/src/build/project/create/profile.ts +13 -3
  57. package/src/build/project/index.ts +1 -1
  58. package/src/build/project/installer.ts +6 -5
  59. package/src/build/project/kinds.ts +4 -0
  60. package/src/build/project/manifest/env.ts +10 -0
  61. package/src/build/project/models/blobs/blobs.ts +57 -0
  62. package/src/build/project/models/blobs/index.ts +1 -0
  63. package/src/build/project/models/fetch.ts +46 -51
  64. package/src/build/project/models/index.ts +2 -1
  65. package/src/build/project/models/models.ts +12 -38
  66. package/src/build/project/models/onnx.ts +82 -0
  67. package/src/build/project/models/specifier.ts +9 -3
  68. package/src/build/project/models/storage/index-store.ts +27 -0
  69. package/src/build/project/models/storage/index.ts +1 -0
  70. package/src/build/project/models/store.ts +21 -16
  71. package/src/build/project/prepare.ts +82 -27
  72. package/src/build/project/project.ts +8 -14
  73. package/src/build/project/projects.ts +12 -1
  74. package/src/build/project/tree.ts +13 -3
  75. package/src/build/project/treecache.ts +8 -4
  76. package/src/build/project/typegen/axon-dts.ts +18 -0
  77. package/src/build/project/typegen/cognet-dts.ts +248 -59
  78. package/src/build/project/typegen/prompt-dts.ts +2 -3
  79. package/src/build/project/typegen/registry-dts.ts +2 -2
  80. package/src/build/project/typegen/tsconfig.ts +13 -13
  81. package/src/build/project/typegen/tui-dts.ts +3 -4
  82. package/src/build/project/typegen/workspace-scripts.ts +8 -7
  83. package/src/build/project/typegen/write.ts +15 -2
  84. package/src/build/project/watcher.ts +27 -0
  85. package/src/build/runtime/agent.ts +102 -63
  86. package/src/build/runtime/conformance.ts +25 -0
  87. package/src/build/runtime/escalations.ts +3 -8
  88. package/src/build/runtime/index.ts +2 -0
  89. package/src/build/runtime/instances.ts +7 -4
  90. package/src/build/runtime/progress.ts +6 -2
  91. package/src/build/runtime/reload-watch.ts +11 -8
  92. package/src/debug/README.md +398 -0
  93. package/src/debug/debug.ts +101 -0
  94. package/src/debug/events.ts +156 -0
  95. package/src/debug/graph.ts +94 -0
  96. package/src/debug/index.ts +5 -0
  97. package/src/debug/indexer.ts +286 -0
  98. package/src/debug/inference.ts +53 -0
  99. package/src/debug/log.ts +68 -0
  100. package/src/debug/overview.ts +78 -0
  101. package/src/debug/perf.ts +75 -0
  102. package/src/debug/resources.ts +125 -0
  103. package/src/debug/ring.ts +31 -0
  104. package/src/debug/sessions.ts +90 -0
  105. package/src/debug/signs.ts +119 -0
  106. package/src/debug/tally.ts +44 -0
  107. package/src/debug/types.ts +146 -0
  108. package/src/index.ts +9 -0
  109. package/src/link/agent-main.ts +36 -10
  110. package/src/link/index.ts +1 -1
  111. package/src/link/services.ts +88 -57
  112. package/src/platform.ts +17 -25
  113. package/src/services/cloud.ts +1 -4
  114. package/src/services/control/client.ts +1 -1
  115. package/src/services/control/server.ts +1 -1
  116. package/src/services/index.ts +1 -0
  117. package/src/services/ollama/daemon.ts +23 -0
  118. package/src/services/ollama/http.ts +7 -1
  119. package/src/services/ollama/ollama.ts +8 -14
  120. package/src/services/probe/ask.ts +139 -0
  121. package/src/services/probe/index.ts +3 -0
  122. package/src/services/providers.ts +18 -0
  123. package/src/services/resources/hardware.ts +15 -18
  124. package/src/services/resources/resources.ts +4 -5
  125. package/src/services/store/types.ts +3 -0
  126. package/src/services/running/index.ts +0 -1
  127. package/src/services/running/running.ts +0 -216
@@ -0,0 +1,18 @@
1
+ import type { ProviderEntry } from "@arcforge/types"
2
+ import type { ProfileConfigResult } from "../build/extensions"
3
+
4
+ /** Reads the active machine policy without turning a broken config into account discovery. */
5
+ export function ProfileProviders(opts: {
6
+ root(): string | undefined
7
+ read(root: string): Promise<ProfileConfigResult>
8
+ }) {
9
+ return {
10
+ async read(): Promise<readonly ProviderEntry[] | undefined> {
11
+ const root = opts.root()
12
+ if (!root) return undefined
13
+ const result = await opts.read(root)
14
+ if (result.error) throw result.error
15
+ return result.providers
16
+ },
17
+ }
18
+ }
@@ -1,4 +1,5 @@
1
1
  import { totalmem } from "node:os"
2
+ import { ask } from "../probe"
2
3
 
3
4
  /**
4
5
  * What this machine can offer local inference.
@@ -40,21 +41,17 @@ function fromMiB(text: string): number | null {
40
41
  * report one line each; the FIRST is used rather than the sum, because a
41
42
  * model loads onto one card and a total across cards would advertise room no
42
43
  * single load can use.
44
+ *
45
+ * Asked, never waited on: a synchronous spawn of nvidia-smi once wedged a
46
+ * test worker on its un-reaped child for hours (see probe/ask.ts). The first
47
+ * reading is "unknown" — which means unbounded, never empty — and the real
48
+ * one lands a moment later.
43
49
  */
44
50
  function nvidiaVram(): number | null {
45
- try {
46
- const probe = Bun.spawnSync([
47
- "nvidia-smi",
48
- "--query-gpu=memory.total",
49
- "--format=csv,noheader,nounits",
50
- ])
51
- if (probe.exitCode !== 0) return null
52
-
53
- const first = probe.stdout.toString().trim().split("\n")[0]
54
- return first ? fromMiB(first) : null
55
- } catch {
56
- return null
57
- }
51
+ const probe = ask(["nvidia-smi", "--query-gpu=memory.total", "--format=csv,noheader,nounits"])
52
+ if (probe.exitCode !== 0) return null
53
+ const first = probe.stdout.toString().trim().split("\n")[0]
54
+ return first ? fromMiB(first) : null
58
55
  }
59
56
 
60
57
  /**
@@ -72,12 +69,12 @@ function appleVram(): number | null {
72
69
  }
73
70
 
74
71
  /**
75
- * Read this machine once.
72
+ * Read this machine, as last measured.
76
73
  *
77
- * Synchronous and cheap enough to call per boot: one subprocess on NVIDIA,
78
- * arithmetic everywhere else. Not cached here — a caller that wants it cached
79
- * holds it, and a long-running process re-reading after a driver change is a
80
- * feature rather than a cost.
74
+ * Synchronous and cheap: the NVIDIA reading is the last answer of a probe
75
+ * refreshed in the background, arithmetic everywhere else. Read it per use
76
+ * rather than holding it — the first reading may be "unknown" until the probe
77
+ * answers, and a driver change is a reading worth seeing.
81
78
  */
82
79
  export function probeHardware(): Hardware {
83
80
  const nvidia = nvidiaVram()
@@ -57,7 +57,6 @@ type ResourcesOpts = {
57
57
  }
58
58
 
59
59
  export function Resources(opts: ResourcesOpts = {}) {
60
- const hardware = probeHardware()
61
60
  const reservations = opts.reservations ?? Reservations()
62
61
 
63
62
  /**
@@ -71,7 +70,7 @@ export function Resources(opts: ResourcesOpts = {}) {
71
70
  function ceiling(): number | null {
72
71
  const declared = parseSize(opts.budget?.()?.vram)
73
72
  if (declared !== null) return declared
74
- return hardware.vram ?? null
73
+ return probeHardware().vram ?? null
75
74
  }
76
75
 
77
76
  function state(): ResourceState {
@@ -80,7 +79,7 @@ export function Resources(opts: ResourcesOpts = {}) {
80
79
  const limit = ceiling()
81
80
 
82
81
  return {
83
- hardware,
82
+ hardware: probeHardware(),
84
83
  budget: parseSize(opts.budget?.()?.vram),
85
84
  held,
86
85
  // Never negative: over-commitment is possible (a load that grew
@@ -93,7 +92,7 @@ export function Resources(opts: ResourcesOpts = {}) {
93
92
 
94
93
  return {
95
94
  get hardware(): Hardware {
96
- return hardware
95
+ return probeHardware()
97
96
  },
98
97
 
99
98
  state,
@@ -127,7 +126,7 @@ export function Resources(opts: ResourcesOpts = {}) {
127
126
 
128
127
  throw err("RESOURCES_EXHAUSTED", {
129
128
  detail: `${entry.model} needs ${formatSize(entry.bytes)}, `
130
- + `${formatSize(current.available)} available of ${formatSize(current.budget ?? hardware.vram ?? 0)}.`
129
+ + `${formatSize(current.available)} available of ${formatSize(current.budget ?? current.hardware.vram ?? 0)}.`
131
130
  + (holders ? `\n\nheld by:\n${holders}` : ""),
132
131
  context: {
133
132
  model: entry.model,
@@ -255,6 +255,9 @@ export type AppState = {
255
255
  */
256
256
  lastAgent?: string
257
257
 
258
+ /** Last selected Claude subscription model, when Claude owns the terminal. */
259
+ lastClaudeModel?: string
260
+
258
261
  /**
259
262
  * Last known model per agent, keyed by ADDRESS.
260
263
  *
@@ -1 +0,0 @@
1
- export { Running, type RunningT } from "./running"
@@ -1,216 +0,0 @@
1
- import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, watch, writeFileSync } from "node:fs"
2
- import type { FSWatcher } from "node:fs"
3
- import { homedir } from "node:os"
4
- import { join } from "node:path"
5
- import type { AxonInstance } from "@arcforge/types"
6
-
7
- /**
8
- * Every store root a locally-booted agent might register in.
9
- *
10
- * `~/.axon` is the installed CLI's store; `~/.axon-dev` is what a source
11
- * build uses (see resolvePlatformEnvironment — production is hermetic, so
12
- * source development gets its own store and the two cannot collide). They
13
- * hold the same shape and describe the same machine, so an observer reads
14
- * both: an agent is running whether or not the binary that booted it was
15
- * the installed one.
16
- */
17
- const ROOTS = [
18
- join(homedir(), ".axon", "cache", "running"),
19
- join(homedir(), ".axon-dev", "cache", "running"),
20
- // The pre-cache/ locations. Read, never written — an agent booted by an
21
- // older binary is still running on this machine, and an observer that
22
- // could not see it would report the machine as idle while it worked.
23
- // Records here drain on their own: every reader probes the pid, so one
24
- // whose process has gone is already indistinguishable from no record.
25
- join(homedir(), ".axon", "running"),
26
- join(homedir(), ".axon-dev", "running"),
27
- ]
28
-
29
- /** True if a process with this pid exists — sends no signal (kill(pid, 0)), just probes. */
30
- function isAlive(pid: number): boolean {
31
- try {
32
- process.kill(pid, 0)
33
- return true
34
- } catch {
35
- return false
36
- }
37
- }
38
-
39
- /**
40
- * A record that fails to parse (a write torn mid-flush) or predates the
41
- * current shape is treated as absent rather than thrown — the next write
42
- * supersedes it, and one bad file must never empty a reader's whole view.
43
- */
44
- function read(path: string): AxonInstance | null {
45
- try {
46
- const record = JSON.parse(readFileSync(path, "utf-8")) as AxonInstance
47
- return typeof record.dataRoot === "string" && typeof record.pid === "number" ? record : null
48
- } catch {
49
- return null
50
- }
51
- }
52
-
53
- type RunningOpts = {
54
- /** Where THIS process registers itself. Readers still see every root. */
55
- root?: string
56
- /**
57
- * Read ONLY `root`, rather than every well-known store.
58
- *
59
- * The default is deliberately wide: an observer must see an agent booted by
60
- * the installed binary and one booted from a source checkout alike, or it
61
- * reports an idle machine while work is running. That is right in
62
- * production and wrong under test, where sweeping the real `~/.axon` means
63
- * a developer with an agent open fails an assertion about an empty store —
64
- * and, worse, a test can DELETE a real record (`remove` sweeps every root).
65
- *
66
- * The daemon's Registry already carries this exact flag; naming it the same
67
- * way here keeps one idea with one spelling.
68
- */
69
- isolated?: boolean
70
- /** Coalesce a burst of fs events (several agents booting at once) into one callback. */
71
- debounceMs?: number
72
- /** How often to re-check without an fs event — catches a crashed pid, which touches no file. */
73
- pollMs?: number
74
- }
75
-
76
- /**
77
- * Running — the registry of locally-running Axon processes.
78
- *
79
- * One file per live process at `<store>/running/<sessionId>.json`, with the
80
- * pid as the liveness proof. No daemon, no IPC, no lockfile: any process on
81
- * the machine can read it, and correctness comes from the OS rather than
82
- * from cooperation between writers.
83
- *
84
- * Self-healing by construction. A dead record is DELETED on read, not
85
- * skipped, so GC happens on whichever process looks next and a `kill -9`
86
- * leaves no permanent ghost. That is also why the registry holds no
87
- * authored state — nothing here can disagree with reality, because
88
- * everything here is either checkable against the OS or written once at
89
- * boot.
90
- *
91
- * Answers exactly one question: what is running RIGHT NOW. A finished run
92
- * leaves nothing behind; its session log is the durable trace.
93
- */
94
- export function Running(opts: RunningOpts = {}) {
95
- const writeRoot = opts.root ?? ROOTS[0]!
96
- /** Every directory this instance reads and prunes. See `isolated`. */
97
- const roots = opts.isolated === true ? [writeRoot] : [...new Set([...ROOTS, writeRoot])]
98
- const debounceMs = opts.debounceMs ?? 100
99
- const pollMs = opts.pollMs ?? 5000
100
-
101
- let watchers: FSWatcher[] = []
102
- let poll: ReturnType<typeof setInterval> | null = null
103
- let debounce: ReturnType<typeof setTimeout> | null = null
104
- const listeners = new Set<(instances: AxonInstance[]) => void>()
105
-
106
- function fileOf(root: string, sessionId: string): string {
107
- return join(root, `${sessionId}.json`)
108
- }
109
-
110
- function snapshot(): AxonInstance[] {
111
- // Deduped by session id: one process cannot register twice, but a
112
- // stale record in one root must never shadow the live one in another.
113
- const live = new Map<string, AxonInstance>()
114
-
115
- for (const root of roots) {
116
- if (!existsSync(root)) continue
117
-
118
- for (const name of readdirSync(root)) {
119
- if (!name.endsWith(".json")) continue
120
- const path = join(root, name)
121
- const record = read(path)
122
- if (!record) continue
123
-
124
- if (isAlive(record.pid)) live.set(record.sessionId, record)
125
- else rmSync(path, { force: true })
126
- }
127
- }
128
-
129
- return [...live.values()]
130
- }
131
-
132
- function notify(): void {
133
- if (debounce) clearTimeout(debounce)
134
- debounce = setTimeout(() => {
135
- debounce = null
136
- const instances = snapshot()
137
- for (const listener of listeners) listener(instances)
138
- }, debounceMs)
139
- }
140
-
141
- return {
142
- /** Every root read by list()/watch(). Exposed for diagnostics, not for callers to walk. */
143
- roots: roots,
144
-
145
- /** Register this process. Called once, immediately after the runtime is up. */
146
- start(instance: AxonInstance): void {
147
- // 0700/0600: a record may carry the instance's control-channel
148
- // token, which is the only thing standing between another local
149
- // account and a socket that drives this agent. The mode is set
150
- // on the directory AND the file because `recursive: true` does
151
- // not re-chmod a directory that already exists from an earlier
152
- // version.
153
- mkdirSync(writeRoot, { recursive: true, mode: 0o700 })
154
- chmodSync(writeRoot, 0o700)
155
- writeFileSync(fileOf(writeRoot, instance.sessionId), JSON.stringify(instance, null, 2), { mode: 0o600 })
156
- },
157
-
158
- /** Deregister. Called first thing on shutdown — a reader must never see "alive" for a session mid-teardown. */
159
- stop(sessionId: string): void {
160
- for (const root of roots) rmSync(fileOf(root, sessionId), { force: true })
161
- },
162
-
163
- /** Every currently-live instance, pid-checked fresh. Dead records are GC'd as a side effect. */
164
- list(): AxonInstance[] {
165
- return snapshot()
166
- },
167
-
168
- /** One instance by session id, or null when it is not running. */
169
- get(sessionId: string): AxonInstance | null {
170
- return snapshot().find(instance => instance.sessionId === sessionId) ?? null
171
- },
172
-
173
- /**
174
- * Subscribe to the live list. Called once immediately with the
175
- * current snapshot, then on every add/remove/crash.
176
- *
177
- * Two triggers, because one is not enough: fs.watch fires instantly
178
- * when a record appears or is deleted, and a slow poll catches a
179
- * killed process — which touches no file and so fires no fs event
180
- * at all. Returns an unsubscribe function.
181
- */
182
- watch(listener: (instances: AxonInstance[]) => void): () => void {
183
- if (!watchers.length) {
184
- for (const root of roots) {
185
- mkdirSync(root, { recursive: true }) // fs.watch throws on a missing directory
186
- watchers.push(watch(root, () => notify()))
187
- }
188
- poll = setInterval(() => notify(), pollMs)
189
- }
190
-
191
- listeners.add(listener)
192
- listener(snapshot())
193
-
194
- return () => {
195
- listeners.delete(listener)
196
- if (listeners.size === 0) stopWatching()
197
- }
198
- },
199
-
200
- dispose(): void {
201
- stopWatching()
202
- listeners.clear()
203
- },
204
- }
205
-
206
- function stopWatching(): void {
207
- for (const fsWatcher of watchers) fsWatcher.close()
208
- watchers = []
209
- if (poll) clearInterval(poll)
210
- poll = null
211
- if (debounce) clearTimeout(debounce)
212
- debounce = null
213
- }
214
- }
215
-
216
- export type RunningT = ReturnType<typeof Running>