@agentproto/runtime 1.1.0 → 2.1.0

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.
@@ -0,0 +1,192 @@
1
+ import { CostBudget } from '@agentproto/auth';
2
+ import { C as ContextContinuityPolicy } from './context-continuity-B9n0t0v-.js';
3
+
4
+ /**
5
+ * SessionConfig — the unified per-session config surface, decomposed into
6
+ * orthogonal axes (SPEC §3.1, out-of-repo design doc
7
+ * `agentproto-session-config-axes/SPEC.md`). Pure types + a `decomposeMode`/
8
+ * `composeMode` shim over the legacy AIP-45 `mode` string — no I/O, no runtime
9
+ * wiring, no adapter behavior change. This is the additive type foundation
10
+ * (SPEC §7.2 build step 1); the live spawn-path extraction (deleting gateway
11
+ * modes, sourcing posture from the ACP registry) is a separate later step.
12
+ *
13
+ * Boundary note: this module deliberately does NOT import from
14
+ * `@agentproto/auth`. `packages/runtime` intentionally has no dependency on
15
+ * that package (`mcp-credential-deps.ts:1-9`), so the named-profile record it
16
+ * owns — `AuthProfile` (`packages/auth/src/profile-types.ts:24`, shipped in
17
+ * #470) — is referenced by citation, never redefined here: the `access` axis
18
+ * only needs a `profileRef` string, and the profile record itself stays in
19
+ * `@agentproto/auth`. The narrow `AuthMethod` *facet*, by contrast, is
20
+ * structurally mirrored below (§3.1) — the descriptor's `accessProfile` echo
21
+ * (§3.7) names it, and mirroring a two-value string union is cheaper than
22
+ * taking a package dependency on `@agentproto/auth` for it, the same
23
+ * structural-mirror rationale as `DeclaredAdapterMode` (below) and
24
+ * `DeclaredAdapterOption` (`spawn-defaults.ts:447`).
25
+ *
26
+ * It DOES, however, import a VALUE — the legacy AIP-45 mode-id classification
27
+ * (`inferLegacyModeKind`) — from `@agentproto/driver-agent-cli` (a lean,
28
+ * acyclic runtime → driver edge; the driver never depends back on the runtime).
29
+ * Unlike the type mirrors above (a mirror can't silently break — the compiler
30
+ * still checks structural compatibility), the gateway/posture id SET is a value
31
+ * list needed on BOTH sides of the driver/runtime boundary — here for
32
+ * `decomposeMode` and in the driver's `composeSpawn` back-compat shim — so it
33
+ * is single-sourced in the driver (its AIP-45 home) rather than copied, which
34
+ * for a value list WOULD silently drift. Only the daemon-domain canonical-
35
+ * posture VALUE mapping (`POSTURE_MODE_VALUES`) stays local.
36
+ */
37
+
38
+ /**
39
+ * Reasoning / compute budget label.
40
+ *
41
+ * SUPERSET ONLY — this flat union is the documented ceiling, NOT the valid set.
42
+ * The real accepted values are a function of (adapter × model), resolved at
43
+ * runtime (SPEC §3.9): the same label maps to a different compute budget across
44
+ * models, and `"max"` / `"ultracode"` are session-only and model-gated (opus
45
+ * offers `ultracode`, haiku does not —
46
+ * `adapters/claude-code/src/index.ts:310-321`). Consumers must resolve the
47
+ * offerable set per session/model, never treat this enum as authoritative.
48
+ */
49
+ type EffortLevel = "low" | "medium" | "high" | "xhigh" | "max" | "ultracode";
50
+ /**
51
+ * agentproto-canonical posture — a portable, normalized vocabulary for "what
52
+ * the agent may DO" (SPEC §3.1/§3.4a). A canonical posture resolves to a
53
+ * harness `SessionModeId` when the session's advertised `availableModes` has an
54
+ * equivalent (native, enforced, live via `setSessionMode`); otherwise it is
55
+ * applied as an injected system-prompt preamble (advisory, not a permission
56
+ * boundary — SPEC risk Rw).
57
+ */
58
+ type CanonicalPosture = "default" | "plan" | "accept-edits" | "bypass" | "read-only";
59
+ /**
60
+ * The posture axis: either an agentproto-canonical posture OR a raw harness
61
+ * mode id sourced directly from the harness's own ACP mode registry
62
+ * (`SessionModeState.availableModes` — SDK `types.gen.d.ts:4227`). Postures are
63
+ * NOT a manifest mode list going forward (SPEC §3.4a); the `{ harnessModeId }`
64
+ * form carries a native mode the canonical vocabulary doesn't name.
65
+ */
66
+ type Posture = CanonicalPosture | {
67
+ harnessModeId: string;
68
+ };
69
+ /**
70
+ * Endpoint / billing rail — model/route config, NOT a mode (SPEC §3.4a). A
71
+ * gateway is reached by resolving the model's `@route` against the catalog
72
+ * (`packages/model-catalog/src/route-identity/index.ts:1-46`) and applying its
73
+ * base_url + credential-scrub on the route apply-path; `access` (which profile
74
+ * is eligible) is downstream of THIS axis (SPEC §1c).
75
+ */
76
+ interface RouteSpec {
77
+ /** Preset id ("anthropic"/direct, "moonshot", "openrouter", "requesty",
78
+ * "deepseek") or a custom id paired with an explicit `baseUrl`. */
79
+ gateway: string;
80
+ /** Resolved base URL; carried only for a custom gateway the catalog can't
81
+ * resolve. The attached profile's credential is resolved separately (§1c),
82
+ * never inlined here. */
83
+ baseUrl?: string;
84
+ }
85
+ /**
86
+ * What enters context. `"lean"` drops bundled skills
87
+ * (`adapters/claude-code/src/index.ts:196-204`); `"full"` is the default. The
88
+ * `(string & {})` arm keeps a future adapter-declared context profile from
89
+ * being blocked while preserving literal autocompletion for the known values.
90
+ */
91
+ type ContextProfile = "full" | "lean" | (string & {});
92
+ /**
93
+ * How an attached auth profile authenticates — the narrow eligibility gate,
94
+ * a *facet* of a named profile (SPEC §1c/§3.1), NOT a session-level enum. A
95
+ * structural mirror of `@agentproto/auth`'s `AuthMethod`
96
+ * (`packages/auth/src/profile-types.ts:21`, #470): `"api-key"` ↔ `tokenKind
97
+ * "pat"`, `"oauth-bearer"` ↔ `tokenKind "oat"` (a subscription bearer). Kept
98
+ * here — rather than imported — because `packages/runtime` has no dependency
99
+ * on `@agentproto/auth` (see the boundary note above); only the descriptor's
100
+ * `accessProfile` echo (§3.7) needs to name it.
101
+ */
102
+ type AuthMethod = "oauth-bearer" | "api-key";
103
+ /**
104
+ * The complete per-session config surface, decomposed into orthogonal axes
105
+ * (SPEC §3.1). Every field optional; omission = "adapter default" for that
106
+ * axis. The decomposed axes are the canonical form — persistence and transport
107
+ * use these fields, never a recomposed legacy `mode` string (SPEC §3.8).
108
+ */
109
+ interface SessionConfig {
110
+ /** Route-identity ref: `[route:]vendor/product[:pin][@route]`
111
+ * (`packages/model-catalog/src/route-identity/index.ts:1-46`). */
112
+ model?: string;
113
+ effort?: EffortLevel;
114
+ /** Attach a NAMED auth profile by id (SPEC §1c). The profile record —
115
+ * `AuthProfile { id, endpoint, method, credentialRef, label? }` — lives in
116
+ * `@agentproto/auth` (`packages/auth/src/profile-types.ts:24`, #470), NOT on
117
+ * the session and NOT in `providers.json`. Omit ⇒ default profile. */
118
+ access?: {
119
+ profileRef?: string;
120
+ };
121
+ /** Endpoint / gateway rail; `access` is downstream of this (SPEC §1c). */
122
+ route?: RouteSpec;
123
+ /** What the agent may DO. */
124
+ posture?: Posture;
125
+ /** What enters context. */
126
+ contextProfile?: ContextProfile;
127
+ /** Windowed cost-budget cap (SPEC §1c). A RESTART-only axis: it is read at
128
+ * spawn time to auto-attach a governance policy that trips `policy:failed`
129
+ * when the session's (or its profile's) ROLLING windowed spend crosses the
130
+ * cap. DISTINCT from the scalar `maxCostUsd` session-kill — a `costBudget`
131
+ * never kills the session, it only trips a policy. The record lives in
132
+ * `@agentproto/auth` (`CostBudget { maxCostUsd, window, scope }`). Omit ⇒ no
133
+ * windowed budget. */
134
+ costBudget?: CostBudget;
135
+ /** Configurable context-continuity policy for this session — controls
136
+ * warning/compact/continue-fresh thresholds and checkpoint sections. */
137
+ contextContinuity?: ContextContinuityPolicy;
138
+ /** Adapter harness slug — the canonical name for the adapter that runs the
139
+ * session (e.g. 'claude-code', 'hermes'). This is the same value historically
140
+ * carried on the wire as `adapter` / `adapterSlug`; the `harness` field is the
141
+ * canonical descriptor identity and remains optional for back-compat. */
142
+ harness?: string;
143
+ }
144
+ /**
145
+ * Manifest-declared AIP-45 mode id + axis discriminant — the minimum
146
+ * `decomposeMode`/`composeMode` need from `AgentCliMode` (driver `types.ts`).
147
+ * Mirrors its `id`/`kind` fields structurally rather than importing the full
148
+ * `AgentCliMode` TYPE surface from `@agentproto/driver-agent-cli` — the same
149
+ * structural-mirror pattern as `DeclaredAdapterOption` (`spawn-defaults.ts:447`)
150
+ * and `DeclaredAdapterPreset` (`preset-tools.ts`). (The module does take a
151
+ * value-level import — `inferLegacyModeKind` — from that package; see the
152
+ * boundary note at the top for why a shared value list is single-sourced, not
153
+ * mirrored.)
154
+ *
155
+ * `kind` narrows to a single meaningful value going forward — `"context"` (the
156
+ * one axis with no ACP-protocol home); routes come from the catalog and
157
+ * postures from the harness's ACP registry (SPEC §3.4a). `"posture"`/`"route"`
158
+ * remain accepted so `decomposeMode` can still classify a LEGACY tagged
159
+ * manifest during migration.
160
+ */
161
+ interface DeclaredAdapterMode {
162
+ id: string;
163
+ kind?: "posture" | "route" | "context";
164
+ }
165
+ /**
166
+ * Map ONE legacy `mode` id (AIP-45 `modes[]`) onto its orthogonal axis
167
+ * (SPEC §3.5). Classification order: (1) the mode's own explicit `kind` tag;
168
+ * (2) inference over well-known ids (gateway ids ⇒ route, known posture ids ⇒
169
+ * posture); (3) a truly-unknown id defaults to `contextProfile` —
170
+ * least-privilege, since defaulting to `posture` or `route` could silently
171
+ * grant elevated permissions or reroute billing (SPEC risk R4).
172
+ *
173
+ * Always yields a `CanonicalPosture` for the posture axis, never a
174
+ * `{ harnessModeId }` — the shim speaks the portable vocabulary only; raw
175
+ * harness modes come from the ACP registry, not a legacy `mode` id.
176
+ */
177
+ declare function decomposeMode(modes: readonly DeclaredAdapterMode[], modeId: string): Partial<SessionConfig>;
178
+ /**
179
+ * The reverse of `decomposeMode` — picks the single legacy mode id whose
180
+ * decomposition matches `cfg`.
181
+ *
182
+ * LOSSY / display-and-back-compat ONLY (SPEC §3.8). A single legacy `mode`
183
+ * string cannot represent an orthogonal combination — `{ posture: "plan",
184
+ * route: { gateway: "moonshot" } }` has no single legacy id — so `composeMode`
185
+ * returns the FIRST declared mode whose axis matches and silently drops the
186
+ * rest. It is NEVER a storage or transport form: the driver applies each axis's
187
+ * env/argv patch directly, and anything that must persist/transmit config uses
188
+ * the decomposed axes. Returns undefined when no declared mode matches.
189
+ */
190
+ declare function composeMode(cfg: Partial<SessionConfig>, modes: readonly DeclaredAdapterMode[]): string | undefined;
191
+
192
+ export { type AuthMethod as A, type ContextProfile as C, type DeclaredAdapterMode as D, type EffortLevel as E, type Posture as P, type RouteSpec as R, type SessionConfig as S, type CanonicalPosture as a, composeMode as c, decomposeMode as d };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * MCP App resource: agentproto session story panel.
3
+ *
4
+ * Ported 1:1 from the validated mockup at docs/session-story-mockup.html —
5
+ * same CSS, same DOM structure/classes, same interaction model (anchored
6
+ * side panel, sticky collapsible chapter headers, Simple/Tech toggle,
7
+ * composer with local chapter-routing classification). Fake data is
8
+ * replaced with live data pulled through the MCP Apps postMessage bridge.
9
+ *
10
+ * The HTML must stay fully self-contained (CSP: inline CSS/JS only, no
11
+ * CDN, no external fonts) — see mcp-apps-adapter.ts and the other panels
12
+ * in this file family (sessions-panel.ts, agents-overview-app.ts) for the
13
+ * same constraint. Because of that, this file cannot `import` the pure
14
+ * `buildStory` module from session-story.ts — the folding/chaptering
15
+ * heuristics are ported to vanilla JS below (`buildStoryJs`), mirroring
16
+ * session-story.ts function-for-function so the two stay easy to diff.
17
+ *
18
+ * Protocol: MCP Apps ext spec 2026-01-26
19
+ * – Bridge: JSON-RPC 2.0 over window.parent.postMessage
20
+ * – Handshake: ui/initialize → host result → ui/notifications/initialized
21
+ * – Data: tools/call → session_list (status/picker) + agent_export
22
+ * (timeline, re-fetched on turn boundaries) + agent_prompt (composer)
23
+ */
24
+ declare const SESSION_STORY_PANEL_HTML: string;
25
+
26
+ export { SESSION_STORY_PANEL_HTML };