@arcforge/types 2.0.166 → 2.0.168

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/types",
3
- "version": "2.0.166",
3
+ "version": "2.0.168",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./src/index.ts",
package/src/handle.ts CHANGED
@@ -3,6 +3,7 @@ import type { AxonEntry, AxonKernelEvent, AxonSessionEvent, AxonStimulusEvent, A
3
3
  import type { AxonOutputEvent } from "./session/events/stdio/output"
4
4
  import type { AxonScript } from "./scripts"
5
5
  import type { AxonPrompt, AxonPromptName, AxonPromptProps } from "./prompts"
6
+ import type { AxonToolNamespaces } from "./tools"
6
7
  import type { AxonPartialBlueprint } from "./blueprint"
7
8
  import type { AxonHookName, AxonHooks, AxonModuleEvents } from "./hooks"
8
9
  import type { AxonAmbient } from "./session/events/activity"
@@ -206,6 +207,31 @@ export type AxonHandle = {
206
207
  */
207
208
  prompt<K extends AxonPromptName>(name: K, props?: AxonPromptProps<K>): Promise<string>
208
209
 
210
+ /**
211
+ * This agent's tools, addressed by namespace —
212
+ * `axon.tools.<namespace>.<fn>()`.
213
+ *
214
+ * An ESCAPE HATCH, not the primary path. A tool's exports are installed
215
+ * as flat globals (`add(1, 2)`), which is how the model's `<scope>` block
216
+ * and the generated `.agent/tool-globals.d.ts` describe them, and how
217
+ * agent-authored code normally calls them. Reach for this surface when a
218
+ * bare name cannot serve:
219
+ *
220
+ * - the name is already taken. A tool exporting `fetch` never replaces
221
+ * the host builtin, so this is the only way to call it.
222
+ * - the caller wants to name the tool it means rather than depend on
223
+ * the ambient scope — a route, a hook, a prompt's `<script setup>`.
224
+ *
225
+ * Live, not a snapshot: a hot reload replaces the loaded set and this
226
+ * reflects it. The functions are the SAME mediated ones the globals
227
+ * expose, so policy, tracing and escalation are identical on both paths.
228
+ *
229
+ * A namespace the blueprint declares but nothing could load is present
230
+ * here and REJECTS when called, naming itself — never absent (a property
231
+ * error pointing at the caller) and never a silent no-op.
232
+ */
233
+ readonly tools: AxonToolNamespaces
234
+
209
235
  /**
210
236
  * This agent's installed modules, as configured.
211
237
  *
package/src/kernel/abi.ts CHANGED
@@ -230,7 +230,23 @@ export type AxonRunResult = {
230
230
  * to distinguish "no scope" from "scope unavailable".
231
231
  */
232
232
  scope: CapsuleScope
233
- error?: { kind: "timeout" | "interrupt" | "exception"; message: string }
233
+ error?: { kind: "timeout" | "policy" | "interrupt" | "exception"; message: string }
234
+ /**
235
+ * Calls policy refused during this block. Empty for almost every run.
236
+ *
237
+ * A block with denials is NOT ok, even when its code ran to completion —
238
+ * which is the whole reason this is on the result rather than only on the
239
+ * bus. A refused `process.spawn()` returns a handle rather than throwing,
240
+ * so nothing propagated: the block finished, `ok` was true, and the record
241
+ * said a denied call had succeeded. Every surface reading that record
242
+ * agreed, so a user saw a normal tool call and no indication their policy
243
+ * had blocked anything.
244
+ *
245
+ * The block's `value` is KEPT alongside them. A script that made ten calls
246
+ * and had one refused still did nine real things, and discarding that
247
+ * output would trade one silent failure for another.
248
+ */
249
+ denials?: { fn: string; module: string; rule: string }[]
234
250
  }
235
251
 
236
252
  /**
package/src/scope.ts CHANGED
@@ -21,6 +21,26 @@ export type AxonScopeModule = {
21
21
  description?: string
22
22
  members: readonly AxonScopeMember[]
23
23
  ambientTypes?: readonly string[]
24
+ /**
25
+ * How these members are ADDRESSED — flat globals, or under `name`.
26
+ *
27
+ * Derived from the tool's origin at `toScopeModule()`: the agent's own
28
+ * src/tools and the shared workspace's are flat, a MODULE's live under the
29
+ * module's name, so an installed module cannot claim a bare name in the
30
+ * author's scope.
31
+ *
32
+ * Carried on the scope rather than re-derived by each renderer, because
33
+ * three surfaces spell this one decision — the model's `<scope>` block,
34
+ * the editor's `tool-globals.d.ts`, and the runtime's actual global
35
+ * installation — and they must not be able to disagree. They did: both
36
+ * renderers declared every tool flat while the runtime namespaced module
37
+ * ones, so the model was told `openPr()` for a function that only ever
38
+ * existed as `github.openPr()`.
39
+ *
40
+ * Optional, defaulting to flat where absent, so a hand-built scope in a
41
+ * test need not state it.
42
+ */
43
+ flat?: boolean
24
44
  }
25
45
 
26
46
  /** The complete TypeScript scope implemented by one live capsule. */
@@ -150,8 +150,15 @@ export type CapsuleEventMap =
150
150
  "process:proc:stdin:error": { procId: string; error: AxonErrorJSON }
151
151
 
152
152
  // ── Policy ───────────────────────────────────────────────────────────
153
- "process:policy:denied": { id: string; module: string; fn: string; args: unknown[]; rule: string }
154
- "process:policy:escalation": { id: string; module: string; fn: string; args: unknown[]; rule: string }
153
+ /**
154
+ * A call policy refused. DURABLE — a refusal is a fact about the run.
155
+ *
156
+ * `commandId` is the `cognet:action:typescript` block this belongs to,
157
+ * so a surface can hang the denial under the `Run(...)` that provoked
158
+ * it. Null for a host-initiated call, which belongs to no block.
159
+ */
160
+ "process:policy:denied": { id: string; commandId: string | null; module: string; fn: string; args: unknown[]; rule: string }
161
+ "process:policy:escalation": { id: string; commandId: string | null; module: string; fn: string; args: unknown[]; rule: string }
155
162
  /** Host-side: the escalate callback's verdict for a pending escalation. */
156
163
  "process:policy:decision": { id: string; allow: boolean; durationMs: number }
157
164
 
@@ -171,6 +171,62 @@ export type AxonRuntimeEvent =
171
171
  stepKind?: "instruct" | "input" | "work"
172
172
  }
173
173
  }
174
+ // ── Scripts (agent-authored orchestration, run as one job) ──────────────
175
+ /**
176
+ * One script invocation, start to finish.
177
+ *
178
+ * A script is a LAYER OVER the agent, not brain code and not body code:
179
+ * high-level orchestration the author wrote, driving the same runtime a
180
+ * user drives from the terminal. `axon` inside one is this runtime — it
181
+ * spawns nothing — so the wakes it triggers are ordinary turns in the same
182
+ * conversation.
183
+ *
184
+ * A SPAN, and that is what makes it legible in the flame graph. The
185
+ * bracket opens at depth 0 and everything the script causes — its wakes,
186
+ * their ticks, the capsule work inside them — nests by containment (see
187
+ * span.ts: nesting is bracket-matching in seq order, not parent pointers).
188
+ * Without it a script run is one long opaque bar; with it, it decomposes
189
+ * for free and Fleet needs no changes at all.
190
+ *
191
+ * CANCELLABLE, because Escape must be able to stop one. Interruption is a
192
+ * settled outcome rather than a failure — a script the user stopped did
193
+ * what it was told. Note the cancellation is COOPERATIVE: it aborts the
194
+ * script's pending `axon.request`, but a script inside a tight loop or a
195
+ * long shell call runs to its own end, the same limit the capsule has
196
+ * in-process. `durationMs` on every terminal state is what makes a
197
+ * runaway visible rather than mysterious.
198
+ */
199
+ & AxonCancellableSpan<
200
+ "axon:script",
201
+ { id: string; name: string; args: Record<string, unknown> },
202
+ { id: string },
203
+ { id: string; error: AxonError },
204
+ { id: string }
205
+ >
206
+ & {
207
+ /**
208
+ * A line the script itself printed.
209
+ *
210
+ * Scripts talk through `console.log` — that is their existing contract
211
+ * and every script in the registry is written to it. Committed as a
212
+ * durable event rather than left on stdout because the terminal that
213
+ * used to own stdout no longer does: the agent runs in its own
214
+ * process, and a surface reading a mirrored log must still see what
215
+ * the script said.
216
+ *
217
+ * DISTINCT from a tool's console output, which belongs to the tool
218
+ * call that produced it. These are the SCRIPT's own words, and the two
219
+ * have different authors — so a script calling a chatty tool produces
220
+ * both, correctly.
221
+ */
222
+ "axon:script:log": {
223
+ /** The run this line belongs to — pairs with the enclosing span. */
224
+ id: string
225
+ level: "log" | "error"
226
+ content: string
227
+ }
228
+ }
229
+
174
230
  // ── Module install/uninstall (registry op, then a reload rides the same
175
231
  // hot-swap path above) ─────────────────────────────────────────────
176
232
  & AxonSpan<
@@ -66,8 +66,19 @@ export type AxonSpanName = {
66
66
  /** One line in the session's kernel log — internal telemetry, never rendered to the user. */
67
67
  export type AxonKernelEvent = AxonEventUnion<AxonKernelEventMap>
68
68
 
69
- /** One line in the session's own log — runtime/continuity facts. */
70
- export type AxonSessionEvent = AxonEventUnion<AxonRuntimeEvent>
69
+ /**
70
+ * One line in the session's own log — runtime/continuity facts, and the build
71
+ * events that precede them.
72
+ *
73
+ * BuildEventMap is included because those events genuinely LAND HERE: the
74
+ * session is opened before the build so a failed one leaves a readable record
75
+ * (see AxonEventMap above, which says exactly that). Typing this as runtime
76
+ * events alone made the log's type narrower than the log, so a consumer
77
+ * filtering for `build:warning` — the durable record of what a scan found —
78
+ * got "this comparison has no overlap" for a string the log demonstrably
79
+ * contains.
80
+ */
81
+ export type AxonSessionEvent = AxonEventUnion<AxonRuntimeEvent & BuildEventMap>
71
82
 
72
83
  /** One line in the session's entry log. */
73
84
  export type AxonEntry = AxonEventUnion<AxonEntryEvent>
package/src/tools.ts CHANGED
@@ -46,3 +46,33 @@ export type AxonTool = {
46
46
  */
47
47
  ambientTypes?: string[]
48
48
  }
49
+
50
+ /**
51
+ * Every tool namespace this agent declares, as namespace → its functions.
52
+ *
53
+ * EMPTY HERE ON PURPOSE, and augmented by generated declarations exactly as
54
+ * `AxonPromptMap` is — the interface has to be declared here for a
55
+ * `declare module` block to attach to anything.
56
+ *
57
+ * An agent with no generated frame falls back to a permissive shape (see
58
+ * `AxonToolNamespaces`), so hand-written and pre-prepare code still compiles.
59
+ */
60
+ export interface AxonToolMap {}
61
+
62
+ /**
63
+ * The shape of `axon.tools`: the generated map when there is one, and an
64
+ * open record of callables when there is not.
65
+ *
66
+ * The fallback matters more here than for prompts, because this surface is
67
+ * reached from `<script setup>` and host code written against no particular
68
+ * agent. Narrowing to `never` would make every such call an error for the
69
+ * wrong reason.
70
+ */
71
+ export type AxonToolNamespaces = keyof AxonToolMap extends never
72
+ // `unknown[]`, not `never[]`: a parameter typed `never` accepts NO
73
+ // argument, so `axon.tools.greeter.greet("world")` was an error under the
74
+ // fallback — the shape meant for agents with no generated frame made every
75
+ // real call fail to typecheck. The fallback exists to permit calls it
76
+ // cannot know the signature of; `never[]` forbade all of them.
77
+ ? Record<string, Record<string, (...args: unknown[]) => Promise<unknown>>>
78
+ : AxonToolMap