@arcforge/types 2.0.162 → 2.0.164
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/README.md +26 -0
- package/package.json +22 -2
- package/src/agent-handle.ts +163 -0
- package/src/blueprint.ts +38 -0
- package/src/capsule-config.ts +13 -6
- package/src/error.ts +5 -0
- package/src/handle.ts +11 -5
- package/src/index.ts +7 -0
- package/src/policy-build.ts +28 -6
- package/src/policy-normalize.ts +266 -33
- package/src/policy-resolve.ts +14 -2
- package/src/policy-shell.ts +189 -0
- package/src/policy.ts +329 -21
- package/src/prompts.ts +32 -0
- package/src/scope.ts +4 -4
- package/src/supervisor.ts +28 -1
- package/src/tools.ts +0 -6
- package/src/tui-contract.ts +1 -1
- package/src/tui.ts +31 -12
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @arcforge/types
|
|
2
|
+
|
|
3
|
+
Shared type definitions for the [Axon](https://axon.arclabs.it) agent runtime.
|
|
4
|
+
|
|
5
|
+
This is the leaf of the Axon dependency graph — every other package depends on it,
|
|
6
|
+
and it depends on nothing. It holds the contracts that cross package boundaries:
|
|
7
|
+
the agent handle, engine connections, policy shapes, and the session event vocabulary.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @arcforge/types
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Most people never install this directly. It arrives as a dependency of the Axon
|
|
14
|
+
framework when you scaffold an agent with `axon init`.
|
|
15
|
+
|
|
16
|
+
## Documentation
|
|
17
|
+
|
|
18
|
+
Full documentation is at **[axon.arclabs.it/docs/v2](https://axon.arclabs.it/docs/v2)**.
|
|
19
|
+
|
|
20
|
+
- [What is Axon?](https://axon.arclabs.it/docs/v2)
|
|
21
|
+
- [The axon API](https://axon.arclabs.it/docs/v2/api)
|
|
22
|
+
- [Policy](https://axon.arclabs.it/docs/v2/agent/policy)
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Proprietary. © ArcLabs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcforge/types",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.164",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -24,5 +24,25 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"typescript": "^5"
|
|
27
|
-
}
|
|
27
|
+
},
|
|
28
|
+
"description": "Shared type definitions for the Axon agent runtime.",
|
|
29
|
+
"homepage": "https://axon.arclabs.it/docs/v2",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/artificial-cognition-laboratories/axon.git",
|
|
33
|
+
"directory": "libs/axon/types"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/artificial-cognition-laboratories/axon/issues"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"axon",
|
|
40
|
+
"ai",
|
|
41
|
+
"agent",
|
|
42
|
+
"agents",
|
|
43
|
+
"llm",
|
|
44
|
+
"ai-agent",
|
|
45
|
+
"agent-runtime",
|
|
46
|
+
"typescript"
|
|
47
|
+
]
|
|
28
48
|
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { AxonBlueprint } from "./blueprint"
|
|
2
|
+
import type { AxonEntry } from "./session"
|
|
3
|
+
import type { AxonStimulusEntry } from "./session/events/stdio/stimuli"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A handle to ONE running agent, wherever it runs.
|
|
7
|
+
*
|
|
8
|
+
* ── Why one type for three transports ───────────────────────────────────────
|
|
9
|
+
*
|
|
10
|
+
* An agent may be a process this daemon supervises, a process on another
|
|
11
|
+
* machine's daemon, or a deployment reached over HTTPS. Those differ in how
|
|
12
|
+
* bytes move and in nothing else that a consumer should have to know.
|
|
13
|
+
*
|
|
14
|
+
* Before this, they differed in TYPE: a local agent returned an object graph
|
|
15
|
+
* with a live session, a live bus and a `select()` method, while a remote one
|
|
16
|
+
* returned a proxy. Every surface written against the local shape was silently
|
|
17
|
+
* unusable against the remote one — which is why the Fleet extension can list
|
|
18
|
+
* running agents and cannot speak to them, and why "debug an agent on my other
|
|
19
|
+
* machine" had no path at all.
|
|
20
|
+
*
|
|
21
|
+
* The object graph was the anomaly, not the proxy. A handle whose verbs are
|
|
22
|
+
* async and fallible is the honest description of talking to a process you are
|
|
23
|
+
* not inside; the local shortcut only looked simpler because it hid a
|
|
24
|
+
* boundary that was always there.
|
|
25
|
+
*
|
|
26
|
+
* ── Stimulus is the way in ──────────────────────────────────────────────────
|
|
27
|
+
*
|
|
28
|
+
* Every input is an `AxonStimulusEntry`. A prompt is not a separate concept —
|
|
29
|
+
* it is `cognet:stimulus:text`, and a surface that took a bare string would be
|
|
30
|
+
* inventing a second door into the same brain. Convenience over that belongs
|
|
31
|
+
* in a helper, never in the contract.
|
|
32
|
+
*/
|
|
33
|
+
export type AxonAgentHandle = {
|
|
34
|
+
/** This agent's session id — its identity everywhere in Axon. */
|
|
35
|
+
readonly sessionId: string
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Deliver a stimulus. Resolves on ADMISSION, never on completion.
|
|
39
|
+
*
|
|
40
|
+
* A continuous cognet is ticked by its own plugin and wakes whether or not
|
|
41
|
+
* the last wake finished; resolving on completion would serialise that
|
|
42
|
+
* overlap and turn a mind under a clock into a queue. `admitted: false` is
|
|
43
|
+
* the mind declining a second conversation — an answer, not a failure.
|
|
44
|
+
*/
|
|
45
|
+
stimulus(entry: AxonStimulusEntry): Promise<{ admitted: boolean }>
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Deliver a stimulus and wait for the wake it caused to SETTLE.
|
|
49
|
+
*
|
|
50
|
+
* The completion counterpart to `stimulus`, for an interactive caller who
|
|
51
|
+
* needs to know when the reply is finished. A UI rendering a spinner
|
|
52
|
+
* forever because nothing said "done" is broken in a way admission cannot
|
|
53
|
+
* fix.
|
|
54
|
+
*/
|
|
55
|
+
request(entry: AxonStimulusEntry): Promise<{ ok: boolean; interrupted?: boolean }>
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Deliver a stimulus and iterate what it produces.
|
|
59
|
+
*
|
|
60
|
+
* The streaming form, and what a surface renders from. `interrupt` aborts
|
|
61
|
+
* the run rather than merely stopping the iteration — a consumer that
|
|
62
|
+
* walked away must not leave a wake burning tokens.
|
|
63
|
+
*/
|
|
64
|
+
stream(entry: AxonStimulusEntry): { stream: AsyncGenerator<AxonEntry, void, undefined>; interrupt(): void }
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Abort the active wake.
|
|
68
|
+
*
|
|
69
|
+
* Out-of-band, which is why the link has two channels: an interrupt must
|
|
70
|
+
* land WHILE inference is streaming, and behind the same queue it would
|
|
71
|
+
* wait on exactly the traffic it exists to stop.
|
|
72
|
+
*/
|
|
73
|
+
interrupt(reason: "user" | "shutdown"): Promise<void>
|
|
74
|
+
|
|
75
|
+
/** Hot reload: a re-normalised blueprint replaces the live one. */
|
|
76
|
+
update(blueprint: AxonBlueprint): Promise<void>
|
|
77
|
+
|
|
78
|
+
/** Drain and exit. */
|
|
79
|
+
shutdown(): Promise<void>
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The agent's log, as this consumer can see it.
|
|
83
|
+
*
|
|
84
|
+
* MIRRORED for every transport, including one in the same process. The
|
|
85
|
+
* local case genuinely holds the real session and could expose it — and
|
|
86
|
+
* that asymmetry is precisely what let surfaces become accidentally
|
|
87
|
+
* local-only. One shape everywhere costs the local case some rebuilt state
|
|
88
|
+
* and buys every surface working against any agent.
|
|
89
|
+
*/
|
|
90
|
+
readonly session: AxonMirroredSession
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Rebind a role to a different model.
|
|
94
|
+
*
|
|
95
|
+
* A VERB rather than an `engines` object, because the object it replaced
|
|
96
|
+
* carried a `select()` closure that only exists supervisor-side. A method
|
|
97
|
+
* crosses a wire; a closure does not.
|
|
98
|
+
*/
|
|
99
|
+
selectModel(model: string): Promise<void>
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The read surface of an agent's log.
|
|
104
|
+
*
|
|
105
|
+
* Modelled on `MirroredSession`, which already solved this for deployments —
|
|
106
|
+
* the accumulated view plus a subscription that replays from a cursor and
|
|
107
|
+
* survives reconnection. A flatter "subscribe(handler)" was the obvious first
|
|
108
|
+
* shape and would have thrown away the two facts a consumer actually needs:
|
|
109
|
+
* when replay ends and live begins, and when the agent behind the URL turns
|
|
110
|
+
* out to be a DIFFERENT session because it restarted.
|
|
111
|
+
*/
|
|
112
|
+
export type AxonMirroredSession = {
|
|
113
|
+
/** The conversation — what a UI renders. */
|
|
114
|
+
readonly entries: readonly AxonEntry[]
|
|
115
|
+
/** Everything committed, entries included. */
|
|
116
|
+
readonly log: readonly unknown[]
|
|
117
|
+
/** Machine-body events: boot, build, kernel spans. */
|
|
118
|
+
readonly kernelLog: readonly unknown[]
|
|
119
|
+
/**
|
|
120
|
+
* How far this mirror has read. Null before the first event.
|
|
121
|
+
*
|
|
122
|
+
* Exposed because a resume is only meaningful against the session the
|
|
123
|
+
* cursor came from — see `onReset`.
|
|
124
|
+
*/
|
|
125
|
+
readonly cursor: number | null
|
|
126
|
+
|
|
127
|
+
/** Follow the agent. Returns an unsubscribe. */
|
|
128
|
+
subscribe(handlers: AxonSessionHandlers): () => void
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** What a subscriber is told. Every field optional — a consumer takes what it needs. */
|
|
132
|
+
export type AxonSessionHandlers = {
|
|
133
|
+
/** Each newly absorbed event, in order. */
|
|
134
|
+
onEvent?: (event: { type: string } & Record<string, unknown>) => void
|
|
135
|
+
/** Replay is done; everything after this is live. */
|
|
136
|
+
onLive?: (cursor: number | null) => void
|
|
137
|
+
/** The stream ended cleanly — the agent shut down. */
|
|
138
|
+
onClose?: () => void
|
|
139
|
+
/**
|
|
140
|
+
* The agent is a DIFFERENT session than the one mirrored — it restarted.
|
|
141
|
+
*
|
|
142
|
+
* The mirror has already dropped the old history, so a consumer rendering
|
|
143
|
+
* from it must re-read rather than append to what it had. Without this a
|
|
144
|
+
* restart shows one conversation with two agents' turns interleaved.
|
|
145
|
+
*/
|
|
146
|
+
onReset?: (sessionId: string) => void
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The authoring verbs, available only where the agent's project is.
|
|
151
|
+
*
|
|
152
|
+
* Deliberately NOT on `AxonAgentHandle`. `prompts` and `run` read and execute
|
|
153
|
+
* source that lives beside the agent on disk — a deployment has no project to
|
|
154
|
+
* read, and a daemon on another machine has one this caller cannot see. A
|
|
155
|
+
* transport that cannot do them says so by not implementing this, rather than
|
|
156
|
+
* by throwing at a verb the type promised.
|
|
157
|
+
*/
|
|
158
|
+
export type AxonAuthoringHandle = {
|
|
159
|
+
/** The prompts this agent declares, rendered. */
|
|
160
|
+
prompts(): Promise<unknown>
|
|
161
|
+
/** Execute code in the agent's own scope. */
|
|
162
|
+
run(code: string): Promise<unknown>
|
|
163
|
+
}
|
package/src/blueprint.ts
CHANGED
|
@@ -107,6 +107,22 @@ export type AxonBlueprint = {
|
|
|
107
107
|
*/
|
|
108
108
|
env: Record<string, string>
|
|
109
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Host environment the SUPERVISOR needs, and the box must never receive.
|
|
112
|
+
*
|
|
113
|
+
* The split exists because two different processes read from this blueprint
|
|
114
|
+
* and they have opposite trust: the supervisor holds credentials and makes
|
|
115
|
+
* outbound calls on the agent's behalf; the box runs model-emitted code and
|
|
116
|
+
* must hold nothing it does not need. `AXON_API_KEY` is the clear case —
|
|
117
|
+
* the supervisor's cloud client needs it, and it is precisely the value
|
|
118
|
+
* that must not be reachable from inside the box.
|
|
119
|
+
*
|
|
120
|
+
* `env` above is the agent's own `.env`: what a developer put beside their
|
|
121
|
+
* code, and what may cross into the box (subject to policy). This is the
|
|
122
|
+
* host's, and it stops at the boundary.
|
|
123
|
+
*/
|
|
124
|
+
hostEnv?: Record<string, string>
|
|
125
|
+
|
|
110
126
|
tools: AxonTool[]
|
|
111
127
|
prompts: AxonPrompt[]
|
|
112
128
|
scripts: AxonScript[]
|
|
@@ -128,6 +144,26 @@ export type AxonBlueprint = {
|
|
|
128
144
|
*/
|
|
129
145
|
modules: AxonModule[]
|
|
130
146
|
|
|
147
|
+
/**
|
|
148
|
+
* What the PRIMARY role actually resolved to, as a flat fact.
|
|
149
|
+
*
|
|
150
|
+
* Nothing is declared any more — a user supplies providers, a cognet
|
|
151
|
+
* names roles, and which model serves the cortex is decided at boot by
|
|
152
|
+
* whoever holds the credential. For a confined agent that is the
|
|
153
|
+
* SUPERVISOR: the agent has no credential and therefore cannot resolve,
|
|
154
|
+
* so it cannot answer "which model am I on" from anything it holds.
|
|
155
|
+
*
|
|
156
|
+
* Carried here because the answer is a fact about this boot and every
|
|
157
|
+
* client's header asks for it. `/_axon/health` reported `engine: null`
|
|
158
|
+
* on a perfectly working agent for exactly this reason — it read the
|
|
159
|
+
* kernel's engines, which a confined agent never has.
|
|
160
|
+
*
|
|
161
|
+
* Absent when the cognet declares no roles, or none is primary: a pure
|
|
162
|
+
* control loop genuinely has no model, and inventing one would put a
|
|
163
|
+
* dead row in every client's header.
|
|
164
|
+
*/
|
|
165
|
+
engine?: { provider: string; model: string | null }
|
|
166
|
+
|
|
131
167
|
paths: {
|
|
132
168
|
/** agent root — still needed for capsule fs-tool sandboxing, not for discovery */
|
|
133
169
|
root: string
|
|
@@ -152,12 +188,14 @@ export type AxonPartialBlueprint = {
|
|
|
152
188
|
profileProviders?: AxonBlueprint["profileProviders"]
|
|
153
189
|
cognet?: CognetBlueprint
|
|
154
190
|
env?: AxonBlueprint["env"]
|
|
191
|
+
hostEnv?: AxonBlueprint["hostEnv"]
|
|
155
192
|
tools?: AxonBlueprint["tools"]
|
|
156
193
|
prompts?: AxonBlueprint["prompts"]
|
|
157
194
|
scripts?: AxonBlueprint["scripts"]
|
|
158
195
|
knowledge?: AxonBlueprint["knowledge"]
|
|
159
196
|
server?: Partial<AxonServerBlueprint>
|
|
160
197
|
modules?: AxonBlueprint["modules"]
|
|
198
|
+
engine?: AxonBlueprint["engine"]
|
|
161
199
|
paths?: Partial<AxonBlueprint["paths"]>
|
|
162
200
|
}
|
|
163
201
|
|
package/src/capsule-config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CapsulePolicy, EscalationCall, PolicyBucket, PolicyRule } from "./policy"
|
|
1
|
+
import type { CapsulePolicy, EscalationCall, PolicyBucket, PolicyRule, ResolvedCapsulePolicy, ToolBucket } from "./policy"
|
|
2
2
|
import type { AxonScopeModule } from "./scope"
|
|
3
3
|
|
|
4
4
|
export type CapsuleHostRequest = {
|
|
@@ -53,7 +53,15 @@ export type CapsuleBlueprint = {
|
|
|
53
53
|
tools: CapsuleTool[]
|
|
54
54
|
|
|
55
55
|
/** What the sandbox may do — mediator gates + OS confinement (see CapsulePolicy). */
|
|
56
|
-
|
|
56
|
+
/**
|
|
57
|
+
* The policy as the enforcer reads it — RESOLVED, not authored.
|
|
58
|
+
*
|
|
59
|
+
* `ResolvedCapsulePolicy` rather than `CapsulePolicy` because a rule here
|
|
60
|
+
* may be a carried profile/agent pair, which is a shape nobody writes and
|
|
61
|
+
* every enforcement point must handle. The authored form is
|
|
62
|
+
* `CapsulePartialConfig["policy"]` below.
|
|
63
|
+
*/
|
|
64
|
+
policy: ResolvedCapsulePolicy
|
|
57
65
|
|
|
58
66
|
/**
|
|
59
67
|
* Answer policy escalations. One callback, one decision — default deny.
|
|
@@ -100,9 +108,8 @@ export type CapsulePartialConfig = Partial<Omit<CapsuleBlueprint, "policy">> & {
|
|
|
100
108
|
* covering the whole surface (`tools: "escalate"`), which `Blueprint()`
|
|
101
109
|
* normalises into the keyed shape the capsule enforces. See `PolicyBucket`.
|
|
102
110
|
*/
|
|
103
|
-
policy?: Partial<Omit<CapsulePolicy, "
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
network?: PolicyBucket
|
|
111
|
+
policy?: Partial<Omit<CapsulePolicy, "tools" | "shell">> & {
|
|
112
|
+
tools?: ToolBucket
|
|
113
|
+
shell?: NonNullable<CapsulePolicy["shell"]> | boolean
|
|
107
114
|
}
|
|
108
115
|
}
|
package/src/error.ts
CHANGED
|
@@ -31,6 +31,11 @@ export type AxonStackFrame = {
|
|
|
31
31
|
export type AxonErrorSource =
|
|
32
32
|
| "runtime" | "manifest" | "capsule" | "server" | "thread" | "cli"
|
|
33
33
|
| "cloud" | "kernel" | "cognet" | "tui" | "bench"
|
|
34
|
+
// The machine-wide daemon. Its own source rather than "runtime": a
|
|
35
|
+
// failure here is about SHARED state — the GPU, the instance registry —
|
|
36
|
+
// and telling that apart from one agent's runtime fault is the difference
|
|
37
|
+
// between "restart your agent" and "start the daemon".
|
|
38
|
+
| "daemon"
|
|
34
39
|
|
|
35
40
|
/** Lifecycle impact of an error. */
|
|
36
41
|
export type AxonErrorSeverity = "fatal" | "recovered" | "degraded"
|
package/src/handle.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { EscalationCall } from "./policy"
|
|
|
2
2
|
import type { AxonEntry, AxonKernelEvent, AxonSessionEvent, AxonStimulusEvent, AxonStimulusType } from "./session"
|
|
3
3
|
import type { AxonOutputEvent } from "./session/events/stdio/output"
|
|
4
4
|
import type { AxonScript } from "./scripts"
|
|
5
|
-
import type { AxonPrompt } from "./prompts"
|
|
5
|
+
import type { AxonPrompt, AxonPromptName, AxonPromptProps } from "./prompts"
|
|
6
6
|
import type { AxonPartialBlueprint } from "./blueprint"
|
|
7
7
|
import type { AxonHookName, AxonHooks, AxonModuleEvents } from "./hooks"
|
|
8
8
|
import type { AxonAmbient } from "./session/events/activity"
|
|
@@ -195,8 +195,16 @@ export type AxonHandle = {
|
|
|
195
195
|
*/
|
|
196
196
|
readonly ready: boolean
|
|
197
197
|
|
|
198
|
-
/**
|
|
199
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Render a prompt by name. Static .md returns as-is; dynamic .vue
|
|
200
|
+
* renders with props.
|
|
201
|
+
*
|
|
202
|
+
* Generic over `AxonPromptMap`, which `axon prepare` fills in with one
|
|
203
|
+
* entry per prompt the agent declares — so a name that does not exist is
|
|
204
|
+
* a compile error, and props are checked against the prompt that will
|
|
205
|
+
* actually receive them.
|
|
206
|
+
*/
|
|
207
|
+
prompt<K extends AxonPromptName>(name: K, props?: AxonPromptProps<K>): Promise<string>
|
|
200
208
|
|
|
201
209
|
/**
|
|
202
210
|
* This agent's installed modules, as configured.
|
|
@@ -350,8 +358,6 @@ export type AxonHandle = {
|
|
|
350
358
|
list(): AxonScript[]
|
|
351
359
|
}
|
|
352
360
|
|
|
353
|
-
/** Installed tool namespaces, callable by name — each call is a mediated capsule request. */
|
|
354
|
-
tools: Record<string, Record<string, (...args: unknown[]) => Promise<unknown>>>
|
|
355
361
|
|
|
356
362
|
/**
|
|
357
363
|
* Hot-reload trigger — apply a blueprint to the live runtime.
|
package/src/index.ts
CHANGED
|
@@ -32,3 +32,10 @@ export * from "./cognet"
|
|
|
32
32
|
export * from "./tools"
|
|
33
33
|
export * from "./tui"
|
|
34
34
|
export * from "./bench"
|
|
35
|
+
export * from "./policy-shell"
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The one handle every running agent is reached through — local, daemon, or
|
|
39
|
+
* deployed. See agent-handle.ts for why the transports share a type.
|
|
40
|
+
*/
|
|
41
|
+
export type { AxonAgentHandle, AxonAuthoringHandle, AxonMirroredSession, AxonSessionHandlers } from "./agent-handle"
|
package/src/policy-build.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AxonBlueprint } from "./blueprint"
|
|
2
2
|
import type { CapsulePolicy } from "./policy"
|
|
3
|
-
import { intersect, keyed, resolveFsPaths, type NormalizedPolicy } from "./policy-normalize"
|
|
3
|
+
import { intersect, keyed, POLICY_WILDCARD, resolveFsPaths, type NormalizedPolicy, type ToolPolicyEntry } from "./policy-normalize"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Policy — the ONE place a user's intent becomes a machine-enforceable policy.
|
|
@@ -88,11 +88,34 @@ export function Policy(opts: PolicyOpts): ResolvedPolicy {
|
|
|
88
88
|
// every agent on the machine into it — an agent that declares nothing still
|
|
89
89
|
// gets the wall its profile asked for.
|
|
90
90
|
const wantsContainment =
|
|
91
|
-
userPolicy.fs !== undefined
|
|
91
|
+
userPolicy.fs !== undefined
|
|
92
|
+
|| userPolicy.net !== undefined
|
|
93
|
+
|| userPolicy.limits !== undefined
|
|
94
|
+
|| userPolicy.env !== undefined
|
|
92
95
|
const isolation = userPolicy.isolation ?? (wantsContainment ? "auto" : "none")
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Installed tools default to allowed — but ONLY where no layer has spoken.
|
|
99
|
+
*
|
|
100
|
+
* The default used to be written as `{ ...defaults, ...userPolicy.tools }`,
|
|
101
|
+
* which looks like "the user's rules win" and is not. A profile blanket
|
|
102
|
+
* normalises to the key `"*"`, so it never collides with a tool's own name:
|
|
103
|
+
* the default `github: true` sat at key `github`, the address walk found it
|
|
104
|
+
* before ever consulting `"*"`, and a profile declaring `tools: "escalate"`
|
|
105
|
+
* silently granted every installed tool instead. That is precisely the leak
|
|
106
|
+
* `pairRules` exists to prevent, reintroduced one layer above it.
|
|
107
|
+
*
|
|
108
|
+
* So a default is only applied to a name that the RESOLVED policy — after
|
|
109
|
+
* the ceiling has run — says nothing about, wildcard included.
|
|
110
|
+
*/
|
|
111
|
+
const resolvedTools = userPolicy.tools ?? {}
|
|
112
|
+
const blanket = resolvedTools[POLICY_WILDCARD]
|
|
113
|
+
const tools: Record<string, ToolPolicyEntry> = { ...resolvedTools }
|
|
114
|
+
for (const name of opts.tools) {
|
|
115
|
+
if (name in resolvedTools) continue
|
|
116
|
+
if (blanket !== undefined) continue
|
|
117
|
+
tools[name] = true
|
|
118
|
+
}
|
|
96
119
|
|
|
97
120
|
return {
|
|
98
121
|
isolation,
|
|
@@ -100,8 +123,7 @@ export function Policy(opts: PolicyOpts): ResolvedPolicy {
|
|
|
100
123
|
...userPolicy,
|
|
101
124
|
isolation,
|
|
102
125
|
...(userPolicy.fs ? { fs: resolveFsPaths(userPolicy.fs, blueprint.paths.root) } : {}),
|
|
103
|
-
|
|
104
|
-
tools: { ...tools, ...userPolicy.tools },
|
|
126
|
+
tools,
|
|
105
127
|
} as CapsulePolicy,
|
|
106
128
|
}
|
|
107
129
|
}
|