@ouro.bot/cli 0.1.0-alpha.1612 → 0.1.0-alpha.1614
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 +8 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/actions/generated/mailbox/actions.json +2 -1
- package/dist/actions/generated/mailbox/commands.json +1 -1
- package/dist/actions/generated/mailbox/mcp.json +3 -2
- package/dist/actions/generated/mailbox-tools/tools.json +3 -2
- package/dist/heart/daemon/cli-exec.js +1 -1
- package/dist/heart/daemon/daemon.js +36 -3
- package/dist/heart/daemon/socket-client.js +5 -1
- package/dist/heart/letters/doors.js +1 -1
- package/dist/heart/letters/letter.js +19 -5
- package/dist/heart/letters/store.js +31 -3
- package/dist/heart/letters/writer.js +20 -6
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
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.1614",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Tests now prove that the Butler's rollback, like its upgrade, skips a container that disappears while it checks for other programs reading the bundle. On 2026-11-23 the 1435 rollback failed on exactly that. Nothing changes for people using it ([#1761](https://github.com/ourostack/ouroboros/issues/1761)).",
|
|
8
|
+
"Mailbox letters: a letter larger than 8 KB now files instead of failing with an unclear daemon error, because the daemon waits for a whole command on its socket (capped at 1 MiB) and both sides decode UTF-8 across chunks, so a long answer with non-Latin text no longer turns a character into �. A letter takes at most 10 links, and a GitHub line anchor such as `#L207-L213` in a link no longer reads as a letter code.",
|
|
9
|
+
"Mailbox letters: a send that fails partway no longer leaves a second waiting letter in the same dedupe scope after a restart; new letter folders are synced into their parents so a power loss can't lose a rolled letter; `ouro mailbox` keeps the `no-agent` code when the daemon has no bundle by that name; a dry run never rolls, and a dry-run duplicate shows the real letter's code and state; the Lisu and Cherokee look-alikes of L fold; an empty dedupe key means no key; number flags take digits only."
|
|
10
|
+
]
|
|
11
|
+
},
|
|
4
12
|
{
|
|
5
13
|
"version": "0.1.0-alpha.1612",
|
|
6
14
|
"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.1614</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -105,9 +105,10 @@
|
|
|
105
105
|
},
|
|
106
106
|
"links": {
|
|
107
107
|
"label": "Links",
|
|
108
|
-
"description": "Pages the person may want while answering, each { label, url }.",
|
|
108
|
+
"description": "Pages the person may want while answering, at most 10, each { label, url }.",
|
|
109
109
|
"optional": true,
|
|
110
110
|
"protocolOnly": true,
|
|
111
|
+
"maxItems": 10,
|
|
111
112
|
"of": {
|
|
112
113
|
"label": "Link",
|
|
113
114
|
"description": "One page.",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"links": {
|
|
40
40
|
"type": "string",
|
|
41
|
-
"description": "Pages the person may want while answering, each { label, url }, as JSON."
|
|
41
|
+
"description": "Pages the person may want while answering, at most 10, each { label, url }, as JSON."
|
|
42
42
|
},
|
|
43
43
|
"dedupe-key": {
|
|
44
44
|
"type": "string",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"links": {
|
|
65
65
|
"type": "array",
|
|
66
|
-
"description": "Pages the person may want while answering, each { label, url }.",
|
|
66
|
+
"description": "Pages the person may want while answering, at most 10, each { label, url }.",
|
|
67
67
|
"items": {
|
|
68
68
|
"type": "object",
|
|
69
69
|
"description": "One page.",
|
|
@@ -84,7 +84,8 @@
|
|
|
84
84
|
"url"
|
|
85
85
|
],
|
|
86
86
|
"additionalProperties": false
|
|
87
|
-
}
|
|
87
|
+
},
|
|
88
|
+
"maxItems": 10
|
|
88
89
|
},
|
|
89
90
|
"dedupeKey": {
|
|
90
91
|
"type": "string",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"links": {
|
|
66
66
|
"type": "array",
|
|
67
|
-
"description": "Pages the person may want while answering, each { label, url }.",
|
|
67
|
+
"description": "Pages the person may want while answering, at most 10, each { label, url }.",
|
|
68
68
|
"items": {
|
|
69
69
|
"type": "object",
|
|
70
70
|
"description": "One page.",
|
|
@@ -85,7 +85,8 @@
|
|
|
85
85
|
"url"
|
|
86
86
|
],
|
|
87
87
|
"additionalProperties": false
|
|
88
|
-
}
|
|
88
|
+
},
|
|
89
|
+
"maxItems": 10
|
|
89
90
|
},
|
|
90
91
|
"dedupeKey": {
|
|
91
92
|
"type": "string",
|
|
@@ -116,7 +116,7 @@ const cli_manifest_1 = require("./cli-manifest");
|
|
|
116
116
|
const doors_1 = require("../letters/doors");
|
|
117
117
|
/** The codes the mailbox commands fail with: the doors' own checks and the daemon's letters writer. */
|
|
118
118
|
exports.MAILBOX_CLI_REFUSAL_CODES = new Set([
|
|
119
|
-
"daemon-down", "bad-input", "not-found",
|
|
119
|
+
"daemon-down", "bad-input", "no-agent", "not-found",
|
|
120
120
|
"invalid-letter", "no-person", "not-sender", "not-waiting", "no-answering-handle",
|
|
121
121
|
]);
|
|
122
122
|
const plugin_cli_1 = require("./plugin-cli");
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.OuroDaemon = void 0;
|
|
36
|
+
exports.OuroDaemon = exports.MAX_SOCKET_COMMAND_BYTES = void 0;
|
|
37
37
|
exports.messageFromHabitPokeError = messageFromHabitPokeError;
|
|
38
38
|
exports.parseOrphanPidsFromPs = parseOrphanPidsFromPs;
|
|
39
39
|
exports.filterPidfilePidsToActualOrphans = filterPidfilePidsToActualOrphans;
|
|
@@ -45,11 +45,13 @@ exports.killOrphanProcesses = killOrphanProcesses;
|
|
|
45
45
|
exports.writePidfile = writePidfile;
|
|
46
46
|
exports.handleAgentSenseTurn = handleAgentSenseTurn;
|
|
47
47
|
exports.handleAgentAskTurn = handleAgentAskTurn;
|
|
48
|
+
exports.socketCommandComplete = socketCommandComplete;
|
|
48
49
|
const fs = __importStar(require("fs"));
|
|
49
50
|
const net = __importStar(require("net"));
|
|
50
51
|
const os = __importStar(require("os"));
|
|
51
52
|
const path = __importStar(require("path"));
|
|
52
53
|
const node_crypto_1 = require("node:crypto");
|
|
54
|
+
const node_string_decoder_1 = require("node:string_decoder");
|
|
53
55
|
const identity_1 = require("../identity");
|
|
54
56
|
const state_retention_1 = require("./state-retention");
|
|
55
57
|
const agent_discovery_1 = require("./agent-discovery");
|
|
@@ -625,6 +627,22 @@ const STATE_RETENTION_FIRST_DELAY_MS = 10 * 60_000;
|
|
|
625
627
|
const STATE_RETENTION_INTERVAL_MS = 24 * 60 * 60_000;
|
|
626
628
|
const UPDATER_AGENT_WATCH_FIRST_DELAY_MS = 5 * 60_000;
|
|
627
629
|
const UPDATER_AGENT_WATCH_INTERVAL_MS = 60 * 60_000;
|
|
630
|
+
/** The most one socket command may hold; a bigger one is refused rather than read on. */
|
|
631
|
+
exports.MAX_SOCKET_COMMAND_BYTES = 1024 * 1024;
|
|
632
|
+
/** Whether the text read so far is a whole command: it has the newline clients end with, or is JSON on its own. */
|
|
633
|
+
function socketCommandComplete(raw) {
|
|
634
|
+
if (raw.includes("\n"))
|
|
635
|
+
return true;
|
|
636
|
+
if (!raw.trimEnd().endsWith("}"))
|
|
637
|
+
return false;
|
|
638
|
+
try {
|
|
639
|
+
JSON.parse(raw);
|
|
640
|
+
return true;
|
|
641
|
+
}
|
|
642
|
+
catch {
|
|
643
|
+
return false;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
628
646
|
class OuroDaemon {
|
|
629
647
|
socketPath;
|
|
630
648
|
processManager;
|
|
@@ -1018,11 +1036,26 @@ class OuroDaemon {
|
|
|
1018
1036
|
}
|
|
1019
1037
|
/* v8 ignore stop */
|
|
1020
1038
|
};
|
|
1039
|
+
// One write can arrive in several chunks (macOS cuts a unix socket write at 8 KiB), and a chunk can end inside
|
|
1040
|
+
// a UTF-8 character, so the command is decoded as a stream and read only once it is whole.
|
|
1041
|
+
const decoder = new node_string_decoder_1.StringDecoder("utf8");
|
|
1042
|
+
let bytes = 0;
|
|
1021
1043
|
connection.on("data", (chunk) => {
|
|
1022
|
-
|
|
1023
|
-
|
|
1044
|
+
if (responded)
|
|
1045
|
+
return;
|
|
1046
|
+
bytes += chunk.length;
|
|
1047
|
+
raw += decoder.write(chunk);
|
|
1048
|
+
if (bytes > exports.MAX_SOCKET_COMMAND_BYTES) {
|
|
1049
|
+
responded = true;
|
|
1050
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "daemon.command_too_large", message: "socket command over the size cap refused", meta: { bytes, cap: exports.MAX_SOCKET_COMMAND_BYTES } });
|
|
1051
|
+
connection.end(JSON.stringify({ ok: false, error: `The daemon command is larger than ${exports.MAX_SOCKET_COMMAND_BYTES} bytes.` }));
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
if (socketCommandComplete(raw))
|
|
1055
|
+
void flushResponse();
|
|
1024
1056
|
});
|
|
1025
1057
|
connection.on("end", () => {
|
|
1058
|
+
raw += decoder.end();
|
|
1026
1059
|
void flushResponse();
|
|
1027
1060
|
});
|
|
1028
1061
|
});
|
|
@@ -41,6 +41,7 @@ exports.requestInnerWake = requestInnerWake;
|
|
|
41
41
|
exports.requestPrivateWake = requestPrivateWake;
|
|
42
42
|
const fs = __importStar(require("fs"));
|
|
43
43
|
const net = __importStar(require("net"));
|
|
44
|
+
const node_string_decoder_1 = require("node:string_decoder");
|
|
44
45
|
const runtime_1 = require("../../nerves/runtime");
|
|
45
46
|
exports.DEFAULT_DAEMON_SOCKET_PATH = "/tmp/ouroboros-daemon.sock";
|
|
46
47
|
exports.DEFAULT_DAEMON_COMMAND_TIMEOUT_MS = 10 * 60 * 1000;
|
|
@@ -191,8 +192,10 @@ function sendDaemonCommand(socketPath, command, options = {}) {
|
|
|
191
192
|
// fix" but actually *added* the half-close back).
|
|
192
193
|
client.write(JSON.stringify(command) + "\n");
|
|
193
194
|
});
|
|
195
|
+
// A long answer comes in several chunks, and one can end inside a UTF-8 character, so decode it as a stream.
|
|
196
|
+
const decoder = new node_string_decoder_1.StringDecoder("utf8");
|
|
194
197
|
client.on("data", (chunk) => {
|
|
195
|
-
raw +=
|
|
198
|
+
raw += decoder.write(chunk);
|
|
196
199
|
});
|
|
197
200
|
client.on("error", (error) => {
|
|
198
201
|
/* v8 ignore next -- duplicate post-settlement socket errors are ignored defensively @preserve */
|
|
@@ -215,6 +218,7 @@ function sendDaemonCommand(socketPath, command, options = {}) {
|
|
|
215
218
|
/* v8 ignore next -- duplicate post-settlement socket end events are ignored defensively @preserve */
|
|
216
219
|
if (settled)
|
|
217
220
|
return;
|
|
221
|
+
raw += decoder.end();
|
|
218
222
|
const trimmed = raw.trim();
|
|
219
223
|
if (trimmed.length === 0 && command.kind === "daemon.stop") {
|
|
220
224
|
(0, runtime_1.emitNervesEvent)({
|
|
@@ -289,7 +289,7 @@ function parseMailboxCli(word, tokens) {
|
|
|
289
289
|
const type = properties[key].type;
|
|
290
290
|
// The generator gives a whole number flag type "number" and a list one JSON string (ouro-actions.mts).
|
|
291
291
|
if (type === "integer") {
|
|
292
|
-
input[key] = Number(value);
|
|
292
|
+
input[key] = /^\d+$/.test(value) ? Number(value) : Number.NaN;
|
|
293
293
|
if (!Number.isFinite(input[key]))
|
|
294
294
|
throw new Error(`${token} takes a number, not ${value}.\n${usageText}`);
|
|
295
295
|
}
|
|
@@ -21,6 +21,7 @@ exports.LETTER_LIMITS = {
|
|
|
21
21
|
effect: 160,
|
|
22
22
|
linkLabel: 80,
|
|
23
23
|
url: 500,
|
|
24
|
+
links: 10,
|
|
24
25
|
dedupeKey: 120,
|
|
25
26
|
lane: 120,
|
|
26
27
|
reason: 200,
|
|
@@ -46,6 +47,8 @@ const LOOK_ALIKES = {
|
|
|
46
47
|
"Α": "A", "Β": "B", "Ε": "E", "Ζ": "Z", "Η": "H", "Ι": "I", "Κ": "K", "Μ": "M",
|
|
47
48
|
"Ν": "N", "Ο": "O", "Ρ": "P", "Τ": "T", "Υ": "Y", "Χ": "X", "ο": "o", "ι": "i",
|
|
48
49
|
"ν": "v", "ρ": "p", "ı": "i", "ʟ": "L",
|
|
50
|
+
// Lisu and Cherokee capitals that NFKC leaves alone.
|
|
51
|
+
"ꓡ": "L", "Ꮮ": "L",
|
|
49
52
|
};
|
|
50
53
|
const HIDDEN = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu;
|
|
51
54
|
const HIDDEN_RUNS = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu;
|
|
@@ -123,20 +126,30 @@ function options(kind, value) {
|
|
|
123
126
|
return { id: String(index + 1), label, effect };
|
|
124
127
|
});
|
|
125
128
|
}
|
|
129
|
+
// A line anchor such as GitHub's #L207 or #L207-L213, which would otherwise read as a letter code.
|
|
130
|
+
const LINE_ANCHOR = /#L\d+(?:C\d+)?(?:-L\d+(?:C\d+)?)?$/;
|
|
131
|
+
/** A link's address: checked like other sender text, except that a line anchor at its end is allowed. */
|
|
132
|
+
function url(at, value) {
|
|
133
|
+
const address = plain(`${at}'s url`, value, exports.LETTER_LIMITS.url, true);
|
|
134
|
+
if (!/^https?:\/\//.test(address))
|
|
135
|
+
refuse(`${at}'s url must start with https:// or http://.`);
|
|
136
|
+
if (hasLetterCode(address.replace(LINE_ANCHOR, "")))
|
|
137
|
+
refuse(`${at}'s url contains a letter code, which only Ouro writes. Fix: link to a page whose address has no code such as L8.`);
|
|
138
|
+
return storedText(address);
|
|
139
|
+
}
|
|
126
140
|
function links(value) {
|
|
127
141
|
if (value === undefined)
|
|
128
142
|
return [];
|
|
129
143
|
if (!Array.isArray(value))
|
|
130
144
|
refuse("links must be a list of { label, url }.");
|
|
145
|
+
if (value.length > exports.LETTER_LIMITS.links)
|
|
146
|
+
refuse(`a letter takes at most ${exports.LETTER_LIMITS.links} links.`);
|
|
131
147
|
return value.map((entry, index) => {
|
|
132
148
|
const at = `link ${index + 1}`;
|
|
133
149
|
if (!isObject(entry))
|
|
134
150
|
refuse(`${at} must be { label, url }.`);
|
|
135
151
|
const label = text(`${at}'s label`, entry.label, exports.LETTER_LIMITS.linkLabel, true);
|
|
136
|
-
|
|
137
|
-
if (!/^https?:\/\//.test(url))
|
|
138
|
-
refuse(`${at}'s url must start with https:// or http://.`);
|
|
139
|
-
return { label, url };
|
|
152
|
+
return { label, url: url(at, entry.url) };
|
|
140
153
|
});
|
|
141
154
|
}
|
|
142
155
|
function isoTime(value) {
|
|
@@ -171,7 +184,8 @@ function draft(input) {
|
|
|
171
184
|
if (expiresAt !== undefined && (typeof expiresAt !== "string" || !isoTime(expiresAt)))
|
|
172
185
|
refuse("expiresAt must be an ISO time.");
|
|
173
186
|
// The person never sees the dedupe key, so it may hold anything, a code such as L2 included.
|
|
174
|
-
|
|
187
|
+
// An empty key means no key.
|
|
188
|
+
const dedupeKey = plain("dedupeKey", input.dedupeKey, exports.LETTER_LIMITS.dedupeKey, false);
|
|
175
189
|
const lane = text("lane", input.lane, exports.LETTER_LIMITS.lane, false);
|
|
176
190
|
return {
|
|
177
191
|
kind,
|
|
@@ -54,7 +54,7 @@ class LetterStore {
|
|
|
54
54
|
/** Writes a new letter's file, then syncs the file and the folder, so the letter survives a crash once this returns. */
|
|
55
55
|
create(letter) {
|
|
56
56
|
const file = this.openFile(letter.id);
|
|
57
|
-
this.
|
|
57
|
+
this.makeDir(this.dir);
|
|
58
58
|
const fd = this.io.openSync(file, "wx", 0o600);
|
|
59
59
|
try {
|
|
60
60
|
this.io.writeSync(fd, `${JSON.stringify(letter)}\n`);
|
|
@@ -66,6 +66,23 @@ class LetterStore {
|
|
|
66
66
|
this.syncDir(this.dir);
|
|
67
67
|
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.letter_created", message: "letter file created", meta: { kind: letter.kind } });
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Removes a letter file a failed create left behind, then syncs the folder. Returns whether no file is left; a
|
|
71
|
+
* leftover the call couldn't remove is the writer's to index, so a retry finds it.
|
|
72
|
+
*/
|
|
73
|
+
discard(id) {
|
|
74
|
+
const file = this.openFile(id);
|
|
75
|
+
try {
|
|
76
|
+
if (this.io.existsSync(file)) {
|
|
77
|
+
this.io.unlinkSync(file);
|
|
78
|
+
this.syncDir(this.dir);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.discard_failed", message: "a failed create's letter file could not be removed", meta: { reason: error.message } });
|
|
83
|
+
}
|
|
84
|
+
return !this.io.existsSync(file);
|
|
85
|
+
}
|
|
69
86
|
/** Appends one event to an open letter, after cutting any torn last line back to the last newline. */
|
|
70
87
|
append(id, event) {
|
|
71
88
|
const fd = this.io.openSync(this.openFile(id), "r+");
|
|
@@ -92,7 +109,7 @@ class LetterStore {
|
|
|
92
109
|
roll(id, at) {
|
|
93
110
|
const month = at.toISOString().slice(0, 7);
|
|
94
111
|
const target = path.join(this.dir, "closed", month);
|
|
95
|
-
this.
|
|
112
|
+
this.makeDir(target);
|
|
96
113
|
this.io.renameSync(this.openFile(id), path.join(target, `${id}.jsonl`));
|
|
97
114
|
this.syncDir(target);
|
|
98
115
|
this.syncDir(this.dir);
|
|
@@ -124,7 +141,7 @@ class LetterStore {
|
|
|
124
141
|
}
|
|
125
142
|
/** Records the next code number: a temporary file, synced, renamed over the record, then the folder synced. */
|
|
126
143
|
writeNextCode(next) {
|
|
127
|
-
this.
|
|
144
|
+
this.makeDir(this.dir);
|
|
128
145
|
const temp = path.join(this.dir, `${NEXT_CODE}.tmp`);
|
|
129
146
|
const fd = this.io.openSync(temp, "w", 0o600);
|
|
130
147
|
try {
|
|
@@ -142,6 +159,17 @@ class LetterStore {
|
|
|
142
159
|
throw new Error(`${id} is not a letter id.`);
|
|
143
160
|
return path.join(this.dir, `${id}.jsonl`);
|
|
144
161
|
}
|
|
162
|
+
/** Makes a folder and any missing parents, syncing the parent of each one it made so the new entries survive a crash. */
|
|
163
|
+
makeDir(dir) {
|
|
164
|
+
const missing = [];
|
|
165
|
+
for (let at = dir; !this.io.existsSync(at); at = path.dirname(at))
|
|
166
|
+
missing.push(at);
|
|
167
|
+
if (missing.length === 0)
|
|
168
|
+
return;
|
|
169
|
+
this.io.mkdirSync(dir, { recursive: true });
|
|
170
|
+
for (const made of missing)
|
|
171
|
+
this.syncDir(path.dirname(made));
|
|
172
|
+
}
|
|
145
173
|
syncDir(dir) {
|
|
146
174
|
const fd = this.io.openSync(dir, "r");
|
|
147
175
|
try {
|
|
@@ -108,7 +108,7 @@ class LettersWriter {
|
|
|
108
108
|
async run(agent, action, input, options = {}) {
|
|
109
109
|
if (typeof input !== "object" || input === null || Array.isArray(input))
|
|
110
110
|
throw new LetterRefusal("bad-input", "The action's input must be an object.");
|
|
111
|
-
const letters = this.open(agent);
|
|
111
|
+
const letters = this.open(agent, options.dryRun === true);
|
|
112
112
|
const result = await this.dispatch(letters, action, input, options.dryRun === true);
|
|
113
113
|
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.action_done", message: "letters action done", meta: { action, outcome: result.outcome } });
|
|
114
114
|
return result;
|
|
@@ -130,8 +130,8 @@ class LettersWriter {
|
|
|
130
130
|
default: return Promise.reject(new LetterRefusal("unknown-door", `The mailbox has no action ${action}.`));
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
/** The agent's letters, read from its bundle the first time; letters closed long enough are rolled then. */
|
|
134
|
-
open(agent) {
|
|
133
|
+
/** The agent's letters, read from its bundle the first time; letters closed long enough are rolled then, unless that first call is a dry run, which writes nothing. */
|
|
134
|
+
open(agent, dryRun) {
|
|
135
135
|
const bundle = path.join(this.deps.bundlesRoot, `${agent}.ouro`);
|
|
136
136
|
if (!AGENT_NAME.test(agent) || !fs.existsSync(bundle))
|
|
137
137
|
throw new LetterRefusal("no-agent", `No agent bundle ${agent}.ouro is on this machine.`);
|
|
@@ -142,7 +142,8 @@ class LettersWriter {
|
|
|
142
142
|
const index = new letter_index_1.LetterIndex(store.loadAll(), store.readNextCode());
|
|
143
143
|
const letters = { agent, store, index, queue: Promise.resolve(), waiters: new Map() };
|
|
144
144
|
this.agents.set(agent, letters);
|
|
145
|
-
|
|
145
|
+
if (!dryRun)
|
|
146
|
+
this.rollClosed(letters);
|
|
146
147
|
return letters;
|
|
147
148
|
}
|
|
148
149
|
rollClosed(letters) {
|
|
@@ -200,7 +201,7 @@ class LettersWriter {
|
|
|
200
201
|
if (duplicate) {
|
|
201
202
|
const { letter } = duplicate.entry;
|
|
202
203
|
if (dryRun)
|
|
203
|
-
return { outcome: "preview", id:
|
|
204
|
+
return { outcome: "preview", id: letter.id, code: letter.code, state: duplicate.entry.state, message: `Would return ${letter.code}, which is already ${duplicate.entry.state} with this dedupeKey.` };
|
|
204
205
|
if (duplicate.why === "answered") {
|
|
205
206
|
const answer = duplicate.entry.events.find((event) => event.t === "answered");
|
|
206
207
|
return { outcome: "done", id: letter.id, code: letter.code, state: "answered", message: `${letter.code} was answered ${optionText(letter, answer.option)} in the last day, so the answer stands.` };
|
|
@@ -216,7 +217,20 @@ class LettersWriter {
|
|
|
216
217
|
letters.store.writeNextCode(number + 1);
|
|
217
218
|
letters.index.reserve(number + 1);
|
|
218
219
|
const letter = { v: 1, id: (this.deps.newId ?? letter_1.newLetterId)(now.getTime()), code: `L${number}`, to, from, ...draft, createdAt: now.toISOString() };
|
|
219
|
-
|
|
220
|
+
try {
|
|
221
|
+
letters.store.create(letter);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
// A create that fails after its write would leave a letter the index doesn't know, and a retry would file a
|
|
225
|
+
// second one in the same dedupe scope. Remove it; if it can't be removed, index it so the retry finds it.
|
|
226
|
+
// EEXIST means the file is another letter's, which this create never wrote, so it stays.
|
|
227
|
+
if (error.code !== "EEXIST" && !letters.store.discard(letter.id)) {
|
|
228
|
+
const left = letters.store.read(letter.id);
|
|
229
|
+
if (left)
|
|
230
|
+
letters.index.add(left);
|
|
231
|
+
}
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
220
234
|
letters.index.add({ letter, events: [], closed: false });
|
|
221
235
|
return { outcome: "needs-human", id: letter.id, code: letter.code, state: "waiting", message: `Filed ${letter.code}, ${letter.subject}. It waits for the person's answer.` };
|
|
222
236
|
}
|
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.1614",
|
|
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.1614",
|
|
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.1614",
|
|
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": {
|