replicas-engine 0.1.7 → 0.1.8

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,4 +1,5 @@
1
1
  import { Codex, Thread } from '@openai/codex-sdk';
2
+ import { randomUUID } from 'crypto';
2
3
  import { findSessionFile, readJSONL } from '../utils/jsonl-reader.js';
3
4
  export class CodexManager {
4
5
  codex;
@@ -39,13 +40,26 @@ export class CodexManager {
39
40
  skipGitRepoCheck: true,
40
41
  sandboxMode: 'danger-full-access',
41
42
  });
43
+ if (this.currentThread.id) {
44
+ this.currentThreadId = this.currentThread.id;
45
+ console.log(`Thread started: ${this.currentThreadId}`);
46
+ }
47
+ // prime the thread with system instructions if thread is new
48
+ const workspaceName = process.env.WORKSPACE_NAME || 'workspace';
49
+ const workspaceBranchSegment = workspaceName
50
+ .trim()
51
+ .toLowerCase()
52
+ .replace(/[^a-z0-9]+/g, '-')
53
+ .replace(/^-+|-+$/g, '') || 'workspace';
54
+ const uuid = randomUUID().slice(0, 8);
55
+ const branchName = `replicas/${workspaceBranchSegment}-${uuid}`;
56
+ const systemMessage = `<replicas_important_instructions>When completing solutions, push your changes to branch ${branchName} and to origin. Greet the user.</replicas_important_instructions>`;
57
+ console.log('Priming thread with system instructions');
58
+ await this.currentThread.run(systemMessage);
59
+ console.log('Thread primed successfully');
42
60
  }
43
61
  }
44
62
  await this.currentThread.run(message);
45
- if (!this.currentThreadId && this.currentThread.id) {
46
- this.currentThreadId = this.currentThread.id;
47
- console.log(`Thread started: ${this.currentThreadId}`);
48
- }
49
63
  }
50
64
  async getHistory() {
51
65
  if (!this.currentThreadId) {
@@ -64,9 +78,13 @@ export class CodexManager {
64
78
  }
65
79
  console.log(`Reading session file: ${sessionFile}`);
66
80
  const events = await readJSONL(sessionFile);
81
+ const filteredEvents = events.filter((event) => {
82
+ const eventStr = JSON.stringify(event);
83
+ return !eventStr.includes('<replicas_important_instructions>');
84
+ });
67
85
  return {
68
86
  thread_id: this.currentThreadId,
69
- events,
87
+ events: filteredEvents,
70
88
  };
71
89
  }
72
90
  async getStatus() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replicas-engine",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Lightweight API server for Replicas workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",