Compare commits
4 Commits
c2d00c18a7
...
fix/meta-p
| Author | SHA1 | Date | |
|---|---|---|---|
| c8998c6b0d | |||
| 686f2c7cb0 | |||
| 81d40ae63d | |||
| 65a3fb8d2d |
@@ -128,7 +128,9 @@ function register(api: PluginAPI): void {
|
|||||||
/** Resolve agent ID from env, config, or fallback. */
|
/** Resolve agent ID from env, config, or fallback. */
|
||||||
function resolveAgentId(): string {
|
function resolveAgentId(): string {
|
||||||
if (process.env.AGENT_ID) return process.env.AGENT_ID;
|
if (process.env.AGENT_ID) return process.env.AGENT_ID;
|
||||||
const cfg = api.runtime?.config?.loadConfig?.();
|
// Read from cached `api.config` first — see pushMetaToMonitor for why
|
||||||
|
// the deprecated `api.runtime?.config?.loadConfig?.()` path is heavy.
|
||||||
|
const cfg = (api as any).config ?? api.runtime?.config?.loadConfig?.();
|
||||||
return cfg?.agents?.list?.[0]?.id ?? cfg?.agents?.defaults?.id ?? 'unknown';
|
return cfg?.agents?.list?.[0]?.id ?? cfg?.agents?.defaults?.id ?? 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +186,25 @@ function register(api: PluginAPI): void {
|
|||||||
* Push OpenClaw metadata to the Monitor bridge.
|
* Push OpenClaw metadata to the Monitor bridge.
|
||||||
* This enriches Monitor heartbeats with OpenClaw version/plugin/agent info.
|
* This enriches Monitor heartbeats with OpenClaw version/plugin/agent info.
|
||||||
* Failures are non-fatal — Monitor continues to work without this data.
|
* Failures are non-fatal — Monitor continues to work without this data.
|
||||||
|
*
|
||||||
|
* IMPORTANT — read config from the cached `api.config` surface, NOT from
|
||||||
|
* the deprecated `api.runtime?.config?.loadConfig?.()` path. The
|
||||||
|
* deprecated path triggers a full plugin-metadata-snapshot rebuild on
|
||||||
|
* every call: realpathSync walks every plugin's package.json + manifest
|
||||||
|
* + source paths (lstats up the directory tree), `hashWatchedFiles`
|
||||||
|
* fingerprints all watched plugin files, and `discoverInDirectory`
|
||||||
|
* re-scans every `dist/extensions/<plugin>` dir. On t2 with ~100 plugins
|
||||||
|
* each rebuild costs ~6-7s of CPU; with this push firing every 30s
|
||||||
|
* (default reportIntervalSec) the chronic baseline was ~22-25% gateway
|
||||||
|
* CPU even with zero agent activity (V8 profile 2026-05-27 08:14:00 60s:
|
||||||
|
* lstat 44.2%, statSync 6.9%, hashWatchedFiles via memo key 1.7%, all
|
||||||
|
* routed through readPersistedInstalledPluginIndexInstallRecordsSync ->
|
||||||
|
* discoverInDirectory). Switching to `api.config` reads from the
|
||||||
|
* already-loaded snapshot cache; the elsewhere-in-this-file pattern was
|
||||||
|
* already `api.config ?? api.runtime?.config?.loadConfig?.()`.
|
||||||
|
*
|
||||||
|
* Same fix is applied to `resolveAgentId` below — that's read once at
|
||||||
|
* gateway start so the impact is smaller, but it's the same anti-pattern.
|
||||||
*/
|
*/
|
||||||
async function pushMetaToMonitor() {
|
async function pushMetaToMonitor() {
|
||||||
const bridgeClient = getBridgeClient();
|
const bridgeClient = getBridgeClient();
|
||||||
@@ -191,7 +212,7 @@ function register(api: PluginAPI): void {
|
|||||||
|
|
||||||
let agentNames: string[] = [];
|
let agentNames: string[] = [];
|
||||||
try {
|
try {
|
||||||
const cfg = api.runtime?.config?.loadConfig?.();
|
const cfg = (api as any).config ?? api.runtime?.config?.loadConfig?.();
|
||||||
const agentsList = cfg?.agents?.list;
|
const agentsList = cfg?.agents?.list;
|
||||||
if (Array.isArray(agentsList)) {
|
if (Array.isArray(agentsList)) {
|
||||||
agentNames = agentsList
|
agentNames = agentsList
|
||||||
@@ -307,21 +328,22 @@ function register(api: PluginAPI): void {
|
|||||||
)}\n\`\`\``;
|
)}\n\`\`\``;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First-line ack `WAKEUP_OK` is the plugin's ack-receipt token; the
|
// The wakeup dispatcher's `deliver` callback below only logs the
|
||||||
// agent MUST then continue in the same session and drive the
|
// reply text — it does NOT inspect any ack token. The earlier
|
||||||
// `hf-wakeup` workflow to completion (calendar_status → task fetch →
|
// `WAKEUP_OK` first-line-ack convention was prompt-only theatre;
|
||||||
// sub-workflow → calendar_complete/abort). Without that continuation
|
// nothing in this plugin or in openclaw acted on it. The only
|
||||||
// the scheduler keeps re-waking every 30s because the slot stays
|
// thing that ends a wake cycle is the slot transitioning out of
|
||||||
// `not_started` forever.
|
// `not_started`, which happens when the agent calls
|
||||||
|
// `harborforge_calendar_complete` or `harborforge_calendar_abort`.
|
||||||
|
// Tell the agent that plainly instead of asking for a fake ack.
|
||||||
const wakeupMessage =
|
const wakeupMessage =
|
||||||
`You have due slots. **First line of your reply MUST be exactly ` +
|
`You have due slots. Drive the \`hf-wakeup\` workflow of skill ` +
|
||||||
`\`WAKEUP_OK\`** so the plugin records the ack. Then, **in this ` +
|
`\`hf-hangman-lab\` to completion in this session — read slot ` +
|
||||||
`same session**, drive the \`hf-wakeup\` workflow of skill ` +
|
`context, call the harborforge_calendar_* tools, route to the ` +
|
||||||
`\`hf-hangman-lab\` to completion — read slot context, call the ` +
|
`right sub-workflow, and finish with harborforge_calendar_complete ` +
|
||||||
`harborforge_calendar_* tools, route to the right sub-workflow, ` +
|
`or harborforge_calendar_abort. The scheduler keeps re-waking you ` +
|
||||||
`and finish with harborforge_calendar_complete or abort. Do NOT ` +
|
`every 30s until the slot transitions out of \`not_started\`, so ` +
|
||||||
`stop after the ack — the scheduler will re-wake you every 30s ` +
|
`partial work or silence just produces another wake.${slotBlock}`;
|
||||||
`until the slot transitions out of \`not_started\`.${slotBlock}`;
|
|
||||||
|
|
||||||
const result = await dispatchInboundMessageWithDispatcher({
|
const result = await dispatchInboundMessageWithDispatcher({
|
||||||
ctx: {
|
ctx: {
|
||||||
|
|||||||
Reference in New Issue
Block a user