@ouro.bot/cli 0.1.0-alpha.1102 → 0.1.0-alpha.1104
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 +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/arc/flight-recorder.js +2 -6
- package/dist/heart/approval-files.js +2 -21
- package/dist/heart/atomic-file.js +115 -0
- package/dist/heart/attachments/downloaded-store.js +2 -30
- package/dist/heart/context-loss-sentinel.js +2 -6
- package/dist/heart/external-events/router.js +2 -18
- package/dist/senses/context-packet-ledger.js +2 -6
- package/dist/senses/pipeline.js +14 -0
- package/dist/senses/shared-turn.js +3 -13
- package/dist/senses/shepherd/notice-outbox.js +2 -10
- package/dist/senses/teams-off-turn.js +2 -4
- package/dist/senses/teams-outbox.js +2 -6
- package/dist/senses/telegram-admission.js +2 -20
- package/dist/senses/telegram-client.js +2 -22
- package/dist/senses/telegram-handoff.js +3 -7
- package/dist/senses/telegram.js +2 -17
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
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.1104",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Agent state is written through one atomic file writer. Telegram handoff notices, the Teams off-turn ledger and the Teams outbox no longer share a temporary file between two writes in the same process, and state files are created private."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1103",
|
|
12
|
+
"changes": [
|
|
13
|
+
"iMessage and Teams now tell the person when a turn fails, the way Telegram already did, instead of going silent or showing a raw error."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1102",
|
|
6
18
|
"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.1104</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -53,6 +53,7 @@ const session_events_1 = require("../heart/session-events");
|
|
|
53
53
|
const runtime_1 = require("../nerves/runtime");
|
|
54
54
|
const obligations_1 = require("./obligations");
|
|
55
55
|
const packets_1 = require("./packets");
|
|
56
|
+
const atomic_file_1 = require("../heart/atomic-file");
|
|
56
57
|
function isHabitRunTrigger(value) {
|
|
57
58
|
return value === "cron"
|
|
58
59
|
|| value === "launchd"
|
|
@@ -78,12 +79,7 @@ function flightRecorderLatestPath(agentRoot) {
|
|
|
78
79
|
function eventDay(recordedAt) {
|
|
79
80
|
return recordedAt.slice(0, 10) || "unknown";
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
83
|
-
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
84
|
-
fs.writeFileSync(tmpPath, `${JSON.stringify(value, null, 2)}\n`, "utf-8");
|
|
85
|
-
fs.renameSync(tmpPath, filePath);
|
|
86
|
-
}
|
|
82
|
+
const atomicWriteJson = atomic_file_1.writeJsonAtomicSync;
|
|
87
83
|
function cappedArray(values) {
|
|
88
84
|
return values.map((value) => (0, session_events_1.capStructuredRecordString)(value));
|
|
89
85
|
}
|
|
@@ -36,9 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.FileApprovalTokenStore = exports.FileApprovalCheckpointStore = void 0;
|
|
37
37
|
const fs = __importStar(require("node:fs"));
|
|
38
38
|
const path = __importStar(require("node:path"));
|
|
39
|
-
const node_crypto_1 = require("node:crypto");
|
|
40
39
|
const tool_approval_1 = require("./tool-approval");
|
|
41
40
|
const runtime_1 = require("../nerves/runtime");
|
|
41
|
+
const atomic_file_1 = require("./atomic-file");
|
|
42
42
|
function readObject(filePath) {
|
|
43
43
|
try {
|
|
44
44
|
const value = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
@@ -53,26 +53,7 @@ function readObject(filePath) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
function atomicWrite(filePath, value) {
|
|
56
|
-
|
|
57
|
-
fs.mkdirSync(directory, { recursive: true });
|
|
58
|
-
const temporary = `${filePath}.tmp-${process.pid}-${(0, node_crypto_1.randomUUID)()}`;
|
|
59
|
-
fs.writeFileSync(temporary, `${JSON.stringify(value)}\n`, { mode: 0o600 });
|
|
60
|
-
const temporaryHandle = fs.openSync(temporary, "r");
|
|
61
|
-
try {
|
|
62
|
-
fs.fsyncSync(temporaryHandle);
|
|
63
|
-
}
|
|
64
|
-
finally {
|
|
65
|
-
fs.closeSync(temporaryHandle);
|
|
66
|
-
}
|
|
67
|
-
fs.renameSync(temporary, filePath);
|
|
68
|
-
fs.chmodSync(filePath, 0o600);
|
|
69
|
-
const directoryHandle = fs.openSync(directory, "r");
|
|
70
|
-
try {
|
|
71
|
-
fs.fsyncSync(directoryHandle);
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
fs.closeSync(directoryHandle);
|
|
75
|
-
}
|
|
56
|
+
(0, atomic_file_1.writeFileAtomicSync)(filePath, `${JSON.stringify(value)}\n`);
|
|
76
57
|
}
|
|
77
58
|
class FileApprovalCheckpointStore {
|
|
78
59
|
filePath;
|
|
@@ -0,0 +1,115 @@
|
|
|
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.writeFileAtomicSync = writeFileAtomicSync;
|
|
37
|
+
exports.writeJsonAtomicSync = writeJsonAtomicSync;
|
|
38
|
+
exports.writeFileAtomic = writeFileAtomic;
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const fsp = __importStar(require("node:fs/promises"));
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
const node_crypto_1 = require("node:crypto");
|
|
43
|
+
const runtime_1 = require("../nerves/runtime");
|
|
44
|
+
/**
|
|
45
|
+
* Replace a file all at once: a reader sees the old contents or the new, never a torn write.
|
|
46
|
+
* The temporary name is unique per call, so concurrent writers in one process cannot collide, and
|
|
47
|
+
* the file and its folder are flushed to disk before this returns.
|
|
48
|
+
*/
|
|
49
|
+
function writeFileAtomicSync(filePath, contents, options = {}) {
|
|
50
|
+
const directory = path.dirname(filePath);
|
|
51
|
+
const temporaryDirectory = options.temporaryDirectory ?? directory;
|
|
52
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
53
|
+
fs.mkdirSync(temporaryDirectory, { recursive: true });
|
|
54
|
+
const temporary = path.join(temporaryDirectory, `${path.basename(filePath)}.${process.pid}.${(0, node_crypto_1.randomUUID)()}.tmp`);
|
|
55
|
+
try {
|
|
56
|
+
const handle = fs.openSync(temporary, "wx", options.mode ?? 0o600);
|
|
57
|
+
try {
|
|
58
|
+
fs.writeFileSync(handle, contents);
|
|
59
|
+
fs.fsyncSync(handle);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
fs.closeSync(handle);
|
|
63
|
+
}
|
|
64
|
+
fs.renameSync(temporary, filePath);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
fs.rmSync(temporary, { force: true });
|
|
68
|
+
(0, runtime_1.emitNervesEvent)({
|
|
69
|
+
level: "warn",
|
|
70
|
+
component: "engine",
|
|
71
|
+
event: "engine.atomic_write_failed",
|
|
72
|
+
message: "atomic file write failed",
|
|
73
|
+
meta: { file: path.basename(filePath), reason: error instanceof Error ? error.message : String(error) },
|
|
74
|
+
});
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
const directoryHandle = fs.openSync(directory, "r");
|
|
78
|
+
try {
|
|
79
|
+
fs.fsyncSync(directoryHandle);
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
fs.closeSync(directoryHandle);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** `writeFileAtomicSync` for a JSON value, pretty-printed with a trailing newline. */
|
|
86
|
+
function writeJsonAtomicSync(filePath, value, options = {}) {
|
|
87
|
+
writeFileAtomicSync(filePath, `${JSON.stringify(value, null, 2)}\n`, options);
|
|
88
|
+
}
|
|
89
|
+
/** The async `writeFileAtomicSync`, for large buffers on a sense's hot path. Folders it creates are private (0o700). */
|
|
90
|
+
async function writeFileAtomic(filePath, buffer) {
|
|
91
|
+
const directory = path.dirname(filePath);
|
|
92
|
+
await fsp.mkdir(directory, { recursive: true, mode: 0o700 });
|
|
93
|
+
const temporary = `${filePath}.${process.pid}.${(0, node_crypto_1.randomUUID)()}.tmp`;
|
|
94
|
+
let handle;
|
|
95
|
+
try {
|
|
96
|
+
handle = await fsp.open(temporary, "wx", 0o600);
|
|
97
|
+
await handle.writeFile(buffer);
|
|
98
|
+
await handle.sync();
|
|
99
|
+
await handle.close();
|
|
100
|
+
handle = undefined;
|
|
101
|
+
await fsp.rename(temporary, filePath);
|
|
102
|
+
const directoryHandle = await fsp.open(directory, "r");
|
|
103
|
+
try {
|
|
104
|
+
await directoryHandle.sync();
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
await directoryHandle.close();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
await handle?.close().catch(() => undefined);
|
|
112
|
+
await fsp.unlink(temporary).catch((error) => { if (error.code !== "ENOENT")
|
|
113
|
+
throw error; });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -34,12 +34,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.readBoundedResponse = readBoundedResponse;
|
|
37
|
-
exports.atomicWriteFile = atomicWriteFile;
|
|
38
37
|
exports.storeDownloadedAttachment = storeDownloadedAttachment;
|
|
39
|
-
const fs = __importStar(require("node:fs/promises"));
|
|
40
38
|
const path = __importStar(require("node:path"));
|
|
41
|
-
const node_crypto_1 = require("node:crypto");
|
|
42
39
|
const runtime_1 = require("../../nerves/runtime");
|
|
40
|
+
const atomic_file_1 = require("../atomic-file");
|
|
43
41
|
const store_1 = require("./store");
|
|
44
42
|
const originals_1 = require("./originals");
|
|
45
43
|
const downloaded_1 = require("./sources/downloaded");
|
|
@@ -69,32 +67,6 @@ async function readBoundedResponse(response, limit) {
|
|
|
69
67
|
}
|
|
70
68
|
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)), total);
|
|
71
69
|
}
|
|
72
|
-
async function atomicWriteFile(filePath, buffer) {
|
|
73
|
-
const directory = path.dirname(filePath);
|
|
74
|
-
await fs.mkdir(directory, { recursive: true, mode: 0o700 });
|
|
75
|
-
const temporary = `${filePath}.${(0, node_crypto_1.randomUUID)()}.tmp`;
|
|
76
|
-
let handle;
|
|
77
|
-
try {
|
|
78
|
-
handle = await fs.open(temporary, "wx", 0o600);
|
|
79
|
-
await handle.writeFile(buffer);
|
|
80
|
-
await handle.sync();
|
|
81
|
-
await handle.close();
|
|
82
|
-
handle = undefined;
|
|
83
|
-
await fs.rename(temporary, filePath);
|
|
84
|
-
const directoryHandle = await fs.open(directory, "r");
|
|
85
|
-
try {
|
|
86
|
-
await directoryHandle.sync();
|
|
87
|
-
}
|
|
88
|
-
finally {
|
|
89
|
-
await directoryHandle.close();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
await handle?.close().catch(() => undefined);
|
|
94
|
-
await fs.unlink(temporary).catch((error) => { if (error.code !== "ENOENT")
|
|
95
|
-
throw error; });
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
70
|
/** Keep a downloaded file as the original of an attachment record and remember it for the agent's attachment tools. */
|
|
99
71
|
async function storeDownloadedAttachment(input) {
|
|
100
72
|
const describe = (localPath) => ({
|
|
@@ -106,7 +78,7 @@ async function storeDownloadedAttachment(input) {
|
|
|
106
78
|
});
|
|
107
79
|
const provisional = (0, downloaded_1.buildDownloadedAttachmentRecord)(input.source, describe(path.resolve(input.agentRoot, "state", "attachments", ".pending", input.sourceId)));
|
|
108
80
|
const localPath = (0, originals_1.originalStoragePath)(input.agentRoot, provisional, provisional.mimeType);
|
|
109
|
-
await
|
|
81
|
+
await (0, atomic_file_1.writeFileAtomic)(localPath, input.buffer);
|
|
110
82
|
(0, runtime_1.emitNervesEvent)({ component: "engine", event: "engine.downloaded_attachment_stored", message: "downloaded attachment stored", meta: { source: input.source, byteCount: input.buffer.length } });
|
|
111
83
|
return (0, store_1.cacheRecentAttachment)(input.agentName, (0, downloaded_1.buildDownloadedAttachmentRecord)(input.source, describe(localPath)), input.agentRoot);
|
|
112
84
|
}
|
|
@@ -48,6 +48,7 @@ const flight_recorder_1 = require("../arc/flight-recorder");
|
|
|
48
48
|
const runtime_1 = require("../nerves/runtime");
|
|
49
49
|
const context_loss_gauntlet_1 = require("./context-loss-gauntlet");
|
|
50
50
|
const provider_visibility_1 = require("./provider-visibility");
|
|
51
|
+
const atomic_file_1 = require("./atomic-file");
|
|
51
52
|
const CONTEXT_LOSS_SENTINEL_RECEIPT_FILE_LIMIT = 512;
|
|
52
53
|
const CONTEXT_LOSS_SENTINEL_GIT_STATUS_TIMEOUT_MS = 5_000;
|
|
53
54
|
const REQUIRED_LANES = ["outward", "inner"];
|
|
@@ -83,12 +84,7 @@ function contextLossSentinelPaths(agentRoot) {
|
|
|
83
84
|
lock: path.join(rootDir, ".write.lock"),
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
88
|
-
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.${(0, crypto_1.randomUUID)()}.tmp`;
|
|
89
|
-
fs.writeFileSync(tmpPath, `${JSON.stringify(value, null, 2)}\n`, "utf-8");
|
|
90
|
-
fs.renameSync(tmpPath, filePath);
|
|
91
|
-
}
|
|
87
|
+
const atomicWriteJson = atomic_file_1.writeJsonAtomicSync;
|
|
92
88
|
function sleep(ms) {
|
|
93
89
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
94
90
|
}
|
|
@@ -59,6 +59,7 @@ const fs = __importStar(require("node:fs"));
|
|
|
59
59
|
const path = __importStar(require("node:path"));
|
|
60
60
|
const runtime_1 = require("../../nerves/runtime");
|
|
61
61
|
const ouro_version_manager_1 = require("../versioning/ouro-version-manager");
|
|
62
|
+
const atomic_file_1 = require("../atomic-file");
|
|
62
63
|
const MAX_EVENT_TEXT_BYTES = 4_096;
|
|
63
64
|
const MAX_EVENT_EVIDENCE = 32;
|
|
64
65
|
const MAX_EVENT_RECORD_BYTES = 64 * 1_024;
|
|
@@ -231,24 +232,7 @@ function atomicWriteJson(filePath, value, errorPrefix) {
|
|
|
231
232
|
const serialized = `${JSON.stringify(value, null, 2)}\n`;
|
|
232
233
|
if (Buffer.byteLength(serialized) > MAX_EVENT_RECORD_BYTES)
|
|
233
234
|
throw new Error(`${errorPrefix} must be bounded`);
|
|
234
|
-
|
|
235
|
-
const temporary = `${filePath}.tmp-${process.pid}-${(0, node_crypto_1.randomUUID)()}`;
|
|
236
|
-
fs.writeFileSync(temporary, serialized, { encoding: "utf8", mode: 0o600, flag: "wx" });
|
|
237
|
-
const handle = fs.openSync(temporary, "r");
|
|
238
|
-
try {
|
|
239
|
-
fs.fsyncSync(handle);
|
|
240
|
-
}
|
|
241
|
-
finally {
|
|
242
|
-
fs.closeSync(handle);
|
|
243
|
-
}
|
|
244
|
-
fs.renameSync(temporary, filePath);
|
|
245
|
-
const directory = fs.openSync(path.dirname(filePath), "r");
|
|
246
|
-
try {
|
|
247
|
-
fs.fsyncSync(directory);
|
|
248
|
-
}
|
|
249
|
-
finally {
|
|
250
|
-
fs.closeSync(directory);
|
|
251
|
-
}
|
|
235
|
+
(0, atomic_file_1.writeFileAtomicSync)(filePath, serialized);
|
|
252
236
|
}
|
|
253
237
|
function atomicWrite(recordPath, record) {
|
|
254
238
|
atomicWriteJson(recordPath, record, "External event record");
|
|
@@ -43,6 +43,7 @@ const fs = __importStar(require("node:fs"));
|
|
|
43
43
|
const path = __importStar(require("node:path"));
|
|
44
44
|
const runtime_1 = require("../nerves/runtime");
|
|
45
45
|
const context_packets_1 = require("./context-packets");
|
|
46
|
+
const atomic_file_1 = require("../heart/atomic-file");
|
|
46
47
|
function contextPacketRoot(agentRoot, sense) {
|
|
47
48
|
return path.join(agentRoot, "state", "senses", "context-packets", sense);
|
|
48
49
|
}
|
|
@@ -62,12 +63,7 @@ function receiptsDir(agentRoot, sense) {
|
|
|
62
63
|
function receiptPath(agentRoot, packet) {
|
|
63
64
|
return path.join(receiptsDir(agentRoot, packet.sense), `${packet.packetId}.json`);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
67
|
-
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
68
|
-
fs.writeFileSync(tmpPath, `${JSON.stringify(value, null, 2)}\n`, "utf-8");
|
|
69
|
-
fs.renameSync(tmpPath, filePath);
|
|
70
|
-
}
|
|
66
|
+
const atomicWriteJson = atomic_file_1.writeJsonAtomicSync;
|
|
71
67
|
function preview160(message) {
|
|
72
68
|
return {
|
|
73
69
|
sourceRef: message.renderedSourceRef,
|
package/dist/senses/pipeline.js
CHANGED
|
@@ -41,6 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
41
41
|
exports.emitObligationTransitionEpisodes = emitObligationTransitionEpisodes;
|
|
42
42
|
exports.selectCheckpointCurrentAsk = selectCheckpointCurrentAsk;
|
|
43
43
|
exports.startPostTurnSync = startPostTurnSync;
|
|
44
|
+
exports.erroredTurnReply = erroredTurnReply;
|
|
44
45
|
exports.handleInboundTurn = handleInboundTurn;
|
|
45
46
|
const fs = __importStar(require("fs"));
|
|
46
47
|
const path = __importStar(require("path"));
|
|
@@ -532,6 +533,17 @@ function startPostTurnSync(agentRoot, config) {
|
|
|
532
533
|
});
|
|
533
534
|
});
|
|
534
535
|
}
|
|
536
|
+
/**
|
|
537
|
+
* What every outward sense says when a turn errors and provider failover has nothing to say.
|
|
538
|
+
* Such turns used to end in silence: the owner saw no reply, prodded, and later got
|
|
539
|
+
* the late answer followed by a greeting to a prod (D-004); the step-limit stop was the
|
|
540
|
+
* observed cause (D-007). The engine still refuses to answer without evidence.
|
|
541
|
+
*/
|
|
542
|
+
function erroredTurnReply(errorMessage) {
|
|
543
|
+
return /iteration limit exhausted/u.test(errorMessage ?? "")
|
|
544
|
+
? "I hit my step limit in the middle of that job and couldn't finish it. Tell me to continue and I'll pick up from where I stopped."
|
|
545
|
+
: "I couldn't finish that one: something went wrong before I had an answer. Ask me again and I'll retry.";
|
|
546
|
+
}
|
|
535
547
|
async function handleInboundTurn(input) {
|
|
536
548
|
return (0, turn_execution_lease_1.withTurnExecutionLease)(() => handleInboundTurnExclusive(input));
|
|
537
549
|
}
|
|
@@ -1283,6 +1295,8 @@ async function handleInboundTurnExclusive(input) {
|
|
|
1283
1295
|
messages: sessionMessages,
|
|
1284
1296
|
drainedPending: pending,
|
|
1285
1297
|
...(input.switchedProvider ? { switchedProvider: input.switchedProvider } : {}),
|
|
1298
|
+
// Every chat sense answers an errored turn. The inner channel stays silent, and the CLI keeps showing its operator the raw error.
|
|
1299
|
+
...(result.outcome === "errored" && input.channel !== "inner" && input.channel !== "cli" ? { failoverMessage: erroredTurnReply(result.error?.message) } : {}),
|
|
1286
1300
|
};
|
|
1287
1301
|
}
|
|
1288
1302
|
finally {
|
|
@@ -39,10 +39,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.erroredTurnReply = void 0;
|
|
42
43
|
exports.stripThinkBlocks = stripThinkBlocks;
|
|
43
44
|
exports.extractOutwardSenseDeliveryText = extractOutwardSenseDeliveryText;
|
|
44
45
|
exports.getSenseSessionPath = getSenseSessionPath;
|
|
45
|
-
exports.erroredTurnReply = erroredTurnReply;
|
|
46
46
|
exports.runSenseTurn = runSenseTurn;
|
|
47
47
|
const os = __importStar(require("os"));
|
|
48
48
|
const path = __importStar(require("path"));
|
|
@@ -59,6 +59,7 @@ const pending_1 = require("../mind/pending");
|
|
|
59
59
|
const context_2 = require("../mind/context");
|
|
60
60
|
const trust_gate_1 = require("./trust-gate");
|
|
61
61
|
const pipeline_1 = require("./pipeline");
|
|
62
|
+
Object.defineProperty(exports, "erroredTurnReply", { enumerable: true, get: function () { return pipeline_1.erroredTurnReply; } });
|
|
62
63
|
const mcp_manager_1 = require("../repertoire/mcp-manager");
|
|
63
64
|
const runtime_1 = require("../nerves/runtime");
|
|
64
65
|
const session_transaction_1 = require("../mind/session-transaction");
|
|
@@ -353,17 +354,6 @@ function getSenseSessionPath(agentName, friendId, channel, sessionKey, agentRoot
|
|
|
353
354
|
* Caller provides channel, session key, friend, and message;
|
|
354
355
|
* this function handles all pipeline wiring.
|
|
355
356
|
*/
|
|
356
|
-
/**
|
|
357
|
-
* What an outward sense says when a turn errors and provider failover has nothing to say.
|
|
358
|
-
* Such turns used to end in silence: the owner saw no reply, prodded, and later got
|
|
359
|
-
* the late answer followed by a greeting to a prod (D-004); the step-limit stop was the
|
|
360
|
-
* observed cause (D-007). The engine still refuses to answer without evidence.
|
|
361
|
-
*/
|
|
362
|
-
function erroredTurnReply(errorMessage) {
|
|
363
|
-
return /iteration limit exhausted/u.test(errorMessage ?? "")
|
|
364
|
-
? "I hit my step limit in the middle of that job and couldn't finish it. Tell me to continue and I'll pick up from where I stopped."
|
|
365
|
-
: "I couldn't finish that one: something went wrong before I had an answer. Ask me again and I'll retry.";
|
|
366
|
-
}
|
|
367
357
|
async function runSenseTurn(options) {
|
|
368
358
|
options = { ...options, ...(options.shepherdSession ? { shepherdSession: Object.freeze({ ...options.shepherdSession }) } : {}) };
|
|
369
359
|
return (0, turn_execution_lease_1.withTurnExecutionLease)(async () => {
|
|
@@ -720,7 +710,7 @@ async function runSenseTurnExclusive(options, owner) {
|
|
|
720
710
|
let finalDeliveryKind = terminalDeliveryKind;
|
|
721
711
|
const acceptedTerminalOutcome = turnResult.turnOutcome === "settled" || turnResult.turnOutcome === "blocked";
|
|
722
712
|
const failoverText = turnResult.turnOutcome === "errored"
|
|
723
|
-
? turnResult.failoverMessage?.trim() || (channel === "inner" ? undefined : erroredTurnReply(terminalErrorMessage))
|
|
713
|
+
? turnResult.failoverMessage?.trim() || (channel === "inner" ? undefined : (0, pipeline_1.erroredTurnReply)(terminalErrorMessage))
|
|
724
714
|
: undefined;
|
|
725
715
|
const expectsOutwardResponse = acceptedTerminalOutcome || turnResult.turnOutcome === "command" || Boolean(failoverText);
|
|
726
716
|
let finalCausalCoordinate;
|
|
@@ -49,6 +49,7 @@ const file_lock_1 = require("../../heart/file-lock");
|
|
|
49
49
|
const runtime_1 = require("../../nerves/runtime");
|
|
50
50
|
const redact_1 = require("./redact");
|
|
51
51
|
const returns_1 = require("./returns");
|
|
52
|
+
const atomic_file_1 = require("../../heart/atomic-file");
|
|
52
53
|
const MAX_BYTES = 2 * 1024 * 1024;
|
|
53
54
|
const RECENT_SENT = 256;
|
|
54
55
|
const STATES = new Set(["pending", "sent", "unknown"]);
|
|
@@ -112,16 +113,7 @@ function atomicWrite(file, value) {
|
|
|
112
113
|
const encoded = JSON.stringify(value);
|
|
113
114
|
if (Buffer.byteLength(encoded) > MAX_BYTES)
|
|
114
115
|
throw new Error("Shepherd notice outbox exceeds its 2 MiB limit");
|
|
115
|
-
|
|
116
|
-
const fd = fs.openSync(temp, "wx", 0o600);
|
|
117
|
-
try {
|
|
118
|
-
fs.writeFileSync(fd, encoded);
|
|
119
|
-
fs.fsyncSync(fd);
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
fs.closeSync(fd);
|
|
123
|
-
}
|
|
124
|
-
fs.renameSync(temp, file);
|
|
116
|
+
(0, atomic_file_1.writeFileAtomicSync)(file, encoded);
|
|
125
117
|
}
|
|
126
118
|
function persist(root, entries) {
|
|
127
119
|
const sent = entries.filter(entry => Object.keys(entry.deliveries).length > 0 && Object.values(entry.deliveries).every(value => value.state === "sent"));
|
|
@@ -48,6 +48,7 @@ const machine_identity_1 = require("../heart/machine-identity");
|
|
|
48
48
|
const runtime_1 = require("../nerves/runtime");
|
|
49
49
|
const owner_notice_1 = require("./shepherd/owner-notice");
|
|
50
50
|
const teams_outbox_1 = require("./teams-outbox");
|
|
51
|
+
const atomic_file_1 = require("../heart/atomic-file");
|
|
51
52
|
const bots = new Map();
|
|
52
53
|
/** Forget built clients (tests). */
|
|
53
54
|
function resetOffTurnTeamsBots() {
|
|
@@ -125,10 +126,7 @@ function readLedger(agentRoot, now) {
|
|
|
125
126
|
}
|
|
126
127
|
function writeLedger(agentRoot, ledger) {
|
|
127
128
|
const target = ledgerPath(agentRoot);
|
|
128
|
-
|
|
129
|
-
const temp = `${target}.${process.pid}.tmp`;
|
|
130
|
-
fs.writeFileSync(temp, `${JSON.stringify(ledger)}\n`, { mode: 0o600 });
|
|
131
|
-
fs.renameSync(temp, target);
|
|
129
|
+
(0, atomic_file_1.writeFileAtomicSync)(target, `${JSON.stringify(ledger)}\n`);
|
|
132
130
|
}
|
|
133
131
|
function forwardToTeamsOwner(request, presence, machineId, agentRoot, now) {
|
|
134
132
|
const ownerId = (0, presence_1.effectiveOwner)(presence, "teams");
|
|
@@ -45,6 +45,7 @@ const fs = __importStar(require("fs"));
|
|
|
45
45
|
const path = __importStar(require("path"));
|
|
46
46
|
const runtime_1 = require("../nerves/runtime");
|
|
47
47
|
const session_events_1 = require("../heart/session-events");
|
|
48
|
+
const atomic_file_1 = require("../heart/atomic-file");
|
|
48
49
|
/**
|
|
49
50
|
* Teams sends that a presence without the Teams sense hands to the machine that runs it. A non-owner writes one file
|
|
50
51
|
* per message into `presence/outbox/` in the bundle, which git sync carries to the owner; the owner's Teams sense sends
|
|
@@ -70,13 +71,8 @@ function writeTeamsOutboxEntry(agentRoot, entry, nowMs) {
|
|
|
70
71
|
const hash = (0, crypto_1.createHash)("sha256").update(body).digest("hex").slice(0, 8);
|
|
71
72
|
const name = `${nowMs}-${entry.fromMachineId.replace(/[^\w.-]/g, "_")}-${hash}.json`;
|
|
72
73
|
const dir = teamsOutboxDir(agentRoot);
|
|
73
|
-
const tempDir = path.join(agentRoot, "state", "outbox-tmp");
|
|
74
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
75
|
-
fs.mkdirSync(tempDir, { recursive: true });
|
|
76
|
-
const temp = path.join(tempDir, `${name}.${process.pid}.tmp`);
|
|
77
|
-
fs.writeFileSync(temp, body, "utf-8");
|
|
78
74
|
const target = path.join(dir, name);
|
|
79
|
-
|
|
75
|
+
(0, atomic_file_1.writeFileAtomicSync)(target, body, { temporaryDirectory: path.join(agentRoot, "state", "outbox-tmp") });
|
|
80
76
|
return target;
|
|
81
77
|
}
|
|
82
78
|
function errorText(error) {
|
|
@@ -43,6 +43,7 @@ const session_transaction_1 = require("../mind/session-transaction");
|
|
|
43
43
|
const telegram_effect_adapter_1 = require("./telegram-effect-adapter");
|
|
44
44
|
Object.defineProperty(exports, "FIXED_ADMISSION_ACKNOWLEDGEMENT", { enumerable: true, get: function () { return telegram_effect_adapter_1.FIXED_ADMISSION_ACKNOWLEDGEMENT; } });
|
|
45
45
|
const telegram_client_1 = require("./telegram-client");
|
|
46
|
+
const atomic_file_1 = require("../heart/atomic-file");
|
|
46
47
|
exports.NEWLY_ADMITTED_ORIENTATION = {
|
|
47
48
|
kind: "newly_admitted",
|
|
48
49
|
instruction: "welcome_and_explain_capabilities",
|
|
@@ -132,26 +133,7 @@ function validateRecord(value, expectedId) {
|
|
|
132
133
|
throw new Error("Telegram admission record is invalid");
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
|
-
|
|
136
|
-
const temporaryPath = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
137
|
-
const handle = fs.openSync(temporaryPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY | fs.constants.O_NOFOLLOW, 0o600);
|
|
138
|
-
try {
|
|
139
|
-
fs.writeFileSync(handle, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
140
|
-
fs.fsyncSync(handle);
|
|
141
|
-
}
|
|
142
|
-
finally {
|
|
143
|
-
fs.closeSync(handle);
|
|
144
|
-
}
|
|
145
|
-
fs.renameSync(temporaryPath, filePath);
|
|
146
|
-
fs.chmodSync(filePath, 0o600);
|
|
147
|
-
const directory = fs.openSync(path.dirname(filePath), fs.constants.O_RDONLY | fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW);
|
|
148
|
-
try {
|
|
149
|
-
fs.fsyncSync(directory);
|
|
150
|
-
}
|
|
151
|
-
finally {
|
|
152
|
-
fs.closeSync(directory);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
136
|
+
const atomicWrite = atomic_file_1.writeJsonAtomicSync;
|
|
155
137
|
function readBoundedPrivateJson(filePath, maxBytes, label) {
|
|
156
138
|
const handle = fs.openSync(filePath, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
157
139
|
try {
|
|
@@ -10,8 +10,8 @@ exports.sendTelegramText = sendTelegramText;
|
|
|
10
10
|
exports.createTelegramBotApi = createTelegramBotApi;
|
|
11
11
|
const runtime_1 = require("../nerves/runtime");
|
|
12
12
|
const node_fs_1 = require("node:fs");
|
|
13
|
-
const node_path_1 = require("node:path");
|
|
14
13
|
const node_crypto_1 = require("node:crypto");
|
|
14
|
+
const atomic_file_1 = require("../heart/atomic-file");
|
|
15
15
|
class TelegramApiError extends Error {
|
|
16
16
|
status;
|
|
17
17
|
errorCode;
|
|
@@ -25,27 +25,7 @@ class TelegramApiError extends Error {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.TelegramApiError = TelegramApiError;
|
|
28
|
-
|
|
29
|
-
const directory = (0, node_path_1.dirname)(path);
|
|
30
|
-
(0, node_fs_1.mkdirSync)(directory, { recursive: true });
|
|
31
|
-
const temporaryPath = `${path}.tmp-${process.pid}-${(0, node_crypto_1.randomUUID)()}`;
|
|
32
|
-
(0, node_fs_1.writeFileSync)(temporaryPath, contents, { mode: 0o600 });
|
|
33
|
-
const temporary = (0, node_fs_1.openSync)(temporaryPath, "r");
|
|
34
|
-
try {
|
|
35
|
-
(0, node_fs_1.fsyncSync)(temporary);
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
(0, node_fs_1.closeSync)(temporary);
|
|
39
|
-
}
|
|
40
|
-
(0, node_fs_1.renameSync)(temporaryPath, path);
|
|
41
|
-
const directoryHandle = (0, node_fs_1.openSync)(directory, "r");
|
|
42
|
-
try {
|
|
43
|
-
(0, node_fs_1.fsyncSync)(directoryHandle);
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
(0, node_fs_1.closeSync)(directoryHandle);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
28
|
+
const durableAtomicWrite = (filePath, contents) => (0, atomic_file_1.writeFileAtomicSync)(filePath, contents);
|
|
49
29
|
class FileTelegramOffsetStore {
|
|
50
30
|
path;
|
|
51
31
|
constructor(path) {
|
|
@@ -55,6 +55,7 @@ const path = __importStar(require("node:path"));
|
|
|
55
55
|
const node_crypto_1 = require("node:crypto");
|
|
56
56
|
const session_events_1 = require("../heart/session-events");
|
|
57
57
|
const runtime_1 = require("../nerves/runtime");
|
|
58
|
+
const atomic_file_1 = require("../heart/atomic-file");
|
|
58
59
|
exports.OWNER_CHAT_HANDOFF_MS = 2 * 60 * 60 * 1000;
|
|
59
60
|
const HANDOFF_CUE = /\b(?:hand(?:ing)?|pass(?:ing)?)\s+you\s+(?:(?:over|off)\s+)?to\b|\bsay\s+(?:hi|hello)\s+to\s+(?:her|him|them)\b/i;
|
|
60
61
|
/** True when the owner's chat was handed to someone else and has had a message from them within the window. */
|
|
@@ -80,10 +81,7 @@ function readHeldNotices(filePath) {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
function writeHeldNotices(filePath, notices) {
|
|
83
|
-
|
|
84
|
-
const temporary = `${filePath}.${process.pid}.tmp`;
|
|
85
|
-
fs.writeFileSync(temporary, JSON.stringify(notices), { mode: 0o600 });
|
|
86
|
-
fs.renameSync(temporary, filePath);
|
|
84
|
+
(0, atomic_file_1.writeFileAtomicSync)(filePath, JSON.stringify(notices));
|
|
87
85
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.telegram_held_notices_saved", message: "saved the house notices held during a handoff", meta: { held: notices.length } });
|
|
88
86
|
}
|
|
89
87
|
/**
|
|
@@ -148,7 +146,5 @@ function readReleasedHeldKeys(filePath) {
|
|
|
148
146
|
function recordReleasedHeldKeys(filePath, keys) {
|
|
149
147
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
150
148
|
const next = [...readReleasedHeldKeys(filePath).filter((key) => !keys.includes(key)), ...keys].slice(-RELEASED_KEYS_LIMIT);
|
|
151
|
-
|
|
152
|
-
fs.writeFileSync(temporary, JSON.stringify(next), { mode: 0o600 });
|
|
153
|
-
fs.renameSync(temporary, filePath);
|
|
149
|
+
(0, atomic_file_1.writeFileAtomicSync)(filePath, JSON.stringify(next));
|
|
154
150
|
}
|
package/dist/senses/telegram.js
CHANGED
|
@@ -104,6 +104,7 @@ const pending_1 = require("../mind/pending");
|
|
|
104
104
|
const relationship_authorization_1 = require("../repertoire/relationship-authorization");
|
|
105
105
|
const telegram_admission_1 = require("./telegram-admission");
|
|
106
106
|
const telegram_effect_adapter_1 = require("./telegram-effect-adapter");
|
|
107
|
+
const atomic_file_1 = require("../heart/atomic-file");
|
|
107
108
|
const EMPTY_SHARED_TURN_DIAGNOSTIC = "(agent responded but response was empty)";
|
|
108
109
|
function hasUserVisibleTurnResponse(response) {
|
|
109
110
|
const text = response.trim();
|
|
@@ -369,23 +370,7 @@ async function appendSanctuaryTurnReceipt(agentRoot, receipt, afterPreReadStat)
|
|
|
369
370
|
while (aggregateBytes > TELEGRAM_TURN_LEDGER_MAX_BYTES && lines.length > 1) {
|
|
370
371
|
aggregateBytes -= Buffer.byteLength(lines.shift()) + 1;
|
|
371
372
|
}
|
|
372
|
-
|
|
373
|
-
(0, node_fs_1.writeFileSync)(temporary, `${lines.join("\n")}\n`, { mode: 0o600, flag: "wx" });
|
|
374
|
-
const handle = (0, node_fs_1.openSync)(temporary, "r");
|
|
375
|
-
try {
|
|
376
|
-
(0, node_fs_1.fsyncSync)(handle);
|
|
377
|
-
}
|
|
378
|
-
finally {
|
|
379
|
-
(0, node_fs_1.closeSync)(handle);
|
|
380
|
-
}
|
|
381
|
-
(0, node_fs_1.renameSync)(temporary, filePath);
|
|
382
|
-
const directory = (0, node_fs_1.openSync)(path.dirname(filePath), "r");
|
|
383
|
-
try {
|
|
384
|
-
(0, node_fs_1.fsyncSync)(directory);
|
|
385
|
-
}
|
|
386
|
-
finally {
|
|
387
|
-
(0, node_fs_1.closeSync)(directory);
|
|
388
|
-
}
|
|
373
|
+
(0, atomic_file_1.writeFileAtomicSync)(filePath, `${lines.join("\n")}\n`);
|
|
389
374
|
});
|
|
390
375
|
telegramTurnLedgerTails.set(filePath, current);
|
|
391
376
|
try {
|
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.1104",
|
|
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.1104",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|