@ouro.bot/cli 0.1.0-alpha.1615 → 0.1.0-alpha.1616
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
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.1616",
|
|
6
|
+
"changes": [
|
|
7
|
+
"The shell can no longer write an agent's friends store or product rules. The file tools already refused those writes for everyone. Now a shell command that names either folder runs only when every part of it plainly reads, so an A2A peer can't raise its own trust with `sed -i` ([#1949](https://github.com/ourostack/ouroboros/issues/1949)). The command counts as naming a folder when it does so through a path, a `cd`, the call's `cwd`, `~` or `$HOME`, a glob that could land there, or the home folder handed to `find`, `xargs`, `rm` and the like. The shell's `cwd` now counts for the psyche guard too, and `rm -rf ./psyche*` is refused again. Reads through `jq`, `sort`, and `find` without an action still work."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1615",
|
|
6
12
|
"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.1616</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -42,6 +42,7 @@ exports.psycheEditNote = psycheEditNote;
|
|
|
42
42
|
exports.fileToolPath = fileToolPath;
|
|
43
43
|
exports.guardInvocation = guardInvocation;
|
|
44
44
|
const fs = __importStar(require("node:fs"));
|
|
45
|
+
const os = __importStar(require("node:os"));
|
|
45
46
|
const path = __importStar(require("node:path"));
|
|
46
47
|
const friends_1 = require("@ouro.bot/friends");
|
|
47
48
|
const shell_quote_1 = require("shell-quote");
|
|
@@ -206,8 +207,14 @@ function psycheWriteAllowed(fileClass, _filePath, context) {
|
|
|
206
207
|
// that may not write a psyche file may still read it from the shell: a command that names the psyche runs only when every part
|
|
207
208
|
// of it is a plain read. Commands that never name the psyche are untouched.
|
|
208
209
|
const PSYCHE_SHELL_FILE = /^(?:SOUL|IDENTITY|LORE|ASPIRATIONS|TACIT)\.md$/i;
|
|
209
|
-
const
|
|
210
|
-
|
|
210
|
+
const SHELL_FOLDER_PATHLIKE = {
|
|
211
|
+
psyche: /[\w.~/-]*(?:\/psyche(?:\/[\w.*-]*|(?![\w.-]))|psyche\/[\w.*-]*)/g,
|
|
212
|
+
friends: /[\w.~/-]*(?:\/friends(?:\/[\w.*-]*|(?![\w.-]))|friends\/[\w.*-]*)/g,
|
|
213
|
+
product: /[\w.~/-]*(?:\/product(?:\/[\w.*-]*|(?![\w.-]))|product\/[\w.*-]*)/g,
|
|
214
|
+
};
|
|
215
|
+
const PSYCHE_SHELL_READERS = new Set(["cat", "head", "tail", "grep", "egrep", "fgrep", "rg", "wc", "ls", "stat", "file", "diff", "cmp", "sha256sum", "shasum", "md5sum", "cd", "pwd", "echo", "printf", "true", "jq", "uniq", "cut", "tr", "nl", "column", "tree", "basename", "dirname", "realpath", "readlink", "od", "xxd", "less", "more"]);
|
|
216
|
+
/** find reads unless it runs, deletes or prints into a file. */
|
|
217
|
+
const FIND_ACTIONS = /^-(?:exec|execdir|ok|okdir|delete|fprint|fprint0|fprintf|fls)$/;
|
|
211
218
|
const PSYCHE_SHELL_GIT_READS = new Set(["log", "show", "diff", "status", "blame"]);
|
|
212
219
|
const PSYCHE_SHELL_SEPARATORS = /\s*(?:&&|\|\||[;&|\n])\s*/;
|
|
213
220
|
/** The command's words, split on unquoted whitespace and shell operators, with their quotes removed. */
|
|
@@ -238,6 +245,13 @@ function shellWordsLoosely(command) {
|
|
|
238
245
|
words.push(word);
|
|
239
246
|
return words;
|
|
240
247
|
}
|
|
248
|
+
/** The words in one shell word that could name the agent's `folder`: the bare folder name, or a path through it. */
|
|
249
|
+
function shellFolderCandidates(word, folder) {
|
|
250
|
+
const candidates = new Set(word === folder || word === `./${folder}` ? [word] : []);
|
|
251
|
+
for (const match of word.matchAll(SHELL_FOLDER_PATHLIKE[folder]))
|
|
252
|
+
candidates.add(match[0]);
|
|
253
|
+
return candidates;
|
|
254
|
+
}
|
|
241
255
|
/** Which psyche files the command names: null for none, else whether any of them is an identity file. */
|
|
242
256
|
function shellPsycheTarget(command, agentRoot) {
|
|
243
257
|
let target = null;
|
|
@@ -246,10 +260,7 @@ function shellPsycheTarget(command, agentRoot) {
|
|
|
246
260
|
for (const word of shellWordsLoosely(command)) {
|
|
247
261
|
if (PSYCHE_SHELL_FILE.test(word))
|
|
248
262
|
note(/^TACIT\.md$/i.test(word) ? "tacit" : "identity");
|
|
249
|
-
const
|
|
250
|
-
for (const match of word.matchAll(PSYCHE_SHELL_PATHLIKE))
|
|
251
|
-
candidates.add(match[0]);
|
|
252
|
-
for (const candidate of candidates) {
|
|
263
|
+
for (const candidate of shellFolderCandidates(word, "psyche")) {
|
|
253
264
|
try {
|
|
254
265
|
const fileClass = psycheFileClass(candidate, agentRoot);
|
|
255
266
|
if (fileClass)
|
|
@@ -272,6 +283,10 @@ function shellSegmentOnlyReads(segment) {
|
|
|
272
283
|
const program = words[0]?.split("/").pop() ?? "";
|
|
273
284
|
if (PSYCHE_SHELL_READERS.has(program))
|
|
274
285
|
return true;
|
|
286
|
+
if (program === "find")
|
|
287
|
+
return !words.some((word) => FIND_ACTIONS.test(word));
|
|
288
|
+
if (program === "sort")
|
|
289
|
+
return !words.some((word) => /^-[a-zA-Z]*o/.test(word) || word.startsWith("--output"));
|
|
275
290
|
if (program === "sed")
|
|
276
291
|
return !words.some((word) => /^-[a-zA-Z]*i/.test(word) || word.startsWith("--in-place"));
|
|
277
292
|
if (program === "git") {
|
|
@@ -289,14 +304,96 @@ function shellPsycheRefusal(command, context) {
|
|
|
289
304
|
const fileClass = shellPsycheTarget(command, agentRoot);
|
|
290
305
|
if (!fileClass || psycheWriteAllowed(fileClass, "", context))
|
|
291
306
|
return null;
|
|
307
|
+
if (shellCommandOnlyReads(command))
|
|
308
|
+
return null;
|
|
309
|
+
(0, runtime_1.emitNervesEvent)({ component: "repertoire", event: "repertoire.psyche_shell_refused", message: "refused a shell command that could write a psyche file this turn may not write", meta: { fileClass, channel: context.channel ?? null } });
|
|
310
|
+
return fileClass === "tacit" && isFriendTurn(context) ? exports.TACIT_REFUSAL : exports.PSYCHE_REFUSAL;
|
|
311
|
+
}
|
|
312
|
+
/** Whether every part of the command plainly reads: no output into a file, no tee and no substitution. */
|
|
313
|
+
function shellCommandOnlyReads(command) {
|
|
292
314
|
// Output into a file (a numbered stream into /dev/null or another stream aside), a substitution or a tee can write.
|
|
293
315
|
const streams = command.replace(/\d>(?:&\d|\s*\/dev\/null)/g, "");
|
|
294
316
|
const writesOut = /(?:^|[^0-9&>])>|&>|>>|\btee\b/.test(streams);
|
|
295
|
-
|
|
296
|
-
|
|
317
|
+
return !writesOut && !SUBSHELL_PATTERN.test(command) && streams.split(PSYCHE_SHELL_SEPARATORS).filter(Boolean).every(shellSegmentOnlyReads);
|
|
318
|
+
}
|
|
319
|
+
// The harness writes the friends store (each friend's trust) and the product rules; the file tools refuse a model's write there
|
|
320
|
+
// for everyone. The shell had no such check, so an A2A peer could ask for `sed -i s/friend/family/ friends/<it>.json` (#1949).
|
|
321
|
+
// A command that names either folder, resolved against the agent's own root, runs only when every part of it plainly reads.
|
|
322
|
+
const SHELL_STORE_FOLDERS = ["friends", "product"];
|
|
323
|
+
/** A word's `~/`, `$HOME/` or `${HOME}/` start, written out as the shell would. */
|
|
324
|
+
function shellHomeExpanded(word) {
|
|
325
|
+
return word.replace(/^(?:~|\$HOME|\$\{HOME\})(?=\/|$)/, os.homedir());
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* A word the shell would expand as a glob: shaped like a path (no spaces, quotes, parentheses, `:` or `=`), with `*`, `?`, a
|
|
329
|
+
* closed `[…]` or a `{a,b}`. Code handed to `node -e` (`{if`, `{length:2}`) isn't one.
|
|
330
|
+
*/
|
|
331
|
+
function isShellGlob(word) {
|
|
332
|
+
return /^[\w.~/*?[\]{},!@+-]+$/u.test(word) && (/[*?]/u.test(word) || /\[[^\]]+\]/u.test(word) || /\{[^}]*,[^}]*\}/u.test(word));
|
|
333
|
+
}
|
|
334
|
+
const SHELL_GLOB = /[*?[{]/;
|
|
335
|
+
/** Programs that change files in every folder they're given, so naming the agent's home with one reaches the store too. */
|
|
336
|
+
const SHELL_RECURSIVE_WRITERS = new Set(["find", "xargs", "rm", "mv", "cp", "rsync", "chmod", "chown", "sed", "perl", "tar", "install", "ln", "truncate", "touch"]);
|
|
337
|
+
/** Whether the absolute `dir` is the agent's home or a folder above it, from which a glob or a recursive program reaches `folder`. */
|
|
338
|
+
function holdsAgentFolder(dir, agentRoot) {
|
|
339
|
+
const roots = [path.resolve(agentRoot), canonicalize(path.resolve(agentRoot))];
|
|
340
|
+
return [dir, canonicalize(dir)].some((target) => roots.some((root) => root === target || root.startsWith(`${target === path.sep ? "" : target}${path.sep}`)));
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Whether the command names the agent's own `folder`: as a path through it, as a glob that could land in it, or as the home
|
|
344
|
+
* that holds it given to a program that changes whole folders (`find . -delete`, `xargs sed -i`). A path whose landing place
|
|
345
|
+
* can't be read counts as naming it. The bare word is also an English one ("my friends are kind"), so echo and printf's words
|
|
346
|
+
* and a git message name it only as a path.
|
|
347
|
+
*/
|
|
348
|
+
function shellNamesAgentFolder(command, agentRoot, folder) {
|
|
349
|
+
const segments = command.split(PSYCHE_SHELL_SEPARATORS).map(shellWordsLoosely);
|
|
350
|
+
const piped = segments.some((words) => programOf(words) === "xargs");
|
|
351
|
+
// Relative words start where the command is: the agent's home, then wherever a cd moved it.
|
|
352
|
+
let base = agentRoot;
|
|
353
|
+
return segments.some((words) => {
|
|
354
|
+
const program = programOf(words);
|
|
355
|
+
const prose = program === "echo" || program === "printf";
|
|
356
|
+
const wholeFolders = piped || SHELL_RECURSIVE_WRITERS.has(program);
|
|
357
|
+
const named = words.some((raw, index) => {
|
|
358
|
+
if (program === "git" && /^(?:-m|--message|-F|--file)$/.test(words[index - 1] ?? ""))
|
|
359
|
+
return false;
|
|
360
|
+
const word = shellHomeExpanded(raw);
|
|
361
|
+
try {
|
|
362
|
+
if (!prose && isShellGlob(word)) {
|
|
363
|
+
// The folder the glob starts in, before its first wildcard segment.
|
|
364
|
+
const parts = word.split("/");
|
|
365
|
+
const literal = parts.slice(0, parts.findIndex((part) => SHELL_GLOB.test(part))).join("/");
|
|
366
|
+
const start = path.resolve(base, word.startsWith("/") && literal === "" ? "/" : literal || ".");
|
|
367
|
+
if (holdsAgentFolder(start, agentRoot) || insideAgentFolder(start, agentRoot, folder))
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
if (wholeFolders && index > 0 && !raw.startsWith("-") && holdsAgentFolder(path.resolve(base, word), agentRoot))
|
|
371
|
+
return true;
|
|
372
|
+
return [...shellFolderCandidates(word, folder)].some((candidate) => (!prose || candidate.includes("/")) && insideAgentFolder(path.resolve(base, candidate), agentRoot, folder));
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
if (program === "cd" && words[1] !== undefined)
|
|
379
|
+
base = path.resolve(base, shellHomeExpanded(words[1]));
|
|
380
|
+
return named;
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
/** The program a simple command runs: its first word after any leading assignments, without its folder. */
|
|
384
|
+
function programOf(words) {
|
|
385
|
+
return words.find((word) => !/^[A-Za-z_][A-Za-z0-9_]*=/.test(word))?.split("/").pop() ?? "";
|
|
386
|
+
}
|
|
387
|
+
/** The refusal for a shell command that could write the friends store or the product rules, or null. */
|
|
388
|
+
function shellStoreRefusal(command, context) {
|
|
389
|
+
const agentRoot = context.agentRoot;
|
|
390
|
+
if (!agentRoot)
|
|
297
391
|
return null;
|
|
298
|
-
|
|
299
|
-
|
|
392
|
+
const folder = SHELL_STORE_FOLDERS.find((name) => fs.existsSync(path.join(agentRoot, name)) && shellNamesAgentFolder(command, agentRoot, name));
|
|
393
|
+
if (!folder || shellCommandOnlyReads(command))
|
|
394
|
+
return null;
|
|
395
|
+
(0, runtime_1.emitNervesEvent)({ component: "repertoire", event: "repertoire.store_shell_refused", message: "refused a shell command that could write the friends store or the product rules", meta: { folder, channel: context.channel ?? null } });
|
|
396
|
+
return REASONS.protectedPath;
|
|
300
397
|
}
|
|
301
398
|
/** A turn that carries a person who is not family: TACIT is read-only to it. */
|
|
302
399
|
function isFriendTurn(context) {
|
|
@@ -367,9 +464,14 @@ function checkProtectedPaths(toolName, args, context) {
|
|
|
367
464
|
return deny(REASONS.unreadablePath);
|
|
368
465
|
if (shellWritesToProtectedPath(command))
|
|
369
466
|
return deny(REASONS.protectedPath);
|
|
370
|
-
|
|
467
|
+
// A cwd is where the command runs, so it is read as a cd in front of it: `sed -i` with cwd friends names the store.
|
|
468
|
+
const placed = typeof args.cwd === "string" && args.cwd !== "" ? `cd '${args.cwd.replaceAll("'", "")}' && ${command}` : command;
|
|
469
|
+
const psycheRefusal = shellPsycheRefusal(placed, context);
|
|
371
470
|
if (psycheRefusal)
|
|
372
471
|
return deny(psycheRefusal);
|
|
472
|
+
const storeRefusal = shellStoreRefusal(placed, context);
|
|
473
|
+
if (storeRefusal)
|
|
474
|
+
return deny(storeRefusal);
|
|
373
475
|
}
|
|
374
476
|
return allow;
|
|
375
477
|
}
|
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.1616",
|
|
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.1616",
|
|
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.1616",
|
|
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": {
|