@ouro.bot/cli 0.1.0-alpha.681 → 0.1.0-alpha.683

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,18 @@
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.683",
6
+ "changes": [
7
+ "Apply daemon credential bootstrap IPC buffered before the private-runtime credential waiter attaches."
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.682",
12
+ "changes": [
13
+ "Buffer private-runtime IPC messages during credential bootstrap so external event wakes are not lost, with coverage for filters and child-process-only disconnect behavior."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.681",
6
18
  "changes": [
@@ -36,15 +36,83 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  // Unified agent runtime entrypoint.
37
37
  // Requires --agent before importing runtime modules that rely on identity.
38
38
  const agentArgIndex = process.argv.indexOf("--agent");
39
- const agentName = agentArgIndex >= 0 ? process.argv[agentArgIndex + 1] : undefined;
40
- if (!agentName) {
39
+ const parsedAgentName = agentArgIndex >= 0 ? process.argv[agentArgIndex + 1] : undefined;
40
+ if (!parsedAgentName) {
41
41
  // eslint-disable-next-line no-console -- pre-boot guard
42
42
  console.error("Missing required --agent <name> argument.\nUsage: node dist/heart/agent-entry.js --agent ouroboros");
43
43
  process.exit(1);
44
44
  }
45
+ const agentName = parsedAgentName;
45
46
  const cli_logging_1 = require("../nerves/cli-logging");
46
47
  const runtime_1 = require("../nerves/runtime");
47
48
  (0, cli_logging_1.configureCliRuntimeLogger)("self");
49
+ const ipcStateKey = Symbol.for("ouro.agentEntry.ipcState");
50
+ const ipcState = (globalThis[ipcStateKey] ??= {
51
+ bufferedRuntimeCredentialMessages: [],
52
+ bufferedMessages: [],
53
+ installed: false,
54
+ workerMessageHandler: null,
55
+ });
56
+ ipcState.bufferedRuntimeCredentialMessages = [];
57
+ ipcState.bufferedMessages = [];
58
+ ipcState.workerMessageHandler = null;
59
+ function isRuntimeCredentialBootstrapMessage(message) {
60
+ return !!message
61
+ && typeof message === "object"
62
+ && !Array.isArray(message)
63
+ && message.type === "ouro.runtimeCredentialBootstrap";
64
+ }
65
+ function isRuntimeCredentialBootstrapForAgent(message, expectedAgentName) {
66
+ return isRuntimeCredentialBootstrapMessage(message)
67
+ && message.agentName === expectedAgentName;
68
+ }
69
+ function drainBufferedRuntimeCredentialBootstrap(applyRuntimeCredentialBootstrapMessage) {
70
+ let bootstrapped = false;
71
+ const remainingMessages = [];
72
+ for (const message of ipcState.bufferedRuntimeCredentialMessages.splice(0)) {
73
+ if (isRuntimeCredentialBootstrapForAgent(message, agentName)) {
74
+ bootstrapped = applyRuntimeCredentialBootstrapMessage(message) || bootstrapped;
75
+ }
76
+ else {
77
+ remainingMessages.push(message);
78
+ }
79
+ }
80
+ ipcState.bufferedRuntimeCredentialMessages.push(...remainingMessages);
81
+ return bootstrapped;
82
+ }
83
+ function isPrivateRuntimeWorkMessage(message) {
84
+ if (!message || typeof message !== "object" || Array.isArray(message))
85
+ return false;
86
+ const type = message.type;
87
+ return type === "heartbeat"
88
+ || type === "habit"
89
+ || type === "await"
90
+ || type === "shutdown"
91
+ || type === "poke"
92
+ || type === "chat"
93
+ || type === "message";
94
+ }
95
+ function forwardOrBufferRuntimeMessage(message) {
96
+ if (isRuntimeCredentialBootstrapMessage(message)) {
97
+ ipcState.bufferedRuntimeCredentialMessages.push(message);
98
+ return;
99
+ }
100
+ if (!isPrivateRuntimeWorkMessage(message))
101
+ return;
102
+ if (ipcState.workerMessageHandler) {
103
+ ipcState.workerMessageHandler(message);
104
+ return;
105
+ }
106
+ ipcState.bufferedMessages.push(message);
107
+ }
108
+ if (!ipcState.installed) {
109
+ process.on("message", forwardOrBufferRuntimeMessage);
110
+ /* v8 ignore next 3 -- child-process disconnect exits the live worker; default worker listener covers this behavior in process-listener tests @preserve */
111
+ process.on("disconnect", () => {
112
+ process.exit(0);
113
+ });
114
+ ipcState.installed = true;
115
+ }
48
116
  (0, runtime_1.emitNervesEvent)({
49
117
  component: "senses",
50
118
  event: "senses.entry_boot",
@@ -53,8 +121,15 @@ const runtime_1 = require("../nerves/runtime");
53
121
  });
54
122
  // Dynamic import: agent-entry is process-start wiring that starts a sense process.
55
123
  // Using dynamic import avoids a static heart/ -> senses/ dependency.
56
- Promise.resolve().then(() => __importStar(require("./runtime-credentials"))).then(async ({ readMachineRuntimeCredentialConfig, readRuntimeCredentialConfig, refreshMachineRuntimeCredentialConfig, refreshRuntimeCredentialConfig, waitForRuntimeCredentialBootstrap, }) => {
57
- await waitForRuntimeCredentialBootstrap(agentName);
124
+ Promise.resolve().then(() => __importStar(require("./runtime-credentials"))).then(async ({ readMachineRuntimeCredentialConfig, readRuntimeCredentialConfig, refreshMachineRuntimeCredentialConfig, refreshRuntimeCredentialConfig, applyRuntimeCredentialBootstrapMessage, waitForRuntimeCredentialBootstrap, }) => {
125
+ const bootstrappedBeforeWait = drainBufferedRuntimeCredentialBootstrap(applyRuntimeCredentialBootstrapMessage);
126
+ const bootstrappedDuringWait = bootstrappedBeforeWait ? true : await waitForRuntimeCredentialBootstrap(agentName);
127
+ if (bootstrappedDuringWait) {
128
+ ipcState.bufferedRuntimeCredentialMessages = ipcState.bufferedRuntimeCredentialMessages.filter((message) => !isRuntimeCredentialBootstrapForAgent(message, agentName));
129
+ }
130
+ else {
131
+ drainBufferedRuntimeCredentialBootstrap(applyRuntimeCredentialBootstrapMessage);
132
+ }
58
133
  if (!readRuntimeCredentialConfig(agentName).ok) {
59
134
  void refreshRuntimeCredentialConfig(agentName, { preserveCachedOnFailure: true }).catch(() => undefined);
60
135
  }
@@ -67,7 +142,18 @@ Promise.resolve().then(() => __importStar(require("./runtime-credentials"))).the
67
142
  .catch(() => undefined);
68
143
  }
69
144
  const { startPrivateRuntimeWorker } = await Promise.resolve().then(() => __importStar(require("../senses/private-runtime-worker")));
70
- await startPrivateRuntimeWorker();
145
+ const bufferedMessages = ipcState.bufferedMessages.splice(0);
146
+ const worker = await startPrivateRuntimeWorker({
147
+ attachProcessListeners: false,
148
+ bufferedMessages,
149
+ });
150
+ ipcState.workerMessageHandler = (message) => {
151
+ void worker.handleMessage(message);
152
+ };
153
+ const messagesBufferedDuringStart = ipcState.bufferedMessages.splice(0);
154
+ for (const message of messagesBufferedDuringStart) {
155
+ ipcState.workerMessageHandler(message);
156
+ }
71
157
  })
72
158
  .catch((error) => {
73
159
  (0, runtime_1.emitNervesEvent)({
@@ -567,12 +567,18 @@ function createPrivateRuntimeWorker(runTurn = (options) => (0, private_runtime_1
567
567
  }
568
568
  return { run, handleMessage };
569
569
  }
570
- async function startPrivateRuntimeWorker() {
570
+ async function startPrivateRuntimeWorker(options = {}) {
571
571
  const worker = createPrivateRuntimeWorker();
572
- process.on("message", (message) => {
572
+ if (options.attachProcessListeners ?? true) {
573
+ process.on("message", (message) => {
574
+ void worker.handleMessage(message);
575
+ });
576
+ process.on("disconnect", () => {
577
+ process.exit(0);
578
+ });
579
+ }
580
+ for (const message of options.bufferedMessages ?? []) {
573
581
  void worker.handleMessage(message);
574
- });
575
- process.on("disconnect", () => {
576
- process.exit(0);
577
- });
582
+ }
583
+ return worker;
578
584
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.681",
3
+ "version": "0.1.0-alpha.683",
4
4
  "main": "dist/heart/daemon/ouro-entry.js",
5
5
  "bin": {
6
6
  "cli": "dist/heart/daemon/ouro-bot-entry.js",