operon-agents-core 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
Files changed (85) hide show
  1. package/dist/agent/index.d.ts +2 -2
  2. package/dist/agent/index.js +1 -1
  3. package/dist/agent/runner.d.ts +21 -15
  4. package/dist/agent/runner.js +23 -26
  5. package/dist/agent/session.d.ts +64 -73
  6. package/dist/agent/session.js +173 -175
  7. package/dist/agent/workflow/prompt.js +1 -1
  8. package/dist/agent/workflow/tool.js +9 -22
  9. package/dist/capabilities/assembler.d.ts +6 -4
  10. package/dist/capabilities/assembler.js +10 -5
  11. package/dist/capabilities/background/index.js +33 -26
  12. package/dist/capabilities/background/manager.d.ts +10 -1
  13. package/dist/capabilities/background/manager.js +20 -2
  14. package/dist/capabilities/background/tools.js +32 -6
  15. package/dist/capabilities/capability-state.d.ts +5 -7
  16. package/dist/capabilities/capability-state.js +6 -4
  17. package/dist/capabilities/capability.d.ts +52 -40
  18. package/dist/capabilities/compaction/index.js +5 -4
  19. package/dist/capabilities/goal/index.d.ts +1 -0
  20. package/dist/capabilities/goal/index.js +13 -6
  21. package/dist/capabilities/index.d.ts +3 -3
  22. package/dist/capabilities/index.js +2 -2
  23. package/dist/capabilities/plan/index.js +12 -6
  24. package/dist/capabilities/skills/flow-provider.js +3 -3
  25. package/dist/capabilities/skills/index.d.ts +12 -0
  26. package/dist/capabilities/skills/index.js +38 -24
  27. package/dist/capabilities/skills/registry.d.ts +3 -4
  28. package/dist/capabilities/skills/registry.js +4 -7
  29. package/dist/capabilities/skills/service.js +1 -1
  30. package/dist/capabilities/skills/skill-tool.d.ts +2 -0
  31. package/dist/capabilities/skills/skill-tool.js +1 -1
  32. package/dist/capabilities/task/index.js +11 -5
  33. package/dist/capabilities/todo/index.js +12 -6
  34. package/dist/capabilities/tool-provider.d.ts +3 -3
  35. package/dist/capabilities/user-hooks/index.js +22 -16
  36. package/dist/capabilities/workflow/index.d.ts +4 -2
  37. package/dist/capabilities/workflow/index.js +14 -7
  38. package/dist/commands/index.js +6 -4
  39. package/dist/events/events.d.ts +12 -2
  40. package/dist/events/events.js +1 -0
  41. package/dist/events/projection.js +3 -0
  42. package/dist/index.d.ts +3 -1
  43. package/dist/index.js +3 -1
  44. package/dist/internal.d.ts +2 -0
  45. package/dist/internal.js +2 -0
  46. package/dist/loop/turn-step.js +13 -0
  47. package/dist/mcp/capability.js +22 -17
  48. package/dist/mcp/filter.d.ts +2 -2
  49. package/dist/mcp/index.d.ts +1 -1
  50. package/dist/mcp/index.js +1 -1
  51. package/dist/mcp/manager.d.ts +42 -1
  52. package/dist/mcp/manager.js +147 -11
  53. package/dist/plugins/index.js +10 -4
  54. package/dist/scope/index.d.ts +7 -0
  55. package/dist/scope/index.js +4 -0
  56. package/dist/scope/scope.d.ts +143 -0
  57. package/dist/scope/scope.js +406 -0
  58. package/dist/scope/token.d.ts +29 -0
  59. package/dist/scope/token.js +29 -0
  60. package/dist/scope/tokens.d.ts +114 -0
  61. package/dist/scope/tokens.js +65 -0
  62. package/dist/telemetry/appender.d.ts +43 -0
  63. package/dist/telemetry/appender.js +46 -0
  64. package/dist/telemetry/events.d.ts +142 -0
  65. package/dist/telemetry/events.js +141 -0
  66. package/dist/telemetry/index.d.ts +10 -0
  67. package/dist/telemetry/index.js +6 -0
  68. package/dist/telemetry/projection.d.ts +23 -0
  69. package/dist/telemetry/projection.js +185 -0
  70. package/dist/telemetry/redact.d.ts +20 -0
  71. package/dist/telemetry/redact.js +40 -0
  72. package/dist/telemetry/service.d.ts +49 -0
  73. package/dist/telemetry/service.js +137 -0
  74. package/dist/testing.d.ts +62 -0
  75. package/dist/testing.js +118 -0
  76. package/dist/tracing/bridge.d.ts +9 -1
  77. package/dist/tracing/bridge.js +281 -77
  78. package/dist/tracing/index.d.ts +2 -2
  79. package/dist/tracing/otel.d.ts +28 -1
  80. package/dist/tracing/otel.js +127 -17
  81. package/dist/tracing/processor.d.ts +22 -0
  82. package/dist/tracing/processor.js +2 -0
  83. package/dist/tracing/spans.d.ts +54 -0
  84. package/dist/tracing/spans.js +5 -0
  85. package/package.json +5 -1
@@ -8,8 +8,8 @@ export { composeLoopHooks } from "./compose-hooks.ts";
8
8
  /** Agent profile + session runtime → the params one request carries. Exported so embedders
9
9
  * that drive `runTurn` directly resolve precedence the same way the Runner does. */
10
10
  export { resolveModelParams } from "./run-support.ts";
11
- export { CapabilityMissingError, Session, newSessionId } from "./session.ts";
12
- export type { BackgroundTaskListOptions, ReadBackgroundTaskOutputDeltaOptions, ReadBackgroundTaskOutputOptions, ConversationHead, CreateGoalInput, GoalBudgetInput, GoalStatusInput, PlanModeOptions, SessionConfig, SessionPort, } from "./session.ts";
11
+ export { Session, newSessionId } from "./session.ts";
12
+ export type { BackgroundTaskListOptions, ReadBackgroundTaskOutputDeltaOptions, ReadBackgroundTaskOutputOptions, ConversationHead, CreateGoalInput, GoalBudgetInput, GoalStatusInput, PlanModeOptions, SessionOpenOptions, SessionPort, } from "./session.ts";
13
13
  export { newAgentId } from "./subagent.ts";
14
14
  export type { SubagentRecord, SubagentStatus, AgentSpawnDetails } from "./subagent.ts";
15
15
  export { RawAgentProfileSchema, resolveAgentProfiles, resolveProfileDirs, loadAgentProfiles, loadAgentProfilesFromSources, prepareSystemPromptContext, buildAgentFromProfile, profileSubagentProvider, } from "./profiles.ts";
@@ -5,7 +5,7 @@ export { composeLoopHooks } from "./compose-hooks.js";
5
5
  /** Agent profile + session runtime → the params one request carries. Exported so embedders
6
6
  * that drive `runTurn` directly resolve precedence the same way the Runner does. */
7
7
  export { resolveModelParams } from "./run-support.js";
8
- export { CapabilityMissingError, Session, newSessionId } from "./session.js";
8
+ export { Session, newSessionId } from "./session.js";
9
9
  export { newAgentId } from "./subagent.js";
10
10
  export { RawAgentProfileSchema, resolveAgentProfiles, resolveProfileDirs, loadAgentProfiles, loadAgentProfilesFromSources, prepareSystemPromptContext, buildAgentFromProfile, profileSubagentProvider, } from "./profiles.js";
11
11
  export { DEFAULT_AGENT_PROFILES, DEFAULT_AGENT_PROFILE_NAME, DEFAULT_SUBAGENT_NAMES } from "./profile-builtins.js";
@@ -1,37 +1,41 @@
1
1
  import type { ChatModel } from "../llm/define-model.ts";
2
2
  import type { AssistantMessage, Message, Usage } from "../protocol/index.ts";
3
3
  import { ConversationContext } from "../loop/context.ts";
4
- import type { Machine, MachineFactory } from "../tool/machine.ts";
4
+ import type { Machine } from "../tool/machine.ts";
5
5
  import type { BackgroundSpawner } from "../tool/background.ts";
6
- import { PermissionManager, type PermissionManagerOptions } from "../permission/manager.ts";
6
+ import { PermissionManager } from "../permission/manager.ts";
7
7
  import type { ApprovalResponse, Responder } from "../permission/types.ts";
8
8
  import type { Capability } from "../capabilities/capability.ts";
9
+ import { Scope } from "../scope/scope.ts";
9
10
  import { type AssembledCapabilities } from "../capabilities/assembler.ts";
10
- import { type EventPublicationMode, type EventSink, type RunHandle } from "../events/index.ts";
11
+ import { type EventSink, type RunHandle } from "../events/index.ts";
11
12
  import { type SessionStore } from "../store/index.ts";
12
13
  import type { PromptOrigin, SessionLock } from "../store/index.ts";
13
- import type { TracingProcessor } from "../tracing/index.ts";
14
14
  import { SteerBus } from "../loop/steer.ts";
15
15
  import { type InterruptAnswer, type InterruptionFrame, type InterruptionState, type PendingRunInterrupt } from "../loop/interruption.ts";
16
16
  import { Session, type SessionPort } from "./session.ts";
17
17
  import { Agent, type AgentRunContext } from "./agent.ts";
18
18
  import type { SubagentInfo, SubagentProvider } from "./profiles.ts";
19
19
  import { type GuardrailStage } from "./guardrail.ts";
20
+ /**
21
+ * Engine configuration — VALUES, not lifetimes. Everything with a lifetime (machine, store,
22
+ * events, responder, permission options, capabilities' services) lives in a `Scope`: the
23
+ * harness-tier scope the Runner is constructed on, and the session-tier scope the `session`
24
+ * hook fills for each session the Runner opens itself.
25
+ */
20
26
  export interface RunnerConfig<TContext = unknown> {
21
27
  readonly resolveModel?: (modelId: string) => ChatModel | Promise<ChatModel>;
22
- readonly machine?: Machine | MachineFactory;
23
- readonly store?: SessionStore;
24
- readonly events?: EventSink;
25
- readonly tracing?: TracingProcessor;
26
- readonly responder?: Responder;
27
- readonly permission?: PermissionManagerOptions;
28
- readonly capabilities?: readonly Capability[];
28
+ /**
29
+ * Called once per session the Runner opens on its own (no `RunOptions.session`): register
30
+ * this session's objects (`T.Store`, `T.Machine`, `T.PermissionOptions`, …) on `scope` and
31
+ * return its capabilities. A caller-supplied session is never passed through here.
32
+ */
33
+ readonly session?: (scope: Scope<"session">, ctx: {
34
+ readonly sessionId: string | undefined;
35
+ }) => readonly Capability[] | Promise<readonly Capability[]>;
29
36
  readonly maxTurns?: number;
30
37
  readonly maxStepsPerTurn?: number;
31
38
  readonly maxRetriesPerStep?: number;
32
- readonly steer?: SteerBus;
33
- readonly background?: BackgroundSpawner;
34
- readonly eventPublication?: EventPublicationMode;
35
39
  /**
36
40
  * Exclusive right to run a session, keyed by session id.
37
41
  *
@@ -204,9 +208,11 @@ export interface SubagentSpawner<TContext> {
204
208
  ctxFor(state: RunState<TContext>): AgentRunContext<TContext>;
205
209
  }
206
210
  export declare class Runner<TContext = unknown> {
211
+ /** The harness-tier scope every Runner-opened session hangs under. */
212
+ readonly scope: Scope<"harness" | "workspace">;
207
213
  private readonly config;
208
214
  private readonly engine;
209
- constructor(config?: RunnerConfig<TContext>);
215
+ constructor(scope: Scope<"harness" | "workspace">, config?: RunnerConfig<TContext>);
210
216
  run(agent: Agent<TContext>, input: AgentInput, opts?: RunOptions<TContext>): Promise<RunResult>;
211
217
  /**
212
218
  * Hold the session lease for the duration of `fn`, when a lock is configured.
@@ -3,6 +3,8 @@ import { runTurn } from "../loop/run-turn.js";
3
3
  import { isAbortError } from "../loop/errors.js";
4
4
  import { ConversationContext, replayContext } from "../loop/context.js";
5
5
  import { PermissionManager } from "../permission/manager.js";
6
+ import { Scope } from "../scope/scope.js";
7
+ import { T } from "../scope/tokens.js";
6
8
  import { assembleCapabilities } from "../capabilities/assembler.js";
7
9
  import { computeContextBreakdown } from "./context-report.js";
8
10
  import { IterableSink, } from "../events/index.js";
@@ -20,9 +22,14 @@ import { buildRunTools } from "./toolset.js";
20
22
  import { activeDeferredTools } from "../tool/search/activation.js";
21
23
  import { emitRunEvent, finalText, historyChangeEmitter, injectAtTurnBoundary, lastAssistant, mapTerminalStatus, resolveModelParams, runCtxFor, tryParseOutput, } from "./run-support.js";
22
24
  export class Runner {
25
+ /** The harness-tier scope every Runner-opened session hangs under. */
26
+ scope;
23
27
  config;
24
28
  engine;
25
- constructor(config = {}) {
29
+ constructor(scope, config = {}) {
30
+ if (scope.kind === "session")
31
+ throw new Error("Runner needs a harness or workspace scope, not a session scope");
32
+ this.scope = scope;
26
33
  this.config = config;
27
34
  this.engine = new Engine(config);
28
35
  }
@@ -173,24 +180,20 @@ export class Runner {
173
180
  }
174
181
  return { session: opts.session, owned: false };
175
182
  }
176
- const cfg = {
177
- machine: this.config.machine,
178
- store: this.config.store,
179
- events: eventsOverride ?? this.config.events,
180
- tracing: this.config.tracing,
181
- responder: this.config.responder,
182
- permission: this.config.permission,
183
- capabilities: this.config.capabilities,
184
- steer: this.config.steer,
185
- background: this.config.background,
186
- eventPublication: this.config.eventPublication,
187
- sessionId: opts?.sessionId,
188
- // Losing the lease cancels the run: a holder that can no longer renew has, by definition,
189
- // been superseded, and must stop before its writes race the node that took over. Only the
190
- // session this runner owns is wired up — a caller-supplied session keeps its own signal.
191
- signal: mergeSignals(opts?.signal, lease?.signal),
192
- };
193
- const session = await Session.open(cfg);
183
+ const scope = this.scope.child("session");
184
+ if (opts?.sessionId !== undefined)
185
+ scope.register(T.SessionId, opts.sessionId);
186
+ // Losing the lease cancels the run: a holder that can no longer renew has, by definition,
187
+ // been superseded, and must stop before its writes race the node that took over. Only the
188
+ // session this runner owns is wired up — a caller-supplied session keeps its own signal.
189
+ const signal = mergeSignals(opts?.signal, lease?.signal);
190
+ if (signal !== undefined)
191
+ scope.register(T.HostSignal, signal, { owned: false });
192
+ // A one-shot pull stream IS the session's event bus (Invariant 4); it wins over the hook's.
193
+ if (eventsOverride !== undefined)
194
+ scope.register(T.Events, eventsOverride, { owned: false });
195
+ const capabilities = (await this.config.session?.(scope, { sessionId: opts?.sessionId })) ?? [];
196
+ const session = await Session.open(scope, { capabilities });
194
197
  return { session, owned: true };
195
198
  }
196
199
  /** Resolve the durable conversation owner by following committed handoffs from `main`. */
@@ -430,15 +433,9 @@ export class Runner {
430
433
  const upstream = opts?.signal ?? session.signal;
431
434
  const signal = AbortSignal.any([upstream, runController.signal]);
432
435
  const ctx = {
436
+ scope: session.scope,
433
437
  sessionId: session.id,
434
- machine: session.machine,
435
- store: session.store,
436
- events: session.events,
437
438
  signal,
438
- steer: session.steer,
439
- responder: session.responder,
440
- background: session.background,
441
- logger: session.logger,
442
439
  // Same session controls, except `abort` is scoped to this run rather than the session.
443
440
  controls: {
444
441
  ...session.controls(),
@@ -1,29 +1,31 @@
1
- import type { Machine, MachineFactory } from "../tool/machine.ts";
1
+ import type { Machine } from "../tool/machine.ts";
2
2
  import { FileFreshnessLedger } from "../tool/file-freshness.ts";
3
3
  import type { ChatModel } from "../llm/define-model.ts";
4
4
  import type { ThinkingLevel } from "../llm/model.ts";
5
5
  import type { PermissionMode, Responder } from "../permission/types.ts";
6
- import { PermissionManager, type PermissionManagerOptions } from "../permission/manager.ts";
6
+ import { PermissionManager } from "../permission/manager.ts";
7
7
  import type { BackgroundSpawner } from "../tool/background.ts";
8
- import type { BackgroundManager, BackgroundTaskInfo, BackgroundTaskOutputDelta, BackgroundTaskOutputSnapshot } from "../capabilities/background/index.ts";
9
- import type { GoalSnapshot, GoalStore } from "../capabilities/goal/index.ts";
10
- import type { WorkflowManager } from "../capabilities/workflow/index.ts";
8
+ import type { BackgroundTaskInfo, BackgroundTaskOutputDelta, BackgroundTaskOutputSnapshot } from "../capabilities/background/index.ts";
9
+ import type { GoalSnapshot } from "../capabilities/goal/index.ts";
10
+ import { WorkflowManager } from "./workflow/manager.ts";
11
+ import type { WorkflowJournal } from "./workflow/journal.ts";
11
12
  import type { WorkflowSnapshot } from "./workflow/snapshot.ts";
12
13
  import type { ContextBreakdown } from "./context-report.ts";
13
- import type { PlanData, PlanMode } from "../capabilities/plan/index.ts";
14
- import type { CompactRequestOptions, CompactionService, PendingCompaction } from "../capabilities/compaction/index.ts";
15
- import type { ActivateSkillRequest, SkillActivationResult, SkillSummary, SkillsService } from "../capabilities/skills/index.ts";
16
- import type { PluginInfo, PluginManager, PluginSummary, ReloadSummary } from "../plugins/index.ts";
17
- import { type EventPublicationMode, type EventSink } from "../events/index.ts";
14
+ import type { PlanData } from "../capabilities/plan/index.ts";
15
+ import type { CompactRequestOptions, PendingCompaction } from "../capabilities/compaction/index.ts";
16
+ import type { ActivateSkillRequest, SkillActivationResult, SkillSummary } from "../capabilities/skills/index.ts";
17
+ import type { PluginInfo, PluginSummary, ReloadSummary } from "../plugins/index.ts";
18
+ import { type EventSink } from "../events/index.ts";
18
19
  import { type Logger } from "../logging/index.ts";
19
20
  import { type AgentRecord, type SessionStore } from "../store/index.ts";
20
- import { type TracingProcessor } from "../tracing/index.ts";
21
21
  import { ConversationContext } from "../loop/context.ts";
22
- import type { McpServersHandle, McpServerView, MCPTool } from "../mcp/index.ts";
22
+ import type { McpServerView, MCPTool } from "../mcp/index.ts";
23
23
  import { SteerBus, type SteerContent, type SteerOrigin } from "../loop/steer.ts";
24
24
  import type { Capability, CapabilityDiagnostic, SessionControls } from "../capabilities/capability.ts";
25
25
  import { type SubagentRecord } from "./subagent.ts";
26
26
  import { type SystemPromptContext } from "./instruction-context.ts";
27
+ import { Scope } from "../scope/scope.ts";
28
+ import type { Token } from "../scope/token.ts";
27
29
  /** Test-only (exported via `operon-agents-core/internal`): shrink the close deadlines
28
30
  * so hang-isolation tests don't wait wall-clock seconds. */
29
31
  export declare function setSessionCloseTimeoutsForTest(ms: {
@@ -31,31 +33,14 @@ export declare function setSessionCloseTimeoutsForTest(ms: {
31
33
  storeFlush?: number;
32
34
  }): void;
33
35
  export declare function newSessionId(): string;
34
- export interface SessionConfig {
35
- /**
36
- * The machine this session operates. Pass a {@link Machine} directly, or a
37
- * {@link MachineFactory} when it can only be built once the session id is known.
38
- * Omitted → a {@link NullMachine}: a stateless session with no filesystem, where any
39
- * file tool that slips through fails loudly instead of touching the host disk.
40
- *
41
- * Either way the session only OPERATES the machine — disposal stays with whoever
42
- * created it. See {@link MachineFactory}.
43
- */
44
- readonly machine?: Machine | MachineFactory;
45
- readonly store?: SessionStore;
46
- readonly events?: EventSink;
47
- /** `immediate` is optimized for an in-process UI. `committed` makes one ordered stream in
48
- * which record-backed events are emitted only after durable append succeeds. */
49
- readonly eventPublication?: EventPublicationMode;
50
- readonly tracing?: TracingProcessor;
51
- readonly responder?: Responder;
52
- readonly permission?: PermissionManagerOptions;
36
+ /**
37
+ * What `Session.open` takes besides the scope. Everything with a lifetime — machine, store,
38
+ * events, steer, responder, logger, permission options — is READ FROM THE SCOPE, registered
39
+ * there by whoever opened it (the harness, a runner, a test). `open` only fills the gaps with
40
+ * defaults (`provide`), never overrides what the creator registered.
41
+ */
42
+ export interface SessionOpenOptions {
53
43
  readonly capabilities?: readonly Capability[];
54
- readonly steer?: SteerBus;
55
- readonly background?: BackgroundSpawner;
56
- readonly sessionId?: string;
57
- readonly signal?: AbortSignal;
58
- readonly logger?: Logger;
59
44
  /**
60
45
  * The session's full append log, pre-read by the caller. `open` then skips its own
61
46
  * `readLog` and every open-time consumer (log-fold capabilities, context pre-build)
@@ -65,16 +50,8 @@ export interface SessionConfig {
65
50
  * Must be the complete log (all addresses, append order) as `readRecords()` returns it.
66
51
  */
67
52
  readonly preloadedLog?: readonly AgentRecord[];
68
- }
69
- /**
70
- * Thrown by `Session`'s capability-backed convenience methods when the capability they
71
- * wrap is not open on this session. Detect with `instanceof`; `capability` names the
72
- * missing one. The probe tier never throws — the getters (`session.cron`, `.goal`, …)
73
- * return `undefined` instead.
74
- */
75
- export declare class CapabilityMissingError extends Error {
76
- readonly capability: string;
77
- constructor(capability: string);
53
+ /** Reopened from a store (vs created fresh). Only telemetry cares; the stream cannot tell. */
54
+ readonly resumed?: boolean;
78
55
  }
79
56
  /** The current owner and root conversation shard for the next user prompt. */
80
57
  export interface ConversationHead {
@@ -129,7 +106,10 @@ export interface SessionPort {
129
106
  readonly reservedContextTokens: number;
130
107
  readonly revision: number;
131
108
  } | undefined;
132
- readonly workflow: WorkflowManager | undefined;
109
+ /** A resume journal for one workflow run, bound to this session's store (the workflow
110
+ * capability's manager, or the session's in-memory fallback) — all the kernel's `Workflow`
111
+ * tool needs; the manager itself stays behind `session.workflow`. */
112
+ newWorkflowJournal(runId: string, parentToolCallId?: string): WorkflowJournal;
133
113
  resolveSystemPromptContext(machine: Machine): Promise<SystemPromptContext>;
134
114
  recordContextBreakdown(breakdown: ContextBreakdown): void;
135
115
  flushEvents(): Promise<void>;
@@ -139,27 +119,28 @@ export interface SessionPort {
139
119
  registerFrameBus(address: string, bus: SteerBus): () => void;
140
120
  }
141
121
  /**
142
- * Capability access on a session has two tiers, one rule each:
143
- * - PROBE — the service getters (`session.cron`, `.goal`, `.plan`, `.backgroundManager`,
144
- * `.mcp`, …) return `undefined` when that capability is not open. Use these to feature-test.
145
- * - REQUIRE — the convenience wrappers (`createCronTask()`, `compact()`, `listSkills()`, …)
146
- * assume the capability and throw {@link CapabilityMissingError} when it is missing.
122
+ * Service access on a session has two tiers, one rule each:
123
+ * - PROBE — `session.get(T.X)` returns `undefined` when that service is not registered
124
+ * (the capability is not open). Use it to feature-test.
125
+ * - REQUIRE — `session.require(T.X)` and the convenience wrappers (`createCronTask()`,
126
+ * `compact()`, `listSkills()`, …) assume the service and throw `ServiceUnavailableError`
127
+ * when it is missing.
147
128
  * The only exceptions are list views documented as degrading to empty when the capability
148
129
  * is off (`listWorkflows`, `listSubagents`, `listMcpServers`) — views over durable state
149
130
  * that stay meaningful on a session opened without the capability.
131
+ *
132
+ * The session OWNS its scope: `close()` closes it, disposing every service registered there
133
+ * (capability provisions first, in reverse order, then the infrastructure).
150
134
  */
151
135
  export declare class Session implements SessionPort {
152
136
  readonly id: string;
137
+ /** The session-tier scope: every session-lived object, registered by the opener or by `open`. */
138
+ readonly scope: Scope<"session">;
153
139
  readonly machine: Machine;
154
140
  readonly store?: SessionStore;
155
141
  readonly events: EventSink;
156
142
  private readonly eventPublisher;
157
143
  readonly responder?: Responder;
158
- private readonly permissionOptions?;
159
- /** Session-lived permission manager: one policy chain + approval memory +
160
- * mode for the whole session. Constructed in `openCapabilities` (needs capability policy
161
- * slots and the replayed log); runs reference it instead of building their own. */
162
- private _permission;
163
144
  readonly steer: SteerBus;
164
145
  readonly signal: AbortSignal;
165
146
  /** Upstream of `signal`. Fires only via `abort()`; a host signal aborts independently. */
@@ -167,9 +148,8 @@ export declare class Session implements SessionPort {
167
148
  readonly logger: Logger;
168
149
  private readonly tracing?;
169
150
  private readonly unsubscribeTracing?;
170
- private readonly injectedBackground?;
151
+ private readonly unsubscribeTelemetry?;
171
152
  private readonly allCapabilities;
172
- private readonly services;
173
153
  private readonly systemPromptContexts;
174
154
  private readonly liveContexts;
175
155
  /** Inboxes of frames currently running under this session, keyed by journal address. */
@@ -177,7 +157,7 @@ export declare class Session implements SessionPort {
177
157
  private activeConversationHead;
178
158
  private readonly fileLedgers;
179
159
  private modelOverride?;
180
- /** Caller-supplied one-shot log for open (see SessionConfig.preloadedLog); cleared after
160
+ /** Caller-supplied one-shot log for open (see SessionOpenOptions.preloadedLog); cleared after
181
161
  * openCapabilities so the array itself is not pinned for the session's lifetime. */
182
162
  private preloadedLog?;
183
163
  private thinkingOverride?;
@@ -187,12 +167,19 @@ export declare class Session implements SessionPort {
187
167
  private readonly pendingDiagnostics;
188
168
  private lastContextBreakdown?;
189
169
  private constructor();
190
- static open(cfg: SessionConfig): Promise<Session>;
170
+ /**
171
+ * Open a session on a session-tier scope. The opener registers what it decides (`T.Machine`,
172
+ * `T.Store`, `T.Events`, `T.Responder`, `T.PermissionOptions`, `T.HostSignal`, `T.SessionId`, …);
173
+ * `open` provides the defaults for whatever is missing, builds the session's own objects
174
+ * (signal, event publisher, log reader, controls), runs every capability's provisions in
175
+ * order, then builds the permission manager. From here on the session owns the scope.
176
+ */
177
+ static open(scope: Scope<"session">, opts?: SessionOpenOptions): Promise<Session>;
191
178
  private openCapabilities;
192
179
  /**
193
180
  * Construct the session-lived PermissionManager: capability policy slots are collected from
194
181
  * the opened capabilities' static `policies` (session-tier fault isolation: a capability whose
195
- * `openSession` failed contributes nothing; a per-run `start()` failure does NOT retract its
182
+ * provision failed contributes nothing; a per-run `start()` failure does NOT retract its
196
183
  * policies — they are pure evaluators over session-lived state). Then runtime permission
197
184
  * state is folded back from the log — `permission.set_mode` (last wins) and approve-for-session
198
185
  * grants (`permission.record_approval` with scope "session").
@@ -201,17 +188,16 @@ export declare class Session implements SessionPort {
201
188
  /** The session-lived permission manager (policy chain + mode + approval memory). */
202
189
  get permission(): PermissionManager;
203
190
  get capabilities(): readonly Capability[];
204
- service<T = unknown>(name: string): T | undefined;
205
- /** The REQUIRE tier (see the class doc): unwrap a probed service or throw the typed error. */
206
- private requireCapability;
207
- get goal(): GoalStore | undefined;
208
- get workflow(): WorkflowManager | undefined;
209
- get skills(): SkillsService | undefined;
210
- get plugins(): PluginManager | undefined;
211
- get backgroundManager(): BackgroundManager | undefined;
212
- get plan(): PlanMode | undefined;
213
- get compaction(): CompactionService | undefined;
214
- get mcp(): McpServersHandle | undefined;
191
+ /** PROBE tier: the service, or undefined when nothing registered it (see the class doc). */
192
+ get<S>(tok: Token<S>): S | undefined;
193
+ /** REQUIRE tier: the service, or a `ServiceUnavailableError` naming what is missing. */
194
+ require<S>(tok: Token<S>): S;
195
+ /** The workflow manager: the capability's, or the in-memory fallback `open` provides. */
196
+ get workflow(): WorkflowManager;
197
+ newWorkflowJournal(runId: string, parentToolCallId?: string): WorkflowJournal;
198
+ get compaction(): import("../capabilities/compaction/index.ts").CompactionService | undefined;
199
+ /** The spawner the Agent/Workflow tools use: the background capability's manager, else the
200
+ * host-injected `T.BackgroundSpawner`. */
215
201
  get background(): BackgroundSpawner | undefined;
216
202
  listBackgroundTasks(options?: BackgroundTaskListOptions): Promise<readonly BackgroundTaskInfo[]>;
217
203
  /** Past BACKGROUND workflow runs (newest first), from the durable task store. A foreground
@@ -354,6 +340,11 @@ export declare class Session implements SessionPort {
354
340
  drainDiagnostics(): CapabilityDiagnostic[];
355
341
  withRunLock<T>(body: () => Promise<T>): Promise<T>;
356
342
  flushEvents(): Promise<void>;
343
+ /**
344
+ * Close the session: flush telemetry and the store, then close the scope — which disposes
345
+ * every capability provision in reverse order (each under a deadline) and finally the
346
+ * session's own infrastructure. Idempotent.
347
+ */
357
348
  close(): Promise<void>;
358
349
  /** Public URL for a port inside the machine, or undefined when the backend can't expose one. */
359
350
  resolveExposedPort(port: number): Promise<string | undefined>;