@ouro.bot/cli 0.1.0-alpha.1145 → 0.1.0-alpha.1146
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 +6 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/shepherd/operations.js +1 -1
- package/dist/heart/shepherd-config.js +3 -13
- package/dist/repertoire/guardrails.js +4 -1
- package/dist/repertoire/tools-app-sessions.js +82 -315
- package/dist/senses/app-sessions/app-interface.js +317 -0
- package/dist/senses/app-sessions/client.js +86 -250
- package/dist/senses/app-sessions/prompts.js +101 -0
- package/dist/senses/app-sessions/sense.js +13 -9
- package/dist/senses/app-sessions/size-watch.js +3 -2
- package/dist/senses/app-sessions/store.js +12 -2
- package/dist/senses/app-sessions/waiting-prompts.js +1 -5
- package/dist/senses/app-sessions/wake-runner.js +2 -1
- package/dist/senses/shepherd/host.js +0 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/senses/shepherd/copilot-app-holds.js +0 -138
- package/dist/senses/shepherd/copilot-app.js +0 -676
|
@@ -44,6 +44,8 @@ exports.updateWatches = updateWatches;
|
|
|
44
44
|
exports.readProbes = readProbes;
|
|
45
45
|
exports.addProbe = addProbe;
|
|
46
46
|
exports.removeProbe = removeProbe;
|
|
47
|
+
exports.readPending = readPending;
|
|
48
|
+
exports.writePending = writePending;
|
|
47
49
|
exports.writeSnapshot = writeSnapshot;
|
|
48
50
|
exports.readSnapshot = readSnapshot;
|
|
49
51
|
exports.snapshotSummary = snapshotSummary;
|
|
@@ -74,15 +76,16 @@ function writeJson(file, value) {
|
|
|
74
76
|
}
|
|
75
77
|
const watchFile = (agentRoot) => path.join(appSessionsStateDir(agentRoot), "watch.json");
|
|
76
78
|
const probesFile = (agentRoot) => path.join(appSessionsStateDir(agentRoot), "probes.json");
|
|
79
|
+
const pendingFile = (agentRoot) => path.join(appSessionsStateDir(agentRoot), "pending.json");
|
|
77
80
|
const snapshotFile = (agentRoot) => path.join(appSessionsStateDir(agentRoot), "snapshot.json");
|
|
78
81
|
function readWatches(agentRoot) {
|
|
79
82
|
return readJson(watchFile(agentRoot), {});
|
|
80
83
|
}
|
|
81
84
|
/** Start (or extend) watching a session from `offset` in its event log. */
|
|
82
|
-
function watchSession(agentRoot, id, name, offset, now) {
|
|
85
|
+
function watchSession(agentRoot, id, name, offset, now, once = false) {
|
|
83
86
|
const watches = readWatches(agentRoot);
|
|
84
87
|
const current = watches[id];
|
|
85
|
-
const entry = { name: name ?? current?.name ?? null, offset: current ? Math.min(current.offset, offset) : offset, until: now + exports.WATCH_MS };
|
|
88
|
+
const entry = { name: name ?? current?.name ?? null, offset: current ? Math.min(current.offset, offset) : offset, until: now + exports.WATCH_MS, ...(once && (current?.once ?? true) ? { once: true } : {}) };
|
|
86
89
|
watches[id] = entry;
|
|
87
90
|
writeJson(watchFile(agentRoot), watches);
|
|
88
91
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_watch", message: "watching a Copilot app session for replies", meta: { session: id } });
|
|
@@ -130,6 +133,13 @@ function removeProbe(agentRoot, id) {
|
|
|
130
133
|
delete probes[id];
|
|
131
134
|
writeJson(probesFile(agentRoot), probes);
|
|
132
135
|
}
|
|
136
|
+
/** The open requests by session id. */
|
|
137
|
+
function readPending(agentRoot) {
|
|
138
|
+
return readJson(pendingFile(agentRoot), {});
|
|
139
|
+
}
|
|
140
|
+
function writePending(agentRoot, pending) {
|
|
141
|
+
writeJson(pendingFile(agentRoot), pending);
|
|
142
|
+
}
|
|
133
143
|
function writeSnapshot(agentRoot, snapshot) {
|
|
134
144
|
writeJson(snapshotFile(agentRoot), snapshot);
|
|
135
145
|
}
|
|
@@ -57,15 +57,11 @@ exports.WAITING_LIST_MAX = 6;
|
|
|
57
57
|
const stateFile = (agentRoot) => path.join((0, store_1.appSessionsStateDir)(agentRoot), "waiting-prompts.json");
|
|
58
58
|
const promptKey = (prompt) => `${prompt.session}:${prompt.requestId}`;
|
|
59
59
|
exports.promptKey = promptKey;
|
|
60
|
-
/** The open permission prompts
|
|
60
|
+
/** The open permission prompts in the sidebar. One the app gave no event time keeps the first time it was seen. */
|
|
61
61
|
function waitingPromptsOf(agentRoot, rows, now) {
|
|
62
62
|
const before = new Map(((0, store_1.readSnapshot)(agentRoot)?.waitingPrompts ?? []).map(prompt => [(0, exports.promptKey)(prompt), prompt.since]));
|
|
63
63
|
const prompts = [];
|
|
64
64
|
for (const row of rows) {
|
|
65
|
-
if (row.repositoryTrust) {
|
|
66
|
-
const requestId = row.repositoryTrust.decisionId;
|
|
67
|
-
prompts.push({ session: row.id, name: row.name, requestId, what: `a repository trust decision for ${row.repositoryTrust.repo}`, since: before.get((0, exports.promptKey)({ session: row.id, requestId })) ?? now });
|
|
68
|
-
}
|
|
69
65
|
if (!row.prompt)
|
|
70
66
|
continue;
|
|
71
67
|
const stamped = Date.parse(row.prompt.at ?? "");
|
|
@@ -40,6 +40,7 @@ exports.runWakeRunners = runWakeRunners;
|
|
|
40
40
|
const node_child_process_1 = require("node:child_process");
|
|
41
41
|
const path = __importStar(require("node:path"));
|
|
42
42
|
const runtime_1 = require("../../nerves/runtime");
|
|
43
|
+
const app_interface_1 = require("./app-interface");
|
|
43
44
|
const client_1 = require("./client");
|
|
44
45
|
const store_1 = require("./store");
|
|
45
46
|
const wake_runner_state_1 = require("./wake-runner-state");
|
|
@@ -118,7 +119,7 @@ const sendWake = (client) => async (session, message, delivery, replaces) => {
|
|
|
118
119
|
// The command re-derives its whole state each run, so a wake still queued in the session is stale news: take it back first.
|
|
119
120
|
if (replaces)
|
|
120
121
|
await (0, client_1.withdrawQueuedMessages)(session, replaces, client).catch(() => 0);
|
|
121
|
-
const result = await (0,
|
|
122
|
+
const result = await (0, app_interface_1.deliverMessage)(session, message, delivery, client);
|
|
122
123
|
return { ok: result.ok, error: result.error };
|
|
123
124
|
};
|
|
124
125
|
exports.sendWake = sendWake;
|
|
@@ -4,13 +4,10 @@ exports.createShepherdHost = createShepherdHost;
|
|
|
4
4
|
const runtime_1 = require("../../nerves/runtime");
|
|
5
5
|
const client_1 = require("./client");
|
|
6
6
|
const cmux_1 = require("./cmux");
|
|
7
|
-
const copilot_app_1 = require("./copilot-app");
|
|
8
7
|
const herdr_1 = require("./herdr");
|
|
9
8
|
/** The host for this machine's connection. */
|
|
10
9
|
function createShepherdHost(connection, options) {
|
|
11
10
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.shepherd_host_created", message: "opened the Shepherd terminal host", meta: { host: connection.host } });
|
|
12
|
-
if (connection.host === "copilot-app")
|
|
13
|
-
return (0, copilot_app_1.createCopilotAppHost)(connection, { schedule: options.schedule, now: options.now });
|
|
14
11
|
return connection.host === "herdr"
|
|
15
12
|
? (0, herdr_1.createHerdrHost)(connection, { schedule: options.schedule })
|
|
16
13
|
: (0, cmux_1.createCmuxHost)((0, client_1.createCmuxClient)(connection, { agentName: options.agentName }), { now: options.now, schedule: options.schedule });
|
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.1146",
|
|
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.1146",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|
package/package.json
CHANGED
|
@@ -1,138 +0,0 @@
|
|
|
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.HANDOFF_TOOLS = exports.CHILD_RECENT_MS = void 0;
|
|
37
|
-
exports.databaseHold = databaseHold;
|
|
38
|
-
exports.copilotAppHold = copilotAppHold;
|
|
39
|
-
const fs = __importStar(require("node:fs"));
|
|
40
|
-
const path = __importStar(require("node:path"));
|
|
41
|
-
const sqlite_1 = require("../../heart/sqlite");
|
|
42
|
-
const runtime_1 = require("../../nerves/runtime");
|
|
43
|
-
/**
|
|
44
|
-
* Why Shepherd leaves a stopped Copilot app session alone. A session that is waiting on something
|
|
45
|
-
* other than its human (a schedule, a lane it coordinates, a reply it asked for) is not stalled,
|
|
46
|
-
* and one Shepherd already nudged since its human last wrote is not nudged again. Every reason
|
|
47
|
-
* comes from the app's own records, so it holds across daemon restarts and across machines.
|
|
48
|
-
*/
|
|
49
|
-
/** A coordinated session that moved this recently still counts as live work. */
|
|
50
|
-
exports.CHILD_RECENT_MS = 2 * 3_600_000;
|
|
51
|
-
/** Tools that hand work to another session, whose answer the caller then waits for. */
|
|
52
|
-
exports.HANDOFF_TOOLS = new Set([
|
|
53
|
-
"send_session_message", "create_session", "write_agent", "open_pr_session", "open_issue_session", "fork_session", "run_dynamic_workflow",
|
|
54
|
-
]);
|
|
55
|
-
/** What the agent says when it is waiting on something other than its human. */
|
|
56
|
-
const WAITING_WORDS = new RegExp([
|
|
57
|
-
String.raw `\b(?:i'?m|i am|we'?re|still|now|currently|just)\s+(?:waiting|holding)\b`,
|
|
58
|
-
String.raw `\bwaiting\s+(?:on|for|until)\b`,
|
|
59
|
-
String.raw `\b(?:i'?ll|i will|will|going to)\s+(?:wait|hold|check back|report back|pick (?:it|this) up)\b`,
|
|
60
|
-
String.raw `\b(?:until|once|when)\s+(?:it|they|that|those|the \w+|#\d+|\w+'s \w+)\s+(?:lands?|merges?|finish(?:es)?|repl(?:y|ies)|reports?|returns?|completes?|comes? back|is (?:in|done|merged|green))\b`,
|
|
61
|
-
String.raw `\bbackground (?:agents?|tasks?|lanes?|work|shells?|jobs?)\b`,
|
|
62
|
-
String.raw `\blanes? (?:is|are) (?:running|working|under ?way)\b`,
|
|
63
|
-
String.raw `\bon hold\b`,
|
|
64
|
-
].join("|"), "i");
|
|
65
|
-
function hasTable(db, table) {
|
|
66
|
-
return !!db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table);
|
|
67
|
-
}
|
|
68
|
-
function columns(db, table) {
|
|
69
|
-
return new Set(db.prepare(`SELECT name FROM pragma_table_info('${table}')`).all().map(row => row.name));
|
|
70
|
-
}
|
|
71
|
-
/** The app database's reasons to leave the session alone, or null. A database that exists but cannot be read holds. */
|
|
72
|
-
function databaseHold(stateDir, sessionId, now) {
|
|
73
|
-
const file = path.join(stateDir, "data.db");
|
|
74
|
-
if (!fs.existsSync(file))
|
|
75
|
-
return null;
|
|
76
|
-
let db;
|
|
77
|
-
try {
|
|
78
|
-
db = (0, sqlite_1.openDatabase)(file, { readonly: true, fileMustExist: true, timeout: 3_000 });
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
return `the Copilot app database could not be read (${String(error).slice(0, 120)})`;
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
if (hasTable(db, "session_automations")) {
|
|
85
|
-
const automation = db.prepare(`SELECT name FROM session_automations
|
|
86
|
-
WHERE (session_id = ? OR owner_session_id = ?) AND paused_at IS NULL LIMIT 1`).get(sessionId, sessionId);
|
|
87
|
-
if (automation)
|
|
88
|
-
return `it has a session automation${automation.name ? ` ("${automation.name}")` : ""}, which wakes it on schedule`;
|
|
89
|
-
}
|
|
90
|
-
const children = [];
|
|
91
|
-
if (hasTable(db, "workspaces") && hasTable(db, "sessions")) {
|
|
92
|
-
const has = columns(db, "workspaces");
|
|
93
|
-
const by = ["creator_session_id", "coordinating_creator_session_id"].filter(column => has.has(column));
|
|
94
|
-
if (by.length > 0) {
|
|
95
|
-
children.push(...db.prepare(`SELECT s.id, s.title, s.is_running, s.updated_at FROM workspaces w JOIN sessions s ON s.id = w.session_id
|
|
96
|
-
WHERE w.archived_at IS NULL AND s.id != ? AND (${by.map(column => `w.${column} = ?`).join(" OR ")})`).all(sessionId, ...by.map(() => sessionId)));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (hasTable(db, "chat_parent_links") && hasTable(db, "sessions")) {
|
|
100
|
-
const has = columns(db, "chat_parent_links");
|
|
101
|
-
const by = ["parent_session_id", "coordinating_creator_session_id"].filter(column => has.has(column));
|
|
102
|
-
if (by.length > 0) {
|
|
103
|
-
children.push(...db.prepare(`SELECT s.id, s.title, s.is_running, s.updated_at FROM chat_parent_links c JOIN sessions s ON s.id = c.session_id
|
|
104
|
-
WHERE s.archived_at IS NULL AND s.id != ? AND (${by.map(column => `c.${column} = ?`).join(" OR ")})`).all(sessionId, ...by.map(() => sessionId)));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const live = children.filter(child => child.is_running === 1 || now - Date.parse(child.updated_at ?? "") < exports.CHILD_RECENT_MS);
|
|
108
|
-
if (live.length > 0) {
|
|
109
|
-
const named = live.slice(0, 3).map(child => child.title ? `"${child.title.slice(0, 60)}"` : child.id.slice(0, 8)).join(", ");
|
|
110
|
-
return `it coordinates ${live.length} live session${live.length === 1 ? "" : "s"} (${named}${live.length > 3 ? ", …" : ""}) and waits on them`;
|
|
111
|
-
}
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
return `the Copilot app database could not be read (${String(error).slice(0, 120)})`;
|
|
116
|
-
}
|
|
117
|
-
finally {
|
|
118
|
-
db.close();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/** Why Shepherd must not nudge this stopped session, or null when it may judge it. */
|
|
122
|
-
function copilotAppHold(stateDir, sessionId, facts, lastBody, now) {
|
|
123
|
-
const reason = holdReason(stateDir, sessionId, facts, lastBody, now);
|
|
124
|
-
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.shepherd_copilot_app_hold", message: reason ? "Shepherd holds off a stopped Copilot app session" : "no hold on a stopped Copilot app session",
|
|
125
|
-
meta: { session: sessionId.slice(0, 8), held: reason !== null } });
|
|
126
|
-
return reason;
|
|
127
|
-
}
|
|
128
|
-
function holdReason(stateDir, sessionId, facts, lastBody, now) {
|
|
129
|
-
if (facts.shepherdAt !== null && (facts.humanAt === null || facts.humanAt < facts.shepherdAt)) {
|
|
130
|
-
return "Shepherd already nudged it once since its human last wrote; one nudge per stall";
|
|
131
|
-
}
|
|
132
|
-
const handoff = facts.lastTurnTools.find(tool => exports.HANDOFF_TOOLS.has(tool));
|
|
133
|
-
if (handoff)
|
|
134
|
-
return `its last turn handed work to another session (${handoff}), so it is waiting on that reply`;
|
|
135
|
-
if (lastBody && WAITING_WORDS.test(lastBody))
|
|
136
|
-
return "its last message says it is waiting on something other than its human";
|
|
137
|
-
return databaseHold(stateDir, sessionId, now);
|
|
138
|
-
}
|