@rynx-ai/runtime 0.1.0 → 0.1.9

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 (53) hide show
  1. package/dist/claude/executor.d.ts +3 -5
  2. package/dist/claude/executor.js +3 -5
  3. package/dist/claude/native-bridge.d.ts +74 -17
  4. package/dist/claude/native-bridge.js +225 -30
  5. package/dist/claude/native-hook-main.js +291 -39
  6. package/dist/claude/native-hooks.d.ts +3 -2
  7. package/dist/claude/native-hooks.js +15 -6
  8. package/dist/claude/native-integration.d.ts +78 -5
  9. package/dist/claude/native-integration.js +417 -26
  10. package/dist/claude/settings.d.ts +8 -0
  11. package/dist/claude/settings.js +50 -0
  12. package/dist/claude/transcript.d.ts +2 -2
  13. package/dist/claude/transcript.js +3 -3
  14. package/dist/codex/rollout-synth.js +1 -1
  15. package/dist/codex-app-server/client.d.ts +26 -40
  16. package/dist/codex-app-server/client.js +1128 -99
  17. package/dist/codex-app-server/forwarder.d.ts +7 -7
  18. package/dist/codex-app-server/forwarder.js +11 -5
  19. package/dist/codex-app-server/mapping.d.ts +1 -1
  20. package/dist/codex-app-server/mapping.js +27 -2
  21. package/dist/codex-app-server/protocol.d.ts +238 -4
  22. package/dist/codex-app-server/transport.d.ts +20 -5
  23. package/dist/codex-app-server/transport.js +93 -40
  24. package/dist/codex-app-server/ws-channel.d.ts +3 -3
  25. package/dist/codex-app-server/ws-channel.js +23 -7
  26. package/dist/codex-child-env.js +33 -0
  27. package/dist/codex-home.d.ts +6 -6
  28. package/dist/codex-home.js +8 -9
  29. package/dist/codex-session-store.d.ts +2 -1
  30. package/dist/host.d.ts +34 -33
  31. package/dist/host.js +531 -91
  32. package/dist/index.d.ts +4 -3
  33. package/dist/index.js +1 -1
  34. package/dist/interactions.d.ts +61 -0
  35. package/dist/interactions.js +236 -0
  36. package/dist/models-catalog.d.ts +1 -1
  37. package/dist/models-catalog.js +1 -1
  38. package/dist/runner/child.d.ts +9 -1
  39. package/dist/runner/child.js +93 -15
  40. package/dist/runner/manager.d.ts +59 -10
  41. package/dist/runner/manager.js +385 -41
  42. package/dist/runner/protocol.d.ts +18 -7
  43. package/dist/runner-main.js +9 -6
  44. package/dist/runtime-status.js +1 -1
  45. package/dist/terminal/claude-tui.d.ts +8 -3
  46. package/dist/terminal/claude-tui.js +6 -2
  47. package/dist/terminal/codex-tui.d.ts +3 -3
  48. package/dist/terminal/codex-tui.js +1 -1
  49. package/dist/terminal/registry.d.ts +1 -1
  50. package/dist/terminal/registry.js +1 -1
  51. package/dist/terminal/tmux.d.ts +6 -6
  52. package/dist/terminal/tmux.js +10 -10
  53. package/package.json +3 -3
@@ -16,9 +16,25 @@
16
16
  * channel.
17
17
  */
18
18
  import { spawn as nodeSpawn } from "node:child_process";
19
- import { type AgentCapabilities, type AgentRuntimeId, type AgentSpec, type AppConfig, type CapabilityResult, type ModelListResponse, type SessionEvent, type ThreadGoal } from "@rynx-ai/core";
19
+ import { type AgentCapabilities, type AgentRuntimeId, type AgentSpec, type AppConfig, type CapabilityResult, type ModelListResponse, type ReasoningEffort, type SessionInteractionResolution, type SessionEvent, type ThreadGoal } from "@rynx-ai/core";
20
20
  import { type CodexSessionStore } from "../host.js";
21
- import { type InjectOutcome, type TerminalRole } from "./protocol.js";
21
+ import type { ResolveInteractionResult } from "../interactions.js";
22
+ import { type InjectOutcome, type TerminalOpenErrorCode, type TerminalRole } from "./protocol.js";
23
+ /** Runtime-local context attached to one Session runner process. The provider is
24
+ * intentionally generic: package-specific resources stay in the composition
25
+ * root that implements this port. */
26
+ export interface RunnerSessionContext {
27
+ /** Extra environment for the runner child. Validated and copied at spawn. */
28
+ readonly childEnv: Readonly<Record<string, string>>;
29
+ /** Rebind resources before a child-published Session rotation becomes visible. */
30
+ rotate(newSessionId: string): void;
31
+ /** Release the context. RunnerManager calls this exactly once. */
32
+ close(): void;
33
+ }
34
+ /** Optional synchronous factory for per-Session runner context. */
35
+ export interface RunnerSessionContextProvider {
36
+ open(sessionId: string): RunnerSessionContext;
37
+ }
22
38
  export interface RunnerManagerOptions {
23
39
  config: AppConfig;
24
40
  /** Shared session store (used by the backend-free status probe). */
@@ -29,12 +45,19 @@ export interface RunnerManagerOptions {
29
45
  idleTtlMs?: number;
30
46
  /** Background reap sweep interval (ms); `0` disables the timer (tests). */
31
47
  reapIntervalMs?: number;
48
+ /** Grace period between SIGTERM and SIGKILL during runner shutdown. */
49
+ shutdownGraceMs?: number;
50
+ /** Final bounded wait for child exit after SIGKILL. */
51
+ shutdownKillGraceMs?: number;
32
52
  /** Injected for tests. */
33
53
  spawn?: typeof nodeSpawn;
34
54
  now?: () => number;
35
55
  /** Extra env merged into every spawned runner child — e.g. the control-plane
36
56
  * URL + token so a claude-native PermissionRequest hook can POST back. */
37
57
  childEnv?: Record<string, string>;
58
+ /** Optional lifecycle context for Session runners. The shared `__cap__`
59
+ * runner never opens one. */
60
+ sessionContextProvider?: RunnerSessionContextProvider;
38
61
  }
39
62
  /** A session rotation reported by a runner child (claude `/clear`·`/fork`): the
40
63
  * new session `to` is now aliased to `from`'s runner; carries meta to carry over. */
@@ -77,6 +100,13 @@ export interface ParentTerminal {
77
100
  resize(cols: number, rows: number): void;
78
101
  close(): void;
79
102
  }
103
+ /** A typed attach failure so transport adapters can distinguish an expected
104
+ * absent pane from an infrastructure failure without matching error strings. */
105
+ export declare class TerminalOpenError extends Error {
106
+ readonly code: TerminalOpenErrorCode;
107
+ readonly name = "TerminalOpenError";
108
+ constructor(message: string, code: TerminalOpenErrorCode);
109
+ }
80
110
  export declare class RunnerManager implements AgentCapabilities {
81
111
  private readonly config;
82
112
  private readonly sessionStore;
@@ -84,16 +114,26 @@ export declare class RunnerManager implements AgentCapabilities {
84
114
  private readonly idleTtlMs;
85
115
  private readonly spawn;
86
116
  private readonly childEnv;
117
+ private readonly sessionContextProvider;
87
118
  private readonly now;
88
119
  private readonly defaultRuntime;
89
120
  private readonly handles;
121
+ /** Every spawned child that has not exited (or failed to spawn), including
122
+ * handles already removed from routing by stopRunner/idle reap. */
123
+ private readonly childHandles;
90
124
  private readonly reapTimer;
125
+ private readonly shutdownGraceMs;
126
+ private readonly shutdownKillGraceMs;
127
+ private stopping;
128
+ private stopPromise;
91
129
  /** Sink for mirrored {@link SessionEvent}s from every session's forwarder. */
92
130
  private mirrorListener;
93
131
  /** Sink for session rotations (claude `/clear`·`/fork`) — server records meta. */
94
132
  private rotateListener;
95
133
  /** Session keys with a live codex forwarder — never reaped while present. */
96
134
  private readonly liveSessionKeys;
135
+ /** Last live-start error per local session, surfaced by the control API. */
136
+ private readonly liveErrors;
97
137
  constructor(opts: RunnerManagerOptions);
98
138
  /**
99
139
  * Open a live terminal on the session's runner child (spawning it if needed).
@@ -103,6 +143,15 @@ export declare class RunnerManager implements AgentCapabilities {
103
143
  * bridge calls it directly.
104
144
  */
105
145
  openTerminal(localThreadId: string, opts: OpenTerminalOptions): ParentTerminal;
146
+ /**
147
+ * Attach to a Session runner that is already live. Unlike {@link openTerminal},
148
+ * this never creates a child, including when liveness changes between lookup
149
+ * and attach.
150
+ */
151
+ openLiveTerminal(localThreadId: string, opts: OpenTerminalOptions): ParentTerminal;
152
+ private openTerminalOnHandle;
153
+ /** Whether this process already owns a live runner for the Session. Read-only; never spawns. */
154
+ hasLiveSession(localThreadId: string): boolean;
106
155
  /**
107
156
  * Register the sink for mirrored {@link SessionEvent}s produced by every
108
157
  * session's persistent codex forwarder (web- AND TUI-initiated turns). The
@@ -123,11 +172,13 @@ export declare class RunnerManager implements AgentCapabilities {
123
172
  cols?: number;
124
173
  rows?: number;
125
174
  runtime?: AgentRuntimeId;
175
+ reasoningEffort?: ReasoningEffort;
126
176
  agentName?: string;
127
177
  agentSpec?: AgentSpec;
128
178
  }): Promise<boolean>;
179
+ lastLiveSessionError(localThreadId: string): string | undefined;
129
180
  /**
130
- * Inject a user turn into a session's live codex thread — omnigent's
181
+ * Inject a user turn into a session's live codex thread — reference implementation's
131
182
  * single-writer web send (`turn/start` / `turn/steer`); the forwarder mirrors
132
183
  * all output. Resolves true when the app-server accepted the turn, false when
133
184
  * the session has no live forwarder (caller falls back to the run path).
@@ -139,12 +190,8 @@ export declare class RunnerManager implements AgentCapabilities {
139
190
  * when the session has no live runner (nothing to interrupt).
140
191
  */
141
192
  interruptLiveSession(localThreadId: string): Promise<boolean>;
142
- /**
143
- * Deliver a user's interactive-approval decision to the session's runner
144
- * child (Phase D). Best-effort: no-op if the runner isn't live (the pending
145
- * approval would have died with it). The child routes it to its codex client.
146
- */
147
- resolveApproval(localThreadId: string, approvalId: string, decision: "acceptForSession" | "accept" | "decline" | "cancel"): void;
193
+ /** Resolve a native question/approval without ever spawning a new runner. */
194
+ resolveInteraction(localThreadId: string, interactionId: string, resolution: SessionInteractionResolution): Promise<ResolveInteractionResult>;
148
195
  listModels(runtime?: AgentRuntimeId): Promise<ModelListResponse | null>;
149
196
  getGoal(localThreadId: string): Promise<CapabilityResult<ThreadGoal | null>>;
150
197
  setGoal(localThreadId: string, objective: string): Promise<CapabilityResult>;
@@ -160,7 +207,7 @@ export declare class RunnerManager implements AgentCapabilities {
160
207
  }): Promise<import("../host.js").CodexRuntimeStatus>;
161
208
  /** Stop the runner bound to one session (if any), rejecting its in-flight work. */
162
209
  stopRunner(localThreadId: string): void;
163
- /** Kill every runner. Call on server shutdown. */
210
+ /** Stop every runner and join all child exits. Idempotent across concurrent calls. */
164
211
  stop(): Promise<void>;
165
212
  /** Forward a capability to a runner child. Session-less caps (listModels/status)
166
213
  * use the shared `CAP_KEY` child; per-thread caps pass the session's key so they
@@ -171,5 +218,7 @@ export declare class RunnerManager implements AgentCapabilities {
171
218
  private onChildMessage;
172
219
  /** Mark a handle dead and reject every pending run/cap with the exit reason. */
173
220
  private failHandle;
221
+ private terminateHandle;
174
222
  private reapIdle;
223
+ private openSessionContext;
175
224
  }