@ouro.bot/cli 0.1.0-alpha.1130 → 0.1.0-alpha.1132
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/repertoire/tools-app-sessions.js +5 -5
- package/dist/senses/app-sessions/client.js +80 -37
- package/dist/senses/app-sessions/waiting-prompts.js +6 -2
- 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.1132",
|
|
6
|
+
"changes": [
|
|
7
|
+
"app_sessions_restart now restarts the Copilot app through Housesitter (`housesitter restart-copilot --resume --detach`) and reads its state, step and result from `--status`, instead of the old per-Mac keeper. It finds Housesitter at HOUSESITTER_BIN, ~/code/housesitter or on PATH, and says so when it is missing."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1131",
|
|
12
|
+
"changes": [
|
|
13
|
+
"The app-sessions sense now notices a session blocked on the Copilot app's repository-trust card, from the notification claim the app records in its database, and tells the owner once per decision with the session name and repository. It shows as waiting in the sidebar picture and in `ouro status`."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1130",
|
|
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.1132</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -210,7 +210,7 @@ exports.appSessionsResumeTool = {
|
|
|
210
210
|
type: "function",
|
|
211
211
|
function: {
|
|
212
212
|
name: "app_sessions_resume",
|
|
213
|
-
description: "Nudge a stuck or stopped Copilot app session to continue where it left off (the resume message
|
|
213
|
+
description: "Nudge a stuck or stopped Copilot app session to continue where it left off (the resume message Housesitter sends after a restart), with an optional note. Its next reply comes back to you.",
|
|
214
214
|
parameters: {
|
|
215
215
|
type: "object",
|
|
216
216
|
properties: { session: sessionParam, note: { type: "string", description: "Anything to add to the resume message." } },
|
|
@@ -304,12 +304,12 @@ exports.appSessionsRestartTool = {
|
|
|
304
304
|
type: "function",
|
|
305
305
|
function: {
|
|
306
306
|
name: "app_sessions_restart",
|
|
307
|
-
description: "
|
|
307
|
+
description: "Restart the Copilot app and lose no session's work, through Housesitter on this Mac (it restarts the app from outside, as a launchd job). status: the restart in progress or the last one: state, step, start time, result, log. enqueue: start one now; every working session is asked to reach a safe point, the app is quit through its Quit menu (it waits while a person is using the Mac), relaunched, and every session that was working gets a resume message and is checked to have taken a turn. Starting one while another runs is refused. Says so plainly when Housesitter is not on this Mac.",
|
|
308
308
|
parameters: {
|
|
309
309
|
type: "object",
|
|
310
310
|
properties: {
|
|
311
311
|
action: { type: "string", enum: ["status", "enqueue"], description: "Default status." },
|
|
312
|
-
why: { type: "string", description: "enqueue: the reason
|
|
312
|
+
why: { type: "string", description: "enqueue: the reason; it completes \"restarted at 11:40 for …\" in the resume message each session gets." },
|
|
313
313
|
},
|
|
314
314
|
additionalProperties: false,
|
|
315
315
|
},
|
|
@@ -320,12 +320,12 @@ exports.appSessionsRestartTool = {
|
|
|
320
320
|
return await (0, client_1.restartStatus)(clientOptions);
|
|
321
321
|
const why = text(args.why);
|
|
322
322
|
if (!why)
|
|
323
|
-
throw new Error("say why the app needs a restart;
|
|
323
|
+
throw new Error("say why the app needs a restart; every session is told in its resume message");
|
|
324
324
|
return await (0, client_1.restartEnqueue)(why, ctx?.agentName ?? "an agent", clientOptions);
|
|
325
325
|
}),
|
|
326
326
|
summaryKeys: ["action"],
|
|
327
327
|
riskProfile: (args) => text(args.action) === "enqueue"
|
|
328
|
-
? { mutates: "external_side_effect", risk: "high", reason: "
|
|
328
|
+
? { mutates: "external_side_effect", risk: "high", reason: "restarts the owner's Copilot app" }
|
|
329
329
|
: { mutates: "none", risk: "low" },
|
|
330
330
|
};
|
|
331
331
|
exports.appSessionsWatchTool = {
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.realRunFile = exports.
|
|
39
|
+
exports.realRunFile = exports.HOUSESITTER_ENV = exports.SEND_WAIT_MS = void 0;
|
|
40
40
|
exports.defaultStateDir = defaultStateDir;
|
|
41
41
|
exports.assertSessionId = assertSessionId;
|
|
42
42
|
exports.eventLogPath = eventLogPath;
|
|
@@ -62,7 +62,7 @@ exports.resumeAppSession = resumeAppSession;
|
|
|
62
62
|
exports.openAppChat = openAppChat;
|
|
63
63
|
exports.archiveAppSession = archiveAppSession;
|
|
64
64
|
exports.appRunning = appRunning;
|
|
65
|
-
exports.
|
|
65
|
+
exports.findHousesitter = findHousesitter;
|
|
66
66
|
exports.restartEnqueue = restartEnqueue;
|
|
67
67
|
exports.restartStatus = restartStatus;
|
|
68
68
|
const fs = __importStar(require("node:fs"));
|
|
@@ -76,12 +76,13 @@ const runtime_1 = require("../../nerves/runtime");
|
|
|
76
76
|
const copilot_app_1 = require("../shepherd/copilot-app");
|
|
77
77
|
/** The most a send waits: a session whose runtime is not in memory loads first, often for more than 20 s. */
|
|
78
78
|
exports.SEND_WAIT_MS = 120_000;
|
|
79
|
-
|
|
79
|
+
/** Names the Housesitter command to run: the path of its `bin/housesitter.mjs`, or of an executable. */
|
|
80
|
+
exports.HOUSESITTER_ENV = "HOUSESITTER_BIN";
|
|
80
81
|
const REQUEST_WAIT_MS = 30_000;
|
|
81
82
|
const ARCHIVE_WAIT_MS = 60_000;
|
|
82
83
|
const CHAT_ARCHIVE_WAIT_MS = 20_000;
|
|
83
84
|
const RENAME_WAIT_MS = 1_500;
|
|
84
|
-
const
|
|
85
|
+
const HOUSESITTER_WAIT_MS = 30_000;
|
|
85
86
|
const STATUS_TAIL_BYTES = 512 * 1024;
|
|
86
87
|
const EVENT_CHUNK_BYTES = 256 * 1024;
|
|
87
88
|
const MAX_EVENT_BYTES = 8 * 1024 * 1024;
|
|
@@ -150,6 +151,39 @@ function databaseRows(stateDir) {
|
|
|
150
151
|
return [...db.prepare(withHierarchy(workspaces, "workspaces", "w")).all(), ...db.prepare(withHierarchy(CHAT_ROWS, "sessions", "s")).all()];
|
|
151
152
|
});
|
|
152
153
|
}
|
|
154
|
+
function hasTable(db, table) {
|
|
155
|
+
return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The sessions blocked on a repository-trust card. When a session that another session created reaches the card, the app
|
|
159
|
+
* records a `repository_trust` notification claim for it, with the decision id as the watermark, and the claim stays after
|
|
160
|
+
* the person decides. So a claim is an open wait only while the project has no trust grant for the session's host and no
|
|
161
|
+
* newer trust revision. A session nobody coordinates leaves no claim and is not seen here.
|
|
162
|
+
*/
|
|
163
|
+
function repositoryTrustWaits(stateDir) {
|
|
164
|
+
return withDatabase(stateDir, (db) => {
|
|
165
|
+
const waits = new Map();
|
|
166
|
+
if (!["creator_notification_claims", "project_host_trust", "project_trust_revisions", "workspaces", "projects"].every(table => hasTable(db, table)))
|
|
167
|
+
return waits;
|
|
168
|
+
const named = hasColumn(db, "projects", "github_owner") && hasColumn(db, "projects", "github_repo");
|
|
169
|
+
const revision = hasColumn(db, "project_trust_revisions", "local_revision") ? "max(r.revision, r.local_revision)" : "r.revision";
|
|
170
|
+
const claims = db.prepare(`
|
|
171
|
+
SELECT c.watermark, w.session_id, p.name AS project, ${named ? "p.github_owner AS owner, p.github_repo AS repo" : "NULL AS owner, NULL AS repo"},
|
|
172
|
+
EXISTS (SELECT 1 FROM project_host_trust h WHERE h.project_id = w.project_id AND h.host_id = coalesce(w.host_id, 'local')) AS trusted,
|
|
173
|
+
(SELECT ${revision} FROM project_trust_revisions r WHERE r.project_id = w.project_id) AS current
|
|
174
|
+
FROM creator_notification_claims c JOIN workspaces w ON w.id = c.workspace_id LEFT JOIN projects p ON p.id = w.project_id
|
|
175
|
+
WHERE c.kind = 'repository_trust' AND w.session_id IS NOT NULL`).all();
|
|
176
|
+
for (const claim of claims) {
|
|
177
|
+
const decided = Number(/:(\d+)$/.exec(claim.watermark)?.[1]);
|
|
178
|
+
if (claim.trusted || Number.isNaN(decided) || (claim.current ?? 0) > decided)
|
|
179
|
+
continue;
|
|
180
|
+
if ((waits.get(claim.session_id)?.revision ?? -1) >= decided)
|
|
181
|
+
continue;
|
|
182
|
+
waits.set(claim.session_id, { decisionId: claim.watermark, repo: claim.owner && claim.repo ? `${claim.owner}/${claim.repo}` : claim.project ?? "this repository", revision: decided });
|
|
183
|
+
}
|
|
184
|
+
return new Map([...waits].map(([session, { decisionId, repo }]) => [session, { decisionId, repo }]));
|
|
185
|
+
});
|
|
186
|
+
}
|
|
153
187
|
function sessionRecord(stateDir, id) {
|
|
154
188
|
return withDatabase(stateDir, (db) => db.prepare(`
|
|
155
189
|
SELECT s.id, s.archived_at, w.id AS workspace_id, w.workspace_type, w.archived_at AS workspace_archived_at
|
|
@@ -335,13 +369,15 @@ function listAppSessions(options = {}) {
|
|
|
335
369
|
const now = (options.now ?? Date.now)();
|
|
336
370
|
const seen = new Set();
|
|
337
371
|
const rows = [];
|
|
372
|
+
const trusts = repositoryTrustWaits(stateDir);
|
|
338
373
|
for (const row of databaseRows(stateDir)) {
|
|
339
374
|
if (seen.has(row.id) || !SESSION_ID.test(row.id))
|
|
340
375
|
continue;
|
|
341
376
|
seen.add(row.id);
|
|
342
377
|
const facts = cachedTailFacts(stateDir, row.id);
|
|
343
378
|
const isRunning = row.is_running === 1;
|
|
344
|
-
const
|
|
379
|
+
const repositoryTrust = trusts.get(row.id);
|
|
380
|
+
const { state, detail } = repositoryTrust ? { state: "waiting", detail: "waiting for a repository trust decision" } : classify(isRunning, facts, now);
|
|
345
381
|
rows.push({
|
|
346
382
|
id: row.id,
|
|
347
383
|
name: row.name || row.title || (row.workspace_id ? "(unnamed)" : "(unnamed chat)"),
|
|
@@ -362,6 +398,7 @@ function listAppSessions(options = {}) {
|
|
|
362
398
|
updatedAt: row.updated_at,
|
|
363
399
|
lastActivity: facts.lastActivity ?? row.updated_at,
|
|
364
400
|
...(facts.prompt ? { prompt: facts.prompt } : {}),
|
|
401
|
+
...(repositoryTrust ? { repositoryTrust } : {}),
|
|
365
402
|
});
|
|
366
403
|
}
|
|
367
404
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_listed", message: "listed the Copilot app's sessions", meta: { sessions: rows.length } });
|
|
@@ -626,7 +663,7 @@ async function withdrawQueuedMessages(id, prefix, options = {}) {
|
|
|
626
663
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_queue_withdrawn", message: "took back queued messages a newer one replaces", meta: { session: id, found: mine.length, removed } });
|
|
627
664
|
return removed;
|
|
628
665
|
}
|
|
629
|
-
/** The nudge
|
|
666
|
+
/** The nudge Housesitter sends a session that stopped mid-work. */
|
|
630
667
|
function resumePrompt(state, note) {
|
|
631
668
|
return [
|
|
632
669
|
`This session stopped while it was ${state}. Continue exactly where you left off. Anything that was in flight (a shell command, a subagent, a send or a push) was interrupted: re-check its real state before relying on it, and redo it if it did not finish.`,
|
|
@@ -734,50 +771,56 @@ function appRunning(options = {}) {
|
|
|
734
771
|
return false;
|
|
735
772
|
}
|
|
736
773
|
}
|
|
737
|
-
// ---------- the app
|
|
774
|
+
// ---------- restarting the app (Housesitter) ----------
|
|
738
775
|
const realRunFile = (file, args, timeoutMs) => new Promise((resolve) => {
|
|
739
776
|
(0, node_child_process_1.execFile)(file, args, { timeout: timeoutMs, maxBuffer: 8 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
740
777
|
resolve({ code: error ? 1 : 0, stdout: String(stdout), stderr: String(stderr) || (error?.message ?? "") });
|
|
741
778
|
});
|
|
742
779
|
});
|
|
743
780
|
exports.realRunFile = realRunFile;
|
|
744
|
-
/**
|
|
745
|
-
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
if (printed.code !== 0)
|
|
781
|
+
/** Housesitter's command on this Mac: `HOUSESITTER_BIN`, the checkout at `~/code/housesitter`, or `housesitter` on PATH. */
|
|
782
|
+
function findHousesitter(options = {}) {
|
|
783
|
+
const onPath = (process.env.PATH ?? "").split(path.delimiter).filter(Boolean).map(dir => path.join(dir, "housesitter"));
|
|
784
|
+
const candidates = options.housesitterPaths ?? [process.env[exports.HOUSESITTER_ENV] ?? "", path.join(options.homeDir ?? os.homedir(), "code", "housesitter", "bin", "housesitter.mjs"), ...onPath];
|
|
785
|
+
const found = candidates.find(candidate => candidate && fs.existsSync(candidate));
|
|
786
|
+
if (!found)
|
|
751
787
|
return null;
|
|
752
|
-
|
|
753
|
-
const args = block ? block[1].split("\n").map(line => line.trim()).filter(Boolean) : [];
|
|
754
|
-
const script = args.find(arg => arg.endsWith("app-keeper.mjs"));
|
|
755
|
-
const node = printed.stdout.match(/\bprogram = (.+)/)?.[1]?.trim() ?? args[0];
|
|
756
|
-
return script && node ? { node, script } : null;
|
|
788
|
+
return found.endsWith(".mjs") ? { file: process.execPath, args: [found] } : { file: found, args: [] };
|
|
757
789
|
}
|
|
758
|
-
const
|
|
790
|
+
const housesitterMissing = () => ({
|
|
759
791
|
installed: false,
|
|
760
|
-
message: `
|
|
792
|
+
message: `Housesitter is not on this Mac, so the app was not restarted. Clone https://github.com/ourostack/housesitter to ~/code/housesitter, put \`housesitter\` on PATH, or set ${exports.HOUSESITTER_ENV} to its bin/housesitter.mjs.`,
|
|
761
793
|
});
|
|
762
|
-
async function
|
|
794
|
+
async function runHousesitter(args, options) {
|
|
763
795
|
const run = options.runFile ?? exports.realRunFile;
|
|
764
|
-
const
|
|
765
|
-
if (!
|
|
766
|
-
return
|
|
767
|
-
const result = await run(
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
}
|
|
772
|
-
|
|
796
|
+
const command = findHousesitter(options);
|
|
797
|
+
if (!command)
|
|
798
|
+
return housesitterMissing();
|
|
799
|
+
const result = await run(command.file, [...command.args, "restart-copilot", ...args, "--json"], HOUSESITTER_WAIT_MS);
|
|
800
|
+
let output = null;
|
|
801
|
+
try {
|
|
802
|
+
output = JSON.parse(result.stdout);
|
|
803
|
+
}
|
|
804
|
+
catch { /* not JSON: housesitter refused or failed */ }
|
|
805
|
+
// `--status` exits 1 for a failed run and `--detach` for a job launchd would not start; both still answer on stdout.
|
|
806
|
+
const answered = output !== null && ("state" in output || output.ok === false);
|
|
807
|
+
if (!output || (result.code !== 0 && !answered))
|
|
808
|
+
throw new Error(`housesitter failed: ${(result.stderr || result.stdout).trim().slice(0, 300)}`);
|
|
809
|
+
return { installed: true, output };
|
|
810
|
+
}
|
|
811
|
+
/** Restart the app now, as a launchd job that outlives the app: Housesitter asks working sessions to reach a safe point, quits the app through its Quit menu (waiting while a person is using the Mac), relaunches it and resumes every session that was working. Read the outcome with {@link restartStatus}. */
|
|
773
812
|
async function restartEnqueue(why, by, options = {}) {
|
|
774
|
-
const result = await
|
|
775
|
-
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_restart_enqueued", message: "asked
|
|
776
|
-
|
|
813
|
+
const result = await runHousesitter(["--resume", "--detach", "--why", `${why} (asked by ${by})`], options);
|
|
814
|
+
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_restart_enqueued", message: "asked housesitter to restart the app", meta: { installed: result.installed, why } });
|
|
815
|
+
if (!result.installed)
|
|
816
|
+
return result;
|
|
817
|
+
if (result.output.ok === false)
|
|
818
|
+
throw new Error(`housesitter did not start the restart: ${String(result.output.error ?? "no reason given")}`);
|
|
819
|
+
return { installed: true, request: result.output };
|
|
777
820
|
}
|
|
778
|
-
/** The
|
|
821
|
+
/** The restart in progress or the last one: state (running, done, failed, none), step, start time, result, log. */
|
|
779
822
|
async function restartStatus(options = {}) {
|
|
780
|
-
const result = await
|
|
781
|
-
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_restart_status", message: "read
|
|
823
|
+
const result = await runHousesitter(["--status"], options);
|
|
824
|
+
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_restart_status", message: "read housesitter's restart status", meta: { installed: result.installed } });
|
|
782
825
|
return result.installed ? { installed: true, status: result.output } : result;
|
|
783
826
|
}
|
|
@@ -44,7 +44,7 @@ const owner_notice_1 = require("../shepherd/owner-notice");
|
|
|
44
44
|
const store_1 = require("./store");
|
|
45
45
|
const waiting_status_1 = require("./waiting-status");
|
|
46
46
|
/**
|
|
47
|
-
* A session frozen on a permission prompt looks idle from outside, and only the person can answer it in the app. The
|
|
47
|
+
* A session frozen on a permission prompt, or on a repository-trust card, looks idle from outside, and only the person can answer it in the app. The
|
|
48
48
|
* snapshot already reads every session's history each minute, so noticing is deterministic and costs no model turn:
|
|
49
49
|
* a prompt open for more than two minutes is told to the owner once, in one plain message, through the same proactive
|
|
50
50
|
* path Shepherd's owner notices use. A prompt older than a day is shown in `ouro status` but never announced: it is
|
|
@@ -57,11 +57,15 @@ 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 in the sidebar.
|
|
60
|
+
/** The open permission prompts and repository-trust decisions 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
|
+
}
|
|
65
69
|
if (!row.prompt)
|
|
66
70
|
continue;
|
|
67
71
|
const stamped = Date.parse(row.prompt.at ?? "");
|
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.1132",
|
|
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.1132",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|