@arcforge/types 2.0.59
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 +29 -0
- package/src/bench/aggregate.ts +67 -0
- package/src/bench/artifact.ts +39 -0
- package/src/bench/bench.ts +62 -0
- package/src/bench/contribution.ts +40 -0
- package/src/bench/dimension.ts +15 -0
- package/src/bench/execution.ts +76 -0
- package/src/bench/factor.ts +69 -0
- package/src/bench/index.ts +108 -0
- package/src/bench/manifest.ts +49 -0
- package/src/bench/measurement.ts +41 -0
- package/src/bench/observation.ts +42 -0
- package/src/bench/protocol.ts +21 -0
- package/src/bench/result.ts +32 -0
- package/src/bench/value.ts +7 -0
- package/src/bench/workspace.ts +76 -0
- package/src/blueprint.ts +125 -0
- package/src/capsule-config.ts +111 -0
- package/src/cognet/blueprint.ts +38 -0
- package/src/cognet/cognet.ts +69 -0
- package/src/cognet/hooks.ts +43 -0
- package/src/cognet/index.ts +3 -0
- package/src/config.ts +72 -0
- package/src/define.ts +184 -0
- package/src/deploy.ts +54 -0
- package/src/engine.ts +254 -0
- package/src/error.ts +88 -0
- package/src/handle.ts +137 -0
- package/src/hooks.ts +31 -0
- package/src/http.ts +49 -0
- package/src/index.ts +23 -0
- package/src/kernel/abi.ts +244 -0
- package/src/kernel/index.ts +2 -0
- package/src/middleware.ts +7 -0
- package/src/module.ts +193 -0
- package/src/plugin.ts +9 -0
- package/src/policy.ts +89 -0
- package/src/prompts.ts +25 -0
- package/src/route.ts +15 -0
- package/src/scope.ts +29 -0
- package/src/scripts.ts +21 -0
- package/src/session/envelope.ts +61 -0
- package/src/session/events/activity.ts +77 -0
- package/src/session/events/bench.ts +49 -0
- package/src/session/events/capsule.ts +114 -0
- package/src/session/events/cognet.ts +51 -0
- package/src/session/events/engine.ts +46 -0
- package/src/session/events/entries.ts +66 -0
- package/src/session/events/kernel.ts +44 -0
- package/src/session/events/log.ts +27 -0
- package/src/session/events/runtime.ts +76 -0
- package/src/session/events/stdio/output.ts +94 -0
- package/src/session/events/stdio/shared.ts +50 -0
- package/src/session/events/stdio/stimuli.ts +110 -0
- package/src/session/events/test.ts +52 -0
- package/src/session/index.ts +40 -0
- package/src/session/session.ts +107 -0
- package/src/tools.ts +54 -0
- package/tsconfig.base.json +14 -0
package/src/module.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { AxonPrompt } from "./prompts"
|
|
2
|
+
import type { AxonScript } from "./scripts"
|
|
3
|
+
import type { AxonTool } from "./tools"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A resolved, installed module as it appears in the blueprint — surfaces
|
|
7
|
+
* plus the overlay metadata the runtime needs (roots for capsule loading,
|
|
8
|
+
* validated options, declared env requirements).
|
|
9
|
+
*/
|
|
10
|
+
export type AxonModule = {
|
|
11
|
+
/** Module name (short form, e.g. "telegram") — how tools and options key off it. */
|
|
12
|
+
name: string
|
|
13
|
+
/**
|
|
14
|
+
* Full package name, e.g. "@axon/telegram" — the module's registry
|
|
15
|
+
* identity, present whenever it ships a package.json. This is what
|
|
16
|
+
* install/uninstall address it by; `name` is the short form used for
|
|
17
|
+
* namespacing and cannot round-trip to the registry.
|
|
18
|
+
*/
|
|
19
|
+
packageName?: string
|
|
20
|
+
/** Package version, when the module ships a package.json. */
|
|
21
|
+
version?: string
|
|
22
|
+
/** Absolute path to the module root. */
|
|
23
|
+
root: string
|
|
24
|
+
/** Whether module files are auto-discovered and merged. Default true. */
|
|
25
|
+
automerge: boolean
|
|
26
|
+
/** Declared env variables and their requirements. */
|
|
27
|
+
env: Record<string, { required: boolean; description?: string }>
|
|
28
|
+
/** Declared options schema, keyed by option name. */
|
|
29
|
+
optionsSchema: Record<string, ModuleOptionSchema>
|
|
30
|
+
/** Resolved options from axon.config.ts, validated against optionsSchema. */
|
|
31
|
+
options?: Record<string, unknown>
|
|
32
|
+
/** Absolute path to modules/<name>/server/, when present. */
|
|
33
|
+
serverPath?: string
|
|
34
|
+
/** Absolute path to modules/<name>/server/api/, when present. */
|
|
35
|
+
apiPath?: string
|
|
36
|
+
/** Absolute path to modules/<name>/data/knowledge/, when present. */
|
|
37
|
+
knowledgePath?: string
|
|
38
|
+
prompts: AxonPrompt[]
|
|
39
|
+
scripts: AxonScript[]
|
|
40
|
+
tools: AxonTool[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Maps a ModuleOptionSchema `type` string to its runtime value type. */
|
|
44
|
+
export type OptionTypeMap = {
|
|
45
|
+
string: string
|
|
46
|
+
number: number
|
|
47
|
+
boolean: boolean
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Module authoring configuration — the object passed to `defineModule()`
|
|
52
|
+
* in `module.config.ts`.
|
|
53
|
+
*/
|
|
54
|
+
export type ModuleConfig<O extends Record<string, ModuleOptionSchema> = Record<string, ModuleOptionSchema>> = {
|
|
55
|
+
/**
|
|
56
|
+
* Identity — name, version, description — lives in package.json, not
|
|
57
|
+
* here. It is what the registry publishes, what `bun install` resolves,
|
|
58
|
+
* and what the module list renders; a second copy in this file could
|
|
59
|
+
* only ever disagree with it. Both fields were declared here and read
|
|
60
|
+
* by nothing, so a module that set them looked configured and wasn't.
|
|
61
|
+
*
|
|
62
|
+
* This config is for BEHAVIOUR: env, policy, options, hooks, setup.
|
|
63
|
+
*/
|
|
64
|
+
/** Environment variables this module expects the host agent to provide. */
|
|
65
|
+
env?: Record<string, { required: boolean; description?: string }>
|
|
66
|
+
/** Event payloads this module may emit. */
|
|
67
|
+
emits?: ModuleEmitMap
|
|
68
|
+
/** Advisory sandbox permissions this module needs. */
|
|
69
|
+
policy?: ModulePolicyNeeds
|
|
70
|
+
/** User-configurable options accepted under `modules.<name>` in `axon.config.ts`. */
|
|
71
|
+
options?: O
|
|
72
|
+
/** Lifecycle or custom hook handlers registered when the module loads. */
|
|
73
|
+
hooks?: Record<string, (...args: any[]) => void | Promise<void>>
|
|
74
|
+
/** Boot-time setup callback for dynamic registration. */
|
|
75
|
+
setup?: (ctx: ModuleSetupCtx<InferOptions<O>>) => void | Promise<void>
|
|
76
|
+
/**
|
|
77
|
+
* Sub-modules this module depends on. Flattened and prepended before the agent's
|
|
78
|
+
* own module list at manifest generation time. First declaration wins on collision.
|
|
79
|
+
*/
|
|
80
|
+
modules?: ModuleEntry[]
|
|
81
|
+
/**
|
|
82
|
+
* Injected by `defineModule()` at call time — absolute path of the
|
|
83
|
+
* module.config.ts file. Never set manually.
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
_sourcePath?: string
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Event payloads a module may emit. */
|
|
90
|
+
export type ModuleEmitMap = Record<string, unknown>
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
/** Context object passed to a module's `setup()` function. */
|
|
94
|
+
export type ModuleSetupCtx<O extends Record<string, unknown> = Record<string, unknown>> = {
|
|
95
|
+
/** Boot-time module setup handle. */
|
|
96
|
+
axon: ModuleSetupAxon
|
|
97
|
+
/** Validated module options resolved from the agent config. */
|
|
98
|
+
options: O
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Return shape produced by `defineModule()`. */
|
|
102
|
+
export type ModuleDefinition = {
|
|
103
|
+
_kind: "module"
|
|
104
|
+
config: ModuleConfig
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Derives a typed options object from a Record<string, ModuleOptionSchema>.
|
|
109
|
+
* Required options are non-optional. Everything else is optional.
|
|
110
|
+
*/
|
|
111
|
+
export type InferOptions<O extends Record<string, ModuleOptionSchema>> =
|
|
112
|
+
{ [K in keyof O as O[K]["required"] extends true ? K : never]: OptionTypeMap[O[K]["type"]] } &
|
|
113
|
+
{ [K in keyof O as O[K]["required"] extends true ? never : K]?: OptionTypeMap[O[K]["type"]] }
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Schema entry for a module option.
|
|
117
|
+
*
|
|
118
|
+
* Module options are declared by `defineModule()` and configured by agents under
|
|
119
|
+
* `modules.<moduleName>`. The schema is intentionally small so the CLI can validate
|
|
120
|
+
* options and generate simple forms.
|
|
121
|
+
*
|
|
122
|
+
* ```ts
|
|
123
|
+
* options: {
|
|
124
|
+
* owner: { type: "string", required: true },
|
|
125
|
+
* retries: { type: "number", default: 3 },
|
|
126
|
+
* dryRun: { type: "boolean", default: false },
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export type ModuleOptionSchema = {
|
|
131
|
+
/** Primitive option type accepted by the generated config validator. */
|
|
132
|
+
type: "string" | "number" | "boolean"
|
|
133
|
+
/** Default value used when the agent does not configure this option. */
|
|
134
|
+
default?: unknown
|
|
135
|
+
/** Optional set of accepted values. */
|
|
136
|
+
enum?: unknown[]
|
|
137
|
+
/** Whether the agent must provide this option. */
|
|
138
|
+
required?: boolean
|
|
139
|
+
/** Human-readable help text shown by config and install tooling. */
|
|
140
|
+
description?: string
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A module entry in `defineAgent({ modules })` or `defineModule({ modules })`.
|
|
144
|
+
*
|
|
145
|
+
* Three forms are accepted:
|
|
146
|
+
* - `"@axon/telegram"` — registry module, auto-installed at prepare time
|
|
147
|
+
* - `TelegramModule` — source import, used directly (no install step)
|
|
148
|
+
* - `[TelegramModule, { mentionOnly: true }]` — either form with options
|
|
149
|
+
*/
|
|
150
|
+
export type ModuleEntry<O extends Record<string, ModuleOptionSchema> = Record<string, ModuleOptionSchema>> =
|
|
151
|
+
| string
|
|
152
|
+
| ModuleConfig<O>
|
|
153
|
+
| [string, Record<string, unknown>]
|
|
154
|
+
| [ModuleConfig<O>, Record<string, unknown>]
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Narrow runtime handle available inside `ModuleConfig.setup()`.
|
|
158
|
+
*
|
|
159
|
+
* This boot-time handle lets modules register hooks, update policy, add server
|
|
160
|
+
* routes, and inspect module tools without exposing the full agent conversation API.
|
|
161
|
+
*/
|
|
162
|
+
export type ModuleSetupAxon = {
|
|
163
|
+
/** Register a lifecycle or custom hook handler. */
|
|
164
|
+
hook(name: string, handler: (...args: any[]) => void | Promise<void>): void
|
|
165
|
+
/** Emit a hook — fires all registered handlers for this name. */
|
|
166
|
+
callHook(name: string, ...args: any[]): Promise<void>
|
|
167
|
+
env: {
|
|
168
|
+
get(key: string): string | undefined
|
|
169
|
+
require(key: string): string
|
|
170
|
+
}
|
|
171
|
+
policy: {
|
|
172
|
+
update(patch: Record<string, unknown>): void
|
|
173
|
+
}
|
|
174
|
+
server: {
|
|
175
|
+
addRoute(method: string, path: string, handler: (...args: any[]) => any): void
|
|
176
|
+
addMiddleware(handler: (...args: any[]) => any): void
|
|
177
|
+
}
|
|
178
|
+
tools: {
|
|
179
|
+
get(name: string): unknown
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Advisory policy requirements declared by a module.
|
|
185
|
+
*
|
|
186
|
+
* The CLI uses these during install to patch or suggest entries in the agent's
|
|
187
|
+
* `policy`. Runtime enforcement still comes from the final agent policy.
|
|
188
|
+
*/
|
|
189
|
+
export type ModulePolicyNeeds = {
|
|
190
|
+
network?: { needs: string[] }
|
|
191
|
+
fs?: { read?: string[]; write?: string[] }
|
|
192
|
+
}
|
|
193
|
+
|
package/src/plugin.ts
ADDED
package/src/policy.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// ─── Policy Rule ──────────────────────────────────────────────────────────────
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Low-level capsule rule for a single capability.
|
|
5
|
+
*
|
|
6
|
+
* - `true` always allows the operation.
|
|
7
|
+
* - `false` always denies the operation.
|
|
8
|
+
* - `"escalate"` pauses and asks the outer system for approval.
|
|
9
|
+
* - An object applies glob-based `allow`, `deny`, and `escalate` matching to the
|
|
10
|
+
* first string argument, such as a path, host, or command.
|
|
11
|
+
*
|
|
12
|
+
* @see https://axon.arclabs.it/docs/v2/api/config/policy
|
|
13
|
+
*/
|
|
14
|
+
export type PolicyRule =
|
|
15
|
+
| boolean
|
|
16
|
+
| "escalate"
|
|
17
|
+
| {
|
|
18
|
+
allow?: string[]
|
|
19
|
+
deny?: string[]
|
|
20
|
+
escalate?: string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Capsule-level wire type. Describes what the sandbox subprocess is allowed to
|
|
26
|
+
* do. Passed directly to the capsule on boot or via `capsule.update()`.
|
|
27
|
+
*
|
|
28
|
+
* Deliberately minimal: two real primitives (process.run/process.spawn),
|
|
29
|
+
* a generic per-namespace tools bucket, and generic network destinations.
|
|
30
|
+
* Filesystem access has no built-in mediation — it is only ever reachable
|
|
31
|
+
* through a tools: entry, so it is gated the same way any other tool is.
|
|
32
|
+
*/
|
|
33
|
+
export type CapsulePolicy = {
|
|
34
|
+
/**
|
|
35
|
+
* OS user to run the capsule subprocess as. Linux only.
|
|
36
|
+
*
|
|
37
|
+
* - `"inherit"` (default) — runs as the invoking user, no OS enforcement.
|
|
38
|
+
* - `"axon-agent"` or any username — subprocess and all its children run as
|
|
39
|
+
* that user. Filesystem ACLs derived from `fs` policy are applied at boot.
|
|
40
|
+
* Requires `axon install` to have been run on the host.
|
|
41
|
+
* - `"root"` — valid explicit opt-in; ACLs are skipped (root bypasses them),
|
|
42
|
+
* mediator gates and env stripping still apply.
|
|
43
|
+
*
|
|
44
|
+
* Hard error at boot if the requested user does not exist on the system.
|
|
45
|
+
*/
|
|
46
|
+
user?: "inherit" | "root" | (string & {})
|
|
47
|
+
|
|
48
|
+
// glob pattern key
|
|
49
|
+
network?: Record<string, PolicyRule>
|
|
50
|
+
|
|
51
|
+
process: {
|
|
52
|
+
spawn: PolicyRule
|
|
53
|
+
run: PolicyRule
|
|
54
|
+
|
|
55
|
+
/** Max heap, in MB. Default 5000. */
|
|
56
|
+
memory: number
|
|
57
|
+
|
|
58
|
+
/** Max CPU, as a percent of one core. Default 100. */
|
|
59
|
+
cpu: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
tools?: Record<string, PolicyRule>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/** Command sent back to the capsule to allow or deny a pending escalation. */
|
|
67
|
+
export type PolicyResponseCommand = {
|
|
68
|
+
id: string
|
|
69
|
+
type: "policy:response"
|
|
70
|
+
allow: boolean
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type PolicyCall = {
|
|
74
|
+
/** Fully qualified function being evaluated, for example `"fs.write"` or `"proc.spawn"`. */
|
|
75
|
+
fn: string
|
|
76
|
+
/** Original arguments passed to the operation. */
|
|
77
|
+
args: unknown[]
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A pending escalation surfaced to the host's escalate callback. */
|
|
81
|
+
export type EscalationCall = {
|
|
82
|
+
/** Escalation id — the policy:response answering this must echo it. */
|
|
83
|
+
id: string
|
|
84
|
+
/** Fully qualified function, e.g. "fs.write". */
|
|
85
|
+
fn: string
|
|
86
|
+
args: unknown[]
|
|
87
|
+
/** The policy rule that triggered escalation. */
|
|
88
|
+
rule: string
|
|
89
|
+
}
|
package/src/prompts.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
/** Prompt template discovered from an agent or module. */
|
|
3
|
+
export type AxonPrompt = {
|
|
4
|
+
/** Prompt name used with `axon.prompt(name)`. */
|
|
5
|
+
name: string
|
|
6
|
+
/** Static markdown prompt or dynamic Vuedown prompt. */
|
|
7
|
+
kind: "static" | "dynamic"
|
|
8
|
+
/** Human-readable prompt summary. */
|
|
9
|
+
description?: string
|
|
10
|
+
/**
|
|
11
|
+
* Absolute path to the prompt file. Set during discovery so the runtime
|
|
12
|
+
* can load the file without re-deriving the path from the name convention.
|
|
13
|
+
* Present for agent-owned and module prompts; absent for inline prompts.
|
|
14
|
+
*/
|
|
15
|
+
filePath?: string
|
|
16
|
+
/** Props required by a dynamic prompt. Present only for dynamic prompts. */
|
|
17
|
+
props?: Array<{
|
|
18
|
+
/** Prop name. */
|
|
19
|
+
name: string
|
|
20
|
+
/** TypeScript type string as written in `defineProps`. */
|
|
21
|
+
type: string
|
|
22
|
+
/** Whether the prop is required. */
|
|
23
|
+
required?: boolean
|
|
24
|
+
}>
|
|
25
|
+
}
|
package/src/route.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EventHandler } from "h3"
|
|
2
|
+
|
|
3
|
+
/** HTTP or WebSocket route discovered from `server/api/`. */
|
|
4
|
+
export type AxonRoute = {
|
|
5
|
+
/** HTTP method or WebSocket marker. */
|
|
6
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "ANY" | "WS"
|
|
7
|
+
/** Route path, for example `/api/users` or `/api/users/[id]`. */
|
|
8
|
+
path: string
|
|
9
|
+
/** Resolved h3 handler — loaded by the CLI, mounted as-is by the runtime. */
|
|
10
|
+
handler: EventHandler
|
|
11
|
+
/** Source file that produced this route. */
|
|
12
|
+
file?: string
|
|
13
|
+
/** Whether the route requires server auth. */
|
|
14
|
+
auth?: boolean
|
|
15
|
+
}
|
package/src/scope.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** One callable or value declaration installed in an execution scope. */
|
|
2
|
+
export type AxonScopeMember = {
|
|
3
|
+
/** Stable member name, used for collision checks and diagnostics. */
|
|
4
|
+
name: string
|
|
5
|
+
/** Standalone TypeScript declaration (`function x(...)`, `const x: ...`). */
|
|
6
|
+
declaration: string
|
|
7
|
+
/** Model-facing documentation carried with the declaration. */
|
|
8
|
+
jsdoc?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A related group of globals in the capsule's executable TypeScript scope.
|
|
13
|
+
*
|
|
14
|
+
* Namespaced modules render as `declare namespace <name> { ... }`. Flat
|
|
15
|
+
* modules install each member directly on globalThis. `ambientTypes` are
|
|
16
|
+
* emitted before members so every referenced type is resolvable.
|
|
17
|
+
*/
|
|
18
|
+
export type AxonScopeModule = {
|
|
19
|
+
name: string
|
|
20
|
+
description?: string
|
|
21
|
+
members: readonly AxonScopeMember[]
|
|
22
|
+
flat?: boolean
|
|
23
|
+
ambientTypes?: readonly string[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The complete TypeScript scope implemented by one live capsule. */
|
|
27
|
+
export type AxonScope = {
|
|
28
|
+
modules: readonly AxonScopeModule[]
|
|
29
|
+
}
|
package/src/scripts.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
/** Script discovered from `src/scripts/` or an installed module. */
|
|
3
|
+
export type AxonScript = {
|
|
4
|
+
/** Script name used with `axon.scripts.request(name)`. */
|
|
5
|
+
name: string
|
|
6
|
+
/** Human-readable script summary. */
|
|
7
|
+
description?: string
|
|
8
|
+
/**
|
|
9
|
+
* Absolute path to the script file. Set during discovery so the runtime
|
|
10
|
+
* can load the file without re-deriving the path from the name convention.
|
|
11
|
+
*/
|
|
12
|
+
filePath?: string
|
|
13
|
+
args?: Array<{
|
|
14
|
+
/** Argument name. */
|
|
15
|
+
name: string
|
|
16
|
+
/** TypeScript type string as written in `defineArgs`. */
|
|
17
|
+
type: string
|
|
18
|
+
/** Whether the argument is required. */
|
|
19
|
+
required?: boolean
|
|
20
|
+
}>
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Axon event envelope — one shape for every event in the system.
|
|
3
|
+
*
|
|
4
|
+
* Design rules (hold these or the event system rots):
|
|
5
|
+
* 1. Call sites emit (type, data) only. id, time, and context are stamped
|
|
6
|
+
* by the emitter (session/run), in exactly one place.
|
|
7
|
+
* 2. Correlation lives in context, never in data. If a field says WHERE the
|
|
8
|
+
* event belongs (run, span) it is context; if it says WHAT
|
|
9
|
+
* happened (code, tokens, duration) it is data.
|
|
10
|
+
* 3. Classification comes from the type namespace and from which log the
|
|
11
|
+
* event lives in. No source/layer/audience fields.
|
|
12
|
+
* 4. Failure payloads carry the full AxonError (@axon/err) in data,
|
|
13
|
+
* verbatim — no compact/wire projection. This is a debugging log, not a
|
|
14
|
+
* bandwidth-constrained wire protocol: anything tailing the session
|
|
15
|
+
* JSONL (a debugger, a session viewer) sees one recognizable shape
|
|
16
|
+
* (isAxonError: true) and can render the complete report — code, title,
|
|
17
|
+
* description, context, captured stack frames with source snippets,
|
|
18
|
+
* cause chain — directly off disk, with nothing lost between the
|
|
19
|
+
* moment of failure and whoever reads the log later.
|
|
20
|
+
* 5. Ingest-time fields (receivedAt, userId) are a backend wrapper — they
|
|
21
|
+
* do not exist on the wire type.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export type AxonEventContext = {
|
|
25
|
+
agentId: string
|
|
26
|
+
sessionId: string
|
|
27
|
+
/** One kernel request = one runId. The unit of "what the user asked for". */
|
|
28
|
+
runId?: string
|
|
29
|
+
/** Tracing tree — minted per run, parented per phase/system. */
|
|
30
|
+
traceId?: string
|
|
31
|
+
spanId?: string
|
|
32
|
+
parentSpanId?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The envelope. `M` is a registry map (event name → payload shape);
|
|
37
|
+
* `K` narrows to one event type.
|
|
38
|
+
*/
|
|
39
|
+
export type AxonEvent<M, K extends keyof M = keyof M, C extends object = AxonEventContext> = {
|
|
40
|
+
/** UUIDv7 — globally unique and time-sortable. Idempotent ingest. */
|
|
41
|
+
id: string
|
|
42
|
+
type: K
|
|
43
|
+
time: {
|
|
44
|
+
/** Wall clock ms since epoch. */
|
|
45
|
+
ms: number
|
|
46
|
+
/** Monotonic per-session counter — authoritative ordering, immune to clock skew. */
|
|
47
|
+
seq: number
|
|
48
|
+
}
|
|
49
|
+
context: C
|
|
50
|
+
/** Typed payload — the registry map is the single source of payload truth. */
|
|
51
|
+
data: M[K]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Discriminated union of enveloped events for a registry map. */
|
|
55
|
+
export type AxonEventUnion<M, C extends object = AxonEventContext> = { [K in keyof M]: AxonEvent<M, K, C> }[keyof M]
|
|
56
|
+
|
|
57
|
+
/** Backend-side wrapper — stamped at ingest, never constructed by the runtime. */
|
|
58
|
+
export type AxonIngestedEvent<M> = AxonEventUnion<M> & {
|
|
59
|
+
receivedAt: number
|
|
60
|
+
userId: string
|
|
61
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Activity — the closed vocabulary of renderable agent activities.
|
|
3
|
+
*
|
|
4
|
+
* An activity is a human-meaningful action a tool performed ("patched a
|
|
5
|
+
* file", "ran a process"), emitted from INSIDE the tool body via the
|
|
6
|
+
* capsule's ambient `axon.activity()` — implementation-independent: the
|
|
7
|
+
* payload is the RENDER contract, never a tool's args or return type, so
|
|
8
|
+
* any tool that patches a file emits the same `file:patch` regardless of
|
|
9
|
+
* how it did it.
|
|
10
|
+
*
|
|
11
|
+
* Stability contract (tool authors depend on this from userland code):
|
|
12
|
+
* the vocabulary is additive-only — new types may be added, existing
|
|
13
|
+
* payload fields never change meaning. A renderer meeting an unknown
|
|
14
|
+
* type falls back to a generic key-value row, it never errors.
|
|
15
|
+
*
|
|
16
|
+
* Lifecycle: two phases on the wire. "declared" opens the row (in-flight),
|
|
17
|
+
* "done"/"failed" settles it. Declare may carry a partial payload (path
|
|
18
|
+
* only); settle merges the rest (the diff). The capsule auto-settles
|
|
19
|
+
* anything still open when its command ends — failed if the command
|
|
20
|
+
* threw — so the error path costs tool authors nothing.
|
|
21
|
+
*/
|
|
22
|
+
export type ActivityPayloads = {
|
|
23
|
+
"file:read": { path: string; range?: [from: number, to: number] }
|
|
24
|
+
"file:write": { path: string; bytes?: number }
|
|
25
|
+
/**
|
|
26
|
+
* `before`/`after` are HUNK-SCOPED excerpts (the changed region plus a
|
|
27
|
+
* few context lines), never the whole file — payloads stay bounded.
|
|
28
|
+
* The renderer diffs and presents them (TUI: the native diff element);
|
|
29
|
+
* tool authors ship facts, not formatting.
|
|
30
|
+
*/
|
|
31
|
+
"file:patch": { path: string; before?: string; after?: string }
|
|
32
|
+
"file:delete": { path: string }
|
|
33
|
+
"file:move": { from: string; to: string }
|
|
34
|
+
"file:search": { query: string; scope?: string; matches?: number }
|
|
35
|
+
"proc:exec": { command: string; cwd?: string; exitCode?: number }
|
|
36
|
+
"http": { method: string; url: string; status?: number }
|
|
37
|
+
"speech": { text: string }
|
|
38
|
+
/** Escape hatch — a plain sentence for anything outside the vocabulary. */
|
|
39
|
+
"note": { text: string }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type ActivityType = keyof ActivityPayloads
|
|
43
|
+
|
|
44
|
+
export type ActivityPhase = "declared" | "done" | "failed"
|
|
45
|
+
|
|
46
|
+
/** One activity emission as recorded on the wire and in the session log. */
|
|
47
|
+
export type Activity<T extends ActivityType = ActivityType> = T extends ActivityType
|
|
48
|
+
? {
|
|
49
|
+
/** Unique per emission — pairs the declare with its settle. */
|
|
50
|
+
id: string
|
|
51
|
+
/** The vocabulary type. `activity`, not `type` — events own `type`. */
|
|
52
|
+
activity: T
|
|
53
|
+
phase: ActivityPhase
|
|
54
|
+
/** Declared may be partial; the settle carries the remainder. */
|
|
55
|
+
data: Partial<ActivityPayloads[T]>
|
|
56
|
+
/** Present when phase is "failed". */
|
|
57
|
+
error?: string
|
|
58
|
+
}
|
|
59
|
+
: never
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The ambient the capsule installs as `globalThis.axon` for tool code.
|
|
63
|
+
* Write-only, fire-and-forget telemetry — returns nothing but the settle
|
|
64
|
+
* handle, grants nothing. Absent outside the capsule; tools guard with
|
|
65
|
+
* `globalThis.axon?.` and stay unit-testable as plain modules.
|
|
66
|
+
*/
|
|
67
|
+
export type AxonAmbient = {
|
|
68
|
+
activity<T extends ActivityType>(
|
|
69
|
+
type: T,
|
|
70
|
+
data?: Partial<ActivityPayloads[T]>,
|
|
71
|
+
): ActivityHandle<T>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type ActivityHandle<T extends ActivityType = ActivityType> = {
|
|
75
|
+
/** Settle the activity with the rest of its payload. Idempotent. */
|
|
76
|
+
done(data?: Partial<ActivityPayloads[T]>): void
|
|
77
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { BenchArtifactRef } from "../../bench/artifact"
|
|
2
|
+
import type { BenchFault, BenchPhysics, BenchResourceUsage, BenchSessionRef, BenchTestRef, BenchTestStatus } from "../../bench/execution"
|
|
3
|
+
import type { BenchCell } from "../../bench/factor"
|
|
4
|
+
import type { BenchRunManifest } from "../../bench/manifest"
|
|
5
|
+
import type { BenchObservationPayload } from "../../bench/observation"
|
|
6
|
+
import type { BenchCoverage } from "../../bench/result"
|
|
7
|
+
import type { BenchWorkspaceResult, BenchWorkspaceTemplate } from "../../bench/workspace"
|
|
8
|
+
import type { BenchHash } from "../../bench/value"
|
|
9
|
+
import type { AxonError } from "../../error"
|
|
10
|
+
import type { AxonEventUnion } from "../envelope"
|
|
11
|
+
|
|
12
|
+
/** Correlation for the bench-run log. It never pretends to be an agent session. */
|
|
13
|
+
export type BenchEventContext = {
|
|
14
|
+
benchRunId: string
|
|
15
|
+
cellId?: string
|
|
16
|
+
trial?: number
|
|
17
|
+
testId?: string
|
|
18
|
+
caseId?: string
|
|
19
|
+
attempt?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type BenchEventMap = {
|
|
23
|
+
"bench:run:start": { manifest: BenchRunManifest }
|
|
24
|
+
"bench:run:complete": { durationMs: number; coverage: BenchCoverage }
|
|
25
|
+
"bench:run:failed": { error: AxonError }
|
|
26
|
+
|
|
27
|
+
"bench:cell:start": { cell: BenchCell }
|
|
28
|
+
"bench:cell:complete": { durationMs: number }
|
|
29
|
+
|
|
30
|
+
"bench:trial:start": Record<string, never>
|
|
31
|
+
"bench:trial:complete": { durationMs: number; physics: BenchPhysics }
|
|
32
|
+
|
|
33
|
+
"bench:case:declare": { test: BenchTestRef }
|
|
34
|
+
"bench:case:complete": { status: BenchTestStatus; durationMs: number; error?: AxonError }
|
|
35
|
+
|
|
36
|
+
"bench:session:attach": { session: BenchSessionRef }
|
|
37
|
+
"bench:session:detach": { session: BenchSessionRef }
|
|
38
|
+
"bench:session:usage": { session: BenchSessionRef; usage: BenchResourceUsage }
|
|
39
|
+
"bench:observation": BenchObservationPayload
|
|
40
|
+
"bench:artifact": { artifact: BenchArtifactRef }
|
|
41
|
+
"bench:workspace:prepared": { template: BenchWorkspaceTemplate }
|
|
42
|
+
"bench:workspace:materialized": { workspaceId: string; templateHash: BenchHash }
|
|
43
|
+
"bench:workspace:captured": { result: BenchWorkspaceResult }
|
|
44
|
+
"bench:workspace:retained": { workspaceId: string; reason: "failed" | "always" }
|
|
45
|
+
"bench:workspace:cleaned": { workspaceId: string }
|
|
46
|
+
"bench:process:fault": { fault: BenchFault }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type BenchEvent = AxonEventUnion<BenchEventMap, BenchEventContext>
|