@ouro.bot/cli 0.1.0-alpha.1712 → 0.1.0-alpha.1714
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 +9 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/daemon/cli-defaults.js +2 -0
- package/dist/heart/daemon/cli-exec.js +17 -0
- package/dist/heart/daemon/handoff-blockers.js +5 -4
- package/dist/heart/versioning/ouro-version-manager.js +13 -0
- package/dist/heart/versioning/self-update-defaults.js +15 -69
- package/dist/heart/versioning/self-update-lock.js +151 -0
- package/dist/heart/versioning/self-update.js +43 -12
- package/dist/mind/pending.js +30 -0
- package/dist/repertoire/tools-surface.js +12 -0
- package/dist/senses/bluebubbles/index.js +18 -0
- package/dist/senses/pipeline.js +29 -1
- package/dist/senses/proactive-content-guard.js +31 -1
- package/dist/senses/shared-turn.js +3 -1
- package/dist/senses/teams.js +34 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "Each pull request writes its own change note under changes/; the release job on main gives each landed change its version and adds the notes here (scripts/release-version.cjs). On main this file stops at the last version set by hand; the published package has every release. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1714",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Ouro no longer sends you unprompted routine notices, or heads-ups about a later approval that asks nothing of you now. It holds them and gives you one short summary the next time you write to it. Requested updates, anything that needs you now (including the later approval request itself), warnings about lost work or an ongoing outage, and corrections still send right away.",
|
|
8
|
+
"The unattended updater no longer rolls back a healthy daemon because a newer release came up while it waited. On 2026-11-27 a pass installed 0.1.0-alpha.1710, the `ouro up` it runs to restart the daemon found and installed 0.1.0-alpha.1711, and the pass then read the daemon answering on 1711 as a failure: it marked 1710 failed, pinned 0.1.0-alpha.1704 and stopped the healthy 1711 daemon. Now a daemon that answers on the target or any newer release counts as healthy, and the restart is judged by health rather than by an exact version match.",
|
|
9
|
+
"`ouro up` no longer installs a release while a self-update pass is running, including the `ouro up` that pass runs itself: both now take the same update lock, and the one that finds it held leaves updating to the holder. A lock left by a crashed process is taken over once its owner is gone or it is older than two hours, so a crash never stops updates.",
|
|
10
|
+
"A rollback no longer stops a daemon that still answers on a version other than the failed one. It reactivates and pins the previous version and leaves that daemon running. A pass also leaves alone a daemon running a newer release than the active one, unless that release already failed on this machine."
|
|
11
|
+
]
|
|
12
|
+
},
|
|
4
13
|
{
|
|
5
14
|
"version": "0.1.0-alpha.1712",
|
|
6
15
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1714</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -70,6 +70,7 @@ const bundle_manifest_1 = require("../../mind/bundle-manifest");
|
|
|
70
70
|
const ouro_bot_global_installer_1 = require("../versioning/ouro-bot-global-installer");
|
|
71
71
|
const version_intent_1 = require("../versioning/version-intent");
|
|
72
72
|
const self_update_defaults_1 = require("../versioning/self-update-defaults");
|
|
73
|
+
const self_update_lock_1 = require("../versioning/self-update-lock");
|
|
73
74
|
const update_state_1 = require("../versioning/update-state");
|
|
74
75
|
const host_self_update_1 = require("../versioning/host-self-update");
|
|
75
76
|
const logs_prune_1 = require("./logs-prune");
|
|
@@ -911,6 +912,7 @@ function createDefaultOuroCliDeps(socketPath = socket_client_1.DEFAULT_DAEMON_SO
|
|
|
911
912
|
distTag: update_checker_1.CLI_UPDATE_DIST_TAG,
|
|
912
913
|
});
|
|
913
914
|
},
|
|
915
|
+
acquireSelfUpdateLock: () => (0, self_update_lock_1.acquireSelfUpdateLock)((0, ouro_version_manager_1.getOuroCliHome)()),
|
|
914
916
|
readVersionIntent: () => (0, version_intent_1.readVersionIntent)(),
|
|
915
917
|
writeVersionIntent: (intent) => (0, version_intent_1.writeVersionIntent)(intent),
|
|
916
918
|
installCliVersion: async (version) => {
|
|
@@ -7304,10 +7304,26 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
|
|
|
7304
7304
|
// ── versioned CLI update check ──
|
|
7305
7305
|
const versionIntent = deps.readVersionIntent?.() ?? null;
|
|
7306
7306
|
const pinnedUpdate = versionIntent?.mode === "pinned" && !command.latest;
|
|
7307
|
+
// The update lock keeps this `ouro up` from installing a release in the middle of a self-update pass, including
|
|
7308
|
+
// the pass's own `ouro up` restart of the daemon (2026-11-27: that restart installed a newer release and the pass
|
|
7309
|
+
// rolled back the healthy daemon running it).
|
|
7310
|
+
const releaseUpdateLock = deps.checkForCliUpdate && !pinnedUpdate && deps.acquireSelfUpdateLock
|
|
7311
|
+
? deps.acquireSelfUpdateLock()
|
|
7312
|
+
: undefined;
|
|
7307
7313
|
if (deps.checkForCliUpdate && pinnedUpdate) {
|
|
7308
7314
|
progress.startPhase("update check");
|
|
7309
7315
|
progress.completePhase("update check", `pinned to ${versionIntent.targetVersion}`);
|
|
7310
7316
|
}
|
|
7317
|
+
else if (deps.checkForCliUpdate && releaseUpdateLock === null) {
|
|
7318
|
+
progress.startPhase("update check");
|
|
7319
|
+
progress.completePhase("update check", "skipped: another update is running");
|
|
7320
|
+
(0, runtime_1.emitNervesEvent)({
|
|
7321
|
+
component: "daemon",
|
|
7322
|
+
event: "daemon.cli_update_check_skipped_for_update_in_progress",
|
|
7323
|
+
message: "left updating to the self-update pass or ouro up that holds the update lock",
|
|
7324
|
+
meta: {},
|
|
7325
|
+
});
|
|
7326
|
+
}
|
|
7311
7327
|
else if (deps.checkForCliUpdate) {
|
|
7312
7328
|
progress.startPhase("update check");
|
|
7313
7329
|
progress.updateDetail(`current runtime: ${(0, bundle_manifest_1.getPackageVersion)()}\nchecking npm registry\ncontinuing startup if it stays quiet`);
|
|
@@ -7376,6 +7392,7 @@ async function runOuroCli(args, deps = (0, cli_defaults_1.createDefaultOuroCliDe
|
|
|
7376
7392
|
});
|
|
7377
7393
|
}
|
|
7378
7394
|
/* v8 ignore stop */
|
|
7395
|
+
releaseUpdateLock?.();
|
|
7379
7396
|
if (pendingReExec) {
|
|
7380
7397
|
progress.end();
|
|
7381
7398
|
deps.reExecFromNewVersion(args);
|
|
@@ -6,6 +6,7 @@ exports.handoffSnapshot = handoffSnapshot;
|
|
|
6
6
|
exports.unsettledReason = unsettledReason;
|
|
7
7
|
exports.judgeRestartAfterUpFailure = judgeRestartAfterUpFailure;
|
|
8
8
|
const runtime_1 = require("../../nerves/runtime");
|
|
9
|
+
const ouro_version_manager_1 = require("../versioning/ouro-version-manager");
|
|
9
10
|
/** Everything `ouro up`'s final daemon check refuses on, in the order it reports them: workers, senses, health checks. */
|
|
10
11
|
/**
|
|
11
12
|
* The exit code `ouro up` uses when it refuses to hand off only because the final daemon check found the daemon's
|
|
@@ -77,14 +78,14 @@ function unsettledReason(before, after) {
|
|
|
77
78
|
* `ouro up` refuses while any sense is down, so one sense's outage (BlueBubbles while its macOS account is logged
|
|
78
79
|
* out) rolled back every release for a day and marked each one failed (2026-10-24, and alpha.1559 to alpha.1586 on
|
|
79
80
|
* 2026-11-25). A release is only at fault for what it broke: it passes when `ouro up` failed only on the final
|
|
80
|
-
* health check, the daemon answers on it with a settled status, and every blocker it reports was already there,
|
|
81
|
+
* health check, the daemon answers on it (or on a newer release) with a settled status, and every blocker it reports was already there,
|
|
81
82
|
* at the same severity, before the update.
|
|
82
83
|
*/
|
|
83
84
|
function judgeRestartAfterUpFailure(input) {
|
|
84
85
|
if (!input.upRefusedOnHandoffHealth) {
|
|
85
86
|
return { ok: false, detail: input.upFailure };
|
|
86
87
|
}
|
|
87
|
-
if (input.seenVersion
|
|
88
|
+
if (input.seenVersion === null || !(0, ouro_version_manager_1.cliVersionAtLeast)(input.seenVersion, input.expectedVersion)) {
|
|
88
89
|
const answered = input.seenVersion ? `; the daemon answered with ${input.seenVersion}` : "; the daemon did not answer";
|
|
89
90
|
return { ok: false, detail: `${input.upFailure}${answered}` };
|
|
90
91
|
}
|
|
@@ -111,7 +112,7 @@ function judgeRestartAfterUpFailure(input) {
|
|
|
111
112
|
return {
|
|
112
113
|
ok: true,
|
|
113
114
|
detail: carried.length > 0
|
|
114
|
-
? `came up on ${input.
|
|
115
|
-
: `came up on ${input.
|
|
115
|
+
? `came up on ${input.seenVersion}; still blocked by what was already wrong before the update: ${carried.join("; ")}`
|
|
116
|
+
: `came up on ${input.seenVersion}`,
|
|
116
117
|
};
|
|
117
118
|
}
|
|
@@ -42,6 +42,7 @@ exports.listInstalledVersions = listInstalledVersions;
|
|
|
42
42
|
exports.validateInstalledVersionForActivation = validateInstalledVersionForActivation;
|
|
43
43
|
exports.installVersion = installVersion;
|
|
44
44
|
exports.activateVersion = activateVersion;
|
|
45
|
+
exports.cliVersionAtLeast = cliVersionAtLeast;
|
|
45
46
|
exports.compareCliVersions = compareCliVersions;
|
|
46
47
|
exports.selectVersionsToPrune = selectVersionsToPrune;
|
|
47
48
|
exports.pruneOldVersions = pruneOldVersions;
|
|
@@ -307,6 +308,18 @@ function activateVersion(version, deps) {
|
|
|
307
308
|
* any version that doesn't match the pattern (so unexpected version
|
|
308
309
|
* formats sort consistently rather than throwing).
|
|
309
310
|
*/
|
|
311
|
+
/**
|
|
312
|
+
* True when `version` is `floor` or a release after it. Anything that cannot be
|
|
313
|
+
* ordered by release number (such as the "unknown" a daemon shows when it
|
|
314
|
+
* reports no version) is never taken for a newer release.
|
|
315
|
+
*/
|
|
316
|
+
function cliVersionAtLeast(version, floor) {
|
|
317
|
+
if (version === floor)
|
|
318
|
+
return true;
|
|
319
|
+
const versionMatch = /alpha\.(\d+)$/.exec(version);
|
|
320
|
+
const floorMatch = /alpha\.(\d+)$/.exec(floor);
|
|
321
|
+
return Boolean(versionMatch && floorMatch && compareCliVersions(version, floor) > 0);
|
|
322
|
+
}
|
|
310
323
|
function compareCliVersions(a, b) {
|
|
311
324
|
const aMatch = /alpha\.(\d+)/.exec(a);
|
|
312
325
|
const bMatch = /alpha\.(\d+)/.exec(b);
|
|
@@ -33,8 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.releaseSourceDeps = void 0;
|
|
37
|
-
exports.isSelfUpdateLockHeld = isSelfUpdateLockHeld;
|
|
36
|
+
exports.isSelfUpdateLockHeld = exports.releaseSourceDeps = void 0;
|
|
38
37
|
exports.createDefaultSelfUpdateDeps = createDefaultSelfUpdateDeps;
|
|
39
38
|
exports.launchUnattendedSelfUpdate = launchUnattendedSelfUpdate;
|
|
40
39
|
exports.ensureDefaultUpdaterAgent = ensureDefaultUpdaterAgent;
|
|
@@ -53,6 +52,8 @@ const handoff_blockers_1 = require("../daemon/handoff-blockers");
|
|
|
53
52
|
const runtime_replacement_handoff_1 = require("../daemon/runtime-replacement-handoff");
|
|
54
53
|
const ouro_version_manager_1 = require("./ouro-version-manager");
|
|
55
54
|
const release_sources_1 = require("./release-sources");
|
|
55
|
+
const self_update_lock_1 = require("./self-update-lock");
|
|
56
|
+
Object.defineProperty(exports, "isSelfUpdateLockHeld", { enumerable: true, get: function () { return self_update_lock_1.isSelfUpdateLockHeld; } });
|
|
56
57
|
const update_state_1 = require("./update-state");
|
|
57
58
|
const updater_launchd_1 = require("./updater-launchd");
|
|
58
59
|
const version_intent_1 = require("./version-intent");
|
|
@@ -140,63 +141,6 @@ async function daemonHandoffSnapshot(socketPath) {
|
|
|
140
141
|
}
|
|
141
142
|
const EMPTY_HANDOFF_SNAPSHOT = { blockers: [], workers: [], healthCheckCount: 0 };
|
|
142
143
|
exports.releaseSourceDeps = { fetchJson, execFile: execFileText, ...(0, release_sources_1.selfUpdateE2eOverrides)(process.env) };
|
|
143
|
-
function isPidAlive(pid) {
|
|
144
|
-
try {
|
|
145
|
-
process.kill(pid, 0);
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
function lockPath(cliHome) {
|
|
153
|
-
return path.join(cliHome, "self-update.lock");
|
|
154
|
-
}
|
|
155
|
-
/** The pid holding the update lock when that process is still alive. */
|
|
156
|
-
function liveLockOwner(cliHome) {
|
|
157
|
-
try {
|
|
158
|
-
const pid = Number.parseInt(fs.readFileSync(lockPath(cliHome), "utf8"), 10);
|
|
159
|
-
return Number.isFinite(pid) && pid > 0 && isPidAlive(pid) ? pid : null;
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/** True when another live process is in the middle of an update pass. */
|
|
166
|
-
function isSelfUpdateLockHeld(cliHome) {
|
|
167
|
-
const owner = liveLockOwner(cliHome);
|
|
168
|
-
return owner !== null && owner !== process.pid;
|
|
169
|
-
}
|
|
170
|
-
function acquireLock(cliHome) {
|
|
171
|
-
const file = lockPath(cliHome);
|
|
172
|
-
fs.mkdirSync(cliHome, { recursive: true });
|
|
173
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
174
|
-
try {
|
|
175
|
-
const fd = fs.openSync(file, "wx", 0o600);
|
|
176
|
-
fs.writeSync(fd, `${process.pid}\n`);
|
|
177
|
-
fs.closeSync(fd);
|
|
178
|
-
return () => {
|
|
179
|
-
try {
|
|
180
|
-
fs.unlinkSync(file);
|
|
181
|
-
}
|
|
182
|
-
catch { /* already released */ }
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
if (error.code !== "EEXIST")
|
|
187
|
-
throw error;
|
|
188
|
-
// A lock is stale only when its owner is gone; a long install by a live
|
|
189
|
-
// owner keeps it, however long it takes.
|
|
190
|
-
if (liveLockOwner(cliHome) !== null)
|
|
191
|
-
return null;
|
|
192
|
-
try {
|
|
193
|
-
fs.unlinkSync(file);
|
|
194
|
-
}
|
|
195
|
-
catch { /* raced with the owner releasing it */ }
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
144
|
function versionEntry(cliHome, version) {
|
|
201
145
|
return path.join(cliHome, "versions", version, "node_modules", "@ouro.bot", "cli", "dist", "heart", "daemon", "ouro-entry.js");
|
|
202
146
|
}
|
|
@@ -256,15 +200,17 @@ function createDefaultSelfUpdateDeps(options = {}) {
|
|
|
256
200
|
}
|
|
257
201
|
const deadline = Date.now() + DAEMON_HEALTH_WAIT_MS;
|
|
258
202
|
let seen = null;
|
|
203
|
+
// A newer release can come up in place of the expected one (someone else updated meanwhile); that is healthy too.
|
|
204
|
+
const answeredOnTarget = (version) => version !== null && (0, ouro_version_manager_1.cliVersionAtLeast)(version, expectedVersion);
|
|
259
205
|
while (Date.now() < deadline) {
|
|
260
206
|
seen = await runningDaemonVersion(socketPath);
|
|
261
|
-
if (seen
|
|
207
|
+
if (answeredOnTarget(seen))
|
|
262
208
|
break;
|
|
263
209
|
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
264
210
|
}
|
|
265
211
|
if (upFailure !== null) {
|
|
266
212
|
let after = null;
|
|
267
|
-
if (upRefusedOnHandoffHealth && seen
|
|
213
|
+
if (upRefusedOnHandoffHealth && answeredOnTarget(seen)) {
|
|
268
214
|
// Judge only a settled status: one read before health checks run or workers register hides problems.
|
|
269
215
|
const settleDeadline = Date.now() + DAEMON_HEALTH_WAIT_MS;
|
|
270
216
|
for (;;) {
|
|
@@ -276,11 +222,11 @@ function createDefaultSelfUpdateDeps(options = {}) {
|
|
|
276
222
|
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
277
223
|
}
|
|
278
224
|
}
|
|
279
|
-
return (0, handoff_blockers_1.judgeRestartAfterUpFailure)({ upFailure, upRefusedOnHandoffHealth, expectedVersion, seenVersion: seen, before, after });
|
|
225
|
+
return { ...(0, handoff_blockers_1.judgeRestartAfterUpFailure)({ upFailure, upRefusedOnHandoffHealth, expectedVersion, seenVersion: seen, before, after }), runningVersion: seen };
|
|
280
226
|
}
|
|
281
|
-
if (seen
|
|
282
|
-
return { ok: true };
|
|
283
|
-
return { ok: false, detail: seen ? `daemon answered with ${seen}, expected ${expectedVersion}` : "daemon did not answer after ouro up" };
|
|
227
|
+
if (answeredOnTarget(seen))
|
|
228
|
+
return { ok: true, runningVersion: seen };
|
|
229
|
+
return { ok: false, runningVersion: seen, detail: seen ? `daemon answered with ${seen}, expected ${expectedVersion} or newer` : "daemon did not answer after ouro up" };
|
|
284
230
|
},
|
|
285
231
|
isDevMode: () => fs.existsSync(path.join(cliHome, "dev-config.json")),
|
|
286
232
|
isDaemonReplacementStranded: () => {
|
|
@@ -308,7 +254,7 @@ function createDefaultSelfUpdateDeps(options = {}) {
|
|
|
308
254
|
},
|
|
309
255
|
});
|
|
310
256
|
},
|
|
311
|
-
acquireLock: () =>
|
|
257
|
+
acquireLock: () => (0, self_update_lock_1.acquireSelfUpdateLock)(cliHome),
|
|
312
258
|
diskSpace: () => {
|
|
313
259
|
try {
|
|
314
260
|
const stats = fs.statfsSync(cliHome);
|
|
@@ -409,7 +355,7 @@ function launchUnattendedSelfUpdate(options = {}) {
|
|
|
409
355
|
const config = (0, host_self_update_1.readHostSelfUpdateConfig)(cliHome);
|
|
410
356
|
if (!config?.enabled)
|
|
411
357
|
return "not-enabled";
|
|
412
|
-
if (isSelfUpdateLockHeld(cliHome))
|
|
358
|
+
if ((0, self_update_lock_1.isSelfUpdateLockHeld)(cliHome))
|
|
413
359
|
return "busy";
|
|
414
360
|
const launcher = path.join(cliHome, "bin", "ouro-launcher.js");
|
|
415
361
|
if (!fs.existsSync(launcher))
|
|
@@ -452,7 +398,7 @@ function ensureDefaultUpdaterAgent(options = {}) {
|
|
|
452
398
|
mkdirp: (dir) => fs.mkdirSync(dir, { recursive: true }),
|
|
453
399
|
exec: (command) => { require("child_process").execSync(command, { stdio: "ignore" }); },
|
|
454
400
|
runningUnderUpdaterAgent: process.env.XPC_SERVICE_NAME === updater_launchd_1.UPDATER_PLIST_LABEL,
|
|
455
|
-
updateInProgress: isSelfUpdateLockHeld((0, ouro_version_manager_1.getOuroCliHome)(homeDir)),
|
|
401
|
+
updateInProgress: (0, self_update_lock_1.isSelfUpdateLockHeld)((0, ouro_version_manager_1.getOuroCliHome)(homeDir)),
|
|
456
402
|
});
|
|
457
403
|
(0, runtime_1.emitNervesEvent)({
|
|
458
404
|
component: "daemon",
|
|
@@ -474,7 +420,7 @@ function restoreDefaultUpdaterAgentIfMissing(options = {}) {
|
|
|
474
420
|
userUid: os.userInfo().uid,
|
|
475
421
|
fileExists: (filePath) => fs.existsSync(filePath),
|
|
476
422
|
exec: (command) => { require("child_process").execSync(command, { stdio: "ignore", timeout: 10_000 }); },
|
|
477
|
-
updateInProgress: () => isSelfUpdateLockHeld((0, ouro_version_manager_1.getOuroCliHome)(homeDir)),
|
|
423
|
+
updateInProgress: () => (0, self_update_lock_1.isSelfUpdateLockHeld)((0, ouro_version_manager_1.getOuroCliHome)(homeDir)),
|
|
478
424
|
});
|
|
479
425
|
}
|
|
480
426
|
function isDefaultUpdaterAgentInstalled(options = {}) {
|
|
@@ -0,0 +1,151 @@
|
|
|
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.SELF_UPDATE_LOCK_MAX_AGE_MS = void 0;
|
|
37
|
+
exports.selfUpdateLockPath = selfUpdateLockPath;
|
|
38
|
+
exports.isSelfUpdateLockHeld = isSelfUpdateLockHeld;
|
|
39
|
+
exports.acquireSelfUpdateLock = acquireSelfUpdateLock;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
43
|
+
/**
|
|
44
|
+
* One lock for everything that installs or activates a CLI release on this
|
|
45
|
+
* machine: the unattended `ouro self-update` pass and the update check in
|
|
46
|
+
* `ouro up`. Without it, the `ouro up` a pass runs to restart the daemon can
|
|
47
|
+
* install a newer release in the middle of the pass (2026-11-27).
|
|
48
|
+
*
|
|
49
|
+
* The lock file holds its owner's pid. A crashed owner never wedges it: the
|
|
50
|
+
* lock is stale once that pid is gone, or once the file is older than any pass
|
|
51
|
+
* can run, which also covers a crashed owner whose pid now belongs to an
|
|
52
|
+
* unrelated process.
|
|
53
|
+
*/
|
|
54
|
+
exports.SELF_UPDATE_LOCK_MAX_AGE_MS = 2 * 60 * 60 * 1000;
|
|
55
|
+
function selfUpdateLockPath(cliHome) {
|
|
56
|
+
return path.join(cliHome, "self-update.lock");
|
|
57
|
+
}
|
|
58
|
+
function defaultIsPidAlive(pid) {
|
|
59
|
+
try {
|
|
60
|
+
process.kill(pid, 0);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function lockOwnerPid(cliHome) {
|
|
68
|
+
try {
|
|
69
|
+
const pid = Number.parseInt(fs.readFileSync(selfUpdateLockPath(cliHome), "utf8"), 10);
|
|
70
|
+
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** The pid holding the lock while it still counts, or null when nobody holds it or the lock is stale. */
|
|
77
|
+
function liveLockOwner(cliHome, deps) {
|
|
78
|
+
const pid = lockOwnerPid(cliHome);
|
|
79
|
+
if (pid === null)
|
|
80
|
+
return null;
|
|
81
|
+
const isPidAlive = deps.isPidAlive ?? defaultIsPidAlive;
|
|
82
|
+
if (!isPidAlive(pid))
|
|
83
|
+
return null;
|
|
84
|
+
let writtenAtMs;
|
|
85
|
+
try {
|
|
86
|
+
writtenAtMs = fs.statSync(selfUpdateLockPath(cliHome)).mtimeMs;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
/* v8 ignore next -- the lock vanished between reading and stat-ing it @preserve */
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const now = deps.now ?? (() => Date.now());
|
|
93
|
+
return now() - writtenAtMs > exports.SELF_UPDATE_LOCK_MAX_AGE_MS ? null : pid;
|
|
94
|
+
}
|
|
95
|
+
/** True when another live process holds the lock. */
|
|
96
|
+
function isSelfUpdateLockHeld(cliHome, deps = {}) {
|
|
97
|
+
const owner = liveLockOwner(cliHome, deps);
|
|
98
|
+
return owner !== null && owner !== (deps.pid ?? process.pid);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Takes the lock and returns its release, or null while another process holds
|
|
102
|
+
* it. Release removes the file only while it still names this process.
|
|
103
|
+
*/
|
|
104
|
+
function acquireSelfUpdateLock(cliHome, deps = {}) {
|
|
105
|
+
const file = selfUpdateLockPath(cliHome);
|
|
106
|
+
const pid = deps.pid ?? process.pid;
|
|
107
|
+
fs.mkdirSync(cliHome, { recursive: true });
|
|
108
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
109
|
+
try {
|
|
110
|
+
const fd = fs.openSync(file, "wx", 0o600);
|
|
111
|
+
fs.writeSync(fd, `${pid}\n`);
|
|
112
|
+
fs.closeSync(fd);
|
|
113
|
+
return () => {
|
|
114
|
+
if (lockOwnerPid(cliHome) !== pid)
|
|
115
|
+
return;
|
|
116
|
+
try {
|
|
117
|
+
fs.unlinkSync(file);
|
|
118
|
+
}
|
|
119
|
+
catch { /* v8 ignore next -- already released @preserve */ }
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
/* v8 ignore next -- permission or disk errors are not a held lock @preserve */
|
|
124
|
+
if (error.code !== "EEXIST")
|
|
125
|
+
throw error;
|
|
126
|
+
const owner = liveLockOwner(cliHome, deps);
|
|
127
|
+
if (owner !== null) {
|
|
128
|
+
(0, runtime_1.emitNervesEvent)({
|
|
129
|
+
component: "daemon",
|
|
130
|
+
event: "daemon.self_update_lock_busy",
|
|
131
|
+
message: "another process is installing or activating a CLI release",
|
|
132
|
+
meta: { owner, pid },
|
|
133
|
+
});
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
(0, runtime_1.emitNervesEvent)({
|
|
137
|
+
level: "warn",
|
|
138
|
+
component: "daemon",
|
|
139
|
+
event: "daemon.self_update_lock_reclaimed",
|
|
140
|
+
message: "took over a self-update lock whose owner is gone or that is older than any pass",
|
|
141
|
+
meta: { stalePid: lockOwnerPid(cliHome), pid },
|
|
142
|
+
});
|
|
143
|
+
try {
|
|
144
|
+
fs.unlinkSync(file);
|
|
145
|
+
}
|
|
146
|
+
catch { /* v8 ignore next -- raced with the owner releasing it @preserve */ }
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/* v8 ignore next -- two processes reclaimed the same stale lock at once and the other won @preserve */
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
@@ -22,8 +22,11 @@ const ouro_version_manager_1 = require("./ouro-version-manager");
|
|
|
22
22
|
* 4. Activate it. If the daemon was running, restart it on the new version
|
|
23
23
|
* and check that it answers; otherwise leave the daemon stopped.
|
|
24
24
|
* 5. On a failed check, reactivate the previous version, pin it with reason
|
|
25
|
-
* "auto-rollback",
|
|
26
|
-
* version
|
|
25
|
+
* "auto-rollback", and never retry the failed version. Restart the daemon
|
|
26
|
+
* on the previous version only when the failed one is what runs (or
|
|
27
|
+
* nothing answers): a rollback never stops a daemon that answers on
|
|
28
|
+
* another version, and a daemon answering on a newer release than the
|
|
29
|
+
* target is a success, not a failure (2026-11-27).
|
|
27
30
|
*/
|
|
28
31
|
exports.PIN_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
29
32
|
/**
|
|
@@ -83,17 +86,31 @@ async function runLocked(deps) {
|
|
|
83
86
|
};
|
|
84
87
|
/**
|
|
85
88
|
* Restart the daemon on `target`. On a failed health check, never retry
|
|
86
|
-
* `target
|
|
87
|
-
*
|
|
89
|
+
* `target` and pin and reactivate `fallback`; restart on it only when the
|
|
90
|
+
* daemon runs `target` or does not answer. Returns the rolled-back result,
|
|
91
|
+
* or the version the daemon is healthy on.
|
|
88
92
|
*/
|
|
89
93
|
const restartOrRollBack = async (target, fallback, source) => {
|
|
90
94
|
const health = await deps.restartDaemon(target);
|
|
91
95
|
if (health.ok)
|
|
92
|
-
return
|
|
96
|
+
return { healthyOn: health.runningVersion ?? target };
|
|
97
|
+
const why = health.detail ?? "no detail";
|
|
98
|
+
const answering = await deps.runningDaemonVersion();
|
|
99
|
+
if (answering && answering !== target && (0, ouro_version_manager_1.cliVersionAtLeast)(answering, target)) {
|
|
100
|
+
// A newer release came up while this pass waited on its own: the machine is ahead of the target, not broken.
|
|
101
|
+
(0, runtime_1.emitNervesEvent)({
|
|
102
|
+
level: "warn",
|
|
103
|
+
component: "daemon",
|
|
104
|
+
event: "daemon.self_update_newer_release_running",
|
|
105
|
+
message: "the daemon came up on a newer release than the one this pass installed; counting it as healthy",
|
|
106
|
+
meta: { target, running: answering, detail: why },
|
|
107
|
+
});
|
|
108
|
+
return { healthyOn: answering };
|
|
109
|
+
}
|
|
93
110
|
failedVersions.push(target);
|
|
94
111
|
if (!fallback) {
|
|
95
112
|
return finish("rolled-back", {
|
|
96
|
-
summary: `${target} did not come up healthy (${
|
|
113
|
+
summary: `${target} did not come up healthy (${why}) and there is no previous version to return to`,
|
|
97
114
|
latestVersion: target,
|
|
98
115
|
source,
|
|
99
116
|
});
|
|
@@ -106,9 +123,17 @@ async function runLocked(deps) {
|
|
|
106
123
|
reason: "auto-rollback",
|
|
107
124
|
});
|
|
108
125
|
deps.activate(fallback);
|
|
126
|
+
if (answering && answering !== target) {
|
|
127
|
+
// The failed release is not what runs, so stopping the daemon would only take a healthy one down.
|
|
128
|
+
return finish("rolled-back", {
|
|
129
|
+
summary: `${target} did not come up healthy (${why}); rolled back to ${fallback} and left the daemon running on ${answering}`,
|
|
130
|
+
latestVersion: target,
|
|
131
|
+
source,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
109
134
|
const restored = await deps.restartDaemon(fallback);
|
|
110
135
|
return finish("rolled-back", {
|
|
111
|
-
summary: `${target} did not come up healthy (${
|
|
136
|
+
summary: `${target} did not come up healthy (${why}); rolled back to ${fallback}${restored.ok ? "" : ` but the daemon did not answer on it either (${restored.detail ?? "no detail"})`}`,
|
|
112
137
|
latestVersion: target,
|
|
113
138
|
source,
|
|
114
139
|
});
|
|
@@ -152,9 +177,12 @@ async function runLocked(deps) {
|
|
|
152
177
|
// A pass killed between activation and restart leaves the old daemon
|
|
153
178
|
// running; finish the job instead of reporting "current" forever.
|
|
154
179
|
const daemonVersion = deps.isDevMode() ? null : await deps.runningDaemonVersion();
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
180
|
+
// A daemon ahead of CurrentVersion was updated by someone else and stays, unless it runs a release that failed here.
|
|
181
|
+
const daemonNeedsRestart = daemonVersion !== null && daemonVersion !== currentVersion
|
|
182
|
+
&& (!(0, ouro_version_manager_1.cliVersionAtLeast)(daemonVersion, currentVersion) || failedVersions.includes(daemonVersion));
|
|
183
|
+
if (daemonVersion && daemonNeedsRestart) {
|
|
184
|
+
const restart = await restartOrRollBack(currentVersion, failedVersions.includes(daemonVersion) ? null : daemonVersion);
|
|
185
|
+
if (!("healthyOn" in restart))
|
|
158
186
|
return restart;
|
|
159
187
|
return finish("updated", {
|
|
160
188
|
summary: `daemon was still running ${daemonVersion}; restarted it on ${currentVersion} and it is healthy`,
|
|
@@ -257,13 +285,16 @@ async function runLocked(deps) {
|
|
|
257
285
|
}
|
|
258
286
|
deps.writeIntent({ schemaVersion: 1, mode: "latest", targetVersion: latest });
|
|
259
287
|
deps.activate(latest);
|
|
288
|
+
let healthyOn = latest;
|
|
260
289
|
if (daemonWasRunning) {
|
|
261
290
|
const restart = await restartOrRollBack(latest, currentVersion, installSource);
|
|
262
|
-
if (restart)
|
|
291
|
+
if (!("healthyOn" in restart))
|
|
263
292
|
return restart;
|
|
293
|
+
healthyOn = restart.healthyOn;
|
|
264
294
|
}
|
|
295
|
+
const healthy = healthyOn === latest ? "; daemon restarted and healthy" : `; daemon restarted and healthy on ${healthyOn}`;
|
|
265
296
|
return finish("updated", {
|
|
266
|
-
summary: `updated ${currentVersion ?? "unknown"} -> ${latest} via ${installSource}${daemonWasRunning ?
|
|
297
|
+
summary: `updated ${currentVersion ?? "unknown"} -> ${latest} via ${installSource}${daemonWasRunning ? healthy : "; daemon was not running and was left stopped"}`,
|
|
267
298
|
latestVersion: latest,
|
|
268
299
|
source: installSource,
|
|
269
300
|
});
|
package/dist/mind/pending.js
CHANGED
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.MAX_PENDING_FAILED_TRIES = exports.PRIVATE_RUNTIME_PENDING = void 0;
|
|
37
37
|
exports.getPendingDir = getPendingDir;
|
|
38
38
|
exports.getDeferredReturnDir = getDeferredReturnDir;
|
|
39
|
+
exports.getHeldNoticeDir = getHeldNoticeDir;
|
|
39
40
|
exports.getPrivateRuntimePendingDir = getPrivateRuntimePendingDir;
|
|
40
41
|
exports.releaseHeldPendingClaimsOnExit = releaseHeldPendingClaimsOnExit;
|
|
41
42
|
exports.hasPendingMessages = hasPendingMessages;
|
|
@@ -44,6 +45,8 @@ exports.queuePendingMessageOnce = queuePendingMessageOnce;
|
|
|
44
45
|
exports.claimPending = claimPending;
|
|
45
46
|
exports.enqueueDeferredReturn = enqueueDeferredReturn;
|
|
46
47
|
exports.drainDeferredReturns = drainDeferredReturns;
|
|
48
|
+
exports.holdNoticeForReturn = holdNoticeForReturn;
|
|
49
|
+
exports.claimHeldNotices = claimHeldNotices;
|
|
47
50
|
exports.withdrawDeferredReturn = withdrawDeferredReturn;
|
|
48
51
|
exports.drainPending = drainPending;
|
|
49
52
|
const fs = __importStar(require("fs"));
|
|
@@ -60,6 +63,9 @@ function getPendingDir(agentName, friendId, channel, key, agentRoot = (0, identi
|
|
|
60
63
|
function getDeferredReturnDir(agentName, friendId) {
|
|
61
64
|
return path.join((0, identity_1.getAgentRoot)(agentName), "state", "pending-returns", friendId);
|
|
62
65
|
}
|
|
66
|
+
function getHeldNoticeDir(agentName, friendId) {
|
|
67
|
+
return path.join((0, identity_1.getAgentRoot)(agentName), "state", "held-notices", friendId);
|
|
68
|
+
}
|
|
63
69
|
/** Canonical private-runtime pending path segments. The path is historical durable state. */
|
|
64
70
|
exports.PRIVATE_RUNTIME_PENDING = { friendId: "self", channel: "inner", key: "dialog" };
|
|
65
71
|
/** Returns the pending dir for this agent's private runtime. */
|
|
@@ -401,6 +407,30 @@ function drainDeferredReturns(agentName, friendId) {
|
|
|
401
407
|
});
|
|
402
408
|
return messages;
|
|
403
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Keeps a routine notice for the friend's next return summary. One file per text, so the same notice held twice
|
|
412
|
+
* is kept once. Throws when it could not be written: the caller must then not treat the notice as held.
|
|
413
|
+
*/
|
|
414
|
+
function holdNoticeForReturn(agentName, friendId, text) {
|
|
415
|
+
const dir = getHeldNoticeDir(agentName, friendId);
|
|
416
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
417
|
+
const filePath = path.join(dir, `${(0, node_crypto_1.createHash)("sha256").update(text).digest("hex").slice(0, 32)}.json`);
|
|
418
|
+
if (!fs.existsSync(filePath)) {
|
|
419
|
+
const message = { from: agentName, friendId, content: (0, session_events_1.capStructuredRecordString)(text), timestamp: Date.now(), disposition: "held_notice" };
|
|
420
|
+
(0, atomic_file_1.writeJsonAtomicSync)(filePath, message);
|
|
421
|
+
}
|
|
422
|
+
(0, runtime_1.emitNervesEvent)({
|
|
423
|
+
event: "mind.held_notice_kept",
|
|
424
|
+
component: "mind",
|
|
425
|
+
message: "routine notice held for the friend's return summary",
|
|
426
|
+
meta: { friendId, dir },
|
|
427
|
+
});
|
|
428
|
+
return filePath;
|
|
429
|
+
}
|
|
430
|
+
/** Takes a friend's held notices for the one turn that summarises them; settle after the summary is delivered, release if not. */
|
|
431
|
+
function claimHeldNotices(agentName, friendId) {
|
|
432
|
+
return claimPending(getHeldNoticeDir(agentName, friendId));
|
|
433
|
+
}
|
|
404
434
|
/**
|
|
405
435
|
* Removes the saved copies of one message from a friend's deferred returns, for when the same turn
|
|
406
436
|
* reached them another way after it was saved. Returns how many it removed.
|
|
@@ -351,6 +351,8 @@ async function routeSurfaceToFriend(agentName, friendId, content, queueItem, hin
|
|
|
351
351
|
return { status: "unconfirmed", detail: unconfirmedDetail("Teams") };
|
|
352
352
|
if (sent?.reason && CONTENT_REFUSALS.has(sent.reason)) {
|
|
353
353
|
const held = (0, proactive_content_guard_1.getProactiveInternalContentBlockReason)(content);
|
|
354
|
+
if ((0, proactive_content_guard_1.isHeldForReturnReason)(held))
|
|
355
|
+
return { status: "queued", detail: "held for their return summary; they get it with other routine notices when they next message" };
|
|
354
356
|
const detail = (0, proactive_content_guard_1.isReturnToSenderReason)(held)
|
|
355
357
|
? (0, proactive_content_guard_1.proactiveContentBlockGuidance)(held)
|
|
356
358
|
: `blocked: Teams refused this text as internal (${sent.reason}); rewrite it as plain words for them`;
|
|
@@ -444,6 +446,16 @@ async function routeSurfaceToFriend(agentName, friendId, content, queueItem, hin
|
|
|
444
446
|
// them, never into a session only agents read (MCP) or one they must reopen (CLI).
|
|
445
447
|
// Text the senses' content guard refuses goes nowhere, whichever chat is newest.
|
|
446
448
|
const contentBlock = (0, proactive_content_guard_1.getProactiveInternalContentBlockReason)(content);
|
|
449
|
+
if ((0, proactive_content_guard_1.isHeldForReturnReason)(contentBlock)) {
|
|
450
|
+
try {
|
|
451
|
+
const { holdNoticeForReturn } = await Promise.resolve().then(() => __importStar(require("../mind/pending")));
|
|
452
|
+
holdNoticeForReturn(agentName, friendId, content);
|
|
453
|
+
}
|
|
454
|
+
catch (error) {
|
|
455
|
+
return { status: "failed", detail: (0, tool_error_code_1.withCode)(`the notice could not be kept for their return summary (${error instanceof Error ? error.message : String(error)}); nothing was sent`, "delivery-blocked") };
|
|
456
|
+
}
|
|
457
|
+
return { status: "queued", detail: "held for their return summary; they get it with other routine notices when they next message" };
|
|
458
|
+
}
|
|
447
459
|
if (contentBlock) {
|
|
448
460
|
return { status: "failed", detail: (0, tool_error_code_1.withCode)((0, proactive_content_guard_1.proactiveContentBlockGuidance)(contentBlock), "delivery-blocked") };
|
|
449
461
|
}
|
|
@@ -4433,6 +4433,14 @@ async function sendProactiveBlueBubblesMessageToSession(params, deps = {}) {
|
|
|
4433
4433
|
source: "session_send",
|
|
4434
4434
|
intent: params.intent ?? "generic_outreach",
|
|
4435
4435
|
});
|
|
4436
|
+
if ((0, proactive_content_guard_1.isHeldForReturnReason)(internalContentBlockReason)) {
|
|
4437
|
+
try {
|
|
4438
|
+
(0, pending_1.holdNoticeForReturn)((0, identity_1.getAgentName)(), params.friendId, params.text);
|
|
4439
|
+
}
|
|
4440
|
+
catch {
|
|
4441
|
+
return { delivered: false, reason: "send_error" };
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4436
4444
|
return { delivered: false, reason: "internal_content_blocked" };
|
|
4437
4445
|
}
|
|
4438
4446
|
let image;
|
|
@@ -4598,6 +4606,16 @@ async function drainAndSendPendingBlueBubbles(deps = {}, pendingRoot) {
|
|
|
4598
4606
|
}
|
|
4599
4607
|
const internalBlockReason = (0, proactive_content_guard_1.getProactiveInternalContentBlockReason)(messageText);
|
|
4600
4608
|
if (internalBlockReason) {
|
|
4609
|
+
if ((0, proactive_content_guard_1.isHeldForReturnReason)(internalBlockReason)) {
|
|
4610
|
+
// The pending file is the only copy: it goes only once the notice is kept.
|
|
4611
|
+
try {
|
|
4612
|
+
(0, pending_1.holdNoticeForReturn)((0, identity_1.getAgentName)(), friendId, messageText);
|
|
4613
|
+
}
|
|
4614
|
+
catch {
|
|
4615
|
+
result.failed++;
|
|
4616
|
+
continue;
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4601
4619
|
result.skipped++;
|
|
4602
4620
|
try {
|
|
4603
4621
|
fs.unlinkSync(filePath);
|
package/dist/senses/pipeline.js
CHANGED
|
@@ -83,6 +83,17 @@ const friend_link_codes_1 = require("../mind/friend-link-codes");
|
|
|
83
83
|
const reply_gate_1 = require("./reply-gate");
|
|
84
84
|
const VOICE_PENDING_MAX_AGE_MS = 15 * 60 * 1_000;
|
|
85
85
|
const TELEGRAM_GENERIC_OUTREACH_PENDING_MAX_AGE_MS = 15 * 60 * 1_000;
|
|
86
|
+
function renderHeldNoticeSummary(held) {
|
|
87
|
+
const lines = [...held]
|
|
88
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
89
|
+
.map((notice) => `- (${new Date(notice.timestamp).toISOString()}) ${notice.content}`);
|
|
90
|
+
return {
|
|
91
|
+
from: held[0].from,
|
|
92
|
+
friendId: held[0].friendId,
|
|
93
|
+
timestamp: Date.now(),
|
|
94
|
+
content: `Routine notices held while they were away, not sent to them. Give them one short summary of these, folded into your reply to this message; do not send them as separate messages, and do not send this summary on its own:\n${lines.join("\n")}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
86
97
|
function pendingExpirationReason(channel, message, now, agentName) {
|
|
87
98
|
/* v8 ignore start -- pending expiry edge permutations are covered by the stale voice queue tests; this helper keeps defensive non-voice fallbacks @preserve */
|
|
88
99
|
if (Number.isFinite(message.expiresAt) && Number(message.expiresAt) <= now)
|
|
@@ -856,6 +867,8 @@ async function handleInboundTurnExclusive(input) {
|
|
|
856
867
|
const liveLatencyMode = input.latencyMode === "live";
|
|
857
868
|
let declinedForHome = false;
|
|
858
869
|
let pendingClaim;
|
|
870
|
+
let heldNoticeClaim;
|
|
871
|
+
let handedOffHeldNotices = false;
|
|
859
872
|
let turnActed = false;
|
|
860
873
|
let turnThrew = false;
|
|
861
874
|
let turnFailedOnMessages = false;
|
|
@@ -942,11 +955,16 @@ async function handleInboundTurnExclusive(input) {
|
|
|
942
955
|
const deferredReturns = input.channel === "inner"
|
|
943
956
|
? []
|
|
944
957
|
: (input.drainDeferredReturns?.(resolvedContext.friend.id) ?? []);
|
|
958
|
+
heldNoticeClaim = input.channel === "inner" ? undefined : input.claimHeldNotices?.(resolvedContext.friend.id);
|
|
959
|
+
const heldNoticeSummary = heldNoticeClaim && heldNoticeClaim.messages.length > 0
|
|
960
|
+
? [renderHeldNoticeSummary(heldNoticeClaim.messages)]
|
|
961
|
+
: [];
|
|
945
962
|
pendingClaim = input.claimPending?.(input.pendingDir);
|
|
946
963
|
const sessionPending = pendingClaim ? pendingClaim.messages : input.drainPending(input.pendingDir);
|
|
947
964
|
// A deferred return was saved for the friend's next message, whenever that comes, so a
|
|
948
965
|
// sense's freshness window for its own pending never drops it.
|
|
949
966
|
const pending = [
|
|
967
|
+
...heldNoticeSummary,
|
|
950
968
|
...deferredReturns,
|
|
951
969
|
...filterDeliverablePendingMessages({
|
|
952
970
|
pendingDir: input.pendingDir,
|
|
@@ -1237,8 +1255,11 @@ async function handleInboundTurnExclusive(input) {
|
|
|
1237
1255
|
turnFailedOnMessages = result.outcome === "errored" && result.errorClassification === "unknown";
|
|
1238
1256
|
const persistTurn = async (...args) => {
|
|
1239
1257
|
await input.postTurn(...args);
|
|
1240
|
-
if (turnFinished)
|
|
1258
|
+
if (turnFinished) {
|
|
1241
1259
|
pendingClaim?.settle();
|
|
1260
|
+
if (!input.confirmHeldNoticeDelivery)
|
|
1261
|
+
heldNoticeClaim?.settle();
|
|
1262
|
+
}
|
|
1242
1263
|
};
|
|
1243
1264
|
if (result.outcome === "suspended") {
|
|
1244
1265
|
if (!result.suspension)
|
|
@@ -1394,6 +1415,8 @@ async function handleInboundTurnExclusive(input) {
|
|
|
1394
1415
|
friendId: resolvedContext.friend.id,
|
|
1395
1416
|
},
|
|
1396
1417
|
});
|
|
1418
|
+
const heldClaimForDelivery = heldNoticeClaim;
|
|
1419
|
+
handedOffHeldNotices = Boolean(input.confirmHeldNoticeDelivery && turnFinished && heldClaimForDelivery && heldClaimForDelivery.messages.length > 0);
|
|
1397
1420
|
return {
|
|
1398
1421
|
resolvedContext,
|
|
1399
1422
|
gateResult,
|
|
@@ -1403,6 +1426,9 @@ async function handleInboundTurnExclusive(input) {
|
|
|
1403
1426
|
sessionPath: session.sessionPath,
|
|
1404
1427
|
messages: sessionMessages,
|
|
1405
1428
|
drainedPending: pending,
|
|
1429
|
+
...(handedOffHeldNotices && heldClaimForDelivery ? {
|
|
1430
|
+
heldNoticeDelivery: { confirm: () => heldClaimForDelivery.settle(), release: () => heldClaimForDelivery.release() },
|
|
1431
|
+
} : {}),
|
|
1406
1432
|
...(input.switchedProvider ? { switchedProvider: input.switchedProvider } : {}),
|
|
1407
1433
|
// Every chat sense answers an errored turn. The inner channel stays silent, and the CLI keeps showing its operator the raw error.
|
|
1408
1434
|
...(result.outcome === "errored" && input.channel !== "inner" && input.channel !== "cli" ? { failoverMessage: erroredTurnReply(result.error?.message) } : {}),
|
|
@@ -1416,6 +1442,8 @@ async function handleInboundTurnExclusive(input) {
|
|
|
1416
1442
|
// Pending messages a turn did not handle go back for the next turn; a throw or an unclassified error counts
|
|
1417
1443
|
// against them. After the first tool start the claim holds nothing, so this is a no-op.
|
|
1418
1444
|
pendingClaim?.release({ failed: turnThrew || turnFailedOnMessages });
|
|
1445
|
+
if (!(handedOffHeldNotices && !turnThrew))
|
|
1446
|
+
heldNoticeClaim?.release();
|
|
1419
1447
|
// Step 6b: Post-turn sync (opt-in). The commit is synchronous, so the
|
|
1420
1448
|
// turn's edits are recorded before the reply goes out; the push runs on
|
|
1421
1449
|
// without being awaited, holding the lock, and records its own failure.
|
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.getProactiveInternalContentBlockReason = getProactiveInternalContentBlockReason;
|
|
37
|
+
exports.isHeldForReturnReason = isHeldForReturnReason;
|
|
37
38
|
exports.isReturnToSenderReason = isReturnToSenderReason;
|
|
38
39
|
exports.proactiveContentBlockGuidance = proactiveContentBlockGuidance;
|
|
39
40
|
exports.returnHeldProactiveMessage = returnHeldProactiveMessage;
|
|
@@ -80,6 +81,28 @@ function getUntestedClaimReason(text) {
|
|
|
80
81
|
return "untested_delivery_claim";
|
|
81
82
|
return null;
|
|
82
83
|
}
|
|
84
|
+
// A routine notice asks nothing of the person now and warns of nothing: it waits for their return summary.
|
|
85
|
+
const NO_ACTION_NOW_PATTERN = /\b(?:nothing (?:to do|needed|for you to do)|no action (?:is )?(?:needed|required)|nothing is needed|fyi|just so you know)\b/i;
|
|
86
|
+
const FUTURE_GATE_PATTERN = /\b(?:nothing to do yet|nothing (?:is )?needed (?:from you )?yet|no action (?:is )?(?:needed|required) yet)\b/i;
|
|
87
|
+
const FUTURE_GATE_LATER_PATTERN = /\b(?:when|once|after|later)\b[^.]*\b(?:i'll|i will|will)\b[^.]*\b(?:send|ask|prompt|text|message)\b/i;
|
|
88
|
+
// Anything the person must know or act on now beats routine: a risk, a correction, a request, an update they asked for.
|
|
89
|
+
const MATERIAL_RISK_PATTERN = /\b(?:lost|lose|losing|data loss|outage|still (?:down|broken|failing)|is down|are down|went down|corrupt\w*|deleted|wiped|breach\w*|leak\w*|exposed|forced reboot|crash\w*|unrecoverable|at risk|urgent|failed to)\b/i;
|
|
90
|
+
const CORRECTION_PATTERN = /\b(?:correction|i was wrong|i got that wrong|that was wrong|ignore (?:my )?(?:last|earlier|previous)|disregard|retract\w*|mistake|my earlier (?:message|note))\b/i;
|
|
91
|
+
const PRESENT_ASK_PATTERN = /\b(?:please|can you|could you|would you|do you want|let me know|reply|need you to|need your|waiting (?:on|for) you|approve (?:it )?now|tap now|tap to approve|sign in now)\b/i;
|
|
92
|
+
function getRoutineNoticeReason(text) {
|
|
93
|
+
if (REQUESTED_STATUS_PATTERN.test(text) || MATERIAL_RISK_PATTERN.test(text) || CORRECTION_PATTERN.test(text))
|
|
94
|
+
return null;
|
|
95
|
+
// The announced later request ("I'll send you a tap to approve") is not a present ask; any other sentence's ask is.
|
|
96
|
+
const futureGate = FUTURE_GATE_PATTERN.test(text) && FUTURE_GATE_LATER_PATTERN.test(text);
|
|
97
|
+
const withoutAnnouncedRequest = futureGate ? text.replace(new RegExp(FUTURE_GATE_LATER_PATTERN.source + "[^.]*[.]?", "ig"), " ") : text;
|
|
98
|
+
if (PRESENT_ASK_PATTERN.test(withoutAnnouncedRequest))
|
|
99
|
+
return null;
|
|
100
|
+
if (futureGate)
|
|
101
|
+
return "routine_notice";
|
|
102
|
+
if (NO_ACTION_NOW_PATTERN.test(text) && !/\?/.test(text))
|
|
103
|
+
return "routine_notice";
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
83
106
|
// ── Public API ──────────────────────────────────────────────────
|
|
84
107
|
/**
|
|
85
108
|
* The reason a proactive (off-turn) send must not reach the person, or null.
|
|
@@ -90,7 +113,11 @@ function getProactiveInternalContentBlockReason(text) {
|
|
|
90
113
|
if (pattern.test(text))
|
|
91
114
|
return reason;
|
|
92
115
|
}
|
|
93
|
-
return getUntestedClaimReason(text);
|
|
116
|
+
return getUntestedClaimReason(text) ?? getRoutineNoticeReason(text);
|
|
117
|
+
}
|
|
118
|
+
/** A routine notice is kept for the person's return summary, not sent and not returned to the sender. */
|
|
119
|
+
function isHeldForReturnReason(reason) {
|
|
120
|
+
return reason === "routine_notice";
|
|
94
121
|
}
|
|
95
122
|
/** Reasons the sender is told about, so it can verify the result itself. */
|
|
96
123
|
function isReturnToSenderReason(reason) {
|
|
@@ -101,6 +128,9 @@ function proactiveContentBlockGuidance(reason) {
|
|
|
101
128
|
if (reason === "untested_delivery_claim") {
|
|
102
129
|
return "held back, not sent (untested_delivery_claim): do not report an untested result. Verify it yourself, then send the verified result with its proof, naming exactly what you verified (a mobile-web browser render is not proof for the native app). A status update they asked for may go unverified if it says so (\"as you asked\")";
|
|
103
130
|
}
|
|
131
|
+
if (reason === "routine_notice") {
|
|
132
|
+
return "held, not sent (routine_notice): it asks nothing of them now and warns of nothing, so it is kept for the one summary they get when they next message. If it reports lost work, data loss or an outage, corrects an earlier message, or asks for something now, say so plainly and send it again";
|
|
133
|
+
}
|
|
104
134
|
return `blocked: this reads as internal status${reason ? ` (${reason})` : ""}, so no chat sends it; rewrite it as plain words for them`;
|
|
105
135
|
}
|
|
106
136
|
/**
|
|
@@ -636,7 +636,9 @@ async function runSenseTurnExclusive(options, owner) {
|
|
|
636
636
|
// A surface saved for a person's next message is picked up on their next
|
|
637
637
|
// Telegram or voice turn too; agent channels (MCP, a2a) never take it.
|
|
638
638
|
...((channel === "telegram" || channel === "voice") && !options.disablePersistence
|
|
639
|
-
? {
|
|
639
|
+
? {
|
|
640
|
+
drainDeferredReturns: (deferredFriendId) => (0, pending_1.drainDeferredReturns)(agentName, deferredFriendId),
|
|
641
|
+
}
|
|
640
642
|
: {}),
|
|
641
643
|
runAgentOptions: {
|
|
642
644
|
mcpManager,
|
package/dist/senses/teams.js
CHANGED
|
@@ -1161,6 +1161,8 @@ async function handleTeamsMessage(text, stream, conversationId, teamsContext, se
|
|
|
1161
1161
|
enforceTrustGate: trust_gate_1.enforceTrustGate,
|
|
1162
1162
|
drainPending: pending_1.drainPending,
|
|
1163
1163
|
drainDeferredReturns: (deferredFriendId) => (0, pending_1.drainDeferredReturns)(agentName, deferredFriendId),
|
|
1164
|
+
claimHeldNotices: (heldFriendId) => (0, pending_1.claimHeldNotices)(agentName, heldFriendId),
|
|
1165
|
+
confirmHeldNoticeDelivery: true,
|
|
1164
1166
|
runAgent: async (msgs, cb, channel, sig, opts) => {
|
|
1165
1167
|
consumingTeamsSteering.add(turnKey);
|
|
1166
1168
|
try {
|
|
@@ -1225,8 +1227,20 @@ async function handleTeamsMessage(text, stream, conversationId, teamsContext, se
|
|
|
1225
1227
|
}
|
|
1226
1228
|
return;
|
|
1227
1229
|
}
|
|
1228
|
-
// Flush any remaining accumulated text at end of turn
|
|
1229
|
-
|
|
1230
|
+
// Flush any remaining accumulated text at end of turn. The held notices are settled only once this reached the
|
|
1231
|
+
// person with a reply; a failed or empty delivery puts them back for the next message.
|
|
1232
|
+
let delivered = false;
|
|
1233
|
+
try {
|
|
1234
|
+
await callbacks.flush();
|
|
1235
|
+
const finalReply = result.messages?.findLast((message) => message.role === "assistant");
|
|
1236
|
+
delivered = typeof finalReply?.content === "string" && finalReply.content.trim().length > 0 && result.turnOutcome !== "superseded";
|
|
1237
|
+
}
|
|
1238
|
+
finally {
|
|
1239
|
+
if (delivered)
|
|
1240
|
+
result.heldNoticeDelivery?.confirm();
|
|
1241
|
+
else
|
|
1242
|
+
result.heldNoticeDelivery?.release();
|
|
1243
|
+
}
|
|
1230
1244
|
// After the agent loop, check if any tool returned AUTH_REQUIRED and trigger signin.
|
|
1231
1245
|
// This must happen after the stream is done so the OAuth card renders properly.
|
|
1232
1246
|
if (teamsContext && result.messages) {
|
|
@@ -1962,6 +1976,14 @@ async function sendProactiveTeamsMessageToSession(params, deps) {
|
|
|
1962
1976
|
reason: internalContentBlockReason,
|
|
1963
1977
|
source: "session_send",
|
|
1964
1978
|
});
|
|
1979
|
+
if ((0, proactive_content_guard_1.isHeldForReturnReason)(internalContentBlockReason)) {
|
|
1980
|
+
try {
|
|
1981
|
+
(0, pending_1.holdNoticeForReturn)((0, identity_1.getAgentName)(), params.friendId, params.text);
|
|
1982
|
+
}
|
|
1983
|
+
catch {
|
|
1984
|
+
return { delivered: false, reason: "send_error" };
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1965
1987
|
return { delivered: false, reason: "internal_content_blocked" };
|
|
1966
1988
|
}
|
|
1967
1989
|
let conversationId;
|
|
@@ -2120,6 +2142,16 @@ async function drainAndSendPendingTeams(store, botApi, pendingRoot) {
|
|
|
2120
2142
|
}
|
|
2121
2143
|
const internalBlockReason = (0, proactive_content_guard_1.getProactiveInternalContentBlockReason)(messageText);
|
|
2122
2144
|
if (internalBlockReason) {
|
|
2145
|
+
if ((0, proactive_content_guard_1.isHeldForReturnReason)(internalBlockReason)) {
|
|
2146
|
+
// The pending file is the only copy: it goes only once the notice is kept.
|
|
2147
|
+
try {
|
|
2148
|
+
(0, pending_1.holdNoticeForReturn)((0, identity_1.getAgentName)(), friendId, messageText);
|
|
2149
|
+
}
|
|
2150
|
+
catch {
|
|
2151
|
+
result.failed++;
|
|
2152
|
+
continue;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2123
2155
|
result.skipped++;
|
|
2124
2156
|
try {
|
|
2125
2157
|
fs.unlinkSync(filePath);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1714",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1714",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@ouro.bot/friends"
|
|
12
12
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1714",
|
|
4
4
|
"description": "Ouroboros, the agent harness: agents with durable memory that live where you talk (terminal, Teams, iMessage, mail, voice) and use real tools. Start with npx ouro.bot@latest.",
|
|
5
5
|
"homepage": "https://ouroboros.bot/",
|
|
6
6
|
"engines": {
|