refactor: package-own watchdog orchestrator entrypoint
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
|
||||
const ENV_PREFIX = 'OPENCLAW_REPORTING_GOVERNANCE_';
|
||||
|
||||
const packageRoot = path.resolve(import.meta.dirname, '..', '..');
|
||||
const repoRoot = packageRoot;
|
||||
const repoRoot = path.resolve(packageRoot, '..', '..');
|
||||
|
||||
const DEFAULT_SCRIPT_ROOT = path.join(packageRoot, 'scripts');
|
||||
const LEGACY_SCRIPT_ROOT = path.join(repoRoot, 'scripts');
|
||||
|
||||
const SCRIPT_NAMES = {
|
||||
watchdog: 'long_task_watchdog.mjs',
|
||||
@@ -26,6 +30,14 @@ function normalizeString(value) {
|
||||
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
||||
}
|
||||
|
||||
function defaultScriptPath(fileName) {
|
||||
const packagePath = path.join(DEFAULT_SCRIPT_ROOT, fileName);
|
||||
if (fs.existsSync(packagePath)) {
|
||||
return packagePath;
|
||||
}
|
||||
return path.join(LEGACY_SCRIPT_ROOT, fileName);
|
||||
}
|
||||
|
||||
export function resolveRepoPath(...segments) {
|
||||
return path.join(repoRoot, ...segments);
|
||||
}
|
||||
@@ -36,7 +48,7 @@ export function createRuntimeBinding(overrides = {}) {
|
||||
for (const [key, fileName] of Object.entries(SCRIPT_NAMES)) {
|
||||
const envValue = normalizeString(process.env[SCRIPT_ENV_KEYS[key]]);
|
||||
const overrideValue = normalizeString(overrides?.scripts?.[key]);
|
||||
scripts[key] = path.resolve(overrideValue ?? envValue ?? resolveRepoPath('scripts', fileName));
|
||||
scripts[key] = path.resolve(overrideValue ?? envValue ?? defaultScriptPath(fileName));
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -56,4 +68,4 @@ export function resolveScriptPath(name, options = {}) {
|
||||
return path.resolve(scriptPath);
|
||||
}
|
||||
|
||||
export { packageRoot, repoRoot, SCRIPT_ENV_KEYS, SCRIPT_NAMES };
|
||||
export { packageRoot, repoRoot, SCRIPT_ENV_KEYS, SCRIPT_NAMES, DEFAULT_SCRIPT_ROOT, LEGACY_SCRIPT_ROOT };
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const packageRoot = path.resolve(import.meta.dirname, '..', '..');
|
||||
const repoRoot = packageRoot;
|
||||
const repoRoot = path.resolve(packageRoot, '..', '..');
|
||||
const EXPECTED_KIND = 'DeploymentProfileArtifact';
|
||||
const EXPECTED_API_VERSION = 'reporting-governance/v1alpha1';
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ const schemaPath = path.resolve(packageRoot, 'schemas', 'reporting-governance',
|
||||
const artifactSchemaRefPath = './schemas/reporting-governance/deployment-profile.schema.json';
|
||||
const defaultSourceProfilePath = path.join('profiles-src', 'strict-manager-mode.yaml');
|
||||
const packageScriptsRoot = 'scripts';
|
||||
const packageScriptsRepoPrefix = 'plugins/reporting-governance';
|
||||
|
||||
function readText(filePath) {
|
||||
return fs.readFileSync(filePath, 'utf8');
|
||||
@@ -73,6 +74,7 @@ export function generateDeploymentProfileArtifact(profile, { sourceProfile } = {
|
||||
const validated = validateDeploymentProfileSchema(profile);
|
||||
const id = validated.metadata.id;
|
||||
const sourceProfilePath = sourceProfile ?? (id === 'strict-manager-mode' ? defaultSourceProfilePath : path.join('profiles-src', `${id}.yaml`));
|
||||
const scriptPrefix = `${packageScriptsRepoPrefix}/${packageScriptsRoot}`;
|
||||
|
||||
return {
|
||||
$schema: artifactSchemaRefPath,
|
||||
@@ -91,13 +93,13 @@ export function generateDeploymentProfileArtifact(profile, { sourceProfile } = {
|
||||
},
|
||||
bindings: {
|
||||
runtime: validated.metadata.runtime,
|
||||
entrypoint: `${packageScriptsRoot}/watchdog_auto_notify_orchestrator.mjs`,
|
||||
entrypoint: `${scriptPrefix}/watchdog_auto_notify_orchestrator.mjs`,
|
||||
scripts: {
|
||||
watchdog: `${packageScriptsRoot}/long_task_watchdog.mjs`,
|
||||
dispatcher: `${packageScriptsRoot}/operator_notify_dispatcher.mjs`,
|
||||
bridgeSupervisor: `${packageScriptsRoot}/operator_notify_bridge_supervisor.mjs`,
|
||||
senderBinding: `${packageScriptsRoot}/operator_notify_sender_binding.mjs`,
|
||||
orchestrator: `${packageScriptsRoot}/watchdog_auto_notify_orchestrator.mjs`,
|
||||
watchdog: `${scriptPrefix}/long_task_watchdog.mjs`,
|
||||
dispatcher: `${scriptPrefix}/operator_notify_dispatcher.mjs`,
|
||||
bridgeSupervisor: `${scriptPrefix}/operator_notify_bridge_supervisor.mjs`,
|
||||
senderBinding: `${scriptPrefix}/operator_notify_sender_binding.mjs`,
|
||||
orchestrator: `${scriptPrefix}/watchdog_auto_notify_orchestrator.mjs`,
|
||||
},
|
||||
artifact_roots: {
|
||||
watchdogEvidence: 'state/long-task-watchdog',
|
||||
|
||||
Reference in New Issue
Block a user