@ouro.bot/cli 0.1.0-alpha.1007 → 0.1.0-alpha.1010

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": "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.1010",
6
+ "changes": [
7
+ "New app-sessions sense: with senses[\"app-sessions\"].enabled in agent.json, an agent can list, read, message, resume, open and archive this machine's GitHub Copilot app sessions, ask the Mac's app keeper for a courtesy restart, and hear back from the sessions it writes to."
8
+ ]
9
+ },
4
10
  {
5
11
  "version": "0.1.0-alpha.1007",
6
12
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1007",
2
+ "runtimeVersion": "0.1.0-alpha.1010",
3
3
  "bundleSchemaVersion": 3,
4
4
  "lastUpdated": "2026-09-03T00:00:00.000Z"
5
5
  }
@@ -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.1007</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1010</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -59,7 +59,7 @@ function defaultLoggingForProcess(processName) {
59
59
  sinks: ["terminal", "ndjson"],
60
60
  };
61
61
  }
62
- if (processName === "bluebubbles" || processName === "mail" || processName === "voice" || processName === "shepherd") {
62
+ if (processName === "bluebubbles" || processName === "mail" || processName === "voice" || processName === "shepherd" || processName === "app-sessions") {
63
63
  return {
64
64
  level: "warn",
65
65
  sinks: ["terminal", "ndjson"],
@@ -45,6 +45,7 @@ const provider_credentials_1 = require("../provider-credentials");
45
45
  const sense_truth_1 = require("../sense-truth");
46
46
  const machine_identity_1 = require("../machine-identity");
47
47
  const shepherd_config_1 = require("../shepherd-config");
48
+ const store_1 = require("../../senses/app-sessions/store");
48
49
  const process_manager_1 = require("./process-manager");
49
50
  const config_1 = require("../../a2a/config");
50
51
  const DEFAULT_TEAMS_PORT = 3978;
@@ -65,6 +66,7 @@ function defaultSenses() {
65
66
  telegram: { ...identity_1.DEFAULT_AGENT_SENSES.telegram },
66
67
  workbench: { ...identity_1.DEFAULT_AGENT_SENSES.workbench },
67
68
  shepherd: { ...identity_1.DEFAULT_AGENT_SENSES.shepherd },
69
+ "app-sessions": { ...identity_1.DEFAULT_AGENT_SENSES["app-sessions"] },
68
70
  };
69
71
  }
70
72
  function readAgentSenses(agentJsonPath) {
@@ -104,7 +106,7 @@ function readAgentSenses(agentJsonPath) {
104
106
  && !Array.isArray(rawMcpServers)
105
107
  && Object.prototype.hasOwnProperty.call(rawMcpServers, "ouro_workbench");
106
108
  const workbenchHasStaleBundleEntry = workbenchSensePresent || workbenchMcpPresent;
107
- for (const sense of ["cli", "teams", "bluebubbles", "mail", "voice", "a2a", "telegram", "workbench", "shepherd"]) {
109
+ for (const sense of ["cli", "teams", "bluebubbles", "mail", "voice", "a2a", "telegram", "workbench", "shepherd", "app-sessions"]) {
108
110
  const rawSense = rawSenses[sense];
109
111
  if (!rawSense || typeof rawSense !== "object" || Array.isArray(rawSense)) {
110
112
  continue;
@@ -183,6 +185,7 @@ function senseFactsFromRuntimeConfig(agent, senses, runtimeConfig, machineRuntim
183
185
  telegram: { configured: false, detail: "not enabled in agent.json" },
184
186
  workbench: { configured: false, detail: "not enabled in agent.json" },
185
187
  shepherd: { configured: false, detail: "not enabled in agent.json" },
188
+ "app-sessions": { configured: false, detail: "not enabled in agent.json" },
186
189
  };
187
190
  const payload = runtimeConfig.ok ? runtimeConfig.config : {};
188
191
  const unavailableDetail = runtimeConfigUnavailableDetail(agent, runtimeConfig);
@@ -362,6 +365,9 @@ function senseFactsFromRuntimeConfig(agent, senses, runtimeConfig, machineRuntim
362
365
  ? { configured: false, detail: runtimeConfigUnavailableDetail(agent, machineRuntimeConfig) }
363
366
  : (0, shepherd_config_1.shepherdConfigFacts)(machinePayload);
364
367
  }
368
+ if (senses["app-sessions"].enabled) {
369
+ base["app-sessions"] = { configured: true, detail: "this machine's GitHub Copilot app" };
370
+ }
365
371
  if (workbenchHasStaleBundleEntry || senses.workbench.enabled) {
366
372
  base.workbench = {
367
373
  configured: false,
@@ -405,7 +411,7 @@ function parseSenseSnapshotName(name) {
405
411
  if (parts.length !== 2)
406
412
  return null;
407
413
  const [agent, sense] = parts;
408
- if (sense !== "teams" && sense !== "bluebubbles" && sense !== "mail" && sense !== "voice" && sense !== "a2a" && sense !== "telegram" && sense !== "shepherd")
414
+ if (sense !== "teams" && sense !== "bluebubbles" && sense !== "mail" && sense !== "voice" && sense !== "a2a" && sense !== "telegram" && sense !== "shepherd" && sense !== "app-sessions")
409
415
  return null;
410
416
  return { agent, sense };
411
417
  }
@@ -427,6 +433,8 @@ function managedSenseEntry(sense) {
427
433
  return "senses/telegram-entry.js";
428
434
  if (sense === "shepherd")
429
435
  return "senses/shepherd-entry.js";
436
+ if (sense === "app-sessions")
437
+ return "senses/app-sessions-entry.js";
430
438
  return "senses/mail-entry.js";
431
439
  }
432
440
  function runtimeCredentialBootstrapFor(agent) {
@@ -607,7 +615,7 @@ class DaemonSenseManager {
607
615
  }));
608
616
  this.initiallyUnmanagedShepherdOwners = new Set([...this.contexts.entries()].filter(([, context]) => !context.senses.shepherd.enabled).map(([agent]) => agent));
609
617
  const managedSenseAgents = [...this.contexts.entries()].flatMap(([agent, context]) => {
610
- return ["teams", "bluebubbles", "mail", "voice", "a2a", "telegram", "shepherd"]
618
+ return ["teams", "bluebubbles", "mail", "voice", "a2a", "telegram", "shepherd", "app-sessions"]
611
619
  .filter((sense) => context.senses[sense].enabled)
612
620
  .map((sense) => ({
613
621
  name: `${agent}:${sense}`,
@@ -765,7 +773,7 @@ class DaemonSenseManager {
765
773
  }
766
774
  async refreshEnabledSenseConfigs() {
767
775
  const refreshes = [...this.contexts.entries()].map(async ([agent, context]) => {
768
- const enabledManagedSenses = ["teams", "bluebubbles", "mail", "voice", "a2a", "telegram", "shepherd"]
776
+ const enabledManagedSenses = ["teams", "bluebubbles", "mail", "voice", "a2a", "telegram", "shepherd", "app-sessions"]
769
777
  .filter((sense) => context.senses[sense].enabled);
770
778
  /* v8 ignore next -- periodic refresh work only exists when a managed background sense is enabled @preserve */
771
779
  if (enabledManagedSenses.length === 0)
@@ -993,6 +1001,10 @@ class DaemonSenseManager {
993
1001
  optional: context.facts.shepherd.optional,
994
1002
  ...(runtime.get(agent)?.shepherd ?? {}),
995
1003
  },
1004
+ "app-sessions": {
1005
+ configured: context.facts["app-sessions"].configured,
1006
+ ...(runtime.get(agent)?.["app-sessions"] ?? {}),
1007
+ },
996
1008
  };
997
1009
  const inventory = (0, sense_truth_1.getSenseInventory)({ senses: context.senses }, runtimeInfo);
998
1010
  return inventory.map((entry) => ({
@@ -1007,7 +1019,9 @@ class DaemonSenseManager {
1007
1019
  ? blueBubblesRuntimeFacts.detail
1008
1020
  ?? context.facts[entry.sense].detail
1009
1021
  : context.facts[entry.sense].detail
1010
- : context.facts[entry.sense].detail
1022
+ : entry.sense === "app-sessions"
1023
+ ? (0, store_1.snapshotSummary)((0, store_1.readSnapshot)(path.join(this.bundlesRoot, `${agent}.ouro`)), Date.now())
1024
+ : context.facts[entry.sense].detail
1011
1025
  : entry.sense === "workbench"
1012
1026
  ? WORKBENCH_RUNTIME_INJECTION_DETAIL
1013
1027
  : "not enabled in agent.json",
@@ -149,6 +149,7 @@ exports.DEFAULT_AGENT_SENSES = {
149
149
  telegram: { enabled: false },
150
150
  workbench: { enabled: false },
151
151
  shepherd: { enabled: false },
152
+ "app-sessions": { enabled: false },
152
153
  };
153
154
  function normalizeSenses(value, configFile) {
154
155
  const defaults = {
@@ -161,6 +162,7 @@ function normalizeSenses(value, configFile) {
161
162
  telegram: { ...exports.DEFAULT_AGENT_SENSES.telegram },
162
163
  workbench: { ...exports.DEFAULT_AGENT_SENSES.workbench },
163
164
  shepherd: { ...exports.DEFAULT_AGENT_SENSES.shepherd },
165
+ "app-sessions": { ...exports.DEFAULT_AGENT_SENSES["app-sessions"] },
164
166
  };
165
167
  if (value === undefined) {
166
168
  return defaults;
@@ -176,7 +178,7 @@ function normalizeSenses(value, configFile) {
176
178
  throw new Error(`agent.json at ${configFile} must include senses as an object when present.`);
177
179
  }
178
180
  const raw = value;
179
- const senseNames = ["cli", "teams", "bluebubbles", "mail", "voice", "a2a", "telegram", "workbench", "shepherd"];
181
+ const senseNames = ["cli", "teams", "bluebubbles", "mail", "voice", "a2a", "telegram", "workbench", "shepherd", "app-sessions"];
180
182
  for (const senseName of senseNames) {
181
183
  const rawSense = raw[senseName];
182
184
  if (rawSense === undefined) {
@@ -261,6 +263,7 @@ function buildDefaultAgentTemplate(_agentName) {
261
263
  telegram: { ...exports.DEFAULT_AGENT_SENSES.telegram },
262
264
  workbench: { ...exports.DEFAULT_AGENT_SENSES.workbench },
263
265
  shepherd: { ...exports.DEFAULT_AGENT_SENSES.shepherd },
266
+ "app-sessions": { ...exports.DEFAULT_AGENT_SENSES["app-sessions"] },
264
267
  },
265
268
  phrases: {
266
269
  thinking: [...exports.DEFAULT_AGENT_PHRASES.thinking],
@@ -158,6 +158,14 @@ async function evaluatePolicy(request, context, deps) {
158
158
  reason: "Shepherd escalation",
159
159
  };
160
160
  }
161
+ if (request.triggerSource === "app-sessions"
162
+ && hasNonEmptyOriginRef(originRefs, "app-session-reply")
163
+ && hasOriginRef(originRefs, "sense", "app-sessions")) {
164
+ return {
165
+ result: "allow",
166
+ reason: "Copilot app session reply",
167
+ };
168
+ }
161
169
  if (request.triggerSource === "operator-cli"
162
170
  && hasOriginRef(originRefs, "cli-command", "ouro msg")
163
171
  && hasNonEmptyOriginRef(originRefs, "daemon-receipt")) {
@@ -13,6 +13,7 @@ const SENSES = [
13
13
  { sense: "telegram", label: "Telegram", daemonManaged: true },
14
14
  { sense: "workbench", label: "Workbench", daemonManaged: false },
15
15
  { sense: "shepherd", label: "shepherd", daemonManaged: true },
16
+ { sense: "app-sessions", label: "app-sessions", daemonManaged: true },
16
17
  ];
17
18
  function configuredSenses(senses) {
18
19
  const configured = senses ?? {};
@@ -27,6 +28,7 @@ function configuredSenses(senses) {
27
28
  telegram: configured.telegram ?? { ...identity_1.DEFAULT_AGENT_SENSES.telegram },
28
29
  workbench: configured.workbench ?? { ...identity_1.DEFAULT_AGENT_SENSES.workbench },
29
30
  shepherd: configured.shepherd ?? { ...identity_1.DEFAULT_AGENT_SENSES.shepherd },
31
+ "app-sessions": configured["app-sessions"] ?? { ...identity_1.DEFAULT_AGENT_SENSES["app-sessions"] },
30
32
  };
31
33
  }
32
34
  function resolveStatus(enabled, daemonManaged, runtimeInfo) {
@@ -64,6 +64,7 @@ const mail_import_discovery_1 = require("./mail-import-discovery");
64
64
  const flight_recorder_1 = require("../arc/flight-recorder");
65
65
  const context_loss_sentinel_1 = require("./context-loss-sentinel");
66
66
  const shepherd_config_1 = require("./shepherd-config");
67
+ const store_1 = require("../senses/app-sessions/store");
67
68
  // ── Helpers ─────────────────────────────────────────────────────────
68
69
  const DAEMON_SOCKET_PATH = "/tmp/ouroboros-daemon.sock";
69
70
  function isLiveCodingSessionStatus(status) {
@@ -169,6 +170,7 @@ function readSenseStatusLines() {
169
170
  telegram: configuredSenses.telegram ?? { enabled: false },
170
171
  workbench: configuredSenses.workbench ?? { enabled: false },
171
172
  shepherd: configuredSenses.shepherd ?? { enabled: false },
173
+ "app-sessions": configuredSenses["app-sessions"] ?? { enabled: false },
172
174
  };
173
175
  const payload = (0, config_1.loadConfig)();
174
176
  const agentName = (0, identity_1.getAgentName)();
@@ -226,6 +228,7 @@ function readSenseStatusLines() {
226
228
  && hasTextField(runtimePayload, "telegramAuthorizedChatId"),
227
229
  workbench: false,
228
230
  shepherd: (0, shepherd_config_1.shepherdSenseStatus)(true, machinePayload) === "ready",
231
+ "app-sessions": true,
229
232
  };
230
233
  const rows = [
231
234
  { label: "CLI", status: "interactive" },
@@ -257,6 +260,10 @@ function readSenseStatusLines() {
257
260
  label: "shepherd",
258
261
  status: (0, shepherd_config_1.shepherdSenseStatus)(senses.shepherd.enabled, machinePayload),
259
262
  },
263
+ {
264
+ label: "app-sessions",
265
+ status: (0, store_1.appSessionsSenseStatus)(senses["app-sessions"].enabled, (0, identity_1.getAgentRoot)(), Date.now()),
266
+ },
260
267
  {
261
268
  label: "Workbench",
262
269
  // Workbench can be injected at runtime (the Workbench app spawns
@@ -92,7 +92,8 @@ const scrutiny_1 = require("./scrutiny");
92
92
  const pulse_1 = require("../heart/daemon/pulse");
93
93
  const provider_visibility_1 = require("../heart/provider-visibility");
94
94
  const shepherd_config_1 = require("../heart/shepherd-config");
95
- const store_1 = require("../trips/store");
95
+ const store_1 = require("../senses/app-sessions/store");
96
+ const store_2 = require("../trips/store");
96
97
  const orientation_frame_1 = require("../heart/orientation-frame");
97
98
  const flight_recorder_1 = require("../arc/flight-recorder");
98
99
  function flattenSystemPrompt(sp) {
@@ -608,6 +609,7 @@ function localSenseStatusLines() {
608
609
  telegram: configuredSenses.telegram ?? { enabled: false },
609
610
  workbench: configuredSenses.workbench ?? { enabled: false },
610
611
  shepherd: configuredSenses.shepherd ?? { enabled: false },
612
+ "app-sessions": configuredSenses["app-sessions"] ?? { enabled: false },
611
613
  };
612
614
  const payload = (0, config_1.loadConfig)();
613
615
  const runtimeConfig = (0, runtime_credentials_1.readRuntimeCredentialConfig)((0, identity_1.getAgentName)());
@@ -637,6 +639,7 @@ function localSenseStatusLines() {
637
639
  && hasTextField(runtimePayload, "telegramAuthorizedChatId"),
638
640
  workbench: false,
639
641
  shepherd: (0, shepherd_config_1.shepherdSenseStatus)(true, machinePayload) === "ready",
642
+ "app-sessions": true,
640
643
  };
641
644
  const rows = [
642
645
  { label: "CLI", status: "interactive" },
@@ -668,6 +671,10 @@ function localSenseStatusLines() {
668
671
  label: "shepherd",
669
672
  status: (0, shepherd_config_1.shepherdSenseStatus)(senses.shepherd.enabled, machinePayload),
670
673
  },
674
+ {
675
+ label: "app-sessions",
676
+ status: (0, store_1.appSessionsSenseStatus)(senses["app-sessions"].enabled, (0, identity_1.getAgentRoot)(), Date.now()),
677
+ },
671
678
  {
672
679
  label: "Workbench",
673
680
  // Workbench can be injected at runtime (the Workbench app spawns
@@ -1031,7 +1038,7 @@ function tripLedgerTruthSection(channel, context) {
1031
1038
  return "";
1032
1039
  let tripIds;
1033
1040
  try {
1034
- tripIds = (0, store_1.listTripIds)((0, identity_1.getAgentName)());
1041
+ tripIds = (0, store_2.listTripIds)((0, identity_1.getAgentName)());
1035
1042
  }
1036
1043
  catch {
1037
1044
  return "";
@@ -1048,7 +1055,7 @@ function tripLedgerTruthSection(channel, context) {
1048
1055
  const visibleTripIds = tripIds.slice(0, 8);
1049
1056
  for (const tripId of visibleTripIds) {
1050
1057
  try {
1051
- lines.push(renderTripLedgerSummary((0, store_1.readTripRecord)((0, identity_1.getAgentName)(), tripId)));
1058
+ lines.push(renderTripLedgerSummary((0, store_2.readTripRecord)((0, identity_1.getAgentName)(), tripId)));
1052
1059
  }
1053
1060
  catch {
1054
1061
  lines.push(`- ${tripId} :: unreadable right now; use trip_get before reasoning from it.`);
@@ -684,6 +684,8 @@ const COMMERCE_AUTHORITY_TOOLS = new Set(["stripe_create_card", "flight_hold", "
684
684
  // The Shepherd tools read the owner's terminals and speak to them through their desktop, so only family may use them.
685
685
  // A call with no known trust level fails closed.
686
686
  const SHEPHERD_FAMILY_TOOLS = new Set(["shepherd_overview", "shepherd_read", "shepherd_signal", "shepherd_send"]);
687
+ // The app-sessions tools read and write the owner's Copilot app sessions on this machine: family only, as Shepherd's.
688
+ const APP_SESSIONS_FAMILY_TOOLS = new Set(["app_sessions_list", "app_sessions_tail", "app_sessions_send", "app_sessions_resume", "app_sessions_new", "app_sessions_archive", "app_sessions_restart", "app_sessions_watch"]);
687
689
  const MAIL_FAMILY_TOOLS = new Set(["mail_screener", "mail_decide", "mail_access_log", "mail_send", "mail_index_refresh"]);
688
690
  const MAIL_DELEGATED_READ_TOOLS = new Set(["mail_recent", "mail_search"]);
689
691
  function opaqueAnsiShellAtoms(command) {
@@ -1430,6 +1432,9 @@ function checkTrustLevelGuardrails(toolName, args, context) {
1430
1432
  if (SHEPHERD_FAMILY_TOOLS.has(toolName) && context.trustLevel !== "family") {
1431
1433
  return deny("the owner's terminals require family trust.");
1432
1434
  }
1435
+ if (APP_SESSIONS_FAMILY_TOOLS.has(toolName) && context.trustLevel !== "family") {
1436
+ return deny("the owner's Copilot app sessions require family trust.");
1437
+ }
1433
1438
  // Credential tools have their own trust rules that apply at all levels
1434
1439
  const credentialResult = checkCredentialTrustGuardrails(toolName, context);
1435
1440
  if (!credentialResult.allowed)
@@ -0,0 +1,331 @@
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.appSessionsToolDefinitions = exports.appSessionsWatchTool = exports.appSessionsRestartTool = exports.appSessionsArchiveTool = exports.appSessionsNewTool = exports.appSessionsResumeTool = exports.appSessionsSendTool = exports.appSessionsTailTool = exports.appSessionsListTool = void 0;
37
+ exports.appSessionsToolsEnabled = appSessionsToolsEnabled;
38
+ const fs = __importStar(require("node:fs"));
39
+ const path = __importStar(require("node:path"));
40
+ const runtime_1 = require("../nerves/runtime");
41
+ const client_1 = require("../senses/app-sessions/client");
42
+ const store_1 = require("../senses/app-sessions/store");
43
+ /**
44
+ * The app-sessions tools: read and write this machine's GitHub Copilot app sessions. Every write is logged as a
45
+ * nerves event; none is gated. A session the agent writes to is watched, so its next finished reply comes back to the
46
+ * agent through the app-sessions sense.
47
+ */
48
+ const STATES = ["working", "waiting", "stuck", "idle"];
49
+ /** This Mac's app, in `~/.copilot`. */
50
+ const clientOptions = {};
51
+ function text(value) {
52
+ return typeof value === "string" ? value.trim() : "";
53
+ }
54
+ function flag(value, fallback) {
55
+ if (value === true || value === "true")
56
+ return true;
57
+ if (value === false || value === "false")
58
+ return false;
59
+ return fallback;
60
+ }
61
+ function appSessionsToolsEnabled(agentRoot) {
62
+ if (!agentRoot)
63
+ return false;
64
+ try {
65
+ const config = JSON.parse(fs.readFileSync(path.join(agentRoot, "agent.json"), "utf-8"));
66
+ return config.senses?.["app-sessions"]?.enabled === true;
67
+ }
68
+ catch {
69
+ return false;
70
+ }
71
+ }
72
+ async function run(tool, ctx, body) {
73
+ if (!ctx?.agentRoot)
74
+ return JSON.stringify({ error: "the app-sessions tools need an agent runtime" });
75
+ try {
76
+ const result = await body(ctx.agentRoot);
77
+ (0, runtime_1.emitNervesEvent)({ component: "repertoire", event: "repertoire.app_sessions_tool", message: "ran an app-sessions tool", meta: { tool } });
78
+ return JSON.stringify(result);
79
+ }
80
+ catch (error) {
81
+ (0, runtime_1.emitNervesEvent)({ level: "warn", component: "repertoire", event: "repertoire.app_sessions_tool_error", message: "app-sessions tool call failed", meta: { tool, error: error.message } });
82
+ return JSON.stringify({ error: error.message });
83
+ }
84
+ }
85
+ /** A full session id, or a unique prefix of one (the first 8 characters are enough). */
86
+ function resolveSession(value) {
87
+ const wanted = text(value);
88
+ if (!wanted)
89
+ throw new Error("name a session: its id, or the start of it, from app_sessions_list");
90
+ const rows = (0, client_1.listAppSessions)(clientOptions);
91
+ const exact = rows.find(row => row.id === wanted);
92
+ if (exact)
93
+ return { id: exact.id, name: exact.name };
94
+ const matches = rows.filter(row => row.id.startsWith(wanted));
95
+ if (matches.length === 1)
96
+ return { id: matches[0].id, name: matches[0].name };
97
+ if (matches.length > 1)
98
+ throw new Error(`'${wanted}' matches ${matches.length} sessions; give more of the id`);
99
+ throw new Error(`no session '${wanted}' in this Mac's Copilot app sidebar (app_sessions_list shows them)`);
100
+ }
101
+ function watch(agentRoot, id, name, offset) {
102
+ (0, store_1.watchSession)(agentRoot, id, name, offset, Date.now());
103
+ }
104
+ const sessionParam = { type: "string", description: "Session id from app_sessions_list (a unique prefix such as the first 8 characters works)." };
105
+ exports.appSessionsListTool = {
106
+ tool: {
107
+ type: "function",
108
+ function: {
109
+ name: "app_sessions_list",
110
+ description: "Every session in this Mac's GitHub Copilot app sidebar: id, name, state (working, waiting for the person, stuck = stopped mid-work and not running, idle), why, project and last activity, plus counts. Read-only.",
111
+ parameters: {
112
+ type: "object",
113
+ properties: { state: { type: "string", enum: [...STATES], description: "Only sessions in this state." } },
114
+ additionalProperties: false,
115
+ },
116
+ },
117
+ },
118
+ handler: (args, ctx) => run("app_sessions_list", ctx, () => {
119
+ const state = text(args.state);
120
+ const rows = (0, client_1.listAppSessions)(clientOptions);
121
+ const picture = (0, client_1.snapshot)(clientOptions);
122
+ return {
123
+ appRunning: picture.appRunning,
124
+ counts: picture.counts,
125
+ sessions: rows.filter(row => !state || row.state === state).map(row => ({
126
+ id: row.id, name: row.name, state: row.state, why: row.detail, kind: row.kind, project: row.project, lastActivity: row.lastActivity, ...(row.remote ? { remote: true } : {}),
127
+ })),
128
+ };
129
+ }),
130
+ summaryKeys: ["state"],
131
+ riskProfile: { mutates: "none", risk: "low" },
132
+ };
133
+ exports.appSessionsTailTool = {
134
+ tool: {
135
+ type: "function",
136
+ function: {
137
+ name: "app_sessions_tail",
138
+ description: "A Copilot app session's last messages (the person's or agent's prompts and the session's replies), oldest first. Read-only.",
139
+ parameters: {
140
+ type: "object",
141
+ properties: { session: sessionParam, count: { type: "number", description: "How many messages, 1-50. Default 6." } },
142
+ required: ["session"],
143
+ additionalProperties: false,
144
+ },
145
+ },
146
+ },
147
+ handler: (args, ctx) => run("app_sessions_tail", ctx, () => {
148
+ const session = resolveSession(args.session);
149
+ const count = Math.min(50, Math.max(1, Math.trunc(Number(args.count) || 6)));
150
+ return { session: session.id, name: session.name, messages: (0, client_1.tailAppSession)(session.id, count, clientOptions) };
151
+ }),
152
+ summaryKeys: ["session"],
153
+ riskProfile: { mutates: "none", risk: "low" },
154
+ };
155
+ exports.appSessionsSendTool = {
156
+ tool: {
157
+ type: "function",
158
+ function: {
159
+ name: "app_sessions_send",
160
+ description: "Deliver a message into a Copilot app session, the same request the app's own message box sends. Waits (up to 2 minutes) for the app to accept it: a session that is not loaded loads first. Its next finished reply comes back to you as an inbound message unless watch is false.",
161
+ parameters: {
162
+ type: "object",
163
+ properties: {
164
+ session: sessionParam,
165
+ message: { type: "string", description: "What to send." },
166
+ delivery: { type: "string", enum: ["immediate", "enqueue"], description: "immediate (default) steers the session now; enqueue waits behind its current work." },
167
+ watch: { type: "boolean", description: "Bring the session's next reply back to you. Default true." },
168
+ },
169
+ required: ["session", "message"],
170
+ additionalProperties: false,
171
+ },
172
+ },
173
+ },
174
+ handler: (args, ctx) => run("app_sessions_send", ctx, async (agentRoot) => {
175
+ const session = resolveSession(args.session);
176
+ const message = typeof args.message === "string" ? args.message : "";
177
+ if (!message.trim())
178
+ throw new Error("say what to send");
179
+ const offset = (0, client_1.eventLogSize)(session.id, clientOptions);
180
+ const delivery = text(args.delivery) === "enqueue" ? "enqueue" : "immediate";
181
+ const result = await (0, client_1.sendToAppSession)(session.id, message, { ...clientOptions, delivery });
182
+ const watching = result.ok && flag(args.watch, true);
183
+ if (watching)
184
+ watch(agentRoot, session.id, session.name, offset);
185
+ return { session: session.id, name: session.name, ...result, watching };
186
+ }),
187
+ summaryKeys: ["session"],
188
+ riskProfile: { mutates: "external_side_effect", risk: "high", reason: "sends a message into another agent session in the owner's Copilot app" },
189
+ };
190
+ exports.appSessionsResumeTool = {
191
+ tool: {
192
+ type: "function",
193
+ function: {
194
+ name: "app_sessions_resume",
195
+ description: "Nudge a stuck or stopped Copilot app session to continue where it left off (the resume message the Mac's app keeper sends after a restart), with an optional note. Its next reply comes back to you.",
196
+ parameters: {
197
+ type: "object",
198
+ properties: { session: sessionParam, note: { type: "string", description: "Anything to add to the resume message." } },
199
+ required: ["session"],
200
+ additionalProperties: false,
201
+ },
202
+ },
203
+ },
204
+ handler: (args, ctx) => run("app_sessions_resume", ctx, async (agentRoot) => {
205
+ const session = resolveSession(args.session);
206
+ const offset = (0, client_1.eventLogSize)(session.id, clientOptions);
207
+ const result = await (0, client_1.resumeAppSession)(session.id, text(args.note) || undefined, clientOptions);
208
+ if (result.ok)
209
+ watch(agentRoot, session.id, session.name, offset);
210
+ return { session: session.id, name: session.name, ...result, watching: result.ok };
211
+ }),
212
+ summaryKeys: ["session"],
213
+ riskProfile: { mutates: "external_side_effect", risk: "high", reason: "tells another agent session in the owner's Copilot app to continue" },
214
+ };
215
+ exports.appSessionsNewTool = {
216
+ tool: {
217
+ type: "function",
218
+ function: {
219
+ name: "app_sessions_new",
220
+ description: "Open a new chat session in this Mac's Copilot app (for example a throwaway probe), named, with an optional first message. You may archive the sessions you open with app_sessions_archive. Its first reply comes back to you.",
221
+ parameters: {
222
+ type: "object",
223
+ properties: {
224
+ name: { type: "string", description: "Sidebar title." },
225
+ prompt: { type: "string", description: "First message." },
226
+ cwd: { type: "string", description: "Working folder. Default: the home folder." },
227
+ agent: { type: "string", description: "Custom agent to run as, for example desk:worker." },
228
+ model: { type: "string", description: "Model id." },
229
+ },
230
+ additionalProperties: false,
231
+ },
232
+ },
233
+ },
234
+ handler: (args, ctx) => run("app_sessions_new", ctx, async (agentRoot) => {
235
+ const name = text(args.name);
236
+ const prompt = typeof args.prompt === "string" && args.prompt.trim() ? args.prompt : undefined;
237
+ const opened = await (0, client_1.openAppChat)({
238
+ ...(name ? { name } : {}), ...(prompt ? { prompt } : {}),
239
+ ...(text(args.cwd) ? { cwd: text(args.cwd) } : {}), ...(text(args.agent) ? { agent: text(args.agent) } : {}), ...(text(args.model) ? { model: text(args.model) } : {}),
240
+ }, clientOptions);
241
+ if (!opened.ok)
242
+ return { ...opened };
243
+ (0, store_1.addProbe)(agentRoot, opened.sessionId, name || null, Date.now());
244
+ if (prompt)
245
+ watch(agentRoot, opened.sessionId, name || null, 0);
246
+ return { ...opened, watching: !!prompt };
247
+ }),
248
+ summaryKeys: ["name"],
249
+ riskProfile: { mutates: "external_side_effect", risk: "high", reason: "opens a new agent session in the owner's Copilot app" },
250
+ };
251
+ exports.appSessionsArchiveTool = {
252
+ tool: {
253
+ type: "function",
254
+ function: {
255
+ name: "app_sessions_archive",
256
+ description: "Archive a Copilot app session that you opened with app_sessions_new (its workspace goes too).",
257
+ parameters: { type: "object", properties: { session: sessionParam }, required: ["session"], additionalProperties: false },
258
+ },
259
+ },
260
+ handler: (args, ctx) => run("app_sessions_archive", ctx, async (agentRoot) => {
261
+ const id = text(args.session);
262
+ const probes = (0, store_1.readProbes)(agentRoot);
263
+ const match = Object.keys(probes).filter(probe => probe === id || (id.length > 0 && probe.startsWith(id)));
264
+ if (match.length !== 1)
265
+ throw new Error(`'${id}' is not one session you opened with app_sessions_new (yours: ${Object.keys(probes).join(", ") || "none"})`);
266
+ const result = await (0, client_1.archiveAppSession)(match[0], clientOptions);
267
+ if (result.ok) {
268
+ (0, store_1.removeProbe)(agentRoot, match[0]);
269
+ (0, store_1.unwatchSession)(agentRoot, match[0]);
270
+ }
271
+ return { session: match[0], name: probes[match[0]].name, ...result };
272
+ }),
273
+ summaryKeys: ["session"],
274
+ riskProfile: { mutates: "external_side_effect", risk: "high", reason: "archives a session in the owner's Copilot app" },
275
+ };
276
+ exports.appSessionsRestartTool = {
277
+ tool: {
278
+ type: "function",
279
+ function: {
280
+ name: "app_sessions_restart",
281
+ description: "The Copilot app's courtesy restart, through this Mac's app keeper (it never restarts the app itself). status: the keeper's queue, panel, last restarts and resume state. enqueue: ask for a restart; the keeper restarts at once when nobody is at the Mac, otherwise shows the person a \"Restart now\" / \"Not now\" panel, and resumes every working session afterwards. Says so plainly when the keeper is not installed.",
282
+ parameters: {
283
+ type: "object",
284
+ properties: {
285
+ action: { type: "string", enum: ["status", "enqueue"], description: "Default status." },
286
+ why: { type: "string", description: "enqueue: the reason, shown to the person in the panel." },
287
+ },
288
+ additionalProperties: false,
289
+ },
290
+ },
291
+ },
292
+ handler: (args, ctx) => run("app_sessions_restart", ctx, async () => {
293
+ if (text(args.action) !== "enqueue")
294
+ return await (0, client_1.restartStatus)(clientOptions);
295
+ const why = text(args.why);
296
+ if (!why)
297
+ throw new Error("say why the app needs a restart; the person sees it in the panel");
298
+ return await (0, client_1.restartEnqueue)(why, ctx?.agentName ?? "an agent", clientOptions);
299
+ }),
300
+ summaryKeys: ["action"],
301
+ riskProfile: (args) => text(args.action) === "enqueue"
302
+ ? { mutates: "external_side_effect", risk: "high", reason: "queues a restart of the owner's Copilot app" }
303
+ : { mutates: "none", risk: "low" },
304
+ };
305
+ exports.appSessionsWatchTool = {
306
+ tool: {
307
+ type: "function",
308
+ function: {
309
+ name: "app_sessions_watch",
310
+ description: "Start or stop bringing a Copilot app session's finished replies back to you as inbound messages (sending to a session starts it; it lasts a day after your last message).",
311
+ parameters: {
312
+ type: "object",
313
+ properties: { session: sessionParam, watch: { type: "boolean", description: "true to start (default), false to stop." } },
314
+ required: ["session"],
315
+ additionalProperties: false,
316
+ },
317
+ },
318
+ },
319
+ handler: (args, ctx) => run("app_sessions_watch", ctx, (agentRoot) => {
320
+ const session = resolveSession(args.session);
321
+ if (!flag(args.watch, true))
322
+ return { session: session.id, watching: false, wasWatching: (0, store_1.unwatchSession)(agentRoot, session.id) };
323
+ watch(agentRoot, session.id, session.name, (0, client_1.eventLogSize)(session.id, clientOptions));
324
+ return { session: session.id, name: session.name, watching: true };
325
+ }),
326
+ summaryKeys: ["session"],
327
+ riskProfile: { mutates: "durable_state_write", risk: "high", reason: "changes which app sessions' replies wake the agent" },
328
+ };
329
+ exports.appSessionsToolDefinitions = [
330
+ exports.appSessionsListTool, exports.appSessionsTailTool, exports.appSessionsSendTool, exports.appSessionsResumeTool, exports.appSessionsNewTool, exports.appSessionsArchiveTool, exports.appSessionsRestartTool, exports.appSessionsWatchTool,
331
+ ];