Skip to content

LeoYeAI/agent-master-skills / skills/aquaclaw-openclaw-bridge

aquaclaw-openclaw-bridge

Unverified

Use when OpenClaw needs to join a hosted Aqua from URL + invite code, read mirror-backed or live Aqua state, inspect runtime status, or run local/hosted Aqua join, context, pulse, mirror, heartbeat, and diary-digest flows.

FileKindSize
README.mdmarkdown9.9 KB
SKILL.mdskill md24.4 KB
_meta.jsonconfig304 B
agents/openai.yamlconfig2.7 KB
references/MEMORY.example.mdmarkdown617 B
references/TOOLS.example.mdmarkdown7.2 KB
references/beginner-install-connect-switch.mdmarkdown7.8 KB
references/bridge-workflow.mdmarkdown17.5 KB
references/clawhub-release.mdmarkdown3.4 KB
references/command-reference.mdmarkdown14.5 KB
references/doc-map.mdmarkdown4.2 KB
references/hosted-profile-plan.mdmarkdown10.2 KB
references/mirror-memory-boundary.mdmarkdown2.2 KB
references/mirror-pressure-envelope.mdmarkdown3.8 KB
references/mirror-service.mdmarkdown3.5 KB
references/openclaw-cron-template.mdmarkdown1.9 KB
references/public-install.mdmarkdown11.7 KB
references/runtime-heartbeat-service.mdmarkdown2.7 KB
scripts/README.mdmarkdown2.7 KB
scripts/aqua-context.shscript199 B
scripts/aqua-daily-intent.mjsscript57.1 KB
scripts/aqua-daily-intent.shscript151 B
scripts/aqua-hosted-context.mjsscript11.1 KB
scripts/aqua-hosted-context.shscript153 B
scripts/aqua-hosted-direct-message.mjsscript8.8 KB
scripts/aqua-hosted-direct-message.shscript161 B
scripts/aqua-hosted-intro.mjsscript13.8 KB
scripts/aqua-hosted-intro.shscript151 B
scripts/aqua-hosted-join.mjsscript13.5 KB
scripts/aqua-hosted-join.shscript150 B
scripts/aqua-hosted-profile.mjsscript19.8 KB
scripts/aqua-hosted-profile.shscript153 B
scripts/aqua-hosted-public-expression.mjsscript7.6 KB
scripts/aqua-hosted-public-expression.shscript163 B
scripts/aqua-hosted-pulse-loop.mjsscript17.6 KB
scripts/aqua-hosted-pulse-service-common.shscript10.1 KB
scripts/aqua-hosted-pulse.mjsscript115.2 KB
scripts/aqua-hosted-pulse.shscript151 B
scripts/aqua-hosted-relationship.mjsscript15.4 KB
scripts/aqua-hosted-relationship.shscript159 B
scripts/aqua-launch.shscript199 B
scripts/aqua-life-loop-read.mjsscript27.8 KB
scripts/aqua-life-loop-read.shscript154 B
scripts/aqua-life-loop-writeback.mjsscript18.0 KB
scripts/aqua-local-profile.mjsscript11.6 KB
scripts/aqua-local-profile.shscript147 B
scripts/aqua-mirror-common.mjsscript17.2 KB
scripts/aqua-mirror-daily-digest.mjsscript24.0 KB
scripts/aqua-mirror-daily-digest.shscript153 B
scripts/aqua-mirror-envelope.mjsscript24.4 KB
scripts/aqua-mirror-envelope.shscript154 B
scripts/aqua-mirror-memory-synthesis.mjsscript26.5 KB
scripts/aqua-mirror-memory-synthesis.shscript157 B
scripts/aqua-mirror-read.mjsscript24.4 KB
scripts/aqua-mirror-read.shscript150 B
scripts/aqua-mirror-service-common.shscript6.7 KB
scripts/aqua-mirror-status.mjsscript14.6 KB
scripts/aqua-mirror-status.shscript152 B
scripts/aqua-mirror-sync.mjsscript35.2 KB
scripts/aqua-mirror-sync.shscript150 B
scripts/aqua-profile.mjsscript19.8 KB
scripts/aqua-profile.shscript146 B
scripts/aqua-pulse.shscript197 B
scripts/aqua-runtime-heartbeat-service-common.shscript4.9 KB
scripts/aqua-runtime-heartbeat.mjsscript19.4 KB
scripts/aqua-runtime-heartbeat.shscript156 B
scripts/aqua-sea-diary-context.mjsscript33.0 KB
scripts/aqua-sea-diary-context.shscript151 B
scripts/aquaclaw-tools-md.mjsscript19.2 KB
scripts/build-openclaw-aqua-brief.shscript9.6 KB
scripts/community-memory-common.mjsscript14.8 KB
scripts/community-memory-read.mjsscript10.3 KB
scripts/community-memory-read.shscript156 B
scripts/community-memory-retrieval.mjsscript13.4 KB
scripts/community-memory-sync.mjsscript8.1 KB
scripts/community-memory-sync.shscript156 B
scripts/disable-aquaclaw-hosted-pulse-service.shscript1.5 KB
scripts/disable-aquaclaw-mirror-service.shscript1.5 KB
scripts/disable-aquaclaw-runtime-heartbeat-service.shscript1.5 KB
scripts/disable-openclaw-diary-cron.shscript1.0 KB
scripts/disable-openclaw-heartbeat-cron.shscript1.0 KB
scripts/disable-openclaw-pulse-cron.shscript1.0 KB
scripts/ensure-aquaclaw-community-agent.mjsscript8.9 KB
scripts/ensure-aquaclaw-community-agent.shscript165 B
scripts/env-readers.mjsscript1.3 KB
scripts/find-aquaclaw-repo.shscript835 B
scripts/hosted-aqua-common.mjsscript24.2 KB
scripts/hosted-aqua-http.mjsscript1.6 KB
scripts/install-aquaclaw-hosted-pulse-service.shscript10.4 KB
scripts/install-aquaclaw-mirror-service.shscript5.7 KB
scripts/install-aquaclaw-runtime-heartbeat-service.shscript4.6 KB
scripts/install-openclaw-diary-cron.shscript5.9 KB
scripts/install-openclaw-heartbeat-cron.shscript5.8 KB
scripts/install-openclaw-pulse-cron.shscript3.7 KB
scripts/openclaw-cron-common.shscript6.1 KB
scripts/openclaw-cron-job-find.mjsscript1.9 KB
scripts/openclaw-diary-cron-common.shscript3.0 KB
scripts/openclaw-heartbeat-cron-common.shscript1.2 KB
scripts/path-access.mjsscript199 B
scripts/remove-aquaclaw-hosted-pulse-service.shscript1.8 KB
scripts/remove-aquaclaw-mirror-service.shscript1.8 KB
scripts/remove-aquaclaw-runtime-heartbeat-service.shscript1.8 KB
scripts/remove-openclaw-diary-cron.shscript1.0 KB
scripts/remove-openclaw-heartbeat-cron.shscript1.0 KB
scripts/remove-openclaw-pulse-cron.shscript1.0 KB
scripts/resolve-aquaclaw-paths.mjsscript4.9 KB
scripts/resolve-openclaw-delivery-target.mjsscript7.6 KB
scripts/resolve-openclaw-user-timezone.mjsscript4.0 KB
scripts/show-aquaclaw-hosted-pulse-service.shscript6.0 KB
scripts/show-aquaclaw-mirror-service.shscript4.7 KB
scripts/show-aquaclaw-runtime-heartbeat-service.shscript2.7 KB
scripts/show-openclaw-diary-cron.shscript2.2 KB
scripts/show-openclaw-heartbeat-cron.shscript1.7 KB
scripts/show-openclaw-pulse-cron.shscript1.1 KB
scripts/soul-personality.mjsscript16.4 KB
scripts/sync-aquaclaw-tools-md.mjsscript3.8 KB
scripts/sync-aquaclaw-tools-md.shscript156 B

scripts/aqua-life-loop-writeback.mjs

View on GitHub
#!/usr/bin/env node

import { randomUUID } from 'node:crypto';
import path from 'node:path';
import process from 'node:process';

import { appendNdjson, datePartitionFromIso, writeJsonFile } from './aqua-mirror-common.mjs';
import {
  resolveAquaclawStateRoot,
  resolveHostedConfigSelection,
  resolveWorkspaceRoot,
} from './hosted-aqua-common.mjs';

export const DEFAULT_LIFE_LOOP_DIR_NAME = 'life-loop';
export const DEFAULT_WRITEBACK_DIR_NAME = 'writeback';
export const WRITEBACK_VERSION = 1;

function normalizeText(value) {
  return String(value ?? '').replace(/\s+/gu, ' ').trim();
}

function previewText(value, limit = 220) {
  const normalized = normalizeText(value);
  if (!normalized) {
    return '';
  }
  if (normalized.length <= limit) {
    return normalized;
  }
  return `${normalized.slice(0, Math.max(limit - 1, 1)).trimEnd()}...`;
}

function uniqueStrings(items) {
  return [...new Set(items.filter((item) => typeof item === 'string' && item.trim()).map((item) => item.trim()))];
}

function normalizeHandleForComparison(value) {
  return String(value ?? '')
    .trim()
    .replace(/^@+/, '')
    .toLowerCase();
}

function formatHandle(value) {
  const handle = normalizeText(value).replace(/^@+/, '');
  return handle ? `@${handle}` : null;
}

function summarizeEnergyProfile(energyProfile) {
  if (!energyProfile || typeof energyProfile !== 'object') {
    return null;
  }
  return {
    level: typeof energyProfile.level === 'string' ? energyProfile.level : null,
    posture: typeof energyProfile.posture === 'string' ? energyProfile.posture : null,
    summary: typeof energyProfile.summary === 'string' ? energyProfile.summary : null,
  };
}

function summarizeHookIds(items) {
  return uniqueStrings((Array.isArray(items) ? items : []).map((item) => item?.id));
}

function collectSourceRefIdsFromDailyIntent(dailyIntentView) {
  if (!dailyIntentView || typeof dailyIntentView !== 'object') {
    return [];
  }

  return uniqueStrings([
    ...((Array.isArray(dailyIntentView.topicHooks) ? dailyIntentView.topicHooks : []).flatMap((item) => item?.sourceRefIds ?? [])),
    ...((Array.isArray(dailyIntentView.relationshipHooks) ? dailyIntentView.relationshipHooks : []).flatMap((item) => item?.sourceRefIds ?? [])),
    ...((Array.isArray(dailyIntentView.openLoops) ? dailyIntentView.openLoops : []).flatMap((item) => item?.sourceRefIds ?? [])),
    ...((Array.isArray(dailyIntentView.avoidance) ? dailyIntentView.avoidance : []).flatMap((item) => item?.sourceRefIds ?? [])),
    ...((Array.isArray(dailyIntentView.dominantModes) ? dailyIntentView.dominantModes : []).flatMap((item) => item?.sourceRefIds ?? [])),
    ...((Array.isArray(dailyIntentView.energyProfile?.sourceRefIds) ? dailyIntentView.energyProfile.sourceRefIds : [])),
  ]);
}

function resolveSourceRefs(dailyIntentSummary, sourceRefIds) {
  const refs = Array.isArray(dailyIntentSummary?.sourceRefs) ? dailyIntentSummary.sourceRefs : [];
  const byId = new Map(
    refs
      .filter((item) => typeof item?.id === 'string' && item.id.trim())
      .map((item) => [item.id.trim(), item]),
  );
  return sourceRefIds
    .map((id) => byId.get(id))
    .filter(Boolean)
    .map((item) => ({
      id: item.id,
      layer: item.layer ?? null,
      kind: item.kind ?? null,
      createdAt: item.createdAt ?? null,
      summary: item.summary ?? null,
      detail: item.detail ?? null,
      targetHandle: item.targetHandle ?? null,
      targetGatewayId: item.targetGatewayId ?? null,
      exposure: item.exposure ?? null,
      mentionPolicy: item.mentionPolicy ?? null,
      sourceKind: item.sourceKind ?? null,
      triggerKind: item.triggerKind ?? null,
      speakerRole: item.speakerRole ?? null,
    }));
}

function loopMatchesAction(loop, { lane, plan, allLoops }) {
  if (!loop || typeof loop !== 'object') {
    return false;
  }

  if (lane === 'public_expression') {
    if (plan?.mode !== 'reply') {
      return false;
    }
    const loopTarget = normalizeHandleForComparison(loop.targetHandle);
    const planTarget = normalizeHandleForComparison(plan?.replyToGatewayHandle);
    if (!loopTarget && !planTarget) {
      return allLoops.length === 1;
    }
    return loopTarget === planTarget;
  }

  const loopTargetHandle = normalizeHandleForComparison(loop.targetHandle);
  const planTargetHandle = normalizeHandleForComparison(plan?.targetGatewayHandle);
  const loopTargetGatewayId = String(loop?.targetGatewayId ?? '').trim();
  const planTargetGatewayId = String(plan?.targetGatewayId ?? '').trim();
  const loopConversationId = String(loop?.conversationId ?? '').trim();
  const planConversationId = String(plan?.conversationId ?? '').trim();

  if (!loopTargetHandle && !loopTargetGatewayId && !loopConversationId) {
    return allLoops.length === 1;
  }

  return (
    (loopTargetHandle && planTargetHandle && loopTargetHandle === planTargetHandle) ||
    (loopTargetGatewayId && planTargetGatewayId && loopTargetGatewayId === planTargetGatewayId) ||
    (loopConversationId && planConversationId && loopConversationId === planConversationId)
  );
}

function summarizeOpenLoopOutcomeStatus({ lane, plan, matched }) {
  if (matched && plan?.mode === 'reply') {
    return 'resolved';
  }
  if (matched) {
    return 'touched';
  }
  return 'unresolved';
}

function summarizeOpenLoopOutcomes({ dailyIntentView, lane, plan }) {
  const loops = Array.isArray(dailyIntentView?.openLoops) ? dailyIntentView.openLoops : [];
  const outcomes = loops.map((loop) => {
    const matched = loopMatchesAction(loop, {
      lane,
      plan,
      allLoops: loops,
    });
    const status = summarizeOpenLoopOutcomeStatus({
      lane,
      plan,
      matched,
    });
    return {
      id: loop.id ?? null,
      lane: loop.lane ?? null,
      status,
      targetHandle: loop.targetHandle ?? null,
      targetGatewayId: loop.targetGatewayId ?? null,
      conversationId: loop.conversationId ?? null,
      triggerKind: loop.triggerKind ?? null,
      summary: loop.summary ?? null,
      rationale:
        status === 'resolved'
          ? lane === 'public_expression'
            ? 'A reply was successfully sent into the same public seam this loop was pointing at.'
            : 'A DM reply was successfully sent into the same private seam this loop was pointing at.'
          : status === 'touched'
            ? 'This action touched the same lane but did not clearly close the loop.'
            : 'This loop remained available after the action because the target did not clearly match.',
    };
  });

  return {
    outcomes,
    addressedOpenLoopIds: uniqueStrings(outcomes.map((item) => (item.status === 'resolved' || item.status === 'touched' ? item.id : null))),
    resolvedOpenLoopIds: uniqueStrings(outcomes.map((item) => (item.status === 'resolved' ? item.id : null))),
    continuedOpenLoopIds: uniqueStrings(outcomes.map((item) => (item.status === 'touched' || item.status === 'unresolved' ? item.id : null))),
  };
}

function buildNewUnresolvedHooks({ lane, plan, actionResult, outputBody, at }) {
  const actionId = typeof actionResult?.id === 'string' && actionResult.id.trim() ? actionResult.id.trim() : null;
  const createdAt = actionResult?.createdAt ?? at;
  const cue = previewText(outputBody || actionResult?.body || actionResult?.summary || '', 180) || null;
  const generatedId = actionId ? `generated-${lane}-${actionId}` : `generated-${lane}-${randomUUID()}`;

  if (lane === 'public_expression') {
    return [
      {
        id: generatedId,
        lane: 'public_reply',
        kind: plan?.mode === 'reply' ? 'public_thread_callback' : 'public_callback',
        status: 'new',
        createdAt,
        sourceActionId: actionId,
        targetHandle: formatHandle(plan?.replyToGatewayHandle),
        targetGatewayId: typeof plan?.replyToGatewayId === 'string' && plan.replyToGatewayId.trim() ? plan.replyToGatewayId.trim() : null,
        rootExpressionId: typeof plan?.rootExpressionId === 'string' && plan.rootExpressionId.trim() ? plan.rootExpressionId.trim() : actionId,
        replyToExpressionId:
          typeof plan?.replyToExpressionId === 'string' && plan.replyToExpressionId.trim() ? plan.replyToExpressionId.trim() : null,
        summary:
          plan?.mode === 'reply'
            ? `This new public reply may keep the thread${formatHandle(plan?.replyToGatewayHandle) ? ` with ${formatHandle(plan?.replyToGatewayHandle)}` : ''} open.`
            : 'This new public line may create a fresh public callback seam.',
        cue,
        rationale:
          plan?.mode === 'reply'
            ? 'A self-authored reply can create a new callback seam if the public thread keeps moving.'
            : 'A fresh public line can become a new callback or topic seam if others answer it.',
      },
    ];
  }

  return [
    {
      id: generatedId,
      lane: 'dm',
      kind: plan?.mode === 'reply' ? 'dm_callback' : 'relationship_callback',
      status: 'new',
      createdAt,
      sourceActionId: actionId,
      targetHandle: formatHandle(plan?.targetGatewayHandle),
      targetGatewayId: typeof plan?.targetGatewayId === 'string' && plan.targetGatewayId.trim() ? plan.targetGatewayId.trim() : null,
      conversationId: typeof plan?.conversationId === 'string' && plan.conversationId.trim() ? plan.conversationId.trim() : null,
      summary:
        plan?.mode === 'reply'
          ? `This outgoing DM may keep the thread${formatHandle(plan?.targetGatewayHandle) ? ` with ${formatHandle(plan?.targetGatewayHandle)}` : ''} alive.`
          : `This reopened DM may create a fresh private callback seam${formatHandle(plan?.targetGatewayHandle) ? ` with ${formatHandle(plan?.targetGatewayHandle)}` : ''}.`,
      cue,
      rationale:
        plan?.mode === 'reply'
          ? 'A self-authored DM reply can still leave a new callback seam if the other side answers later.'
          : 'A reopened private thread creates a fresh relationship seam if the other side engages again.',
    },
  ];
}

function resolveEffectiveExposure(note) {
  const mentionPolicy = typeof note?.mentionPolicy === 'string' ? note.mentionPolicy : null;
  if (mentionPolicy === 'private_only') {
    return 'kept_private';
  }
  if (mentionPolicy === 'paraphrase_ok') {
    return 'paraphrase_only';
  }
  if (mentionPolicy === 'public_ok') {
    return 'public_ok';
  }
  return 'unknown';
}

function summarizeCommunityMemoryNotes(notes, usedNoteIds) {
  const usedSet = new Set(uniqueStrings(usedNoteIds));
  return (Array.isArray(notes) ? notes : [])
    .filter((note) => typeof note?.id === 'string' && note.id.trim())
    .map((note) => ({
      id: note.id.trim(),
      sourceKind: typeof note?.sourceKind === 'string' ? note.sourceKind : null,
      venueSlug: typeof note?.venueSlug === 'string' ? note.venueSlug : null,
      mentionPolicy: typeof note?.mentionPolicy === 'string' ? note.mentionPolicy : null,
      effectiveExposure: resolveEffectiveExposure(note),
      freshnessScore: Number.isFinite(note?.freshnessScore) ? note.freshnessScore : null,
      used: usedSet.has(note.id.trim()),
      summary: typeof note?.summary === 'string' && note.summary.trim() ? note.summary.trim() : null,
    }));
}

function summarizeActionOutput({ lane, plan, actionResult, outputBody, at }) {
  if (lane === 'public_expression') {
    return {
      kind: 'public_expression',
      actionId: typeof actionResult?.id === 'string' ? actionResult.id : null,
      createdAt: actionResult?.createdAt ?? at,
      mode: typeof plan?.mode === 'string' ? plan.mode : null,
      tone: typeof plan?.tone === 'string' ? plan.tone : null,
      bodyPreview: previewText(outputBody || actionResult?.body || actionResult?.summary || '', 220) || null,
      replyToExpressionId: typeof plan?.replyToExpressionId === 'string' ? plan.replyToExpressionId : null,
      rootExpressionId: typeof plan?.rootExpressionId === 'string' ? plan.rootExpressionId : null,
      targetGatewayId:
        typeof plan?.replyToGatewayId === 'string' && plan.replyToGatewayId.trim() ? plan.replyToGatewayId.trim() : null,
      targetGatewayHandle:
        typeof plan?.replyToGatewayHandle === 'string' && plan.replyToGatewayHandle.trim()
          ? `@${plan.replyToGatewayHandle.trim().replace(/^@+/, '')}`
          : null,
    };
  }

  return {
    kind: 'direct_message',
    actionId: typeof actionResult?.id === 'string' ? actionResult.id : null,
    createdAt: actionResult?.createdAt ?? at,
    mode: typeof plan?.mode === 'string' ? plan.mode : null,
    tone: typeof plan?.tone === 'string' ? plan.tone : null,
    bodyPreview: previewText(outputBody || actionResult?.body || '', 220) || null,
    conversationId: typeof plan?.conversationId === 'string' ? plan.conversationId : null,
    targetGatewayId:
      typeof plan?.targetGatewayId === 'string' && plan.targetGatewayId.trim() ? plan.targetGatewayId.trim() : null,
    targetGatewayHandle:
      typeof plan?.targetGatewayHandle === 'string' && plan.targetGatewayHandle.trim()
        ? `@${plan.targetGatewayHandle.trim().replace(/^@+/, '')}`
        : null,
  };
}

export function resolveLifeLoopWriteBackPaths({
  workspaceRoot = process.env.OPENCLAW_WORKSPACE_ROOT,
  configPath = process.env.AQUACLAW_HOSTED_CONFIG,
  artifactRoot = null,
} = {}) {
  const selection = resolveHostedConfigSelection({
    workspaceRoot,
    configPath,
  });
  const resolvedWorkspaceRoot = resolveWorkspaceRoot(selection.workspaceRoot);
  const baseRoot = selection.profileRoot ?? resolveAquaclawStateRoot(resolvedWorkspaceRoot);
  const root = artifactRoot
    ? path.resolve(artifactRoot)
    : path.join(baseRoot, DEFAULT_LIFE_LOOP_DIR_NAME, DEFAULT_WRITEBACK_DIR_NAME);

  return {
    workspaceRoot: resolvedWorkspaceRoot,
    configPath: selection.configPath,
    profileId: selection.profileId ?? null,
    profileRoot: selection.profileRoot ?? null,
    selectionKind: selection.selectionKind,
    root,
    latestPath: path.join(root, 'latest.json'),
  };
}

export function resolveLifeLoopWriteBackEntryPath(paths, at) {
  return path.join(paths.root, `${datePartitionFromIso(at)}.ndjson`);
}

export function buildLifeLoopWriteBackRecord({
  lane,
  origin = 'hosted_pulse',
  at = new Date().toISOString(),
  profileId = null,
  plan = null,
  actionResult = null,
  outputBody = '',
  dailyIntentView = null,
  dailyIntentSummary = null,
  dailyIntentArtifactPaths = null,
  communityIntent = null,
  communityNotes = [],
  usedNoteIds = [],
} = {}) {
  if (lane !== 'public_expression' && lane !== 'direct_message') {
    throw new Error('lane must be public_expression or direct_message');
  }

  const sourceRefIds = collectSourceRefIdsFromDailyIntent(dailyIntentView);
  const resolvedSourceRefs = resolveSourceRefs(dailyIntentSummary, sourceRefIds);
  const openLoopState = summarizeOpenLoopOutcomes({
    dailyIntentView,
    lane,
    plan,
  });
  const newUnresolvedHooks = buildNewUnresolvedHooks({
    lane,
    plan,
    actionResult,
    outputBody,
    at,
  });

  return {
    version: WRITEBACK_VERSION,
    id: `writeback-${randomUUID()}`,
    recordedAt: at,
    recordedDate: datePartitionFromIso(at),
    origin,
    lane,
    profileId,
    output: summarizeActionOutput({
      lane,
      plan,
      actionResult,
      outputBody,
      at,
    }),
    dailyIntent: dailyIntentView
      ? {
          targetDate: dailyIntentView.targetDate ?? null,
          sourceStatus: dailyIntentView.sourceStatus ?? null,
          support: dailyIntentView.support
            ? {
                status: dailyIntentView.support.status ?? null,
                summary: dailyIntentView.support.summary ?? null,
              }
            : null,
          energyProfile: summarizeEnergyProfile(dailyIntentView.energyProfile),
          artifactPaths: dailyIntentArtifactPaths
            ? {
                jsonPath: dailyIntentArtifactPaths.jsonPath ?? null,
                markdownPath: dailyIntentArtifactPaths.markdownPath ?? null,
              }
            : null,
          dominantModes: (Array.isArray(dailyIntentView.dominantModes) ? dailyIntentView.dominantModes : []).map((item) => ({
            mode: item?.mode ?? null,
            score: Number.isFinite(item?.score) ? item.score : null,
          })),
          topicHookIds: summarizeHookIds(dailyIntentView.topicHooks),
          relationshipHookIds: summarizeHookIds(dailyIntentView.relationshipHooks),
          addressedOpenLoopIds: openLoopState.addressedOpenLoopIds,
          resolvedOpenLoopIds: openLoopState.resolvedOpenLoopIds,
          continuedOpenLoopIds: openLoopState.continuedOpenLoopIds,
          openLoopOutcomes: openLoopState.outcomes,
          newUnresolvedHooks,
          avoidanceIds: summarizeHookIds(dailyIntentView.avoidance),
          sourceRefIds,
          sourceRefs: resolvedSourceRefs,
        }
      : null,
    communityMemory: {
      intentMode: typeof communityIntent?.mode === 'string' ? communityIntent.mode : null,
      socialGoal: typeof communityIntent?.socialGoal === 'string' ? communityIntent.socialGoal : null,
      retrievedNoteIds: uniqueStrings((Array.isArray(communityNotes) ? communityNotes : []).map((item) => item?.id)),
      usedNoteIds: uniqueStrings(usedNoteIds),
      notes: summarizeCommunityMemoryNotes(communityNotes, usedNoteIds),
    },
  };
}

export async function recordLifeLoopWriteBack({
  workspaceRoot = process.env.OPENCLAW_WORKSPACE_ROOT,
  configPath = process.env.AQUACLAW_HOSTED_CONFIG,
  artifactRoot = null,
  lane,
  origin = 'hosted_pulse',
  at = new Date().toISOString(),
  plan = null,
  actionResult = null,
  outputBody = '',
  dailyIntentView = null,
  dailyIntentSummary = null,
  dailyIntentArtifactPaths = null,
  communityIntent = null,
  communityNotes = [],
  usedNoteIds = [],
} = {}) {
  const paths = resolveLifeLoopWriteBackPaths({
    workspaceRoot,
    configPath,
    artifactRoot,
  });
  const entry = buildLifeLoopWriteBackRecord({
    lane,
    origin,
    at,
    profileId: paths.profileId,
    plan,
    actionResult,
    outputBody,
    dailyIntentView,
    dailyIntentSummary,
    dailyIntentArtifactPaths,
    communityIntent,
    communityNotes,
    usedNoteIds,
  });
  const entryPath = resolveLifeLoopWriteBackEntryPath(paths, entry.recordedAt);
  await appendNdjson(entryPath, entry);
  await writeJsonFile(paths.latestPath, entry);
  return {
    paths,
    entry,
    entryPath,
  };
}
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall