@ouro.bot/cli 0.1.0-alpha.34 → 0.1.0-alpha.340
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/README.md +188 -187
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +3 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +1 -1
- package/changelog.json +2031 -0
- package/dist/arc/attention-types.js +8 -0
- package/dist/arc/cares.js +140 -0
- package/dist/arc/episodes.js +117 -0
- package/dist/arc/intentions.js +133 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +237 -0
- package/dist/arc/packets.js +193 -0
- package/dist/arc/presence.js +185 -0
- package/dist/arc/task-lifecycle.js +65 -0
- package/dist/heart/active-work.js +832 -0
- package/dist/heart/agent-entry.js +37 -2
- package/dist/heart/attachments/image-normalize.js +194 -0
- package/dist/heart/attachments/materialize.js +97 -0
- package/dist/heart/attachments/originals.js +88 -0
- package/dist/heart/attachments/render.js +29 -0
- package/dist/heart/attachments/sources/adapter.js +2 -0
- package/dist/heart/attachments/sources/bluebubbles.js +156 -0
- package/dist/heart/attachments/sources/cli-local-file.js +78 -0
- package/dist/heart/attachments/sources/index.js +16 -0
- package/dist/heart/attachments/store.js +103 -0
- package/dist/heart/attachments/types.js +93 -0
- package/dist/heart/auth/auth-flow.js +463 -0
- package/dist/heart/bridges/manager.js +358 -0
- package/dist/heart/bridges/state-machine.js +135 -0
- package/dist/heart/bridges/store.js +123 -0
- package/dist/heart/bundle-state.js +168 -0
- package/dist/heart/commitments.js +111 -0
- package/dist/heart/config-registry.js +304 -0
- package/dist/heart/config.js +53 -21
- package/dist/heart/core.js +695 -195
- package/dist/heart/cross-chat-delivery.js +131 -0
- package/dist/heart/daemon/agent-config-check.js +292 -0
- package/dist/heart/daemon/agent-discovery.js +79 -3
- package/dist/heart/daemon/agent-service.js +360 -0
- package/dist/heart/daemon/agentic-repair.js +170 -0
- package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
- package/dist/heart/daemon/cadence.js +70 -0
- package/dist/heart/daemon/cli-defaults.js +591 -0
- package/dist/heart/daemon/cli-exec.js +2297 -0
- package/dist/heart/daemon/cli-help.js +306 -0
- package/dist/heart/daemon/cli-parse.js +824 -0
- package/dist/heart/daemon/cli-render-doctor.js +57 -0
- package/dist/heart/daemon/cli-render.js +512 -0
- package/dist/heart/daemon/cli-types.js +8 -0
- package/dist/heart/daemon/daemon-cli.js +30 -1171
- package/dist/heart/daemon/daemon-entry.js +358 -3
- package/dist/heart/daemon/daemon-health.js +141 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +157 -12
- package/dist/heart/daemon/daemon-tombstone.js +236 -0
- package/dist/heart/daemon/daemon.js +751 -58
- package/dist/heart/daemon/doctor-types.js +8 -0
- package/dist/heart/daemon/doctor.js +401 -0
- package/dist/heart/daemon/health-monitor.js +79 -1
- package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
- package/dist/heart/daemon/hooks/bundle-meta.js +115 -1
- package/dist/heart/daemon/http-health-probe.js +80 -0
- package/dist/heart/daemon/inner-status.js +89 -0
- package/dist/heart/daemon/interactive-repair.js +91 -0
- package/dist/heart/daemon/launchd.js +46 -9
- package/dist/heart/daemon/log-tailer.js +82 -12
- package/dist/heart/daemon/logs-prune.js +105 -0
- package/dist/heart/daemon/message-router.js +17 -8
- package/dist/heart/daemon/os-cron-deps.js +134 -0
- package/dist/heart/daemon/ouro-bot-entry.js +1 -1
- package/dist/heart/daemon/process-manager.js +201 -0
- package/dist/heart/daemon/provider-discovery.js +105 -0
- package/dist/heart/daemon/pulse.js +463 -0
- package/dist/heart/daemon/run-hooks.js +2 -0
- package/dist/heart/daemon/runtime-logging.js +67 -16
- package/dist/heart/daemon/runtime-metadata.js +101 -0
- package/dist/heart/daemon/runtime-mode.js +67 -0
- package/dist/heart/daemon/safe-mode.js +161 -0
- package/dist/heart/daemon/sense-manager.js +72 -3
- package/dist/heart/daemon/session-id-resolver.js +131 -0
- package/dist/heart/daemon/skill-management-installer.js +94 -0
- package/dist/heart/daemon/socket-client.js +307 -0
- package/dist/heart/daemon/stale-bundle-prune.js +96 -0
- package/dist/heart/daemon/startup-tui.js +237 -0
- package/dist/heart/daemon/task-scheduler.js +3 -25
- package/dist/heart/daemon/thoughts.js +510 -0
- package/dist/heart/daemon/up-progress.js +135 -0
- package/dist/heart/delegation.js +62 -0
- package/dist/heart/habits/habit-migration.js +181 -0
- package/dist/heart/habits/habit-parser.js +140 -0
- package/dist/heart/habits/habit-scheduler.js +371 -0
- package/dist/heart/{daemon → hatch}/hatch-flow.js +32 -120
- package/dist/heart/{daemon → hatch}/hatch-specialist.js +3 -3
- package/dist/heart/{daemon → hatch}/specialist-prompt.js +10 -7
- package/dist/heart/{daemon → hatch}/specialist-tools.js +49 -3
- package/dist/heart/identity.js +154 -59
- package/dist/heart/kicks.js +2 -20
- package/dist/heart/mcp/mcp-server.js +653 -0
- package/dist/heart/migrate-config.js +127 -0
- package/dist/heart/model-capabilities.js +59 -0
- package/dist/heart/outlook/outlook-http-hooks.js +64 -0
- package/dist/heart/outlook/outlook-http-response.js +7 -0
- package/dist/heart/outlook/outlook-http-routes.js +232 -0
- package/dist/heart/outlook/outlook-http-static.js +99 -0
- package/dist/heart/outlook/outlook-http-transport.js +116 -0
- package/dist/heart/outlook/outlook-http.js +99 -0
- package/dist/heart/outlook/outlook-read.js +28 -0
- package/dist/heart/outlook/outlook-types.js +27 -0
- package/dist/heart/outlook/outlook-view.js +194 -0
- package/dist/heart/outlook/readers/agent-machine.js +355 -0
- package/dist/heart/outlook/readers/continuity-readers.js +332 -0
- package/dist/heart/outlook/readers/runtime-readers.js +660 -0
- package/dist/heart/outlook/readers/sessions.js +231 -0
- package/dist/heart/outlook/readers/shared.js +111 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/provider-failover.js +135 -0
- package/dist/heart/provider-models.js +81 -0
- package/dist/heart/provider-ping.js +234 -0
- package/dist/heart/providers/anthropic-token.js +163 -0
- package/dist/heart/providers/anthropic.js +171 -50
- package/dist/heart/providers/azure.js +97 -11
- package/dist/heart/providers/error-classification.js +63 -0
- package/dist/heart/providers/github-copilot.js +135 -0
- package/dist/heart/providers/minimax-vlm.js +189 -0
- package/dist/heart/providers/minimax.js +23 -6
- package/dist/heart/providers/openai-codex.js +33 -23
- package/dist/heart/session-activity.js +190 -0
- package/dist/heart/session-events.js +726 -0
- package/dist/heart/session-recall.js +162 -0
- package/dist/heart/start-of-turn-packet.js +341 -0
- package/dist/heart/streaming.js +36 -27
- package/dist/heart/sync.js +332 -0
- package/dist/heart/target-resolution.js +127 -0
- package/dist/heart/tempo.js +93 -0
- package/dist/heart/temporal-view.js +41 -0
- package/dist/heart/tool-activity-callbacks.js +36 -0
- package/dist/heart/tool-description.js +135 -0
- package/dist/heart/tool-friction.js +55 -0
- package/dist/heart/tool-loop.js +200 -0
- package/dist/heart/turn-context.js +358 -0
- package/dist/heart/turn-coordinator.js +28 -0
- package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +1 -1
- package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
- package/dist/heart/{daemon → versioning}/ouro-path-installer.js +78 -35
- package/dist/heart/versioning/ouro-version-manager.js +295 -0
- package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
- package/dist/heart/{daemon → versioning}/update-checker.js +12 -2
- package/dist/heart/{daemon → versioning}/update-hooks.js +63 -59
- package/dist/mind/associative-recall.js +137 -66
- package/dist/mind/bundle-manifest.js +7 -1
- package/dist/mind/context.js +89 -93
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/{memory.js → diary.js} +84 -96
- package/dist/mind/embedding-provider.js +60 -0
- package/dist/mind/file-state.js +179 -0
- package/dist/mind/first-impressions.js +14 -1
- package/dist/mind/friends/channel.js +56 -0
- package/dist/mind/friends/group-context.js +144 -0
- package/dist/mind/friends/resolver.js +37 -0
- package/dist/mind/friends/store-file.js +58 -3
- package/dist/mind/friends/trust-explanation.js +74 -0
- package/dist/mind/friends/types.js +8 -0
- package/dist/mind/journal-index.js +161 -0
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +74 -7
- package/dist/mind/prompt.js +999 -111
- package/dist/mind/provenance-trust.js +26 -0
- package/dist/mind/scrutiny.js +173 -0
- package/dist/mind/token-estimate.js +8 -12
- package/dist/nerves/cli-logging.js +7 -1
- package/dist/nerves/coverage/audit.js +1 -1
- package/dist/nerves/coverage/file-completeness.js +83 -5
- package/dist/nerves/coverage/run-artifacts.js +1 -1
- package/dist/nerves/event-buffer.js +111 -0
- package/dist/nerves/index.js +224 -4
- package/dist/nerves/observation.js +20 -0
- package/dist/nerves/redact.js +79 -0
- package/dist/nerves/runtime.js +5 -1
- package/dist/outlook-ui/assets/index-DC7sZefn.js +61 -0
- package/dist/outlook-ui/assets/index-LwChZTgL.css +1 -0
- package/dist/outlook-ui/index.html +15 -0
- package/dist/repertoire/ado-client.js +15 -56
- package/dist/repertoire/ado-semantic.js +11 -10
- package/dist/repertoire/api-client.js +97 -0
- package/dist/repertoire/bitwarden-store.js +319 -0
- package/dist/repertoire/bundle-templates.js +72 -0
- package/dist/repertoire/bw-installer.js +79 -0
- package/dist/repertoire/coding/codex-jsonl.js +64 -0
- package/dist/repertoire/coding/context-pack.js +330 -0
- package/dist/repertoire/coding/feedback.js +197 -30
- package/dist/repertoire/coding/manager.js +158 -9
- package/dist/repertoire/coding/spawner.js +55 -9
- package/dist/repertoire/coding/tools.js +170 -7
- package/dist/repertoire/commerce-errors.js +109 -0
- package/dist/repertoire/commerce-self-test.js +156 -0
- package/dist/repertoire/credential-access.js +527 -0
- package/dist/repertoire/duffel-client.js +185 -0
- package/dist/repertoire/github-client.js +14 -55
- package/dist/repertoire/graph-client.js +11 -52
- package/dist/repertoire/guardrails.js +375 -0
- package/dist/repertoire/mcp-client.js +255 -0
- package/dist/repertoire/mcp-manager.js +305 -0
- package/dist/repertoire/mcp-tools.js +63 -0
- package/dist/repertoire/shell-sessions.js +133 -0
- package/dist/repertoire/skills.js +14 -23
- package/dist/repertoire/stripe-client.js +131 -0
- package/dist/repertoire/tasks/board.js +43 -5
- package/dist/repertoire/tasks/fix.js +182 -0
- package/dist/repertoire/tasks/index.js +28 -10
- package/dist/repertoire/tasks/lifecycle.js +2 -2
- package/dist/repertoire/tasks/parser.js +3 -2
- package/dist/repertoire/tasks/scanner.js +194 -37
- package/dist/repertoire/tasks/transitions.js +16 -79
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-attachments.js +316 -0
- package/dist/repertoire/tools-base.js +45 -771
- package/dist/repertoire/tools-bluebubbles.js +1 -0
- package/dist/repertoire/tools-bridge.js +141 -0
- package/dist/repertoire/tools-bundle.js +984 -0
- package/dist/repertoire/tools-config.js +185 -0
- package/dist/repertoire/tools-continuity.js +248 -0
- package/dist/repertoire/tools-credential.js +182 -0
- package/dist/repertoire/tools-files.js +342 -0
- package/dist/repertoire/tools-flight.js +224 -0
- package/dist/repertoire/tools-flow.js +105 -0
- package/dist/repertoire/tools-github.js +1 -7
- package/dist/repertoire/tools-memory.js +376 -0
- package/dist/repertoire/tools-session.js +739 -0
- package/dist/repertoire/tools-shell.js +120 -0
- package/dist/repertoire/tools-stripe.js +180 -0
- package/dist/repertoire/tools-surface.js +243 -0
- package/dist/repertoire/tools-teams.js +12 -62
- package/dist/repertoire/tools-travel.js +125 -0
- package/dist/repertoire/tools-user-profile.js +144 -0
- package/dist/repertoire/tools-vault.js +110 -0
- package/dist/repertoire/tools.js +144 -138
- package/dist/repertoire/travel-api-client.js +360 -0
- package/dist/repertoire/user-profile.js +118 -0
- package/dist/repertoire/vault-setup.js +241 -0
- package/dist/scripts/claude-code-hook.js +41 -0
- package/dist/scripts/claude-code-stop-hook.js +47 -0
- package/dist/senses/attention-queue.js +116 -0
- package/dist/senses/bluebubbles/attachment-cache.js +53 -0
- package/dist/senses/bluebubbles/attachment-download.js +137 -0
- package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +225 -9
- package/dist/senses/bluebubbles/entry.js +13 -0
- package/dist/senses/bluebubbles/inbound-log.js +113 -0
- package/dist/senses/bluebubbles/index.js +1590 -0
- package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -70
- package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +43 -12
- package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +46 -6
- package/dist/senses/bluebubbles/replay.js +129 -0
- package/dist/senses/bluebubbles/runtime-state.js +109 -0
- package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
- package/dist/senses/cli/bracketed-paste.js +82 -0
- package/dist/senses/cli/image-paste.js +287 -0
- package/dist/senses/cli/image-ref-navigation.js +75 -0
- package/dist/senses/cli/ink-app.js +156 -0
- package/dist/senses/cli/inline-diff.js +64 -0
- package/dist/senses/cli/input-keys.js +174 -0
- package/dist/senses/cli/kill-ring.js +86 -0
- package/dist/senses/cli/message-list.js +51 -0
- package/dist/senses/cli/ouro-tui.js +605 -0
- package/dist/senses/cli/spinner-imperative.js +135 -0
- package/dist/senses/cli/spinner.js +101 -0
- package/dist/senses/cli/status-line.js +60 -0
- package/dist/senses/cli/streaming-markdown.js +526 -0
- package/dist/senses/cli/tool-display.js +83 -0
- package/dist/senses/cli/tool-render.js +85 -0
- package/dist/senses/cli/tui-store.js +240 -0
- package/dist/senses/cli/virtual-list.js +35 -0
- package/dist/senses/cli-entry.js +1 -1
- package/dist/senses/cli-layout.js +187 -0
- package/dist/senses/cli.js +595 -246
- package/dist/senses/commands.js +65 -1
- package/dist/senses/continuity.js +94 -0
- package/dist/senses/habit-turn-message.js +108 -0
- package/dist/senses/inner-dialog-worker.js +112 -19
- package/dist/senses/inner-dialog.js +633 -86
- package/dist/senses/pipeline.js +567 -0
- package/dist/senses/shared-turn.js +199 -0
- package/dist/senses/surface-tool.js +68 -0
- package/dist/senses/teams.js +665 -160
- package/dist/senses/trust-gate.js +112 -2
- package/package.json +29 -7
- package/skills/agent-commerce.md +106 -0
- package/skills/browser-navigation.md +110 -0
- package/skills/commerce-setup-guide.md +116 -0
- package/skills/commerce-setup.md +84 -0
- package/skills/configure-dev-tools.md +81 -0
- package/skills/travel-planning.md +138 -0
- package/dist/heart/daemon/subagent-installer.js +0 -134
- package/dist/senses/bluebubbles-entry.js +0 -11
- package/dist/senses/bluebubbles.js +0 -547
- package/dist/senses/debug-activity.js +0 -124
- package/subagents/README.md +0 -73
- package/subagents/work-doer.md +0 -235
- package/subagents/work-merger.md +0 -618
- package/subagents/work-planner.md +0 -382
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
- /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
- /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
- /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
- /package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Type definitions for the `ouro doctor` system health check.
|
|
4
|
+
*
|
|
5
|
+
* Describes the structure of health check results: individual checks,
|
|
6
|
+
* grouped categories, and the aggregated result.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* System health check ("ouro doctor") — runs all diagnostic categories
|
|
4
|
+
* and aggregates results into a structured DoctorResult.
|
|
5
|
+
*
|
|
6
|
+
* Each category checker is isolated: if one throws, it produces a single
|
|
7
|
+
* "fail" check and the remaining categories still run.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.checkDaemon = checkDaemon;
|
|
11
|
+
exports.checkAgents = checkAgents;
|
|
12
|
+
exports.checkSenses = checkSenses;
|
|
13
|
+
exports.checkHabits = checkHabits;
|
|
14
|
+
exports.checkSecurity = checkSecurity;
|
|
15
|
+
exports.checkDisk = checkDisk;
|
|
16
|
+
exports.runDoctorChecks = runDoctorChecks;
|
|
17
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
18
|
+
const bluebubbles_health_diagnostics_1 = require("./bluebubbles-health-diagnostics");
|
|
19
|
+
const DEFAULT_BLUEBUBBLES_REQUEST_TIMEOUT_MS = 30_000;
|
|
20
|
+
// ── Category checkers ──
|
|
21
|
+
async function checkDaemon(deps) {
|
|
22
|
+
const checks = [];
|
|
23
|
+
const socketExists = deps.existsSync(deps.socketPath);
|
|
24
|
+
checks.push({
|
|
25
|
+
label: "daemon socket exists",
|
|
26
|
+
status: socketExists ? "pass" : "fail",
|
|
27
|
+
detail: socketExists ? deps.socketPath : `not found at ${deps.socketPath}`,
|
|
28
|
+
});
|
|
29
|
+
if (socketExists) {
|
|
30
|
+
const alive = await deps.checkSocketAlive(deps.socketPath);
|
|
31
|
+
checks.push({
|
|
32
|
+
label: "daemon is responsive",
|
|
33
|
+
status: alive ? "pass" : "fail",
|
|
34
|
+
detail: alive ? "socket responded" : "socket exists but daemon unresponsive",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
checks.push({
|
|
39
|
+
label: "daemon is responsive",
|
|
40
|
+
status: "fail",
|
|
41
|
+
detail: "skipped — socket missing",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return { name: "Daemon", checks };
|
|
45
|
+
}
|
|
46
|
+
/** Discover all *.ouro directories under bundlesRoot. */
|
|
47
|
+
function discoverAgents(deps) {
|
|
48
|
+
if (!deps.existsSync(deps.bundlesRoot))
|
|
49
|
+
return [];
|
|
50
|
+
return deps.readdirSync(deps.bundlesRoot).filter((name) => name.endsWith(".ouro"));
|
|
51
|
+
}
|
|
52
|
+
function asRecord(value) {
|
|
53
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
54
|
+
? value
|
|
55
|
+
: null;
|
|
56
|
+
}
|
|
57
|
+
function textField(record, key) {
|
|
58
|
+
const value = record?.[key];
|
|
59
|
+
return typeof value === "string" ? value.trim() : "";
|
|
60
|
+
}
|
|
61
|
+
function numberField(record, key, fallback) {
|
|
62
|
+
const value = record?.[key];
|
|
63
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
64
|
+
}
|
|
65
|
+
function readJsonObject(deps, filePath) {
|
|
66
|
+
try {
|
|
67
|
+
return asRecord(JSON.parse(deps.readFileSync(filePath)));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function checkAgents(deps) {
|
|
74
|
+
const checks = [];
|
|
75
|
+
if (!deps.existsSync(deps.bundlesRoot)) {
|
|
76
|
+
checks.push({ label: "bundles directory", status: "fail", detail: `${deps.bundlesRoot} not found` });
|
|
77
|
+
return { name: "Agents", checks };
|
|
78
|
+
}
|
|
79
|
+
const agents = discoverAgents(deps);
|
|
80
|
+
if (agents.length === 0) {
|
|
81
|
+
checks.push({ label: "agent bundles", status: "warn", detail: "no *.ouro bundles found" });
|
|
82
|
+
return { name: "Agents", checks };
|
|
83
|
+
}
|
|
84
|
+
for (const agentDir of agents) {
|
|
85
|
+
const agentPath = `${deps.bundlesRoot}/${agentDir}`;
|
|
86
|
+
const configPath = `${agentPath}/agent.json`;
|
|
87
|
+
if (!deps.existsSync(configPath)) {
|
|
88
|
+
checks.push({ label: `${agentDir}/agent.json`, status: "fail", detail: "missing" });
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
let config;
|
|
92
|
+
try {
|
|
93
|
+
config = JSON.parse(deps.readFileSync(configPath));
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
checks.push({ label: `${agentDir}/agent.json`, status: "fail", detail: "unparseable JSON" });
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const missing = [];
|
|
100
|
+
if (!config.version)
|
|
101
|
+
missing.push("version");
|
|
102
|
+
if (!config.humanFacing || typeof config.humanFacing !== "object") {
|
|
103
|
+
missing.push("humanFacing");
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const hf = config.humanFacing;
|
|
107
|
+
if (!hf.provider)
|
|
108
|
+
missing.push("humanFacing.provider");
|
|
109
|
+
if (!hf.model)
|
|
110
|
+
missing.push("humanFacing.model");
|
|
111
|
+
}
|
|
112
|
+
if (!config.agentFacing || typeof config.agentFacing !== "object") {
|
|
113
|
+
missing.push("agentFacing");
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const af = config.agentFacing;
|
|
117
|
+
if (!af.provider)
|
|
118
|
+
missing.push("agentFacing.provider");
|
|
119
|
+
if (!af.model)
|
|
120
|
+
missing.push("agentFacing.model");
|
|
121
|
+
}
|
|
122
|
+
if (missing.length > 0) {
|
|
123
|
+
checks.push({ label: `${agentDir}/agent.json`, status: "warn", detail: `missing fields: ${missing.join(", ")}` });
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
checks.push({ label: `${agentDir}/agent.json`, status: "pass", detail: "valid" });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { name: "Agents", checks };
|
|
130
|
+
}
|
|
131
|
+
async function checkSenses(deps) {
|
|
132
|
+
const checks = [];
|
|
133
|
+
const agents = discoverAgents(deps);
|
|
134
|
+
for (const agentDir of agents) {
|
|
135
|
+
const agentName = agentDir.replace(/\.ouro$/, "");
|
|
136
|
+
const configPath = `${deps.bundlesRoot}/${agentDir}/agent.json`;
|
|
137
|
+
if (!deps.existsSync(configPath))
|
|
138
|
+
continue;
|
|
139
|
+
let config;
|
|
140
|
+
try {
|
|
141
|
+
config = JSON.parse(deps.readFileSync(configPath));
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
checks.push({ label: `${agentDir} senses`, status: "fail", detail: "agent.json unparseable" });
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (!config.senses || typeof config.senses !== "object") {
|
|
148
|
+
checks.push({ label: `${agentDir} senses`, status: "warn", detail: "no senses config block" });
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const senses = config.senses;
|
|
152
|
+
const senseNames = ["cli", "teams", "bluebubbles"];
|
|
153
|
+
for (const sense of senseNames) {
|
|
154
|
+
if (!(sense in senses))
|
|
155
|
+
continue;
|
|
156
|
+
const entry = senses[sense];
|
|
157
|
+
if (!entry || typeof entry !== "object") {
|
|
158
|
+
checks.push({ label: `${agentDir} ${sense}`, status: "fail", detail: "malformed sense entry" });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const senseObj = entry;
|
|
162
|
+
if (typeof senseObj.enabled !== "boolean") {
|
|
163
|
+
checks.push({ label: `${agentDir} ${sense}`, status: "warn", detail: "missing enabled boolean" });
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
checks.push({
|
|
167
|
+
label: `${agentDir} ${sense}`,
|
|
168
|
+
status: "pass",
|
|
169
|
+
detail: senseObj.enabled ? "enabled" : "disabled",
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (sense === "bluebubbles" && senseObj.enabled === true) {
|
|
173
|
+
const secretsPath = `${deps.secretsRoot}/${agentName}/secrets.json`;
|
|
174
|
+
if (!deps.existsSync(secretsPath)) {
|
|
175
|
+
checks.push({
|
|
176
|
+
label: `${agentDir} bluebubbles config`,
|
|
177
|
+
status: "fail",
|
|
178
|
+
detail: "missing secrets.json",
|
|
179
|
+
});
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const secrets = readJsonObject(deps, secretsPath);
|
|
183
|
+
if (!secrets) {
|
|
184
|
+
checks.push({
|
|
185
|
+
label: `${agentDir} bluebubbles config`,
|
|
186
|
+
status: "fail",
|
|
187
|
+
detail: "secrets.json unparseable",
|
|
188
|
+
});
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const bluebubbles = asRecord(secrets.bluebubbles);
|
|
192
|
+
const bluebubblesChannel = asRecord(secrets.bluebubblesChannel);
|
|
193
|
+
const serverUrl = textField(bluebubbles, "serverUrl");
|
|
194
|
+
const password = textField(bluebubbles, "password");
|
|
195
|
+
const missing = [];
|
|
196
|
+
if (!serverUrl)
|
|
197
|
+
missing.push("bluebubbles.serverUrl");
|
|
198
|
+
if (!password)
|
|
199
|
+
missing.push("bluebubbles.password");
|
|
200
|
+
if (missing.length > 0) {
|
|
201
|
+
checks.push({
|
|
202
|
+
label: `${agentDir} bluebubbles config`,
|
|
203
|
+
status: "fail",
|
|
204
|
+
detail: `missing ${missing.join("/")}`,
|
|
205
|
+
});
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
checks.push({
|
|
209
|
+
label: `${agentDir} bluebubbles config`,
|
|
210
|
+
status: "pass",
|
|
211
|
+
detail: serverUrl,
|
|
212
|
+
});
|
|
213
|
+
if (deps.fetchImpl) {
|
|
214
|
+
const probe = await (0, bluebubbles_health_diagnostics_1.probeBlueBubblesHealth)({
|
|
215
|
+
serverUrl,
|
|
216
|
+
password,
|
|
217
|
+
requestTimeoutMs: numberField(bluebubblesChannel, "requestTimeoutMs", DEFAULT_BLUEBUBBLES_REQUEST_TIMEOUT_MS),
|
|
218
|
+
fetchImpl: deps.fetchImpl,
|
|
219
|
+
});
|
|
220
|
+
checks.push({
|
|
221
|
+
label: `${agentDir} bluebubbles upstream`,
|
|
222
|
+
status: probe.ok ? "pass" : "fail",
|
|
223
|
+
detail: probe.detail,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (checks.length === 0) {
|
|
230
|
+
checks.push({ label: "senses", status: "warn", detail: "no agents with senses config found" });
|
|
231
|
+
}
|
|
232
|
+
return { name: "Senses", checks };
|
|
233
|
+
}
|
|
234
|
+
function checkHabits(deps) {
|
|
235
|
+
const checks = [];
|
|
236
|
+
const agents = discoverAgents(deps);
|
|
237
|
+
for (const agentDir of agents) {
|
|
238
|
+
const agentName = agentDir.replace(/\.ouro$/, "");
|
|
239
|
+
const habitsDir = `${deps.bundlesRoot}/${agentDir}/habits`;
|
|
240
|
+
if (!deps.existsSync(habitsDir)) {
|
|
241
|
+
checks.push({ label: `${agentDir} habits dir`, status: "warn", detail: "no habits directory" });
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
checks.push({ label: `${agentDir} habits dir`, status: "pass", detail: habitsDir });
|
|
245
|
+
// Check for launchd plists on macOS
|
|
246
|
+
const launchAgentsDir = `${deps.homedir}/Library/LaunchAgents`;
|
|
247
|
+
if (deps.existsSync(launchAgentsDir)) {
|
|
248
|
+
const plists = deps.readdirSync(launchAgentsDir).filter((f) => f.startsWith(`bot.ouro.${agentName}.`) && f.endsWith(".plist"));
|
|
249
|
+
if (plists.length > 0) {
|
|
250
|
+
checks.push({ label: `${agentDir} launchd plists`, status: "pass", detail: `${plists.length} plist(s)` });
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
checks.push({ label: `${agentDir} launchd plists`, status: "fail", detail: "no matching plists in LaunchAgents" });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (checks.length === 0) {
|
|
258
|
+
checks.push({ label: "habits", status: "warn", detail: "no agents found" });
|
|
259
|
+
}
|
|
260
|
+
return { name: "Habits", checks };
|
|
261
|
+
}
|
|
262
|
+
function checkSecurity(deps) {
|
|
263
|
+
const checks = [];
|
|
264
|
+
const agents = discoverAgents(deps);
|
|
265
|
+
for (const agentDir of agents) {
|
|
266
|
+
const agentName = agentDir.replace(/\.ouro$/, "");
|
|
267
|
+
const secretsPath = `${deps.secretsRoot}/${agentName}/secrets.json`;
|
|
268
|
+
if (!deps.existsSync(secretsPath)) {
|
|
269
|
+
checks.push({ label: `${agentDir} secrets.json`, status: "fail", detail: "missing" });
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
// Check file permissions
|
|
273
|
+
const stat = deps.statSync(secretsPath);
|
|
274
|
+
const worldReadable = (stat.mode & 0o004) !== 0;
|
|
275
|
+
if (worldReadable) {
|
|
276
|
+
checks.push({ label: `${agentDir} secrets.json perms`, status: "warn", detail: "world-readable — consider chmod 600" });
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
checks.push({ label: `${agentDir} secrets.json perms`, status: "pass", detail: "not world-readable" });
|
|
280
|
+
}
|
|
281
|
+
// Check agent.json for leaked credential keys
|
|
282
|
+
const configPath = `${deps.bundlesRoot}/${agentDir}/agent.json`;
|
|
283
|
+
if (deps.existsSync(configPath)) {
|
|
284
|
+
try {
|
|
285
|
+
const raw = deps.readFileSync(configPath);
|
|
286
|
+
const sensitiveKeys = ["apiKey", "token", "secret", "password"];
|
|
287
|
+
const found = sensitiveKeys.filter((key) => raw.includes(`"${key}"`));
|
|
288
|
+
if (found.length > 0) {
|
|
289
|
+
checks.push({ label: `${agentDir} credential leak`, status: "warn", detail: `agent.json contains keys: ${found.join(", ")}` });
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
checks.push({ label: `${agentDir} credential leak`, status: "pass", detail: "no credential keys in agent.json" });
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
checks.push({ label: `${agentDir} credential leak`, status: "fail", detail: "could not read agent.json" });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (checks.length === 0) {
|
|
301
|
+
checks.push({ label: "security", status: "warn", detail: "no agents found" });
|
|
302
|
+
}
|
|
303
|
+
return { name: "Security", checks };
|
|
304
|
+
}
|
|
305
|
+
function checkDisk(deps) {
|
|
306
|
+
const checks = [];
|
|
307
|
+
// Check daemon logs directory
|
|
308
|
+
const logsDir = `${deps.homedir}/.ouro-cli/logs`;
|
|
309
|
+
if (!deps.existsSync(logsDir)) {
|
|
310
|
+
checks.push({ label: "daemon logs dir", status: "warn", detail: `${logsDir} not found` });
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
let totalSize = 0;
|
|
314
|
+
try {
|
|
315
|
+
const files = deps.readdirSync(logsDir);
|
|
316
|
+
for (const file of files) {
|
|
317
|
+
try {
|
|
318
|
+
const stat = deps.statSync(`${logsDir}/${file}`);
|
|
319
|
+
totalSize += stat.size;
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
// skip unreadable files
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
// readdirSync failure handled below
|
|
328
|
+
}
|
|
329
|
+
const sizeMB = totalSize / (1024 * 1024);
|
|
330
|
+
if (sizeMB > 500) {
|
|
331
|
+
checks.push({ label: "daemon log size", status: "fail", detail: `${sizeMB.toFixed(1)}MB — exceeds 500MB limit` });
|
|
332
|
+
}
|
|
333
|
+
else if (sizeMB > 100) {
|
|
334
|
+
checks.push({ label: "daemon log size", status: "warn", detail: `${sizeMB.toFixed(1)}MB — consider pruning with \`ouro logs prune\`` });
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
checks.push({ label: "daemon log size", status: "pass", detail: `${sizeMB.toFixed(1)}MB` });
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// Check AgentBundles root
|
|
341
|
+
if (deps.existsSync(deps.bundlesRoot)) {
|
|
342
|
+
checks.push({ label: "bundles root", status: "pass", detail: deps.bundlesRoot });
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
checks.push({ label: "bundles root", status: "warn", detail: `${deps.bundlesRoot} not found` });
|
|
346
|
+
}
|
|
347
|
+
return { name: "Disk", checks };
|
|
348
|
+
}
|
|
349
|
+
// ── Orchestrator ──
|
|
350
|
+
function computeSummary(categories) {
|
|
351
|
+
let passed = 0;
|
|
352
|
+
let warnings = 0;
|
|
353
|
+
let failed = 0;
|
|
354
|
+
for (const cat of categories) {
|
|
355
|
+
for (const check of cat.checks) {
|
|
356
|
+
/* v8 ignore next 3 -- all three branches tested; v8 misreports compound if/else-if chain @preserve */
|
|
357
|
+
if (check.status === "pass")
|
|
358
|
+
passed++;
|
|
359
|
+
else if (check.status === "warn")
|
|
360
|
+
warnings++;
|
|
361
|
+
else
|
|
362
|
+
failed++;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return { passed, warnings, failed };
|
|
366
|
+
}
|
|
367
|
+
const CATEGORY_CHECKERS = [
|
|
368
|
+
{ name: "Daemon", fn: checkDaemon },
|
|
369
|
+
{ name: "Agents", fn: checkAgents },
|
|
370
|
+
{ name: "Senses", fn: checkSenses },
|
|
371
|
+
{ name: "Habits", fn: checkHabits },
|
|
372
|
+
{ name: "Security", fn: checkSecurity },
|
|
373
|
+
{ name: "Disk", fn: checkDisk },
|
|
374
|
+
];
|
|
375
|
+
async function runDoctorChecks(deps) {
|
|
376
|
+
const categories = [];
|
|
377
|
+
for (const checker of CATEGORY_CHECKERS) {
|
|
378
|
+
try {
|
|
379
|
+
const category = await Promise.resolve(checker.fn(deps));
|
|
380
|
+
categories.push(category);
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
(0, runtime_1.emitNervesEvent)({
|
|
384
|
+
level: "warn",
|
|
385
|
+
component: "daemon",
|
|
386
|
+
event: "daemon.doctor_check_error",
|
|
387
|
+
message: `doctor check ${checker.name} failed`,
|
|
388
|
+
meta: { category: checker.name, error: error instanceof Error ? error.message : String(error) },
|
|
389
|
+
});
|
|
390
|
+
categories.push({
|
|
391
|
+
name: checker.name,
|
|
392
|
+
checks: [{
|
|
393
|
+
label: checker.name.toLowerCase(),
|
|
394
|
+
status: "fail",
|
|
395
|
+
detail: `check crashed: ${error instanceof Error ? error.message : String(error)}`,
|
|
396
|
+
}],
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return { categories, summary: computeSummary(categories) };
|
|
401
|
+
}
|
|
@@ -7,22 +7,74 @@ class HealthMonitor {
|
|
|
7
7
|
scheduler;
|
|
8
8
|
alertSink;
|
|
9
9
|
diskUsagePercent;
|
|
10
|
+
onCriticalAgent;
|
|
11
|
+
senseProbes;
|
|
12
|
+
intervalHandle = null;
|
|
10
13
|
constructor(options) {
|
|
11
14
|
this.processManager = options.processManager;
|
|
12
15
|
this.scheduler = options.scheduler;
|
|
13
16
|
this.alertSink = options.alertSink ?? (() => undefined);
|
|
14
17
|
this.diskUsagePercent = options.diskUsagePercent ?? (() => 0);
|
|
18
|
+
this.onCriticalAgent = options.onCriticalAgent ?? (() => undefined);
|
|
19
|
+
this.senseProbes = options.senseProbes ?? [];
|
|
20
|
+
}
|
|
21
|
+
startPeriodicChecks(intervalMs) {
|
|
22
|
+
if (this.intervalHandle !== null)
|
|
23
|
+
return;
|
|
24
|
+
(0, runtime_1.emitNervesEvent)({
|
|
25
|
+
level: "info",
|
|
26
|
+
component: "daemon",
|
|
27
|
+
event: "daemon.health_check_scheduled",
|
|
28
|
+
message: "periodic health checks started",
|
|
29
|
+
meta: { intervalMs },
|
|
30
|
+
});
|
|
31
|
+
this.intervalHandle = setInterval(() => {
|
|
32
|
+
void this.runChecks();
|
|
33
|
+
}, intervalMs);
|
|
34
|
+
}
|
|
35
|
+
stopPeriodicChecks() {
|
|
36
|
+
if (this.intervalHandle === null)
|
|
37
|
+
return;
|
|
38
|
+
clearInterval(this.intervalHandle);
|
|
39
|
+
this.intervalHandle = null;
|
|
15
40
|
}
|
|
16
41
|
async runChecks() {
|
|
17
42
|
const results = [];
|
|
18
43
|
const snapshots = this.processManager.listAgentSnapshots();
|
|
19
44
|
const unhealthy = snapshots.filter((snapshot) => snapshot.status !== "running");
|
|
20
45
|
if (unhealthy.length > 0) {
|
|
46
|
+
const unhealthySummary = unhealthy.map((item) => {
|
|
47
|
+
const detail = [
|
|
48
|
+
item.errorReason ?? null,
|
|
49
|
+
item.fixHint ? `fix: ${item.fixHint}` : null,
|
|
50
|
+
].filter((part) => part !== null).join("; ");
|
|
51
|
+
return detail.length > 0 ? `${item.name} (${detail})` : item.name;
|
|
52
|
+
}).join(", ");
|
|
21
53
|
results.push({
|
|
22
54
|
name: "agent-processes",
|
|
23
55
|
status: "critical",
|
|
24
|
-
message: `non-running agents: ${
|
|
56
|
+
message: `non-running agents: ${unhealthySummary}`,
|
|
25
57
|
});
|
|
58
|
+
for (const agent of unhealthy) {
|
|
59
|
+
try {
|
|
60
|
+
(0, runtime_1.emitNervesEvent)({
|
|
61
|
+
level: "warn",
|
|
62
|
+
component: "daemon",
|
|
63
|
+
event: "daemon.health_check_recovery_attempted",
|
|
64
|
+
message: "triggering recovery restart for non-running agent",
|
|
65
|
+
meta: {
|
|
66
|
+
agentName: agent.name,
|
|
67
|
+
agentStatus: agent.status,
|
|
68
|
+
errorReason: agent.errorReason ?? null,
|
|
69
|
+
fixHint: agent.fixHint ?? null,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
this.onCriticalAgent(agent.name);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// Recovery is best-effort -- callback errors must not crash runChecks
|
|
76
|
+
}
|
|
77
|
+
}
|
|
26
78
|
}
|
|
27
79
|
else {
|
|
28
80
|
results.push({ name: "agent-processes", status: "ok", message: "all managed agents running" });
|
|
@@ -61,6 +113,32 @@ class HealthMonitor {
|
|
|
61
113
|
message: `disk usage healthy (${diskPercent}%)`,
|
|
62
114
|
});
|
|
63
115
|
}
|
|
116
|
+
for (const probe of this.senseProbes) {
|
|
117
|
+
try {
|
|
118
|
+
const outcome = await probe.check();
|
|
119
|
+
if (outcome.ok) {
|
|
120
|
+
results.push({
|
|
121
|
+
name: `sense-probe:${probe.name}`,
|
|
122
|
+
status: "ok",
|
|
123
|
+
message: `${probe.name} healthy`,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
results.push({
|
|
128
|
+
name: `sense-probe:${probe.name}`,
|
|
129
|
+
status: "critical",
|
|
130
|
+
message: `${probe.name} failed: ${outcome.detail ?? "unknown"}`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
results.push({
|
|
136
|
+
name: `sense-probe:${probe.name}`,
|
|
137
|
+
status: "critical",
|
|
138
|
+
message: `${probe.name} error: ${error instanceof Error ? error.message : String(error)}`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
64
142
|
for (const result of results) {
|
|
65
143
|
(0, runtime_1.emitNervesEvent)({
|
|
66
144
|
level: result.status === "critical" ? "error" : result.status === "warn" ? "warn" : "info",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agentConfigV2Hook = agentConfigV2Hook;
|
|
4
|
+
const runtime_1 = require("../../../nerves/runtime");
|
|
5
|
+
const migrate_config_1 = require("../../migrate-config");
|
|
6
|
+
async function agentConfigV2Hook(ctx) {
|
|
7
|
+
(0, runtime_1.emitNervesEvent)({
|
|
8
|
+
component: "daemon",
|
|
9
|
+
event: "daemon.agent_config_v2_hook_start",
|
|
10
|
+
message: "running agent-config-v2 update hook",
|
|
11
|
+
meta: { agentRoot: ctx.agentRoot, currentVersion: ctx.currentVersion },
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
(0, migrate_config_1.migrateAgentConfigV1ToV2)(ctx.agentRoot);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
const errorMessage = err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err);
|
|
18
|
+
(0, runtime_1.emitNervesEvent)({
|
|
19
|
+
component: "daemon",
|
|
20
|
+
event: "daemon.agent_config_v2_hook_error",
|
|
21
|
+
message: "agent-config-v2 hook migration failed",
|
|
22
|
+
meta: { agentRoot: ctx.agentRoot, error: errorMessage },
|
|
23
|
+
});
|
|
24
|
+
return { ok: false, error: errorMessage };
|
|
25
|
+
}
|
|
26
|
+
(0, runtime_1.emitNervesEvent)({
|
|
27
|
+
component: "daemon",
|
|
28
|
+
event: "daemon.agent_config_v2_hook_end",
|
|
29
|
+
message: "agent-config-v2 hook completed",
|
|
30
|
+
meta: { agentRoot: ctx.agentRoot },
|
|
31
|
+
});
|
|
32
|
+
return { ok: true };
|
|
33
|
+
}
|
|
@@ -37,6 +37,115 @@ exports.bundleMetaHook = bundleMetaHook;
|
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const runtime_1 = require("../../../nerves/runtime");
|
|
40
|
+
/**
|
|
41
|
+
* Migrate bundle from schema 1 to schema 2:
|
|
42
|
+
* - Move state/{episodes,obligations,cares,intentions}/* to arc/{name}/*
|
|
43
|
+
* - Move psyche/memory/* to diary/
|
|
44
|
+
* Idempotent: skips missing sources; on collision, newer mtime wins.
|
|
45
|
+
*/
|
|
46
|
+
function migrateToSchema2(agentRoot) {
|
|
47
|
+
(0, runtime_1.emitNervesEvent)({
|
|
48
|
+
component: "daemon",
|
|
49
|
+
event: "daemon.bundle_migration_start",
|
|
50
|
+
message: "migrating bundle to schema 2",
|
|
51
|
+
meta: { agentRoot },
|
|
52
|
+
});
|
|
53
|
+
// Migrate arc entities
|
|
54
|
+
for (const name of ["episodes", "obligations", "cares", "intentions"]) {
|
|
55
|
+
const src = path.join(agentRoot, "state", name);
|
|
56
|
+
const dest = path.join(agentRoot, "arc", name);
|
|
57
|
+
migrateDirectory(src, dest);
|
|
58
|
+
}
|
|
59
|
+
// Migrate diary
|
|
60
|
+
const memorySrc = path.join(agentRoot, "psyche", "memory");
|
|
61
|
+
const diaryDest = path.join(agentRoot, "diary");
|
|
62
|
+
migrateDirectory(memorySrc, diaryDest);
|
|
63
|
+
// Update bundle .gitignore
|
|
64
|
+
updateBundleGitignore(agentRoot);
|
|
65
|
+
(0, runtime_1.emitNervesEvent)({
|
|
66
|
+
component: "daemon",
|
|
67
|
+
event: "daemon.bundle_migration_end",
|
|
68
|
+
message: "bundle migration to schema 2 complete",
|
|
69
|
+
meta: { agentRoot },
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Ensure bundle .gitignore has state/ ignored and does NOT ignore arc/, diary/, journal/.
|
|
74
|
+
*/
|
|
75
|
+
function updateBundleGitignore(agentRoot) {
|
|
76
|
+
const gitignorePath = path.join(agentRoot, ".gitignore");
|
|
77
|
+
let lines = [];
|
|
78
|
+
try {
|
|
79
|
+
if (fs.existsSync(gitignorePath)) {
|
|
80
|
+
lines = fs.readFileSync(gitignorePath, "utf-8").split("\n");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// If we can't read, start fresh
|
|
85
|
+
}
|
|
86
|
+
// Remove arc/, diary/, journal/ from ignore (they should be tracked)
|
|
87
|
+
const toRemove = new Set(["arc/", "diary/", "journal/"]);
|
|
88
|
+
lines = lines.filter((line) => !toRemove.has(line.trim()));
|
|
89
|
+
// Ensure state/ is in the ignore list
|
|
90
|
+
const hasState = lines.some((line) => line.trim() === "state/");
|
|
91
|
+
if (!hasState) {
|
|
92
|
+
lines.push("state/");
|
|
93
|
+
}
|
|
94
|
+
// Write back, trimming trailing empty lines and ensuring trailing newline
|
|
95
|
+
const content = lines.join("\n").replace(/\n+$/, "") + "\n";
|
|
96
|
+
try {
|
|
97
|
+
fs.writeFileSync(gitignorePath, content, "utf-8");
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Non-blocking: if we can't write .gitignore, migration still succeeds
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Recursively copy files from src to dest.
|
|
105
|
+
* Creates destination directories as needed. Skips if source doesn't exist.
|
|
106
|
+
* When both source and destination exist, compares mtimes: newer file wins.
|
|
107
|
+
* Logs a warning either way when a collision is detected.
|
|
108
|
+
*/
|
|
109
|
+
function migrateDirectory(src, dest) {
|
|
110
|
+
if (!fs.existsSync(src))
|
|
111
|
+
return;
|
|
112
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
113
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
const srcPath = path.join(src, entry.name);
|
|
116
|
+
const destPath = path.join(dest, entry.name);
|
|
117
|
+
if (entry.isDirectory()) {
|
|
118
|
+
migrateDirectory(srcPath, destPath);
|
|
119
|
+
}
|
|
120
|
+
else if (!fs.existsSync(destPath)) {
|
|
121
|
+
fs.copyFileSync(srcPath, destPath);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// Collision: both source and destination exist — compare mtimes
|
|
125
|
+
const srcMtime = fs.statSync(srcPath).mtimeMs;
|
|
126
|
+
const destMtime = fs.statSync(destPath).mtimeMs;
|
|
127
|
+
if (srcMtime > destMtime) {
|
|
128
|
+
fs.copyFileSync(srcPath, destPath);
|
|
129
|
+
(0, runtime_1.emitNervesEvent)({
|
|
130
|
+
level: "warn",
|
|
131
|
+
component: "daemon",
|
|
132
|
+
event: "daemon.bundle_migration_collision",
|
|
133
|
+
message: `migration collision: source newer, overwriting destination`,
|
|
134
|
+
meta: { srcPath, destPath, srcMtime, destMtime },
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
(0, runtime_1.emitNervesEvent)({
|
|
139
|
+
level: "warn",
|
|
140
|
+
component: "daemon",
|
|
141
|
+
event: "daemon.bundle_migration_collision",
|
|
142
|
+
message: `migration collision: destination newer or equal, keeping destination`,
|
|
143
|
+
meta: { srcPath, destPath, srcMtime, destMtime },
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
40
149
|
async function bundleMetaHook(ctx) {
|
|
41
150
|
(0, runtime_1.emitNervesEvent)({
|
|
42
151
|
component: "daemon",
|
|
@@ -56,9 +165,14 @@ async function bundleMetaHook(ctx) {
|
|
|
56
165
|
// Malformed JSON -- treat as missing, will overwrite with fresh
|
|
57
166
|
existing = undefined;
|
|
58
167
|
}
|
|
168
|
+
// Run schema-2 migration if needed
|
|
169
|
+
const currentSchema = existing?.bundleSchemaVersion ?? 1;
|
|
170
|
+
if (currentSchema < 2) {
|
|
171
|
+
migrateToSchema2(ctx.agentRoot);
|
|
172
|
+
}
|
|
59
173
|
const updated = {
|
|
60
174
|
runtimeVersion: ctx.currentVersion,
|
|
61
|
-
bundleSchemaVersion:
|
|
175
|
+
bundleSchemaVersion: currentSchema < 2 ? 2 : currentSchema,
|
|
62
176
|
lastUpdated: new Date().toISOString(),
|
|
63
177
|
};
|
|
64
178
|
// Save old runtimeVersion as previousRuntimeVersion (if there was one)
|