@arcforge/platform 2.0.170 → 2.0.172

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcforge/platform",
3
- "version": "2.0.170",
3
+ "version": "2.0.172",
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.170",
48
- "@arcforge/engines": "2.0.170",
49
- "@arcforge/err": "2.0.170",
50
- "@arcforge/types": "2.0.170",
51
- "@arcforge/cloud": "2.0.170",
52
- "@arcforge/capsule": "2.0.170",
53
- "@arcforge/core": "2.0.170",
54
- "@arcforge/vstr": "2.0.170",
47
+ "@arcforge/session": "2.0.172",
48
+ "@arcforge/engines": "2.0.172",
49
+ "@arcforge/err": "2.0.172",
50
+ "@arcforge/types": "2.0.172",
51
+ "@arcforge/cloud": "2.0.172",
52
+ "@arcforge/capsule": "2.0.172",
53
+ "@arcforge/core": "2.0.172",
54
+ "@arcforge/vstr": "2.0.172",
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.170"
60
+ "@arcforge/link": "2.0.172"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@arcforge/air": "2.0.167",
@@ -112,15 +112,24 @@ export function Blueprint(opts: BlueprintOpts) {
112
112
  // Authored truth — a broken config is no agent. Throws.
113
113
  const config = await Config(root)
114
114
 
115
- // `engine:` is deprecated and READ BY NOTHING. Warn rather than
116
- // throw for the window: an agent carrying it already boots on the
117
- // profile pool, so failing now would break working agents to tell
118
- // them about a field that was being ignored anyway. The warning is
119
- // the only signal an author gets that their declared model is not
120
- // the one running.
115
+ // `engine:` is READ BY NOTHING, and now REFUSED.
116
+ //
117
+ // It warned for a deprecation window on the reasoning that an
118
+ // agent carrying it already booted on the profile pool, so
119
+ // failing would break working agents over a field that was being
120
+ // ignored anyway. That reasoning had the cost backwards. An agent
121
+ // whose config names a mock engine and silently resolves against
122
+ // the profile pool does not degrade — it runs on a DIFFERENT,
123
+ // billed provider while claiming otherwise, and a warning nobody
124
+ // reads is not a signal. Nine test fixtures declared `engine:
125
+ // Mock()` and spent real credits on every run for exactly as long
126
+ // as this was a warning.
127
+ //
128
+ // Fatal is the honest severity: the config asks for inference
129
+ // this runtime will not provide, and refusing at load is the only
130
+ // point where the author still knows why.
121
131
  if ("engine" in config.value && config.value.engine !== undefined) {
122
- const cause = err("CONFIG_ENGINE_DEPRECATED", { context: { root } })
123
- warnings.push({ domain: "config", error: cause.message, cause })
132
+ throw err("CONFIG_ENGINE_DEPRECATED", { context: { root } })
124
133
  }
125
134
 
126
135
  // Before the scan, never after: Cognet.read() below reads exactly
@@ -3,17 +3,13 @@ import type { AxonRequestInput, AxonResult } from "@arcforge/types"
3
3
  import type { InstancesT } from "./instances"
4
4
 
5
5
  /**
6
- * The envelope on agent-initiated spawning.
6
+ * The in-process door for agent-initiated spawning.
7
7
  *
8
- * A user may run as many agents side by side as they like — ten ambient agents
9
- * is a normal fleet, and nothing here constrains that. These bound the one path
10
- * that can run away without anyone asking: an agent whose own code spawns
11
- * another agent, which spawns another. Depth caps recursion, children caps one
12
- * agent's fan-out, descendants caps the whole tree beneath one root.
8
+ * The LIMITS on it (depth, fan-out, descendants) are enforced by the daemon —
9
+ * see its `checkSubagentLimits`. They lived here while this was the only route
10
+ * an agent could spawn through; it no longer is, and a rule implemented per
11
+ * route is a rule that eventually differs by route.
13
12
  */
14
- const MAX_DEPTH = 4
15
- const MAX_LIVE_CHILDREN = 4
16
- const MAX_LIVE_DESCENDANTS = 12
17
13
 
18
14
  type RequestsOpts = {
19
15
  instances: InstancesT
@@ -51,29 +47,23 @@ export function Requests(opts: RequestsOpts) {
51
47
  return { prompt: prompt }
52
48
  }
53
49
 
54
- /** Refuse before booting anything — a limit checked after the spawn has already cost the spawn. */
50
+ /**
51
+ * Resolve the parent. The LIMITS are the daemon's.
52
+ *
53
+ * Depth, fan-out and descendant caps used to be enforced here, and this
54
+ * was described as "the ONLY caller-initiated spawn path with limits
55
+ * attached". That stopped being true: an agent shelling out to
56
+ * `axon <ref> --parent <id>` spawns through the daemon and never touches
57
+ * this function, so the limits guarded one of two routes.
58
+ *
59
+ * They live in the daemon now — the one place every spawn passes through,
60
+ * and the only one that sees the whole ownership graph. Two
61
+ * implementations of one rule is how they come to disagree about what a
62
+ * limit means, which is worse than either answer.
63
+ */
55
64
  function checkLimits(parentSessionId: string) {
56
65
  const parent = instances.get(parentSessionId)
57
66
  if (!parent) throw err("PARENT_INSTANCE_NOT_RUNNING", { context: { sessionId: parentSessionId } })
58
-
59
- if (parent.depth >= MAX_DEPTH) {
60
- throw err("SUBAGENT_DEPTH_EXCEEDED", {
61
- detail: `maximum depth is ${MAX_DEPTH}`,
62
- context: { sessionId: parent.sessionId, depth: parent.depth, limit: MAX_DEPTH },
63
- })
64
- }
65
- if (instances.children(parent.sessionId).length >= MAX_LIVE_CHILDREN) {
66
- throw err("SUBAGENT_CHILD_LIMIT_EXCEEDED", {
67
- detail: `maximum live children is ${MAX_LIVE_CHILDREN}`,
68
- context: { sessionId: parent.sessionId, limit: MAX_LIVE_CHILDREN },
69
- })
70
- }
71
- if (instances.descendants(parent.rootSessionId).length >= MAX_LIVE_DESCENDANTS) {
72
- throw err("SUBAGENT_DESCENDANT_LIMIT_EXCEEDED", {
73
- detail: `maximum live descendants is ${MAX_LIVE_DESCENDANTS}`,
74
- context: { rootSessionId: parent.rootSessionId, limit: MAX_LIVE_DESCENDANTS },
75
- })
76
- }
77
67
  return parent
78
68
  }
79
69
 
package/src/index.ts CHANGED
@@ -6,6 +6,11 @@ export type { FileEntry, FilesT } from "./services/files"
6
6
  // The process tree every surface renders — folded from the session log, so a
7
7
  // local runtime and an attached deployment read identically.
8
8
  export { procTree, appendOutput, type ProcNode } from "./procs"
9
+ // The live instance forest — agents, their subagents, and each one's procs as
10
+ // one tree. The TUI's `/` palette and the Fleet extension's Instances view
11
+ // both render it; the ordering rules are subtle enough that a second
12
+ // implementation would drift rather than differ.
13
+ export { forest, childrenOf, flatten, type ForestAgent, type ForestNode, type Indented } from "./procs"
9
14
  // The supervisor ↔ agent transport. Moves bytes; the verbs it carries are
10
15
  // SupervisorToAgent / AgentToSupervisor in @arcforge/types.
11
16
  export { serve, connect, Channel, type LinkChannels, type SocketPaths, type ChannelT } from "./link"
@@ -24,7 +24,7 @@ import { err } from "@arcforge/err"
24
24
  import { readFileSync } from "node:fs"
25
25
  import { Axon, AxonBus } from "@arcforge/core"
26
26
  import { Routes, Middleware, Plugins } from "../build/blueprint"
27
- import type { AxonMiddleware, AxonPartialBlueprint, AxonPlugin, AxonRoute } from "@arcforge/types"
27
+ import type { AxonCommitContext, AxonMiddleware, AxonPartialBlueprint, AxonPlugin, AxonRoute } from "@arcforge/types"
28
28
  import {
29
29
  AGENT_BLUEPRINT_ENV,
30
30
  AgentRuntime,
@@ -170,8 +170,8 @@ export async function main(): Promise<void> {
170
170
  * which is why the TUI's header came up blank: the facts it renders had
171
171
  * already gone past.
172
172
  */
173
- const pending: Array<{ type: string; data: unknown }> = []
174
- let forward = (type: string, data: unknown) => { pending.push({ type, data }) }
173
+ const pending: Array<{ type: string; data: unknown; ctx?: AxonCommitContext }> = []
174
+ let forward = (type: string, data: unknown, ctx?: AxonCommitContext) => { pending.push({ type, data, ctx }) }
175
175
 
176
176
  /**
177
177
  * The bus, built HERE and handed to Axon() — so this can subscribe
@@ -240,6 +240,24 @@ export async function main(): Promise<void> {
240
240
  * shape is known: the supervisor receives (type, data) and cannot tell an
241
241
  * envelope from a payload that happens to have a `data` field of its own.
242
242
  */
243
+ /**
244
+ * The correlation half of an envelope's context, for the wire.
245
+ *
246
+ * `agentId` and `sessionId` are the SUPERVISOR's to stamp — it owns the
247
+ * session and knows both — so sending them back would be the child
248
+ * asserting its own identity to the thing that assigned it. Only the ids
249
+ * the child actually mints travel: runId and spanId.
250
+ *
251
+ * Returns undefined when neither is present, so an event with no
252
+ * correlation commits with no context rather than an empty object.
253
+ */
254
+ function contextOf(context: AxonCommitContext | undefined): AxonCommitContext | undefined {
255
+ if (!context) return undefined
256
+ const { runId, spanId } = context
257
+ if (!runId && !spanId) return undefined
258
+ return { ...(runId ? { runId } : {}), ...(spanId ? { spanId } : {}) }
259
+ }
260
+
243
261
  function announce(type: string, payload: unknown): void {
244
262
  /**
245
263
  * Two shapes travel this bus, and the difference is not cosmetic.
@@ -261,9 +279,21 @@ export async function main(): Promise<void> {
261
279
  * payload with its own `data` field is a shape nobody should have to
262
280
  * reason about at this seam.
263
281
  */
264
- const carrier = payload as { time?: unknown; data?: unknown; type?: unknown } | undefined
282
+ const carrier = payload as {
283
+ time?: unknown
284
+ data?: unknown
285
+ type?: unknown
286
+ context?: AxonCommitContext
287
+ } | undefined
265
288
  if (carrier && typeof carrier === "object" && "time" in carrier) {
266
- forward(type, carrier.data)
289
+ // The context travels WITH the payload, as its own argument.
290
+ // Unwrapping the envelope and dropping `context` is what silently
291
+ // un-correlated every span once agents moved into subprocesses:
292
+ // the kernel mints one spanId per engine call, start/input/
293
+ // complete share it, and nothing else joins them. The supervisor
294
+ // re-envelopes on the far side, so this is the only place the ids
295
+ // can be handed over.
296
+ forward(type, carrier.data, contextOf(carrier.context))
267
297
  return
268
298
  }
269
299
  // A raw event: strip the name it already travels under, keep the rest.
@@ -276,8 +306,8 @@ export async function main(): Promise<void> {
276
306
  }
277
307
 
278
308
  // Live from here — and everything boot produced goes first, in order.
279
- forward = (type, data) => { supervisor.commit(type as never, data as never) }
280
- for (const event of pending.splice(0)) forward(event.type, event.data)
309
+ forward = (type, data, ctx) => { supervisor.commit(type as never, data as never, ctx) }
310
+ for (const event of pending.splice(0)) forward(event.type, event.data, event.ctx)
281
311
 
282
312
  /**
283
313
  * The agent's last words.
@@ -0,0 +1,187 @@
1
+ import type { ProcNode } from "./tree"
2
+
3
+ /**
4
+ * The live process forest — agents, the subagents they spawned, and the
5
+ * processes each of those is running, as one tree.
6
+ *
7
+ * ── Why this is shared ──────────────────────────────────────────────────────
8
+ *
9
+ * A subagent is spawned by shelling out to `axon run --parent <sessionId>`, so
10
+ * one spawn produces two rows at two layers: a proc on the parent's log (the
11
+ * `axon` command itself) and an independent agent instance carrying
12
+ * `parentSessionId`. Joining those two structures back into one tree is the
13
+ * same problem for every surface that draws it — the TUI's `/` palette and the
14
+ * Fleet extension's Instances view — and the ordering rules below are subtle
15
+ * enough that a second implementation would drift rather than merely differ.
16
+ *
17
+ * ── Why it is generic ───────────────────────────────────────────────────────
18
+ *
19
+ * Surfaces disagree about what an agent IS. The TUI's InstanceView carries
20
+ * focus and tombstones; the extension's AxonInstance carries a pid and a
21
+ * project root. Neither is wrong, and widening one to cover both would put
22
+ * `focused` on a record that cannot be focused. The forest needs exactly three
23
+ * facts from an agent — its id, its parent, and its procs — so it asks for
24
+ * those and stays ignorant of the rest.
25
+ *
26
+ * ── Why the forest, not the flattened list ──────────────────────────────────
27
+ *
28
+ * A terminal draws an indented list; VS Code's TreeDataProvider asks for one
29
+ * node's children at a time and owns expansion itself. Sharing the flattened
30
+ * list would force the extension to flatten and then re-derive parentage from
31
+ * indent, which is the same information twice with a chance to disagree.
32
+ * `forest()` returns the structure; `flatten()` is for surfaces that draw
33
+ * indentation themselves.
34
+ */
35
+
36
+ /** The three facts the forest needs from an agent. Anything else is the surface's business. */
37
+ export type ForestAgent = {
38
+ sessionId: string
39
+ /** Null or absent for a user-owned root; a spawning agent's id otherwise. */
40
+ parentSessionId?: string | null
41
+ /** What this agent has spawned, as `procTree()` folded it from its own log. */
42
+ processes?: readonly ProcNode[]
43
+ }
44
+
45
+ /**
46
+ * One agent and everything hanging under it.
47
+ *
48
+ * `subagents` and `procs` stay separate rather than being concatenated into
49
+ * one `children` array: they are different kinds of thing with different
50
+ * affordances (a conversation can be focused, a `sleep 3600` cannot), and a
51
+ * surface that had to re-split them would be discriminating on a union we
52
+ * already knew the answer to. Rendering order across the two is fixed —
53
+ * subagents first, see `childrenOf` — so the split costs nothing.
54
+ */
55
+ export type ForestNode<Agent extends ForestAgent> = {
56
+ agent: Agent
57
+ /** Instances this one spawned, each with its own subtree. */
58
+ subagents: ForestNode<Agent>[]
59
+ /** Processes this agent spawned directly, in spawn order. */
60
+ procs: readonly ProcNode[]
61
+ }
62
+
63
+ /**
64
+ * Build the forest from a flat list of live agents.
65
+ *
66
+ * Roots are returned in the order given, except as reordered by `pinned` —
67
+ * a list navigated with a cursor must not reorder under the hand mid-preview,
68
+ * so a surface that previews captures an order once and passes it here.
69
+ *
70
+ * Only ROOTS are pinned. A child always sits under its parent, so pinning a
71
+ * focused subagent to the top would have to tear it out of the tree it belongs
72
+ * to; its root rises instead, which brings it along and keeps the shape.
73
+ */
74
+ export function forest<Agent extends ForestAgent>(
75
+ agents: readonly Agent[],
76
+ opts?: {
77
+ /** Session ids in preferred root order. Ids not listed keep list order, after those that are. */
78
+ pinned?: readonly string[]
79
+ },
80
+ ): ForestNode<Agent>[] {
81
+ const byId = new Map(agents.map(agent => [agent.sessionId, agent]))
82
+
83
+ const childrenOf = new Map<string, Agent[]>()
84
+ const roots: Agent[] = []
85
+ for (const agent of agents) {
86
+ // A parent that is gone (exited and pruned) makes this a root: it has
87
+ // to render somewhere, and hanging it off a row that does not exist is
88
+ // the one option that cannot work.
89
+ const parentId = agent.parentSessionId
90
+ const parent = parentId ? byId.get(parentId) : undefined
91
+ if (!parent) {
92
+ roots.push(agent)
93
+ continue
94
+ }
95
+ const siblings = childrenOf.get(parent.sessionId)
96
+ if (siblings) siblings.push(agent)
97
+ else childrenOf.set(parent.sessionId, [agent])
98
+ }
99
+
100
+ const order = new Map((opts?.pinned ?? []).map((id, index) => [id, index]))
101
+ const rank = (agent: Agent): number => order.get(agent.sessionId) ?? Number.MAX_SAFE_INTEGER
102
+ roots.sort((left, right) => rank(left) - rank(right))
103
+
104
+ // Cycle guard. Parentage is stamped at spawn and never rewritten, so a
105
+ // cycle should be impossible — but if one existed, every agent in it would
106
+ // have a visible parent, none would become a root, and they would vanish
107
+ // from the view while still running. An unreachable running agent is
108
+ // strictly worse than an oddly-drawn one.
109
+ const seen = new Set<string>()
110
+ const build = (agent: Agent): ForestNode<Agent> | null => {
111
+ if (seen.has(agent.sessionId)) return null
112
+ seen.add(agent.sessionId)
113
+ return {
114
+ agent,
115
+ subagents: (childrenOf.get(agent.sessionId) ?? [])
116
+ .map(build)
117
+ .filter((node): node is ForestNode<Agent> => node !== null),
118
+ procs: agent.processes ?? [],
119
+ }
120
+ }
121
+
122
+ const built = roots.map(build).filter((node): node is ForestNode<Agent> => node !== null)
123
+
124
+ // Anything the walk never reached — only possible inside a cycle — renders
125
+ // flat at the root rather than not at all.
126
+ for (const agent of agents) {
127
+ if (seen.has(agent.sessionId)) continue
128
+ seen.add(agent.sessionId)
129
+ built.push({ agent, subagents: [], procs: agent.processes ?? [] })
130
+ }
131
+ return built
132
+ }
133
+
134
+ /**
135
+ * A node's children in render order: subagents, then its own processes.
136
+ *
137
+ * A conversation is a bigger thing than a shell command, and a burst of
138
+ * short-lived `run` rows must not push a subagent off the visible window.
139
+ *
140
+ * This is the one place the two child kinds are interleaved, so a surface that
141
+ * asks for children lazily (VS Code) and one that flattens (a terminal) cannot
142
+ * disagree about the order.
143
+ */
144
+ export function childrenOf<Agent extends ForestAgent>(
145
+ node: ForestNode<Agent>,
146
+ ): ({ kind: "agent"; node: ForestNode<Agent> } | { kind: "proc"; proc: ProcNode })[] {
147
+ return [
148
+ ...node.subagents.map(child => ({ kind: "agent" as const, node: child })),
149
+ ...node.procs.map(proc => ({ kind: "proc" as const, proc })),
150
+ ]
151
+ }
152
+
153
+ /** Where a row sits in the drawn tree — for surfaces that render indentation themselves. */
154
+ export type Indented = { indent: number; last: boolean }
155
+
156
+ /**
157
+ * Flatten the forest into display order, stamping indent and last-child.
158
+ *
159
+ * `indent` is computed HERE rather than read off the record. An agent's
160
+ * `depth` is its true depth in the runtime forest, which is not the same as
161
+ * its indent: a subagent whose parent has already exited and been pruned would
162
+ * render indented under nothing. Deriving it from the rendered ancestry keeps
163
+ * the drawing honest about what is actually on screen.
164
+ */
165
+ export function flatten<Agent extends ForestAgent>(
166
+ nodes: readonly ForestNode<Agent>[],
167
+ ): ({ kind: "agent"; agent: Agent } & Indented | { kind: "proc"; proc: ProcNode; ownerSessionId: string } & Indented)[] {
168
+ const rows: ReturnType<typeof flatten<Agent>> = []
169
+
170
+ const walk = (node: ForestNode<Agent>, indent: number, last: boolean): void => {
171
+ rows.push({ kind: "agent", agent: node.agent, indent, last })
172
+ const children = childrenOf(node)
173
+ children.forEach((child, index) => {
174
+ const isLast = index === children.length - 1
175
+ if (child.kind === "agent") walk(child.node, indent + 1, isLast)
176
+ else rows.push({
177
+ kind: "proc",
178
+ proc: child.proc,
179
+ ownerSessionId: node.agent.sessionId,
180
+ indent: indent + 1,
181
+ last: isLast,
182
+ })
183
+ })
184
+ }
185
+ nodes.forEach((node, index) => walk(node, 0, index === nodes.length - 1))
186
+ return rows
187
+ }
@@ -13,3 +13,8 @@
13
13
  * agent boundary moves out to the whole process.
14
14
  */
15
15
  export { procTree, appendOutput, type ProcNode, type ProcLogEvent } from "./tree"
16
+ // The forest those trees hang in: agents, their subagents, and each one's
17
+ // procs as a single structure. Shared because a subagent spawn produces a row
18
+ // on two layers at once (a proc on the parent's log, an instance on the
19
+ // daemon) and rejoining them is the same problem for every surface.
20
+ export { forest, childrenOf, flatten, type ForestAgent, type ForestNode, type Indented } from "./forest"