@arcforge/types 2.0.219 → 2.0.244
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -2
- package/src/agent-handle.ts +2 -1
- package/src/blueprint.ts +19 -3
- package/src/body/body.ts +669 -0
- package/src/cognet/blueprint.ts +32 -4
- package/src/cognet/cognet.ts +126 -11
- package/src/cognet/index.ts +2 -2
- package/src/config.ts +21 -3
- package/src/connections.ts +70 -0
- package/src/define.ts +34 -0
- package/src/engine.ts +33 -3
- package/src/error.ts +11 -0
- package/src/handle.ts +67 -0
- package/src/index.ts +8 -0
- package/src/inference.ts +193 -12
- package/src/kernel/abi.ts +132 -10
- package/src/kernel/index.ts +1 -1
- package/src/machine.ts +17 -0
- package/src/provider-usage.ts +63 -0
- package/src/services.ts +79 -0
- package/src/session/channel.ts +15 -0
- package/src/session/envelope.ts +10 -1
- package/src/session/events/activity.ts +13 -1
- package/src/session/events/build.ts +26 -1
- package/src/session/events/cognet.ts +211 -15
- package/src/session/events/kernel.ts +20 -0
- package/src/session/events/runtime.ts +29 -1
- package/src/session/events/stdio/output.ts +6 -0
- package/src/session/events/stdio/shared.ts +35 -0
- package/src/session/events/stdio/stimuli.ts +17 -0
- package/src/session/index.ts +4 -1
- package/src/session/session.ts +2 -2
- package/src/session/text.ts +36 -0
- package/src/supervisor.ts +45 -4
- package/src/tui-contract.ts +1 -1
- package/src/tui.ts +14 -0
- package/src/usage.ts +83 -0
- package/src/world/world.ts +224 -0
package/src/tui.ts
CHANGED
|
@@ -1740,6 +1740,8 @@ export type TuiNotifyHooks = {
|
|
|
1740
1740
|
* rather than the one being replaced.
|
|
1741
1741
|
*/
|
|
1742
1742
|
"agent:model": (payload: AgentModelPayload) => void
|
|
1743
|
+
/** The focused conversation's context reading moved. */
|
|
1744
|
+
"context:changed": (payload: { tokens: number; instance: AgentInstance }) => void
|
|
1743
1745
|
|
|
1744
1746
|
/** The user sent a message. Fires once it is delivered. */
|
|
1745
1747
|
"message:sent": (payload: MessageSentPayload) => void
|
|
@@ -1791,6 +1793,7 @@ export const TUI_HOOK_NAMES = [
|
|
|
1791
1793
|
"agent:stopped",
|
|
1792
1794
|
"agent:focused",
|
|
1793
1795
|
"agent:model",
|
|
1796
|
+
"context:changed",
|
|
1794
1797
|
"message:sent",
|
|
1795
1798
|
"message:received",
|
|
1796
1799
|
"mode:changed",
|
|
@@ -2070,10 +2073,21 @@ export type ProfileSettings = {
|
|
|
2070
2073
|
* "@cody/vim": { leader: "," },
|
|
2071
2074
|
* })
|
|
2072
2075
|
*/
|
|
2076
|
+
/** A broad permission preset, applied before the profile's detailed policy. */
|
|
2077
|
+
export type ProfilePermissions = "normal" | "allow" | "ask"
|
|
2078
|
+
|
|
2073
2079
|
export type ProfileConfig = {
|
|
2074
2080
|
extensions?: ExtensionEntry[]
|
|
2075
2081
|
/** Platform settings — see ProfileSettings. */
|
|
2076
2082
|
settings?: ProfileSettings
|
|
2083
|
+
/**
|
|
2084
|
+
* The profile-wide posture for commands and tools.
|
|
2085
|
+
*
|
|
2086
|
+
* `normal` follows each agent's policy. `allow` permits commands and tools
|
|
2087
|
+
* unless an agent explicitly narrows them. `ask` raises every command and
|
|
2088
|
+
* tool for approval in the active TUI.
|
|
2089
|
+
*/
|
|
2090
|
+
permissions?: ProfilePermissions
|
|
2077
2091
|
/**
|
|
2078
2092
|
* The inference this user HAS — every agent on this profile inherits it.
|
|
2079
2093
|
*
|
package/src/usage.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an agent costs the machine — measured by its supervisor, part by part.
|
|
3
|
+
*
|
|
4
|
+
* Every figure is nullable and null means UNMEASURED, never zero: a machine
|
|
5
|
+
* with no NVIDIA driver cannot attribute GPU use to a process, and drawing
|
|
6
|
+
* that as an idle GPU would claim a reading nobody took.
|
|
7
|
+
*/
|
|
8
|
+
export type UsagePart = {
|
|
9
|
+
/** CPU in cores — 1 is one core fully busy, however many the machine has. */
|
|
10
|
+
cpu: number | null
|
|
11
|
+
/** Resident memory, bytes. */
|
|
12
|
+
ram: number | null
|
|
13
|
+
/** GPU busy, 0–100, as the driver attributes it to these processes. */
|
|
14
|
+
gpu: number | null
|
|
15
|
+
/** Video memory these processes hold, bytes. */
|
|
16
|
+
vram: number | null
|
|
17
|
+
/** How many processes were counted. 0 means the part has nothing running. */
|
|
18
|
+
processes: number
|
|
19
|
+
/** Shared with other agents — a daemon's models, a world's server — so not this agent's alone. */
|
|
20
|
+
shared: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** One thread of the agent's processes, as the OS accounts for it. */
|
|
24
|
+
export type UsageThread = {
|
|
25
|
+
/** The process it belongs to. */
|
|
26
|
+
pid: number
|
|
27
|
+
/** The OS thread id — what a worker reports itself as, so a reader can say which worker this is. */
|
|
28
|
+
tid: number
|
|
29
|
+
/** What the runtime named it: `bun` (the main thread), `Worker`, `HeapHelper`, `JITWorker`, … */
|
|
30
|
+
name: string
|
|
31
|
+
/** Cores busy since the previous sample; null on a thread's first sample. */
|
|
32
|
+
cpu: number | null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type AgentUsage = {
|
|
36
|
+
/** When it was measured, epoch ms. */
|
|
37
|
+
at: number
|
|
38
|
+
/**
|
|
39
|
+
* Named parts of what this agent is running: `brain` (its own process
|
|
40
|
+
* tree), `body` (a lab body it is in), `world` (the server that body is
|
|
41
|
+
* in), and the process supervising it — where its local models run —
|
|
42
|
+
* named for what it is: `daemon`, or `terminal` when a terminal hosts
|
|
43
|
+
* the supervisor itself. Absent when it has none.
|
|
44
|
+
*/
|
|
45
|
+
parts: Record<string, UsagePart>
|
|
46
|
+
/** Every thread of the brain's processes, busiest first — where inside the brain the CPU goes. */
|
|
47
|
+
threads: UsageThread[]
|
|
48
|
+
/** The whole machine at the same moment — what the parts are a share of. */
|
|
49
|
+
machine: {
|
|
50
|
+
cores: number
|
|
51
|
+
/** CPU busy across the machine, 0–100. */
|
|
52
|
+
cpu: number | null
|
|
53
|
+
ram: { used: number; total: number }
|
|
54
|
+
/** GPU busy, 0–100. */
|
|
55
|
+
gpu: number | null
|
|
56
|
+
vram: { used: number | null; total: number | null }
|
|
57
|
+
/**
|
|
58
|
+
* The processes keeping the most CPU busy on the whole machine,
|
|
59
|
+
* busiest first — the agent's or not. What says whose a busy machine
|
|
60
|
+
* is, when the parts above do not add up to it. Absent on a sample
|
|
61
|
+
* from before this was measured.
|
|
62
|
+
*/
|
|
63
|
+
busiest?: UsageProcess[]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** One process on the machine, as the OS accounts for it. */
|
|
68
|
+
export type UsageProcess = {
|
|
69
|
+
pid: number
|
|
70
|
+
/** The command name the kernel knows it by. */
|
|
71
|
+
name: string
|
|
72
|
+
/** Cores busy since the previous sample. */
|
|
73
|
+
cpu: number
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Bun's options for writing a CPU profile into `dir` when the process exits:
|
|
78
|
+
* the raw `.cpuprofile` for a profiler, and markdown a person or a model can
|
|
79
|
+
* read. Handed to a Bun process as BUN_OPTIONS — what AXON_PROFILE turns on.
|
|
80
|
+
*/
|
|
81
|
+
export function profiling(dir: string): string {
|
|
82
|
+
return `--cpu-prof --cpu-prof-md --cpu-prof-dir=${dir}`
|
|
83
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
3
|
+
* THE WORLD CONTRACT — atrium.world/0 2026-10-09
|
|
4
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
5
|
+
*
|
|
6
|
+
* How whoever runs a world — axond's lab, a test, a person at a terminal —
|
|
7
|
+
* runs it: puts bodies in it, takes them out, sets how its time passes,
|
|
8
|
+
* steps it, keeps its state and returns to it. Exported from @arcforge/types
|
|
9
|
+
* as the `world` namespace (`world.Request`).
|
|
10
|
+
*
|
|
11
|
+
* The body contract (`body`) is the mind's side of a world: one body, worn.
|
|
12
|
+
* This is the other side: the world itself, whole. A mind never speaks it.
|
|
13
|
+
*
|
|
14
|
+
* THE SHAPE
|
|
15
|
+
*
|
|
16
|
+
* runner ── spawns ──► world process (one process, one world)
|
|
17
|
+
* stdin ── Request ──► one JSON object a line, each with an `id`
|
|
18
|
+
* stdout ◄── Said ─── `ready` first; a `reply` or `failed` per request; events between
|
|
19
|
+
*
|
|
20
|
+
* A body placed answers where a mind wears it (`BodyState.bridge`): the
|
|
21
|
+
* body contract, over a WebSocket, one mind a body.
|
|
22
|
+
*
|
|
23
|
+
* WHY IT IS SHAPED THIS WAY
|
|
24
|
+
*
|
|
25
|
+
* 1. One process a world, run over its own pipes. Booting one is cheap —
|
|
26
|
+
* a baked world loads in a fraction of a second — so worlds are made
|
|
27
|
+
* and thrown away rather than pooled; a world that diverges takes down
|
|
28
|
+
* only itself; and when the runner goes its stdin closes and the world
|
|
29
|
+
* ends with it. Nothing outlives what started it.
|
|
30
|
+
*
|
|
31
|
+
* 2. The world is loaded as the process starts and never swapped: another
|
|
32
|
+
* world is another process. So there is no `load`.
|
|
33
|
+
*
|
|
34
|
+
* 3. Time is the runner's to set. `real` keeps to the wall, `scaled` to a
|
|
35
|
+
* factor of it, and `stepped` moves only when stepped — by the runner
|
|
36
|
+
* (`step`), or by a mind through its body (the body contract's `Step`).
|
|
37
|
+
* A stepped world waits for its mind: however slowly a mind thinks, it
|
|
38
|
+
* lives in a world that never outruns it.
|
|
39
|
+
*
|
|
40
|
+
* 4. State is kept whole and returned to exactly (`snapshot`, `restore`):
|
|
41
|
+
* the same state stepped the same way gives the same world. A snapshot
|
|
42
|
+
* fits the world only while the same bodies are placed; placing or
|
|
43
|
+
* removing one forgets every snapshot.
|
|
44
|
+
*
|
|
45
|
+
* 5. Everything refused is refused by code (`Code`), never ignored: a
|
|
46
|
+
* request that is not of the contract, a body the library has not, a
|
|
47
|
+
* step while running in real time.
|
|
48
|
+
*
|
|
49
|
+
* SPOKEN BY
|
|
50
|
+
*
|
|
51
|
+
* Atrium (`apps/atrium`), Axon's own lab: MuJoCo physics, bodies and
|
|
52
|
+
* worlds imported from MJCF, URDF, USD, glTF and OBJ. The Rust side of these
|
|
53
|
+
* types is `apps/atrium/src/world/wire.rs`; they are the source of truth.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
import type { Pace } from "../body/body"
|
|
57
|
+
|
|
58
|
+
export const CONTRACT = "atrium.world/0"
|
|
59
|
+
|
|
60
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
61
|
+
// 1. REQUESTS — what the runner asks
|
|
62
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
63
|
+
|
|
64
|
+
export type Request = Place | Remove | SetPace | Step | Reset | Snapshot | Restore | State | Close
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A body from the world's library, placed as `name`: its base `at` (m, the
|
|
68
|
+
* world's axes, z up) — or, without `at`, stood on whatever is below the
|
|
69
|
+
* world's spawn, beside the bodies already there — turned `yaw` (rad) about
|
|
70
|
+
* up. Its joints stand at rest. With a `token`, only a mind presenting it
|
|
71
|
+
* (`?token=` on the bridge) may wear it: a lease's.
|
|
72
|
+
*/
|
|
73
|
+
export type Place = { type: "place"; id: number; body: string; name: string; at?: [number, number, number]; yaw?: number; token?: string }
|
|
74
|
+
|
|
75
|
+
/** The body placed as `name` taken out; its mind, if it has one, told why and let go. */
|
|
76
|
+
export type Remove = { type: "remove"; id: number; name: string }
|
|
77
|
+
|
|
78
|
+
export type SetPace = { type: "pace"; id: number; pace: Pace }
|
|
79
|
+
|
|
80
|
+
/** `steps` physics steps (the body contract's clock `step` each), at a stepped pace only. Answered once taken. */
|
|
81
|
+
export type Step = { type: "step"; id: number; steps: number }
|
|
82
|
+
|
|
83
|
+
/** Back to the world as loaded: every body at its placement, its joints at rest. */
|
|
84
|
+
export type Reset = { type: "reset"; id: number }
|
|
85
|
+
|
|
86
|
+
/** The world's whole physical state kept; answered with its id. */
|
|
87
|
+
export type Snapshot = { type: "snapshot"; id: number }
|
|
88
|
+
|
|
89
|
+
export type Restore = { type: "restore"; id: number; snapshot: number }
|
|
90
|
+
|
|
91
|
+
/** What the world is now. */
|
|
92
|
+
export type State = { type: "state"; id: number }
|
|
93
|
+
|
|
94
|
+
/** The world ends: every mind told, then the process exits. */
|
|
95
|
+
export type Close = { type: "close"; id: number }
|
|
96
|
+
|
|
97
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
98
|
+
// 2. WHAT THE WORLD SAYS
|
|
99
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
100
|
+
|
|
101
|
+
export type Said = Ready | Reply | Failed | Event | Ticked
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The first line: the world is loaded and listening. `bridge` is where minds
|
|
105
|
+
* connect — a body at `<bridge>/<name>` — and `view` where a viewer watches
|
|
106
|
+
* the whole world (`View`, below).
|
|
107
|
+
*/
|
|
108
|
+
export type Ready = {
|
|
109
|
+
type: "ready"
|
|
110
|
+
contract: typeof CONTRACT
|
|
111
|
+
/** The world process's own version. */
|
|
112
|
+
version: string
|
|
113
|
+
/** The physics engine's. */
|
|
114
|
+
mujoco: string
|
|
115
|
+
world: string
|
|
116
|
+
bridge: string
|
|
117
|
+
view: string
|
|
118
|
+
/** One physics step, s. */
|
|
119
|
+
timestep: number
|
|
120
|
+
pace: Pace
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** A request done. What `result` holds is each request's own (below). */
|
|
124
|
+
export type Reply = { type: "reply"; id: number; result: unknown }
|
|
125
|
+
|
|
126
|
+
/** A request refused — or, with no `id`, a line that was no request at all. */
|
|
127
|
+
export type Failed = { type: "failed"; id: number | null; code: Code; message: string }
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Something the runner should know, unasked:
|
|
131
|
+
*
|
|
132
|
+
* unsound the physics went wrong — a NaN, a huge velocity — and the
|
|
133
|
+
* world was put back at rest
|
|
134
|
+
* behind the world fell behind the wall and let the time go: it is
|
|
135
|
+
* heavier than real time on this machine
|
|
136
|
+
* refused a mind broke the body contract, and was let go
|
|
137
|
+
*/
|
|
138
|
+
export type Event = { type: "event"; kind: "unsound" | "behind" | "refused"; detail: string; time: number }
|
|
139
|
+
|
|
140
|
+
/** Once a second: the world's time, and how many of its seconds pass in a wall second. */
|
|
141
|
+
export type Ticked = { type: "ticked"; time: number; factor: number }
|
|
142
|
+
|
|
143
|
+
export type Code =
|
|
144
|
+
| "BODY_NOT_FOUND"
|
|
145
|
+
| "WORLD_NOT_FOUND"
|
|
146
|
+
| "IMPORT_UNSUPPORTED"
|
|
147
|
+
| "IMPORT_FAILED"
|
|
148
|
+
| "CONTRACT_UNSAID"
|
|
149
|
+
| "PHYSICS"
|
|
150
|
+
| "REFUSED"
|
|
151
|
+
| "WIRE"
|
|
152
|
+
| "IO"
|
|
153
|
+
|
|
154
|
+
// ── results ───────────────────────────────────────────────────────────────
|
|
155
|
+
|
|
156
|
+
/** `place`'s result, and each body `state` lists. */
|
|
157
|
+
export type BodyState = {
|
|
158
|
+
name: string
|
|
159
|
+
/** Which body of the library it is. */
|
|
160
|
+
body: string
|
|
161
|
+
/** Where a mind wears it: the body contract, over a WebSocket. */
|
|
162
|
+
bridge: string
|
|
163
|
+
worn: boolean
|
|
164
|
+
/** How many joints it moves. */
|
|
165
|
+
joints: number
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export type StateResult = { world: string; time: number; pace: Pace; bodies: BodyState[] }
|
|
169
|
+
|
|
170
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
171
|
+
// 3. THE VIEW — the whole world, for whoever watches it
|
|
172
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
173
|
+
//
|
|
174
|
+
// On `Ready.view`, a WebSocket that only speaks:
|
|
175
|
+
//
|
|
176
|
+
// text a `ViewScene` — what is drawn — said again whenever a body is
|
|
177
|
+
// placed or taken out (geoms are numbered afresh)
|
|
178
|
+
// binary VIEW_MESHES: the scene's meshes, in its order — each one's
|
|
179
|
+
// vertices (f32 × 3), then its triangles (u32 × 3)
|
|
180
|
+
// binary VIEW_FRAME: [tag u32][count u32][time f64], then for each of
|
|
181
|
+
// the scene's `moving` geoms in order, and then each of its
|
|
182
|
+
// `eyes`, pos (f32 × 3) and its 3×3 turn row by row (f32 × 9).
|
|
183
|
+
// `count` is the geoms'. An eye looks down its own −z, its y up.
|
|
184
|
+
//
|
|
185
|
+
// Little-endian; every binary message begins with its tag.
|
|
186
|
+
|
|
187
|
+
export const VIEW_MESHES = 1
|
|
188
|
+
export const VIEW_FRAME = 2
|
|
189
|
+
|
|
190
|
+
/** One geom, as drawn. */
|
|
191
|
+
export type ViewGeom = {
|
|
192
|
+
id: number
|
|
193
|
+
/** The placed body it is part of, by its placement's name — null for scenery and props. */
|
|
194
|
+
placed: string | null
|
|
195
|
+
/** The part of that body (or the prop) it is on. */
|
|
196
|
+
part: string
|
|
197
|
+
shape: "plane" | "sphere" | "capsule" | "ellipsoid" | "cylinder" | "box" | "mesh"
|
|
198
|
+
/** MuJoCo's size parameters, as the shape reads them: a box's half-sizes; a sphere's radius; a capsule's or cylinder's radius and half-length; a plane's half-extents (0: endless). */
|
|
199
|
+
size: [number, number, number]
|
|
200
|
+
/** Which of the scene's meshes, for a mesh. */
|
|
201
|
+
mesh?: number
|
|
202
|
+
rgba: [number, number, number, number]
|
|
203
|
+
/** Where it is as the scene is said, and its 3×3 turn, row by row. */
|
|
204
|
+
pos: [number, number, number]
|
|
205
|
+
mat: [number, number, number, number, number, number, number, number, number]
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export type ViewScene = {
|
|
209
|
+
type: "scene"
|
|
210
|
+
world: string
|
|
211
|
+
time: number
|
|
212
|
+
geoms: ViewGeom[]
|
|
213
|
+
/** Each mesh's vertex and triangle counts, in the order VIEW_MESHES holds them. */
|
|
214
|
+
meshes: Array<[number, number]>
|
|
215
|
+
/** The ids of the geoms a frame moves, in its order. */
|
|
216
|
+
moving: number[]
|
|
217
|
+
/** Every placed body's eyes — the cameras it sees through — in the order a frame places them after the geoms. */
|
|
218
|
+
eyes: ViewEye[]
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** A body's eye: where a viewer looks from to see as the body sees. */
|
|
222
|
+
export type ViewEye = { placed: string; name: string; fovy: number }
|
|
223
|
+
export type SnapshotResult = { snapshot: number; time: number }
|
|
224
|
+
export type TimeResult = { time: number }
|