@enderfga/claw-orchestrator 3.0.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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +218 -0
  3. package/assets/banner.jpg +0 -0
  4. package/configs/council-reviewer-prompt.md +82 -0
  5. package/configs/council-system-prompt.md +141 -0
  6. package/dist/bin/cli.d.ts +13 -0
  7. package/dist/bin/cli.js +460 -0
  8. package/dist/bin/cli.js.map +1 -0
  9. package/dist/src/base-oneshot-session.d.ts +87 -0
  10. package/dist/src/base-oneshot-session.js +228 -0
  11. package/dist/src/base-oneshot-session.js.map +1 -0
  12. package/dist/src/circuit-breaker.d.ts +21 -0
  13. package/dist/src/circuit-breaker.js +49 -0
  14. package/dist/src/circuit-breaker.js.map +1 -0
  15. package/dist/src/consensus.d.ts +20 -0
  16. package/dist/src/consensus.js +52 -0
  17. package/dist/src/consensus.js.map +1 -0
  18. package/dist/src/constants.d.ts +129 -0
  19. package/dist/src/constants.js +138 -0
  20. package/dist/src/constants.js.map +1 -0
  21. package/dist/src/council.d.ts +67 -0
  22. package/dist/src/council.js +914 -0
  23. package/dist/src/council.js.map +1 -0
  24. package/dist/src/embedded-server.d.ts +25 -0
  25. package/dist/src/embedded-server.js +360 -0
  26. package/dist/src/embedded-server.js.map +1 -0
  27. package/dist/src/inbox-manager.d.ts +38 -0
  28. package/dist/src/inbox-manager.js +111 -0
  29. package/dist/src/inbox-manager.js.map +1 -0
  30. package/dist/src/index.d.ts +63 -0
  31. package/dist/src/index.js +973 -0
  32. package/dist/src/index.js.map +1 -0
  33. package/dist/src/logger.d.ts +16 -0
  34. package/dist/src/logger.js +44 -0
  35. package/dist/src/logger.js.map +1 -0
  36. package/dist/src/models.d.ts +69 -0
  37. package/dist/src/models.js +299 -0
  38. package/dist/src/models.js.map +1 -0
  39. package/dist/src/openai-compat.d.ts +224 -0
  40. package/dist/src/openai-compat.js +756 -0
  41. package/dist/src/openai-compat.js.map +1 -0
  42. package/dist/src/persistent-codex-app-session.d.ts +108 -0
  43. package/dist/src/persistent-codex-app-session.js +465 -0
  44. package/dist/src/persistent-codex-app-session.js.map +1 -0
  45. package/dist/src/persistent-codex-session.d.ts +37 -0
  46. package/dist/src/persistent-codex-session.js +208 -0
  47. package/dist/src/persistent-codex-session.js.map +1 -0
  48. package/dist/src/persistent-cursor-session.d.ts +21 -0
  49. package/dist/src/persistent-cursor-session.js +241 -0
  50. package/dist/src/persistent-cursor-session.js.map +1 -0
  51. package/dist/src/persistent-custom-session.d.ts +78 -0
  52. package/dist/src/persistent-custom-session.js +938 -0
  53. package/dist/src/persistent-custom-session.js.map +1 -0
  54. package/dist/src/persistent-gemini-session.d.ts +21 -0
  55. package/dist/src/persistent-gemini-session.js +216 -0
  56. package/dist/src/persistent-gemini-session.js.map +1 -0
  57. package/dist/src/persistent-session.d.ts +80 -0
  58. package/dist/src/persistent-session.js +745 -0
  59. package/dist/src/persistent-session.js.map +1 -0
  60. package/dist/src/proxy/anthropic-adapter.d.ts +136 -0
  61. package/dist/src/proxy/anthropic-adapter.js +392 -0
  62. package/dist/src/proxy/anthropic-adapter.js.map +1 -0
  63. package/dist/src/proxy/handler.d.ts +39 -0
  64. package/dist/src/proxy/handler.js +365 -0
  65. package/dist/src/proxy/handler.js.map +1 -0
  66. package/dist/src/proxy/schema-cleaner.d.ts +11 -0
  67. package/dist/src/proxy/schema-cleaner.js +34 -0
  68. package/dist/src/proxy/schema-cleaner.js.map +1 -0
  69. package/dist/src/proxy/thought-cache.d.ts +19 -0
  70. package/dist/src/proxy/thought-cache.js +53 -0
  71. package/dist/src/proxy/thought-cache.js.map +1 -0
  72. package/dist/src/session-manager.d.ts +317 -0
  73. package/dist/src/session-manager.js +1528 -0
  74. package/dist/src/session-manager.js.map +1 -0
  75. package/dist/src/types.d.ts +513 -0
  76. package/dist/src/types.js +8 -0
  77. package/dist/src/types.js.map +1 -0
  78. package/dist/src/validation.d.ts +31 -0
  79. package/dist/src/validation.js +104 -0
  80. package/dist/src/validation.js.map +1 -0
  81. package/openclaw.plugin.json +122 -0
  82. package/package.json +84 -0
  83. package/skills/SKILL.md +184 -0
  84. package/skills/references/claude-cli-tracking.md +25 -0
  85. package/skills/references/cli.md +187 -0
  86. package/skills/references/council.md +210 -0
  87. package/skills/references/getting-started.md +133 -0
  88. package/skills/references/inbox.md +81 -0
  89. package/skills/references/multi-engine.md +382 -0
  90. package/skills/references/openai-compat.md +203 -0
  91. package/skills/references/sessions.md +191 -0
  92. package/skills/references/tools.md +418 -0
  93. package/skills/references/ultra.md +126 -0
@@ -0,0 +1,317 @@
1
+ /**
2
+ * SessionManager — manages multiple PersistentClaudeSession instances
3
+ *
4
+ * Replaces the Express server layer. Pure class with no HTTP dependency.
5
+ * Can be used by Plugin tools, CLI, or any other consumer.
6
+ */
7
+ interface PersistedSession {
8
+ name: string;
9
+ claudeSessionId: string;
10
+ cwd: string;
11
+ model?: string;
12
+ engine?: EngineType;
13
+ originalCreated: string;
14
+ lastResumed: string;
15
+ lastActivity: number;
16
+ }
17
+ import { type Logger } from './logger.js';
18
+ import { type SessionConfig, type SessionInfo, type SendResult, type PluginConfig, type EffortLevel, type EngineType, type AgentInfo, type SkillInfo, type RuleInfo, type StreamEvent, type ISession, type CouncilConfig, type CouncilSession, type CouncilReviewResult, type CouncilAcceptResult, type CouncilRejectResult, type InboxMessage, type UltraplanResult, type UltrareviewResult } from './types.js';
19
+ interface SendOptions {
20
+ effort?: EffortLevel;
21
+ plan?: boolean;
22
+ autoResume?: boolean;
23
+ timeout?: number;
24
+ onEvent?: (event: StreamEvent) => void;
25
+ onChunk?: (chunk: string) => void;
26
+ }
27
+ export declare class SessionManager {
28
+ private sessions;
29
+ private _pendingSessions;
30
+ private cleanupTimer;
31
+ private pluginConfig;
32
+ private persistedSessions;
33
+ private _debouncedSave;
34
+ private _proxyServer;
35
+ private _proxyPort;
36
+ private _activePids;
37
+ private _circuitBreaker;
38
+ private _inbox;
39
+ private logger;
40
+ constructor(config?: Partial<PluginConfig>, logger?: Logger);
41
+ startSession(config: Partial<SessionConfig> & {
42
+ name?: string;
43
+ }): Promise<SessionInfo>;
44
+ private _doStartSession;
45
+ sendMessage(name: string, message: string, options?: SendOptions): Promise<SendResult>;
46
+ stopSession(name: string): Promise<void>;
47
+ listSessions(): SessionInfo[];
48
+ listPersistedSessions(): PersistedSession[];
49
+ getStatus(name: string): SessionInfo & {
50
+ stats: ReturnType<ISession['getStats']>;
51
+ };
52
+ grepSession(name: string, pattern: string, limit?: number): Promise<Array<{
53
+ time: string;
54
+ type: string;
55
+ content: string;
56
+ }>>;
57
+ compactSession(name: string, summary?: string): Promise<void>;
58
+ setEffort(name: string, level: EffortLevel): void;
59
+ /**
60
+ * Switch model for a session.
61
+ * Updates in-memory config only (takes effect on next restart/resume).
62
+ * For immediate effect, call restartWithConfig() explicitly.
63
+ */
64
+ setModel(name: string, model: string): void;
65
+ /**
66
+ * Switch model immediately by restarting the session with --resume.
67
+ * Conversation history is preserved via the claude session ID.
68
+ *
69
+ * Guards:
70
+ * - Rejects if session is currently processing a message (busy guard)
71
+ * - Validates model string against known aliases before restarting
72
+ * - Rolls back to old session if startSession fails
73
+ */
74
+ switchModel(name: string, model: string): Promise<SessionInfo>;
75
+ /**
76
+ * Update allowedTools or disallowedTools at runtime.
77
+ *
78
+ * The claude CLI does not support changing tool lists while running, so
79
+ * the only way to apply new constraints is to restart the process with
80
+ * the updated flags and --resume to replay conversation history.
81
+ *
82
+ * Guards:
83
+ * - Rejects if session is busy
84
+ * - Rolls back to old session if startSession fails
85
+ * - merge:true adds tools; removeTools removes specific tools from the list
86
+ */
87
+ updateTools(name: string, opts: {
88
+ allowedTools?: string[];
89
+ disallowedTools?: string[];
90
+ removeTools?: string[];
91
+ merge?: boolean;
92
+ }): Promise<SessionInfo>;
93
+ getCost(name: string): import("./types.js").CostBreakdown;
94
+ listAgents(cwd?: string): AgentInfo[];
95
+ createAgent(name: string, cwd?: string, description?: string, prompt?: string): string;
96
+ listSkills(cwd?: string): SkillInfo[];
97
+ createSkill(name: string, cwd?: string, opts?: {
98
+ description?: string;
99
+ prompt?: string;
100
+ trigger?: string;
101
+ }): string;
102
+ listRules(cwd?: string): RuleInfo[];
103
+ createRule(name: string, cwd?: string, opts?: {
104
+ description?: string;
105
+ content?: string;
106
+ paths?: string;
107
+ condition?: string;
108
+ }): string;
109
+ teamList(name: string): Promise<string>;
110
+ teamSend(name: string, teammate: string, message: string): Promise<SendResult>;
111
+ /**
112
+ * Returns an overview of all active sessions — analogous to a dashboard.
113
+ * Unlike claude_session_status (single session), this gives the aggregate
114
+ * view: how many sessions are running, which are busy, total uptime, etc.
115
+ */
116
+ health(): {
117
+ ok: boolean;
118
+ version: string;
119
+ sessions: number;
120
+ sessionNames: string[];
121
+ uptime: number;
122
+ details: Array<{
123
+ name: string;
124
+ ready: boolean;
125
+ busy: boolean;
126
+ paused: boolean;
127
+ turns: number;
128
+ costUsd: number;
129
+ contextPercent: number;
130
+ lastActivity: string | null;
131
+ }>;
132
+ circuitBreakers: Record<string, {
133
+ failures: number;
134
+ backoffUntil: string | null;
135
+ }>;
136
+ };
137
+ /** Return plugin version from package.json */
138
+ getVersion(): string;
139
+ /**
140
+ * Gracefully shut down the session manager.
141
+ *
142
+ * 1. Cancels the periodic TTL cleanup timer
143
+ * 2. Stops all ultrareview polling intervals
144
+ * 3. Sends SIGTERM to all active session child processes
145
+ * 4. Persists final session registry to disk
146
+ *
147
+ * After shutdown(), no new sessions can be started. Idempotent.
148
+ */
149
+ shutdown(): Promise<void>;
150
+ /**
151
+ * Send a `/goal <args>` slash command to a `codex-app` session. Used by
152
+ * the `codex_goal_*` tools. The server-side parser interprets the slash
153
+ * command and emits goal-related notifications which the session class
154
+ * caches.
155
+ *
156
+ * Errors clearly when called against a non-`codex-app` session — those
157
+ * sessions cannot interpret `/goal` (the `codex exec` path has no slash
158
+ * command surface).
159
+ */
160
+ codexGoalCommand(name: string, slashArgs: string, timeoutMs?: number): Promise<{
161
+ ok: true;
162
+ text: string;
163
+ goal: unknown;
164
+ }>;
165
+ /**
166
+ * Read the cached goal state from a `codex-app` session without sending
167
+ * any command. Returns null if no goal is set or the session has not yet
168
+ * received a `thread/goal/updated` notification.
169
+ */
170
+ codexGoalGet(name: string): {
171
+ ok: true;
172
+ goal: unknown;
173
+ };
174
+ private _codexBin;
175
+ /**
176
+ * Parse Codex `--json` JSONL output from a stdout buffer.
177
+ *
178
+ * Codex 0.128 emits one event per line: `thread.started`, `turn.started`,
179
+ * `item.completed` (with `item.type === 'agent_message'` for assistant text
180
+ * or tool-use types for shell/MCP calls), `turn.completed` (with usage).
181
+ *
182
+ * Returns the concatenated assistant text plus the thread_id (if present)
183
+ * and the raw event list for callers that want full visibility.
184
+ */
185
+ private _parseCodexJsonl;
186
+ /**
187
+ * Wraps `codex exec resume [SESSION_ID|--last] [PROMPT]` (Codex 0.119+).
188
+ *
189
+ * Resumes a previously recorded Codex thread by UUID/name or picks the most
190
+ * recent via `--last`. Always uses `--json` + `--sandbox workspace-write`
191
+ * so the output can be parsed into structured fields.
192
+ *
193
+ * Note: this is a one-shot operation independent of the session manager's
194
+ * tracked sessions. For in-session continuity (each send within one session
195
+ * resumes the prior thread automatically), `PersistentCodexSession`
196
+ * already handles that via the captured `thread_id` from `thread.started`.
197
+ */
198
+ codexResume(opts: {
199
+ sessionId?: string;
200
+ last?: boolean;
201
+ message: string;
202
+ cwd?: string;
203
+ model?: string;
204
+ timeout?: number;
205
+ }): Promise<{
206
+ ok: true;
207
+ text: string;
208
+ threadId?: string;
209
+ usage?: {
210
+ input_tokens?: number;
211
+ output_tokens?: number;
212
+ cached_input_tokens?: number;
213
+ reasoning_output_tokens?: number;
214
+ };
215
+ events: unknown[];
216
+ }>;
217
+ /**
218
+ * Wraps `codex review [PROMPT] [--uncommitted | --base BRANCH | --commit SHA]`.
219
+ *
220
+ * Codex 0.128's review subcommand outputs plain text (no `--json` flag),
221
+ * so the wrapper just captures stdout/stderr verbatim.
222
+ */
223
+ codexReview(opts: {
224
+ prompt?: string;
225
+ cwd?: string;
226
+ uncommitted?: boolean;
227
+ base?: string;
228
+ commit?: string;
229
+ title?: string;
230
+ model?: string;
231
+ timeout?: number;
232
+ }): Promise<{
233
+ ok: true;
234
+ stdout: string;
235
+ stderr: string;
236
+ }>;
237
+ /**
238
+ * Wraps `claude project purge` — deletes Claude Code state for a project
239
+ * (transcripts, tasks, file history, config entry).
240
+ *
241
+ * Defaults to dry-run for safety: callers must pass `dryRun: false` to
242
+ * actually delete. When `all` is true, `path` is ignored.
243
+ *
244
+ * The `--yes` flag is always passed (we have no TTY for confirmation prompts);
245
+ * safety is enforced via the dry-run default at the wrapper level instead.
246
+ */
247
+ purgeProject(opts: {
248
+ path?: string;
249
+ all?: boolean;
250
+ dryRun?: boolean;
251
+ }): Promise<{
252
+ stdout: string;
253
+ stderr: string;
254
+ dryRun: boolean;
255
+ }>;
256
+ /**
257
+ * Read OpenClaw gateway config from ~/.openclaw/openclaw.json.
258
+ * Returns { url, key } or null if not configured.
259
+ */
260
+ private _readGatewayConfig;
261
+ /**
262
+ * Start a local proxy server (if not running) that converts Anthropic format
263
+ * to OpenAI format and forwards to the OpenClaw gateway.
264
+ * Returns the proxy port, or null if gateway is not available.
265
+ */
266
+ private _ensureProxyServer;
267
+ private _persistSession;
268
+ private static PID_FILE;
269
+ private _savePids;
270
+ /**
271
+ * Verify that a PID belongs to a known coding CLI before killing it.
272
+ * Prevents killing unrelated processes if the OS recycled the PID.
273
+ */
274
+ private _isKnownCliProcess;
275
+ private _cleanupOrphanedPids;
276
+ private _getSession;
277
+ private _toSessionInfo;
278
+ private _resolveModel;
279
+ private _listMdFiles;
280
+ private _createSession;
281
+ private councils;
282
+ private councilCleanupTimers;
283
+ councilStart(task: string, config: CouncilConfig): CouncilSession;
284
+ private _scheduleCouncilCleanup;
285
+ councilStatus(id: string): CouncilSession | undefined;
286
+ councilAbort(id: string): void;
287
+ councilInject(id: string, message: string): void;
288
+ councilReview(id: string): Promise<CouncilReviewResult>;
289
+ councilAccept(id: string): Promise<CouncilAcceptResult>;
290
+ councilReject(id: string, feedback: string): Promise<CouncilRejectResult>;
291
+ private get _sessionLookup();
292
+ sessionSendTo(from: string, to: string, message: string, summary?: string): Promise<{
293
+ delivered: boolean;
294
+ queued: boolean;
295
+ }>;
296
+ sessionInbox(name: string, unreadOnly?: boolean): InboxMessage[];
297
+ sessionDeliverInbox(name: string): Promise<number>;
298
+ private ultraplans;
299
+ ultraplanStart(task: string, opts?: {
300
+ model?: string;
301
+ cwd?: string;
302
+ timeout?: number;
303
+ }): UltraplanResult;
304
+ private _runUltraplan;
305
+ ultraplanStatus(id: string): UltraplanResult | undefined;
306
+ private ultrareviews;
307
+ private ultrareviewPollers;
308
+ ultrareviewStart(cwd: string, opts?: {
309
+ agentCount?: number;
310
+ maxDurationMinutes?: number;
311
+ model?: string;
312
+ focus?: string;
313
+ }): UltrareviewResult;
314
+ ultrareviewStatus(id: string): UltrareviewResult | undefined;
315
+ private _cleanupIdleSessions;
316
+ }
317
+ export {};