@seele00/seele 0.1.63 → 0.1.64

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 (105) hide show
  1. package/README.md +5 -3
  2. package/bin/seele-codex +1 -1
  3. package/libexec/seele-server +0 -0
  4. package/libexec/seele-worker +0 -0
  5. package/package.json +1 -4
  6. package/scripts/deploy/bootstrap.sh +14 -3
  7. package/scripts/deploy/start.sh +14 -9
  8. package/web/dist/assets/{abnfDiagram-VRR7QNED-DXJQwnn-.js → abnfDiagram-VRR7QNED-BB7DT0BN.js} +1 -1
  9. package/web/dist/assets/{arc-D_47-IET.js → arc-BlEU_mit.js} +1 -1
  10. package/web/dist/assets/{architectureDiagram-ZJ3FMSHR-CKUldIzR.js → architectureDiagram-ZJ3FMSHR-Dy9cu2Mg.js} +1 -1
  11. package/web/dist/assets/{blockDiagram-677ZJIJ3-BD4Ym8Xi.js → blockDiagram-677ZJIJ3-DP4jMSfo.js} +1 -1
  12. package/web/dist/assets/{c4Diagram-LMCZKHZV-Cn268vLB.js → c4Diagram-LMCZKHZV-BtqFzX1w.js} +1 -1
  13. package/web/dist/assets/channel-mhSuRKJT.js +1 -0
  14. package/web/dist/assets/{chunk-2Q5K7J3B-D00lQ7mJ.js → chunk-2Q5K7J3B-BK9F5a0L.js} +1 -1
  15. package/web/dist/assets/{chunk-32BRIVSS-z7gv8Mry.js → chunk-32BRIVSS-nuQI6gtU.js} +1 -1
  16. package/web/dist/assets/{chunk-5VM5RSS4-BZJeO_rz.js → chunk-5VM5RSS4-D4IT05bt.js} +1 -1
  17. package/web/dist/assets/{chunk-EX3LRPZG-DoIg9UGx.js → chunk-EX3LRPZG-CrOtgxcr.js} +1 -1
  18. package/web/dist/assets/{chunk-JWPE2WC7-C1LcQus2.js → chunk-JWPE2WC7-Dn9JHm4W.js} +1 -1
  19. package/web/dist/assets/{chunk-MOJQB5TN--JPbFu4n.js → chunk-MOJQB5TN-VtD0_fGF.js} +1 -1
  20. package/web/dist/assets/{chunk-RYQCIY6F-BVv30W60.js → chunk-RYQCIY6F-TqRYsCot.js} +1 -1
  21. package/web/dist/assets/{chunk-V7JOEXUC-DYoSFgRT.js → chunk-V7JOEXUC-U9b5a7vL.js} +1 -1
  22. package/web/dist/assets/{chunk-VR4S4FIN-C8BRkTOa.js → chunk-VR4S4FIN-B3qLfeNJ.js} +1 -1
  23. package/web/dist/assets/{chunk-XXDRQBXY-CDfofIob.js → chunk-XXDRQBXY-DazVAZe-.js} +1 -1
  24. package/web/dist/assets/classDiagram-OUVF2IWQ-DYQSxD4g.js +1 -0
  25. package/web/dist/assets/classDiagram-v2-EOCWNBFH-DYQSxD4g.js +1 -0
  26. package/web/dist/assets/{core-C10OFTno.js → core-2RdBW0rZ.js} +1 -1
  27. package/web/dist/assets/{cose-bilkent-JH36ORCC-g9E8J4Fz.js → cose-bilkent-JH36ORCC-vvKttQXU.js} +1 -1
  28. package/web/dist/assets/{cynefin-VYW2F7L2-Dc689veM.js → cynefin-VYW2F7L2-BKMZmA-n.js} +1 -1
  29. package/web/dist/assets/{cynefinDiagram-TSTJHNR4-BAAq_jvr.js → cynefinDiagram-TSTJHNR4-ckdzxzlr.js} +1 -1
  30. package/web/dist/assets/{dagre-VKFMJZFB-CPtiniZQ.js → dagre-VKFMJZFB-CZw8DTb1.js} +1 -1
  31. package/web/dist/assets/{diagram-FQU43EPY-CvbIL3lu.js → diagram-FQU43EPY-C06X0Kru.js} +1 -1
  32. package/web/dist/assets/{diagram-G47NLZAW-u5m78Utg.js → diagram-G47NLZAW-HX9CdauD.js} +1 -1
  33. package/web/dist/assets/{diagram-NH7WQ7WH-4f-Ipubv.js → diagram-NH7WQ7WH-Dlo1tIod.js} +1 -1
  34. package/web/dist/assets/{diagram-OA4YK3LP-SUl1EQ56.js → diagram-OA4YK3LP-C9GXFhgw.js} +1 -1
  35. package/web/dist/assets/{diagram-WEI45ONY-C_Upd46l.js → diagram-WEI45ONY-Ch1Xx234.js} +1 -1
  36. package/web/dist/assets/{ebnfDiagram-CCIWWBDH-CHp2D7Q9.js → ebnfDiagram-CCIWWBDH-Q0_rEUgk.js} +1 -1
  37. package/web/dist/assets/{erDiagram-Q63AITRT-DQliHxOw.js → erDiagram-Q63AITRT-BsDRdpx6.js} +1 -1
  38. package/web/dist/assets/{flowDiagram-23GEKE2U-BcOYSJFM.js → flowDiagram-23GEKE2U-DDFuMRJN.js} +1 -1
  39. package/web/dist/assets/{ganttDiagram-NO4QXBWP-CDLHtJq0.js → ganttDiagram-NO4QXBWP-Cjpm08-d.js} +1 -1
  40. package/web/dist/assets/{gitGraphDiagram-IHSO6WYX-2j8C3mlk.js → gitGraphDiagram-IHSO6WYX-CnIosh2K.js} +1 -1
  41. package/web/dist/assets/index-eN6ddNRA.js +111 -0
  42. package/web/dist/assets/{infoDiagram-FWYZ7A6U-ClxdyQnM.js → infoDiagram-FWYZ7A6U-CH163HyC.js} +1 -1
  43. package/web/dist/assets/{ishikawaDiagram-FXEZZL3T-Bc2nIRgb.js → ishikawaDiagram-FXEZZL3T-DkT-3n3D.js} +1 -1
  44. package/web/dist/assets/{journeyDiagram-5HDEW3XC-R-vJ00LW.js → journeyDiagram-5HDEW3XC-34TnH3wG.js} +1 -1
  45. package/web/dist/assets/{kanban-definition-HUTT4EX6-CR0s_Mo8.js → kanban-definition-HUTT4EX6-CJbOm0lN.js} +1 -1
  46. package/web/dist/assets/{linear-BQgrawZS.js → linear-CTKXTLwe.js} +1 -1
  47. package/web/dist/assets/{mermaid.core-faLMbjSU.js → mermaid.core-CAVP16_-.js} +4 -4
  48. package/web/dist/assets/{mindmap-definition-LN4V7U3C-BZULnQui.js → mindmap-definition-LN4V7U3C-rlppHZj_.js} +1 -1
  49. package/web/dist/assets/{pegDiagram-2B236MQR-DUm1p_1o.js → pegDiagram-2B236MQR-MbcWBNJi.js} +1 -1
  50. package/web/dist/assets/{pieDiagram-ENE6RG2P-r3LCASRK.js → pieDiagram-ENE6RG2P-DKU7a4tv.js} +1 -1
  51. package/web/dist/assets/{quadrantDiagram-ABIIQ3AL-CGaCp0Px.js → quadrantDiagram-ABIIQ3AL-DpDsJVLi.js} +1 -1
  52. package/web/dist/assets/{railroadDiagram-RFXS5EU6-DmEKGO1A.js → railroadDiagram-RFXS5EU6-DrPM3aKC.js} +1 -1
  53. package/web/dist/assets/{requirementDiagram-TGXJPOKE-Byc4ivmp.js → requirementDiagram-TGXJPOKE-ZzS_iVag.js} +1 -1
  54. package/web/dist/assets/{sankeyDiagram-HTMAVEWB-BtJiL4zX.js → sankeyDiagram-HTMAVEWB-DrRrN0Lc.js} +1 -1
  55. package/web/dist/assets/{sequenceDiagram-DBY2YBRQ-Bg3vdDGW.js → sequenceDiagram-DBY2YBRQ-CP8GBGZM.js} +1 -1
  56. package/web/dist/assets/{sizeCapture-X5ZJPWSS-CCRwjaWU.js → sizeCapture-X5ZJPWSS-BYVg_dQd.js} +1 -1
  57. package/web/dist/assets/{stateDiagram-2N3HPSRC-CQU-udox.js → stateDiagram-2N3HPSRC-CsJ3M80-.js} +1 -1
  58. package/web/dist/assets/stateDiagram-v2-6OUMAXLB-CaFOY1Xb.js +1 -0
  59. package/web/dist/assets/{swimlanes-5IMT3BWC-r3tJnQLJ.js → swimlanes-5IMT3BWC-XgRKQ20Q.js} +2 -2
  60. package/web/dist/assets/swimlanesDiagram-G3AALYLV-DaKP_iDy.js +8 -0
  61. package/web/dist/assets/{timeline-definition-FHXFAJF6-DryYrdts.js → timeline-definition-FHXFAJF6-CU_Cq10d.js} +1 -1
  62. package/web/dist/assets/{vennDiagram-L72KCM5P-ZLPc0qvQ.js → vennDiagram-L72KCM5P-CLSDbg6o.js} +1 -1
  63. package/web/dist/assets/{wardleyDiagram-EHGQE667-RmgA6vQ9.js → wardleyDiagram-EHGQE667-DnAOuvzv.js} +1 -1
  64. package/web/dist/assets/{xychartDiagram-FW5EYKEG-BGIzispI.js → xychartDiagram-FW5EYKEG-CyC6V11l.js} +1 -1
  65. package/web/dist/index.html +1 -1
  66. package/codex/dist/app-server.js +0 -63
  67. package/codex/dist/errors.js +0 -16
  68. package/codex/dist/index.js +0 -4
  69. package/codex/dist/rpc-client.js +0 -96
  70. package/codex/dist/transports/stdio.js +0 -81
  71. package/codex/dist/types.js +0 -1
  72. package/codex/package.json +0 -12
  73. package/scripts/deploy/npm/postinstall.mjs +0 -10
  74. package/server/dist/auth/session.js +0 -71
  75. package/server/dist/auth/users.js +0 -276
  76. package/server/dist/codex-runtime/run-streamed-turn.js +0 -587
  77. package/server/dist/config/config.js +0 -71
  78. package/server/dist/contracts/artifact-rendering.js +0 -14
  79. package/server/dist/contracts/global-environment.js +0 -23
  80. package/server/dist/contracts/index.js +0 -114
  81. package/server/dist/contracts/managed-assets.js +0 -13
  82. package/server/dist/contracts/response-style.js +0 -23
  83. package/server/dist/contracts/task-clarification.js +0 -13
  84. package/server/dist/contracts/types.js +0 -1
  85. package/server/dist/contracts/wakeup.js +0 -13
  86. package/server/dist/contracts/workspace-boundary.js +0 -20
  87. package/server/dist/contracts/workspace-knowledge.js +0 -48
  88. package/server/dist/contracts/workspace-memory.js +0 -32
  89. package/server/dist/contracts/workspace-responsibility.js +0 -23
  90. package/server/dist/contracts/workspace-transcript.js +0 -26
  91. package/server/dist/conversations/knowledge.js +0 -380
  92. package/server/dist/conversations/store.js +0 -2466
  93. package/server/dist/doctor.js +0 -105
  94. package/server/dist/realtime/sse.js +0 -12
  95. package/server/dist/runtime-worker/client.js +0 -405
  96. package/server/dist/runtime-worker/process.js +0 -216
  97. package/server/dist/runtime-worker/protocol.js +0 -1
  98. package/server/dist/server.js +0 -4605
  99. package/server/dist/storage/sqlite.js +0 -39
  100. package/web/dist/assets/channel-Uz6zF6Xw.js +0 -1
  101. package/web/dist/assets/classDiagram-OUVF2IWQ-D6mpE1t2.js +0 -1
  102. package/web/dist/assets/classDiagram-v2-EOCWNBFH-D6mpE1t2.js +0 -1
  103. package/web/dist/assets/index-BqSosI7W.js +0 -111
  104. package/web/dist/assets/stateDiagram-v2-6OUMAXLB-YNSWW4ip.js +0 -1
  105. package/web/dist/assets/swimlanesDiagram-G3AALYLV-BGZAc11_.js +0 -8
@@ -1,587 +0,0 @@
1
- import { CodexAppServer, } from "@seele-codex/codex";
2
- import { appendFileSync } from "node:fs";
3
- import { execFile } from "node:child_process";
4
- import { promisify } from "node:util";
5
- import { buildRuntimeAdditionalContext, buildRuntimeThreadBootstrapInstructions, } from "../contracts/index.js";
6
- import { sendSse } from "../realtime/sse.js";
7
- const DEVELOPER_INSTRUCTIONS_DEBUG_LOG_PATH = "/tmp/seele-developer-instructions.log";
8
- const execFileAsync = promisify(execFile);
9
- export async function runStreamedTurn(config, request, response, callbacks = {}) {
10
- const cwd = request.cwd ?? config.defaultCwd ?? process.cwd();
11
- const globalEnvironment = describeGlobalEnvironment(config);
12
- const threadBootstrapInstructions = buildRuntimeThreadBootstrapInstructions();
13
- const runtimeContractContext = {
14
- workspaceId: request.workspaceId,
15
- workspaceTitle: request.workspaceTitle,
16
- workspacePath: cwd,
17
- workspaceTranscriptApiBase: request.workspaceTranscriptApiBase,
18
- workspaceResponsibility: request.workspaceResponsibility,
19
- workspaceKnowledge: request.workspaceKnowledge,
20
- workspaceKnowledgeApiBase: request.workspaceKnowledgeApiBase,
21
- globalMemory: request.globalMemory,
22
- workspaceMemory: request.workspaceMemory,
23
- globalMemoryItems: request.globalMemoryItems,
24
- workspaceMemoryItems: request.workspaceMemoryItems,
25
- globalEnvironment,
26
- };
27
- const runtimeAdditionalContext = buildRuntimeAdditionalContext(runtimeContractContext);
28
- const appServer = new CodexAppServer({
29
- codexBin: config.codexBin,
30
- codexArgs: [
31
- "-c",
32
- "project_root_markers=[]",
33
- "-c",
34
- "allow_login_shell=false",
35
- ...runtimeConfigurationArgs(config),
36
- ...shellEnvironmentPolicyArgs(config),
37
- ],
38
- cwd,
39
- env: codexProcessEnv(config),
40
- clientInfo: {
41
- name: "seele_codex",
42
- title: "Seele Codex",
43
- version: "0.1.0",
44
- },
45
- });
46
- let threadId = request.threadId ?? null;
47
- const assistantTextCollector = createAssistantTextCollector();
48
- let activeControl = null;
49
- let hardStopped = false;
50
- let activeTurnId = null;
51
- const pendingApprovals = new Map();
52
- const emit = (event, data) => {
53
- callbacks.onEvent?.(event, data);
54
- if (response) {
55
- sendSse(response, event, data);
56
- }
57
- };
58
- appServer.rpc.on("stderr", (line) => emit("codex.stderr", line));
59
- appServer.rpc.onRequest((serverRequest) => {
60
- if (serverRequest.method === "item/commandExecution/requestApproval") {
61
- void handleCommandApprovalRequest(serverRequest);
62
- return;
63
- }
64
- appServer.rpc.respondError(serverRequest.id, -32601, `Unsupported server request: ${serverRequest.method}`);
65
- });
66
- appServer.rpc.onNotification((notification) => {
67
- if (notification.method === "turn/started") {
68
- const turn = readObject(readObject(notification.params).turn);
69
- if (typeof turn.id === "string") {
70
- activeTurnId = turn.id;
71
- }
72
- }
73
- assistantTextCollector.record(notification);
74
- emit("codex.notification", notification);
75
- });
76
- try {
77
- await appServer.start();
78
- emit("server.status", { status: "initialized" });
79
- const approvalPolicy = request.approvalPolicy ?? approvalPolicyForSandbox(request.sandbox ?? config.defaultSandbox);
80
- const threadOptions = {
81
- model: request.model ?? config.defaultModel,
82
- cwd,
83
- approvalPolicy,
84
- sandbox: request.sandbox ?? config.defaultSandbox,
85
- developerInstructions: threadBootstrapInstructions,
86
- };
87
- let thread;
88
- if (threadId) {
89
- try {
90
- logDeveloperInstructions("thread/resume", {
91
- threadId,
92
- workspaceId: request.workspaceId,
93
- workspaceTitle: request.workspaceTitle,
94
- cwd,
95
- developerInstructions: threadBootstrapInstructions,
96
- });
97
- thread = await appServer.resumeThread({
98
- threadId,
99
- ...threadOptions,
100
- });
101
- }
102
- catch (error) {
103
- if (!isArchivedSessionError(error)) {
104
- throw error;
105
- }
106
- emit("server.status", {
107
- status: "archived_thread_replaced",
108
- archivedThreadId: threadId,
109
- });
110
- threadId = null;
111
- logDeveloperInstructions("thread/start", {
112
- threadId,
113
- workspaceId: request.workspaceId,
114
- workspaceTitle: request.workspaceTitle,
115
- cwd,
116
- developerInstructions: threadBootstrapInstructions,
117
- });
118
- thread = await appServer.startThread(threadOptions);
119
- }
120
- }
121
- else {
122
- logDeveloperInstructions("thread/start", {
123
- threadId,
124
- workspaceId: request.workspaceId,
125
- workspaceTitle: request.workspaceTitle,
126
- cwd,
127
- developerInstructions: threadBootstrapInstructions,
128
- });
129
- thread = await appServer.startThread(threadOptions);
130
- }
131
- threadId = thread.id;
132
- const activeThreadId = thread.id;
133
- emit("server.thread", thread);
134
- activeControl = {
135
- steer: async (message) => {
136
- if (!activeTurnId) {
137
- throw new Error("Cannot steer before the active turn id is known");
138
- }
139
- await appServer.steerTurn({
140
- threadId: activeThreadId,
141
- expectedTurnId: activeTurnId,
142
- input: [{ type: "text", text: message }],
143
- });
144
- },
145
- interrupt: async () => {
146
- await appServer.interruptTurn({ threadId: activeThreadId });
147
- },
148
- stop: async () => {
149
- hardStopped = true;
150
- void appServer
151
- .interruptTurn({ threadId: activeThreadId })
152
- .catch(() => undefined);
153
- appServer.stop();
154
- },
155
- respondApproval: (requestId, decision) => {
156
- const pending = pendingApprovals.get(String(requestId));
157
- if (!pending) {
158
- throw new Error(`approval request not found: ${requestId}`);
159
- }
160
- pending.resolve(decision);
161
- },
162
- };
163
- callbacks.onActiveTurn?.(activeControl);
164
- await appServer.startTurn({
165
- threadId,
166
- input: [{ type: "text", text: request.message }],
167
- cwd,
168
- approvalPolicy,
169
- model: request.model ?? config.defaultModel,
170
- sandbox: request.sandbox ?? config.defaultSandbox,
171
- additionalContext: mapRuntimeAdditionalContext(runtimeAdditionalContext),
172
- });
173
- emit("server.status", { status: "turn_started" });
174
- await waitForTurnCompletion(appServer);
175
- return { threadId, assistantText: assistantTextCollector.text() };
176
- }
177
- catch (error) {
178
- if (hardStopped && threadId) {
179
- emit("server.stopped", { threadId });
180
- return { threadId, assistantText: assistantTextCollector.text() };
181
- }
182
- emit("server.error", {
183
- message: error instanceof Error ? error.message : String(error),
184
- });
185
- return null;
186
- }
187
- finally {
188
- for (const pending of pendingApprovals.values()) {
189
- pending.reject(new Error("Codex turn ended before approval was resolved"));
190
- }
191
- pendingApprovals.clear();
192
- if (activeControl) {
193
- callbacks.onInactiveTurn?.(activeControl);
194
- }
195
- appServer.stop();
196
- }
197
- async function handleCommandApprovalRequest(serverRequest) {
198
- emit("codex.server_request", {
199
- requestId: serverRequest.id,
200
- method: serverRequest.method,
201
- params: serverRequest.params ?? null,
202
- });
203
- try {
204
- const decision = await new Promise((resolve, reject) => {
205
- pendingApprovals.set(String(serverRequest.id), {
206
- resolve,
207
- reject,
208
- });
209
- });
210
- pendingApprovals.delete(String(serverRequest.id));
211
- appServer.rpc.respond(serverRequest.id, { decision });
212
- emit("server.approval.resolved", {
213
- requestId: serverRequest.id,
214
- decision,
215
- });
216
- }
217
- catch (error) {
218
- pendingApprovals.delete(String(serverRequest.id));
219
- appServer.rpc.respond(serverRequest.id, { decision: "cancel" });
220
- emit("server.approval.error", {
221
- requestId: serverRequest.id,
222
- message: error instanceof Error ? error.message : String(error),
223
- });
224
- }
225
- }
226
- }
227
- function logDeveloperInstructions(method, input) {
228
- const entry = [
229
- "===== SEELE DEBUG developerInstructions BEGIN =====",
230
- `time=${new Date().toISOString()}`,
231
- `method=${method}`,
232
- `threadId=${input.threadId ?? "new"}`,
233
- `workspaceId=${input.workspaceId ?? ""}`,
234
- `workspaceTitle=${input.workspaceTitle ?? ""}`,
235
- `cwd=${input.cwd}`,
236
- input.developerInstructions,
237
- "===== SEELE DEBUG developerInstructions END =====",
238
- "",
239
- ].join("\n");
240
- console.log(entry);
241
- appendFileSync(DEVELOPER_INSTRUCTIONS_DEBUG_LOG_PATH, entry, "utf8");
242
- }
243
- function mapRuntimeAdditionalContext(fragments) {
244
- return Object.fromEntries(Object.entries(fragments).map(([key, value]) => [
245
- key,
246
- {
247
- kind: "application",
248
- value,
249
- },
250
- ]));
251
- }
252
- export async function rebuildRuntimeThread(config, request, injectedItems) {
253
- const cwd = request.cwd ?? config.defaultCwd ?? process.cwd();
254
- const threadBootstrapInstructions = buildRuntimeThreadBootstrapInstructions();
255
- const appServer = new CodexAppServer({
256
- codexBin: config.codexBin,
257
- codexArgs: [
258
- "-c",
259
- "project_root_markers=[]",
260
- "-c",
261
- "allow_login_shell=false",
262
- ...runtimeConfigurationArgs(config),
263
- ...shellEnvironmentPolicyArgs(config),
264
- ],
265
- cwd,
266
- env: codexProcessEnv(config),
267
- clientInfo: {
268
- name: "seele_codex",
269
- title: "Seele Codex",
270
- version: "0.1.0",
271
- },
272
- });
273
- try {
274
- await appServer.start();
275
- const sandbox = request.sandbox ?? config.defaultSandbox;
276
- const thread = await appServer.startThread({
277
- model: request.model ?? config.defaultModel,
278
- cwd,
279
- approvalPolicy: request.approvalPolicy ?? approvalPolicyForSandbox(sandbox),
280
- sandbox,
281
- developerInstructions: threadBootstrapInstructions,
282
- });
283
- if (injectedItems.length > 0) {
284
- await appServer.injectThreadItems({
285
- threadId: thread.id,
286
- items: injectedItems,
287
- });
288
- }
289
- return {
290
- threadId: thread.id,
291
- injectedItemCount: injectedItems.length,
292
- };
293
- }
294
- finally {
295
- appServer.stop();
296
- }
297
- }
298
- export async function readRuntimeThread(config, request) {
299
- const cwd = request.cwd ?? config.defaultCwd ?? process.cwd();
300
- const appServer = new CodexAppServer({
301
- codexBin: config.codexBin,
302
- codexArgs: [
303
- "-c",
304
- "project_root_markers=[]",
305
- "-c",
306
- "allow_login_shell=false",
307
- ...runtimeConfigurationArgs(config),
308
- ...shellEnvironmentPolicyArgs(config),
309
- ],
310
- cwd,
311
- env: codexProcessEnv(config),
312
- clientInfo: {
313
- name: "seele_codex",
314
- title: "Seele Codex",
315
- version: "0.1.0",
316
- },
317
- });
318
- try {
319
- await appServer.start();
320
- return await appServer.readThread({
321
- threadId: request.threadId,
322
- includeTurns: true,
323
- });
324
- }
325
- finally {
326
- appServer.stop();
327
- }
328
- }
329
- export async function listRuntimeModels(config) {
330
- const cwd = config.defaultCwd ?? process.cwd();
331
- const codexVersion = await readCodexCliVersion(config, cwd);
332
- const appServer = new CodexAppServer({
333
- codexBin: config.codexBin,
334
- codexArgs: [
335
- "-c",
336
- "project_root_markers=[]",
337
- "-c",
338
- "allow_login_shell=false",
339
- ...shellEnvironmentPolicyArgs(config),
340
- ],
341
- cwd,
342
- env: codexProcessEnv(config),
343
- clientInfo: {
344
- name: "seele_codex",
345
- title: "Seele Codex",
346
- version: "0.1.0",
347
- },
348
- });
349
- try {
350
- await appServer.start();
351
- const models = [];
352
- let cursor = null;
353
- do {
354
- const page = await appServer.listModels({
355
- cursor,
356
- limit: 100,
357
- includeHidden: false,
358
- });
359
- models.push(...page.data);
360
- cursor = page.nextCursor;
361
- } while (cursor);
362
- return { models, codexVersion };
363
- }
364
- finally {
365
- appServer.stop();
366
- }
367
- }
368
- export async function readRuntimeRateLimits(config) {
369
- const cwd = config.defaultCwd ?? process.cwd();
370
- const appServer = new CodexAppServer({
371
- codexBin: config.codexBin,
372
- codexArgs: [
373
- "-c",
374
- "project_root_markers=[]",
375
- "-c",
376
- "allow_login_shell=false",
377
- ...shellEnvironmentPolicyArgs(config),
378
- ],
379
- cwd,
380
- env: codexProcessEnv(config),
381
- clientInfo: {
382
- name: "seele_codex",
383
- title: "Seele Codex",
384
- version: "0.1.0",
385
- },
386
- });
387
- try {
388
- await appServer.start();
389
- return await appServer.readRateLimits();
390
- }
391
- finally {
392
- appServer.stop();
393
- }
394
- }
395
- async function readCodexCliVersion(config, cwd) {
396
- const { stdout, stderr } = await execFileAsync(config.codexBin ?? "codex", ["--version"], {
397
- cwd,
398
- env: codexProcessEnv(config),
399
- });
400
- return stdout.trim() || stderr.trim() || "unknown";
401
- }
402
- const SHELL_ENVIRONMENT_EXCLUDES = [
403
- "*_PROXY",
404
- "GIT_PROXY_COMMAND",
405
- ];
406
- function approvalPolicyForSandbox(sandbox) {
407
- return sandbox === "danger-full-access" ? "never" : "on-request";
408
- }
409
- function waitForTurnCompletion(appServer) {
410
- return new Promise((resolve, reject) => {
411
- const removeNotificationHandler = appServer.rpc.onNotification((notification) => {
412
- if (notification.method === "turn/completed") {
413
- cleanup();
414
- resolve();
415
- }
416
- });
417
- const onError = (error) => {
418
- cleanup();
419
- reject(error);
420
- };
421
- const onExit = (event) => {
422
- cleanup();
423
- reject(new Error(`codex app-server exited before turn completion: code=${event.code} signal=${event.signal}${event.stderr ? `\n${event.stderr}` : ""}`));
424
- };
425
- const cleanup = () => {
426
- removeNotificationHandler();
427
- appServer.rpc.off("error", onError);
428
- appServer.rpc.off("exit", onExit);
429
- };
430
- appServer.rpc.on("error", onError);
431
- appServer.rpc.on("exit", onExit);
432
- });
433
- }
434
- function readObject(value) {
435
- return value && typeof value === "object" ? value : {};
436
- }
437
- function createAssistantTextCollector() {
438
- const phases = new Map();
439
- const texts = new Map();
440
- let anonymousFinalText = "";
441
- let anonymousAssistantText = "";
442
- let lastAssistantItemId = null;
443
- return {
444
- record(notification) {
445
- const params = readObject(notification.params);
446
- if (notification.method === "item/started") {
447
- const item = readObject(params.item);
448
- if (item.type === "agentMessage" && typeof item.id === "string") {
449
- phases.set(item.id, readAgentMessagePhase(item.phase));
450
- texts.set(item.id, "");
451
- lastAssistantItemId = item.id;
452
- }
453
- return;
454
- }
455
- if (notification.method === "item/agentMessage/delta") {
456
- const delta = params.delta;
457
- if (typeof delta !== "string" || !delta) {
458
- return;
459
- }
460
- const itemId = typeof params.itemId === "string" ? params.itemId : lastAssistantItemId;
461
- if (itemId) {
462
- texts.set(itemId, `${texts.get(itemId) ?? ""}${delta}`);
463
- return;
464
- }
465
- if (readAgentMessagePhase(params.phase) === "final_answer") {
466
- anonymousFinalText += delta;
467
- }
468
- else {
469
- anonymousAssistantText += delta;
470
- }
471
- return;
472
- }
473
- if (notification.method === "item/completed") {
474
- const item = readObject(params.item);
475
- if (item.type !== "agentMessage" || typeof item.id !== "string") {
476
- return;
477
- }
478
- phases.set(item.id, readAgentMessagePhase(item.phase));
479
- if (typeof item.text === "string") {
480
- texts.set(item.id, item.text);
481
- }
482
- }
483
- },
484
- text() {
485
- const finalTexts = [...texts.entries()]
486
- .filter(([itemId]) => phases.get(itemId) === "final_answer")
487
- .map(([, value]) => value)
488
- .join("")
489
- .trim();
490
- if (finalTexts) {
491
- return finalTexts;
492
- }
493
- const latestNonCommentary = [...texts.entries()]
494
- .filter(([itemId]) => phases.get(itemId) !== "commentary")
495
- .map(([, value]) => value.trim())
496
- .filter(Boolean)
497
- .at(-1);
498
- if (latestNonCommentary) {
499
- return latestNonCommentary;
500
- }
501
- return (anonymousFinalText || anonymousAssistantText).trim();
502
- },
503
- };
504
- }
505
- function readAgentMessagePhase(value) {
506
- return value === "commentary" || value === "final_answer" ? value : "unknown";
507
- }
508
- function runtimeConfigurationArgs(config) {
509
- const args = [];
510
- if (config.defaultReasoningEffort) {
511
- args.push("-c", `model_reasoning_effort="${config.defaultReasoningEffort}"`);
512
- }
513
- if (config.defaultFastMode) {
514
- args.push("-c", 'service_tier="fast"', "-c", "features.fast_mode=true");
515
- }
516
- return args;
517
- }
518
- function shellEnvironmentPolicyArgs(config) {
519
- const globalKeys = Object.keys(config.globalEnvironment ?? {}).sort();
520
- if (globalKeys.length === 0) {
521
- return [
522
- "-c",
523
- 'shell_environment_policy.inherit="core"',
524
- "-c",
525
- `shell_environment_policy.exclude=${JSON.stringify(SHELL_ENVIRONMENT_EXCLUDES)}`,
526
- ];
527
- }
528
- return [
529
- "-c",
530
- 'shell_environment_policy.inherit="all"',
531
- "-c",
532
- "shell_environment_policy.ignore_default_excludes=true",
533
- "-c",
534
- `shell_environment_policy.include_only=${JSON.stringify([
535
- ...DEFAULT_SHELL_ENVIRONMENT_INCLUDE,
536
- ...globalKeys,
537
- ])}`,
538
- "-c",
539
- `shell_environment_policy.exclude=${JSON.stringify(SHELL_ENVIRONMENT_EXCLUDES)}`,
540
- ];
541
- }
542
- function describeGlobalEnvironment(config) {
543
- const descriptions = config.globalEnvironmentDescriptions ?? {};
544
- return Object.keys(config.globalEnvironment ?? {}).map((key) => ({
545
- key,
546
- description: descriptions[key] ?? "",
547
- }));
548
- }
549
- function codexProcessEnv(config) {
550
- const env = {
551
- ...(config.globalEnvironment ?? {}),
552
- ...codexProxyEnv(config),
553
- };
554
- return Object.keys(env).length > 0 ? env : undefined;
555
- }
556
- function codexProxyEnv(config) {
557
- if (!config.proxy) {
558
- return {};
559
- }
560
- return {
561
- ALL_PROXY: config.proxy,
562
- HTTP_PROXY: config.proxy,
563
- HTTPS_PROXY: config.proxy,
564
- all_proxy: config.proxy,
565
- http_proxy: config.proxy,
566
- https_proxy: config.proxy,
567
- };
568
- }
569
- const DEFAULT_SHELL_ENVIRONMENT_INCLUDE = [
570
- "HOME",
571
- "LANG",
572
- "LC_ALL",
573
- "LC_CTYPE",
574
- "LOGNAME",
575
- "PATH",
576
- "PWD",
577
- "SHELL",
578
- "TEMP",
579
- "TERM",
580
- "TMP",
581
- "TMPDIR",
582
- "USER",
583
- ];
584
- function isArchivedSessionError(error) {
585
- const message = error instanceof Error ? error.message : String(error);
586
- return /session .* is archived/i.test(message);
587
- }
@@ -1,71 +0,0 @@
1
- import os from "node:os";
2
- import path from "node:path";
3
- export function loadConfig(env = process.env) {
4
- const defaultCwd = env.SEELE_CODEX_DEFAULT_CWD ?? inferDefaultCwd();
5
- const seeleRoot = env.SEELE_ROOT ?? path.join(os.homedir(), "seele");
6
- const runtimeDir = env.SEELE_RUNTIME_DIR ?? path.join(seeleRoot, ".runtime");
7
- const centerDbPath = env.SEELE_DB_PATH ?? path.join(seeleRoot, "seele.db");
8
- const workspaceRoot = env.SEELE_CODEX_WORKSPACE_ROOT ?? path.join(seeleRoot, "workspaces");
9
- const host = env.SEELE_CODEX_HOST ?? "127.0.0.1";
10
- const authPassword = env.SEELE_AUTH_PASSWORD;
11
- return {
12
- host,
13
- port: Number.parseInt(env.SEELE_CODEX_PORT ?? "3000", 10),
14
- codexBin: path.join(runtimeDir, "bin", "codex"),
15
- defaultCwd,
16
- seeleRoot,
17
- centerDbPath,
18
- workspaceRoot,
19
- webDistPath: env.SEELE_CODEX_WEB_DIST ?? path.join(defaultCwd, "web", "dist"),
20
- publicBasePath: normalizePublicBasePath(env.SEELE_PUBLIC_BASE_PATH),
21
- proxy: env.SEELE_PROXY,
22
- defaultModel: env.SEELE_CODEX_DEFAULT_MODEL,
23
- defaultReasoningEffort: normalizeReasoningEffort(env.SEELE_CODEX_DEFAULT_REASONING_EFFORT),
24
- defaultFastMode: normalizeBoolean(env.SEELE_CODEX_FAST_MODE),
25
- defaultSandbox: env.SEELE_CODEX_DEFAULT_SANDBOX ??
26
- "workspace-write",
27
- authUsername: env.SEELE_AUTH_USERNAME?.trim() || "admin",
28
- authPassword,
29
- authSessionTtlSeconds: normalizePositiveInteger(env.SEELE_AUTH_SESSION_TTL_SECONDS, 30 * 24 * 60 * 60),
30
- };
31
- }
32
- export function normalizePublicBasePath(value) {
33
- const trimmed = value?.trim() || "/";
34
- if (!trimmed.startsWith("/") ||
35
- trimmed.includes("?") ||
36
- trimmed.includes("#") ||
37
- trimmed.includes("\\")) {
38
- throw new Error("SEELE_PUBLIC_BASE_PATH must be an absolute URL path without a query or fragment");
39
- }
40
- const segments = trimmed.split("/").filter(Boolean);
41
- if (segments.some((segment) => segment === "." || segment === "..")) {
42
- throw new Error("SEELE_PUBLIC_BASE_PATH cannot contain dot segments");
43
- }
44
- return segments.length === 0 ? "/" : `/${segments.join("/")}/`;
45
- }
46
- function normalizePositiveInteger(value, fallback) {
47
- const parsed = Number.parseInt(value ?? "", 10);
48
- return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
49
- }
50
- function normalizeReasoningEffort(value) {
51
- if (value === "minimal" ||
52
- value === "low" ||
53
- value === "medium" ||
54
- value === "high" ||
55
- value === "xhigh") {
56
- return value;
57
- }
58
- return "medium";
59
- }
60
- function normalizeBoolean(value) {
61
- if (!value) {
62
- return undefined;
63
- }
64
- return value === "1" || value === "true" || value === "yes";
65
- }
66
- function inferDefaultCwd() {
67
- if (path.basename(process.cwd()) === "server") {
68
- return path.dirname(process.cwd());
69
- }
70
- return process.cwd();
71
- }
@@ -1,14 +0,0 @@
1
- export function artifactRenderingContract() {
2
- return {
3
- id: "artifact-rendering",
4
- title: "Artifact rendering",
5
- body: [
6
- "CAPABILITY: Seele Web can render generated image artifacts inline when you reference them in the final answer.",
7
- "REQUIRED FORMAT: Supported inline image artifact extensions are .svg, .png, .jpg, .jpeg, .webp, and .gif.",
8
- "REQUIRED FORMAT: Save a visual artifact as a file in the current workspace and mention it once using Markdown link syntax with a workspace-relative path, for example [usage-colors.svg](usage-colors.svg).",
9
- "REQUIRED BOUNDARY: Do not expose host absolute paths such as /Users/... or /home/... in final answers unless the user explicitly asks for an absolute path.",
10
- "REQUIRED BOUNDARY: Do not paste full SVG, image, or generated artifact source into the final answer unless the user explicitly asks for the source.",
11
- "GUIDANCE: Use this for generated visual outputs that should appear directly in the Seele chat UI. Prefer a concise link over verbose path explanation.",
12
- ],
13
- };
14
- }
@@ -1,23 +0,0 @@
1
- export function globalEnvironmentContract(context) {
2
- const variables = context.globalEnvironment
3
- .slice()
4
- .sort((left, right) => left.key.localeCompare(right.key));
5
- return {
6
- id: "global-environment",
7
- title: "Global environment",
8
- body: variables.length > 0
9
- ? [
10
- "CAPABILITY: The following Seele global environment variables are available to shell commands in this workspace:",
11
- ...variables.map((item) => item.description
12
- ? `STATE ENV: ${item.key}: ${item.description}`
13
- : `STATE ENV: ${item.key}: no description provided`),
14
- "REQUIRED BOUNDARY: The variable values are intentionally not shown in the prompt. Read them only from the shell environment when running commands or scripts.",
15
- "REQUIRED BOUNDARY: Do not print, persist, or reveal secret values.",
16
- "GUIDANCE: Use these variables when they match the task's needed credential, token, endpoint, or configuration. Do not ask the user to provide a secret again when a relevant variable is already listed here.",
17
- "GUIDANCE: If the variable name is ambiguous or none of the listed variables matches the missing requirement, ask the user for clarification instead of guessing.",
18
- ]
19
- : [
20
- "STATE: No Seele global environment variables are configured for this workspace run.",
21
- ],
22
- };
23
- }