@ouro.bot/cli 0.1.0-alpha.51 → 0.1.0-alpha.53

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/changelog.json CHANGED
@@ -1,6 +1,23 @@
1
1
  {
2
2
  "_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
3
3
  "versions": [
4
+ {
5
+ "version": "0.1.0-alpha.53",
6
+ "changes": [
7
+ "Daemon plist now inherits PATH from the installing process, so child agent spawns can find node regardless of launchd's minimal default environment.",
8
+ "Daemon startup and status output now show the entry path and runtime mode (dev vs production) so it's immediately obvious where the daemon is running from and whether it's a dev repo, worktree, or npm install.",
9
+ "Agent spawn in the process manager now validates the entry script exists before calling spawn, setting the agent to crashed with a clear error instead of an opaque ENOENT.",
10
+ "Plist write warns when the entry path doesn't exist on disk, catching stale worktree paths before they cause daemon crashes."
11
+ ]
12
+ },
13
+ {
14
+ "version": "0.1.0-alpha.52",
15
+ "changes": [
16
+ "Trusted 1:1 chats can now act live across active group threads: the harness resolves candidate target chats, carries explicit trust context into the model, and delivers messages into the right live BlueBubbles or Teams session instead of only queueing for later.",
17
+ "People discovered through a relevant live group are now bootstrapped as acquaintances with shared-group context, so the agent gets a socially truthful model of who is merely unknown versus who is known through the current group.",
18
+ "Cross-chat work now returns a truthful outcome back to the asking chat, and bridge suggestions can span different outward relationships when one live piece of work is clearly happening across them."
19
+ ]
20
+ },
4
21
  {
5
22
  "version": "0.1.0-alpha.51",
6
23
  "changes": [
@@ -5,6 +5,7 @@ exports.buildActiveWorkFrame = buildActiveWorkFrame;
5
5
  exports.formatActiveWorkFrame = formatActiveWorkFrame;
6
6
  const runtime_1 = require("../nerves/runtime");
7
7
  const state_machine_1 = require("./bridges/state-machine");
8
+ const target_resolution_1 = require("./target-resolution");
8
9
  function activityPriority(source) {
9
10
  return source === "friend-facing" ? 0 : 1;
10
11
  }
@@ -31,16 +32,28 @@ function hasSharedObligationPressure(input) {
31
32
  || summarizeLiveTasks(input.taskBoard).length > 0;
32
33
  }
33
34
  function suggestBridgeForActiveWork(input) {
34
- const candidateSessions = input.friendSessions
35
- .filter((session) => !input.currentSession
36
- || session.friendId !== input.currentSession.friendId
37
- || session.channel !== input.currentSession.channel
38
- || session.key !== input.currentSession.key)
39
- .sort(compareActivity);
40
- const targetSession = candidateSessions[0] ?? null;
41
- if (!targetSession || !hasSharedObligationPressure(input)) {
35
+ const targetCandidates = (input.targetCandidates ?? [])
36
+ .filter((candidate) => {
37
+ if (candidate.delivery.mode === "blocked") {
38
+ return false;
39
+ }
40
+ if (candidate.activitySource !== "friend-facing" || candidate.channel === "inner") {
41
+ return false;
42
+ }
43
+ if (!input.currentSession) {
44
+ return true;
45
+ }
46
+ return !(candidate.friendId === input.currentSession.friendId
47
+ && candidate.channel === input.currentSession.channel
48
+ && candidate.key === input.currentSession.key);
49
+ })
50
+ .sort((a, b) => {
51
+ return b.lastActivityMs - a.lastActivityMs;
52
+ });
53
+ if (!hasSharedObligationPressure(input) || targetCandidates.length !== 1) {
42
54
  return null;
43
55
  }
56
+ const targetSession = targetCandidates[0];
44
57
  const activeBridge = input.bridges.find(isActiveBridge) ?? null;
45
58
  if (activeBridge) {
46
59
  const alreadyAttached = activeBridge.attachedSessions.some((session) => session.friendId === targetSession.friendId
@@ -53,14 +66,14 @@ function suggestBridgeForActiveWork(input) {
53
66
  kind: "attach-existing",
54
67
  bridgeId: activeBridge.id,
55
68
  targetSession,
56
- reason: "same-friend-shared-work",
69
+ reason: "shared-work-candidate",
57
70
  };
58
71
  }
59
72
  return {
60
73
  kind: "begin-new",
61
74
  targetSession,
62
75
  objectiveHint: input.currentObligation?.trim() || "keep this shared work aligned",
63
- reason: "same-friend-shared-work",
76
+ reason: "shared-work-candidate",
64
77
  };
65
78
  }
66
79
  function formatSessionLabel(session) {
@@ -95,13 +108,14 @@ function buildActiveWorkFrame(input) {
95
108
  freshestForCurrentFriend: friendSessions[0] ?? null,
96
109
  otherLiveSessionsForCurrentFriend: friendSessions,
97
110
  },
111
+ targetCandidates: input.targetCandidates ?? [],
98
112
  bridgeSuggestion: suggestBridgeForActiveWork({
99
113
  currentSession: input.currentSession,
100
114
  currentObligation: input.currentObligation,
101
115
  mustResolveBeforeHandoff: input.mustResolveBeforeHandoff,
102
116
  bridges: input.bridges,
103
117
  taskBoard: input.taskBoard,
104
- friendSessions,
118
+ targetCandidates: input.targetCandidates,
105
119
  }),
106
120
  };
107
121
  (0, runtime_1.emitNervesEvent)({
@@ -144,6 +158,13 @@ function formatActiveWorkFrame(frame) {
144
158
  if (frame.friendActivity?.freshestForCurrentFriend) {
145
159
  lines.push(`freshest friend-facing session: ${formatSessionLabel(frame.friendActivity.freshestForCurrentFriend)}`);
146
160
  }
161
+ const targetCandidatesBlock = frame.targetCandidates && frame.targetCandidates.length > 0
162
+ ? (0, target_resolution_1.formatTargetSessionCandidates)(frame.targetCandidates)
163
+ : "";
164
+ if (targetCandidatesBlock) {
165
+ lines.push("");
166
+ lines.push(targetCandidatesBlock);
167
+ }
147
168
  if (frame.bridgeSuggestion) {
148
169
  if (frame.bridgeSuggestion.kind === "attach-existing") {
149
170
  lines.push(`suggested bridge: attach ${frame.bridgeSuggestion.bridgeId} -> ${formatSessionLabel(frame.bridgeSuggestion.targetSession)}`);
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deliverCrossChatMessage = deliverCrossChatMessage;
4
+ const types_1 = require("../mind/friends/types");
5
+ const runtime_1 = require("../nerves/runtime");
6
+ function buildPendingEnvelope(request, agentName, now) {
7
+ return {
8
+ from: agentName,
9
+ friendId: request.friendId,
10
+ channel: request.channel,
11
+ key: request.key,
12
+ content: request.content,
13
+ timestamp: now,
14
+ };
15
+ }
16
+ function queueForLater(request, deps, detail) {
17
+ deps.queuePending(buildPendingEnvelope(request, deps.agentName, (deps.now ?? Date.now)()));
18
+ return {
19
+ status: "queued_for_later",
20
+ detail,
21
+ };
22
+ }
23
+ function isExplicitlyAuthorized(request) {
24
+ return request.intent === "explicit_cross_chat"
25
+ && Boolean(request.authorizingSession)
26
+ && (0, types_1.isTrustedLevel)(request.authorizingSession?.trustLevel);
27
+ }
28
+ async function deliverCrossChatMessage(request, deps) {
29
+ (0, runtime_1.emitNervesEvent)({
30
+ component: "engine",
31
+ event: "engine.cross_chat_delivery_start",
32
+ message: "resolving cross-chat delivery",
33
+ meta: {
34
+ friendId: request.friendId,
35
+ channel: request.channel,
36
+ key: request.key,
37
+ intent: request.intent,
38
+ authorizingTrustLevel: request.authorizingSession?.trustLevel ?? null,
39
+ },
40
+ });
41
+ if (request.intent === "generic_outreach") {
42
+ const result = queueForLater(request, deps, "generic outreach stays queued until the target session is next active");
43
+ (0, runtime_1.emitNervesEvent)({
44
+ component: "engine",
45
+ event: "engine.cross_chat_delivery_end",
46
+ message: "queued generic outreach for later delivery",
47
+ meta: {
48
+ friendId: request.friendId,
49
+ channel: request.channel,
50
+ key: request.key,
51
+ status: result.status,
52
+ },
53
+ });
54
+ return result;
55
+ }
56
+ if (!isExplicitlyAuthorized(request)) {
57
+ const result = {
58
+ status: "blocked",
59
+ detail: "explicit cross-chat delivery requires a trusted asking session",
60
+ };
61
+ (0, runtime_1.emitNervesEvent)({
62
+ level: "warn",
63
+ component: "engine",
64
+ event: "engine.cross_chat_delivery_end",
65
+ message: "blocked explicit cross-chat delivery",
66
+ meta: {
67
+ friendId: request.friendId,
68
+ channel: request.channel,
69
+ key: request.key,
70
+ status: result.status,
71
+ },
72
+ });
73
+ return result;
74
+ }
75
+ const deliverer = deps.deliverers?.[request.channel];
76
+ if (!deliverer) {
77
+ const result = queueForLater(request, deps, "live delivery unavailable right now; queued for the next active turn");
78
+ (0, runtime_1.emitNervesEvent)({
79
+ component: "engine",
80
+ event: "engine.cross_chat_delivery_end",
81
+ message: "queued explicit cross-chat delivery because no live deliverer was available",
82
+ meta: {
83
+ friendId: request.friendId,
84
+ channel: request.channel,
85
+ key: request.key,
86
+ status: result.status,
87
+ },
88
+ });
89
+ return result;
90
+ }
91
+ try {
92
+ const direct = await deliverer(request);
93
+ if (direct.status === "delivered_now" || direct.status === "blocked" || direct.status === "failed") {
94
+ const result = {
95
+ status: direct.status,
96
+ detail: direct.detail,
97
+ };
98
+ (0, runtime_1.emitNervesEvent)({
99
+ level: result.status === "failed" ? "error" : result.status === "blocked" ? "warn" : "info",
100
+ component: "engine",
101
+ event: "engine.cross_chat_delivery_end",
102
+ message: "completed direct cross-chat delivery resolution",
103
+ meta: {
104
+ friendId: request.friendId,
105
+ channel: request.channel,
106
+ key: request.key,
107
+ status: result.status,
108
+ },
109
+ });
110
+ return result;
111
+ }
112
+ const result = queueForLater(request, deps, direct.detail.trim() || "live delivery unavailable right now; queued for the next active turn");
113
+ (0, runtime_1.emitNervesEvent)({
114
+ component: "engine",
115
+ event: "engine.cross_chat_delivery_end",
116
+ message: "queued explicit cross-chat delivery after adapter reported unavailability",
117
+ meta: {
118
+ friendId: request.friendId,
119
+ channel: request.channel,
120
+ key: request.key,
121
+ status: result.status,
122
+ },
123
+ });
124
+ return result;
125
+ }
126
+ catch (error) {
127
+ const result = {
128
+ status: "failed",
129
+ detail: error instanceof Error ? error.message : String(error),
130
+ };
131
+ (0, runtime_1.emitNervesEvent)({
132
+ level: "error",
133
+ component: "engine",
134
+ event: "engine.cross_chat_delivery_end",
135
+ message: "cross-chat delivery threw unexpectedly",
136
+ meta: {
137
+ friendId: request.friendId,
138
+ channel: request.channel,
139
+ key: request.key,
140
+ status: result.status,
141
+ reason: result.detail,
142
+ },
143
+ });
144
+ return result;
145
+ }
146
+ }
@@ -55,6 +55,7 @@ const specialist_orchestrator_1 = require("./specialist-orchestrator");
55
55
  const specialist_prompt_1 = require("./specialist-prompt");
56
56
  const specialist_tools_1 = require("./specialist-tools");
57
57
  const runtime_metadata_1 = require("./runtime-metadata");
58
+ const runtime_mode_1 = require("./runtime-mode");
58
59
  const daemon_runtime_sync_1 = require("./daemon-runtime-sync");
59
60
  const agent_discovery_1 = require("./agent-discovery");
60
61
  const update_hooks_1 = require("./update-hooks");
@@ -94,6 +95,8 @@ function parseStatusPayload(data) {
94
95
  lastUpdated: stringField(overview.lastUpdated) ?? "unknown",
95
96
  workerCount: numberField(overview.workerCount) ?? 0,
96
97
  senseCount: numberField(overview.senseCount) ?? 0,
98
+ entryPath: stringField(overview.entryPath) ?? "unknown",
99
+ mode: stringField(overview.mode) ?? "unknown",
97
100
  };
98
101
  const parsedSenses = senses.map((entry) => {
99
102
  if (!entry || typeof entry !== "object" || Array.isArray(entry))
@@ -174,6 +177,8 @@ function formatDaemonStatusOutput(response, fallback) {
174
177
  ["Socket", payload.overview.socketPath],
175
178
  ["Version", payload.overview.version],
176
179
  ["Last Updated", payload.overview.lastUpdated],
180
+ ["Entry Path", payload.overview.entryPath],
181
+ ["Mode", payload.overview.mode],
177
182
  ["Workers", String(payload.overview.workerCount)],
178
183
  ["Senses", String(payload.overview.senseCount)],
179
184
  ["Health", payload.overview.health],
@@ -272,6 +277,7 @@ function formatVersionOutput() {
272
277
  }
273
278
  function buildStoppedStatusPayload(socketPath) {
274
279
  const metadata = (0, runtime_metadata_1.getRuntimeMetadata)();
280
+ const repoRoot = (0, identity_1.getRepoRoot)();
275
281
  return {
276
282
  overview: {
277
283
  daemon: "stopped",
@@ -281,6 +287,8 @@ function buildStoppedStatusPayload(socketPath) {
281
287
  lastUpdated: metadata.lastUpdated,
282
288
  workerCount: 0,
283
289
  senseCount: 0,
290
+ entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
291
+ mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
284
292
  },
285
293
  senses: [],
286
294
  workers: [],
@@ -729,12 +737,23 @@ function defaultEnsureDaemonBootPersistence(socketPath) {
729
737
  homeDir,
730
738
  };
731
739
  const entryPath = path.join((0, identity_1.getRepoRoot)(), "dist", "heart", "daemon", "daemon-entry.js");
740
+ /* v8 ignore next -- covered via mock in daemon-cli-defaults.test.ts; v8 on CI attributes the real fs.existsSync branch to the non-mock load @preserve */
741
+ if (!fs.existsSync(entryPath)) {
742
+ (0, runtime_1.emitNervesEvent)({
743
+ level: "warn",
744
+ component: "daemon",
745
+ event: "daemon.entry_path_missing",
746
+ message: "entryPath does not exist on disk — plist may point to a stale location. Run 'ouro daemon install' from the correct location.",
747
+ meta: { entryPath },
748
+ });
749
+ }
732
750
  const logDir = path.join(homeDir, ".agentstate", "daemon", "logs");
733
751
  (0, launchd_1.writeLaunchAgentPlist)(launchdDeps, {
734
752
  nodePath: process.execPath,
735
753
  entryPath,
736
754
  socketPath,
737
755
  logDir,
756
+ envPath: process.env.PATH,
738
757
  });
739
758
  }
740
759
  async function defaultInstallSubagents() {
@@ -1,6 +1,41 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
3
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
4
39
  const process_manager_1 = require("./process-manager");
5
40
  const daemon_1 = require("./daemon");
6
41
  const runtime_1 = require("../../nerves/runtime");
@@ -10,6 +45,8 @@ const task_scheduler_1 = require("./task-scheduler");
10
45
  const runtime_logging_1 = require("./runtime-logging");
11
46
  const sense_manager_1 = require("./sense-manager");
12
47
  const agent_discovery_1 = require("./agent-discovery");
48
+ const identity_1 = require("../identity");
49
+ const runtime_mode_1 = require("./runtime-mode");
13
50
  function parseSocketPath(argv) {
14
51
  const socketIndex = argv.indexOf("--socket");
15
52
  if (socketIndex >= 0) {
@@ -21,11 +58,13 @@ function parseSocketPath(argv) {
21
58
  }
22
59
  const socketPath = parseSocketPath(process.argv);
23
60
  (0, runtime_logging_1.configureDaemonRuntimeLogger)("daemon");
61
+ const entryPath = path.resolve(__dirname, "daemon-entry.js");
62
+ const mode = (0, runtime_mode_1.detectRuntimeMode)((0, identity_1.getRepoRoot)());
24
63
  (0, runtime_1.emitNervesEvent)({
25
64
  component: "daemon",
26
65
  event: "daemon.entry_start",
27
66
  message: "starting daemon entrypoint",
28
- meta: { socketPath },
67
+ meta: { socketPath, entryPath, mode },
29
68
  });
30
69
  const managedAgents = (0, agent_discovery_1.listEnabledBundleAgents)();
31
70
  const processManager = new process_manager_1.DaemonProcessManager({
@@ -35,6 +74,7 @@ const processManager = new process_manager_1.DaemonProcessManager({
35
74
  channel: "inner-dialog",
36
75
  autoStart: true,
37
76
  })),
77
+ existsSync: fs.existsSync,
38
78
  });
39
79
  const scheduler = new task_scheduler_1.TaskDrivenScheduler({
40
80
  agents: [...managedAgents],
@@ -40,6 +40,7 @@ const path = __importStar(require("path"));
40
40
  const identity_1 = require("../identity");
41
41
  const runtime_1 = require("../../nerves/runtime");
42
42
  const runtime_metadata_1 = require("./runtime-metadata");
43
+ const runtime_mode_1 = require("./runtime-mode");
43
44
  const update_hooks_1 = require("./update-hooks");
44
45
  const bundle_meta_1 = require("./hooks/bundle-meta");
45
46
  const bundle_manifest_1 = require("../../mind/bundle-manifest");
@@ -373,6 +374,7 @@ class OuroDaemon {
373
374
  const snapshots = this.processManager.listAgentSnapshots();
374
375
  const workers = buildWorkerRows(snapshots);
375
376
  const senses = this.senseManager?.listSenseRows() ?? [];
377
+ const repoRoot = (0, identity_1.getRepoRoot)();
376
378
  const data = {
377
379
  overview: {
378
380
  daemon: "running",
@@ -381,6 +383,8 @@ class OuroDaemon {
381
383
  ...(0, runtime_metadata_1.getRuntimeMetadata)(),
382
384
  workerCount: workers.length,
383
385
  senseCount: senses.length,
386
+ entryPath: path.join(repoRoot, "dist", "heart", "daemon", "daemon-entry.js"),
387
+ mode: (0, runtime_mode_1.detectRuntimeMode)(repoRoot),
384
388
  },
385
389
  workers,
386
390
  senses,
@@ -71,6 +71,9 @@ function generateDaemonPlist(options) {
71
71
  ` <key>KeepAlive</key>`,
72
72
  ` <true/>`,
73
73
  ];
74
+ if (options.envPath) {
75
+ lines.push(` <key>EnvironmentVariables</key>`, ` <dict>`, ` <key>PATH</key>`, ` <string>${options.envPath}</string>`, ` </dict>`);
76
+ }
74
77
  if (options.logDir) {
75
78
  lines.push(` <key>StandardOutPath</key>`, ` <string>${path.join(options.logDir, "ouro-daemon-stdout.log")}</string>`, ` <key>StandardErrorPath</key>`, ` <string>${path.join(options.logDir, "ouro-daemon-stderr.log")}</string>`);
76
79
  }
@@ -51,6 +51,7 @@ class DaemonProcessManager {
51
51
  now;
52
52
  setTimeoutFn;
53
53
  clearTimeoutFn;
54
+ existsSyncFn;
54
55
  constructor(options) {
55
56
  this.maxRestartsPerHour = options.maxRestartsPerHour ?? 10;
56
57
  this.stabilityThresholdMs = options.stabilityThresholdMs ?? 60_000;
@@ -60,6 +61,7 @@ class DaemonProcessManager {
60
61
  this.now = options.now ?? (() => Date.now());
61
62
  this.setTimeoutFn = options.setTimeoutFn ?? ((cb, delay) => setTimeout(cb, delay));
62
63
  this.clearTimeoutFn = options.clearTimeoutFn ?? ((timer) => clearTimeout(timer));
64
+ this.existsSyncFn = options.existsSync ?? null;
63
65
  for (const agent of options.agents) {
64
66
  this.agents.set(agent.name, {
65
67
  config: agent,
@@ -96,6 +98,17 @@ class DaemonProcessManager {
96
98
  state.snapshot.status = "starting";
97
99
  const runCwd = (0, identity_1.getRepoRoot)();
98
100
  const entryScript = path.join((0, identity_1.getRepoRoot)(), "dist", state.config.entry);
101
+ if (this.existsSyncFn && !this.existsSyncFn(entryScript)) {
102
+ state.snapshot.status = "crashed";
103
+ (0, runtime_1.emitNervesEvent)({
104
+ level: "error",
105
+ component: "daemon",
106
+ event: "daemon.agent_entry_missing",
107
+ message: "agent entry script does not exist — cannot spawn. Run 'ouro daemon install' from the correct location.",
108
+ meta: { agent, entryScript },
109
+ });
110
+ return;
111
+ }
99
112
  const args = [entryScript, "--agent", state.config.agentArg ?? agent, ...(state.config.args ?? [])];
100
113
  const child = this.spawnFn("node", args, {
101
114
  cwd: runCwd,
@@ -0,0 +1,67 @@
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.detectRuntimeMode = detectRuntimeMode;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const runtime_1 = require("../../nerves/runtime");
40
+ function detectRuntimeMode(rootPath, deps = {}) {
41
+ const checkExists = deps.existsSync ?? fs.existsSync;
42
+ // 1. Production: installed via npm
43
+ if (rootPath.includes("node_modules/@ouro.bot/cli") ||
44
+ rootPath.includes("node_modules/ouro.bot")) {
45
+ (0, runtime_1.emitNervesEvent)({
46
+ component: "daemon",
47
+ event: "daemon.runtime_mode_detected",
48
+ message: "detected runtime mode",
49
+ meta: { rootPath, mode: "production" },
50
+ });
51
+ return "production";
52
+ }
53
+ // 2-4. Everything else is dev: worktrees, git repos, unknown paths
54
+ // (conservative default: assume dev unless proven production)
55
+ const reason = rootPath.includes(".claude/worktrees/")
56
+ ? "worktree"
57
+ : checkExists(path.join(rootPath, ".git"))
58
+ ? "git-repo"
59
+ : "unknown";
60
+ (0, runtime_1.emitNervesEvent)({
61
+ component: "daemon",
62
+ event: "daemon.runtime_mode_detected",
63
+ message: "detected runtime mode",
64
+ meta: { rootPath, mode: "dev", reason },
65
+ });
66
+ return "dev";
67
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listTargetSessionCandidates = listTargetSessionCandidates;
4
+ exports.formatTargetSessionCandidates = formatTargetSessionCandidates;
5
+ const session_recall_1 = require("./session-recall");
6
+ const session_activity_1 = require("./session-activity");
7
+ const trust_explanation_1 = require("../mind/friends/trust-explanation");
8
+ const runtime_1 = require("../nerves/runtime");
9
+ function synthesizeFriendRecord(candidate) {
10
+ return {
11
+ id: candidate.friendId,
12
+ name: candidate.friendName,
13
+ role: "stranger",
14
+ trustLevel: "stranger",
15
+ connections: [],
16
+ externalIds: [],
17
+ tenantMemberships: [],
18
+ toolPreferences: {},
19
+ notes: {},
20
+ totalTokens: 0,
21
+ createdAt: new Date(0).toISOString(),
22
+ updatedAt: new Date(0).toISOString(),
23
+ schemaVersion: 1,
24
+ };
25
+ }
26
+ function deliveryPriority(mode) {
27
+ if (mode === "deliver_now")
28
+ return 0;
29
+ if (mode === "queue_only")
30
+ return 1;
31
+ return 2;
32
+ }
33
+ function activityPriority(source) {
34
+ return source === "friend-facing" ? 0 : 1;
35
+ }
36
+ function describeDelivery(candidate) {
37
+ if (candidate.channel !== "bluebubbles" && candidate.channel !== "teams") {
38
+ return { mode: "blocked", reason: "this channel does not support proactive outward delivery yet" };
39
+ }
40
+ if (candidate.trust.level === "family" || candidate.trust.level === "friend") {
41
+ return { mode: "deliver_now", reason: "directly trusted target on a proactive-delivery channel" };
42
+ }
43
+ return { mode: "queue_only", reason: "visible as a live chat, but immediate delivery still needs explicit cross-chat authorization" };
44
+ }
45
+ async function listTargetSessionCandidates(input) {
46
+ (0, runtime_1.emitNervesEvent)({
47
+ component: "engine",
48
+ event: "engine.target_resolution_start",
49
+ message: "listing live target session candidates",
50
+ meta: {
51
+ sessionsDir: input.sessionsDir,
52
+ currentSession: input.currentSession
53
+ ? `${input.currentSession.friendId}/${input.currentSession.channel}/${input.currentSession.key}`
54
+ : null,
55
+ },
56
+ });
57
+ const activity = (0, session_activity_1.listSessionActivity)({
58
+ sessionsDir: input.sessionsDir,
59
+ friendsDir: input.friendsDir,
60
+ agentName: input.agentName,
61
+ currentSession: input.currentSession ?? null,
62
+ }).filter((entry) => entry.channel !== "inner");
63
+ const candidates = [];
64
+ for (const entry of activity) {
65
+ const friend = await input.friendStore.get(entry.friendId) ?? synthesizeFriendRecord(entry);
66
+ const trust = (0, trust_explanation_1.describeTrustContext)({
67
+ friend,
68
+ channel: entry.channel,
69
+ });
70
+ const recall = await (0, session_recall_1.recallSession)({
71
+ sessionPath: entry.sessionPath,
72
+ friendId: entry.friendId,
73
+ channel: entry.channel,
74
+ key: entry.key,
75
+ messageCount: 6,
76
+ summarize: input.summarize,
77
+ trustLevel: trust.level,
78
+ });
79
+ const snapshot = recall.kind === "ok"
80
+ ? recall.snapshot
81
+ : recall.kind === "empty"
82
+ ? "recent focus: no recent visible messages"
83
+ : "recent focus: session transcript unavailable";
84
+ const delivery = describeDelivery({
85
+ channel: entry.channel,
86
+ trust,
87
+ });
88
+ candidates.push({
89
+ friendId: entry.friendId,
90
+ friendName: entry.friendName,
91
+ channel: entry.channel,
92
+ key: entry.key,
93
+ sessionPath: entry.sessionPath,
94
+ snapshot,
95
+ trust,
96
+ delivery,
97
+ lastActivityAt: entry.lastActivityAt,
98
+ lastActivityMs: entry.lastActivityMs,
99
+ activitySource: entry.activitySource,
100
+ });
101
+ }
102
+ return candidates.sort((a, b) => {
103
+ const deliveryDiff = deliveryPriority(a.delivery.mode) - deliveryPriority(b.delivery.mode);
104
+ if (deliveryDiff !== 0)
105
+ return deliveryDiff;
106
+ const sourceDiff = activityPriority(a.activitySource) - activityPriority(b.activitySource);
107
+ if (sourceDiff !== 0)
108
+ return sourceDiff;
109
+ return b.lastActivityMs - a.lastActivityMs;
110
+ });
111
+ }
112
+ function formatTargetSessionCandidates(candidates) {
113
+ if (candidates.length === 0)
114
+ return "";
115
+ const lines = ["## candidate target chats"];
116
+ for (const candidate of candidates) {
117
+ lines.push(`- ${candidate.friendName} [${candidate.friendId}] via ${candidate.channel}/${candidate.key}`);
118
+ lines.push(` trust: ${candidate.trust.level} (${candidate.trust.basis}) — ${candidate.trust.summary}`);
119
+ lines.push(` delivery: ${candidate.delivery.mode} — ${candidate.delivery.reason}`);
120
+ lines.push(` snapshot: ${candidate.snapshot}`);
121
+ }
122
+ return lines.join("\n");
123
+ }