@ouro.bot/cli 0.1.0-alpha.1158 → 0.1.0-alpha.1159
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/senses/app-sessions/app-interface.js +10 -2
- package/dist/senses/app-sessions/digest.js +7 -1
- package/dist/senses/app-sessions/sense.js +1 -1
- package/dist/senses/app-sessions/size-watch.js +186 -40
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
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.1159",
|
|
6
|
+
"changes": [
|
|
7
|
+
"The Copilot app size watch flags every local session whose history is over 500 MB, including ones the sidebar no longer lists, and keeps them flagged after they are archived. It asks a running giant and its coordinator again, with immediate delivery, each time the history grows by half. It archives a flagged session (reversibly, keeping its worktree) once it has been idle 30 minutes after its last ask, or at once, largest first, when swap passes 8 GB or free memory falls under 1 GB, and tells its coordinator where it left off. The status digest lists each archive."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1158",
|
|
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.1159</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -43,6 +43,7 @@ exports.createSession = createSession;
|
|
|
43
43
|
exports.answerSessionInput = answerSessionInput;
|
|
44
44
|
exports.respondToSessionPlan = respondToSessionPlan;
|
|
45
45
|
exports.archiveSession = archiveSession;
|
|
46
|
+
exports.archiveRow = archiveRow;
|
|
46
47
|
exports.navigateTo = navigateTo;
|
|
47
48
|
exports.saveSessionAutomation = saveSessionAutomation;
|
|
48
49
|
exports.getSessionAutomation = getSessionAutomation;
|
|
@@ -280,13 +281,20 @@ async function archiveSession(agentRoot, id, options = {}, ownerAsked = false) {
|
|
|
280
281
|
throw new Error(`session ${row.id} was not created by this agent, so it will not archive it unless the owner asked for it or it is oversize and a newer session names it as handed off (yours: ${Object.keys(made).join(", ") || "none"})`);
|
|
281
282
|
}
|
|
282
283
|
}
|
|
284
|
+
return archiveRow(agentRoot, row, reason, options);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Ask the app to archive a session the caller has already decided may go, and log it when `reason` is set. `keepWorktree`
|
|
288
|
+
* leaves a worktree on disk, so an archive nobody asked for in person loses no uncommitted work.
|
|
289
|
+
*/
|
|
290
|
+
async function archiveRow(agentRoot, row, reason, options = {}, extra = {}) {
|
|
283
291
|
const archived = row.workspaceId
|
|
284
|
-
? await ask({ type: "archive_workspace", workspace_id: row.workspaceId, delete_worktree: row.workspaceType === "worktree" }, (reply, requestId) => (reply.request_id === requestId ? (reply.type === "workspace_archived" ? "ok" : "fail") : "ignore"), ARCHIVE_WAIT_MS, options)
|
|
292
|
+
? await ask({ type: "archive_workspace", workspace_id: row.workspaceId, delete_worktree: row.workspaceType === "worktree" && !extra.keepWorktree }, (reply, requestId) => (reply.request_id === requestId ? (reply.type === "workspace_archived" ? "ok" : "fail") : "ignore"), ARCHIVE_WAIT_MS, options)
|
|
285
293
|
: await ask({ type: "archive_session", session_id: row.id }, (reply, requestId) => (reply.type === "general_chat_sessions_changed" ? "ok" : reply.request_id === requestId ? "fail" : "ignore"), ARCHIVE_WAIT_MS, options);
|
|
286
294
|
if (archived.ok) {
|
|
287
295
|
(0, store_1.removeProbe)(agentRoot, row.id);
|
|
288
296
|
if (reason) {
|
|
289
|
-
(0, store_1.addArchiveLog)(agentRoot, { id: row.id, name: row.name, at: new Date(options.now?.() ?? Date.now()).toISOString(), reason });
|
|
297
|
+
(0, store_1.addArchiveLog)(agentRoot, { id: row.id, name: row.name, at: new Date(options.now?.() ?? Date.now()).toISOString(), reason, ...(extra.note ? { note: extra.note } : {}) });
|
|
290
298
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_archived_not_created", message: "archived a session this agent did not create", meta: { session: row.id, reason } });
|
|
291
299
|
}
|
|
292
300
|
}
|
|
@@ -66,6 +66,12 @@ exports.SCAN_BUDGET_BYTES = 1024 * 1024 * 1024;
|
|
|
66
66
|
const INCREMENTAL_SCAN_BYTES = 4 * 1024 * 1024;
|
|
67
67
|
const WORKING_LISTED = 8;
|
|
68
68
|
const NAME_MAX = 60;
|
|
69
|
+
const ARCHIVE_REASONS = {
|
|
70
|
+
"owner-asked": "you asked",
|
|
71
|
+
"handed-off": "handed off to a successor",
|
|
72
|
+
"oversize-idle": "over the size limit and idle 30 min after the hand-off ask",
|
|
73
|
+
"memory-pressure": "over the size limit and idle while memory ran short",
|
|
74
|
+
};
|
|
69
75
|
exports.EMPTY_DIGEST_STATE = { focus: {}, cards: {}, firstSeen: {}, pushed: {}, lastPushAt: 0, seeded: false };
|
|
70
76
|
function digestFiles(agentRoot) {
|
|
71
77
|
const dir = (0, store_1.appSessionsStateDir)(agentRoot);
|
|
@@ -159,7 +165,7 @@ async function buildDigest(input) {
|
|
|
159
165
|
}
|
|
160
166
|
const recentArchives = (0, store_1.readArchiveLog)(input.agentRoot)
|
|
161
167
|
.filter(entry => input.now - Date.parse(entry.at) < exports.CARD_WINDOW_MS)
|
|
162
|
-
.map(entry => ({ name: cut(entry.name, NAME_MAX), reason: entry.reason
|
|
168
|
+
.map(entry => ({ name: cut(entry.name, NAME_MAX), reason: `${ARCHIVE_REASONS[entry.reason]}${entry.note ? ` (${entry.note})` : ""}` }));
|
|
163
169
|
const digest = {
|
|
164
170
|
at: new Date(input.now).toISOString(),
|
|
165
171
|
appRunning: input.appRunning,
|
|
@@ -254,7 +254,7 @@ function startAppSessionsSense(options) {
|
|
|
254
254
|
waitingPoll = waitingPoll.then(() => recordSnapshot(agentRoot, client, now())).then(taken => (0, waiting_prompts_1.noticeWaitingPrompts)(agentRoot, taken, { notify: notifyOwner, now: now() })).catch((error) => {
|
|
255
255
|
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.app_sessions_waiting_error", message: "could not check the sessions waiting on a prompt", meta: { error: error.message } });
|
|
256
256
|
});
|
|
257
|
-
sizePoll = sizePoll.then(async () => (0, size_watch_1.noticeOversizedSessions)(agentRoot, await (0, client_1.listAppSessions)({ ...client, now: () => now() }), { notify: notifyOwner, now: now(), client })).then(() => undefined).catch((error) => {
|
|
257
|
+
sizePoll = sizePoll.then(async () => (0, size_watch_1.noticeOversizedSessions)(agentRoot, await (0, client_1.listAppSessions)({ ...client, now: () => now() }), { notify: notifyOwner, now: now(), client, ...(options.memory ? { memory: options.memory } : {}) })).then(() => undefined).catch((error) => {
|
|
258
258
|
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.app_sessions_oversize_error", message: "could not check the sessions' history sizes", meta: { error: error.message } });
|
|
259
259
|
});
|
|
260
260
|
cancelSnapshot = schedule(snapshotTick, exports.SNAPSHOT_MS);
|
|
@@ -33,9 +33,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.neverResume = exports.readOversize = exports.OVERSIZE_BYTES = void 0;
|
|
36
|
+
exports.shortOfMemory = exports.neverResume = exports.readOversize = exports.PRESSURE_FREE_BYTES = exports.PRESSURE_SWAP_BYTES = exports.IDLE_ARCHIVE_MS = exports.RENUDGE_GROWTH = exports.OVERSIZE_BYTES = void 0;
|
|
37
37
|
exports.handoffNudge = handoffNudge;
|
|
38
|
+
exports.archivedNote = archivedNote;
|
|
39
|
+
exports.readMemory = readMemory;
|
|
40
|
+
exports.whereItLeftOff = whereItLeftOff;
|
|
38
41
|
exports.noticeOversizedSessions = noticeOversizedSessions;
|
|
42
|
+
const node_child_process_1 = require("node:child_process");
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
44
|
+
const os = __importStar(require("node:os"));
|
|
39
45
|
const path = __importStar(require("node:path"));
|
|
40
46
|
const runtime_1 = require("../../nerves/runtime");
|
|
41
47
|
const owner_notice_1 = require("../shepherd/owner-notice");
|
|
@@ -44,12 +50,25 @@ const client_1 = require("./client");
|
|
|
44
50
|
const store_1 = require("./store");
|
|
45
51
|
/**
|
|
46
52
|
* A session's event log is loaded whole into memory when the app resumes it, and a log of several GB (almost all of it
|
|
47
|
-
* inline images) has frozen the machine.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
53
|
+
* inline images) has frozen the machine. Each minute, with no model turn, every local session's `events.jsonl` is
|
|
54
|
+
* measured, listed in the sidebar or not, and one over the limit is flagged never-resume. A listed one is asked to hand
|
|
55
|
+
* off to a fresh successor: its coordinator, and the session itself while it runs, are asked again each time its history
|
|
56
|
+
* grows by half, because one ask is easily ignored. A flagged session that then sits idle for 30 minutes (or at once,
|
|
57
|
+
* when memory runs short) is archived through the app, reversibly and keeping its worktree, to free its runtime, and its
|
|
58
|
+
* coordinator is told where it left off. A session that is not running and has no smaller coordinator is never messaged,
|
|
59
|
+
* because the message would reload it; the owner is told instead.
|
|
51
60
|
*/
|
|
52
61
|
exports.OVERSIZE_BYTES = 500 * 1024 * 1024;
|
|
62
|
+
/** A flagged session that keeps running is asked again each time its history reaches this multiple of its size at the last ask. */
|
|
63
|
+
exports.RENUDGE_GROWTH = 1.5;
|
|
64
|
+
/** A flagged session idle this long after its last ask is archived. */
|
|
65
|
+
exports.IDLE_ARCHIVE_MS = 30 * 60_000;
|
|
66
|
+
/** Swap use above this, or free memory below the next, means the machine is short of memory: idle giants go at once. */
|
|
67
|
+
exports.PRESSURE_SWAP_BYTES = 8 * 1024 ** 3;
|
|
68
|
+
exports.PRESSURE_FREE_BYTES = 1024 ** 3;
|
|
69
|
+
/** How far back from the end of a log to look for where the session last pushed, in chunks. */
|
|
70
|
+
const PUSH_SCAN_BYTES = 64 * 1024 * 1024;
|
|
71
|
+
const PUSH_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
53
72
|
const stateFile = (agentRoot) => path.join((0, store_1.appSessionsStateDir)(agentRoot), "oversize.json");
|
|
54
73
|
const readOversize = (agentRoot) => (0, store_1.readJson)(stateFile(agentRoot), { sessions: {} }).sessions;
|
|
55
74
|
exports.readOversize = readOversize;
|
|
@@ -57,53 +76,180 @@ exports.readOversize = readOversize;
|
|
|
57
76
|
const neverResume = (agentRoot) => Object.keys((0, exports.readOversize)(agentRoot));
|
|
58
77
|
exports.neverResume = neverResume;
|
|
59
78
|
const mb = (bytes) => bytes >= 1024 ** 3 ? `${(bytes / 1024 ** 3).toFixed(1)} GB` : `${Math.round(bytes / 1024 ** 2)} MB`;
|
|
60
|
-
function handoffNudge(name, bytes) {
|
|
61
|
-
|
|
79
|
+
function handoffNudge(name, bytes, asked = 0, askedAtBytes) {
|
|
80
|
+
const again = asked ? ` This is ask ${asked + 1}${askedAtBytes ? `: it was ${mb(askedAtBytes)} at the last one and is still growing` : ""}.` : "";
|
|
81
|
+
return `The session "${(0, owner_notice_1.plain)(name, 60)}" has a ${mb(bytes)} history, over the ${mb(exports.OVERSIZE_BYTES)} limit: the app loads all of it into memory every time that session resumes, and a few like it froze this Mac.${again} Please hand it off now: write a checkpoint of its purpose and open work, start a fresh successor session that reads that checkpoint plus the tail of the old log, then archive the old one. This goes to the session and to its coordinator; the coordinator starts the successor when there is one. Once it has been idle for ${exports.IDLE_ARCHIVE_MS / 60_000} minutes it is archived for you (reversibly) to free its memory. Keep images out of chat (save screenshots and art as files and link the path): inline images are nearly all of the size.`;
|
|
62
82
|
}
|
|
63
|
-
|
|
83
|
+
function archivedNote(name, id, bytes, where) {
|
|
84
|
+
return `I archived the session "${(0, owner_notice_1.plain)(name, 60)}" (${id}) to free memory: its ${mb(bytes)} history is over the ${mb(exports.OVERSIZE_BYTES)} limit and it sat idle after the hand-off ask. The archive is reversible from the app, and its worktree was kept. Where it left off: ${where}. If its work is not finished, start a fresh successor session from there and the tail of its log (~/.copilot/session-state/${id}/events.jsonl).`;
|
|
85
|
+
}
|
|
86
|
+
/** Swap in use and free memory: `sysctl vm.swapusage` on macOS, `/proc/meminfo` elsewhere. An unreadable swap counts as none. */
|
|
87
|
+
function readMemory(platform = process.platform, read = what => what === "swapusage"
|
|
88
|
+
? (0, node_child_process_1.execFileSync)("sysctl", ["-n", "vm.swapusage"], { encoding: "utf8", timeout: 5_000 })
|
|
89
|
+
: fs.readFileSync("/proc/meminfo", "utf8")) {
|
|
90
|
+
let swapUsedBytes = 0;
|
|
91
|
+
try {
|
|
92
|
+
if (platform === "darwin")
|
|
93
|
+
swapUsedBytes = Number(/used = ([\d.]+)M/.exec(read("swapusage"))?.[1] ?? 0) * 1024 ** 2;
|
|
94
|
+
else {
|
|
95
|
+
const info = read("meminfo");
|
|
96
|
+
const kb = (key) => Number(new RegExp(`^${key}:\\s+(\\d+)`, "m").exec(info)?.[1] ?? 0) * 1024;
|
|
97
|
+
swapUsedBytes = kb("SwapTotal") - kb("SwapFree");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
swapUsedBytes = 0;
|
|
102
|
+
}
|
|
103
|
+
return { swapUsedBytes, freeBytes: os.freemem() };
|
|
104
|
+
}
|
|
105
|
+
const shortOfMemory = (memory) => memory.swapUsedBytes > exports.PRESSURE_SWAP_BYTES || memory.freeBytes < exports.PRESSURE_FREE_BYTES;
|
|
106
|
+
exports.shortOfMemory = shortOfMemory;
|
|
107
|
+
const sessionsRoot = (client) => path.dirname(path.dirname((0, client_1.eventLogPath)("x", client)));
|
|
108
|
+
/** Every local session's history size, whether or not the sidebar lists it. */
|
|
109
|
+
function localLogSizes(client) {
|
|
110
|
+
const sizes = new Map();
|
|
111
|
+
let names;
|
|
112
|
+
try {
|
|
113
|
+
names = fs.readdirSync(sessionsRoot(client));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return sizes;
|
|
117
|
+
}
|
|
118
|
+
for (const name of names)
|
|
119
|
+
sizes.set(name, (0, client_1.eventLogSize)(name, client));
|
|
120
|
+
return sizes;
|
|
121
|
+
}
|
|
122
|
+
/** The name the session saved for itself, for one the sidebar no longer lists. */
|
|
123
|
+
function savedName(id, client) {
|
|
124
|
+
try {
|
|
125
|
+
const head = fs.readFileSync(path.join(sessionsRoot(client), id, "workspace.yaml"), "utf8").slice(0, 4096);
|
|
126
|
+
return /^name: ['"]?(.*?)['"]?$/m.exec(head)?.[1] || null;
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const last = (text, pattern) => text.match(pattern)?.at(-1);
|
|
133
|
+
/**
|
|
134
|
+
* Where a session left off, for its coordinator: its workspace branch, and the last `git push` and pull request in the
|
|
135
|
+
* end of its history (credentials in a push URL are cut). Only the last 64 MB is read, a chunk at a time.
|
|
136
|
+
*/
|
|
137
|
+
function whereItLeftOff(row, client = {}) {
|
|
138
|
+
let push;
|
|
139
|
+
let pr;
|
|
140
|
+
let fd = null;
|
|
141
|
+
try {
|
|
142
|
+
fd = fs.openSync((0, client_1.eventLogPath)(row.id, client), "r");
|
|
143
|
+
const size = fs.fstatSync(fd).size;
|
|
144
|
+
for (let end = size; end > 0 && size - end < PUSH_SCAN_BYTES && !(push && pr); end -= PUSH_CHUNK_BYTES) {
|
|
145
|
+
const start = Math.max(0, end - PUSH_CHUNK_BYTES - 512);
|
|
146
|
+
const buffer = Buffer.alloc(end - start);
|
|
147
|
+
fs.readSync(fd, buffer, 0, buffer.length, start);
|
|
148
|
+
const text = buffer.toString("utf8");
|
|
149
|
+
push ??= last(text, /git push\b[^"\\\n]{0,200}/g);
|
|
150
|
+
pr ??= last(text, /https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+/g);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// No log: say what the sidebar knows.
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
if (fd !== null)
|
|
158
|
+
fs.closeSync(fd);
|
|
159
|
+
}
|
|
160
|
+
const parts = [
|
|
161
|
+
...(row.branch ? [`branch ${row.branch}${row.projectRepo ? ` in ${row.projectRepo}` : ""}`] : []),
|
|
162
|
+
...(push ? [`last push \`${push.split(/\s(?:2>|\||;|&&)/)[0].replace(/\/\/[^/@\s]*@/, "//").trim()}\``] : []),
|
|
163
|
+
...(pr ? [`last pull request ${pr}`] : []),
|
|
164
|
+
];
|
|
165
|
+
return parts.length ? parts.join("; ") : "no push or pull request in the end of its history";
|
|
166
|
+
}
|
|
167
|
+
const failed = (error) => ({ ok: false, frame: null, error: error.message });
|
|
168
|
+
/** Flag every over-limit session, ask again as one grows, and archive the idle ones. Returns what this pass did. */
|
|
64
169
|
async function noticeOversizedSessions(agentRoot, rows, deps) {
|
|
65
|
-
const
|
|
66
|
-
const send = deps.send ?? ((id, text) => (0, app_interface_1.deliverMessage)(id, text, "
|
|
170
|
+
const client = deps.client;
|
|
171
|
+
const send = deps.send ?? ((id, text) => (0, app_interface_1.deliverMessage)(id, text, "immediate", deps.client));
|
|
172
|
+
const archive = deps.archive ?? (async (row, reason, note) => (await (0, app_interface_1.archiveRow)(agentRoot, row, reason, client, { note, keepWorktree: true })).ok === true);
|
|
173
|
+
const at = new Date(deps.now).toISOString();
|
|
67
174
|
const before = (0, exports.readOversize)(agentRoot);
|
|
68
|
-
const sizes =
|
|
69
|
-
const
|
|
70
|
-
const bigIds = new Set(big.map(row => row.id));
|
|
175
|
+
const sizes = localLogSizes(client);
|
|
176
|
+
const listed = new Map(rows.filter(row => !row.remote).map(row => [row.id, row]));
|
|
71
177
|
const next = {};
|
|
178
|
+
for (const [id, bytes] of sizes) {
|
|
179
|
+
if (bytes <= exports.OVERSIZE_BYTES)
|
|
180
|
+
continue;
|
|
181
|
+
const { unlisted: _unlisted, ...kept } = before[id] ?? {};
|
|
182
|
+
const row = listed.get(id);
|
|
183
|
+
next[id] = { ...kept, bytes, name: row?.name ?? kept.name ?? savedName(id, client) ?? id, ...(row ? {} : { unlisted: true }) };
|
|
184
|
+
}
|
|
185
|
+
const big = [...listed.values()].filter(row => next[row.id]);
|
|
186
|
+
// A coordinator that is itself a giant is only messaged while it runs, since a message would reload it.
|
|
187
|
+
const reachable = (id) => {
|
|
188
|
+
const row = id ? listed.get(id) : undefined;
|
|
189
|
+
return row && (row.isRunning || !next[row.id]) ? row : undefined;
|
|
190
|
+
};
|
|
72
191
|
let nudged = 0;
|
|
73
|
-
const
|
|
192
|
+
const ownerRows = [];
|
|
74
193
|
for (const row of big) {
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
194
|
+
const entry = next[row.id];
|
|
195
|
+
const due = row.isRunning ? entry.nudgedBytes === undefined || entry.bytes >= entry.nudgedBytes * exports.RENUDGE_GROWTH : !entry.nudgedAt;
|
|
196
|
+
if (!due)
|
|
197
|
+
continue;
|
|
198
|
+
const boss = reachable(row.coordinatingCreatorSessionId);
|
|
199
|
+
const to = [...(boss && boss.id !== row.id ? [boss.id] : []), ...(row.isRunning ? [row.id] : [])];
|
|
200
|
+
if (!to.length) {
|
|
201
|
+
ownerRows.push(row);
|
|
79
202
|
continue;
|
|
80
|
-
const parent = rows.find(other => other.id === row.coordinatingCreatorSessionId);
|
|
81
|
-
const recipient = parent && !bigIds.has(parent.id) ? parent.id : row.isRunning ? row.id : null;
|
|
82
|
-
if (recipient) {
|
|
83
|
-
const sent = await send(recipient, handoffNudge(row.name, bytes)).catch((error) => ({ ok: false, frame: null, error: error.message }));
|
|
84
|
-
if (!sent.ok)
|
|
85
|
-
continue;
|
|
86
|
-
entry.nudgedAt = new Date(deps.now).toISOString();
|
|
87
|
-
entry.to = recipient;
|
|
88
|
-
nudged += 1;
|
|
89
203
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
204
|
+
// An entry from before asks were counted had one ask.
|
|
205
|
+
const asked = entry.nudges ?? (entry.nudgedAt ? 1 : 0);
|
|
206
|
+
const text = handoffNudge(row.name, entry.bytes, asked, entry.nudgedBytes);
|
|
207
|
+
const reached = [];
|
|
208
|
+
for (const id of to)
|
|
209
|
+
if ((await send(id, text).catch(failed)).ok)
|
|
210
|
+
reached.push(id);
|
|
211
|
+
if (!reached.length)
|
|
212
|
+
continue;
|
|
213
|
+
Object.assign(entry, { nudgedAt: at, nudgedBytes: entry.bytes, nudges: asked + 1, to: reached.join(",") });
|
|
214
|
+
nudged += 1;
|
|
215
|
+
}
|
|
216
|
+
if (ownerRows.length) {
|
|
217
|
+
const lines = ownerRows.map(row => `- "${(0, owner_notice_1.plain)(row.name, 60)}" (${mb(next[row.id].bytes)})`);
|
|
218
|
+
const outcome = await deps.notify(`These sessions have histories over ${mb(exports.OVERSIZE_BYTES)} and cannot be nudged without reloading them. They need a hand-off to a fresh successor session (checkpoint, tail, archive); keep images out of chat:\n${lines.join("\n")}`, ownerRows.map(row => `oversize:${row.id}`));
|
|
219
|
+
for (const row of ownerRows) {
|
|
220
|
+
next[row.id].to = "owner";
|
|
221
|
+
if (outcome !== "pending") {
|
|
222
|
+
Object.assign(next[row.id], { nudgedAt: at, nudgedBytes: next[row.id].bytes, nudges: (next[row.id].nudges ?? 0) + 1 });
|
|
223
|
+
nudged += 1;
|
|
224
|
+
}
|
|
94
225
|
}
|
|
95
226
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
227
|
+
const quiet = big.filter(row => !row.isRunning && row.state !== "waiting");
|
|
228
|
+
const pressed = quiet.length > 0 && (0, exports.shortOfMemory)((deps.memory ?? readMemory)());
|
|
229
|
+
const idle = quiet.filter(row => {
|
|
230
|
+
const entry = next[row.id];
|
|
231
|
+
if (pressed)
|
|
232
|
+
return true;
|
|
233
|
+
if (!entry.nudgedAt)
|
|
234
|
+
return false;
|
|
235
|
+
return deps.now - Math.max(Date.parse(entry.nudgedAt), Date.parse(row.lastActivity ?? "") || 0) >= exports.IDLE_ARCHIVE_MS;
|
|
236
|
+
}).sort((a, b) => next[b.id].bytes - next[a.id].bytes);
|
|
237
|
+
let archived = 0;
|
|
238
|
+
for (const row of idle) {
|
|
239
|
+
const entry = next[row.id];
|
|
240
|
+
const where = whereItLeftOff(row, client);
|
|
241
|
+
const reason = pressed ? "memory-pressure" : "oversize-idle";
|
|
242
|
+
if (!(await archive(row, reason, `${mb(entry.bytes)}; ${where}`).catch(() => false)))
|
|
243
|
+
continue;
|
|
244
|
+
entry.archivedAt = at;
|
|
245
|
+
archived += 1;
|
|
246
|
+
const boss = reachable(row.coordinatingCreatorSessionId);
|
|
247
|
+
if (boss && boss.id !== row.id)
|
|
248
|
+
await send(boss.id, archivedNote(row.name, row.id, entry.bytes, where)).catch(failed);
|
|
249
|
+
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_oversize_archived", message: "archived an idle Copilot app session whose history is over the limit", meta: { session: row.id, bytes: entry.bytes, reason } });
|
|
104
250
|
}
|
|
105
251
|
(0, store_1.writeJson)(stateFile(agentRoot), { sessions: next });
|
|
106
252
|
if (nudged)
|
|
107
253
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_oversize_nudge", message: "asked for a hand-off of Copilot app sessions whose history is over the limit", meta: { sessions: nudged } });
|
|
108
|
-
return nudged;
|
|
254
|
+
return { nudged, archived };
|
|
109
255
|
}
|
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.1159",
|
|
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.1159",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|