workspacecord 1.1.2 → 1.1.3

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.
@@ -1,589 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- Store,
4
- config,
5
- resolvePath,
6
- sanitizeName
7
- } from "./chunk-UEX7U2KW.js";
8
-
9
- // ../engine/src/session/permissions.ts
10
- function resolveEffectiveClaudePermissionMode(session) {
11
- return session.mode === "auto" ? "bypass" : session.claudePermissionMode ?? config.claudePermissionMode;
12
- }
13
- function resolveEffectiveCodexOptions(session) {
14
- const bypass = session.codexBypass === true;
15
- if (bypass) {
16
- return {
17
- sandboxMode: "danger-full-access",
18
- approvalPolicy: "never",
19
- networkAccessEnabled: true,
20
- webSearchMode: "live",
21
- bypass: true
22
- };
23
- }
24
- return {
25
- sandboxMode: session.codexSandboxMode ?? config.codexSandboxMode,
26
- approvalPolicy: session.mode === "auto" ? "never" : session.codexApprovalPolicy ?? config.codexApprovalPolicy,
27
- networkAccessEnabled: session.codexNetworkAccessEnabled ?? config.codexNetworkAccessEnabled,
28
- webSearchMode: session.codexWebSearchMode ?? config.codexWebSearchMode,
29
- bypass: false
30
- };
31
- }
32
- function getSessionPermissionSummary(session) {
33
- if (session.provider === "claude") {
34
- return resolveEffectiveClaudePermissionMode(session);
35
- }
36
- const codex = resolveEffectiveCodexOptions(session);
37
- if (codex.bypass) return "bypass";
38
- return `${codex.sandboxMode} | ${codex.approvalPolicy} | net:${codex.networkAccessEnabled ? "on" : "off"} | search:${codex.webSearchMode}`;
39
- }
40
- function getSessionPermissionDetails(session) {
41
- if (session.provider === "claude") {
42
- return `Claude: ${resolveEffectiveClaudePermissionMode(session)}`;
43
- }
44
- const codex = resolveEffectiveCodexOptions(session);
45
- return [
46
- `sandbox=${codex.sandboxMode}`,
47
- `approval=${codex.approvalPolicy}`,
48
- `bypass=${codex.bypass ? "on" : "off"}`,
49
- `network=${codex.networkAccessEnabled ? "on" : "off"}`,
50
- `search=${codex.webSearchMode}`
51
- ].join(" | ");
52
- }
53
-
54
- // ../engine/src/session-registry.ts
55
- import { existsSync } from "fs";
56
- import { sep } from "path";
57
-
58
- // ../engine/src/output-port.ts
59
- var outputPort = null;
60
- function registerOutputPort(port) {
61
- outputPort = port;
62
- }
63
- function getOutputPort() {
64
- if (!outputPort) {
65
- throw new Error("OutputPort not registered. Call registerOutputPort() during bot startup.");
66
- }
67
- return outputPort;
68
- }
69
-
70
- // ../engine/src/session/persistence.ts
71
- var sessionStore = new Store("sessions.json");
72
- var saveQueue = Promise.resolve();
73
- var saveTimer = null;
74
- async function loadPersistedSessions() {
75
- const data = await sessionStore.read();
76
- return data ?? [];
77
- }
78
- function serializeSessions(sessions2) {
79
- const data = [];
80
- for (const [, s] of sessions2) {
81
- data.push({
82
- id: s.id,
83
- channelId: s.channelId,
84
- categoryId: s.categoryId,
85
- projectName: s.projectName,
86
- agentLabel: s.agentLabel,
87
- provider: s.provider,
88
- providerSessionId: s.providerSessionId,
89
- model: s.model,
90
- type: s.type,
91
- parentChannelId: s.parentChannelId,
92
- subagentDepth: s.subagentDepth,
93
- directory: s.directory,
94
- mode: s.mode,
95
- agentPersona: s.agentPersona,
96
- verbose: s.verbose || false,
97
- claudePermissionMode: s.claudePermissionMode,
98
- codexSandboxMode: s.codexSandboxMode,
99
- codexApprovalPolicy: s.codexApprovalPolicy,
100
- codexBypass: s.codexBypass,
101
- codexNetworkAccessEnabled: s.codexNetworkAccessEnabled,
102
- codexWebSearchMode: s.codexWebSearchMode,
103
- monitorGoal: s.monitorGoal,
104
- monitorProviderSessionId: s.monitorProviderSessionId,
105
- workflowState: s.workflowState,
106
- createdAt: s.createdAt,
107
- lastActivity: s.lastActivity,
108
- messageCount: s.messageCount,
109
- totalCost: s.totalCost,
110
- currentTurn: s.currentTurn,
111
- humanResolved: s.humanResolved,
112
- currentInteractionMessageId: s.currentInteractionMessageId,
113
- statusCardMessageId: s.statusCardMessageId,
114
- lastInboundMessageId: s.lastInboundMessageId,
115
- discoverySource: s.discoverySource,
116
- lastObservedState: s.lastObservedState,
117
- lastObservedEventKey: s.lastObservedEventKey,
118
- lastObservedAt: s.lastObservedAt,
119
- lastObservedCwd: s.lastObservedCwd,
120
- remoteHumanControl: s.remoteHumanControl,
121
- activeHumanGateId: s.activeHumanGateId
122
- });
123
- }
124
- return data;
125
- }
126
- async function persistNow(sessions2) {
127
- const data = serializeSessions(sessions2);
128
- await sessionStore.write(data);
129
- }
130
- function saveAllSessions(sessions2) {
131
- saveQueue = saveQueue.catch(() => {
132
- }).then(async () => {
133
- try {
134
- await persistNow(sessions2);
135
- } catch (err) {
136
- console.error(`[session-manager] Failed to persist sessions: ${err.message}`);
137
- }
138
- });
139
- return saveQueue;
140
- }
141
- function debouncedSave(sessions2) {
142
- if (saveTimer) clearTimeout(saveTimer);
143
- saveTimer = setTimeout(() => {
144
- saveTimer = null;
145
- saveAllSessions(sessions2);
146
- }, 1e3);
147
- }
148
- function saveImmediate(sessions2) {
149
- if (saveTimer) {
150
- clearTimeout(saveTimer);
151
- saveTimer = null;
152
- }
153
- return saveAllSessions(sessions2);
154
- }
155
-
156
- // ../engine/src/session-registry.ts
157
- var sessions = /* @__PURE__ */ new Map();
158
- var idToChannelId = /* @__PURE__ */ new Map();
159
- var sessionsByCategory = /* @__PURE__ */ new Map();
160
- var providerSessionIndex = /* @__PURE__ */ new Map();
161
- var sessionControllers = /* @__PURE__ */ new Map();
162
- var sessionAbortReasons = /* @__PURE__ */ new Map();
163
- function createDefaultWorkflowState() {
164
- return {
165
- status: "idle",
166
- iteration: 0,
167
- updatedAt: Date.now()
168
- };
169
- }
170
- async function loadSessions() {
171
- const data = await loadPersistedSessions();
172
- if (data.length === 0) return;
173
- let cleaned = false;
174
- for (const s of data) {
175
- if (!s.categoryId) {
176
- cleaned = true;
177
- console.warn(`Skipping invalid persisted session "${s.id}" (missing categoryId).`);
178
- continue;
179
- }
180
- if (!s.channelId) {
181
- cleaned = true;
182
- console.warn(`Skipping invalid persisted session "${s.id}" (missing channelId).`);
183
- continue;
184
- }
185
- if (sessions.has(s.channelId)) {
186
- cleaned = true;
187
- console.warn(
188
- `Skipping duplicate persisted session "${s.id}" (channelId ${s.channelId} already loaded).`
189
- );
190
- continue;
191
- }
192
- const provider = s.provider ?? "claude";
193
- sessions.set(s.channelId, {
194
- ...s,
195
- provider,
196
- verbose: s.verbose ?? false,
197
- mode: s.mode ?? "auto",
198
- subagentDepth: s.subagentDepth ?? 0,
199
- type: s.type ?? "persistent",
200
- codexSandboxMode: s.codexSandboxMode,
201
- codexApprovalPolicy: s.codexApprovalPolicy,
202
- codexBypass: s.codexBypass,
203
- codexNetworkAccessEnabled: s.codexNetworkAccessEnabled,
204
- codexWebSearchMode: s.codexWebSearchMode,
205
- workflowState: s.workflowState ?? createDefaultWorkflowState(),
206
- currentTurn: s.currentTurn ?? 0,
207
- humanResolved: s.humanResolved ?? false,
208
- currentInteractionMessageId: s.currentInteractionMessageId,
209
- statusCardMessageId: s.statusCardMessageId,
210
- lastInboundMessageId: s.lastInboundMessageId,
211
- discoverySource: s.discoverySource ?? "discord",
212
- lastObservedState: s.lastObservedState,
213
- lastObservedEventKey: s.lastObservedEventKey,
214
- lastObservedAt: s.lastObservedAt,
215
- lastObservedCwd: s.lastObservedCwd,
216
- remoteHumanControl: s.remoteHumanControl,
217
- activeHumanGateId: s.activeHumanGateId,
218
- isGenerating: false
219
- });
220
- idToChannelId.set(s.id, s.channelId);
221
- if (s.providerSessionId) {
222
- providerSessionIndex.set(s.providerSessionId, s.channelId);
223
- }
224
- if (!sessionsByCategory.has(s.categoryId)) {
225
- sessionsByCategory.set(s.categoryId, /* @__PURE__ */ new Set());
226
- }
227
- sessionsByCategory.get(s.categoryId).add(s.channelId);
228
- }
229
- if (cleaned) {
230
- await saveSessions();
231
- }
232
- console.log(`[session-manager] Restored ${sessions.size} session(s)`);
233
- }
234
- function saveSessions() {
235
- return saveAllSessions(sessions);
236
- }
237
- function debouncedSave2() {
238
- debouncedSave(sessions);
239
- }
240
- function saveSessionsImmediate() {
241
- return saveImmediate(sessions);
242
- }
243
- async function createSession(params) {
244
- const {
245
- channelId,
246
- categoryId,
247
- projectName,
248
- agentLabel,
249
- provider,
250
- providerSessionId,
251
- model,
252
- type,
253
- parentChannelId,
254
- subagentDepth = 0,
255
- mode = config.defaultMode,
256
- claudePermissionMode,
257
- codexSandboxMode,
258
- codexApprovalPolicy,
259
- codexBypass,
260
- codexNetworkAccessEnabled,
261
- codexWebSearchMode,
262
- discoverySource = "discord",
263
- remoteHumanControl
264
- } = params;
265
- const resolvedDir = resolvePath(params.directory);
266
- if (!existsSync(resolvedDir)) {
267
- throw new Error(`Directory does not exist: ${resolvedDir}`);
268
- }
269
- if (sessions.has(channelId)) {
270
- throw new Error(`Session for channelId "${channelId}" already exists`);
271
- }
272
- const baseId = sanitizeName(agentLabel);
273
- let id = baseId;
274
- let suffix = 1;
275
- while (idToChannelId.has(id)) {
276
- suffix++;
277
- const suffixStr = `-${suffix}`;
278
- id = baseId.slice(0, 50 - suffixStr.length) + suffixStr;
279
- }
280
- const session = {
281
- id,
282
- channelId,
283
- categoryId,
284
- projectName,
285
- agentLabel,
286
- provider,
287
- providerSessionId,
288
- model,
289
- type,
290
- parentChannelId,
291
- subagentDepth,
292
- directory: resolvedDir,
293
- mode,
294
- agentPersona: void 0,
295
- verbose: false,
296
- claudePermissionMode,
297
- codexSandboxMode,
298
- codexApprovalPolicy,
299
- codexBypass,
300
- codexNetworkAccessEnabled,
301
- codexWebSearchMode,
302
- monitorGoal: void 0,
303
- monitorProviderSessionId: void 0,
304
- workflowState: createDefaultWorkflowState(),
305
- isGenerating: false,
306
- createdAt: Date.now(),
307
- lastActivity: Date.now(),
308
- messageCount: 0,
309
- totalCost: 0,
310
- currentTurn: 0,
311
- humanResolved: false,
312
- currentInteractionMessageId: void 0,
313
- statusCardMessageId: void 0,
314
- lastInboundMessageId: void 0,
315
- discoverySource,
316
- remoteHumanControl
317
- };
318
- sessions.set(channelId, session);
319
- idToChannelId.set(id, channelId);
320
- if (providerSessionId) {
321
- providerSessionIndex.set(providerSessionId, channelId);
322
- }
323
- if (!sessionsByCategory.has(categoryId)) {
324
- sessionsByCategory.set(categoryId, /* @__PURE__ */ new Set());
325
- }
326
- sessionsByCategory.get(categoryId).add(channelId);
327
- await saveSessionsImmediate();
328
- return session;
329
- }
330
- function getSession(id) {
331
- const channelId = idToChannelId.get(id);
332
- return channelId ? sessions.get(channelId) : void 0;
333
- }
334
- function getSessionByChannel(channelId) {
335
- return sessions.get(channelId);
336
- }
337
- function getSessionByProviderSession(provider, providerSessionId) {
338
- if (!providerSessionId) return void 0;
339
- const channelId = providerSessionIndex.get(providerSessionId);
340
- if (channelId) {
341
- const session = sessions.get(channelId);
342
- if (session && session.provider === provider) return session;
343
- }
344
- return void 0;
345
- }
346
- function getSessionsByCategory(categoryId) {
347
- const channelIds = sessionsByCategory.get(categoryId);
348
- if (!channelIds) return [];
349
- const result = [];
350
- for (const channelId of channelIds) {
351
- const session = sessions.get(channelId);
352
- if (session) result.push(session);
353
- }
354
- return result;
355
- }
356
- function getAllSessions() {
357
- return Array.from(sessions.values());
358
- }
359
- function stripCodexMonitorPrefix(sessionId) {
360
- return sessionId.startsWith("codex:") ? sessionId.slice("codex:".length) : sessionId;
361
- }
362
- function findCodexSessionByProviderSessionId(providerSessionId) {
363
- const normalized = stripCodexMonitorPrefix(providerSessionId);
364
- const byNormalized = getSessionByProviderSession("codex", normalized);
365
- if (byNormalized) return byNormalized;
366
- if (normalized !== providerSessionId) {
367
- return getSessionByProviderSession("codex", providerSessionId);
368
- }
369
- return void 0;
370
- }
371
- function findCodexSessionByCwd(cwd) {
372
- const normalizedCwd = resolvePath(cwd);
373
- let best;
374
- let bestLen = -1;
375
- for (const session of sessions.values()) {
376
- if (session.provider !== "codex") continue;
377
- const dir = resolvePath(session.directory);
378
- const isMatch = normalizedCwd === dir || normalizedCwd.startsWith(`${dir}${sep}`);
379
- if (!isMatch) continue;
380
- if (dir.length > bestLen) {
381
- best = session;
382
- bestLen = dir.length;
383
- }
384
- }
385
- return best;
386
- }
387
- function resolveCodexSessionFromMonitor(monitorSessionId, cwd) {
388
- const byProviderSessionId = findCodexSessionByProviderSessionId(monitorSessionId);
389
- if (byProviderSessionId) return byProviderSessionId;
390
- if (cwd) return findCodexSessionByCwd(cwd);
391
- return void 0;
392
- }
393
- function updateSession(sessionId, patch) {
394
- const session = getSession(sessionId);
395
- if (!session) return;
396
- if (patch.providerSessionId !== void 0 && patch.providerSessionId !== session.providerSessionId) {
397
- if (session.providerSessionId) providerSessionIndex.delete(session.providerSessionId);
398
- if (patch.providerSessionId) providerSessionIndex.set(patch.providerSessionId, session.channelId);
399
- }
400
- Object.assign(session, patch);
401
- debouncedSave2();
402
- }
403
- async function updateSessionPermissions(sessionId, patch) {
404
- const session = getSession(sessionId);
405
- if (!session) {
406
- throw new Error(`Session "${sessionId}" not found`);
407
- }
408
- Object.assign(session, patch);
409
- session.lastActivity = Date.now();
410
- await saveSessionsImmediate();
411
- }
412
- function setStatusCardBinding(sessionId, binding) {
413
- const session = getSession(sessionId);
414
- if (!session) return;
415
- session.statusCardMessageId = binding.messageId;
416
- debouncedSave2();
417
- }
418
- function setCurrentInteractionMessage(sessionId, messageId) {
419
- const session = getSession(sessionId);
420
- if (!session) return;
421
- session.currentInteractionMessageId = messageId;
422
- debouncedSave2();
423
- }
424
- async function endSession(id) {
425
- const session = getSession(id);
426
- if (!session) return;
427
- const controller = sessionControllers.get(session.id);
428
- if (controller && session.isGenerating) {
429
- controller.abort();
430
- }
431
- sessionControllers.delete(session.id);
432
- sessionAbortReasons.delete(session.id);
433
- idToChannelId.delete(session.id);
434
- if (session.providerSessionId) {
435
- providerSessionIndex.delete(session.providerSessionId);
436
- }
437
- sessions.delete(session.channelId);
438
- const categorySet = sessionsByCategory.get(session.categoryId);
439
- if (categorySet) {
440
- categorySet.delete(session.channelId);
441
- if (categorySet.size === 0) {
442
- sessionsByCategory.delete(session.categoryId);
443
- }
444
- }
445
- getOutputPort().cleanupPanel(session.id);
446
- await saveSessionsImmediate();
447
- }
448
- function setMode(sessionId, mode) {
449
- const session = getSession(sessionId);
450
- if (session) {
451
- session.mode = mode;
452
- if (mode === "monitor") {
453
- session.monitorProviderSessionId = void 0;
454
- }
455
- session.workflowState = createDefaultWorkflowState();
456
- debouncedSave2();
457
- }
458
- }
459
- function setVerbose(sessionId, verbose) {
460
- const session = getSession(sessionId);
461
- if (session) {
462
- session.verbose = verbose;
463
- debouncedSave2();
464
- }
465
- }
466
- function setModel(sessionId, model) {
467
- const session = getSession(sessionId);
468
- if (session) {
469
- session.model = model;
470
- debouncedSave2();
471
- }
472
- }
473
- function setAgentPersona(sessionId, persona) {
474
- const session = getSession(sessionId);
475
- if (session) {
476
- session.agentPersona = persona;
477
- debouncedSave2();
478
- }
479
- }
480
- function setMonitorGoal(sessionId, goal) {
481
- const session = getSession(sessionId);
482
- if (session) {
483
- session.monitorGoal = goal;
484
- if (!goal) {
485
- session.monitorProviderSessionId = void 0;
486
- }
487
- session.workflowState = createDefaultWorkflowState();
488
- debouncedSave2();
489
- }
490
- }
491
- function updateWorkflowState(sessionId, patch) {
492
- const session = getSession(sessionId);
493
- if (!session) return;
494
- const next = typeof patch === "function" ? patch(session.workflowState) : { ...session.workflowState, ...patch };
495
- session.workflowState = {
496
- ...next,
497
- updatedAt: Date.now()
498
- };
499
- debouncedSave2();
500
- }
501
- function abortSession(sessionId) {
502
- return abortSessionWithReason(sessionId, "user");
503
- }
504
- function abortSessionWithReason(sessionId, reason) {
505
- const session = getSession(sessionId);
506
- if (!session) return false;
507
- const controller = sessionControllers.get(session.id);
508
- sessionAbortReasons.set(session.id, reason);
509
- if (controller) {
510
- controller.abort();
511
- }
512
- if (session.isGenerating) {
513
- session.isGenerating = false;
514
- sessionControllers.delete(session.id);
515
- debouncedSave2();
516
- return true;
517
- }
518
- return !!controller;
519
- }
520
- function consumeAbortReason(sessionId) {
521
- const session = getSession(sessionId);
522
- if (!session) return void 0;
523
- const reason = sessionAbortReasons.get(session.id);
524
- sessionAbortReasons.delete(session.id);
525
- return reason;
526
- }
527
- function getSessionController(sessionId) {
528
- const session = getSession(sessionId);
529
- if (!session) return void 0;
530
- return sessionControllers.get(session.id);
531
- }
532
- function setSessionController(sessionId, controller) {
533
- sessionControllers.set(sessionId, controller);
534
- }
535
- function clearSessionController(sessionId) {
536
- sessionControllers.delete(sessionId);
537
- }
538
- function markSessionGenerating(sessionId, generating) {
539
- const session = getSession(sessionId);
540
- if (!session) return;
541
- session.isGenerating = generating;
542
- session.lastActivity = Date.now();
543
- if (!generating) {
544
- void saveSessionsImmediate();
545
- }
546
- }
547
- function saveSessionImmediate() {
548
- return saveSessionsImmediate();
549
- }
550
- function debouncedSaveSession() {
551
- debouncedSave2();
552
- }
553
-
554
- export {
555
- registerOutputPort,
556
- getOutputPort,
557
- resolveEffectiveClaudePermissionMode,
558
- resolveEffectiveCodexOptions,
559
- getSessionPermissionSummary,
560
- getSessionPermissionDetails,
561
- loadSessions,
562
- createSession,
563
- getSession,
564
- getSessionByChannel,
565
- getSessionByProviderSession,
566
- getSessionsByCategory,
567
- getAllSessions,
568
- resolveCodexSessionFromMonitor,
569
- updateSession,
570
- updateSessionPermissions,
571
- setStatusCardBinding,
572
- setCurrentInteractionMessage,
573
- endSession,
574
- setMode,
575
- setVerbose,
576
- setModel,
577
- setAgentPersona,
578
- setMonitorGoal,
579
- updateWorkflowState,
580
- abortSession,
581
- abortSessionWithReason,
582
- consumeAbortReason,
583
- getSessionController,
584
- setSessionController,
585
- clearSessionController,
586
- markSessionGenerating,
587
- saveSessionImmediate,
588
- debouncedSaveSession
589
- };
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- runCli,
4
- startBot
5
- } from "./chunk-I6EOCCQV.js";
6
- import "./chunk-QWPKAUSV.js";
7
- import "./chunk-ZAQV2RZS.js";
8
- import "./chunk-L2ZJXV6H.js";
9
- import "./chunk-GMYN4SYT.js";
10
- import "./chunk-54DP53ZK.js";
11
- import "./chunk-COXPTYH5.js";
12
- import "./chunk-RK6EIZOL.js";
13
- import "./chunk-UEX7U2KW.js";
14
- import "./chunk-MO4EEYFW.js";
15
- export {
16
- runCli,
17
- startBot
18
- };