replicas-engine 0.1.31 → 0.1.33
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.
- package/dist/src/chunk-ZXMDA7VB.js +16 -0
- package/dist/src/index.js +86 -46
- package/dist/src/lib-WNJM7YOZ.js +3011 -0
- package/package.json +3 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
__require,
|
|
15
|
+
__commonJS
|
|
16
|
+
};
|
package/dist/src/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import "./chunk-ZXMDA7VB.js";
|
|
2
3
|
|
|
3
4
|
// src/index.ts
|
|
4
5
|
import "dotenv/config";
|
|
5
6
|
import { serve } from "@hono/node-server";
|
|
6
7
|
import { Hono as Hono4 } from "hono";
|
|
7
|
-
import { readFile as
|
|
8
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
8
9
|
import { execSync as execSync2 } from "child_process";
|
|
9
10
|
|
|
10
11
|
// src/middleware/auth.ts
|
|
@@ -85,7 +86,8 @@ async function readJSONLPaginated(filePath, limit, offset = 0) {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
// src/services/codex-manager.ts
|
|
88
|
-
import { readdir, stat, writeFile as writeFile3, mkdir as mkdir3 } from "fs/promises";
|
|
89
|
+
import { readdir, stat, writeFile as writeFile3, mkdir as mkdir3, readFile as readFile4 } from "fs/promises";
|
|
90
|
+
import { existsSync as existsSync3 } from "fs";
|
|
89
91
|
import { join as join3 } from "path";
|
|
90
92
|
import { homedir as homedir3 } from "os";
|
|
91
93
|
|
|
@@ -791,6 +793,24 @@ import { join as join2 } from "path";
|
|
|
791
793
|
import { homedir as homedir2 } from "os";
|
|
792
794
|
import { exec } from "child_process";
|
|
793
795
|
import { promisify } from "util";
|
|
796
|
+
|
|
797
|
+
// ../shared/src/sandbox.ts
|
|
798
|
+
var SANDBOX_LIFECYCLE = {
|
|
799
|
+
AUTO_STOP_MINUTES: 60,
|
|
800
|
+
AUTO_ARCHIVE_MINUTES: 60 * 24 * 7,
|
|
801
|
+
AUTO_DELETE_MINUTES: -1,
|
|
802
|
+
SSH_TOKEN_EXPIRATION_MINUTES: 3 * 60
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
// ../shared/src/prompts.ts
|
|
806
|
+
var GENERAL_INSTRUCTIONS_TAG = "general_instructions";
|
|
807
|
+
function wrapInTag(content, tag) {
|
|
808
|
+
return `<${tag}>
|
|
809
|
+
${content}
|
|
810
|
+
</${tag}>`;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// src/services/replicas-config.ts
|
|
794
814
|
var execAsync = promisify(exec);
|
|
795
815
|
var START_HOOKS_LOG = join2(homedir2(), ".replicas", "startHooks.log");
|
|
796
816
|
var START_HOOKS_RUNNING_PROMPT = `IMPORTANT - Start Hooks Running:
|
|
@@ -961,7 +981,8 @@ Commands: ${hooks.length}
|
|
|
961
981
|
* Get the system prompt from replicas.json
|
|
962
982
|
*/
|
|
963
983
|
getSystemPrompt() {
|
|
964
|
-
|
|
984
|
+
if (!this.config?.systemPrompt) return void 0;
|
|
985
|
+
return wrapInTag(this.config.systemPrompt, GENERAL_INSTRUCTIONS_TAG);
|
|
965
986
|
}
|
|
966
987
|
/**
|
|
967
988
|
* Get the full config object
|
|
@@ -985,7 +1006,9 @@ Commands: ${hooks.length}
|
|
|
985
1006
|
var replicasConfigService = new ReplicasConfigService();
|
|
986
1007
|
|
|
987
1008
|
// src/services/codex-manager.ts
|
|
1009
|
+
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
|
|
988
1010
|
var DEFAULT_MODEL = "gpt-5.2-codex";
|
|
1011
|
+
var CODEX_CONFIG_PATH = join3(homedir3(), ".codex", "config.toml");
|
|
989
1012
|
var CodexManager = class {
|
|
990
1013
|
codex;
|
|
991
1014
|
currentThreadId = null;
|
|
@@ -1065,11 +1088,33 @@ var CodexManager = class {
|
|
|
1065
1088
|
return START_HOOKS_RUNNING_PROMPT;
|
|
1066
1089
|
}
|
|
1067
1090
|
/**
|
|
1068
|
-
*
|
|
1069
|
-
*
|
|
1091
|
+
* Update the developer_instructions in ~/.codex/config.toml
|
|
1092
|
+
* This sets the system prompt that Codex will use for this turn
|
|
1070
1093
|
*/
|
|
1071
|
-
async
|
|
1072
|
-
|
|
1094
|
+
async updateCodexConfig(developerInstructions) {
|
|
1095
|
+
try {
|
|
1096
|
+
const codexDir = join3(homedir3(), ".codex");
|
|
1097
|
+
await mkdir3(codexDir, { recursive: true });
|
|
1098
|
+
let config = {};
|
|
1099
|
+
if (existsSync3(CODEX_CONFIG_PATH)) {
|
|
1100
|
+
try {
|
|
1101
|
+
const existingContent = await readFile4(CODEX_CONFIG_PATH, "utf-8");
|
|
1102
|
+
config = parseToml(existingContent);
|
|
1103
|
+
} catch (parseError) {
|
|
1104
|
+
console.warn("[CodexManager] Failed to parse existing config.toml, starting fresh:", parseError);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
if (developerInstructions) {
|
|
1108
|
+
config.developer_instructions = developerInstructions;
|
|
1109
|
+
} else {
|
|
1110
|
+
delete config.developer_instructions;
|
|
1111
|
+
}
|
|
1112
|
+
const tomlContent = stringifyToml(config);
|
|
1113
|
+
await writeFile3(CODEX_CONFIG_PATH, tomlContent, "utf-8");
|
|
1114
|
+
console.log("[CodexManager] Updated config.toml with developer_instructions");
|
|
1115
|
+
} catch (error) {
|
|
1116
|
+
console.error("[CodexManager] Failed to update config.toml:", error);
|
|
1117
|
+
}
|
|
1073
1118
|
}
|
|
1074
1119
|
/**
|
|
1075
1120
|
* Helper method to save normalized images to temp files for Codex SDK
|
|
@@ -1099,36 +1144,31 @@ var CodexManager = class {
|
|
|
1099
1144
|
const normalizedImages = await normalizeImages(images);
|
|
1100
1145
|
tempImagePaths = await this.saveImagesToTempFiles(normalizedImages);
|
|
1101
1146
|
}
|
|
1147
|
+
const startHooksInstruction = this.getStartHooksInstruction();
|
|
1148
|
+
const parts = [];
|
|
1149
|
+
if (this.baseSystemPrompt) {
|
|
1150
|
+
parts.push(this.baseSystemPrompt);
|
|
1151
|
+
}
|
|
1152
|
+
if (startHooksInstruction) {
|
|
1153
|
+
parts.push(startHooksInstruction);
|
|
1154
|
+
}
|
|
1155
|
+
if (customInstructions) {
|
|
1156
|
+
parts.push(customInstructions);
|
|
1157
|
+
}
|
|
1158
|
+
const developerInstructions = parts.length > 0 ? parts.join("\n\n") : void 0;
|
|
1159
|
+
await this.updateCodexConfig(developerInstructions);
|
|
1102
1160
|
const sandboxMode = "danger-full-access";
|
|
1161
|
+
const threadOptions = {
|
|
1162
|
+
workingDirectory: this.workingDirectory,
|
|
1163
|
+
skipGitRepoCheck: true,
|
|
1164
|
+
sandboxMode,
|
|
1165
|
+
model: model || DEFAULT_MODEL,
|
|
1166
|
+
webSearchMode: "live"
|
|
1167
|
+
};
|
|
1103
1168
|
if (this.currentThreadId) {
|
|
1104
|
-
this.currentThread = this.codex.resumeThread(this.currentThreadId,
|
|
1105
|
-
workingDirectory: this.workingDirectory,
|
|
1106
|
-
skipGitRepoCheck: true,
|
|
1107
|
-
sandboxMode,
|
|
1108
|
-
model: model || DEFAULT_MODEL
|
|
1109
|
-
});
|
|
1169
|
+
this.currentThread = this.codex.resumeThread(this.currentThreadId, threadOptions);
|
|
1110
1170
|
} else {
|
|
1111
|
-
this.currentThread = this.codex.startThread(
|
|
1112
|
-
workingDirectory: this.workingDirectory,
|
|
1113
|
-
skipGitRepoCheck: true,
|
|
1114
|
-
sandboxMode,
|
|
1115
|
-
model: model || DEFAULT_MODEL
|
|
1116
|
-
});
|
|
1117
|
-
const startHooksInstruction = this.getStartHooksInstruction();
|
|
1118
|
-
const parts = [];
|
|
1119
|
-
if (this.baseSystemPrompt) {
|
|
1120
|
-
parts.push(this.baseSystemPrompt);
|
|
1121
|
-
}
|
|
1122
|
-
if (startHooksInstruction) {
|
|
1123
|
-
parts.push(startHooksInstruction);
|
|
1124
|
-
}
|
|
1125
|
-
if (customInstructions) {
|
|
1126
|
-
parts.push(customInstructions);
|
|
1127
|
-
}
|
|
1128
|
-
const combinedInstructions = parts.length > 0 ? parts.join("\n\n") : void 0;
|
|
1129
|
-
if (combinedInstructions) {
|
|
1130
|
-
message = combinedInstructions + "\n\n\n" + message;
|
|
1131
|
-
}
|
|
1171
|
+
this.currentThread = this.codex.startThread(threadOptions);
|
|
1132
1172
|
const { events: events2 } = await this.currentThread.runStreamed("Hello");
|
|
1133
1173
|
for await (const event of events2) {
|
|
1134
1174
|
if (event.type === "thread.started") {
|
|
@@ -1883,8 +1923,8 @@ var claude_default = claude;
|
|
|
1883
1923
|
import { Hono as Hono3 } from "hono";
|
|
1884
1924
|
|
|
1885
1925
|
// src/services/plans-service.ts
|
|
1886
|
-
import { readFile as
|
|
1887
|
-
import { existsSync as
|
|
1926
|
+
import { readFile as readFile5, readdir as readdir2, mkdir as mkdir5 } from "fs/promises";
|
|
1927
|
+
import { existsSync as existsSync4 } from "fs";
|
|
1888
1928
|
import { join as join5, basename } from "path";
|
|
1889
1929
|
import { homedir as homedir5 } from "os";
|
|
1890
1930
|
var PLANS_DIR = join5(homedir5(), ".replicas", "plans");
|
|
@@ -1897,10 +1937,10 @@ function isValidFilename(filename) {
|
|
|
1897
1937
|
return safePattern.test(filename);
|
|
1898
1938
|
}
|
|
1899
1939
|
async function ensurePlansDir() {
|
|
1900
|
-
if (!
|
|
1940
|
+
if (!existsSync4(PLANS_DIR)) {
|
|
1901
1941
|
await mkdir5(PLANS_DIR, { recursive: true });
|
|
1902
1942
|
}
|
|
1903
|
-
if (!
|
|
1943
|
+
if (!existsSync4(CLAUDE_PLANS_DIR)) {
|
|
1904
1944
|
await mkdir5(CLAUDE_PLANS_DIR, { recursive: true });
|
|
1905
1945
|
}
|
|
1906
1946
|
}
|
|
@@ -1921,11 +1961,11 @@ async function getPlanContent(filename) {
|
|
|
1921
1961
|
const safeName = basename(filename);
|
|
1922
1962
|
const replicasPath = join5(PLANS_DIR, safeName);
|
|
1923
1963
|
const claudePath = join5(CLAUDE_PLANS_DIR, safeName);
|
|
1924
|
-
if (
|
|
1925
|
-
return await
|
|
1964
|
+
if (existsSync4(replicasPath)) {
|
|
1965
|
+
return await readFile5(replicasPath, "utf-8");
|
|
1926
1966
|
}
|
|
1927
|
-
if (
|
|
1928
|
-
return await
|
|
1967
|
+
if (existsSync4(claudePath)) {
|
|
1968
|
+
return await readFile5(claudePath, "utf-8");
|
|
1929
1969
|
}
|
|
1930
1970
|
throw new Error("Plan not found");
|
|
1931
1971
|
}
|
|
@@ -2232,7 +2272,7 @@ var CodexTokenManager = class {
|
|
|
2232
2272
|
var codexTokenManager = new CodexTokenManager();
|
|
2233
2273
|
|
|
2234
2274
|
// src/services/git-init.ts
|
|
2235
|
-
import { existsSync as
|
|
2275
|
+
import { existsSync as existsSync5 } from "fs";
|
|
2236
2276
|
import path4 from "path";
|
|
2237
2277
|
var initializedBranch = null;
|
|
2238
2278
|
function findAvailableBranchName(baseName, cwd) {
|
|
@@ -2268,7 +2308,7 @@ async function initializeGitRepository() {
|
|
|
2268
2308
|
};
|
|
2269
2309
|
}
|
|
2270
2310
|
const repoPath = path4.join(workspaceHome, "workspaces", repoName);
|
|
2271
|
-
if (!
|
|
2311
|
+
if (!existsSync5(repoPath)) {
|
|
2272
2312
|
console.log(`[GitInit] Repository directory does not exist: ${repoPath}`);
|
|
2273
2313
|
console.log("[GitInit] Waiting for initializer to clone the repository...");
|
|
2274
2314
|
return {
|
|
@@ -2276,7 +2316,7 @@ async function initializeGitRepository() {
|
|
|
2276
2316
|
branch: null
|
|
2277
2317
|
};
|
|
2278
2318
|
}
|
|
2279
|
-
if (!
|
|
2319
|
+
if (!existsSync5(path4.join(repoPath, ".git"))) {
|
|
2280
2320
|
return {
|
|
2281
2321
|
success: false,
|
|
2282
2322
|
branch: null,
|
|
@@ -2359,7 +2399,7 @@ function checkActiveSSHSessions() {
|
|
|
2359
2399
|
var app = new Hono4();
|
|
2360
2400
|
app.get("/health", async (c) => {
|
|
2361
2401
|
try {
|
|
2362
|
-
const logContent = await
|
|
2402
|
+
const logContent = await readFile6("/var/log/cloud-init-output.log", "utf-8");
|
|
2363
2403
|
let status;
|
|
2364
2404
|
if (logContent.includes(COMPLETION_MESSAGE)) {
|
|
2365
2405
|
status = "active";
|