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

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 (56) 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 +61 -73
  6. package/dist/agent/session.js +163 -175
  7. package/dist/agent/workflow/tool.js +8 -21
  8. package/dist/capabilities/assembler.d.ts +6 -4
  9. package/dist/capabilities/assembler.js +10 -5
  10. package/dist/capabilities/background/index.js +33 -26
  11. package/dist/capabilities/capability-state.d.ts +5 -7
  12. package/dist/capabilities/capability-state.js +6 -4
  13. package/dist/capabilities/capability.d.ts +52 -40
  14. package/dist/capabilities/compaction/index.js +5 -4
  15. package/dist/capabilities/goal/index.d.ts +1 -0
  16. package/dist/capabilities/goal/index.js +13 -6
  17. package/dist/capabilities/index.d.ts +3 -3
  18. package/dist/capabilities/index.js +2 -2
  19. package/dist/capabilities/plan/index.js +12 -6
  20. package/dist/capabilities/skills/flow-provider.js +3 -3
  21. package/dist/capabilities/skills/index.d.ts +12 -0
  22. package/dist/capabilities/skills/index.js +38 -24
  23. package/dist/capabilities/skills/registry.d.ts +3 -4
  24. package/dist/capabilities/skills/registry.js +4 -7
  25. package/dist/capabilities/skills/service.js +1 -1
  26. package/dist/capabilities/skills/skill-tool.d.ts +2 -0
  27. package/dist/capabilities/skills/skill-tool.js +1 -1
  28. package/dist/capabilities/task/index.js +11 -5
  29. package/dist/capabilities/todo/index.js +12 -6
  30. package/dist/capabilities/tool-provider.d.ts +3 -3
  31. package/dist/capabilities/user-hooks/index.js +22 -16
  32. package/dist/capabilities/workflow/index.d.ts +4 -2
  33. package/dist/capabilities/workflow/index.js +14 -7
  34. package/dist/commands/index.js +6 -4
  35. package/dist/index.d.ts +2 -1
  36. package/dist/index.js +2 -1
  37. package/dist/internal.d.ts +2 -0
  38. package/dist/internal.js +2 -0
  39. package/dist/mcp/capability.js +22 -17
  40. package/dist/mcp/filter.d.ts +2 -2
  41. package/dist/mcp/index.d.ts +1 -1
  42. package/dist/mcp/index.js +1 -1
  43. package/dist/mcp/manager.d.ts +42 -1
  44. package/dist/mcp/manager.js +147 -11
  45. package/dist/plugins/index.js +10 -4
  46. package/dist/scope/index.d.ts +7 -0
  47. package/dist/scope/index.js +4 -0
  48. package/dist/scope/scope.d.ts +143 -0
  49. package/dist/scope/scope.js +406 -0
  50. package/dist/scope/token.d.ts +29 -0
  51. package/dist/scope/token.js +29 -0
  52. package/dist/scope/tokens.d.ts +98 -0
  53. package/dist/scope/tokens.js +63 -0
  54. package/dist/testing.d.ts +62 -0
  55. package/dist/testing.js +118 -0
  56. package/package.json +1 -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)
@@ -66,16 +51,6 @@ export interface SessionConfig {
66
51
  */
67
52
  readonly preloadedLog?: readonly AgentRecord[];
68
53
  }
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);
78
- }
79
54
  /** The current owner and root conversation shard for the next user prompt. */
80
55
  export interface ConversationHead {
81
56
  readonly agentKey: string;
@@ -129,7 +104,10 @@ export interface SessionPort {
129
104
  readonly reservedContextTokens: number;
130
105
  readonly revision: number;
131
106
  } | undefined;
132
- readonly workflow: WorkflowManager | undefined;
107
+ /** A resume journal for one workflow run, bound to this session's store (the workflow
108
+ * capability's manager, or the session's in-memory fallback) — all the kernel's `Workflow`
109
+ * tool needs; the manager itself stays behind `session.workflow`. */
110
+ newWorkflowJournal(runId: string, parentToolCallId?: string): WorkflowJournal;
133
111
  resolveSystemPromptContext(machine: Machine): Promise<SystemPromptContext>;
134
112
  recordContextBreakdown(breakdown: ContextBreakdown): void;
135
113
  flushEvents(): Promise<void>;
@@ -139,27 +117,28 @@ export interface SessionPort {
139
117
  registerFrameBus(address: string, bus: SteerBus): () => void;
140
118
  }
141
119
  /**
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.
120
+ * Service access on a session has two tiers, one rule each:
121
+ * - PROBE — `session.get(T.X)` returns `undefined` when that service is not registered
122
+ * (the capability is not open). Use it to feature-test.
123
+ * - REQUIRE — `session.require(T.X)` and the convenience wrappers (`createCronTask()`,
124
+ * `compact()`, `listSkills()`, …) assume the service and throw `ServiceUnavailableError`
125
+ * when it is missing.
147
126
  * The only exceptions are list views documented as degrading to empty when the capability
148
127
  * is off (`listWorkflows`, `listSubagents`, `listMcpServers`) — views over durable state
149
128
  * that stay meaningful on a session opened without the capability.
129
+ *
130
+ * The session OWNS its scope: `close()` closes it, disposing every service registered there
131
+ * (capability provisions first, in reverse order, then the infrastructure).
150
132
  */
151
133
  export declare class Session implements SessionPort {
152
134
  readonly id: string;
135
+ /** The session-tier scope: every session-lived object, registered by the opener or by `open`. */
136
+ readonly scope: Scope<"session">;
153
137
  readonly machine: Machine;
154
138
  readonly store?: SessionStore;
155
139
  readonly events: EventSink;
156
140
  private readonly eventPublisher;
157
141
  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
142
  readonly steer: SteerBus;
164
143
  readonly signal: AbortSignal;
165
144
  /** Upstream of `signal`. Fires only via `abort()`; a host signal aborts independently. */
@@ -167,9 +146,7 @@ export declare class Session implements SessionPort {
167
146
  readonly logger: Logger;
168
147
  private readonly tracing?;
169
148
  private readonly unsubscribeTracing?;
170
- private readonly injectedBackground?;
171
149
  private readonly allCapabilities;
172
- private readonly services;
173
150
  private readonly systemPromptContexts;
174
151
  private readonly liveContexts;
175
152
  /** Inboxes of frames currently running under this session, keyed by journal address. */
@@ -177,7 +154,7 @@ export declare class Session implements SessionPort {
177
154
  private activeConversationHead;
178
155
  private readonly fileLedgers;
179
156
  private modelOverride?;
180
- /** Caller-supplied one-shot log for open (see SessionConfig.preloadedLog); cleared after
157
+ /** Caller-supplied one-shot log for open (see SessionOpenOptions.preloadedLog); cleared after
181
158
  * openCapabilities so the array itself is not pinned for the session's lifetime. */
182
159
  private preloadedLog?;
183
160
  private thinkingOverride?;
@@ -187,12 +164,19 @@ export declare class Session implements SessionPort {
187
164
  private readonly pendingDiagnostics;
188
165
  private lastContextBreakdown?;
189
166
  private constructor();
190
- static open(cfg: SessionConfig): Promise<Session>;
167
+ /**
168
+ * Open a session on a session-tier scope. The opener registers what it decides (`T.Machine`,
169
+ * `T.Store`, `T.Events`, `T.Responder`, `T.PermissionOptions`, `T.HostSignal`, `T.SessionId`, …);
170
+ * `open` provides the defaults for whatever is missing, builds the session's own objects
171
+ * (signal, event publisher, log reader, controls), runs every capability's provisions in
172
+ * order, then builds the permission manager. From here on the session owns the scope.
173
+ */
174
+ static open(scope: Scope<"session">, opts?: SessionOpenOptions): Promise<Session>;
191
175
  private openCapabilities;
192
176
  /**
193
177
  * Construct the session-lived PermissionManager: capability policy slots are collected from
194
178
  * 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
179
+ * provision failed contributes nothing; a per-run `start()` failure does NOT retract its
196
180
  * policies — they are pure evaluators over session-lived state). Then runtime permission
197
181
  * state is folded back from the log — `permission.set_mode` (last wins) and approve-for-session
198
182
  * grants (`permission.record_approval` with scope "session").
@@ -201,17 +185,16 @@ export declare class Session implements SessionPort {
201
185
  /** The session-lived permission manager (policy chain + mode + approval memory). */
202
186
  get permission(): PermissionManager;
203
187
  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;
188
+ /** PROBE tier: the service, or undefined when nothing registered it (see the class doc). */
189
+ get<S>(tok: Token<S>): S | undefined;
190
+ /** REQUIRE tier: the service, or a `ServiceUnavailableError` naming what is missing. */
191
+ require<S>(tok: Token<S>): S;
192
+ /** The workflow manager: the capability's, or the in-memory fallback `open` provides. */
193
+ get workflow(): WorkflowManager;
194
+ newWorkflowJournal(runId: string, parentToolCallId?: string): WorkflowJournal;
195
+ get compaction(): import("../capabilities/compaction/index.ts").CompactionService | undefined;
196
+ /** The spawner the Agent/Workflow tools use: the background capability's manager, else the
197
+ * host-injected `T.BackgroundSpawner`. */
215
198
  get background(): BackgroundSpawner | undefined;
216
199
  listBackgroundTasks(options?: BackgroundTaskListOptions): Promise<readonly BackgroundTaskInfo[]>;
217
200
  /** Past BACKGROUND workflow runs (newest first), from the durable task store. A foreground
@@ -354,6 +337,11 @@ export declare class Session implements SessionPort {
354
337
  drainDiagnostics(): CapabilityDiagnostic[];
355
338
  withRunLock<T>(body: () => Promise<T>): Promise<T>;
356
339
  flushEvents(): Promise<void>;
340
+ /**
341
+ * Close the session: flush telemetry and the store, then close the scope — which disposes
342
+ * every capability provision in reverse order (each under a deadline) and finally the
343
+ * session's own infrastructure. Idempotent.
344
+ */
357
345
  close(): Promise<void>;
358
346
  /** Public URL for a port inside the machine, or undefined when the backend can't expose one. */
359
347
  resolveExposedPort(port: number): Promise<string | undefined>;