@wix/ditto-codegen-public 1.0.440 → 1.0.442
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/out.js +478 -130
- package/package.json +2 -2
package/dist/out.js
CHANGED
|
@@ -544,7 +544,15 @@ var require_context = __commonJS({
|
|
|
544
544
|
var types_1 = require_types_impl();
|
|
545
545
|
var dotenv_1 = __importDefault2(require_main());
|
|
546
546
|
var path_12 = __importDefault2(require("path"));
|
|
547
|
+
var provisioned = {
|
|
548
|
+
CODEGEN_JOB_DELIVERY: process.env.CODEGEN_JOB_DELIVERY,
|
|
549
|
+
CODEGEN_JOB_FETCH_PORT: process.env.CODEGEN_JOB_FETCH_PORT
|
|
550
|
+
};
|
|
547
551
|
dotenv_1.default.config({ path: path_12.default.join(__dirname, "../.env"), override: true });
|
|
552
|
+
for (const [key, value] of Object.entries(provisioned)) {
|
|
553
|
+
if (value?.trim())
|
|
554
|
+
process.env[key] = value;
|
|
555
|
+
}
|
|
548
556
|
var HistoryManager = class {
|
|
549
557
|
constructor() {
|
|
550
558
|
this.history = [];
|
|
@@ -11032,7 +11040,7 @@ var require_CodeGenService = __commonJS({
|
|
|
11032
11040
|
"dist/services/CodeGenService.js"(exports2) {
|
|
11033
11041
|
"use strict";
|
|
11034
11042
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
11035
|
-
exports2.CodeGenService = exports2.JobsSortOrder = exports2.TaskKind = exports2.Status = void 0;
|
|
11043
|
+
exports2.CodeGenService = exports2.FETCH_TIMEOUT_MS = exports2.REQUEST_TIMEOUT_MS = exports2.JobsSortOrder = exports2.TaskKind = exports2.Status = void 0;
|
|
11036
11044
|
exports2.createCodeGenErrorHandler = createCodeGenErrorHandler;
|
|
11037
11045
|
var http_client_1 = require_index_node();
|
|
11038
11046
|
var http_1 = require_http_impl();
|
|
@@ -11116,6 +11124,14 @@ var require_CodeGenService = __commonJS({
|
|
|
11116
11124
|
}
|
|
11117
11125
|
};
|
|
11118
11126
|
}
|
|
11127
|
+
exports2.REQUEST_TIMEOUT_MS = 12e4;
|
|
11128
|
+
exports2.FETCH_TIMEOUT_MS = 3e4;
|
|
11129
|
+
function isNotFound(error) {
|
|
11130
|
+
return http_client_1.HttpClient.isHttpError(error) && error.response?.status === 404;
|
|
11131
|
+
}
|
|
11132
|
+
function mapRequest(req, fn) {
|
|
11133
|
+
return typeof req === "function" ? (ctx) => fn(req(ctx)) : fn(req);
|
|
11134
|
+
}
|
|
11119
11135
|
var CodeGenService = class {
|
|
11120
11136
|
constructor(projectId, httpClient) {
|
|
11121
11137
|
this.projectId = projectId;
|
|
@@ -11126,15 +11142,16 @@ var require_CodeGenService = __commonJS({
|
|
|
11126
11142
|
this.setAccessToken(token);
|
|
11127
11143
|
return token;
|
|
11128
11144
|
};
|
|
11129
|
-
this.request = async (req) => {
|
|
11145
|
+
this.request = async (req, timeout) => {
|
|
11146
|
+
const build = () => this.withTimeout(this.withAuth(req), timeout);
|
|
11130
11147
|
try {
|
|
11131
|
-
return await this.httpClient.request(
|
|
11148
|
+
return await this.httpClient.request(build());
|
|
11132
11149
|
} catch (err) {
|
|
11133
11150
|
if (!this.isUnauthorized(err))
|
|
11134
11151
|
throw err;
|
|
11135
11152
|
logger_12.logger.warn("[CodeGenService] 401 received, refreshing token and retrying once");
|
|
11136
11153
|
await this.refreshAccessToken();
|
|
11137
|
-
return await this.httpClient.request(
|
|
11154
|
+
return await this.httpClient.request(build());
|
|
11138
11155
|
}
|
|
11139
11156
|
};
|
|
11140
11157
|
this.fetchPendingJobs = async () => {
|
|
@@ -11145,10 +11162,19 @@ var require_CodeGenService = __commonJS({
|
|
|
11145
11162
|
paging: { limit: 1 },
|
|
11146
11163
|
sortOrder: types_1.JobsSortOrder.CREATED_AT_ASC
|
|
11147
11164
|
} : void 0;
|
|
11148
|
-
const resp = await this.request((0, http_1.listProjectJobs)(filtered ?? { projectId: this.projectId }));
|
|
11165
|
+
const resp = await this.request((0, http_1.listProjectJobs)(filtered ?? { projectId: this.projectId }), exports2.FETCH_TIMEOUT_MS);
|
|
11149
11166
|
const jobs = resp.data?.jobs ?? [];
|
|
11150
11167
|
return filtered ? jobs : jobs.filter(this.shouldProcessJob);
|
|
11151
11168
|
};
|
|
11169
|
+
this.findJob = async (jobId) => {
|
|
11170
|
+
try {
|
|
11171
|
+
return await this.getJob(jobId, exports2.FETCH_TIMEOUT_MS);
|
|
11172
|
+
} catch (error) {
|
|
11173
|
+
if (isNotFound(error))
|
|
11174
|
+
return null;
|
|
11175
|
+
throw error;
|
|
11176
|
+
}
|
|
11177
|
+
};
|
|
11152
11178
|
this.shouldProcessJob = (job) => {
|
|
11153
11179
|
if (job.status !== types_1.Status.PENDING)
|
|
11154
11180
|
return false;
|
|
@@ -11279,11 +11305,11 @@ var require_CodeGenService = __commonJS({
|
|
|
11279
11305
|
}
|
|
11280
11306
|
}));
|
|
11281
11307
|
};
|
|
11282
|
-
this.getJob = async (jobId) => {
|
|
11308
|
+
this.getJob = async (jobId, timeout) => {
|
|
11283
11309
|
const resp = await this.request((0, http_1.getJob)({
|
|
11284
11310
|
projectId: this.projectId,
|
|
11285
11311
|
jobId
|
|
11286
|
-
}));
|
|
11312
|
+
}), timeout);
|
|
11287
11313
|
return resp.data?.job ?? null;
|
|
11288
11314
|
};
|
|
11289
11315
|
this.runContext = (ctx) => ({
|
|
@@ -11329,6 +11355,7 @@ var require_CodeGenService = __commonJS({
|
|
|
11329
11355
|
const serverUrl = process.env.CODEGEN_SERVER_BASE_URL || "https://manage.wix.com";
|
|
11330
11356
|
this.httpClient = (0, http_client_1.createHttpClient)({
|
|
11331
11357
|
baseURL: serverUrl,
|
|
11358
|
+
timeout: exports2.REQUEST_TIMEOUT_MS,
|
|
11332
11359
|
errorHandler: createCodeGenErrorHandler(() => this.httpClient)
|
|
11333
11360
|
});
|
|
11334
11361
|
}
|
|
@@ -11346,14 +11373,16 @@ var require_CodeGenService = __commonJS({
|
|
|
11346
11373
|
return error.response?.status === 401;
|
|
11347
11374
|
}
|
|
11348
11375
|
withAuth(req) {
|
|
11349
|
-
|
|
11350
|
-
|
|
11351
|
-
|
|
11352
|
-
|
|
11353
|
-
|
|
11354
|
-
}
|
|
11355
|
-
}
|
|
11356
|
-
|
|
11376
|
+
return mapRequest(req, (r) => ({
|
|
11377
|
+
...r,
|
|
11378
|
+
headers: {
|
|
11379
|
+
...r.headers ?? {},
|
|
11380
|
+
authorization: `Bearer ${this.accessToken}`
|
|
11381
|
+
}
|
|
11382
|
+
}));
|
|
11383
|
+
}
|
|
11384
|
+
withTimeout(req, timeout) {
|
|
11385
|
+
return timeout === void 0 ? req : mapRequest(req, (r) => ({ ...r, timeout }));
|
|
11357
11386
|
}
|
|
11358
11387
|
};
|
|
11359
11388
|
exports2.CodeGenService = CodeGenService;
|
|
@@ -12075,80 +12104,6 @@ var require_rules_writer = __commonJS({
|
|
|
12075
12104
|
}
|
|
12076
12105
|
});
|
|
12077
12106
|
|
|
12078
|
-
// dist/opencode-integration/generated-plugins.js
|
|
12079
|
-
var require_generated_plugins = __commonJS({
|
|
12080
|
-
"dist/opencode-integration/generated-plugins.js"(exports2) {
|
|
12081
|
-
"use strict";
|
|
12082
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
12083
|
-
exports2.OPENCODE_PLUGIN_DIR = void 0;
|
|
12084
|
-
exports2.writeGeneratedPlugin = writeGeneratedPlugin;
|
|
12085
|
-
var promises_1 = require("fs/promises");
|
|
12086
|
-
var os_1 = require("os");
|
|
12087
|
-
var path_12 = require("path");
|
|
12088
|
-
var logger_12 = require_logger();
|
|
12089
|
-
exports2.OPENCODE_PLUGIN_DIR = (0, path_12.join)((0, os_1.homedir)(), ".config", "opencode", "plugin");
|
|
12090
|
-
async function writeGeneratedPlugin(filename, source) {
|
|
12091
|
-
await (0, promises_1.mkdir)(exports2.OPENCODE_PLUGIN_DIR, { recursive: true });
|
|
12092
|
-
await (0, promises_1.writeFile)((0, path_12.join)(exports2.OPENCODE_PLUGIN_DIR, filename), source, "utf-8");
|
|
12093
|
-
logger_12.logger.info("[OpenCode] Wrote generated plugin", { plugin: filename });
|
|
12094
|
-
}
|
|
12095
|
-
}
|
|
12096
|
-
});
|
|
12097
|
-
|
|
12098
|
-
// dist/opencode-integration/node-modules-guard.js
|
|
12099
|
-
var require_node_modules_guard = __commonJS({
|
|
12100
|
-
"dist/opencode-integration/node-modules-guard.js"(exports2) {
|
|
12101
|
-
"use strict";
|
|
12102
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
12103
|
-
exports2.GUARD_PLUGIN_PATH = exports2.GUARD_MESSAGE = exports2.MAX_SPELUNK_CALLS = void 0;
|
|
12104
|
-
exports2.isSpelunkCommand = isSpelunkCommand;
|
|
12105
|
-
exports2.buildGuardPluginSource = buildGuardPluginSource;
|
|
12106
|
-
exports2.writeGuardPlugin = writeGuardPlugin;
|
|
12107
|
-
var path_12 = require("path");
|
|
12108
|
-
var generated_plugins_1 = require_generated_plugins();
|
|
12109
|
-
var READ_VERB_RE = /(^|[\s|;&(])(grep|rg|cat|head|tail|sed|awk|less|more|strings|find)\b/;
|
|
12110
|
-
var SDK_INTERNALS_RE = /node_modules\/(@wix|vite|astro)\b/;
|
|
12111
|
-
exports2.MAX_SPELUNK_CALLS = 2;
|
|
12112
|
-
exports2.GUARD_MESSAGE = `BLOCKED: node_modules is not a documentation source, and the exploratory budget (${exports2.MAX_SPELUNK_CALLS} lookups) is used up. The API you are hunting is already documented:
|
|
12113
|
-
- Wix Data items CRUD: import { items } from "@wix/data" (items.query/get/insert/update/remove).
|
|
12114
|
-
- Dashboard host SDK (toasts, navigation): import { dashboard } from "@wix/dashboard".
|
|
12115
|
-
For anything more (CSS-module/asset typing, component config, etc.), re-read the wix-app skill's references with batch-read, or call SearchWixSDKDocumentation / ReadFullDocsMethodSchema. Do not retry this command.`;
|
|
12116
|
-
function isSpelunkCommand(command) {
|
|
12117
|
-
return READ_VERB_RE.test(command) && SDK_INTERNALS_RE.test(command);
|
|
12118
|
-
}
|
|
12119
|
-
var GUARD_PLUGIN_FILENAME = "node-modules-guard.ts";
|
|
12120
|
-
exports2.GUARD_PLUGIN_PATH = (0, path_12.join)(generated_plugins_1.OPENCODE_PLUGIN_DIR, GUARD_PLUGIN_FILENAME);
|
|
12121
|
-
function buildGuardPluginSource() {
|
|
12122
|
-
return `// Generated by @wix/ditto-codegen (node-modules-guard) \u2014 do not edit.
|
|
12123
|
-
const READ_VERB_RE = /${READ_VERB_RE.source}/;
|
|
12124
|
-
const SDK_INTERNALS_RE = /${SDK_INTERNALS_RE.source}/;
|
|
12125
|
-
const MAX_SPELUNK_CALLS = ${exports2.MAX_SPELUNK_CALLS};
|
|
12126
|
-
const GUARD_MESSAGE = ${JSON.stringify(exports2.GUARD_MESSAGE)};
|
|
12127
|
-
|
|
12128
|
-
let spelunkCalls = 0;
|
|
12129
|
-
|
|
12130
|
-
export const NodeModulesGuard = async () => ({
|
|
12131
|
-
"tool.execute.before": async (
|
|
12132
|
-
input: { tool: string },
|
|
12133
|
-
output: { args: { command?: string } },
|
|
12134
|
-
) => {
|
|
12135
|
-
if (input.tool !== "bash") return;
|
|
12136
|
-
const command = output.args?.command ?? "";
|
|
12137
|
-
if (!READ_VERB_RE.test(command) || !SDK_INTERNALS_RE.test(command)) return;
|
|
12138
|
-
spelunkCalls += 1;
|
|
12139
|
-
if (spelunkCalls > MAX_SPELUNK_CALLS) {
|
|
12140
|
-
throw new Error(GUARD_MESSAGE);
|
|
12141
|
-
}
|
|
12142
|
-
},
|
|
12143
|
-
});
|
|
12144
|
-
`;
|
|
12145
|
-
}
|
|
12146
|
-
async function writeGuardPlugin() {
|
|
12147
|
-
await (0, generated_plugins_1.writeGeneratedPlugin)(GUARD_PLUGIN_FILENAME, buildGuardPluginSource());
|
|
12148
|
-
}
|
|
12149
|
-
}
|
|
12150
|
-
});
|
|
12151
|
-
|
|
12152
12107
|
// ../../node_modules/@wix/ambassador-ctp-ditto-v1-blueprint/cjs/build/types.impl.js
|
|
12153
12108
|
var require_types_impl2 = __commonJS({
|
|
12154
12109
|
"../../node_modules/@wix/ambassador-ctp-ditto-v1-blueprint/cjs/build/types.impl.js"(exports2) {
|
|
@@ -15705,7 +15660,6 @@ var require_config = __commonJS({
|
|
|
15705
15660
|
var constants_1 = require_constants5();
|
|
15706
15661
|
var subagents_1 = require_subagents();
|
|
15707
15662
|
var rules_writer_12 = require_rules_writer();
|
|
15708
|
-
var node_modules_guard_12 = require_node_modules_guard();
|
|
15709
15663
|
var environments_12 = require_environments();
|
|
15710
15664
|
var CodeGenService_12 = require_CodeGenService();
|
|
15711
15665
|
exports2.DEFAULT_TIMEOUT_MS = 20 * 60 * 1e3;
|
|
@@ -15843,7 +15797,7 @@ var require_config = __commonJS({
|
|
|
15843
15797
|
]: "deny",
|
|
15844
15798
|
external_directory: READABLE_EXTERNAL_DIRS
|
|
15845
15799
|
};
|
|
15846
|
-
function buildConfig(instructionPaths, permission, {
|
|
15800
|
+
function buildConfig(instructionPaths, permission, { isCodeWritingFlow = false, withAgents = false } = {}) {
|
|
15847
15801
|
return {
|
|
15848
15802
|
model: exports2.DEFAULT_MODEL,
|
|
15849
15803
|
small_model: exports2.DEFAULT_SMALL_MODEL,
|
|
@@ -15855,7 +15809,7 @@ var require_config = __commonJS({
|
|
|
15855
15809
|
lsp: false,
|
|
15856
15810
|
mcp: WIX_MCP_CONFIG,
|
|
15857
15811
|
watcher: { ignore: WATCHER_IGNORE_PATTERNS },
|
|
15858
|
-
...
|
|
15812
|
+
...isCodeWritingFlow ? { autoupdate: false, share: "disabled" } : {},
|
|
15859
15813
|
// Only code-writing flows register subagents. The read-only ask flow must
|
|
15860
15814
|
// not: its primary agent re-opens `task`, which would let the write-capable
|
|
15861
15815
|
// validator subagent run in a flow meant to stay read-only.
|
|
@@ -15896,12 +15850,12 @@ var require_config = __commonJS({
|
|
|
15896
15850
|
return buildConfig(paths(env.askRules), ASK_PERMISSIONS);
|
|
15897
15851
|
case CodeGenService_12.TaskKind.FIX_GIT_CONFLICTS:
|
|
15898
15852
|
return buildConfig(paths(env.gitConflictsRules), GIT_CONFLICTS_PERMISSIONS, {
|
|
15899
|
-
|
|
15853
|
+
isCodeWritingFlow: true,
|
|
15900
15854
|
withAgents: true
|
|
15901
15855
|
});
|
|
15902
15856
|
default:
|
|
15903
15857
|
return buildConfig(paths(env.codegenRules), CODEGEN_PERMISSIONS, {
|
|
15904
|
-
|
|
15858
|
+
isCodeWritingFlow: true,
|
|
15905
15859
|
withAgents: true
|
|
15906
15860
|
});
|
|
15907
15861
|
}
|
|
@@ -15909,6 +15863,26 @@ var require_config = __commonJS({
|
|
|
15909
15863
|
}
|
|
15910
15864
|
});
|
|
15911
15865
|
|
|
15866
|
+
// dist/opencode-integration/generated-plugins.js
|
|
15867
|
+
var require_generated_plugins = __commonJS({
|
|
15868
|
+
"dist/opencode-integration/generated-plugins.js"(exports2) {
|
|
15869
|
+
"use strict";
|
|
15870
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15871
|
+
exports2.OPENCODE_PLUGIN_DIR = void 0;
|
|
15872
|
+
exports2.writeGeneratedPlugin = writeGeneratedPlugin;
|
|
15873
|
+
var promises_1 = require("fs/promises");
|
|
15874
|
+
var os_1 = require("os");
|
|
15875
|
+
var path_12 = require("path");
|
|
15876
|
+
var logger_12 = require_logger();
|
|
15877
|
+
exports2.OPENCODE_PLUGIN_DIR = (0, path_12.join)((0, os_1.homedir)(), ".config", "opencode", "plugin");
|
|
15878
|
+
async function writeGeneratedPlugin(filename, source) {
|
|
15879
|
+
await (0, promises_1.mkdir)(exports2.OPENCODE_PLUGIN_DIR, { recursive: true });
|
|
15880
|
+
await (0, promises_1.writeFile)((0, path_12.join)(exports2.OPENCODE_PLUGIN_DIR, filename), source, "utf-8");
|
|
15881
|
+
logger_12.logger.info("[OpenCode] Wrote generated plugin", { plugin: filename });
|
|
15882
|
+
}
|
|
15883
|
+
}
|
|
15884
|
+
});
|
|
15885
|
+
|
|
15912
15886
|
// dist/opencode-integration/subagent-tool-logger.js
|
|
15913
15887
|
var require_subagent_tool_logger = __commonJS({
|
|
15914
15888
|
"dist/opencode-integration/subagent-tool-logger.js"(exports2) {
|
|
@@ -16563,11 +16537,13 @@ var require_utils9 = __commonJS({
|
|
|
16563
16537
|
"dist/utils.js"(exports2) {
|
|
16564
16538
|
"use strict";
|
|
16565
16539
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16566
|
-
exports2.errorStack = void 0;
|
|
16540
|
+
exports2.errorStack = exports2.delay = void 0;
|
|
16567
16541
|
exports2.serializeError = serializeError;
|
|
16568
16542
|
exports2.updateAllRunningTasks = updateAllRunningTasks;
|
|
16569
16543
|
var types_1 = require_types_impl();
|
|
16570
16544
|
var codeGenerationService_12 = require_codeGenerationService();
|
|
16545
|
+
var delay = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
16546
|
+
exports2.delay = delay;
|
|
16571
16547
|
var errorStack = (error) => error instanceof Error ? error.stack ?? error.message : String(error);
|
|
16572
16548
|
exports2.errorStack = errorStack;
|
|
16573
16549
|
function serializeError(error) {
|
|
@@ -23815,7 +23791,7 @@ var require_skills_installer = __commonJS({
|
|
|
23815
23791
|
const nested = discoverSkills((0, path_12.join)(packageRoot, "skills"));
|
|
23816
23792
|
return nested.length > 0 ? nested : discoverSkills(packageRoot);
|
|
23817
23793
|
}
|
|
23818
|
-
var
|
|
23794
|
+
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
23819
23795
|
async function applySkillsOverride(outputPath, log) {
|
|
23820
23796
|
const skillsOverride = process.env.SKILLS_OVERRIDE_BRANCH;
|
|
23821
23797
|
if (!skillsOverride) {
|
|
@@ -23861,7 +23837,7 @@ var require_skills_installer = __commonJS({
|
|
|
23861
23837
|
});
|
|
23862
23838
|
const deadline = Date.now() + timeoutMs;
|
|
23863
23839
|
while (Date.now() < deadline) {
|
|
23864
|
-
await
|
|
23840
|
+
await delay(intervalMs);
|
|
23865
23841
|
state = inspect(state.candidates);
|
|
23866
23842
|
if (state.ready) {
|
|
23867
23843
|
log.info("[Skills] Skills became available", { present: state.present });
|
|
@@ -24268,6 +24244,367 @@ var require_plugin_artifacts = __commonJS({
|
|
|
24268
24244
|
}
|
|
24269
24245
|
});
|
|
24270
24246
|
|
|
24247
|
+
// dist/fetch-scheduler.js
|
|
24248
|
+
var require_fetch_scheduler = __commonJS({
|
|
24249
|
+
"dist/fetch-scheduler.js"(exports2) {
|
|
24250
|
+
"use strict";
|
|
24251
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
24252
|
+
exports2.FetchScheduler = exports2.MAX_AWAITED_JOB_IDS = exports2.MAX_MISSING_JOB_RECHECKS = exports2.ERROR_BACKOFF_MS = exports2.POST_JOB_INTERVAL_MS = exports2.MIN_FETCH_INTERVAL_MS = void 0;
|
|
24253
|
+
var logger_12 = require_logger();
|
|
24254
|
+
var utils_12 = require_utils9();
|
|
24255
|
+
exports2.MIN_FETCH_INTERVAL_MS = 1e3;
|
|
24256
|
+
exports2.POST_JOB_INTERVAL_MS = 3e3;
|
|
24257
|
+
exports2.ERROR_BACKOFF_MS = 5e3;
|
|
24258
|
+
exports2.MAX_MISSING_JOB_RECHECKS = 3;
|
|
24259
|
+
exports2.MAX_AWAITED_JOB_IDS = 4;
|
|
24260
|
+
var FetchScheduler = class {
|
|
24261
|
+
constructor(deps) {
|
|
24262
|
+
this.deps = deps;
|
|
24263
|
+
this.cycle = null;
|
|
24264
|
+
this.checkAgain = false;
|
|
24265
|
+
this.stopped = false;
|
|
24266
|
+
this.nextFetchNotBefore = 0;
|
|
24267
|
+
this.interval = 0;
|
|
24268
|
+
this.awaitedJobIds = /* @__PURE__ */ new Map();
|
|
24269
|
+
}
|
|
24270
|
+
start() {
|
|
24271
|
+
this.stopped = false;
|
|
24272
|
+
}
|
|
24273
|
+
/** A cycle already inside runJob is NOT awaited. A caller that needs exclusivity must
|
|
24274
|
+
* not start another runner until that cycle settles. */
|
|
24275
|
+
stop() {
|
|
24276
|
+
this.stopped = true;
|
|
24277
|
+
}
|
|
24278
|
+
/** Records the nudge and makes sure a cycle is running. It does not wait for the
|
|
24279
|
+
* fetch. A caller held on a slow socket times out and reads that as "machine down",
|
|
24280
|
+
* so retrying is ours to do, not theirs. */
|
|
24281
|
+
nudge(jobId) {
|
|
24282
|
+
if (this.stopped)
|
|
24283
|
+
return;
|
|
24284
|
+
if (jobId) {
|
|
24285
|
+
this.awaitedJobIds.delete(jobId);
|
|
24286
|
+
if (this.awaitedJobIds.size >= exports2.MAX_AWAITED_JOB_IDS) {
|
|
24287
|
+
this.awaitedJobIds.delete(this.awaitedJobIds.keys().next().value);
|
|
24288
|
+
}
|
|
24289
|
+
this.awaitedJobIds.set(jobId, exports2.MAX_MISSING_JOB_RECHECKS);
|
|
24290
|
+
}
|
|
24291
|
+
if (this.cycle) {
|
|
24292
|
+
this.checkAgain = true;
|
|
24293
|
+
return;
|
|
24294
|
+
}
|
|
24295
|
+
this.cycle = this.runUntilIdle().catch((error) => logger_12.logger.error("[JobFetch] Cycle aborted", { error: (0, utils_12.errorStack)(error) }));
|
|
24296
|
+
}
|
|
24297
|
+
async runUntilIdle() {
|
|
24298
|
+
try {
|
|
24299
|
+
do {
|
|
24300
|
+
await this.runSingleJobCycle();
|
|
24301
|
+
} while (this.checkAgain && !this.stopped);
|
|
24302
|
+
} finally {
|
|
24303
|
+
this.cycle = null;
|
|
24304
|
+
}
|
|
24305
|
+
}
|
|
24306
|
+
async runSingleJobCycle() {
|
|
24307
|
+
await this.throttle();
|
|
24308
|
+
if (this.stopped)
|
|
24309
|
+
return;
|
|
24310
|
+
this.checkAgain = false;
|
|
24311
|
+
const due = await this.findRunnableJob();
|
|
24312
|
+
if (!due)
|
|
24313
|
+
return;
|
|
24314
|
+
this.checkAgain = true;
|
|
24315
|
+
if (this.stopped)
|
|
24316
|
+
return;
|
|
24317
|
+
await this.attemptJob(due);
|
|
24318
|
+
}
|
|
24319
|
+
async findRunnableJob() {
|
|
24320
|
+
let jobs;
|
|
24321
|
+
try {
|
|
24322
|
+
jobs = await this.deps.fetchPendingJobs();
|
|
24323
|
+
} catch (error) {
|
|
24324
|
+
this.recordDebt("Fetch failed", error);
|
|
24325
|
+
return null;
|
|
24326
|
+
}
|
|
24327
|
+
this.schedule(exports2.MIN_FETCH_INTERVAL_MS);
|
|
24328
|
+
logger_12.logger.info("[JobFetch] Fetched pending jobs", { count: jobs.length });
|
|
24329
|
+
for (const job of jobs) {
|
|
24330
|
+
if (job.id)
|
|
24331
|
+
this.awaitedJobIds.delete(job.id);
|
|
24332
|
+
}
|
|
24333
|
+
if (jobs.length > 0)
|
|
24334
|
+
return jobs[0];
|
|
24335
|
+
if (this.awaitedJobIds.size === 0)
|
|
24336
|
+
return null;
|
|
24337
|
+
try {
|
|
24338
|
+
return await this.claimNudgedJob();
|
|
24339
|
+
} catch (error) {
|
|
24340
|
+
this.recordDebt("Nudged job lookup failed", error);
|
|
24341
|
+
return null;
|
|
24342
|
+
}
|
|
24343
|
+
}
|
|
24344
|
+
async attemptJob(job) {
|
|
24345
|
+
try {
|
|
24346
|
+
await this.deps.runJob(job);
|
|
24347
|
+
this.schedule(exports2.POST_JOB_INTERVAL_MS);
|
|
24348
|
+
} catch (error) {
|
|
24349
|
+
this.recordDebt("Job run failed", error);
|
|
24350
|
+
}
|
|
24351
|
+
}
|
|
24352
|
+
/** A nudged job the list did not return. Read it by key, which does not wait on the
|
|
24353
|
+
* index. A key read is still a replica read, so a job the server does not know about
|
|
24354
|
+
* yet keeps a small budget of re-checks instead of one answer settling it. */
|
|
24355
|
+
async claimNudgedJob() {
|
|
24356
|
+
for (const jobId of [...this.awaitedJobIds.keys()]) {
|
|
24357
|
+
if (this.stopped)
|
|
24358
|
+
return null;
|
|
24359
|
+
const job = await this.deps.findJob(jobId);
|
|
24360
|
+
if (job) {
|
|
24361
|
+
this.awaitedJobIds.delete(jobId);
|
|
24362
|
+
if (this.deps.canRunJob(job))
|
|
24363
|
+
return job;
|
|
24364
|
+
continue;
|
|
24365
|
+
}
|
|
24366
|
+
const rechecksLeft = this.awaitedJobIds.get(jobId);
|
|
24367
|
+
if (rechecksLeft === void 0)
|
|
24368
|
+
continue;
|
|
24369
|
+
if (rechecksLeft > 0) {
|
|
24370
|
+
this.awaitedJobIds.set(jobId, rechecksLeft - 1);
|
|
24371
|
+
this.checkAgain = true;
|
|
24372
|
+
} else {
|
|
24373
|
+
this.awaitedJobIds.delete(jobId);
|
|
24374
|
+
logger_12.logger.warn("[JobFetch] Nudged job does not exist", { jobId });
|
|
24375
|
+
}
|
|
24376
|
+
}
|
|
24377
|
+
return null;
|
|
24378
|
+
}
|
|
24379
|
+
schedule(intervalMs) {
|
|
24380
|
+
this.interval = intervalMs;
|
|
24381
|
+
this.nextFetchNotBefore = Date.now() + intervalMs;
|
|
24382
|
+
}
|
|
24383
|
+
/** Nobody else will retry. We already answered the caller 200. */
|
|
24384
|
+
recordDebt(what, error) {
|
|
24385
|
+
logger_12.logger.error(`[JobFetch] ${what}`, { error: (0, utils_12.errorStack)(error) });
|
|
24386
|
+
this.checkAgain = true;
|
|
24387
|
+
this.schedule(exports2.ERROR_BACKOFF_MS);
|
|
24388
|
+
}
|
|
24389
|
+
async throttle() {
|
|
24390
|
+
const wait = Math.min(this.nextFetchNotBefore - Date.now(), this.interval);
|
|
24391
|
+
if (wait > 0)
|
|
24392
|
+
await (0, utils_12.delay)(wait);
|
|
24393
|
+
}
|
|
24394
|
+
};
|
|
24395
|
+
exports2.FetchScheduler = FetchScheduler;
|
|
24396
|
+
}
|
|
24397
|
+
});
|
|
24398
|
+
|
|
24399
|
+
// dist/nudge-listener-server.js
|
|
24400
|
+
var require_nudge_listener_server = __commonJS({
|
|
24401
|
+
"dist/nudge-listener-server.js"(exports2) {
|
|
24402
|
+
"use strict";
|
|
24403
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
24404
|
+
exports2.NudgeListenerServer = exports2.BIND_RETRY_DELAY_MS = exports2.BIND_RETRIES = exports2.MAX_LOGGED_PATH_LENGTH = exports2.JOB_ID_PATTERN = exports2.JOB_FETCH_PATH = exports2.JOB_FETCH_PORT = void 0;
|
|
24405
|
+
var node_http_1 = require("node:http");
|
|
24406
|
+
var logger_12 = require_logger();
|
|
24407
|
+
var utils_12 = require_utils9();
|
|
24408
|
+
var fetch_scheduler_1 = require_fetch_scheduler();
|
|
24409
|
+
exports2.JOB_FETCH_PORT = 52402;
|
|
24410
|
+
exports2.JOB_FETCH_PATH = "/_wix/codegen/fetch-jobs";
|
|
24411
|
+
exports2.JOB_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
24412
|
+
exports2.MAX_LOGGED_PATH_LENGTH = 128;
|
|
24413
|
+
exports2.BIND_RETRIES = 5;
|
|
24414
|
+
exports2.BIND_RETRY_DELAY_MS = 300;
|
|
24415
|
+
var NudgeListenerServer = class {
|
|
24416
|
+
constructor(deps, port = exports2.JOB_FETCH_PORT) {
|
|
24417
|
+
this.port = port;
|
|
24418
|
+
this.server = null;
|
|
24419
|
+
this.stopped = false;
|
|
24420
|
+
this.scheduler = new fetch_scheduler_1.FetchScheduler(deps);
|
|
24421
|
+
}
|
|
24422
|
+
async start() {
|
|
24423
|
+
this.stopped = false;
|
|
24424
|
+
this.scheduler.start();
|
|
24425
|
+
await this.listen();
|
|
24426
|
+
if (this.stopped) {
|
|
24427
|
+
await this.stop();
|
|
24428
|
+
throw new Error("Nudge listener was stopped while binding");
|
|
24429
|
+
}
|
|
24430
|
+
logger_12.logger.info("[JobFetch] Endpoint listening", {
|
|
24431
|
+
port: this.boundPort(),
|
|
24432
|
+
path: exports2.JOB_FETCH_PATH
|
|
24433
|
+
});
|
|
24434
|
+
this.scheduler.nudge();
|
|
24435
|
+
}
|
|
24436
|
+
/** Closes the socket and stops the scheduler; a cycle already inside runJob is NOT
|
|
24437
|
+
* awaited. A caller that needs exclusivity must not start another runner until that
|
|
24438
|
+
* cycle settles. */
|
|
24439
|
+
async stop() {
|
|
24440
|
+
this.stopped = true;
|
|
24441
|
+
this.scheduler.stop();
|
|
24442
|
+
const server = this.server;
|
|
24443
|
+
if (!server)
|
|
24444
|
+
return;
|
|
24445
|
+
this.server = null;
|
|
24446
|
+
server.removeAllListeners("error");
|
|
24447
|
+
server.on("error", (error) => logger_12.logger.warn("[JobFetch] Endpoint error while closing", {
|
|
24448
|
+
error: (0, utils_12.errorStack)(error)
|
|
24449
|
+
}));
|
|
24450
|
+
server.closeAllConnections();
|
|
24451
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
24452
|
+
}
|
|
24453
|
+
boundPort() {
|
|
24454
|
+
const address = this.server?.address();
|
|
24455
|
+
return address && typeof address === "object" ? address.port : null;
|
|
24456
|
+
}
|
|
24457
|
+
/** The agent is restarted in a tight `while true` loop, so a bind can land before
|
|
24458
|
+
* the previous process has released the port. Falling straight back to poll there
|
|
24459
|
+
* would strand the machine on the slow path for the whole session. */
|
|
24460
|
+
async listen() {
|
|
24461
|
+
for (let attempt = 0; ; attempt++) {
|
|
24462
|
+
try {
|
|
24463
|
+
return await this.listenOnce();
|
|
24464
|
+
} catch (error) {
|
|
24465
|
+
const inUse = error?.code === "EADDRINUSE" && attempt < exports2.BIND_RETRIES;
|
|
24466
|
+
if (!inUse)
|
|
24467
|
+
throw error;
|
|
24468
|
+
await (0, utils_12.delay)(exports2.BIND_RETRY_DELAY_MS);
|
|
24469
|
+
}
|
|
24470
|
+
}
|
|
24471
|
+
}
|
|
24472
|
+
listenOnce() {
|
|
24473
|
+
return new Promise((resolve, reject) => {
|
|
24474
|
+
const server = (0, node_http_1.createServer)((req, res) => {
|
|
24475
|
+
try {
|
|
24476
|
+
this.handleRequest(req, res);
|
|
24477
|
+
} catch (error) {
|
|
24478
|
+
logger_12.logger.error("[JobFetch] Request handler failed", {
|
|
24479
|
+
error: (0, utils_12.errorStack)(error)
|
|
24480
|
+
});
|
|
24481
|
+
if (res.headersSent)
|
|
24482
|
+
res.destroy();
|
|
24483
|
+
else
|
|
24484
|
+
this.respond(res, 500, { error: "request failed" });
|
|
24485
|
+
}
|
|
24486
|
+
});
|
|
24487
|
+
server.once("error", reject);
|
|
24488
|
+
server.listen(this.port, "0.0.0.0", () => {
|
|
24489
|
+
server.removeListener("error", reject);
|
|
24490
|
+
server.on("error", (error) => {
|
|
24491
|
+
logger_12.logger.error("[JobFetch] Endpoint failed after binding, exiting", {
|
|
24492
|
+
error: (0, utils_12.errorStack)(error)
|
|
24493
|
+
});
|
|
24494
|
+
process.exit(1);
|
|
24495
|
+
});
|
|
24496
|
+
this.server = server;
|
|
24497
|
+
resolve();
|
|
24498
|
+
});
|
|
24499
|
+
});
|
|
24500
|
+
}
|
|
24501
|
+
handleRequest(req, res) {
|
|
24502
|
+
const url = new URL((req.url ?? "").replace(/^\/+/, "/"), "http://localhost");
|
|
24503
|
+
const path = url.pathname.replace(/\/+$/, "");
|
|
24504
|
+
if (req.method !== "GET" || path !== exports2.JOB_FETCH_PATH) {
|
|
24505
|
+
logger_12.logger.warn("[JobFetch] Rejected request", {
|
|
24506
|
+
method: req.method,
|
|
24507
|
+
path: url.pathname.slice(0, exports2.MAX_LOGGED_PATH_LENGTH)
|
|
24508
|
+
});
|
|
24509
|
+
this.respond(res, 404, { error: "not found" });
|
|
24510
|
+
return;
|
|
24511
|
+
}
|
|
24512
|
+
const nudgedId = url.searchParams.get("jobId");
|
|
24513
|
+
const usable = nudgedId === null || exports2.JOB_ID_PATTERN.test(nudgedId);
|
|
24514
|
+
if (!usable) {
|
|
24515
|
+
logger_12.logger.warn("[JobFetch] Nudge carried an unusable jobId", {
|
|
24516
|
+
length: nudgedId.length
|
|
24517
|
+
});
|
|
24518
|
+
}
|
|
24519
|
+
const jobId = usable ? nudgedId ?? void 0 : void 0;
|
|
24520
|
+
this.scheduler.nudge(jobId);
|
|
24521
|
+
logger_12.logger.info("[JobFetch] Nudge accepted", { jobId });
|
|
24522
|
+
this.respond(res, 200, { accepted: true });
|
|
24523
|
+
}
|
|
24524
|
+
respond(res, status, body) {
|
|
24525
|
+
res.writeHead(status, {
|
|
24526
|
+
"Content-Type": "application/json",
|
|
24527
|
+
// A cached response would turn every nudge into a no-op.
|
|
24528
|
+
"Cache-Control": "no-store"
|
|
24529
|
+
});
|
|
24530
|
+
res.end(JSON.stringify(body));
|
|
24531
|
+
}
|
|
24532
|
+
};
|
|
24533
|
+
exports2.NudgeListenerServer = NudgeListenerServer;
|
|
24534
|
+
}
|
|
24535
|
+
});
|
|
24536
|
+
|
|
24537
|
+
// dist/job-fetching.js
|
|
24538
|
+
var require_job_fetching = __commonJS({
|
|
24539
|
+
"dist/job-fetching.js"(exports2) {
|
|
24540
|
+
"use strict";
|
|
24541
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
24542
|
+
exports2.JobDeliveryMode = void 0;
|
|
24543
|
+
exports2.getJobDeliveryMode = getJobDeliveryMode;
|
|
24544
|
+
exports2.getJobFetchPort = getJobFetchPort;
|
|
24545
|
+
exports2.startJobFetching = startJobFetching;
|
|
24546
|
+
var nudge_listener_server_12 = require_nudge_listener_server();
|
|
24547
|
+
var logger_12 = require_logger();
|
|
24548
|
+
var utils_12 = require_utils9();
|
|
24549
|
+
var JobDeliveryMode;
|
|
24550
|
+
(function(JobDeliveryMode2) {
|
|
24551
|
+
JobDeliveryMode2["POLL"] = "poll";
|
|
24552
|
+
JobDeliveryMode2["PUSH"] = "push";
|
|
24553
|
+
})(JobDeliveryMode || (exports2.JobDeliveryMode = JobDeliveryMode = {}));
|
|
24554
|
+
var DEFAULT_MODE = JobDeliveryMode.POLL;
|
|
24555
|
+
function getJobDeliveryMode() {
|
|
24556
|
+
const mode = process.env.CODEGEN_JOB_DELIVERY?.trim().toLowerCase();
|
|
24557
|
+
const supported = Object.values(JobDeliveryMode).find((candidate) => candidate === mode);
|
|
24558
|
+
if (supported)
|
|
24559
|
+
return supported;
|
|
24560
|
+
if (mode) {
|
|
24561
|
+
logger_12.logger.warn("[Startup] Unrecognized CODEGEN_JOB_DELIVERY, using default", {
|
|
24562
|
+
mode,
|
|
24563
|
+
default: DEFAULT_MODE
|
|
24564
|
+
});
|
|
24565
|
+
}
|
|
24566
|
+
return DEFAULT_MODE;
|
|
24567
|
+
}
|
|
24568
|
+
var MIN_PORT = 1;
|
|
24569
|
+
var MAX_PORT = 65535;
|
|
24570
|
+
function getJobFetchPort() {
|
|
24571
|
+
const configured = process.env.CODEGEN_JOB_FETCH_PORT;
|
|
24572
|
+
if (configured === void 0)
|
|
24573
|
+
return nudge_listener_server_12.JOB_FETCH_PORT;
|
|
24574
|
+
const port = /^\s*\d+\s*$/.test(configured) ? Number(configured) : NaN;
|
|
24575
|
+
if (Number.isInteger(port) && port >= MIN_PORT && port <= MAX_PORT)
|
|
24576
|
+
return port;
|
|
24577
|
+
logger_12.logger.warn("[Startup] Unusable CODEGEN_JOB_FETCH_PORT, using default", {
|
|
24578
|
+
port: configured,
|
|
24579
|
+
default: nudge_listener_server_12.JOB_FETCH_PORT
|
|
24580
|
+
});
|
|
24581
|
+
return nudge_listener_server_12.JOB_FETCH_PORT;
|
|
24582
|
+
}
|
|
24583
|
+
async function startJobFetching(deps) {
|
|
24584
|
+
const mode = getJobDeliveryMode();
|
|
24585
|
+
logger_12.logger.info("[Startup] Job delivery mode", { mode });
|
|
24586
|
+
if (mode === JobDeliveryMode.POLL) {
|
|
24587
|
+
return deps.runPollLoop();
|
|
24588
|
+
}
|
|
24589
|
+
try {
|
|
24590
|
+
await deps.nudgeListenerServer.start();
|
|
24591
|
+
} catch (error) {
|
|
24592
|
+
try {
|
|
24593
|
+
await deps.nudgeListenerServer.stop();
|
|
24594
|
+
} catch (stopError) {
|
|
24595
|
+
logger_12.logger.error("[Startup] Closing the half-started listener failed", {
|
|
24596
|
+
error: (0, utils_12.errorStack)(stopError)
|
|
24597
|
+
});
|
|
24598
|
+
}
|
|
24599
|
+
logger_12.logger.error("[Startup] Push delivery unavailable, falling back to poll", {
|
|
24600
|
+
error: (0, utils_12.errorStack)(error)
|
|
24601
|
+
});
|
|
24602
|
+
return deps.runPollLoop();
|
|
24603
|
+
}
|
|
24604
|
+
}
|
|
24605
|
+
}
|
|
24606
|
+
});
|
|
24607
|
+
|
|
24271
24608
|
// dist/index.js
|
|
24272
24609
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24273
24610
|
exports.processJob = processJob;
|
|
@@ -24289,7 +24626,6 @@ var logger_1 = require_logger();
|
|
|
24289
24626
|
var skills_installer_1 = require_skills_installer();
|
|
24290
24627
|
var rules_writer_1 = require_rules_writer();
|
|
24291
24628
|
var tools_writer_1 = require_tools_writer();
|
|
24292
|
-
var node_modules_guard_1 = require_node_modules_guard();
|
|
24293
24629
|
var tool_policies_1 = require_tool_policies3();
|
|
24294
24630
|
var skills_override_1 = require_skills_override();
|
|
24295
24631
|
var generated_files_guard_1 = require_generated_files_guard();
|
|
@@ -24297,61 +24633,67 @@ var subagent_tool_logger_1 = require_subagent_tool_logger();
|
|
|
24297
24633
|
var plugin_artifacts_1 = require_plugin_artifacts();
|
|
24298
24634
|
var config_1 = require_config();
|
|
24299
24635
|
var environments_1 = require_environments();
|
|
24300
|
-
var plugin_host_1 = require_plugin_host();
|
|
24301
24636
|
var utils_1 = require_utils9();
|
|
24637
|
+
var job_fetching_1 = require_job_fetching();
|
|
24638
|
+
var nudge_listener_server_1 = require_nudge_listener_server();
|
|
24639
|
+
var plugin_host_1 = require_plugin_host();
|
|
24640
|
+
var utils_2 = require_utils9();
|
|
24302
24641
|
var sessionId = process.env.CODEGEN_SESSION_ID || (0, crypto_1.randomUUID)();
|
|
24303
24642
|
process.env.CODEGEN_SESSION_ID = sessionId;
|
|
24304
24643
|
(0, logger_1.initLogger)(sessionId);
|
|
24305
24644
|
var jobCancellationMonitor = new job_cancellation_monitor_1.JobCancellationMonitor(codeGenerationService_1.codeGenerationService);
|
|
24306
24645
|
var jobTimeoutMonitor = new job_timeout_monitor_1.JobTimeoutMonitor(codeGenerationService_1.codeGenerationService);
|
|
24307
|
-
var
|
|
24646
|
+
var POLL_LOG_PREFIX = "[Loop]";
|
|
24647
|
+
var PUSH_LOG_PREFIX = "[JobFetch]";
|
|
24308
24648
|
var ACTIVE_JOB_SLEEP_MS = 1e3;
|
|
24309
24649
|
var NO_JOBS_SLEEP_MS = 5e3;
|
|
24310
24650
|
var POST_JOB_SLEEP_MS = 3e3;
|
|
24651
|
+
var runPendingJob = async (job, logPrefix) => {
|
|
24652
|
+
const redactAgentData = (payload) => payload?.agentData ? { ...payload, agentData: Object.keys(payload.agentData) } : payload;
|
|
24653
|
+
logger_1.logger.info("Job details", {
|
|
24654
|
+
job: {
|
|
24655
|
+
...job,
|
|
24656
|
+
tasks: job.tasks?.map((task) => ({
|
|
24657
|
+
...task,
|
|
24658
|
+
input: redactAgentData(task.input),
|
|
24659
|
+
payload: redactAgentData(task.payload)
|
|
24660
|
+
}))
|
|
24661
|
+
}
|
|
24662
|
+
});
|
|
24663
|
+
if (!job.id) {
|
|
24664
|
+
throw new ditto_codegen_types_1.MissingJobIdError();
|
|
24665
|
+
}
|
|
24666
|
+
const jobId = job.id;
|
|
24667
|
+
logger_1.logger.info(`${logPrefix} Selected job`, { jobId });
|
|
24668
|
+
const freshToken = await codeGenerationService_1.codeGenerationService.refreshAccessToken();
|
|
24669
|
+
(0, config_1.setCurrentAccessToken)(freshToken);
|
|
24670
|
+
await codeGenerationService_1.codeGenerationService.markJobAsRuninng(jobId);
|
|
24671
|
+
await processJob(job);
|
|
24672
|
+
await codeGenerationService_1.codeGenerationService.markJobAsCompleted(jobId);
|
|
24673
|
+
logger_1.logger.info(`${logPrefix} Processed job`, { jobId });
|
|
24674
|
+
};
|
|
24311
24675
|
var alwaysOnLoop = async () => {
|
|
24312
24676
|
while (true) {
|
|
24313
24677
|
try {
|
|
24314
24678
|
if (context_1.ctx.hasActiveJobs()) {
|
|
24315
24679
|
console.log(`[Loop] Local active job in progress. Sleeping ${ACTIVE_JOB_SLEEP_MS}ms`);
|
|
24316
|
-
await delay(ACTIVE_JOB_SLEEP_MS);
|
|
24680
|
+
await (0, utils_1.delay)(ACTIVE_JOB_SLEEP_MS);
|
|
24317
24681
|
continue;
|
|
24318
24682
|
}
|
|
24319
24683
|
const jobs = await codeGenerationService_1.codeGenerationService.fetchPendingJobs();
|
|
24320
24684
|
console.log("[Loop] Fetched pending jobs", { count: jobs.length });
|
|
24321
24685
|
if (jobs.length === 0) {
|
|
24322
24686
|
console.log("[Loop] No pending jobs, sleeping");
|
|
24323
|
-
await delay(NO_JOBS_SLEEP_MS);
|
|
24687
|
+
await (0, utils_1.delay)(NO_JOBS_SLEEP_MS);
|
|
24324
24688
|
continue;
|
|
24325
24689
|
}
|
|
24326
|
-
|
|
24327
|
-
|
|
24328
|
-
logger_1.logger.info("Job details", {
|
|
24329
|
-
job: {
|
|
24330
|
-
...job,
|
|
24331
|
-
tasks: job.tasks?.map((task) => ({
|
|
24332
|
-
...task,
|
|
24333
|
-
input: redactAgentData(task.input),
|
|
24334
|
-
payload: redactAgentData(task.payload)
|
|
24335
|
-
}))
|
|
24336
|
-
}
|
|
24337
|
-
});
|
|
24338
|
-
if (!job.id) {
|
|
24339
|
-
throw new ditto_codegen_types_1.MissingJobIdError();
|
|
24340
|
-
}
|
|
24341
|
-
const jobId = job.id;
|
|
24342
|
-
logger_1.logger.info("[Loop] Selected job", { jobId });
|
|
24343
|
-
const freshToken = await codeGenerationService_1.codeGenerationService.refreshAccessToken();
|
|
24344
|
-
(0, config_1.setCurrentAccessToken)(freshToken);
|
|
24345
|
-
await codeGenerationService_1.codeGenerationService.markJobAsRuninng(jobId);
|
|
24346
|
-
await processJob(job);
|
|
24347
|
-
await codeGenerationService_1.codeGenerationService.markJobAsCompleted(jobId);
|
|
24348
|
-
logger_1.logger.info("[Loop] Processed job", { jobId });
|
|
24349
|
-
await delay(POST_JOB_SLEEP_MS);
|
|
24690
|
+
await runPendingJob(jobs[0], POLL_LOG_PREFIX);
|
|
24691
|
+
await (0, utils_1.delay)(POST_JOB_SLEEP_MS);
|
|
24350
24692
|
} catch (loopError) {
|
|
24351
24693
|
logger_1.logger.error("Polling loop encountered an error. Will continue after backoff:", {
|
|
24352
24694
|
error: loopError instanceof Error ? loopError.message : String(loopError)
|
|
24353
24695
|
});
|
|
24354
|
-
await delay(NO_JOBS_SLEEP_MS);
|
|
24696
|
+
await (0, utils_1.delay)(NO_JOBS_SLEEP_MS);
|
|
24355
24697
|
}
|
|
24356
24698
|
context_1.ctx.resetJobs();
|
|
24357
24699
|
}
|
|
@@ -24372,7 +24714,6 @@ async function initOpenCode() {
|
|
|
24372
24714
|
]),
|
|
24373
24715
|
(0, skills_installer_1.applySkillsOverride)((0, codegen_flow_helpers_1.getOutputPath)(), logger_1.logger),
|
|
24374
24716
|
(0, tools_writer_1.writeToolFiles)(pluginArtifacts.tools),
|
|
24375
|
-
(0, node_modules_guard_1.writeGuardPlugin)(),
|
|
24376
24717
|
(0, generated_files_guard_1.writeGeneratedFilesGuardPlugin)(),
|
|
24377
24718
|
(0, subagent_tool_logger_1.writeSubagentToolLoggerPlugin)(),
|
|
24378
24719
|
(0, tool_policies_1.writeToolPoliciesPlugin)(toolPolicies)
|
|
@@ -24390,7 +24731,13 @@ async function main(ctx) {
|
|
|
24390
24731
|
metasiteId: ctx.metasiteId
|
|
24391
24732
|
});
|
|
24392
24733
|
await initOpenCode();
|
|
24393
|
-
|
|
24734
|
+
const nudgeListenerServer = new nudge_listener_server_1.NudgeListenerServer({
|
|
24735
|
+
fetchPendingJobs: () => codeGenerationService_1.codeGenerationService.fetchPendingJobs(),
|
|
24736
|
+
findJob: (jobId) => codeGenerationService_1.codeGenerationService.findJob(jobId),
|
|
24737
|
+
canRunJob: (job) => codeGenerationService_1.codeGenerationService.shouldProcessJob(job),
|
|
24738
|
+
runJob: (job) => runPendingJob(job, PUSH_LOG_PREFIX)
|
|
24739
|
+
}, (0, job_fetching_1.getJobFetchPort)());
|
|
24740
|
+
await (0, job_fetching_1.startJobFetching)({ runPollLoop: alwaysOnLoop, nudgeListenerServer });
|
|
24394
24741
|
}
|
|
24395
24742
|
var getFirstTask = (job) => {
|
|
24396
24743
|
return job.tasks?.[0];
|
|
@@ -24434,7 +24781,7 @@ async function reportPreDispatchFailure(jobId, error) {
|
|
|
24434
24781
|
});
|
|
24435
24782
|
try {
|
|
24436
24783
|
await codeGenerationService_1.codeGenerationService.markJobAsFailed(jobId, codegenError);
|
|
24437
|
-
await (0,
|
|
24784
|
+
await (0, utils_2.updateAllRunningTasks)(jobId, CodeGenService_1.Status.FAILED, codegenError);
|
|
24438
24785
|
} catch (reportError) {
|
|
24439
24786
|
logger_1.logger.error("[Job] Could not mark the job failed", {
|
|
24440
24787
|
jobId,
|
|
@@ -24501,6 +24848,7 @@ async function processJob(job) {
|
|
|
24501
24848
|
} finally {
|
|
24502
24849
|
jobCancellationMonitor.stop();
|
|
24503
24850
|
jobTimeoutMonitor.stop();
|
|
24851
|
+
context_1.ctx.resetJobs();
|
|
24504
24852
|
}
|
|
24505
24853
|
});
|
|
24506
24854
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/ditto-codegen-public",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.442",
|
|
4
4
|
"description": "AI-powered Wix CLI app generator - standalone executable",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "node build.mjs",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"esbuild": "^0.27.2",
|
|
30
30
|
"vitest": "^4.0.16"
|
|
31
31
|
},
|
|
32
|
-
"falconPackageHash": "
|
|
32
|
+
"falconPackageHash": "19c7b1e106b5b7a1aa3bc62b9fc8ebae4ce01f8641d5971c6e7138c3"
|
|
33
33
|
}
|