@ouro.bot/cli 0.1.0-alpha.42 → 0.1.0-alpha.420
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 +118 -15
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +3 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +2 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +1 -1
- package/changelog.json +2627 -9
- 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 +58 -3
- 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 +424 -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 +110 -128
- package/dist/heart/core.js +801 -217
- package/dist/heart/cross-chat-delivery.js +131 -0
- package/dist/heart/daemon/agent-config-check.js +419 -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 +214 -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 +605 -0
- package/dist/heart/daemon/cli-exec.js +4140 -0
- package/dist/heart/daemon/cli-help.js +413 -0
- package/dist/heart/daemon/cli-parse.js +1151 -0
- package/dist/heart/daemon/cli-render-doctor.js +57 -0
- package/dist/heart/daemon/cli-render.js +561 -0
- package/dist/heart/daemon/cli-types.js +8 -0
- package/dist/heart/daemon/daemon-cli.js +28 -1582
- package/dist/heart/daemon/daemon-entry.js +356 -3
- package/dist/heart/daemon/daemon-health.js +141 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +171 -12
- package/dist/heart/daemon/daemon-tombstone.js +236 -0
- package/dist/heart/daemon/daemon.js +684 -58
- package/dist/heart/daemon/doctor-types.js +8 -0
- package/dist/heart/daemon/doctor.js +427 -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 +307 -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 +2 -2
- package/dist/heart/daemon/os-cron-deps.js +134 -0
- package/dist/heart/daemon/ouro-bot-entry.js +4 -2
- package/dist/heart/daemon/ouro-entry.js +3 -1
- package/dist/heart/daemon/process-manager.js +214 -0
- package/dist/heart/daemon/provider-discovery.js +137 -0
- package/dist/heart/daemon/pulse.js +475 -0
- package/dist/heart/daemon/readiness-repair.js +250 -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 +73 -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 +145 -32
- 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 +259 -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 +218 -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 +53 -117
- package/dist/heart/{daemon → hatch}/hatch-specialist.js +3 -3
- package/dist/heart/{daemon → hatch}/specialist-prompt.js +12 -9
- package/dist/heart/{daemon → hatch}/specialist-tools.js +35 -12
- package/dist/heart/identity.js +161 -65
- package/dist/heart/kept-notes.js +357 -0
- package/dist/heart/kicks.js +1 -1
- package/dist/heart/machine-identity.js +161 -0
- package/dist/heart/mcp/mcp-server.js +653 -0
- package/dist/heart/migrate-config.js +100 -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 +195 -0
- package/dist/heart/outlook/readers/agent-machine.js +359 -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 +232 -0
- package/dist/heart/outlook/readers/shared.js +111 -0
- package/dist/heart/platform.js +81 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/provider-attempt.js +133 -0
- package/dist/heart/provider-binding-resolver.js +239 -0
- package/dist/heart/provider-credentials.js +389 -0
- package/dist/heart/provider-failover.js +266 -0
- package/dist/heart/provider-models.js +81 -0
- package/dist/heart/provider-ping.js +237 -0
- package/dist/heart/provider-state.js +216 -0
- package/dist/heart/provider-visibility.js +186 -0
- package/dist/heart/providers/anthropic-token.js +131 -0
- package/dist/heart/providers/anthropic.js +193 -55
- package/dist/heart/providers/azure.js +103 -12
- package/dist/heart/providers/error-classification.js +63 -0
- package/dist/heart/providers/github-copilot.js +145 -0
- package/dist/heart/providers/minimax-vlm.js +189 -0
- package/dist/heart/providers/minimax.js +29 -7
- package/dist/heart/providers/openai-codex.js +62 -38
- package/dist/heart/runtime-credentials.js +260 -0
- package/dist/heart/sense-truth.js +3 -0
- package/dist/heart/session-activity.js +190 -0
- package/dist/heart/session-events.js +855 -0
- package/dist/heart/session-transcript.js +167 -0
- package/dist/heart/start-of-turn-packet.js +345 -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 +351 -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/versioning/ouro-path-installer.js +301 -0
- 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 +3 -1
- package/dist/heart/{daemon → versioning}/update-hooks.js +63 -59
- package/dist/mind/bundle-manifest.js +7 -1
- package/dist/mind/context.js +134 -87
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/{memory.js → diary.js} +74 -93
- 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 +21 -0
- package/dist/mind/friends/group-context.js +144 -0
- package/dist/mind/friends/resolver.js +38 -1
- package/dist/mind/friends/store-file.js +39 -3
- package/dist/mind/friends/trust-explanation.js +74 -0
- package/dist/mind/friends/types.js +1 -1
- package/dist/mind/journal-index.js +161 -0
- package/dist/mind/note-search.js +268 -0
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +66 -7
- package/dist/mind/prompt-refresh.js +3 -2
- package/dist/mind/prompt.js +948 -168
- package/dist/mind/provenance-trust.js +26 -0
- package/dist/mind/scrutiny.js +173 -0
- package/dist/nerves/cli-logging.js +7 -1
- package/dist/nerves/coverage/audit-rules.js +15 -6
- package/dist/nerves/coverage/audit.js +28 -2
- package/dist/nerves/coverage/cli.js +1 -1
- package/dist/nerves/coverage/contract.js +5 -5
- 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-BAcU08c-.css +1 -0
- package/dist/outlook-ui/assets/index-D7l3l4vY.js +61 -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 +702 -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 +111 -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 +371 -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 +15 -24
- 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 +26 -1
- 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 -78
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-attachments.js +317 -0
- package/dist/repertoire/tools-base.js +42 -687
- 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 +361 -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-notes.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 +9 -39
- package/dist/repertoire/tools-travel.js +125 -0
- package/dist/repertoire/tools-user-profile.js +144 -0
- package/dist/repertoire/tools-vault.js +40 -0
- package/dist/repertoire/tools.js +144 -113
- package/dist/repertoire/travel-api-client.js +360 -0
- package/dist/repertoire/user-profile.js +131 -0
- package/dist/repertoire/vault-setup.js +246 -0
- package/dist/repertoire/vault-unlock.js +421 -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} +260 -9
- package/dist/senses/bluebubbles/entry.js +73 -0
- package/dist/senses/bluebubbles/inbound-log.js +113 -0
- package/dist/senses/bluebubbles/index.js +1620 -0
- package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -70
- package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +33 -12
- package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +45 -3
- 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 +60 -8
- package/dist/senses/cli-layout.js +187 -0
- package/dist/senses/cli.js +526 -211
- package/dist/senses/commands.js +66 -3
- 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 +596 -94
- package/dist/senses/pipeline.js +539 -61
- package/dist/senses/proactive-content-guard.js +51 -0
- package/dist/senses/shared-turn.js +205 -0
- package/dist/senses/surface-tool.js +68 -0
- package/dist/senses/teams-entry.js +60 -8
- package/dist/senses/teams.js +569 -237
- package/dist/senses/trust-gate.js +5 -5
- package/package.json +29 -7
- package/skills/agent-commerce.md +106 -0
- package/skills/browser-navigation.md +117 -0
- package/skills/commerce-setup-guide.md +116 -0
- package/skills/commerce-setup.md +84 -0
- package/skills/configure-dev-tools.md +101 -0
- package/skills/travel-planning.md +138 -0
- package/dist/heart/daemon/ouro-path-installer.js +0 -178
- package/dist/heart/daemon/subagent-installer.js +0 -134
- package/dist/mind/associative-recall.js +0 -209
- package/dist/senses/bluebubbles-entry.js +0 -11
- package/dist/senses/bluebubbles.js +0 -832
- package/dist/senses/debug-activity.js +0 -127
- package/subagents/README.md +0 -60
- 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-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,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.diagnoseOuroPath = diagnoseOuroPath;
|
|
37
|
+
exports.installOuroCommand = installOuroCommand;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const os = __importStar(require("os"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
42
|
+
const WRAPPER_SCRIPT = `#!/bin/sh
|
|
43
|
+
# Check for dev mode — if dev-config.json exists, dispatch to the dev repo
|
|
44
|
+
# Skip dev dispatch for "up" command (explicitly returns to production)
|
|
45
|
+
DEV_CONFIG="$HOME/.ouro-cli/dev-config.json"
|
|
46
|
+
if [ -f "$DEV_CONFIG" ] && [ "$1" != "up" ]; then
|
|
47
|
+
DEV_REPO=$(node -e "try{console.log(JSON.parse(require('fs').readFileSync('$DEV_CONFIG','utf-8')).repoPath)}catch{}" 2>/dev/null)
|
|
48
|
+
DEV_ENTRY="$DEV_REPO/dist/heart/daemon/ouro-entry.js"
|
|
49
|
+
if [ -n "$DEV_REPO" ] && [ -e "$DEV_ENTRY" ]; then
|
|
50
|
+
exec node "$DEV_ENTRY" "$@"
|
|
51
|
+
fi
|
|
52
|
+
fi
|
|
53
|
+
# Fall back to installed version
|
|
54
|
+
ENTRY="$HOME/.ouro-cli/CurrentVersion/node_modules/@ouro.bot/cli/dist/heart/daemon/ouro-entry.js"
|
|
55
|
+
if [ ! -e "$ENTRY" ]; then
|
|
56
|
+
echo "ouro not installed. Run: npx ouro.bot" >&2
|
|
57
|
+
exit 1
|
|
58
|
+
fi
|
|
59
|
+
exec node "$ENTRY" "$@"
|
|
60
|
+
`;
|
|
61
|
+
function writeWrapperScript(scriptPath, mkdirSync, writeFileSync, chmodSync) {
|
|
62
|
+
mkdirSync(path.dirname(scriptPath), { recursive: true });
|
|
63
|
+
writeFileSync(scriptPath, WRAPPER_SCRIPT, { mode: 0o755 });
|
|
64
|
+
chmodSync(scriptPath, 0o755);
|
|
65
|
+
}
|
|
66
|
+
function detectShellProfile(homeDir, shell, platform) {
|
|
67
|
+
if (!shell)
|
|
68
|
+
return null;
|
|
69
|
+
const base = path.basename(shell);
|
|
70
|
+
if (base === "zsh")
|
|
71
|
+
return path.join(homeDir, ".zshrc");
|
|
72
|
+
if (base === "bash") {
|
|
73
|
+
// macOS uses .bash_profile; Linux/WSL uses .bashrc (the default
|
|
74
|
+
// interactive shell config on Debian/Ubuntu). Writing to .bash_profile
|
|
75
|
+
// on Linux often has no effect because non-login shells skip it.
|
|
76
|
+
/* v8 ignore next -- ?? fallback: callers always pass platform from deps @preserve */
|
|
77
|
+
const effectivePlatform = platform ?? process.platform;
|
|
78
|
+
return effectivePlatform === "darwin"
|
|
79
|
+
? path.join(homeDir, ".bash_profile")
|
|
80
|
+
: path.join(homeDir, ".bashrc");
|
|
81
|
+
}
|
|
82
|
+
if (base === "fish")
|
|
83
|
+
return path.join(homeDir, ".config", "fish", "config.fish");
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
function isBinDirInPath(binDir, envPath) {
|
|
87
|
+
return envPath.split(path.delimiter).some((p) => p === binDir);
|
|
88
|
+
}
|
|
89
|
+
function samePath(a, b) {
|
|
90
|
+
return path.resolve(a) === path.resolve(b);
|
|
91
|
+
}
|
|
92
|
+
function buildPathExportLine(binDir, shell) {
|
|
93
|
+
const base = shell ? path.basename(shell) : /* v8 ignore next -- unreachable: only called when detectShellProfile returns non-null, which requires shell @preserve */ "";
|
|
94
|
+
if (base === "fish") {
|
|
95
|
+
return `\n# Added by ouro\nset -gx PATH ${binDir} $PATH\n`;
|
|
96
|
+
}
|
|
97
|
+
return `\n# Added by ouro\nexport PATH="${binDir}:$PATH"\n`;
|
|
98
|
+
}
|
|
99
|
+
function isWrapperCurrent(scriptPath, existsSync, readFileSync) {
|
|
100
|
+
if (!existsSync(scriptPath))
|
|
101
|
+
return false;
|
|
102
|
+
try {
|
|
103
|
+
return readFileSync(scriptPath, "utf-8") === WRAPPER_SCRIPT;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function firstOuroOnPath(envPath, existsSync) {
|
|
110
|
+
for (const dir of envPath.split(path.delimiter)) {
|
|
111
|
+
if (!dir)
|
|
112
|
+
continue;
|
|
113
|
+
const candidate = path.join(dir, "ouro");
|
|
114
|
+
if (existsSync(candidate))
|
|
115
|
+
return candidate;
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
function diagnoseOuroPath(deps) {
|
|
120
|
+
const binDir = path.join(deps.homeDir, ".ouro-cli", "bin");
|
|
121
|
+
const expectedPath = path.join(binDir, "ouro");
|
|
122
|
+
const resolvedPath = firstOuroOnPath(deps.envPath, deps.existsSync);
|
|
123
|
+
if (!resolvedPath) {
|
|
124
|
+
return {
|
|
125
|
+
status: "missing",
|
|
126
|
+
expectedPath,
|
|
127
|
+
resolvedPath: null,
|
|
128
|
+
detail: `PATH does not resolve ouro; expected ${expectedPath}`,
|
|
129
|
+
remediation: `add ${binDir} to PATH or open a new shell after ouro up updates your shell profile`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (samePath(resolvedPath, expectedPath)) {
|
|
133
|
+
return {
|
|
134
|
+
status: "ok",
|
|
135
|
+
expectedPath,
|
|
136
|
+
resolvedPath,
|
|
137
|
+
detail: `PATH resolves ouro to ${expectedPath}`,
|
|
138
|
+
remediation: null,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (isWrapperCurrent(resolvedPath, deps.existsSync, deps.readFileSync)) {
|
|
142
|
+
return {
|
|
143
|
+
status: "ok",
|
|
144
|
+
expectedPath,
|
|
145
|
+
resolvedPath,
|
|
146
|
+
detail: `PATH resolves ouro through a compatible wrapper at ${resolvedPath}`,
|
|
147
|
+
remediation: null,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const shadowDir = path.dirname(resolvedPath);
|
|
151
|
+
return {
|
|
152
|
+
status: "shadowed",
|
|
153
|
+
expectedPath,
|
|
154
|
+
resolvedPath,
|
|
155
|
+
detail: `PATH resolves ouro to ${resolvedPath} before ${expectedPath}`,
|
|
156
|
+
remediation: `move ${binDir} before ${shadowDir} in PATH, or remove/replace ${resolvedPath} after confirming it is the stale ouro launcher`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function installOuroCommand(deps = {}) {
|
|
160
|
+
/* v8 ignore start -- dep defaults: only used in real runtime, tests always inject @preserve */
|
|
161
|
+
const platform = deps.platform ?? process.platform;
|
|
162
|
+
const homeDir = deps.homeDir ?? os.homedir();
|
|
163
|
+
const existsSync = deps.existsSync ?? fs.existsSync;
|
|
164
|
+
const mkdirSync = deps.mkdirSync ?? fs.mkdirSync;
|
|
165
|
+
const writeFileSync = deps.writeFileSync ?? fs.writeFileSync;
|
|
166
|
+
const readFileSync = deps.readFileSync ?? ((p, enc) => fs.readFileSync(p, enc));
|
|
167
|
+
const appendFileSync = deps.appendFileSync ?? fs.appendFileSync;
|
|
168
|
+
const chmodSync = deps.chmodSync ?? fs.chmodSync;
|
|
169
|
+
const envPath = deps.envPath ?? process.env.PATH ?? "";
|
|
170
|
+
const shell = deps.shell ?? process.env.SHELL;
|
|
171
|
+
/* v8 ignore stop */
|
|
172
|
+
if (platform === "win32") {
|
|
173
|
+
(0, runtime_1.emitNervesEvent)({
|
|
174
|
+
component: "daemon",
|
|
175
|
+
event: "daemon.ouro_path_install_skip",
|
|
176
|
+
message: "skipped ouro PATH install on Windows",
|
|
177
|
+
meta: { platform },
|
|
178
|
+
});
|
|
179
|
+
return { installed: false, scriptPath: null, pathReady: false, shellProfileUpdated: null, skippedReason: "windows", repairedOldLauncher: false };
|
|
180
|
+
}
|
|
181
|
+
// Ensure ~/.ouro-cli/ directory layout exists
|
|
182
|
+
if (deps.ensureCliLayout) {
|
|
183
|
+
deps.ensureCliLayout();
|
|
184
|
+
}
|
|
185
|
+
const binDir = path.join(homeDir, ".ouro-cli", "bin");
|
|
186
|
+
const scriptPath = path.join(binDir, "ouro");
|
|
187
|
+
const oldScriptPath = path.join(homeDir, ".local", "bin", "ouro");
|
|
188
|
+
const resolvePath = () => diagnoseOuroPath({ homeDir, envPath, existsSync, readFileSync });
|
|
189
|
+
const modernCurrent = isWrapperCurrent(scriptPath, existsSync, readFileSync);
|
|
190
|
+
const oldExists = existsSync(oldScriptPath);
|
|
191
|
+
const oldCurrent = oldExists && isWrapperCurrent(oldScriptPath, existsSync, readFileSync);
|
|
192
|
+
// ── Repair old ~/.local/bin/ouro launcher ──
|
|
193
|
+
// If the old launcher exists with stale content it can shadow the modern
|
|
194
|
+
// path and cause the wrong CLI version to run. Overwrite it with the
|
|
195
|
+
// current wrapper so both paths resolve to ~/.ouro-cli/CurrentVersion.
|
|
196
|
+
let repairedOldLauncher = false;
|
|
197
|
+
if (oldExists && !oldCurrent) {
|
|
198
|
+
(0, runtime_1.emitNervesEvent)({
|
|
199
|
+
component: "daemon",
|
|
200
|
+
event: "daemon.ouro_path_repair_old",
|
|
201
|
+
message: "repairing stale old launcher at ~/.local/bin/ouro",
|
|
202
|
+
meta: { oldScriptPath },
|
|
203
|
+
});
|
|
204
|
+
try {
|
|
205
|
+
writeFileSync(oldScriptPath, WRAPPER_SCRIPT, { mode: 0o755 });
|
|
206
|
+
chmodSync(oldScriptPath, 0o755);
|
|
207
|
+
repairedOldLauncher = true;
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
// Best effort — old launcher repair failure must not block modern install
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// ── Fast-path: modern wrapper already current ──
|
|
214
|
+
if (modernCurrent) {
|
|
215
|
+
const pathResolution = resolvePath();
|
|
216
|
+
if (pathResolution.status === "shadowed") {
|
|
217
|
+
(0, runtime_1.emitNervesEvent)({
|
|
218
|
+
level: "warn",
|
|
219
|
+
component: "daemon",
|
|
220
|
+
event: "daemon.ouro_path_shadowed",
|
|
221
|
+
message: "PATH resolves ouro to a stale external launcher",
|
|
222
|
+
meta: { resolvedPath: pathResolution.resolvedPath, expectedPath: pathResolution.expectedPath, remediation: pathResolution.remediation },
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
(0, runtime_1.emitNervesEvent)({
|
|
226
|
+
component: "daemon",
|
|
227
|
+
event: "daemon.ouro_path_install_skip",
|
|
228
|
+
message: "ouro command already installed",
|
|
229
|
+
meta: { scriptPath, pathStatus: pathResolution.status, resolvedPath: pathResolution.resolvedPath },
|
|
230
|
+
});
|
|
231
|
+
return { installed: false, scriptPath, pathReady: isBinDirInPath(binDir, envPath), shellProfileUpdated: null, skippedReason: "already-installed", repairedOldLauncher, pathResolution };
|
|
232
|
+
}
|
|
233
|
+
(0, runtime_1.emitNervesEvent)({
|
|
234
|
+
component: "daemon",
|
|
235
|
+
event: "daemon.ouro_path_install_start",
|
|
236
|
+
message: existsSync(scriptPath) ? "repairing stale ouro wrapper script" : "installing ouro command to PATH",
|
|
237
|
+
meta: { scriptPath, binDir },
|
|
238
|
+
});
|
|
239
|
+
try {
|
|
240
|
+
if (!modernCurrent) {
|
|
241
|
+
writeWrapperScript(scriptPath, mkdirSync, writeFileSync, chmodSync);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
(0, runtime_1.emitNervesEvent)({
|
|
246
|
+
level: "warn",
|
|
247
|
+
component: "daemon",
|
|
248
|
+
event: "daemon.ouro_path_install_error",
|
|
249
|
+
message: "failed to install ouro command",
|
|
250
|
+
meta: { error: error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error) },
|
|
251
|
+
});
|
|
252
|
+
return { installed: false, scriptPath: null, pathReady: false, shellProfileUpdated: null, skippedReason: error instanceof Error ? error.message : /* v8 ignore next -- defensive @preserve */ String(error), repairedOldLauncher };
|
|
253
|
+
}
|
|
254
|
+
// Check if ~/.ouro-cli/bin is already in PATH
|
|
255
|
+
const pathReady = isBinDirInPath(binDir, envPath);
|
|
256
|
+
let shellProfileUpdated = null;
|
|
257
|
+
if (!pathReady) {
|
|
258
|
+
const profilePath = detectShellProfile(homeDir, shell, platform);
|
|
259
|
+
if (profilePath) {
|
|
260
|
+
try {
|
|
261
|
+
let existing = "";
|
|
262
|
+
try {
|
|
263
|
+
existing = readFileSync(profilePath, "utf-8");
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
// Profile doesn't exist yet — that's fine, we'll create it
|
|
267
|
+
}
|
|
268
|
+
if (!existing.includes(binDir)) {
|
|
269
|
+
appendFileSync(profilePath, buildPathExportLine(binDir, shell));
|
|
270
|
+
shellProfileUpdated = profilePath;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
(0, runtime_1.emitNervesEvent)({
|
|
275
|
+
level: "warn",
|
|
276
|
+
component: "daemon",
|
|
277
|
+
event: "daemon.ouro_path_profile_error",
|
|
278
|
+
message: "failed to update shell profile for PATH",
|
|
279
|
+
meta: { profilePath, error: error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error) },
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const pathResolution = resolvePath();
|
|
285
|
+
if (pathResolution.status === "shadowed") {
|
|
286
|
+
(0, runtime_1.emitNervesEvent)({
|
|
287
|
+
level: "warn",
|
|
288
|
+
component: "daemon",
|
|
289
|
+
event: "daemon.ouro_path_shadowed",
|
|
290
|
+
message: "PATH resolves ouro to a stale external launcher",
|
|
291
|
+
meta: { resolvedPath: pathResolution.resolvedPath, expectedPath: pathResolution.expectedPath, remediation: pathResolution.remediation },
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
(0, runtime_1.emitNervesEvent)({
|
|
295
|
+
component: "daemon",
|
|
296
|
+
event: "daemon.ouro_path_install_end",
|
|
297
|
+
message: "ouro command installed",
|
|
298
|
+
meta: { scriptPath, pathReady, shellProfileUpdated, oldScriptPath: oldExists ? oldScriptPath : null, pathStatus: pathResolution.status, resolvedPath: pathResolution.resolvedPath },
|
|
299
|
+
});
|
|
300
|
+
return { installed: true, scriptPath, pathReady, shellProfileUpdated, repairedOldLauncher, pathResolution };
|
|
301
|
+
}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DEFAULT_RETAIN_VERSIONS = void 0;
|
|
37
|
+
exports.getOuroCliHome = getOuroCliHome;
|
|
38
|
+
exports.getCurrentVersion = getCurrentVersion;
|
|
39
|
+
exports.getPreviousVersion = getPreviousVersion;
|
|
40
|
+
exports.buildChangelogCommand = buildChangelogCommand;
|
|
41
|
+
exports.listInstalledVersions = listInstalledVersions;
|
|
42
|
+
exports.installVersion = installVersion;
|
|
43
|
+
exports.activateVersion = activateVersion;
|
|
44
|
+
exports.compareCliVersions = compareCliVersions;
|
|
45
|
+
exports.selectVersionsToPrune = selectVersionsToPrune;
|
|
46
|
+
exports.pruneOldVersions = pruneOldVersions;
|
|
47
|
+
exports.ensureLayout = ensureLayout;
|
|
48
|
+
const fs = __importStar(require("fs"));
|
|
49
|
+
const os = __importStar(require("os"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
52
|
+
/** Maximum number of installed CLI versions to retain after pruning. */
|
|
53
|
+
exports.DEFAULT_RETAIN_VERSIONS = 5;
|
|
54
|
+
function getOuroCliHome(homeDir) {
|
|
55
|
+
/* v8 ignore next -- dep default: tests always inject @preserve */
|
|
56
|
+
const home = homeDir ?? os.homedir();
|
|
57
|
+
return path.join(home, ".ouro-cli");
|
|
58
|
+
}
|
|
59
|
+
function getCurrentVersion(deps) {
|
|
60
|
+
const cliHome = getOuroCliHome(deps.homeDir);
|
|
61
|
+
/* v8 ignore next -- dep default: tests always inject @preserve */
|
|
62
|
+
const readlinkSync = deps.readlinkSync ?? fs.readlinkSync;
|
|
63
|
+
try {
|
|
64
|
+
const target = readlinkSync(path.join(cliHome, "CurrentVersion"));
|
|
65
|
+
return path.basename(target);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function getPreviousVersion(deps) {
|
|
72
|
+
const cliHome = getOuroCliHome(deps.homeDir);
|
|
73
|
+
/* v8 ignore next -- dep default: tests always inject @preserve */
|
|
74
|
+
const readlinkSync = deps.readlinkSync ?? fs.readlinkSync;
|
|
75
|
+
try {
|
|
76
|
+
const target = readlinkSync(path.join(cliHome, "previous"));
|
|
77
|
+
return path.basename(target);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function buildChangelogCommand(previousVersion, currentVersion) {
|
|
84
|
+
if (!previousVersion || !currentVersion || previousVersion === currentVersion) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return `ouro changelog --from ${previousVersion}`;
|
|
88
|
+
}
|
|
89
|
+
function listInstalledVersions(deps) {
|
|
90
|
+
const cliHome = getOuroCliHome(deps.homeDir);
|
|
91
|
+
/* v8 ignore next -- dep default: tests always inject @preserve */
|
|
92
|
+
const readdirSync = deps.readdirSync ?? ((p, opts) => fs.readdirSync(p, opts));
|
|
93
|
+
try {
|
|
94
|
+
const entries = readdirSync(path.join(cliHome, "versions"), { withFileTypes: true });
|
|
95
|
+
return entries.filter((e) => e.isDirectory()).map((e) => e.name);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function installVersion(version, deps) {
|
|
102
|
+
const cliHome = getOuroCliHome(deps.homeDir);
|
|
103
|
+
/* v8 ignore start -- dep defaults: tests always inject @preserve */
|
|
104
|
+
const mkdirSync = deps.mkdirSync ?? fs.mkdirSync;
|
|
105
|
+
const execSync = deps.execSync ?? ((cmd, opts) => require("child_process").execSync(cmd, opts));
|
|
106
|
+
/* v8 ignore stop */
|
|
107
|
+
const versionDir = path.join(cliHome, "versions", version);
|
|
108
|
+
(0, runtime_1.emitNervesEvent)({
|
|
109
|
+
component: "daemon",
|
|
110
|
+
event: "daemon.cli_version_install_start",
|
|
111
|
+
message: "installing CLI version",
|
|
112
|
+
meta: { version, versionDir },
|
|
113
|
+
});
|
|
114
|
+
mkdirSync(versionDir, { recursive: true });
|
|
115
|
+
execSync(`npm install --prefix ${versionDir} @ouro.bot/cli@${version}`, { stdio: "pipe" });
|
|
116
|
+
(0, runtime_1.emitNervesEvent)({
|
|
117
|
+
component: "daemon",
|
|
118
|
+
event: "daemon.cli_version_install_end",
|
|
119
|
+
message: "CLI version installed",
|
|
120
|
+
meta: { version, versionDir },
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function activateVersion(version, deps) {
|
|
124
|
+
const cliHome = getOuroCliHome(deps.homeDir);
|
|
125
|
+
/* v8 ignore start -- dep defaults: tests always inject @preserve */
|
|
126
|
+
const readlinkSync = deps.readlinkSync ?? fs.readlinkSync;
|
|
127
|
+
const unlinkSync = deps.unlinkSync ?? fs.unlinkSync;
|
|
128
|
+
const symlinkSync = deps.symlinkSync ?? fs.symlinkSync;
|
|
129
|
+
const existsSync = deps.existsSync ?? fs.existsSync;
|
|
130
|
+
/* v8 ignore stop */
|
|
131
|
+
const currentVersionPath = path.join(cliHome, "CurrentVersion");
|
|
132
|
+
const previousPath = path.join(cliHome, "previous");
|
|
133
|
+
const newTarget = path.join(cliHome, "versions", version);
|
|
134
|
+
(0, runtime_1.emitNervesEvent)({
|
|
135
|
+
component: "daemon",
|
|
136
|
+
event: "daemon.cli_version_activate",
|
|
137
|
+
message: "activating CLI version",
|
|
138
|
+
meta: { version },
|
|
139
|
+
});
|
|
140
|
+
// Read old CurrentVersion target (may not exist)
|
|
141
|
+
let oldTarget = null;
|
|
142
|
+
try {
|
|
143
|
+
oldTarget = readlinkSync(currentVersionPath);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// No current version — first install
|
|
147
|
+
}
|
|
148
|
+
// Update previous symlink to point to old current
|
|
149
|
+
if (oldTarget) {
|
|
150
|
+
try {
|
|
151
|
+
unlinkSync(previousPath);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// previous symlink may not exist yet
|
|
155
|
+
}
|
|
156
|
+
symlinkSync(oldTarget, previousPath);
|
|
157
|
+
}
|
|
158
|
+
// Update CurrentVersion symlink
|
|
159
|
+
if (existsSync(currentVersionPath)) {
|
|
160
|
+
unlinkSync(currentVersionPath);
|
|
161
|
+
}
|
|
162
|
+
symlinkSync(newTarget, currentVersionPath);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Compare two version strings of the form `0.1.0-alpha.{n}`. Returns
|
|
166
|
+
* positive when `a` is newer, negative when `b` is newer, 0 when equal.
|
|
167
|
+
*
|
|
168
|
+
* The harness only ships `0.1.0-alpha.{n}` versions today; this comparator
|
|
169
|
+
* extracts the numeric tail and falls back to a lexicographic compare for
|
|
170
|
+
* any version that doesn't match the pattern (so unexpected version
|
|
171
|
+
* formats sort consistently rather than throwing).
|
|
172
|
+
*/
|
|
173
|
+
function compareCliVersions(a, b) {
|
|
174
|
+
const aMatch = /alpha\.(\d+)/.exec(a);
|
|
175
|
+
const bMatch = /alpha\.(\d+)/.exec(b);
|
|
176
|
+
if (aMatch && bMatch) {
|
|
177
|
+
const aN = parseInt(aMatch[1], 10);
|
|
178
|
+
const bN = parseInt(bMatch[1], 10);
|
|
179
|
+
return aN - bN;
|
|
180
|
+
}
|
|
181
|
+
// Fallback: lexicographic. Both-mismatched and one-mismatched cases land
|
|
182
|
+
// here. Predictable, even if not strictly semver-correct.
|
|
183
|
+
if (a < b)
|
|
184
|
+
return -1;
|
|
185
|
+
if (a > b)
|
|
186
|
+
return 1;
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Identify which installed CLI versions can be safely deleted, given a
|
|
191
|
+
* retention policy. Pure: takes the full version list and the protected
|
|
192
|
+
* (current/previous) versions, returns the versions to delete.
|
|
193
|
+
*
|
|
194
|
+
* Retention rules:
|
|
195
|
+
* - Always keep the N most recent versions (default 5).
|
|
196
|
+
* - Always keep the currently-active version (CurrentVersion symlink target).
|
|
197
|
+
* - Always keep the previous version (previous symlink target) so rollback
|
|
198
|
+
* stays one command away.
|
|
199
|
+
* - Delete everything else.
|
|
200
|
+
*
|
|
201
|
+
* Exported so tests can pin the policy without shelling out to a real fs.
|
|
202
|
+
*/
|
|
203
|
+
function selectVersionsToPrune(installedVersions, protectedVersions, retain = exports.DEFAULT_RETAIN_VERSIONS) {
|
|
204
|
+
if (installedVersions.length <= retain)
|
|
205
|
+
return [];
|
|
206
|
+
const sorted = [...installedVersions].sort(compareCliVersions).reverse();
|
|
207
|
+
const keepers = new Set(sorted.slice(0, retain));
|
|
208
|
+
if (protectedVersions.current)
|
|
209
|
+
keepers.add(protectedVersions.current);
|
|
210
|
+
if (protectedVersions.previous)
|
|
211
|
+
keepers.add(protectedVersions.previous);
|
|
212
|
+
return installedVersions.filter((v) => !keepers.has(v));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Prune installed CLI versions according to the retention policy. Removes
|
|
216
|
+
* `~/.ouro-cli/versions/{version}/` directories for versions outside the
|
|
217
|
+
* retention window. Best-effort: per-version delete failures are logged
|
|
218
|
+
* via nerves but don't propagate.
|
|
219
|
+
*
|
|
220
|
+
* Called from the activate path (cli-defaults.ts) so that every successful
|
|
221
|
+
* `ouro up` self-prunes. The user observed `~/.ouro-cli/versions/` going
|
|
222
|
+
* back to alpha.85 from March 20 — every CLI version they'd ever installed
|
|
223
|
+
* was still on disk because nothing ever GCed.
|
|
224
|
+
*/
|
|
225
|
+
function pruneOldVersions(retain = exports.DEFAULT_RETAIN_VERSIONS, deps = {}) {
|
|
226
|
+
const cliHome = getOuroCliHome(deps.homeDir);
|
|
227
|
+
/* v8 ignore start -- dep defaults: tests always inject @preserve */
|
|
228
|
+
const readdirSync = deps.readdirSync ?? ((p, opts) => fs.readdirSync(p, opts));
|
|
229
|
+
const readlinkSync = deps.readlinkSync ?? fs.readlinkSync;
|
|
230
|
+
const rmSync = deps.rmSync ?? fs.rmSync;
|
|
231
|
+
/* v8 ignore stop */
|
|
232
|
+
const versionsDir = path.join(cliHome, "versions");
|
|
233
|
+
let installed;
|
|
234
|
+
try {
|
|
235
|
+
installed = readdirSync(versionsDir, { withFileTypes: true })
|
|
236
|
+
.filter((e) => e.isDirectory())
|
|
237
|
+
.map((e) => e.name);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return { kept: [], deleted: [], failed: [] };
|
|
241
|
+
}
|
|
242
|
+
const current = (() => {
|
|
243
|
+
try {
|
|
244
|
+
return path.basename(readlinkSync(path.join(cliHome, "CurrentVersion")));
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
})();
|
|
250
|
+
const previous = (() => {
|
|
251
|
+
try {
|
|
252
|
+
return path.basename(readlinkSync(path.join(cliHome, "previous")));
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
})();
|
|
258
|
+
const toDelete = selectVersionsToPrune(installed, { current, previous }, retain);
|
|
259
|
+
const deleted = [];
|
|
260
|
+
const failed = [];
|
|
261
|
+
for (const version of toDelete) {
|
|
262
|
+
const versionDir = path.join(versionsDir, version);
|
|
263
|
+
try {
|
|
264
|
+
rmSync(versionDir, { recursive: true, force: true });
|
|
265
|
+
deleted.push(version);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
failed.push({
|
|
269
|
+
version,
|
|
270
|
+
error: error instanceof Error ? error.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(error),
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
(0, runtime_1.emitNervesEvent)({
|
|
275
|
+
component: "daemon",
|
|
276
|
+
event: "daemon.cli_versions_pruned",
|
|
277
|
+
message: `pruned ${deleted.length} old CLI versions`,
|
|
278
|
+
meta: { retain, deleted, failed: failed.length, kept: installed.filter((v) => !deleted.includes(v)) },
|
|
279
|
+
});
|
|
280
|
+
return { kept: installed.filter((v) => !deleted.includes(v)), deleted, failed };
|
|
281
|
+
}
|
|
282
|
+
function ensureLayout(deps) {
|
|
283
|
+
const cliHome = getOuroCliHome(deps.homeDir);
|
|
284
|
+
/* v8 ignore next -- dep default: tests always inject @preserve */
|
|
285
|
+
const mkdirSync = deps.mkdirSync ?? fs.mkdirSync;
|
|
286
|
+
mkdirSync(cliHome, { recursive: true });
|
|
287
|
+
mkdirSync(path.join(cliHome, "bin"), { recursive: true });
|
|
288
|
+
mkdirSync(path.join(cliHome, "versions"), { recursive: true });
|
|
289
|
+
(0, runtime_1.emitNervesEvent)({
|
|
290
|
+
component: "daemon",
|
|
291
|
+
event: "daemon.cli_layout_ensured",
|
|
292
|
+
message: "CLI directory layout ensured",
|
|
293
|
+
meta: { cliHome },
|
|
294
|
+
});
|
|
295
|
+
}
|
|
@@ -45,14 +45,22 @@ async function performStagedRestart(version, deps) {
|
|
|
45
45
|
});
|
|
46
46
|
// Step 1: Install new version
|
|
47
47
|
try {
|
|
48
|
-
deps.
|
|
48
|
+
if (deps.installNewVersion) {
|
|
49
|
+
deps.installNewVersion(version);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Backward-compat fallback for callers that haven't migrated to the
|
|
53
|
+
// version-managed installer. Tests use this path with a mocked
|
|
54
|
+
// execSync; production callers inject installNewVersion.
|
|
55
|
+
deps.execSync(`npm install -g @ouro.bot/cli@${version}`);
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
catch (err) {
|
|
51
59
|
const errorMessage = err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err);
|
|
52
60
|
(0, runtime_1.emitNervesEvent)({
|
|
53
61
|
component: "daemon",
|
|
54
62
|
event: "daemon.staged_restart_install_failed",
|
|
55
|
-
message: "
|
|
63
|
+
message: "install failed",
|
|
56
64
|
meta: { version, error: errorMessage },
|
|
57
65
|
});
|
|
58
66
|
return { ok: false, error: errorMessage };
|
|
@@ -90,25 +98,49 @@ async function performStagedRestart(version, deps) {
|
|
|
90
98
|
});
|
|
91
99
|
return { ok: false, error: `hook runner exited with code ${spawnResult.status}` };
|
|
92
100
|
}
|
|
93
|
-
// Step 4: Graceful shutdown
|
|
101
|
+
// Step 4: Graceful shutdown then self-spawn new daemon
|
|
102
|
+
// We can't rely on launchd KeepAlive — the plist may not be loaded.
|
|
103
|
+
// Instead: shut down (releases socket), spawn new daemon from updated code.
|
|
94
104
|
(0, runtime_1.emitNervesEvent)({
|
|
95
105
|
component: "daemon",
|
|
96
106
|
event: "daemon.staged_restart_hooks_passed",
|
|
97
|
-
message: "hooks passed, shutting down
|
|
107
|
+
message: "hooks passed, shutting down and spawning new daemon",
|
|
98
108
|
meta: { version },
|
|
99
109
|
});
|
|
110
|
+
let shutdownError;
|
|
100
111
|
try {
|
|
101
112
|
await deps.gracefulShutdown();
|
|
102
113
|
}
|
|
103
114
|
catch (err) {
|
|
104
|
-
|
|
115
|
+
shutdownError = err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err);
|
|
105
116
|
(0, runtime_1.emitNervesEvent)({
|
|
106
117
|
component: "daemon",
|
|
107
118
|
event: "daemon.staged_restart_shutdown_error",
|
|
108
|
-
message: "graceful shutdown encountered error",
|
|
119
|
+
message: "graceful shutdown encountered error (continuing with spawn)",
|
|
109
120
|
meta: { version, error: shutdownError },
|
|
110
121
|
});
|
|
111
|
-
return { ok: true, shutdownError };
|
|
112
122
|
}
|
|
113
|
-
|
|
123
|
+
// Spawn new daemon from updated code path
|
|
124
|
+
const newEntry = path.join(newCodePath, "dist", "heart", "daemon", "daemon-entry.js");
|
|
125
|
+
const socketArg = deps.socketPath ?? "/tmp/ouroboros-daemon.sock";
|
|
126
|
+
try {
|
|
127
|
+
const { pid } = deps.spawnNewDaemon(newEntry, socketArg);
|
|
128
|
+
(0, runtime_1.emitNervesEvent)({
|
|
129
|
+
component: "daemon",
|
|
130
|
+
event: "daemon.staged_restart_spawned",
|
|
131
|
+
message: "new daemon spawned successfully",
|
|
132
|
+
meta: { version, pid, entry: newEntry },
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
const spawnError = err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err);
|
|
137
|
+
(0, runtime_1.emitNervesEvent)({
|
|
138
|
+
component: "daemon",
|
|
139
|
+
event: "daemon.staged_restart_respawn_failed",
|
|
140
|
+
message: "failed to spawn new daemon after shutdown",
|
|
141
|
+
meta: { version, error: spawnError, entry: newEntry },
|
|
142
|
+
});
|
|
143
|
+
return { ok: false, error: `shutdown succeeded but failed to spawn new daemon: ${spawnError}`, shutdownError };
|
|
144
|
+
}
|
|
145
|
+
return { ok: true, shutdownError };
|
|
114
146
|
}
|