@arcforge/types 2.0.143 → 2.0.145
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 +1 -1
- package/src/blueprint.ts +23 -0
- package/src/cognet/cognet.ts +14 -1
- package/src/define.ts +9 -3
- package/src/engine.ts +31 -5
- package/src/handle.ts +26 -0
- package/src/index.ts +1 -0
- package/src/module.ts +25 -0
- package/src/policy-resolve.ts +159 -0
- package/src/policy.ts +37 -0
- package/src/session/events/entries.ts +43 -2
- package/src/session/events/kernel.ts +22 -0
- package/src/session/events/runtime.ts +23 -1
- package/src/session/events/stdio/shared.ts +24 -0
- package/src/tui-contract.ts +1 -1
- package/src/tui.ts +120 -21
package/package.json
CHANGED
package/src/blueprint.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AxonConfig } from "./config"
|
|
2
|
+
import type { CapsulePartialConfig } from "./capsule-config"
|
|
2
3
|
import { CognetBlueprint } from "./cognet/blueprint"
|
|
3
4
|
import { AxonPlugin } from "./plugin"
|
|
4
5
|
import { AxonRoute } from "./route"
|
|
@@ -53,6 +54,27 @@ export type AxonBlueprint = {
|
|
|
53
54
|
/** resolved axon.config.ts — engine, policy, environment. no raw process.env reads at runtime. */
|
|
54
55
|
config: AxonConfig
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The machine-wide policy CEILING, from the profile that owns this agent.
|
|
59
|
+
*
|
|
60
|
+
* Kept beside `config.policy` rather than merged into it, deliberately.
|
|
61
|
+
* The two layers stay distinct all the way to enforcement so a denial can
|
|
62
|
+
* name which one produced it — merged, a user reading "denied" would have
|
|
63
|
+
* no way to tell whether to edit their agent or their profile, and
|
|
64
|
+
* removing the agent rule would silently change nothing.
|
|
65
|
+
*
|
|
66
|
+
* Resolved at LOAD, never baked in at prepare: a blueprint travels (it is
|
|
67
|
+
* what `axon deploy` ships), and a deployed agent runs on a machine with
|
|
68
|
+
* no profile. Baking the ceiling in would carry one machine's rules to
|
|
69
|
+
* another, where they describe a filesystem and a threat model that do not
|
|
70
|
+
* exist there.
|
|
71
|
+
*
|
|
72
|
+
* Absent means no ceiling — every capability falls through to the agent's
|
|
73
|
+
* own policy. That is the case for a deployment, for `axon run` outside a
|
|
74
|
+
* profile, and for a profile that simply declares none.
|
|
75
|
+
*/
|
|
76
|
+
profilePolicy?: CapsulePartialConfig["policy"]
|
|
77
|
+
|
|
56
78
|
/**
|
|
57
79
|
* The brain. REQUIRED and never defaulted: an agent without a brain is
|
|
58
80
|
* not an agent — normalization fails loudly when it's missing. The CLI
|
|
@@ -110,6 +132,7 @@ export type AxonPartialBlueprint = {
|
|
|
110
132
|
boot?: string
|
|
111
133
|
bootFilePath?: string
|
|
112
134
|
config?: AxonBlueprint["config"]
|
|
135
|
+
profilePolicy?: AxonBlueprint["profilePolicy"]
|
|
113
136
|
cognet?: CognetBlueprint
|
|
114
137
|
env?: AxonBlueprint["env"]
|
|
115
138
|
tools?: AxonBlueprint["tools"]
|
package/src/cognet/cognet.ts
CHANGED
|
@@ -57,7 +57,20 @@ export type CognetConfig = {
|
|
|
57
57
|
/** Default wake mask — overridable by the blueprint's wakeOn. Absent = wake on everything. */
|
|
58
58
|
wakeOn?: Array<keyof AxonEntryEvent>
|
|
59
59
|
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Hard safety bound for one wake. Omitted means UNBOUNDED, which is the
|
|
62
|
+
* default and the right one for most cognets.
|
|
63
|
+
*
|
|
64
|
+
* A ceiling cannot distinguish a runaway loop from a long job — the only
|
|
65
|
+
* difference is whether the ticks accomplish anything, which a count
|
|
66
|
+
* cannot see. Zero capped this at 32 and killed a run mid-verification
|
|
67
|
+
* after forty clean turns of real work.
|
|
68
|
+
*
|
|
69
|
+
* Set it only where a wake is genuinely expected to converge in a known
|
|
70
|
+
* number of steps (a classifier, a fixed pipeline), so exceeding it really
|
|
71
|
+
* is a bug. For open-ended work, what bounds a wake is `<done/>`, the
|
|
72
|
+
* user's interrupt, and the engine failing loudly.
|
|
73
|
+
*/
|
|
61
74
|
maxTicksPerWake?: number
|
|
62
75
|
|
|
63
76
|
/**
|
package/src/define.ts
CHANGED
|
@@ -212,13 +212,19 @@ export function defineProps<T extends Record<string, unknown>>(): T {
|
|
|
212
212
|
*
|
|
213
213
|
* ```ts
|
|
214
214
|
* export default defineAxonPlugin(async (axon) => {
|
|
215
|
-
* axon.hooks.hook("
|
|
216
|
-
*
|
|
217
|
-
* await reply(result.text)
|
|
215
|
+
* axon.hooks.hook("axon:agent:ready", async () => {
|
|
216
|
+
* console.log("agent ready")
|
|
218
217
|
* })
|
|
219
218
|
* })
|
|
220
219
|
* ```
|
|
221
220
|
*
|
|
221
|
+
* Note what this is NOT for: answering an inbound message by calling
|
|
222
|
+
* `axon.request()` per event. That spawns an isolated wake outside the
|
|
223
|
+
* scheduler, so the agent has no continuity across its own conversation.
|
|
224
|
+
* A channel (Telegram, Discord) is a sense organ — it delivers
|
|
225
|
+
* `cognet:stimulus:text` through the module's `axon.stim`, and the mind
|
|
226
|
+
* replies with the channel's send tool.
|
|
227
|
+
*
|
|
222
228
|
* The `axon` handle is passed in by the runtime that boots the plugin — never
|
|
223
229
|
* read from a global — so a plugin is always bound to its own Axon() instance
|
|
224
230
|
* even when a host runs several at once.
|
package/src/engine.ts
CHANGED
|
@@ -24,12 +24,15 @@ export type EngineConfig = AxonEngineDef | EngineRef
|
|
|
24
24
|
* workspace writes, what a model pick in the TUI serializes, and the form
|
|
25
25
|
* the product contract promises: swap the reference, zero code changes.
|
|
26
26
|
*/
|
|
27
|
+
/** Requested reasoning effort. Unsupported engines accept and ignore it. */
|
|
28
|
+
export type EngineEffort = "low" | "medium" | "high" | "xhigh"
|
|
29
|
+
|
|
27
30
|
export type EngineRef =
|
|
28
|
-
| { provider: "axon"; model?: string; optimize?: EngineAutoWeights; limit?: EngineAutoLimits }
|
|
29
|
-
| { provider: "openrouter"; model: string }
|
|
30
|
-
| { provider: "codex"; model?: string }
|
|
31
|
-
| { provider: "ollama"; model: string }
|
|
32
|
-
| { provider: "mock" }
|
|
31
|
+
| { provider: "axon"; model?: string; effort?: EngineEffort; optimize?: EngineAutoWeights; limit?: EngineAutoLimits }
|
|
32
|
+
| { provider: "openrouter"; model: string; effort?: EngineEffort }
|
|
33
|
+
| { provider: "codex"; model?: string; effort?: EngineEffort }
|
|
34
|
+
| { provider: "ollama"; model: string; effort?: EngineEffort }
|
|
35
|
+
| { provider: "mock"; effort?: EngineEffort }
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
38
|
* Axon({ model: "auto" }) weighting — resolved server-side against a
|
|
@@ -57,6 +60,8 @@ export type AxonEngineDef = {
|
|
|
57
60
|
* resolves server-side, per call; a client showing it should say so.
|
|
58
61
|
*/
|
|
59
62
|
model?: string
|
|
63
|
+
/** Requested reasoning effort, if configured. Unsupported providers ignore it. */
|
|
64
|
+
effort?: EngineEffort
|
|
60
65
|
/**
|
|
61
66
|
* Auto-selection weighting, when the constructor was given it. Only
|
|
62
67
|
* meaningful alongside model: "auto".
|
|
@@ -219,6 +224,27 @@ export type AxonEngineCall = AxonEngineRequest & {
|
|
|
219
224
|
}
|
|
220
225
|
/** Attempts after a response fails `output`. Ignored without one. Default 2. */
|
|
221
226
|
retries?: number
|
|
227
|
+
/**
|
|
228
|
+
* Re-render the request from the session, for a retry.
|
|
229
|
+
*
|
|
230
|
+
* A retry has to show the model its own rejected reply and the correction
|
|
231
|
+
* it earned, and those are session ENTRIES — so the only honest way to put
|
|
232
|
+
* them in front of the model is to render the document again now that they
|
|
233
|
+
* exist. Appending the correction to the finished messages instead put a
|
|
234
|
+
* `<system>` block AFTER `</timeline>`, outside every structure the
|
|
235
|
+
* context had just taught, in the highest-attention position on the wire.
|
|
236
|
+
* A model shown a floating block immediately before being told not to emit
|
|
237
|
+
* floating blocks does the obvious thing.
|
|
238
|
+
*
|
|
239
|
+
* Supplied by the caller because rendering belongs to cognition: the
|
|
240
|
+
* engine owns the retry budget and knows a reply failed, but has no view
|
|
241
|
+
* of a timeline and must not grow one.
|
|
242
|
+
*
|
|
243
|
+
* Optional — a caller that renders nothing (an internal one-shot) has no
|
|
244
|
+
* document to re-render, and the engine falls back to reusing the
|
|
245
|
+
* messages it was given.
|
|
246
|
+
*/
|
|
247
|
+
rerender?(): Promise<AxonEngineMessage[]>
|
|
222
248
|
}
|
|
223
249
|
|
|
224
250
|
/**
|
package/src/handle.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EscalationCall } from "./policy"
|
|
1
2
|
import type { AxonEntry, AxonKernelEvent, AxonSessionEvent, AxonStimulusEvent, AxonStimulusType } from "./session"
|
|
2
3
|
import type { AxonOutputEvent } from "./session/events/stdio/output"
|
|
3
4
|
import type { AxonScript } from "./scripts"
|
|
@@ -23,6 +24,16 @@ import type { AxonAmbient } from "./session/events/activity"
|
|
|
23
24
|
export type AxonRequestInput = {
|
|
24
25
|
/** One stimulus, or an ordered batch committed before a single wake. */
|
|
25
26
|
prompt: string | string[]
|
|
27
|
+
/**
|
|
28
|
+
* The surface this message arrived on — and the address a reply goes back
|
|
29
|
+
* to. `terminal`, `axon-cli`, `telegram:8199237521`.
|
|
30
|
+
*
|
|
31
|
+
* Supplied by the host, because the runtime cannot know which surface it
|
|
32
|
+
* is embedded in. A channel module reaching the agent names its own line
|
|
33
|
+
* the same way, which is what lets the agent answer on the line it was
|
|
34
|
+
* asked. Defaults to `terminal`.
|
|
35
|
+
*/
|
|
36
|
+
channel?: string
|
|
26
37
|
/**
|
|
27
38
|
* The shape this response must have, as a TypeScript type.
|
|
28
39
|
*
|
|
@@ -102,6 +113,21 @@ export type AxonHost = {
|
|
|
102
113
|
}): Promise<unknown>
|
|
103
114
|
}
|
|
104
115
|
|
|
116
|
+
/**
|
|
117
|
+
* The platform's answer to a capsule's "may I?".
|
|
118
|
+
*
|
|
119
|
+
* Deliberately NOT a method on AxonHost. That is the GUEST-facing channel —
|
|
120
|
+
* sandboxed code calls through it — and a guest able to invoke the policy
|
|
121
|
+
* decider could raise its own escalations, or answer them. This is host-side
|
|
122
|
+
* code asking host-side code, on the trusted side of the same boundary the
|
|
123
|
+
* mediator enforces.
|
|
124
|
+
*
|
|
125
|
+
* Absent means no decider, which the capsule already treats as deny. That is
|
|
126
|
+
* the honest state for a headless run and for any embedder that never wired
|
|
127
|
+
* one.
|
|
128
|
+
*/
|
|
129
|
+
export type AxonEscalate = (call: EscalationCall) => Promise<boolean>
|
|
130
|
+
|
|
105
131
|
export type EngineDelegate = {
|
|
106
132
|
/** Tool execution target. Absent/undefined = no capsule attached; capsule RPCs reject loudly. */
|
|
107
133
|
capsule?: () => CapsuleDelegate | undefined
|
package/src/index.ts
CHANGED
package/src/module.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AxonPrompt } from "./prompts"
|
|
2
2
|
import type { AxonScript } from "./scripts"
|
|
3
3
|
import type { AxonTool } from "./tools"
|
|
4
|
+
import type { AxonEntry } from "./session/session"
|
|
5
|
+
import type { AxonStimulusEvent, AxonStimulusType } from "./session/events/stdio/stimuli"
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* A resolved, installed module as it appears in the blueprint — surfaces
|
|
@@ -193,6 +195,29 @@ export type ModuleSetupAxon = {
|
|
|
193
195
|
hook(name: string, handler: (...args: any[]) => void | Promise<void>): void
|
|
194
196
|
/** Emit a hook — fires all registered handlers for this name. */
|
|
195
197
|
callHook(name: string, ...args: any[]): Promise<void>
|
|
198
|
+
/**
|
|
199
|
+
* Deliver a stimulus — the sense door, for modules that ARE sense organs.
|
|
200
|
+
*
|
|
201
|
+
* A channel module (Telegram, Discord, Slack) holds a live transport for
|
|
202
|
+
* the agent's whole life and pushes what it receives into the session:
|
|
203
|
+
*
|
|
204
|
+
* ```ts
|
|
205
|
+
* axon.stim("cognet:stimulus:text", {
|
|
206
|
+
* channel: "telegram:123456789",
|
|
207
|
+
* content: "cody: did the deploy finish?",
|
|
208
|
+
* })
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* Granted here, unlike `request`/`stream`, because sensing is not
|
|
212
|
+
* cognition. A stimulus is raw sense data — nothing upstream of the brain
|
|
213
|
+
* may judge, rank, or filter it (see stimuli.ts) — so this hands a module
|
|
214
|
+
* no cognitive power, only a wire into the session. The mind still decides
|
|
215
|
+
* when to wake and what to attend to.
|
|
216
|
+
*
|
|
217
|
+
* The counterpart is the module's TOOL surface: sense in through `stim`,
|
|
218
|
+
* act out through a tool the brain calls deliberately.
|
|
219
|
+
*/
|
|
220
|
+
stim<K extends AxonStimulusType>(type: K, data: AxonStimulusEvent[K]): Promise<AxonEntry>
|
|
196
221
|
/**
|
|
197
222
|
* Register teardown for this module's live resources (connections, timers,
|
|
198
223
|
* sockets). Disposers run in REVERSE module order on shutdown, and on
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { CapsulePolicy, PolicyRule, PolicyVerdictSource } from "./policy"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolving two policy layers into one verdict — the ceiling model.
|
|
5
|
+
*
|
|
6
|
+
* A PROFILE policy bounds every agent on the machine; an AGENT policy narrows
|
|
7
|
+
* within it. "No internet, no shell" set once at the profile is then true of
|
|
8
|
+
* every agent, and an agent can only ever tighten — which is the property that
|
|
9
|
+
* makes a profile worth setting at all.
|
|
10
|
+
*
|
|
11
|
+
* Lives here, in types, because three consumers must resolve identically: the
|
|
12
|
+
* kernel (enforcement), the CLI (`axon policy`), and Fleet (the policy view).
|
|
13
|
+
* A second implementation would drift on exactly the cases that matter.
|
|
14
|
+
*
|
|
15
|
+
* ── Verdicts intersect; globs do NOT merge ──────────────────────────────────
|
|
16
|
+
*
|
|
17
|
+
* Each layer is evaluated INDEPENDENTLY against the subject, then the stricter
|
|
18
|
+
* verdict wins. Merging the rule objects would be wrong in a way that quietly
|
|
19
|
+
* grants capability: profile `allow: ["git *"]` unioned with agent
|
|
20
|
+
* `allow: ["git push*"]` produces a rule permitting both, when the profile
|
|
21
|
+
* never permitted `git push` on its own. Evaluating separately makes widening
|
|
22
|
+
* impossible by construction rather than by careful glob authorship.
|
|
23
|
+
*
|
|
24
|
+
* ── Silence is "no opinion", not "deny" ─────────────────────────────────────
|
|
25
|
+
*
|
|
26
|
+
* The mediator's own default is deny-by-omission — correct for a sandbox
|
|
27
|
+
* holding foreign code. This is the opposite: a profile that declares one tool
|
|
28
|
+
* rule must not thereby deny every other tool on the machine, or adding a
|
|
29
|
+
* single line to a profile would break every agent on it. So an undeclared
|
|
30
|
+
* capability falls through to the other layer, and only DECLARED rules
|
|
31
|
+
* intersect.
|
|
32
|
+
*
|
|
33
|
+
* The two defaults sit inches apart and mean opposite things. That is
|
|
34
|
+
* deliberate, and it is the thing to re-read before changing either.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/** How strict a verdict is. Higher wins when two layers disagree. */
|
|
38
|
+
const RANK = { allow: 0, escalate: 1, deny: 2 } as const
|
|
39
|
+
|
|
40
|
+
export type PolicyVerdict = "allow" | "deny" | "escalate"
|
|
41
|
+
|
|
42
|
+
/** A verdict plus what produced it, for a surface that has to explain itself. */
|
|
43
|
+
export type ResolvedVerdict = {
|
|
44
|
+
verdict: PolicyVerdict
|
|
45
|
+
/** Absent when no layer declared a rule — the caller applies its own default. */
|
|
46
|
+
source?: PolicyVerdictSource
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Minimal glob matcher — `*` (any chars, no `/`), `**` (any chars including
|
|
51
|
+
* `/`), everything else literal.
|
|
52
|
+
*
|
|
53
|
+
* Duplicated from the capsule's own matcher on purpose: this package must not
|
|
54
|
+
* import from a runtime package (it is the contract every one of them depends
|
|
55
|
+
* on), and policy globs are a handful of characters rather than a library. The
|
|
56
|
+
* two are asserted equivalent by the resolver's tests — if either grows, that
|
|
57
|
+
* is the moment to promote one into a shared leaf.
|
|
58
|
+
*/
|
|
59
|
+
export function policyGlobMatch(pattern: string, value: string): boolean {
|
|
60
|
+
// Built by SCANNING rather than by chained replaces.
|
|
61
|
+
//
|
|
62
|
+
// The chained form used a space as its `**` placeholder and then rewrote
|
|
63
|
+
// every space to `.*` — including the literal spaces the user typed. So
|
|
64
|
+
// `allow: ["bun run *"]` compiled to `bun.*run.*[^/]*` and permitted
|
|
65
|
+
// `bun-run-anything`: an allowlist granting far more than it named, which
|
|
66
|
+
// is the exact failure a policy matcher must not have. Scanning has no
|
|
67
|
+
// placeholder to collide with.
|
|
68
|
+
let source = ""
|
|
69
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
70
|
+
if (pattern[i] === "*") {
|
|
71
|
+
if (pattern[i + 1] === "*") {
|
|
72
|
+
source += ".*"
|
|
73
|
+
i++
|
|
74
|
+
} else {
|
|
75
|
+
source += "[^/]*"
|
|
76
|
+
}
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
// Everything else is literal, including spaces.
|
|
80
|
+
source += pattern[i]!.replace(/[.+^${}()|[\]\\?*]/g, "\\$&")
|
|
81
|
+
}
|
|
82
|
+
return new RegExp(`^${source}$`).test(value)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Evaluate ONE layer's rule against a subject.
|
|
87
|
+
*
|
|
88
|
+
* Returns undefined when the layer declared nothing — distinct from a rule
|
|
89
|
+
* that declared something and matched nothing, which is a deny.
|
|
90
|
+
*
|
|
91
|
+
* Precedence inside a glob rule is deny → escalate → allow, matching the
|
|
92
|
+
* capsule mediator exactly: the strictest matching clause wins regardless of
|
|
93
|
+
* authoring order, so a user cannot accidentally out-order their own denial.
|
|
94
|
+
*/
|
|
95
|
+
export function evaluateRule(
|
|
96
|
+
rule: PolicyRule | undefined,
|
|
97
|
+
subject: string,
|
|
98
|
+
layer: PolicyVerdictSource["layer"],
|
|
99
|
+
): ResolvedVerdict | undefined {
|
|
100
|
+
if (rule === undefined) return undefined
|
|
101
|
+
|
|
102
|
+
if (rule === true) return { verdict: "allow", source: { layer, subject, rule } }
|
|
103
|
+
if (rule === false) return { verdict: "deny", source: { layer, subject, rule } }
|
|
104
|
+
if (rule === "escalate") return { verdict: "escalate", source: { layer, subject, rule } }
|
|
105
|
+
|
|
106
|
+
const denied = rule.deny?.find(pattern => policyGlobMatch(pattern, subject))
|
|
107
|
+
if (denied !== undefined) return { verdict: "deny", source: { layer, subject, pattern: denied, rule } }
|
|
108
|
+
|
|
109
|
+
const escalated = rule.escalate?.find(pattern => policyGlobMatch(pattern, subject))
|
|
110
|
+
if (escalated !== undefined) return { verdict: "escalate", source: { layer, subject, pattern: escalated, rule } }
|
|
111
|
+
|
|
112
|
+
const allowed = rule.allow?.find(pattern => policyGlobMatch(pattern, subject))
|
|
113
|
+
if (allowed !== undefined) return { verdict: "allow", source: { layer, subject, pattern: allowed, rule } }
|
|
114
|
+
|
|
115
|
+
// Declared, matched nothing. A glob rule is an allowlist: naming what is
|
|
116
|
+
// permitted and hitting none of it is a denial, not silence.
|
|
117
|
+
return { verdict: "deny", source: { layer, subject, rule } }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The effective verdict for one subject under both layers.
|
|
122
|
+
*
|
|
123
|
+
* The stricter of the two wins, and the returned `source` is the layer that
|
|
124
|
+
* PRODUCED that verdict — so a denial can always name who denied it. When both
|
|
125
|
+
* agree, the profile is reported: it is the binding constraint, and telling a
|
|
126
|
+
* user their agent denied something their profile also denies sends them to
|
|
127
|
+
* the wrong file.
|
|
128
|
+
*/
|
|
129
|
+
export function resolveVerdict(
|
|
130
|
+
profileRule: PolicyRule | undefined,
|
|
131
|
+
agentRule: PolicyRule | undefined,
|
|
132
|
+
subject: string,
|
|
133
|
+
): ResolvedVerdict {
|
|
134
|
+
const profile = evaluateRule(profileRule, subject, "profile")
|
|
135
|
+
const agent = evaluateRule(agentRule, subject, "agent")
|
|
136
|
+
|
|
137
|
+
if (!profile && !agent) return { verdict: "allow" }
|
|
138
|
+
if (!profile) return agent!
|
|
139
|
+
if (!agent) return profile
|
|
140
|
+
|
|
141
|
+
// Ties go to the profile — see above.
|
|
142
|
+
return RANK[agent.verdict] > RANK[profile.verdict] ? agent : profile
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Isolation is a TIER, not a rule, so it intersects as a maximum rather than
|
|
147
|
+
* through the verdict ranking: a profile asking for `hardened` cannot be
|
|
148
|
+
* loosened to `none` by an agent, but an agent may harden beyond its profile.
|
|
149
|
+
*/
|
|
150
|
+
const ISOLATION_RANK = { none: 0, auto: 1, hardened: 2 } as const
|
|
151
|
+
|
|
152
|
+
export function resolveIsolation(
|
|
153
|
+
profile: CapsulePolicy["isolation"],
|
|
154
|
+
agent: CapsulePolicy["isolation"],
|
|
155
|
+
): CapsulePolicy["isolation"] | undefined {
|
|
156
|
+
if (profile === undefined) return agent
|
|
157
|
+
if (agent === undefined) return profile
|
|
158
|
+
return ISOLATION_RANK[agent] > ISOLATION_RANK[profile] ? agent : profile
|
|
159
|
+
}
|
package/src/policy.ts
CHANGED
|
@@ -111,6 +111,43 @@ export type CapsulePolicy = {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Which layer produced a verdict.
|
|
116
|
+
*
|
|
117
|
+
* The ceiling model resolves two independently-authored policies, and a user
|
|
118
|
+
* reading a denial has to know WHICH said no — a profile denying `**\/secrets/**`
|
|
119
|
+
* while an agent allows `./data/**` denies `data/secrets/key`, and without the
|
|
120
|
+
* source that reads as the agent's own rule misbehaving.
|
|
121
|
+
*
|
|
122
|
+
* "grant" is a standing approval satisfying an escalation that would otherwise
|
|
123
|
+
* have prompted. Reported so an allow that came from a remembered decision is
|
|
124
|
+
* distinguishable from one the policy always permitted — the two look identical
|
|
125
|
+
* at the call site and mean very different things to someone auditing.
|
|
126
|
+
*/
|
|
127
|
+
export type PolicyLayer = "profile" | "agent" | "grant"
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Why an operation was denied or escalated — structured, never a string.
|
|
131
|
+
*
|
|
132
|
+
* This replaced `rule: String(rule)`, which stringified the object form to
|
|
133
|
+
* "[object Object]": the one case that carries the actual patterns was the one
|
|
134
|
+
* case that reported nothing. Every surface that has to explain a decision
|
|
135
|
+
* (the timeline, an escalation prompt, Fleet's policy view) reads this.
|
|
136
|
+
*/
|
|
137
|
+
export type PolicyVerdictSource = {
|
|
138
|
+
/** Which policy layer decided. */
|
|
139
|
+
layer: PolicyLayer
|
|
140
|
+
/** The subject matched against — a command, host, or tool namespace. */
|
|
141
|
+
subject: string
|
|
142
|
+
/**
|
|
143
|
+
* The specific pattern that matched, when the rule was glob-shaped.
|
|
144
|
+
* Absent for a bare `true`/`false`/`"escalate"`, which has no pattern.
|
|
145
|
+
*/
|
|
146
|
+
pattern?: string
|
|
147
|
+
/** The rule as authored, for a surface that wants to show it verbatim. */
|
|
148
|
+
rule: PolicyRule
|
|
149
|
+
}
|
|
150
|
+
|
|
114
151
|
/** Command sent back to the capsule to allow or deny a pending escalation. */
|
|
115
152
|
export type PolicyResponseCommand = {
|
|
116
153
|
id: string
|
|
@@ -16,7 +16,7 @@ import type { AxonOutputEvent } from "./stdio/output"
|
|
|
16
16
|
*
|
|
17
17
|
* Four families:
|
|
18
18
|
* - stimulus:* — exteroception: the world reaching the agent (stdio/stimuli.ts).
|
|
19
|
-
* A
|
|
19
|
+
* A terminal message is cognet:stimulus:text on channel "terminal".
|
|
20
20
|
* - output:* — effectorception: the cognet reaching the world, unmediated
|
|
21
21
|
* (stdio/output.ts). Committed exclusively by kernel.output()
|
|
22
22
|
* — the cognet never calls session.commit directly; it has
|
|
@@ -26,6 +26,10 @@ import type { AxonOutputEvent } from "./stdio/output"
|
|
|
26
26
|
* implementation, the moment the capsule's own
|
|
27
27
|
* cmd:complete/cmd:failed lands — same pattern as
|
|
28
28
|
* capsule:attach/detach, never something cognet code writes.
|
|
29
|
+
* - agent:* — the agent's own control signals, as opposed to what it
|
|
30
|
+
* emitted to the world. `axon:agent:done` is the turn it
|
|
31
|
+
* declared over; it reaches nobody outside the runtime, but
|
|
32
|
+
* it is part of the record the model reads back.
|
|
29
33
|
* - the rest — interoception: machine-body facts (interrupts).
|
|
30
34
|
*/
|
|
31
35
|
/**
|
|
@@ -34,7 +38,7 @@ import type { AxonOutputEvent } from "./stdio/output"
|
|
|
34
38
|
* renderers) derives from THIS list, never from its own prefix sniff: a new
|
|
35
39
|
* family added to AxonEntryEvent must be added here in the same change.
|
|
36
40
|
*/
|
|
37
|
-
export const ENTRY_EVENT_PREFIXES = ["cognet:stimulus:", "cognet:output:", "cognet:action:", "axon:interrupt", "axon:system:"] as const
|
|
41
|
+
export const ENTRY_EVENT_PREFIXES = ["cognet:stimulus:", "cognet:output:", "cognet:action:", "axon:interrupt", "axon:system:", "axon:agent:"] as const
|
|
38
42
|
|
|
39
43
|
export type AxonEntryEvent = AxonStimulusEvent & AxonOutputEvent & {
|
|
40
44
|
/** Kernel signal record — an interrupt is machinery, never a stimulus. */
|
|
@@ -63,4 +67,41 @@ export type AxonEntryEvent = AxonStimulusEvent & AxonOutputEvent & {
|
|
|
63
67
|
/** Additional trusted AIR attributes. `type` and `lang` are reserved. */
|
|
64
68
|
attributes?: Record<string, string>
|
|
65
69
|
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A reply that broke the output contract, kept verbatim.
|
|
73
|
+
*
|
|
74
|
+
* The correction alone was a scolding with no referent: the malformed
|
|
75
|
+
* text never entered the log, so the next turn showed the model a
|
|
76
|
+
* complaint about output it could no longer see. It cannot fix a shape
|
|
77
|
+
* it is not looking at, and runs were observed repeating the same
|
|
78
|
+
* violation immediately after being corrected for it.
|
|
79
|
+
*
|
|
80
|
+
* Stored raw and uninterpreted — the parser already failed on it, so any
|
|
81
|
+
* structure claimed here would be a guess. It renders as the agent turn
|
|
82
|
+
* it was, directly above the correction it earned.
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* The model declared its turn over.
|
|
86
|
+
*
|
|
87
|
+
* Committed so the model can SEE its own turn endings. `<done/>` was
|
|
88
|
+
* parsed as a signal and dropped, which made it the one block whose
|
|
89
|
+
* correct use matters most and the only one absent from the model's own
|
|
90
|
+
* record — it read the rule in the contract and never once saw itself
|
|
91
|
+
* having followed it. Over a long run that is the block with the least
|
|
92
|
+
* in-context reinforcement and the most consequence when it goes wrong.
|
|
93
|
+
*
|
|
94
|
+
* Carries no payload: the fact IS the event. A turn either ended here or
|
|
95
|
+
* it did not.
|
|
96
|
+
*/
|
|
97
|
+
"axon:agent:done": Record<string, never>
|
|
98
|
+
|
|
99
|
+
"axon:system:malformed": {
|
|
100
|
+
/** The model's output exactly as it came off the wire. */
|
|
101
|
+
content: string
|
|
102
|
+
/** The violation code this reply produced, matching the paired fault. */
|
|
103
|
+
code: string
|
|
104
|
+
/** Which engine attempt this was — 1-based, so a reader can see the sequence. */
|
|
105
|
+
attempt: number
|
|
106
|
+
}
|
|
66
107
|
}
|
|
@@ -59,4 +59,26 @@ export type AxonKernelEventMap =
|
|
|
59
59
|
*/
|
|
60
60
|
"kernel:engine:input": { messages: AxonEngineMessage[]; bytes: number }
|
|
61
61
|
"kernel:engine:retry": { attempt: number; nextAttempt: number; delayMs: number; fault: AxonEngineFault }
|
|
62
|
+
/**
|
|
63
|
+
* The first provider delta crossed the boundary — the moment an engine
|
|
64
|
+
* call stops waiting and starts producing.
|
|
65
|
+
*
|
|
66
|
+
* Not a span, and deliberately so: this is an INSTANT inside the
|
|
67
|
+
* kernel:engine bracket, not a bracket of its own. The two intervals a
|
|
68
|
+
* reader wants (latency before it, generation after it) are both
|
|
69
|
+
* derivable from one marker plus the ends that already exist, so a
|
|
70
|
+
* second pair of start/complete events would be two lines describing
|
|
71
|
+
* the same split.
|
|
72
|
+
*
|
|
73
|
+
* `meta.firstTokenMs` on :complete carries the same number, but only in
|
|
74
|
+
* arrears and only for a call that finished. This is emitted AS IT
|
|
75
|
+
* HAPPENS, which is what makes it drawable on a live bar and what keeps
|
|
76
|
+
* the split visible on a call that was interrupted or failed mid-stream
|
|
77
|
+
* — precisely the calls where "was it slow to start or slow to finish"
|
|
78
|
+
* is the question being asked.
|
|
79
|
+
*
|
|
80
|
+
* Same spanId as its kernel:engine:start, per attempt: a retried call
|
|
81
|
+
* emits one per attempt, and `attempt` distinguishes them.
|
|
82
|
+
*/
|
|
83
|
+
"kernel:engine:firstToken": { attempt: number; elapsedMs: number }
|
|
62
84
|
}
|
|
@@ -34,8 +34,13 @@ import type { AxonSpan } from "./span"
|
|
|
34
34
|
*
|
|
35
35
|
* Absent means module — every event written before extensions could be
|
|
36
36
|
* installed is one, and defaulting keeps those readable.
|
|
37
|
+
*
|
|
38
|
+
* "cognet" is the agent's brain. It updates through the same installer as a
|
|
39
|
+
* module (it IS an ordinary registry package), so it belongs on this span
|
|
40
|
+
* rather than a fourth triad — but it is not a module: it is selected by
|
|
41
|
+
* `cognet:`, never listed under `modules:`, and there is exactly one.
|
|
37
42
|
*/
|
|
38
|
-
export type ArtifactInstalled = "module" | "extension"
|
|
43
|
+
export type ArtifactInstalled = "module" | "extension" | "cognet"
|
|
39
44
|
|
|
40
45
|
export type AxonRuntimeEvent =
|
|
41
46
|
& AxonLogEvents<"axon">
|
|
@@ -49,6 +54,23 @@ export type AxonRuntimeEvent =
|
|
|
49
54
|
{ revision: number; toolCount: number },
|
|
50
55
|
{ revision?: number; error: AxonError }
|
|
51
56
|
>
|
|
57
|
+
/**
|
|
58
|
+
* A variable set in the agent's own .env, then a reload so it is live.
|
|
59
|
+
*
|
|
60
|
+
* THE KEY ONLY, NEVER THE VALUE. This is the path secrets arrive on — an
|
|
61
|
+
* API token, a bot key — and the session log is durable and syncs. Naming
|
|
62
|
+
* the variable is what makes the change auditable ("TELEGRAM_BOT_TOKEN was
|
|
63
|
+
* set at 14:02"); recording what it was set to would write every secret
|
|
64
|
+
* the user ever types into a permanent record. The one is the audit trail,
|
|
65
|
+
* the other is a leak, and they are separated here rather than left to
|
|
66
|
+
* each caller to remember.
|
|
67
|
+
*/
|
|
68
|
+
& AxonSpan<
|
|
69
|
+
"axon:env:set",
|
|
70
|
+
{ key: string },
|
|
71
|
+
{ key: string },
|
|
72
|
+
{ key: string; error: AxonError }
|
|
73
|
+
>
|
|
52
74
|
// ── Module install/uninstall (registry op, then a reload rides the same
|
|
53
75
|
// hot-swap path above) ─────────────────────────────────────────────
|
|
54
76
|
& AxonSpan<
|
|
@@ -26,6 +26,30 @@
|
|
|
26
26
|
* to /cmd_vel and /speaker, has the same addressing problem outbound as a
|
|
27
27
|
* ROS network has inbound — a mind emitting to two lines is not doing one
|
|
28
28
|
* thing, and an observer that cannot tell them apart cannot debug either.
|
|
29
|
+
*
|
|
30
|
+
* ── CONVENTION: CHANNEL MODULES ──────────────────────────────────────────
|
|
31
|
+
*
|
|
32
|
+
* A channel module (Telegram, Discord, Slack, SMS) names its channels
|
|
33
|
+
* `"<module>:<address>"` — `"telegram:123456789"`, `"discord:9876"`. Two
|
|
34
|
+
* rules, and they exist for different reasons:
|
|
35
|
+
*
|
|
36
|
+
* 1. The MODULE PREFIX keeps the namespace collision-free. An agent with
|
|
37
|
+
* both Telegram and Discord installed would otherwise see two `"chat"`
|
|
38
|
+
* channels and could answer one person on the other's transport.
|
|
39
|
+
*
|
|
40
|
+
* 2. The ADDRESS is what makes a reply possible. The mind reads the channel
|
|
41
|
+
* off the stimulus it is answering and hands that address to the module's
|
|
42
|
+
* send tool. This is the whole return path, and it is stateless by
|
|
43
|
+
* construction: two people messaging at once produce two stimuli each
|
|
44
|
+
* carrying its own return address, so nothing upstream has to remember
|
|
45
|
+
* who spoke last. A module whose send tool targets "the last sender"
|
|
46
|
+
* instead has moved an addressing decision out of the mind and into a
|
|
47
|
+
* hidden global, where concurrency breaks it.
|
|
48
|
+
*
|
|
49
|
+
* WHO IS SPEAKING GOES IN THE PAYLOAD, NOT HERE. The channel is routing; the
|
|
50
|
+
* sender is content the mind should weigh — including when deciding whether
|
|
51
|
+
* to trust the request at all. This is why `StimulusSource = { channel, id? }`
|
|
52
|
+
* collapsed to a bare address: participant identity that matters is content.
|
|
29
53
|
*/
|
|
30
54
|
export type AxonChannel = string
|
|
31
55
|
|