@ouro.bot/cli 0.1.0-alpha.1314 → 0.1.0-alpha.1316
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 +52 -21
- package/dist/repertoire/tools-bundle.js +111 -31
- package/dist/repertoire/tools-habits.js +17 -9
- package/dist/repertoire/tools-runtime.js +29 -7
- package/dist/repertoire/tools-shepherd-guidance.js +22 -10
- package/dist/repertoire/tools-shepherd.js +63 -19
- package/dist/repertoire/tools-steward-policy.js +25 -15
- 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.1316",
|
|
6
|
+
"changes": [
|
|
7
|
+
"restart_runtime, revive_sense, habit_cancel and steward_policy_manage carry Ouro AX cards, and their errors end with a code the card explains."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1315",
|
|
12
|
+
"changes": [
|
|
13
|
+
"The Shepherd, bundle and Copilot app session tools now carry Ouro AX cards, and their failures return the code a card names."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1314",
|
|
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.1316</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -80,12 +80,43 @@ function because(action, ...detail) {
|
|
|
80
80
|
const short = (id) => String(id).slice(0, 8);
|
|
81
81
|
/** Whether a watch answers the session's replies: `never` does not, `always` keeps watching for a day, `once` (the default) stops at the first reply. */
|
|
82
82
|
const watchMode = (value) => (value === "never" ? null : value === "always" ? "always" : "once");
|
|
83
|
-
|
|
83
|
+
/** A refusal of this module's own, with the code its card names. */
|
|
84
|
+
class AppSessionsRefusal extends Error {
|
|
85
|
+
code;
|
|
86
|
+
constructor(code, message) {
|
|
87
|
+
super(message);
|
|
88
|
+
this.code = code;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The code a failed call ends with: Shepherd's own, or one of this module's. */
|
|
92
|
+
function codeOf(error) {
|
|
93
|
+
if (error instanceof shepherd_cli_1.ShepherdFailure || error instanceof AppSessionsRefusal)
|
|
94
|
+
return error.code;
|
|
95
|
+
return error instanceof shepherd_cli_1.ShepherdUnavailableError ? "shepherd-not-installed" : "app-sessions-failed";
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* An app-sessions tool's card: Shepherd missing (unless the tool doesn't run Shepherd), then the tool's own refusal if
|
|
99
|
+
* it has one, then any other failure.
|
|
100
|
+
*/
|
|
101
|
+
function card(name, effect, when, fix, extra = {}) {
|
|
102
|
+
const errors = [
|
|
103
|
+
...(extra.withoutShepherd ? [] : [{ code: "shepherd-not-installed", means: "Shepherd isn't installed on this Mac, so the Copilot app can't be reached.", fix: `Tell the owner ${name} needs Shepherd installed; don't reach the app another way.` }]),
|
|
104
|
+
...(extra.refusal ? [extra.refusal] : []),
|
|
105
|
+
{ code: "app-sessions-failed", means: "The call failed outside Shepherd; the error says why. A Shepherd refusal carries Shepherd's own code and fix instead.", fix },
|
|
106
|
+
{ code: "no-agent-runtime", means: "The call ran outside an agent's runtime, so the app can't be reached.", fix: `Don't retry; report that ${name} was called without an agent runtime.` },
|
|
107
|
+
];
|
|
108
|
+
return {
|
|
109
|
+
id: `tool:${name}`, group: "turn-app-sessions", when, effect, errors,
|
|
110
|
+
...(extra.idempotent ? { idempotent: true } : {}), ...(extra.destructive ? { destructive: true } : {}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function define(name, description, ax, properties, required, risk, body, summaryKeys = []) {
|
|
84
114
|
return {
|
|
85
115
|
tool: { type: "function", function: { name, description, parameters: { type: "object", properties, ...(required.length ? { required } : {}), additionalProperties: false } } },
|
|
116
|
+
ax,
|
|
86
117
|
handler: async (args, ctx) => {
|
|
87
118
|
if (!ctx?.agentRoot)
|
|
88
|
-
return JSON.stringify({ error: "the app-sessions tools need an agent runtime" });
|
|
119
|
+
return JSON.stringify({ error: "the app-sessions tools need an agent runtime", code: "no-agent-runtime" });
|
|
89
120
|
try {
|
|
90
121
|
const result = await body(args, ctx.agentRoot, ctx);
|
|
91
122
|
(0, runtime_1.emitNervesEvent)({ component: "repertoire", event: "repertoire.app_sessions_tool", message: "ran an app-sessions tool", meta: { tool: name } });
|
|
@@ -93,7 +124,7 @@ function define(name, description, properties, required, risk, body, summaryKeys
|
|
|
93
124
|
}
|
|
94
125
|
catch (error) {
|
|
95
126
|
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "repertoire", event: "repertoire.app_sessions_tool_error", message: "app-sessions tool call failed", meta: { tool: name, error: error.message } });
|
|
96
|
-
return JSON.stringify({ error: error.message,
|
|
127
|
+
return JSON.stringify({ error: error.message, code: codeOf(error) });
|
|
97
128
|
}
|
|
98
129
|
},
|
|
99
130
|
summaryKeys,
|
|
@@ -102,13 +133,13 @@ function define(name, description, properties, required, risk, body, summaryKeys
|
|
|
102
133
|
}
|
|
103
134
|
const session = { type: "string", description: "A session's id from list_sessions_and_chats; a unique start of it (the first 8 characters) works." };
|
|
104
135
|
const notifyOnIdle = { type: "string", enum: ["once", "always", "never"], description: "Whether the session's finished replies come back to you as inbound messages: once (default, the next one), always (for a day), or never. The app does not report back to an outside client, so this is how replies reach you." };
|
|
105
|
-
exports.listSessionsAndChatsTool = define("list_sessions_and_chats", "Every open coding session and chat in this Mac's GitHub Copilot app: id, app_url, name, project, branch, who created and coordinates it. Read-only.", {}, [], READ, async () => {
|
|
136
|
+
exports.listSessionsAndChatsTool = define("list_sessions_and_chats", "Every open coding session and chat in this Mac's GitHub Copilot app: id, app_url, name, project, branch, who created and coordinates it. Read-only.", card("list_sessions_and_chats", "read", "Pick this to find a session's id or app_url by name, project or branch; get_sessions_status says what each is doing.", "Call list_sessions_and_chats once more; if it fails again, tell the owner the app can't be listed."), {}, [], READ, async () => {
|
|
106
137
|
const picture = await (0, shepherd_cli_1.shepherd)(["sessions"]);
|
|
107
138
|
return { total: picture.summary.total, items: picture.sessions.map(row => Object.fromEntries(Object.entries(row).filter(([key]) => !STATUS_KEYS.includes(key)))) };
|
|
108
139
|
});
|
|
109
|
-
exports.getSessionsStatusTool = define("get_sessions_status", "What every session is doing now, with counts: busy, idle, stuck, blocked, and what each blocked one waits on. awaiting_input carries the request_id and the question that answer_session_input or respond_to_session_plan_v2 needs. Read-only.", { state: { type: "string", enum: ["busy", "idle", "waiting", "stuck"], description: "Only sessions in this state." } }, [], READ, args => (0, shepherd_cli_1.shepherd)(["sessions", ...(typeof args.state === "string" ? ["--state", args.state] : [])]), ["state"]);
|
|
110
|
-
exports.getSessionTool = define("get_session", "One session's details and what it is doing now, including what it waits on (awaiting_input). Read-only.", { session_id: session }, ["session_id"], READ, args => (0, shepherd_cli_1.shepherd)(["session", sessionId(args)]), ["session_id"]);
|
|
111
|
-
exports.sendSessionMessageTool = define("send_session_message", "Send a message to a session as a peer: the session sees it as a cross-session message from Ouroboros (Shepherd's own Ouroboros session is the sender and relays it, so the sender is not this runtime itself), never as the owner's turn. Write as yourself, Ouroboros, not as the owner or the owner's agent; the sender already says who you are. Replies come back to that Ouroboros session (read it with shepherd messages). Waits up to 2 minutes for the app to accept it (a session that is not loaded loads first). immediate (default) is admitted at the session's next turn boundary; enqueue waits behind its work.", { session_id: session, message: { type: "string", description: "What to send." }, delivery_mode: { type: "string", enum: ["immediate", "enqueue"] }, notify_on_idle: notifyOnIdle }, ["session_id", "message"], write("sends a message into another agent session in the owner's Copilot app"), async (args, agentRoot) => {
|
|
140
|
+
exports.getSessionsStatusTool = define("get_sessions_status", "What every session is doing now, with counts: busy, idle, stuck, blocked, and what each blocked one waits on. awaiting_input carries the request_id and the question that answer_session_input or respond_to_session_plan_v2 needs. Read-only.", card("get_sessions_status", "read", "Pick this to see which sessions are busy, stuck or waiting on someone, and on what, across the whole app at once.", "Call get_session for the one you care about, or try get_sessions_status again shortly."), { state: { type: "string", enum: ["busy", "idle", "waiting", "stuck"], description: "Only sessions in this state." } }, [], READ, args => (0, shepherd_cli_1.shepherd)(["sessions", ...(typeof args.state === "string" ? ["--state", args.state] : [])]), ["state"]);
|
|
141
|
+
exports.getSessionTool = define("get_session", "One session's details and what it is doing now, including what it waits on (awaiting_input). Read-only.", card("get_session", "read", "Pick this to check one session's state and the exact question it waits on before you answer or message it.", "Check the id with list_sessions_and_chats and call get_session again."), { session_id: session }, ["session_id"], READ, args => (0, shepherd_cli_1.shepherd)(["session", sessionId(args)]), ["session_id"]);
|
|
142
|
+
exports.sendSessionMessageTool = define("send_session_message", "Send a message to a session as a peer: the session sees it as a cross-session message from Ouroboros (Shepherd's own Ouroboros session is the sender and relays it, so the sender is not this runtime itself), never as the owner's turn. Write as yourself, Ouroboros, not as the owner or the owner's agent; the sender already says who you are. Replies come back to that Ouroboros session (read it with shepherd messages). Waits up to 2 minutes for the app to accept it (a session that is not loaded loads first). immediate (default) is admitted at the session's next turn boundary; enqueue waits behind its work.", card("send_session_message", "write", "Pick this to tell or ask another session something as yourself; answer_session_input fits a question it is blocked on.", "Read the session with get_session; resend only if your message isn't in app_sessions_tail."), { session_id: session, message: { type: "string", description: "What to send." }, delivery_mode: { type: "string", enum: ["immediate", "enqueue"] }, notify_on_idle: notifyOnIdle }, ["session_id", "message"], write("sends a message into another agent session in the owner's Copilot app"), async (args, agentRoot) => {
|
|
112
143
|
// The session is resolved and the send time taken before the send, so the watch's cursor sits before any reply to it.
|
|
113
144
|
const row = await (0, shepherd_cli_1.shepherd)(["session", sessionId(args)]);
|
|
114
145
|
const id = String(row.id);
|
|
@@ -119,7 +150,7 @@ exports.sendSessionMessageTool = define("send_session_message", "Send a message
|
|
|
119
150
|
(0, store_1.watchSession)(agentRoot, id, String(row.name), sentAt, Date.now(), mode === "once");
|
|
120
151
|
return { ...sent, watching: mode !== null };
|
|
121
152
|
}, ["session_id"]);
|
|
122
|
-
exports.createSessionTool = define("create_session", "Start a session. With project_id (a project's id or name): a project session in its own worktree (workspace_type branch uses the project's checkout instead), kicked off with kickoff.prompt and allow-all permissions unless kickoff.permission_mode says otherwise. Without it: a standalone chat, which shows to peers as \"General Chat\" and has no repository, so use it only for talk that is not repository work. Any work in a repository (for the harness itself: the ouroboros project) must pass project_id, never a chat. Waits for the session to exist (a worktree takes about two minutes). It has no coordinator: the app does not let an outside client be one. You may archive what you create.", {
|
|
153
|
+
exports.createSessionTool = define("create_session", "Start a session. With project_id (a project's id or name): a project session in its own worktree (workspace_type branch uses the project's checkout instead), kicked off with kickoff.prompt and allow-all permissions unless kickoff.permission_mode says otherwise. Without it: a standalone chat, which shows to peers as \"General Chat\" and has no repository, so use it only for talk that is not repository work. Any work in a repository (for the harness itself: the ouroboros project) must pass project_id, never a chat. Waits for the session to exist (a worktree takes about two minutes). It has no coordinator: the app does not let an outside client be one. You may archive what you create.", card("create_session", "write", "Pick this to start new work in the app: a project session for anything in a repository, a chat only for talk.", "Check list_sessions_and_chats for a half-made session before you create another."), {
|
|
123
154
|
name: { type: "string", description: "Sidebar title." }, project_id: { type: "string", description: "The project's id or name." }, session_kind: { type: "string", enum: ["chat", "project"] },
|
|
124
155
|
workspace_type: { type: "string", enum: ["worktree", "branch"] }, branch_name: { type: "string", description: "Branch for a worktree; a fresh ouro-… name by default." },
|
|
125
156
|
kickoff: {
|
|
@@ -140,9 +171,9 @@ exports.createSessionTool = define("create_session", "Start a session. With proj
|
|
|
140
171
|
(0, store_1.watchSession)(agentRoot, String(created.session_id), typeof args.name === "string" ? args.name : null, new Date().toISOString(), Date.now(), mode === "once");
|
|
141
172
|
return prompted ? { ...created, watching: mode !== null } : created;
|
|
142
173
|
}, ["name"]);
|
|
143
|
-
exports.answerSessionInputTool = define("answer_session_input", "Answer the question a session asked with ask_user and is blocked on. get_session shows it (awaiting_input.question, choices). A choice or free text. A question asked while this agent was not connected has no request id and cannot be answered here.", { session_id: session, answer: { type: "string" } }, ["session_id", "answer"], write("answers a question for the person in another agent session"), args => (0, shepherd_cli_1.shepherd)(["answer", sessionId(args)], bodyOf(args, "session_id"), because(`Ouroboros answers the question session ${short(args.session_id)} asked`, args.answer)), ["session_id"]);
|
|
144
|
-
exports.respondToSessionPlanTool = define("respond_to_session_plan_v2", "Approve or reject the plan a session paused on (awaiting_plan_approval). feedback is sent to the session as a message after the decision.", { session_id: session, approved: { type: "boolean" }, selected_action: { type: "string", description: "One of awaiting_input.actions; the recommended one by default." }, feedback: { type: "string" } }, ["session_id", "approved"], write("approves or rejects another agent session's plan for the person"), args => (0, shepherd_cli_1.shepherd)(["plan", sessionId(args)], bodyOf(args, "session_id"), because(`Ouroboros ${args.approved === true ? "approves" : "rejects"} the plan of session ${short(args.session_id)}`, args.feedback)), ["session_id"]);
|
|
145
|
-
exports.archiveSessionTool = define("archive_session", "Archive a session you created with create_session (a project session's worktree goes with it). A session you did not create is archived only when the owner asked for that session in this conversation (owner_asked: true) or when it is over the size limit and a newer session names it as handed off. Archiving can be undone, and each such archive is logged and shown in the next digest.", { session_id: session, owner_asked: { type: "boolean", description: "True only when the owner asked in this conversation for this session to be archived." } }, ["session_id"], write("archives a session in the owner's Copilot app"), async (args, agentRoot) => {
|
|
174
|
+
exports.answerSessionInputTool = define("answer_session_input", "Answer the question a session asked with ask_user and is blocked on. get_session shows it (awaiting_input.question, choices). A choice or free text. A question asked while this agent was not connected has no request id and cannot be answered here.", card("answer_session_input", "write", "Pick this when a session is blocked on an ask_user question and the person has told you the answer.", "Call get_session to see whether the question is still open and what choices it takes."), { session_id: session, answer: { type: "string" } }, ["session_id", "answer"], write("answers a question for the person in another agent session"), args => (0, shepherd_cli_1.shepherd)(["answer", sessionId(args)], bodyOf(args, "session_id"), because(`Ouroboros answers the question session ${short(args.session_id)} asked`, args.answer)), ["session_id"]);
|
|
175
|
+
exports.respondToSessionPlanTool = define("respond_to_session_plan_v2", "Approve or reject the plan a session paused on (awaiting_plan_approval). feedback is sent to the session as a message after the decision.", card("respond_to_session_plan_v2", "write", "Pick this when a session waits for its plan to be approved or rejected and the person has decided.", "Call get_session to see whether the plan still waits, then respond to what it shows."), { session_id: session, approved: { type: "boolean" }, selected_action: { type: "string", description: "One of awaiting_input.actions; the recommended one by default." }, feedback: { type: "string" } }, ["session_id", "approved"], write("approves or rejects another agent session's plan for the person"), args => (0, shepherd_cli_1.shepherd)(["plan", sessionId(args)], bodyOf(args, "session_id"), because(`Ouroboros ${args.approved === true ? "approves" : "rejects"} the plan of session ${short(args.session_id)}`, args.feedback)), ["session_id"]);
|
|
176
|
+
exports.archiveSessionTool = define("archive_session", "Archive a session you created with create_session (a project session's worktree goes with it). A session you did not create is archived only when the owner asked for that session in this conversation (owner_asked: true) or when it is over the size limit and a newer session names it as handed off. Archiving can be undone, and each such archive is logged and shown in the next digest.", card("archive_session", "write", "Pick this to put away a session you started, or one the owner named for archiving in this conversation.", "Leave the session as it is and tell the owner it couldn't be archived, with the reason.", { destructive: true }), { session_id: session, owner_asked: { type: "boolean", description: "True only when the owner asked in this conversation for this session to be archived." } }, ["session_id"], write("archives a session in the owner's Copilot app"), async (args, agentRoot) => {
|
|
146
177
|
const ownerAsked = args.owner_asked === true;
|
|
147
178
|
const row = await (0, shepherd_cli_1.shepherd)(["session", sessionId(args)]);
|
|
148
179
|
const archived = await (0, shepherd_cli_1.shepherd)(["archive", String(row.id)], ownerAsked ? { owner_asked: true } : undefined, because(ownerAsked ? `The owner asked Ouroboros to archive ${String(row.name)}` : `Ouroboros archives ${String(row.name)}, which it created or which was handed off`));
|
|
@@ -151,8 +182,8 @@ exports.archiveSessionTool = define("archive_session", "Archive a session you cr
|
|
|
151
182
|
(0, store_1.addArchiveLog)(agentRoot, { id: String(row.id), name: String(row.name), at: new Date().toISOString(), reason: "owner-asked" });
|
|
152
183
|
return archived;
|
|
153
184
|
}, ["session_id"]);
|
|
154
|
-
exports.navigateToTool = define("navigate_to", "Show a session in the app's window, as following its app_url does.", { id: session }, ["id"], write("changes what the owner's Copilot app shows"), args => (0, shepherd_cli_1.shepherd)(["open", String(args.id)]), ["id"]);
|
|
155
|
-
exports.saveSessionAutomationTool = define("save_session_automation", "Create or replace the automation that wakes a session on a schedule, or clear it. interval is once (run_at), minutes (every_minutes), daily or weekly (schedule_hour, schedule_minute, schedule_day), or cron (cron_expression, five fields, local time).", {
|
|
185
|
+
exports.navigateToTool = define("navigate_to", "Show a session in the app's window, as following its app_url does.", card("navigate_to", "write", "Pick this when the owner wants a particular session brought up on screen in the app's window.", "Give the owner the session's app_url from list_sessions_and_chats instead.", { idempotent: true }), { id: session }, ["id"], write("changes what the owner's Copilot app shows"), args => (0, shepherd_cli_1.shepherd)(["open", String(args.id)]), ["id"]);
|
|
186
|
+
exports.saveSessionAutomationTool = define("save_session_automation", "Create or replace the automation that wakes a session on a schedule, or clear it. interval is once (run_at), minutes (every_minutes), daily or weekly (schedule_hour, schedule_minute, schedule_day), or cron (cron_expression, five fields, local time).", card("save_session_automation", "write", "Pick this to schedule a session to wake with a prompt later or on repeat, or to stop that schedule.", "Read the current schedule with get_session_automation before trying again."), {
|
|
156
187
|
session_id: session, prompt: { type: "string" }, interval: { type: "string", enum: ["once", "minutes", "daily", "weekly", "cron"] }, run_at: { type: "string" }, every_minutes: { type: "number" },
|
|
157
188
|
schedule_hour: { type: "number" }, schedule_minute: { type: "number" }, schedule_day: { type: "number" }, cron_expression: { type: "string" }, name: { type: "string" },
|
|
158
189
|
clear: { type: "boolean", description: "Remove the session's automation instead." },
|
|
@@ -160,26 +191,26 @@ exports.saveSessionAutomationTool = define("save_session_automation", "Create or
|
|
|
160
191
|
const body = bodyOf(args, "session_id");
|
|
161
192
|
return (0, shepherd_cli_1.shepherd)(["automation", sessionId(args)], body, because(body ? (args.clear === true ? `Ouroboros clears the wake-ups of session ${short(args.session_id)}` : `Ouroboros schedules a wake-up for session ${short(args.session_id)}`) : `Ouroboros reads the wake-ups of session ${short(args.session_id)}`, args.prompt));
|
|
162
193
|
}, ["session_id"]);
|
|
163
|
-
exports.getSessionAutomationTool = define("get_session_automation", "The automation attached to a session. Read-only.", { session_id: session }, ["session_id"], READ, args => (0, shepherd_cli_1.shepherd)(["automation", sessionId(args)], undefined, because(`Ouroboros reads the wake-ups of session ${short(args.session_id)}`)), ["session_id"]);
|
|
164
|
-
exports.listWorkflowsTool = define("list_workflows", "The app's automations (workflows), with their ids and schedules. Read-only.", {}, [], READ, () => (0, shepherd_cli_1.shepherd)(["workflows"]));
|
|
165
|
-
exports.runWorkflowTool = define("run_workflow", "Run one of the app's automations now, in a new session.", { id: { type: "string", description: "From list_workflows." } }, ["id"], write("starts a session in the owner's Copilot app"), args => (0, shepherd_cli_1.shepherd)(["run-workflow", String(args.id)], undefined, because(`Ouroboros runs workflow ${String(args.id)}`)), ["id"]);
|
|
166
|
-
exports.appSessionsTailTool = define("app_sessions_tail", "A session's last visible prompts and replies, oldest first, with its current name and state and how much of the local log was read. Re-read before reporting current progress: older messages are not live status. Read-only.", { session_id: session, count: { type: "number", description: "How many messages, 1-50. Default 6." } }, ["session_id"], READ, async (args, agentRoot) => {
|
|
194
|
+
exports.getSessionAutomationTool = define("get_session_automation", "The automation attached to a session. Read-only.", card("get_session_automation", "read", "Pick this to check whether and when a session is set to wake on its own, before changing that.", "Check the session id with list_sessions_and_chats and read it again."), { session_id: session }, ["session_id"], READ, args => (0, shepherd_cli_1.shepherd)(["automation", sessionId(args)], undefined, because(`Ouroboros reads the wake-ups of session ${short(args.session_id)}`)), ["session_id"]);
|
|
195
|
+
exports.listWorkflowsTool = define("list_workflows", "The app's automations (workflows), with their ids and schedules. Read-only.", card("list_workflows", "read", "Pick this to find the app's saved automations and their ids before running one with run_workflow.", "Call list_workflows again shortly; say the automations can't be listed if it keeps failing."), {}, [], READ, () => (0, shepherd_cli_1.shepherd)(["workflows"]));
|
|
196
|
+
exports.runWorkflowTool = define("run_workflow", "Run one of the app's automations now, in a new session.", card("run_workflow", "write", "Pick this to start one of the app's saved automations right now in a fresh session.", "Check the id with list_workflows, and look for a session it already started before running it again."), { id: { type: "string", description: "From list_workflows." } }, ["id"], write("starts a session in the owner's Copilot app"), args => (0, shepherd_cli_1.shepherd)(["run-workflow", String(args.id)], undefined, because(`Ouroboros runs workflow ${String(args.id)}`)), ["id"]);
|
|
197
|
+
exports.appSessionsTailTool = define("app_sessions_tail", "A session's last visible prompts and replies, oldest first, with its current name and state and how much of the local log was read. Re-read before reporting current progress: older messages are not live status. Read-only.", card("app_sessions_tail", "read", "Pick this to read what a session said and was asked most recently, before reporting its progress.", "Fall back to get_session for its state, and say the latest messages couldn't be read."), { session_id: session, count: { type: "number", description: "How many messages, 1-50. Default 6." } }, ["session_id"], READ, async (args, agentRoot) => {
|
|
167
198
|
const history = await (0, shepherd_cli_1.shepherd)(["messages", sessionId(args)], { count: Math.min(50, Math.max(1, Math.trunc(Number(args.count) || 6))) });
|
|
168
199
|
const watchedName = (0, store_1.readWatches)(agentRoot)[String(history.session_id)]?.name;
|
|
169
200
|
return { ...history, ...(watchedName && watchedName !== history.name ? { renamed_from: watchedName } : {}) };
|
|
170
201
|
}, ["session_id"]);
|
|
171
|
-
exports.appSessionsRestartTool = define("app_sessions_restart", "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.", { action: { type: "string", enum: ["status", "enqueue"], description: "Default status." }, why: { type: "string", description: "enqueue: the reason; it completes \"restarted at 11:40 for …\" in the resume message each session gets." } }, [], { mutates: "external_side_effect", risk: "high", reason: "restarts the owner's Copilot app" }, async (args, _agentRoot, ctx) => {
|
|
202
|
+
exports.appSessionsRestartTool = define("app_sessions_restart", "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.", card("app_sessions_restart", "write", "Pick this when the Copilot app itself is hung or needs restarting; it keeps every session's work and resumes them.", "Call app_sessions_restart with action status to see whether a restart is already running.", { withoutShepherd: true, refusal: { code: "why-required", means: "action enqueue came without a reason.", fix: "Call again with why set to what the restart is for; every session sees it in its resume message." } }), { action: { type: "string", enum: ["status", "enqueue"], description: "Default status." }, why: { type: "string", description: "enqueue: the reason; it completes \"restarted at 11:40 for …\" in the resume message each session gets." } }, [], { mutates: "external_side_effect", risk: "high", reason: "restarts the owner's Copilot app" }, async (args, _agentRoot, ctx) => {
|
|
172
203
|
if (args.action !== "enqueue")
|
|
173
204
|
return await (0, client_1.restartStatus)(clientOptions);
|
|
174
205
|
const why = typeof args.why === "string" ? args.why.trim() : "";
|
|
175
206
|
if (!why)
|
|
176
|
-
throw new
|
|
207
|
+
throw new AppSessionsRefusal("why-required", "say why the app needs a restart; every session is told in its resume message");
|
|
177
208
|
return await (0, client_1.restartEnqueue)(why, ctx.agentName ?? "an agent", clientOptions);
|
|
178
209
|
}, ["action"]);
|
|
179
|
-
exports.appSessionsDigestTool = define("app_sessions_digest", "How everything is going, already worked out with no model: what needs the owner, what is broken, each working session with its card's next step, the Mac's health, the drains and what merged today. Read-only.", {}, [], READ, async (_args, agentRoot) => {
|
|
210
|
+
exports.appSessionsDigestTool = define("app_sessions_digest", "How everything is going, already worked out with no model: what needs the owner, what is broken, each working session with its card's next step, the Mac's health, the drains and what merged today. Read-only.", card("app_sessions_digest", "read", "Pick this for one precomputed picture of how all the work is going, what needs the owner, and what broke.", "Build the picture from get_sessions_status instead.", { withoutShepherd: true, refusal: { code: "no-digest-yet", means: "No status digest exists, because agent.json gives the app-sessions sense no digest block.", fix: "Tell the owner the digest isn't set up; answer from get_sessions_status meanwhile." } }), {}, [], READ, async (_args, agentRoot) => {
|
|
180
211
|
const digest = (0, digest_1.readDigestText)(agentRoot, Date.now());
|
|
181
212
|
if (!digest)
|
|
182
|
-
throw new
|
|
213
|
+
throw new AppSessionsRefusal("no-digest-yet", "no status digest yet: it is built when agent.json gives the app-sessions sense a digest block");
|
|
183
214
|
return { digest };
|
|
184
215
|
});
|
|
185
216
|
exports.appSessionsToolDefinitions = [
|
|
@@ -229,7 +229,7 @@ const initGitHandler = (args) => {
|
|
|
229
229
|
});
|
|
230
230
|
return json({
|
|
231
231
|
ok: false,
|
|
232
|
-
error: "bundle already has a .git directory — pass force: true to re-init",
|
|
232
|
+
error: "bundle already has a .git directory — pass force: true to re-init", code: "already-initialized",
|
|
233
233
|
alreadyInit: true,
|
|
234
234
|
});
|
|
235
235
|
}
|
|
@@ -250,7 +250,7 @@ const initGitHandler = (args) => {
|
|
|
250
250
|
message: "git init failed",
|
|
251
251
|
meta: { bundleRoot, ok: false },
|
|
252
252
|
});
|
|
253
|
-
return json({ ok: false, error: `git init failed: ${init.stderr}
|
|
253
|
+
return json({ ok: false, error: `git init failed: ${init.stderr}`, code: "git-failed" });
|
|
254
254
|
}
|
|
255
255
|
/* v8 ignore stop */
|
|
256
256
|
}
|
|
@@ -296,7 +296,7 @@ const addRemoteHandler = (args) => {
|
|
|
296
296
|
return json({ ok, ...payload });
|
|
297
297
|
};
|
|
298
298
|
if (!isGitRepo(bundleRoot)) {
|
|
299
|
-
return finish(false, { error: "bundle is not a git repo — run bundle_init_git first" });
|
|
299
|
+
return finish(false, { error: "bundle is not a git repo — run bundle_init_git first", code: "not-a-repo" });
|
|
300
300
|
}
|
|
301
301
|
if (!REMOTE_URL_PATTERN.test(url)) {
|
|
302
302
|
(0, runtime_1.emitNervesEvent)({
|
|
@@ -306,7 +306,7 @@ const addRemoteHandler = (args) => {
|
|
|
306
306
|
message: "bundle_add_remote refused: invalid url",
|
|
307
307
|
meta: { bundleRoot, url },
|
|
308
308
|
});
|
|
309
|
-
return finish(false, { error: `invalid remote url: ${url || "(empty)"}
|
|
309
|
+
return finish(false, { error: `invalid remote url: ${url || "(empty)"}`, code: "invalid-remote-url" });
|
|
310
310
|
}
|
|
311
311
|
const existing = getRemoteUrl(bundleRoot, name);
|
|
312
312
|
if (existing && !force) {
|
|
@@ -318,7 +318,7 @@ const addRemoteHandler = (args) => {
|
|
|
318
318
|
meta: { bundleRoot, name, existing },
|
|
319
319
|
});
|
|
320
320
|
return finish(false, {
|
|
321
|
-
error: `remote "${name}" already points to ${existing} — pass force: true to overwrite`,
|
|
321
|
+
error: `remote "${name}" already points to ${existing} — pass force: true to overwrite`, code: "remote-exists",
|
|
322
322
|
previousUrl: existing,
|
|
323
323
|
});
|
|
324
324
|
}
|
|
@@ -326,14 +326,14 @@ const addRemoteHandler = (args) => {
|
|
|
326
326
|
const setUrl = gitExec(bundleRoot, ["remote", "set-url", name, url]);
|
|
327
327
|
/* v8 ignore next 3 -- git remote set-url failure requires a permissions/git-state edge case @preserve */
|
|
328
328
|
if (setUrl.code !== 0) {
|
|
329
|
-
return finish(false, { error: `git remote set-url failed: ${setUrl.stderr}
|
|
329
|
+
return finish(false, { error: `git remote set-url failed: ${setUrl.stderr}`, code: "git-failed" });
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
else {
|
|
333
333
|
const add = gitExec(bundleRoot, ["remote", "add", name, url]);
|
|
334
334
|
/* v8 ignore next 3 -- git remote add failure requires a permissions/git-state edge case @preserve */
|
|
335
335
|
if (add.code !== 0) {
|
|
336
|
-
return finish(false, { error: `git remote add failed: ${add.stderr}
|
|
336
|
+
return finish(false, { error: `git remote add failed: ${add.stderr}`, code: "git-failed" });
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
return finish(true, { name, url, previousUrl: existing ?? null });
|
|
@@ -356,15 +356,15 @@ const listFirstCommitHandler = () => {
|
|
|
356
356
|
return json({ ok, ...payload });
|
|
357
357
|
};
|
|
358
358
|
if (!isGitRepo(bundleRoot)) {
|
|
359
|
-
return finish(false, { error: "bundle is not a git repo — run bundle_init_git first" });
|
|
359
|
+
return finish(false, { error: "bundle is not a git repo — run bundle_init_git first", code: "not-a-repo" });
|
|
360
360
|
}
|
|
361
361
|
if (hasHead(bundleRoot)) {
|
|
362
|
-
return finish(false, { error: "bundle already has commits — bundle_list_first_commit only applies before the first commit" });
|
|
362
|
+
return finish(false, { error: "bundle already has commits — bundle_list_first_commit only applies before the first commit", code: "already-committed" });
|
|
363
363
|
}
|
|
364
364
|
const ls = gitExec(bundleRoot, ["ls-files", "-o", "--exclude-standard"]);
|
|
365
365
|
/* v8 ignore next 3 -- git ls-files failure requires a corrupt repo @preserve */
|
|
366
366
|
if (ls.code !== 0) {
|
|
367
|
-
return finish(false, { error: `git ls-files failed: ${ls.stderr}
|
|
367
|
+
return finish(false, { error: `git ls-files failed: ${ls.stderr}`, code: "git-failed" });
|
|
368
368
|
}
|
|
369
369
|
const files = ls.stdout
|
|
370
370
|
.split("\n")
|
|
@@ -421,16 +421,16 @@ const doFirstCommitHandler = (args) => {
|
|
|
421
421
|
return json({ ok, ...payload });
|
|
422
422
|
};
|
|
423
423
|
if (!isGitRepo(bundleRoot)) {
|
|
424
|
-
return finish(false, { error: "bundle is not a git repo — run bundle_init_git first" });
|
|
424
|
+
return finish(false, { error: "bundle is not a git repo — run bundle_init_git first", code: "not-a-repo" });
|
|
425
425
|
}
|
|
426
426
|
if (hasHead(bundleRoot)) {
|
|
427
|
-
return finish(false, { error: "bundle already has commits — first commit already exists" });
|
|
427
|
+
return finish(false, { error: "bundle already has commits — first commit already exists", code: "already-committed" });
|
|
428
428
|
}
|
|
429
429
|
// Resolve the file list — either explicit or the default set from ls-files.
|
|
430
430
|
let filesToStage;
|
|
431
431
|
if (hasExplicitFiles) {
|
|
432
432
|
if (!Array.isArray(rawFiles)) {
|
|
433
|
-
return finish(false, { error: "files must be an array of relative paths" });
|
|
433
|
+
return finish(false, { error: "files must be an array of relative paths", code: "invalid-files" });
|
|
434
434
|
}
|
|
435
435
|
if (rawFiles.length === 0) {
|
|
436
436
|
// Directive A: explicit enumeration required. Empty list is a refusal.
|
|
@@ -441,7 +441,7 @@ const doFirstCommitHandler = (args) => {
|
|
|
441
441
|
message: "bundle_do_first_commit refused: empty file list",
|
|
442
442
|
meta: { bundleRoot },
|
|
443
443
|
});
|
|
444
|
-
return finish(false, { error: "refused: files array must be non-empty — pass explicit file paths or omit the argument to stage everything" });
|
|
444
|
+
return finish(false, { error: "refused: files array must be non-empty — pass explicit file paths or omit the argument to stage everything", code: "invalid-files" });
|
|
445
445
|
}
|
|
446
446
|
filesToStage = rawFiles;
|
|
447
447
|
}
|
|
@@ -449,7 +449,7 @@ const doFirstCommitHandler = (args) => {
|
|
|
449
449
|
const ls = gitExec(bundleRoot, ["ls-files", "-o", "--exclude-standard"]);
|
|
450
450
|
/* v8 ignore next 3 -- git ls-files failure requires a corrupt repo @preserve */
|
|
451
451
|
if (ls.code !== 0) {
|
|
452
|
-
return finish(false, { error: `git ls-files failed: ${ls.stderr}
|
|
452
|
+
return finish(false, { error: `git ls-files failed: ${ls.stderr}`, code: "git-failed" });
|
|
453
453
|
}
|
|
454
454
|
filesToStage = ls.stdout
|
|
455
455
|
.split("\n")
|
|
@@ -458,13 +458,13 @@ const doFirstCommitHandler = (args) => {
|
|
|
458
458
|
}
|
|
459
459
|
/* v8 ignore next 3 -- empty filesToStage on default path means ls-files returned zero entries, covered by the empty-bundle test path elsewhere @preserve */
|
|
460
460
|
if (filesToStage.length === 0) {
|
|
461
|
-
return finish(false, { error: "no files to commit" });
|
|
461
|
+
return finish(false, { error: "no files to commit", code: "nothing-to-commit" });
|
|
462
462
|
}
|
|
463
463
|
// Security boundary: every file must resolve inside bundleRoot.
|
|
464
464
|
for (const file of filesToStage) {
|
|
465
465
|
/* v8 ignore next 3 -- defensive non-string entry check: LLM tool call args are JSON-parsed, a non-string would already fail JSON schema validation upstream @preserve */
|
|
466
466
|
if (typeof file !== "string" || file.length === 0) {
|
|
467
|
-
return finish(false, { error: `invalid file entry: ${JSON.stringify(file)}
|
|
467
|
+
return finish(false, { error: `invalid file entry: ${JSON.stringify(file)}`, code: "invalid-files" });
|
|
468
468
|
}
|
|
469
469
|
const check = assertInsideBundle(bundleRoot, file);
|
|
470
470
|
if (!check.ok) {
|
|
@@ -475,19 +475,19 @@ const doFirstCommitHandler = (args) => {
|
|
|
475
475
|
message: "bundle_do_first_commit refused: path outside bundle root",
|
|
476
476
|
meta: { bundleRoot, file },
|
|
477
477
|
});
|
|
478
|
-
return finish(false, { error: check.error });
|
|
478
|
+
return finish(false, { error: check.error, code: "outside-bundle" });
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
481
|
// Stage via `git add -- <file1> <file2> ...` — explicit enumeration.
|
|
482
482
|
const add = gitExec(bundleRoot, ["add", "--", ...filesToStage]);
|
|
483
483
|
/* v8 ignore next 3 -- git add failure on a valid file list requires a corrupt repo or race @preserve */
|
|
484
484
|
if (add.code !== 0) {
|
|
485
|
-
return finish(false, { error: `git add failed: ${add.stderr}
|
|
485
|
+
return finish(false, { error: `git add failed: ${add.stderr}`, code: "git-failed" });
|
|
486
486
|
}
|
|
487
487
|
const commit = gitExec(bundleRoot, ["commit", "-m", message]);
|
|
488
488
|
/* v8 ignore next 3 -- git commit failure requires a hook-reject or missing user.email, which createTmpBundle pre-configures @preserve */
|
|
489
489
|
if (commit.code !== 0) {
|
|
490
|
-
return finish(false, { error: `git commit failed: ${commit.stderr}
|
|
490
|
+
return finish(false, { error: `git commit failed: ${commit.stderr}`, code: "git-failed" });
|
|
491
491
|
}
|
|
492
492
|
const rev = gitExec(bundleRoot, ["rev-parse", "HEAD"]);
|
|
493
493
|
const commitSha = rev.stdout.trim();
|
|
@@ -572,17 +572,17 @@ function makeFirstPushReviewHandler(deps = {}) {
|
|
|
572
572
|
return json({ ok, ...payload });
|
|
573
573
|
};
|
|
574
574
|
if (!isGitRepo(bundleRoot)) {
|
|
575
|
-
return finish(false, { error: "bundle is not a git repo — run bundle_init_git first" });
|
|
575
|
+
return finish(false, { error: "bundle is not a git repo — run bundle_init_git first", code: "not-a-repo" });
|
|
576
576
|
}
|
|
577
577
|
const remotes = listRemotes(bundleRoot);
|
|
578
578
|
if (remotes.length === 0) {
|
|
579
|
-
return finish(false, { error: "no remote configured — run bundle_add_remote first" });
|
|
579
|
+
return finish(false, { error: "no remote configured — run bundle_add_remote first", code: "no-remote" });
|
|
580
580
|
}
|
|
581
581
|
const remoteName = remotes[0];
|
|
582
582
|
const remoteUrl = getRemoteUrl(bundleRoot, remoteName);
|
|
583
583
|
/* v8 ignore next 3 -- listRemotes returned a name but get-url failed; only possible under a git race @preserve */
|
|
584
584
|
if (!remoteUrl) {
|
|
585
|
-
return finish(false, { error: "could not resolve remote url" });
|
|
585
|
+
return finish(false, { error: "could not resolve remote url", code: "git-failed" });
|
|
586
586
|
}
|
|
587
587
|
// Enumerate PII directory counts
|
|
588
588
|
const piiCounts = {};
|
|
@@ -712,17 +712,17 @@ function makeSyncHandler(toolName, deps = {}) {
|
|
|
712
712
|
message,
|
|
713
713
|
meta: { bundleRoot, tool: toolName },
|
|
714
714
|
});
|
|
715
|
-
return finish(false, { error, kind: "confirmation_required" });
|
|
715
|
+
return finish(false, { error, kind: "confirmation_required", code: "confirmation-required" });
|
|
716
716
|
};
|
|
717
717
|
if (!isGitRepo(bundleRoot)) {
|
|
718
|
-
return finish(false, { error: "bundle is not a git repo" });
|
|
718
|
+
return finish(false, { error: "bundle is not a git repo", code: "not-a-repo" });
|
|
719
719
|
}
|
|
720
720
|
const remotes = listRemotes(bundleRoot);
|
|
721
721
|
if (!remotes.includes(remote)) {
|
|
722
|
-
return finish(false, { error: `remote "${remote}" not configured — run bundle_add_remote first
|
|
722
|
+
return finish(false, { error: `remote "${remote}" not configured — run bundle_add_remote first`, code: "no-remote" });
|
|
723
723
|
}
|
|
724
724
|
if (!hasHead(bundleRoot)) {
|
|
725
|
-
return finish(false, { error: "bundle has no commits — run bundle_do_first_commit first" });
|
|
725
|
+
return finish(false, { error: "bundle has no commits — run bundle_do_first_commit first", code: "no-commits" });
|
|
726
726
|
}
|
|
727
727
|
// Directive D: first push to a remote requires the agent to have
|
|
728
728
|
// previously called bundle_first_push_review and obtained a
|
|
@@ -730,7 +730,7 @@ function makeSyncHandler(toolName, deps = {}) {
|
|
|
730
730
|
// "bundle built locally" and "bundle contents on the internet".
|
|
731
731
|
const probe = await probeFirstPush(bundleRoot, remote, config.branch);
|
|
732
732
|
if (probe.kind === "unreachable") {
|
|
733
|
-
return finish(false, { error: `I couldn't reach GitHub to check whether this would be my first push, so I didn't sync: ${probe.error}`, kind: "remote_unreachable" });
|
|
733
|
+
return finish(false, { error: `I couldn't reach GitHub to check whether this would be my first push, so I didn't sync: ${probe.error}`, kind: "remote_unreachable", code: "remote-unreachable" });
|
|
734
734
|
}
|
|
735
735
|
const isFirstPush = probe.kind === "first";
|
|
736
736
|
if (isFirstPush) {
|
|
@@ -757,9 +757,9 @@ function makeSyncHandler(toolName, deps = {}) {
|
|
|
757
757
|
const result = await (0, sync_1.syncNow)(bundleRoot, config, agentName, BUNDLE_TOOL_SYNC_WAIT_MS, { firstPushApproved: isFirstPush });
|
|
758
758
|
const where = { remote, branch: config.branch, firstPush: isFirstPush };
|
|
759
759
|
if (result.paused)
|
|
760
|
-
return finish(false, { ...where, paused: true, pausedUntil: result.pausedUntil, error: `sync paused until ${result.pausedUntil}
|
|
760
|
+
return finish(false, { ...where, paused: true, pausedUntil: result.pausedUntil, error: `sync paused until ${result.pausedUntil}`, code: "sync-paused" });
|
|
761
761
|
if (result.busy)
|
|
762
|
-
return finish(false, { ...where, busy: true, holderPid: result.holderPid, error: result.error });
|
|
762
|
+
return finish(false, { ...where, busy: true, holderPid: result.holderPid, error: result.error, code: "sync-busy" });
|
|
763
763
|
// One-shot: the token is spent once sync actually ran, not on a busy or paused refusal.
|
|
764
764
|
if (confirmationToken !== undefined && isFirstPush)
|
|
765
765
|
_confirmationTokens.delete(confirmationToken);
|
|
@@ -767,7 +767,7 @@ function makeSyncHandler(toolName, deps = {}) {
|
|
|
767
767
|
const failure = readPendingFailure(bundleRoot);
|
|
768
768
|
return finish(false, {
|
|
769
769
|
...where,
|
|
770
|
-
error: result.error,
|
|
770
|
+
error: result.error, code: "sync-failed",
|
|
771
771
|
...(failure?.classification ? { kind: failure.classification } : {}),
|
|
772
772
|
...(failure?.conflictFiles && failure.conflictFiles.length > 0 ? { conflictFiles: failure.conflictFiles } : {}),
|
|
773
773
|
});
|
|
@@ -787,6 +787,21 @@ function readPendingFailure(bundleRoot) {
|
|
|
787
787
|
const pushHandler = makeSyncHandler("bundle_push");
|
|
788
788
|
const pullRebaseHandler = makeSyncHandler("bundle_pull_rebase");
|
|
789
789
|
// ─── registry ──────────────────────────────────────────────────────────
|
|
790
|
+
const notARepo = (tool) => ({ code: "not-a-repo", means: "My bundle has no .git directory yet.", fix: `Call bundle_init_git, then ${tool} again.` });
|
|
791
|
+
const gitFailed = (tool) => ({ code: "git-failed", means: "A git command failed; the error carries git's own words.", fix: `Fix what git names, or call bundle_check_sync_status to see the state, before ${tool} again.` });
|
|
792
|
+
/** The refusals bundle_push and bundle_pull_rebase share, since both run the same sync. */
|
|
793
|
+
function syncErrors(tool) {
|
|
794
|
+
return [
|
|
795
|
+
notARepo(tool),
|
|
796
|
+
{ code: "no-remote", means: "The bundle has no remote of that name.", fix: `Call bundle_add_remote with the owner's repository URL, then ${tool} again.` },
|
|
797
|
+
{ code: "no-commits", means: "The bundle has no commits to sync.", fix: `Call bundle_list_first_commit and bundle_do_first_commit, then ${tool} again.` },
|
|
798
|
+
{ code: "confirmation-required", means: "This would be the first push, and no valid confirmationToken came with it.", fix: `Call bundle_first_push_review, show the human its warning, and on their yes pass its token to ${tool}.` },
|
|
799
|
+
{ code: "remote-unreachable", means: "GitHub couldn't be reached to tell whether this is a first push, so nothing synced.", fix: `Call ${tool} again later; it changed nothing.` },
|
|
800
|
+
{ code: "sync-busy", means: "Another sync holds the bundle right now.", fix: `Wait a minute and call ${tool} again.` },
|
|
801
|
+
{ code: "sync-paused", means: "Syncing is paused by a pause marker; pausedUntil says until when, and nothing synced.", fix: `Tell the human sync is paused until pausedUntil; don't call ${tool} again before then.` },
|
|
802
|
+
{ code: "sync-failed", means: "The sync ran and failed; kind and conflictFiles say how.", fix: "Tell the human what kind and conflictFiles name; for conflicts, fix those files and sync again." },
|
|
803
|
+
];
|
|
804
|
+
}
|
|
790
805
|
exports.bundleToolDefinitions = [
|
|
791
806
|
{
|
|
792
807
|
tool: {
|
|
@@ -797,7 +812,13 @@ exports.bundleToolDefinitions = [
|
|
|
797
812
|
parameters: { type: "object", properties: {} },
|
|
798
813
|
},
|
|
799
814
|
},
|
|
815
|
+
ax: {
|
|
816
|
+
id: "tool:bundle_check_sync_status", group: "turn-bundle", effect: "read",
|
|
817
|
+
when: "Pick this first whenever the turn packet flags a bundleState issue, to see which bundle_ fix comes next.",
|
|
818
|
+
errors: [{ code: "tool-changed", means: "The tools for this turn changed before the check ran, so it read nothing.", fix: "Check the current tool list; call bundle_check_sync_status again only if it is still there." }],
|
|
819
|
+
},
|
|
800
820
|
handler: checkSyncStatusHandler,
|
|
821
|
+
riskProfile: { mutates: "none", risk: "low" },
|
|
801
822
|
},
|
|
802
823
|
{
|
|
803
824
|
tool: {
|
|
@@ -813,6 +834,14 @@ exports.bundleToolDefinitions = [
|
|
|
813
834
|
},
|
|
814
835
|
},
|
|
815
836
|
},
|
|
837
|
+
ax: {
|
|
838
|
+
id: "tool:bundle_init_git", group: "turn-bundle", effect: "write",
|
|
839
|
+
when: "Pick this when bundle_check_sync_status says my bundle isn't a git repository yet; force only with the human's yes.",
|
|
840
|
+
errors: [
|
|
841
|
+
{ code: "already-initialized", means: "The bundle already has a .git directory, so nothing changed.", fix: "Go on with bundle_add_remote; pass force: true only if the human asks to re-run git init." },
|
|
842
|
+
gitFailed("bundle_init_git"),
|
|
843
|
+
],
|
|
844
|
+
},
|
|
816
845
|
handler: initGitHandler,
|
|
817
846
|
riskProfile: { mutates: "durable_state_write", risk: "high", reason: "initializes bundle git state" },
|
|
818
847
|
},
|
|
@@ -833,6 +862,16 @@ exports.bundleToolDefinitions = [
|
|
|
833
862
|
},
|
|
834
863
|
},
|
|
835
864
|
},
|
|
865
|
+
ax: {
|
|
866
|
+
id: "tool:bundle_add_remote", group: "turn-bundle", effect: "write",
|
|
867
|
+
when: "Pick this once my bundle is a repository and needs the owner's backup repository to sync with.",
|
|
868
|
+
errors: [
|
|
869
|
+
notARepo("bundle_add_remote"),
|
|
870
|
+
{ code: "invalid-remote-url", means: "url isn't an https:// or git@ address.", fix: "Ask the human for the repository's https or SSH URL and pass it exactly." },
|
|
871
|
+
{ code: "remote-exists", means: "A remote with that name already points somewhere else; previousUrl says where.", fix: "Show the human both URLs; pass force: true only if they say to replace it." },
|
|
872
|
+
gitFailed("bundle_add_remote"),
|
|
873
|
+
],
|
|
874
|
+
},
|
|
836
875
|
handler: addRemoteHandler,
|
|
837
876
|
riskProfile: { mutates: "durable_state_write", risk: "high", reason: "updates bundle git remote configuration" },
|
|
838
877
|
},
|
|
@@ -845,7 +884,17 @@ exports.bundleToolDefinitions = [
|
|
|
845
884
|
parameters: { type: "object", properties: {} },
|
|
846
885
|
},
|
|
847
886
|
},
|
|
887
|
+
ax: {
|
|
888
|
+
id: "tool:bundle_list_first_commit", group: "turn-bundle", effect: "read",
|
|
889
|
+
when: "Pick this before bundle_do_first_commit, to show the human exactly which files the very first commit would take.",
|
|
890
|
+
errors: [
|
|
891
|
+
notARepo("bundle_list_first_commit"),
|
|
892
|
+
{ code: "already-committed", means: "The bundle already has commits, so there is no first commit to plan.", fix: "Call bundle_check_sync_status; ordinary changes sync with bundle_push." },
|
|
893
|
+
gitFailed("bundle_list_first_commit"),
|
|
894
|
+
],
|
|
895
|
+
},
|
|
848
896
|
handler: listFirstCommitHandler,
|
|
897
|
+
riskProfile: { mutates: "none", risk: "low" },
|
|
849
898
|
},
|
|
850
899
|
{
|
|
851
900
|
tool: {
|
|
@@ -862,6 +911,18 @@ exports.bundleToolDefinitions = [
|
|
|
862
911
|
},
|
|
863
912
|
},
|
|
864
913
|
},
|
|
914
|
+
ax: {
|
|
915
|
+
id: "tool:bundle_do_first_commit", group: "turn-bundle", effect: "write",
|
|
916
|
+
when: "Pick this after the human has seen bundle_list_first_commit's list and agreed, to record the bundle's very first commit.",
|
|
917
|
+
errors: [
|
|
918
|
+
notARepo("bundle_do_first_commit"),
|
|
919
|
+
{ code: "already-committed", means: "The bundle already has a first commit.", fix: "Skip this step; go on with bundle_first_push_review and bundle_push." },
|
|
920
|
+
{ code: "invalid-files", means: "files is empty, isn't a list of path strings, or holds a bad entry.", fix: "Pass relative paths from bundle_list_first_commit, or omit files to stage that whole list." },
|
|
921
|
+
{ code: "outside-bundle", means: "A path in files leads outside the bundle, so nothing was staged.", fix: "Pass only paths inside the bundle, as bundle_list_first_commit shows them." },
|
|
922
|
+
{ code: "nothing-to-commit", means: "There are no files to commit.", fix: "Call bundle_list_first_commit to check; if it is empty, there is nothing to do." },
|
|
923
|
+
gitFailed("bundle_do_first_commit"),
|
|
924
|
+
],
|
|
925
|
+
},
|
|
865
926
|
handler: doFirstCommitHandler,
|
|
866
927
|
riskProfile: { mutates: "durable_state_write", risk: "high", reason: "creates a bundle git commit" },
|
|
867
928
|
},
|
|
@@ -874,6 +935,15 @@ exports.bundleToolDefinitions = [
|
|
|
874
935
|
parameters: { type: "object", properties: {} },
|
|
875
936
|
},
|
|
876
937
|
},
|
|
938
|
+
ax: {
|
|
939
|
+
id: "tool:bundle_first_push_review", group: "turn-bundle", effect: "write",
|
|
940
|
+
when: "Pick this before the first sync to a new remote: it shows the human what private records would leave this machine.",
|
|
941
|
+
errors: [
|
|
942
|
+
notARepo("bundle_first_push_review"),
|
|
943
|
+
{ code: "no-remote", means: "The bundle has no remote yet, so there is nothing to review a push to.", fix: "Call bundle_add_remote with the owner's repository URL, then review again." },
|
|
944
|
+
gitFailed("bundle_first_push_review"),
|
|
945
|
+
],
|
|
946
|
+
},
|
|
877
947
|
handler: firstPushReviewHandler,
|
|
878
948
|
},
|
|
879
949
|
{
|
|
@@ -890,6 +960,11 @@ exports.bundleToolDefinitions = [
|
|
|
890
960
|
},
|
|
891
961
|
},
|
|
892
962
|
},
|
|
963
|
+
ax: {
|
|
964
|
+
id: "tool:bundle_push", group: "turn-bundle", effect: "write",
|
|
965
|
+
when: "Pick this to send my bundle's new commits to its remote; it runs the same merge-only sync as bundle_pull_rebase.",
|
|
966
|
+
errors: syncErrors("bundle_push"),
|
|
967
|
+
},
|
|
893
968
|
handler: pushHandler,
|
|
894
969
|
riskProfile: { mutates: "external_side_effect", risk: "high", reason: "pushes bundle state to a remote" },
|
|
895
970
|
},
|
|
@@ -907,6 +982,11 @@ exports.bundleToolDefinitions = [
|
|
|
907
982
|
},
|
|
908
983
|
},
|
|
909
984
|
},
|
|
985
|
+
ax: {
|
|
986
|
+
id: "tool:bundle_pull_rebase", group: "turn-bundle", effect: "write",
|
|
987
|
+
when: "Pick this to bring the remote's changes into my bundle; despite its name it merges, the same sync bundle_push runs.",
|
|
988
|
+
errors: syncErrors("bundle_pull_rebase"),
|
|
989
|
+
},
|
|
910
990
|
handler: pullRebaseHandler,
|
|
911
991
|
riskProfile: {
|
|
912
992
|
mutates: ["durable_state_write", "external_side_effect"],
|
|
@@ -5,21 +5,22 @@ const friends_1 = require("@ouro.bot/friends");
|
|
|
5
5
|
const runtime_1 = require("../nerves/runtime");
|
|
6
6
|
const habit_cancel_1 = require("../heart/habits/habit-cancel");
|
|
7
7
|
const semantic_receipts_1 = require("../senses/bluebubbles/semantic-receipts");
|
|
8
|
+
const tools_base_1 = require("./tools-base");
|
|
8
9
|
const CAPTURE_LOCATOR_PATTERN = /^capture:([a-f0-9]{64})$/;
|
|
9
10
|
const ACTOR_AUTHORITY_ERROR = "habit_cancel requires trusted current-ingress actor authority";
|
|
10
11
|
async function requireTrustedCurrentIngressActor(agentRoot, captureKeyHash, context) {
|
|
11
12
|
const capture = (0, semantic_receipts_1.readBlueBubblesSemanticCaptureAtRoot)(agentRoot, captureKeyHash);
|
|
12
13
|
const actor = capture?.event.actor;
|
|
13
14
|
if (!actor || !context?.friendStore)
|
|
14
|
-
throw new Error(ACTOR_AUTHORITY_ERROR);
|
|
15
|
+
throw new Error((0, tools_base_1.withCode)(ACTOR_AUTHORITY_ERROR, "actor-not-trusted"));
|
|
15
16
|
try {
|
|
16
17
|
const friend = await context.friendStore.findByExternalId(actor.provider, actor.externalId);
|
|
17
18
|
if (!friends_1.TRUSTED_LEVELS.has(friend?.trustLevel ?? "stranger")) {
|
|
18
|
-
throw new Error(ACTOR_AUTHORITY_ERROR);
|
|
19
|
+
throw new Error((0, tools_base_1.withCode)(ACTOR_AUTHORITY_ERROR, "actor-not-trusted"));
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
catch {
|
|
22
|
-
throw new Error(ACTOR_AUTHORITY_ERROR);
|
|
23
|
+
throw new Error((0, tools_base_1.withCode)(ACTOR_AUTHORITY_ERROR, "actor-not-trusted"));
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
exports.habitToolDefinitions = [
|
|
@@ -67,13 +68,13 @@ exports.habitToolDefinitions = [
|
|
|
67
68
|
const keys = Object.keys(args);
|
|
68
69
|
const unexpected = keys.find((key) => key !== "habit" && key !== "evidence");
|
|
69
70
|
if (unexpected)
|
|
70
|
-
throw new Error(`unexpected habit_cancel argument: ${unexpected}
|
|
71
|
+
throw new Error((0, tools_base_1.withCode)(`unexpected habit_cancel argument: ${unexpected}`, "bad-argument"));
|
|
71
72
|
if (keys.length !== 2 || typeof args.habit !== "string" || args.habit.trim().length === 0) {
|
|
72
|
-
throw new Error("habit_cancel requires exactly habit and evidence");
|
|
73
|
+
throw new Error((0, tools_base_1.withCode)("habit_cancel requires exactly habit and evidence", "bad-argument"));
|
|
73
74
|
}
|
|
74
75
|
const match = CAPTURE_LOCATOR_PATTERN.exec(args.evidence);
|
|
75
76
|
if (!match)
|
|
76
|
-
throw new Error("habit_cancel evidence must use capture:<sha256>");
|
|
77
|
+
throw new Error((0, tools_base_1.withCode)("habit_cancel evidence must use capture:<sha256>", "bad-argument"));
|
|
77
78
|
const currentIngressEvidence = context?.currentIngressEvidence;
|
|
78
79
|
if (!currentIngressEvidence
|
|
79
80
|
|| Object.keys(currentIngressEvidence).length !== 3
|
|
@@ -81,12 +82,12 @@ exports.habitToolDefinitions = [
|
|
|
81
82
|
|| currentIngressEvidence.schemaVersion !== 1
|
|
82
83
|
|| currentIngressEvidence.provider !== "bluebubbles"
|
|
83
84
|
|| !/^[a-f0-9]{64}$/.test(currentIngressEvidence.captureKeyHash))
|
|
84
|
-
throw new Error("habit_cancel requires authoritative current ingress evidence");
|
|
85
|
+
throw new Error((0, tools_base_1.withCode)("habit_cancel requires authoritative current ingress evidence", "no-ingress-evidence"));
|
|
85
86
|
if (currentIngressEvidence.captureKeyHash !== match[1]) {
|
|
86
|
-
throw new Error("habit_cancel evidence mismatch with current ingress evidence");
|
|
87
|
+
throw new Error((0, tools_base_1.withCode)("habit_cancel evidence mismatch with current ingress evidence", "evidence-mismatch"));
|
|
87
88
|
}
|
|
88
89
|
if (!context?.agentRoot)
|
|
89
|
-
throw new Error("habit_cancel requires an agent root");
|
|
90
|
+
throw new Error((0, tools_base_1.withCode)("habit_cancel requires an agent root", "no-agent-root"));
|
|
90
91
|
await requireTrustedCurrentIngressActor(context.agentRoot, currentIngressEvidence.captureKeyHash, context);
|
|
91
92
|
const receipt = await (0, habit_cancel_1.cancelHabit)({
|
|
92
93
|
agentRoot: context.agentRoot,
|
|
@@ -99,5 +100,12 @@ exports.habitToolDefinitions = [
|
|
|
99
100
|
});
|
|
100
101
|
return receipt.acknowledgement;
|
|
101
102
|
},
|
|
103
|
+
ax: { id: "tool:habit_cancel", group: "turn-habits", when: "Pick this when the message that started this turn asks to stop a named habit for good, citing that message's own capture.", effect: "write", destructive: true, errors: [
|
|
104
|
+
{ code: "bad-argument", means: "An argument other than habit and evidence was passed, habit is empty, or evidence isn't capture:<sha256>.", fix: "Call again with only habit and evidence, with evidence set to this turn's capture locator." },
|
|
105
|
+
{ code: "no-ingress-evidence", means: "This turn didn't start from a captured BlueBubbles message, so nobody's request can authorize it.", fix: "Don't retry; a habit is cancelled only from the person's own message asking for it." },
|
|
106
|
+
{ code: "evidence-mismatch", means: "evidence names a different capture from the message that started this turn.", fix: "Pass this turn's own capture locator; an older message can't authorize a cancel." },
|
|
107
|
+
{ code: "actor-not-trusted", means: "The person who sent the message isn't a trusted friend, or can't be found.", fix: "Don't retry; tell them a trusted friend has to ask for it." },
|
|
108
|
+
{ code: "no-agent-root", means: "The runtime gave this turn no agent home, so no habit can be found.", fix: "Report it to the owner; this is a runtime fault, not something to retry." },
|
|
109
|
+
] },
|
|
102
110
|
},
|
|
103
111
|
];
|
|
@@ -40,6 +40,7 @@ const node_crypto_1 = require("node:crypto");
|
|
|
40
40
|
const identity_1 = require("../heart/identity");
|
|
41
41
|
const runtime_1 = require("../nerves/runtime");
|
|
42
42
|
const socket_client_1 = require("../heart/daemon/socket-client");
|
|
43
|
+
const tools_base_1 = require("./tools-base");
|
|
43
44
|
exports.RESTART_COOLDOWN_MS = 6 * 60 * 60 * 1000;
|
|
44
45
|
function restartCooldownPath(agentName) {
|
|
45
46
|
return path.join((0, identity_1.getAgentStateRoot)(agentName), "daemon", "restart-runtime-cooldown.json");
|
|
@@ -68,7 +69,7 @@ function recordRestart(agentName, nowMs) {
|
|
|
68
69
|
}
|
|
69
70
|
async function restartRuntime(args, agentName, ctx) {
|
|
70
71
|
if (typeof args.reason !== "string" || args.reason.trim().length === 0) {
|
|
71
|
-
return JSON.stringify({ error: "reason is required (one-line audit string)" });
|
|
72
|
+
return JSON.stringify({ error: "reason is required (one-line audit string)", code: "missing-reason" });
|
|
72
73
|
}
|
|
73
74
|
const reason = args.reason.trim();
|
|
74
75
|
if (ctx?.autonomousTurnKind) {
|
|
@@ -80,7 +81,7 @@ async function restartRuntime(args, agentName, ctx) {
|
|
|
80
81
|
});
|
|
81
82
|
return JSON.stringify({
|
|
82
83
|
refused: true,
|
|
83
|
-
code: "
|
|
84
|
+
code: "autonomous-restart-refused",
|
|
84
85
|
error: `restart_runtime is not allowed from an autonomous ${ctx.autonomousTurnKind} turn: restarting the daemon kills in-flight work for every agent and habit. A tool error or missing capability is not evidence of a dead runtime. Record or report the problem (note it, surface it to the owner) instead of restarting.`,
|
|
85
86
|
});
|
|
86
87
|
}
|
|
@@ -89,7 +90,7 @@ async function restartRuntime(args, agentName, ctx) {
|
|
|
89
90
|
if (lastMs !== null && lastMs <= nowMs && nowMs - lastMs < exports.RESTART_COOLDOWN_MS) {
|
|
90
91
|
return JSON.stringify({
|
|
91
92
|
refused: true,
|
|
92
|
-
code: "
|
|
93
|
+
code: "restart-cooldown",
|
|
93
94
|
error: `a restart was already requested ${Math.round((nowMs - lastMs) / 60000)} minutes ago; agent-requested restarts are limited to one per 6 hours. Record or report the problem instead.`,
|
|
94
95
|
retryAfterMs: exports.RESTART_COOLDOWN_MS - (nowMs - lastMs),
|
|
95
96
|
});
|
|
@@ -118,19 +119,20 @@ async function restartRuntime(args, agentName, ctx) {
|
|
|
118
119
|
catch (error) {
|
|
119
120
|
return JSON.stringify({
|
|
120
121
|
error: "failed to reach daemon socket",
|
|
122
|
+
code: "daemon-unreachable",
|
|
121
123
|
detail: error instanceof Error ? error.message : String(error),
|
|
122
124
|
});
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
async function reviveSense(args, agentName) {
|
|
126
128
|
if (args.agent !== undefined) {
|
|
127
|
-
return "cross-agent revive is unsupported; revive_sense can only revive this agent's own senses.";
|
|
129
|
+
return (0, tools_base_1.withCode)("cross-agent revive is unsupported; revive_sense can only revive this agent's own senses.", "cross-agent-unsupported");
|
|
128
130
|
}
|
|
129
131
|
if (typeof args.sense !== "string" || args.sense.trim().length === 0) {
|
|
130
|
-
return JSON.stringify({ error: "sense is required (for example, 'bluebubbles')" });
|
|
132
|
+
return JSON.stringify({ error: "sense is required (for example, 'bluebubbles')", code: "missing-sense" });
|
|
131
133
|
}
|
|
132
134
|
if (typeof args.reason !== "string" || args.reason.trim().length === 0) {
|
|
133
|
-
return JSON.stringify({ error: "reason is required (one-line audit string)" });
|
|
135
|
+
return JSON.stringify({ error: "reason is required (one-line audit string)", code: "missing-reason" });
|
|
134
136
|
}
|
|
135
137
|
const sense = args.sense.trim();
|
|
136
138
|
const reason = args.reason.trim();
|
|
@@ -151,6 +153,7 @@ async function reviveSense(args, agentName) {
|
|
|
151
153
|
if (response.error === "Unknown daemon command kind 'daemon.sense_revive'.") {
|
|
152
154
|
return JSON.stringify({
|
|
153
155
|
error: "daemon does not support this command; try restart_runtime",
|
|
156
|
+
code: "revive-unsupported",
|
|
154
157
|
detail: response.error,
|
|
155
158
|
agent: agentName,
|
|
156
159
|
sense,
|
|
@@ -158,6 +161,7 @@ async function reviveSense(args, agentName) {
|
|
|
158
161
|
}
|
|
159
162
|
return JSON.stringify({
|
|
160
163
|
error: response.error ?? "daemon failed to revive sense",
|
|
164
|
+
code: "revive-failed",
|
|
161
165
|
agent: agentName,
|
|
162
166
|
sense,
|
|
163
167
|
});
|
|
@@ -173,12 +177,15 @@ async function reviveSense(args, agentName) {
|
|
|
173
177
|
catch (error) {
|
|
174
178
|
return JSON.stringify({
|
|
175
179
|
error: "failed to reach daemon socket",
|
|
180
|
+
code: "daemon-unreachable",
|
|
176
181
|
detail: error instanceof Error ? error.message : String(error),
|
|
177
182
|
agent: agentName,
|
|
178
183
|
sense,
|
|
179
184
|
});
|
|
180
185
|
}
|
|
181
186
|
}
|
|
187
|
+
const MISSING_REASON_ERROR = { code: "missing-reason", means: "reason is empty; every restart or revive needs a one-line reason for the audit log.", fix: "Call again with reason saying what is wedged and since when." };
|
|
188
|
+
const DAEMON_UNREACHABLE_ERROR = { code: "daemon-unreachable", means: "The daemon's socket didn't answer, so no command reached it.", fix: "Don't retry in a loop; note the problem for the owner, since the daemon may already be down or restarting." };
|
|
182
189
|
exports.runtimeToolDefinitions = [
|
|
183
190
|
{
|
|
184
191
|
tool: {
|
|
@@ -203,6 +210,12 @@ exports.runtimeToolDefinitions = [
|
|
|
203
210
|
return restartRuntime({ reason: args.reason }, agentName, ctx);
|
|
204
211
|
},
|
|
205
212
|
riskProfile: { mutates: "external_side_effect", risk: "high", reason: "restarts the hosting runtime" },
|
|
213
|
+
ax: { id: "tool:restart_runtime", group: "turn-runtime", when: "Pick this only when the daemon itself is wedged for every chat, such as a jammed recovery queue; never for one failing tool.", effect: "write", errors: [
|
|
214
|
+
MISSING_REASON_ERROR,
|
|
215
|
+
{ code: "autonomous-restart-refused", means: "This is an autonomous turn, such as a habit, and a restart would kill every agent's in-flight work.", fix: "Don't restart; note the problem and surface it to the owner, who can restart from a conversation." },
|
|
216
|
+
{ code: "restart-cooldown", means: "A restart was already requested in the last 6 hours; retryAfterMs says how long is left.", fix: "Don't restart again; note what is still wrong and report it to the owner instead." },
|
|
217
|
+
DAEMON_UNREACHABLE_ERROR,
|
|
218
|
+
] },
|
|
206
219
|
},
|
|
207
220
|
{
|
|
208
221
|
tool: {
|
|
@@ -228,11 +241,20 @@ exports.runtimeToolDefinitions = [
|
|
|
228
241
|
},
|
|
229
242
|
handler: async (args, ctx) => {
|
|
230
243
|
if (ctx?.context?.friend?.trustLevel !== "family") {
|
|
231
|
-
return "revive_sense requires family trust before I can revive runtime senses.";
|
|
244
|
+
return (0, tools_base_1.withCode)("revive_sense requires family trust before I can revive runtime senses.", "family-required");
|
|
232
245
|
}
|
|
233
246
|
const agentName = (0, identity_1.getAgentName)();
|
|
234
247
|
return reviveSense({ agent: args.agent, sense: args.sense, reason: args.reason }, agentName);
|
|
235
248
|
},
|
|
236
249
|
riskProfile: { mutates: "external_side_effect", risk: "high", reason: "revives a managed runtime sense" },
|
|
250
|
+
ax: { id: "tool:revive_sense", group: "turn-runtime", when: "Pick this when one of your own senses, such as bluebubbles, is stuck or failed while the rest of the daemon is fine.", effect: "write", errors: [
|
|
251
|
+
{ code: "family-required", means: "The person in this conversation isn't family, and only family may revive senses.", fix: "Don't retry; tell the person a family member has to ask for this." },
|
|
252
|
+
{ code: "cross-agent-unsupported", means: "agent was passed, but revive_sense only revives this agent's own senses.", fix: "Call again without agent; another agent's sense is revived from that agent." },
|
|
253
|
+
{ code: "missing-sense", means: "sense is empty.", fix: "Call again with the sense's name, such as bluebubbles." },
|
|
254
|
+
MISSING_REASON_ERROR,
|
|
255
|
+
{ code: "revive-unsupported", means: "The running daemon is too old to revive one sense.", fix: "Use restart_runtime instead, if a restart is justified." },
|
|
256
|
+
{ code: "revive-failed", means: "The daemon refused the revive; error gives its reason, such as no sense by that name.", fix: "Check the sense's name in the error and the daemon's status, then report it if the name is right." },
|
|
257
|
+
DAEMON_UNREACHABLE_ERROR,
|
|
258
|
+
] },
|
|
237
259
|
},
|
|
238
260
|
];
|
|
@@ -68,16 +68,26 @@ async function targetFor(ctx, args) {
|
|
|
68
68
|
(0, target_binding_1.assertBoundShepherdTarget)(ctx.currentShepherdSurface, found.id, host.name);
|
|
69
69
|
return { target: live.find(t => t.session === found.id), live };
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
/** A guidance tool's card: the family gate every one shares, then its own failure and what to do about it. */
|
|
72
|
+
function card(name, when, failed, mutates = false) {
|
|
73
|
+
const errors = [
|
|
74
|
+
{ code: "family-only", means: "The person in this conversation isn't a real family member, so Shepherd's private guidance stays closed.", fix: `Tell them ${name} is only for the family; change nothing.` },
|
|
75
|
+
{ code: "no-agent-runtime", means: "The call ran outside an agent's runtime, so there is no guidance store to use.", fix: `Don't retry; report that ${name} was called without an agent runtime.` },
|
|
76
|
+
{ code: "guidance-failed", ...failed },
|
|
77
|
+
];
|
|
78
|
+
return { id: `tool:${name}`, group: "turn-shepherd", when, effect: mutates ? "write" : "read", errors, ...(mutates ? { idempotent: true } : {}) };
|
|
79
|
+
}
|
|
80
|
+
function definition(name, description, ax, properties, required, run, mutates = false) {
|
|
72
81
|
return {
|
|
73
82
|
tool: { type: "function", function: { name, description, parameters: { type: "object", properties, required, additionalProperties: false } } },
|
|
83
|
+
ax,
|
|
74
84
|
handler: async (args, ctx) => {
|
|
75
85
|
// Same real-family gate as shepherd_send, including rejection of the private runtime's family self.
|
|
76
86
|
const friend = ctx?.context?.friend;
|
|
77
87
|
if (!friend || friend.trustLevel !== "family" || !friend.id || friend.id === tools_base_1.SELF_FRIEND_ID)
|
|
78
|
-
return json({ error: "Shepherd private guidance is only for a real family member in this conversation" });
|
|
88
|
+
return json({ error: "Shepherd private guidance is only for a real family member in this conversation", code: "family-only" });
|
|
79
89
|
if (!ctx?.agentRoot || !ctx.agentName)
|
|
80
|
-
return json({ error: "Shepherd guidance needs an agent runtime" });
|
|
90
|
+
return json({ error: "Shepherd guidance needs an agent runtime", code: "no-agent-runtime" });
|
|
81
91
|
try {
|
|
82
92
|
const boundDefault = name === "shepherd_correct" && !text(args.session) && !text(args.return_id) && ctx.currentShepherdSurface;
|
|
83
93
|
const request = { actorId: friend.id, requestId: text(args.request_id), requestFingerprint: fingerprint(name, boundDefault ? { ...args, session: boundDefault.id, host: boundDefault.host } : args) };
|
|
@@ -96,7 +106,7 @@ function definition(name, description, properties, required, run, mutates = fals
|
|
|
96
106
|
catch (error) {
|
|
97
107
|
const message = (0, redact_1.redactSecrets)(error instanceof Error ? error.message : String(error));
|
|
98
108
|
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "repertoire", event: "repertoire.shepherd_guidance_tool_error", message: "private Shepherd guidance tool failed", meta: { tool: name, error: "private_guidance_operation_failed" } });
|
|
99
|
-
return json({ error: message });
|
|
109
|
+
return json({ error: message, code: "guidance-failed" });
|
|
100
110
|
}
|
|
101
111
|
},
|
|
102
112
|
summaryKeys: [],
|
|
@@ -104,7 +114,7 @@ function definition(name, description, properties, required, run, mutates = fals
|
|
|
104
114
|
};
|
|
105
115
|
}
|
|
106
116
|
exports.shepherdGuidanceToolDefinitions = [
|
|
107
|
-
definition("shepherd_history", "Read private Shepherd return history with stable return IDs, actual judgment/reply/outcome and your own ownerNotice receipts when tracked. Historical, not current status; a vanished terminal remains readable. The session filter is a stable ID, not a short ref. Use to understand 'that was wrong because...' before correcting it, or to check whether a notice was sent. Use displayId as the human-facing return label; never invent a shortened ID suffix. Mutations require the exact full id, not displayId. ownerNotice.state sent means transport acceptance, not proof the human read it; pending awaits a safe retry; unknown may already have arrived and must not be blindly replayed. messageId is the activity ID returned by transport. ownerNotice null means no receipt recorded for this recipient, not proof of non-delivery. ownerNoticeError explicitly identifies unavailable receipt evidence. Never types into a terminal.", targetProperties, [], async (args, ctx, request) => {
|
|
117
|
+
definition("shepherd_history", "Read private Shepherd return history with stable return IDs, actual judgment/reply/outcome and your own ownerNotice receipts when tracked. Historical, not current status; a vanished terminal remains readable. The session filter is a stable ID, not a short ref. Use to understand 'that was wrong because...' before correcting it, or to check whether a notice was sent. Use displayId as the human-facing return label; never invent a shortened ID suffix. Mutations require the exact full id, not displayId. ownerNotice.state sent means transport acceptance, not proof the human read it; pending awaits a safe retry; unknown may already have arrived and must not be blindly replayed. messageId is the activity ID returned by transport. ownerNotice null means no receipt recorded for this recipient, not proof of non-delivery. ownerNoticeError explicitly identifies unavailable receipt evidence. Never types into a terminal.", card("shepherd_history", "Pick this to look back at what Shepherd judged and replied in a session, even one that closed, before anyone corrects it.", { means: "The history couldn't be read; the error says why, such as a session not bound to this chat.", fix: "Drop the session filter, or use the stable id from an earlier shepherd_history, and call again." }), targetProperties, [], async (args, ctx, request) => {
|
|
108
118
|
const session = text(args.session) || ctx.currentShepherdSurface?.id;
|
|
109
119
|
const host = text(args.host) || ctx.currentShepherdSurface?.host;
|
|
110
120
|
if (session)
|
|
@@ -130,7 +140,7 @@ exports.shepherdGuidanceToolDefinitions = [
|
|
|
130
140
|
return { returns, ownerNoticeError: message };
|
|
131
141
|
}
|
|
132
142
|
}),
|
|
133
|
-
definition("shepherd_correct", "Record the human's post-action correction ('that was wrong because…') or prospective instruction. Optionally learn a principle for 'in future…'. A return_id must name a real history entry; omit it for a prospective instruction, never fabricate one. Session scope is the default; project is the exact recorded folder and optional task; global only when the human deliberately generalizes. Feedback <=2000 characters; principle <=1000; at most 20 active rules. This is not an approval gate and never sends anything. For requested immediate steering use existing shepherd_send.", {
|
|
143
|
+
definition("shepherd_correct", "Record the human's post-action correction ('that was wrong because…') or prospective instruction. Optionally learn a principle for 'in future…'. A return_id must name a real history entry; omit it for a prospective instruction, never fabricate one. Session scope is the default; project is the exact recorded folder and optional task; global only when the human deliberately generalizes. Feedback <=2000 characters; principle <=1000; at most 20 active rules. This is not an approval gate and never sends anything. For requested immediate steering use existing shepherd_send.", card("shepherd_correct", "Pick this when the human says Shepherd got something wrong or tells it how to behave next time; shepherd_send steers now.", { means: "Nothing was recorded; the error says why: an unknown return_id or session, a reused request_id, or text over its limit.", fix: "Fix what the error names (take ids from shepherd_history) and call again with a new request_id." }, true), {
|
|
134
144
|
...targetProperties, ...requestProperty,
|
|
135
145
|
return_id: stringProperty("Real stable return ID from shepherd_history, if correcting an actual judgment."),
|
|
136
146
|
feedback: stringProperty("The human's explanation or prospective instruction, at most 2000 characters."),
|
|
@@ -145,7 +155,7 @@ exports.shepherdGuidanceToolDefinitions = [
|
|
|
145
155
|
...(args.scope !== undefined ? { scope: args.scope } : {}),
|
|
146
156
|
}, live);
|
|
147
157
|
}, true),
|
|
148
|
-
definition("shepherd_guidance", "Inspect what Shepherd learned ('what did you learn?'). With a session, returns revision, pause and applicable active principles with IDs, scopes and operator provenance. Omit session to inspect all active principles and pauses, including their exact targets. No send.", targetProperties, [], async (args, ctx) => {
|
|
158
|
+
definition("shepherd_guidance", "Inspect what Shepherd learned ('what did you learn?'). With a session, returns revision, pause and applicable active principles with IDs, scopes and operator provenance. Omit session to inspect all active principles and pauses, including their exact targets. No send.", card("shepherd_guidance", "Pick this when the human asks what Shepherd has learned, or before you change or forget one of its preferences.", { means: "The guidance for that target couldn't be read; the error says why, such as an unknown session.", fix: "Call again without session to see every active principle and pause." }), targetProperties, [], async (args, ctx) => {
|
|
149
159
|
if (args.session === undefined && !ctx.currentShepherdSurface) {
|
|
150
160
|
const state = (0, guidance_1.readGuidance)(ctx.agentRoot);
|
|
151
161
|
return { revision: state.revision, principles: state.principles.filter(p => p.active), pauses: state.pauses.filter(p => p.paused) };
|
|
@@ -153,18 +163,20 @@ exports.shepherdGuidanceToolDefinitions = [
|
|
|
153
163
|
const { target } = await targetFor(ctx, args);
|
|
154
164
|
return (0, guidance_1.applicableGuidance)((0, guidance_1.readGuidance)(ctx.agentRoot), target);
|
|
155
165
|
}),
|
|
156
|
-
definition("shepherd_update_principle", "Change a learned preference ('change that') by its principle ID. Keeps its existing scope, never silently generalizes it. No send.", {
|
|
166
|
+
definition("shepherd_update_principle", "Change a learned preference ('change that') by its principle ID. Keeps its existing scope, never silently generalizes it. No send.", card("shepherd_update_principle", "Pick this when the human wants a preference Shepherd already holds reworded; for a new one use shepherd_correct.", { means: "The preference wasn't changed; the error says why: an unknown or inactive principle_id, empty or long text, or a reused request_id.", fix: "Take the id from shepherd_guidance, keep text under 1000 characters, and call with a new request_id." }, true), {
|
|
157
167
|
...requestProperty, principle_id: stringProperty("Active principle ID from shepherd_guidance."), text: stringProperty("Replacement preference, nonempty and at most 1000 characters."),
|
|
158
168
|
}, ["request_id", "principle_id", "text"], async (args, ctx, request) => (0, guidance_1.updateShepherdPrinciple)(ctx.agentRoot, {
|
|
159
169
|
...request, principleId: text(args.principle_id), text: typeof args.text === "string" ? args.text : "",
|
|
160
170
|
}), true),
|
|
161
|
-
definition("shepherd_forget_principle", "Forget a learned preference ('forget that') by its ID. Removes only that preference from future judgments but retains the private operator trail. Built-in judgment policy, including legitimate outside dependency waits, and all existing guards remain unchanged: forgetting does not make dependency waits premature or delivered done. No send.", {
|
|
171
|
+
definition("shepherd_forget_principle", "Forget a learned preference ('forget that') by its ID. Removes only that preference from future judgments but retains the private operator trail. Built-in judgment policy, including legitimate outside dependency waits, and all existing guards remain unchanged: forgetting does not make dependency waits premature or delivered done. No send.", card("shepherd_forget_principle", "Pick this when the human wants Shepherd to drop a learned preference entirely, keeping the record of who set it.", { means: "Nothing was forgotten; the error says why: an unknown or inactive principle_id, or a reused request_id.", fix: "Take the principle id from shepherd_guidance and call again with a new request_id." }, true), {
|
|
162
172
|
...requestProperty, principle_id: stringProperty("Active principle ID from shepherd_guidance."),
|
|
163
173
|
}, ["request_id", "principle_id"], async (args, ctx, request) => (0, guidance_1.forgetShepherdPrinciple)(ctx.agentRoot, {
|
|
164
174
|
...request, principleId: text(args.principle_id),
|
|
165
175
|
}), true),
|
|
166
176
|
...["pause", "resume"].map(action => definition(`shepherd_${action}`, action === "pause" ? "Leave this one alone: pause automatic Shepherd replies for this session only, durably. Independent judgment/owner notices remain. Never interrupts or types into the terminal."
|
|
167
|
-
: "Resume automatic Shepherd replies for this paused session. All focus, screen, syntax and loop guards still apply; resume is not an immediate send.",
|
|
177
|
+
: "Resume automatic Shepherd replies for this paused session. All focus, screen, syntax and loop guards still apply; resume is not an immediate send.", action === "pause"
|
|
178
|
+
? card("shepherd_pause", "Pick this when the human says to leave one session alone, so Shepherd stops answering it until resumed.", { means: "The session wasn't paused; the error says why, such as an unknown session or a reused request_id.", fix: "Name the session from shepherd_overview or shepherd_history and call with a new request_id." }, true)
|
|
179
|
+
: card("shepherd_resume", "Pick this when the human wants Shepherd answering a session it was told to leave alone again.", { means: "The session wasn't resumed; the error says why, such as an unknown session or a reused request_id.", fix: "Check the paused session's id with shepherd_guidance and call with a new request_id." }, true), { ...targetProperties, ...requestProperty }, ["session", "request_id"], async (args, ctx, request) => {
|
|
168
180
|
const { target, live } = await targetFor(ctx, args);
|
|
169
181
|
return (0, guidance_1.setShepherdSessionPause)(ctx.agentRoot, { ...request, target, paused: action === "pause" }, live);
|
|
170
182
|
}, true)),
|
|
@@ -85,10 +85,10 @@ function hostFor(agentName) {
|
|
|
85
85
|
}
|
|
86
86
|
async function withHost(tool, ctx, run) {
|
|
87
87
|
if (!ctx?.agentName || !ctx.agentRoot)
|
|
88
|
-
return JSON.stringify({ error: "the Shepherd tools need an agent runtime" });
|
|
88
|
+
return JSON.stringify({ error: "the Shepherd tools need an agent runtime", code: "no-agent-runtime" });
|
|
89
89
|
const host = hostFor(ctx.agentName);
|
|
90
90
|
if (typeof host === "string")
|
|
91
|
-
return JSON.stringify({ error: host });
|
|
91
|
+
return JSON.stringify({ error: host, code: "host-unconfigured" });
|
|
92
92
|
try {
|
|
93
93
|
if (ctx.currentShepherdSurface) {
|
|
94
94
|
const bound = ctx.currentShepherdSurface;
|
|
@@ -102,9 +102,17 @@ async function withHost(tool, ctx, run) {
|
|
|
102
102
|
}
|
|
103
103
|
catch (error) {
|
|
104
104
|
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "repertoire", event: "repertoire.shepherd_tool_error", message: "Shepherd tool call failed", meta: { tool, error: error.message } });
|
|
105
|
-
return JSON.stringify({ error: error.message });
|
|
105
|
+
return JSON.stringify({ error: error.message, code: "host-failed" });
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
+
/** The errors every Shepherd terminal tool can end with, from `withHost`; `tool` is named in each fix. */
|
|
109
|
+
function hostErrors(tool, retry) {
|
|
110
|
+
return [
|
|
111
|
+
{ code: "no-agent-runtime", means: "The call ran outside an agent's runtime, so there is no terminal host to ask.", fix: `Don't retry; report that ${tool} was called without an agent runtime.` },
|
|
112
|
+
{ code: "host-unconfigured", means: "This machine has no Shepherd terminal host connection set up for the agent.", fix: `Tell the human Shepherd isn't connected here; ${tool} works once it is.` },
|
|
113
|
+
{ code: "host-failed", means: "The terminal host refused or failed the call; the error says why (often a session that is gone or not bound to this chat).", fix: retry },
|
|
114
|
+
];
|
|
115
|
+
}
|
|
108
116
|
async function currentScreen(host, session, maxChars) {
|
|
109
117
|
try {
|
|
110
118
|
const raw = await host.read(session, OVERVIEW_READ_LINES);
|
|
@@ -144,6 +152,11 @@ exports.shepherdOverviewToolDefinition = {
|
|
|
144
152
|
})),
|
|
145
153
|
};
|
|
146
154
|
}),
|
|
155
|
+
ax: {
|
|
156
|
+
id: "tool:shepherd_overview", group: "turn-shepherd", effect: "read",
|
|
157
|
+
when: "Pick this first when asked what the coding agents on this machine are doing; it covers every terminal in one call.",
|
|
158
|
+
errors: hostErrors("shepherd_overview", "Say which part failed, then call shepherd_overview once more; don't guess the missing rows."),
|
|
159
|
+
},
|
|
147
160
|
summaryKeys: [],
|
|
148
161
|
riskProfile: { mutates: "none", risk: "low" },
|
|
149
162
|
};
|
|
@@ -171,7 +184,7 @@ exports.shepherdReadToolDefinition = {
|
|
|
171
184
|
handler: (args, ctx) => {
|
|
172
185
|
const session = text(args.session).trim();
|
|
173
186
|
if (!session)
|
|
174
|
-
return Promise.resolve(JSON.stringify({ error: "name a session id or ref from shepherd_overview" }));
|
|
187
|
+
return Promise.resolve(JSON.stringify({ error: "name a session id or ref from shepherd_overview", code: "session-required" }));
|
|
175
188
|
return withHost("shepherd_read", ctx, async (host) => {
|
|
176
189
|
(0, target_binding_1.assertBoundShepherdTarget)(ctx?.currentShepherdSurface, session, host.name);
|
|
177
190
|
const lines = boundedLines(args.lines);
|
|
@@ -181,6 +194,14 @@ exports.shepherdReadToolDefinition = {
|
|
|
181
194
|
return { session, text: screen.slice(-READ_MAX_CHARS), truncated: screen.length > READ_MAX_CHARS, screen: (0, redact_1.screenFingerprint)(raw) };
|
|
182
195
|
});
|
|
183
196
|
},
|
|
197
|
+
ax: {
|
|
198
|
+
id: "tool:shepherd_read", group: "turn-shepherd", effect: "read",
|
|
199
|
+
when: "Pick this to look closely at one terminal after shepherd_overview, and always just before pressing a choosing key with shepherd_send.",
|
|
200
|
+
errors: [
|
|
201
|
+
{ code: "session-required", means: "No session id or ref was given.", fix: "Take the session's ref (surface:12) from shepherd_overview and pass it as session." },
|
|
202
|
+
...hostErrors("shepherd_read", "Call shepherd_overview to see whether that terminal still exists, then read the one it lists."),
|
|
203
|
+
],
|
|
204
|
+
},
|
|
184
205
|
summaryKeys: ["session"],
|
|
185
206
|
riskProfile: { mutates: "none", risk: "low" },
|
|
186
207
|
};
|
|
@@ -208,21 +229,30 @@ exports.shepherdSignalToolDefinition = {
|
|
|
208
229
|
const status = text(args.status).trim();
|
|
209
230
|
const title = text(args.notify_title).trim();
|
|
210
231
|
if (!session)
|
|
211
|
-
return Promise.resolve(JSON.stringify({ error: "name a session id or ref from shepherd_overview" }));
|
|
232
|
+
return Promise.resolve(JSON.stringify({ error: "name a session id or ref from shepherd_overview", code: "session-required" }));
|
|
212
233
|
if (status.length > STATUS_MAX_CHARS || /[\r\n]/.test(status))
|
|
213
|
-
return Promise.resolve(JSON.stringify({ error: `status must be one line of at most ${STATUS_MAX_CHARS} characters
|
|
234
|
+
return Promise.resolve(JSON.stringify({ error: `status must be one line of at most ${STATUS_MAX_CHARS} characters`, code: "status-too-long" }));
|
|
214
235
|
return withHost("shepherd_signal", ctx, async (host) => {
|
|
215
236
|
(0, target_binding_1.assertBoundShepherdTarget)(ctx?.currentShepherdSurface, session, host.name);
|
|
216
237
|
await host.signal(session, status || null, title ? { title, body: text(args.notify_body) } : undefined);
|
|
217
238
|
return { session, status: status ? "set" : "cleared", notified: !!title };
|
|
218
239
|
});
|
|
219
240
|
},
|
|
241
|
+
ax: {
|
|
242
|
+
id: "tool:shepherd_signal", group: "turn-shepherd", effect: "write",
|
|
243
|
+
when: "Pick this to leave the human a status line or desktop alert beside a terminal without typing into it; shepherd_send types.",
|
|
244
|
+
errors: [
|
|
245
|
+
{ code: "session-required", means: "No session id or ref was given.", fix: "Pass the ref from shepherd_overview of the terminal the status belongs to." },
|
|
246
|
+
{ code: "status-too-long", means: `status is longer than ${STATUS_MAX_CHARS} characters or has a line break.`, fix: `Shorten status to one line of at most ${STATUS_MAX_CHARS} characters; put detail in notify_body.` },
|
|
247
|
+
...hostErrors("shepherd_signal", "Call shepherd_overview and signal a terminal it still lists."),
|
|
248
|
+
],
|
|
249
|
+
},
|
|
220
250
|
summaryKeys: ["session", "status"],
|
|
221
251
|
riskProfile: { mutates: "external_side_effect", risk: "high", reason: "changes what the terminal host shows the human (a status line or a desktop notification)" },
|
|
222
252
|
};
|
|
223
|
-
function refused(reason, meta) {
|
|
253
|
+
function refused(reason, code, meta) {
|
|
224
254
|
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "repertoire", event: "repertoire.shepherd_send_refused", message: "refused to type into a terminal", meta: { ...meta, reason } });
|
|
225
|
-
return { error: reason };
|
|
255
|
+
return { error: reason, code };
|
|
226
256
|
}
|
|
227
257
|
exports.shepherdSendToolDefinition = {
|
|
228
258
|
tool: {
|
|
@@ -250,31 +280,31 @@ exports.shepherdSendToolDefinition = {
|
|
|
250
280
|
const seen = text(args.screen).trim();
|
|
251
281
|
const friend = ctx?.context?.friend;
|
|
252
282
|
const meta = { session, chars: line.length, key: key || null, friendId: friend?.id ?? null };
|
|
253
|
-
const refuse = (reason) => Promise.resolve(JSON.stringify(refused(reason, meta)));
|
|
283
|
+
const refuse = (reason, code) => Promise.resolve(JSON.stringify(refused(reason, code, meta)));
|
|
254
284
|
// The private runtime talks to itself as a family "friend"; only a real family member's request may type.
|
|
255
285
|
if (!friend || friend.trustLevel !== "family" || friend.id === tools_base_1.SELF_FRIEND_ID)
|
|
256
|
-
return refuse("shepherd_send types only for a family member who asked for it in this conversation");
|
|
286
|
+
return refuse("shepherd_send types only for a family member who asked for it in this conversation", "family-only");
|
|
257
287
|
if (!session)
|
|
258
|
-
return refuse("name a session id or ref from shepherd_overview");
|
|
288
|
+
return refuse("name a session id or ref from shepherd_overview", "session-required");
|
|
259
289
|
if (!line === !key)
|
|
260
|
-
return refuse("give exactly one of text or key");
|
|
290
|
+
return refuse("give exactly one of text or key", "text-or-key");
|
|
261
291
|
if (key && !exports.SEND_KEYS.includes(key))
|
|
262
|
-
return refuse(`key must be one of ${exports.SEND_KEYS.join(", ")}
|
|
292
|
+
return refuse(`key must be one of ${exports.SEND_KEYS.join(", ")}`, "text-or-key");
|
|
263
293
|
if (line.length > exports.SEND_TEXT_MAX_CHARS)
|
|
264
|
-
return refuse(`text must be at most ${exports.SEND_TEXT_MAX_CHARS} characters
|
|
294
|
+
return refuse(`text must be at most ${exports.SEND_TEXT_MAX_CHARS} characters`, "text-or-key");
|
|
265
295
|
if (/[\p{Cc}\u2028\u2029]/u.test(line))
|
|
266
|
-
return refuse("text must be one line with no control characters; press enter, escape or ctrl-c with key");
|
|
296
|
+
return refuse("text must be one line with no control characters; press enter, escape or ctrl-c with key", "text-or-key");
|
|
267
297
|
if (CHOOSING_KEYS.has(key) && !seen)
|
|
268
|
-
return refuse(`${key} can approve or choose on a prompt, so pass screen from a shepherd_read made just before
|
|
298
|
+
return refuse(`${key} can approve or choose on a prompt, so pass screen from a shepherd_read made just before`, "screen-required");
|
|
269
299
|
return withHost("shepherd_send", ctx, async (host) => {
|
|
270
300
|
(0, target_binding_1.assertBoundShepherdTarget)(ctx?.currentShepherdSurface, session, host.name);
|
|
271
301
|
const target = (await host.list()).find((entry) => entry.id === session || entry.ref === session);
|
|
272
302
|
if (!target)
|
|
273
|
-
return refused(`session ${session} is gone; check shepherd_overview`, meta);
|
|
303
|
+
return refused(`session ${session} is gone; check shepherd_overview`, "session-gone", meta);
|
|
274
304
|
// Read again right before typing, as Shepherd does before its own answers: a gone or changed screen gets nothing.
|
|
275
305
|
const now = (0, redact_1.screenFingerprint)(await host.read(target.id, redact_1.FINGERPRINT_READ_LINES));
|
|
276
306
|
if (seen && seen !== now)
|
|
277
|
-
return refused("the terminal changed since it was read, so nothing was sent; read it again", meta);
|
|
307
|
+
return refused("the terminal changed since it was read, so nothing was sent; read it again", "screen-changed", meta);
|
|
278
308
|
const label = `[${(0, agent_presentation_1.readAgentPresentation)(ctx.agentName, ctx.agentRoot).name} for ${friend.name}]`;
|
|
279
309
|
// The agent sometimes writes the label itself; type it once.
|
|
280
310
|
const typed = key ? null : `${label} ${line.toLowerCase().startsWith(label.toLowerCase()) ? line.slice(label.length).trimStart() : line}`;
|
|
@@ -300,7 +330,7 @@ exports.shepherdSendToolDefinition = {
|
|
|
300
330
|
meta: { ...meta, session: target.id, ref: target.ref, instance: target.instance ?? null, attemptId, attemptedAt, error: message },
|
|
301
331
|
});
|
|
302
332
|
return {
|
|
303
|
-
error: message, session: target.ref, attempted: input,
|
|
333
|
+
error: message, code: "submission-unknown", session: target.ref, attempted: input,
|
|
304
334
|
submission: { state: "unknown", attemptId, attemptedAt, reportedAt: new Date().toISOString(), target: receiptTarget },
|
|
305
335
|
verification, retry,
|
|
306
336
|
};
|
|
@@ -319,6 +349,20 @@ exports.shepherdSendToolDefinition = {
|
|
|
319
349
|
};
|
|
320
350
|
});
|
|
321
351
|
},
|
|
352
|
+
ax: {
|
|
353
|
+
id: "tool:shepherd_send", group: "turn-shepherd", effect: "write",
|
|
354
|
+
when: "Pick this when a family member replies to a Shepherd prompt with a go-ahead, a correction or a stop meant for that coding session.",
|
|
355
|
+
errors: [
|
|
356
|
+
{ code: "family-only", means: "The person in this conversation isn't a family member, so nothing is typed for them.", fix: "Tell them you can't type into terminals for them, and send nothing." },
|
|
357
|
+
{ code: "text-or-key", means: "The call gave both text and key or neither, a key outside the list, or text that is too long or has control characters.", fix: "Send exactly one: a one-line text, or one key from the list (enter, escape and ctrl-c go as key)." },
|
|
358
|
+
{ code: "screen-required", means: "A choosing key (enter, tab, a digit, y or n) came without screen.", fix: "Call shepherd_read on that session and pass its screen value with the key." },
|
|
359
|
+
{ code: "screen-changed", means: "The terminal changed since your read, so nothing was typed.", fix: "Call shepherd_read again, check the prompt is still the one the human answered, then send." },
|
|
360
|
+
{ code: "submission-unknown", means: "The host failed partway, so the input may or may not have arrived.", fix: "Don't resend; call shepherd_read to see whether it landed, and tell the human it's unverified." },
|
|
361
|
+
{ code: "session-required", means: "No session id or ref was given.", fix: "Pass the ref from shepherd_overview of the terminal the human means." },
|
|
362
|
+
{ code: "session-gone", means: "That terminal no longer exists, so nothing was typed.", fix: "Call shepherd_overview, and ask the human which listed terminal they meant." },
|
|
363
|
+
...hostErrors("shepherd_send", "Nothing was typed; call shepherd_overview and shepherd_read before trying again."),
|
|
364
|
+
],
|
|
365
|
+
},
|
|
322
366
|
summaryKeys: ["session", "key"],
|
|
323
367
|
riskProfile: { mutates: "external_side_effect", risk: "high", reason: "types into a coding agent's terminal for the human, which can answer or approve its prompts" },
|
|
324
368
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stewardPolicyToolDefinition = void 0;
|
|
4
|
+
const tools_base_1 = require("./tools-base");
|
|
4
5
|
const steward_policy_1 = require("../heart/steward-policy");
|
|
5
6
|
const runtime_1 = require("../nerves/runtime");
|
|
6
7
|
function arrayArgument(raw, label) {
|
|
7
8
|
if (!raw)
|
|
8
|
-
throw new Error(`${label} is required
|
|
9
|
+
throw new Error((0, tools_base_1.withCode)(`${label} is required`, "bad-argument"));
|
|
9
10
|
const value = JSON.parse(raw);
|
|
10
11
|
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string"))
|
|
11
|
-
throw new Error(`${label} must be a JSON string array
|
|
12
|
+
throw new Error((0, tools_base_1.withCode)(`${label} must be a JSON string array`, "bad-argument"));
|
|
12
13
|
return value;
|
|
13
14
|
}
|
|
14
15
|
exports.stewardPolicyToolDefinition = {
|
|
@@ -42,9 +43,9 @@ exports.stewardPolicyToolDefinition = {
|
|
|
42
43
|
},
|
|
43
44
|
handler: (args, ctx) => {
|
|
44
45
|
if (!ctx?.agentRoot)
|
|
45
|
-
throw new Error("steward policy runtime is unavailable");
|
|
46
|
+
throw new Error((0, tools_base_1.withCode)("steward policy runtime is unavailable", "runtime-unavailable"));
|
|
46
47
|
if (!ctx.relationshipAuthorization)
|
|
47
|
-
throw new Error("steward policy access requires authenticated relationship authority");
|
|
48
|
+
throw new Error((0, tools_base_1.withCode)("steward policy access requires authenticated relationship authority", "relationship-authority-required"));
|
|
48
49
|
if (args.action === "read") {
|
|
49
50
|
(0, runtime_1.emitNervesEvent)({ component: "repertoire", event: "repertoire.steward_policy_tool_call", message: "read steward policy", meta: { action: "read" } });
|
|
50
51
|
return JSON.stringify((0, steward_policy_1.readStewardPolicy)(ctx.agentRoot));
|
|
@@ -52,7 +53,7 @@ exports.stewardPolicyToolDefinition = {
|
|
|
52
53
|
const relationship = ctx.relationshipAuthorization;
|
|
53
54
|
const actor = relationship.actor;
|
|
54
55
|
if (!actor)
|
|
55
|
-
throw new Error("steward policy mutation requires authenticated relationship authority");
|
|
56
|
+
throw new Error((0, tools_base_1.withCode)("steward policy mutation requires authenticated relationship authority", "relationship-authority-required"));
|
|
56
57
|
const { friendId, trustLevel, sessionEventId } = actor;
|
|
57
58
|
const { profileId, requestId } = relationship;
|
|
58
59
|
(0, steward_policy_1.assertNotReplayIdentity)(ctx.agentRoot, [friendId, ctx.delegatedCommand?.delegateFriendId]);
|
|
@@ -68,20 +69,20 @@ exports.stewardPolicyToolDefinition = {
|
|
|
68
69
|
if (trustLevel !== "family" || profileId !== "sanctuary-owner" || typeof requestId !== "string" || !requestId.trim()
|
|
69
70
|
|| typeof sessionKey !== "string" || !sessionKey.trim() || !sessionEventId.trim()
|
|
70
71
|
|| !sessionMatches() || ctx.currentExternalEvent) {
|
|
71
|
-
throw new Error(delegated
|
|
72
|
+
throw new Error((0, tools_base_1.withCode)(delegated
|
|
72
73
|
? "steward policy mutation requires a current admitted delegated owner command"
|
|
73
|
-
: "steward policy mutation requires a current authenticated owner Telegram request and session");
|
|
74
|
+
: "steward policy mutation requires a current authenticated owner Telegram request and session", "owner-request-required"));
|
|
74
75
|
}
|
|
75
76
|
const sourceFor = (raw) => delegated
|
|
76
77
|
? `${delegated.principalName} via ${delegated.delegateName} (delegated)${raw?.trim() ? `: ${raw.trim()}` : ""}`
|
|
77
78
|
: raw ?? "";
|
|
78
79
|
const expectedVersion = args.expectedVersion === undefined ? undefined : Number(args.expectedVersion);
|
|
79
80
|
if (expectedVersion !== undefined && (!Number.isSafeInteger(expectedVersion) || expectedVersion < 0))
|
|
80
|
-
throw new Error("expectedVersion must be a nonnegative integer");
|
|
81
|
+
throw new Error((0, tools_base_1.withCode)("expectedVersion must be a nonnegative integer", "bad-argument"));
|
|
81
82
|
let mutation;
|
|
82
83
|
if (args.action === "set_desired_state") {
|
|
83
84
|
if (args.provenance !== "stated" && args.provenance !== "observed" && args.provenance !== "default")
|
|
84
|
-
throw new Error("desired state provenance is invalid");
|
|
85
|
+
throw new Error((0, tools_base_1.withCode)("desired state provenance is invalid", "bad-argument"));
|
|
85
86
|
mutation = { kind: "set_desired_state", key: args.key ?? "", value: args.value ?? "", provenance: args.provenance, source: sourceFor(args.source), ...(args.expiresAt ? { expiresAt: args.expiresAt } : {}) };
|
|
86
87
|
}
|
|
87
88
|
else if (args.action === "correct_provenance") {
|
|
@@ -89,12 +90,12 @@ exports.stewardPolicyToolDefinition = {
|
|
|
89
90
|
}
|
|
90
91
|
else if (args.action === "grant_routine_action") {
|
|
91
92
|
if (args.provenance !== "stated" && args.provenance !== "installed_explicit_policy")
|
|
92
|
-
throw new Error("routine action provenance is invalid");
|
|
93
|
+
throw new Error((0, tools_base_1.withCode)("routine action provenance is invalid", "bad-argument"));
|
|
93
94
|
const targets = arrayArgument(args.targetsJson, "targetsJson");
|
|
94
95
|
const exclusions = arrayArgument(args.exclusionsJson, "exclusionsJson");
|
|
95
96
|
const verificationRequired = args.verificationRequired;
|
|
96
97
|
if (verificationRequired !== true)
|
|
97
|
-
throw new Error("verificationRequired must be true");
|
|
98
|
+
throw new Error((0, tools_base_1.withCode)("verificationRequired must be true", "bad-argument"));
|
|
98
99
|
mutation = {
|
|
99
100
|
kind: "grant_routine_action",
|
|
100
101
|
key: args.key ?? "",
|
|
@@ -109,18 +110,18 @@ exports.stewardPolicyToolDefinition = {
|
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
112
|
else
|
|
112
|
-
throw new Error("steward policy action is invalid");
|
|
113
|
+
throw new Error((0, tools_base_1.withCode)("steward policy action is invalid", "bad-argument"));
|
|
113
114
|
const agentRoot = ctx.agentRoot;
|
|
114
115
|
return Promise.resolve(relationship.authorizeTool("steward_policy_manage", args)).then((authorization) => {
|
|
115
116
|
if (!authorization.allowed)
|
|
116
|
-
throw new Error(`steward policy authorization denied: ${authorization.reason}
|
|
117
|
+
throw new Error((0, tools_base_1.withCode)(`steward policy authorization denied: ${authorization.reason}`, "authorization-denied"));
|
|
117
118
|
if (typeof authorization.profileVersion !== "number" || !Number.isSafeInteger(authorization.profileVersion) || authorization.profileVersion < 1 || !authorization.receiptId.trim()) {
|
|
118
|
-
throw new Error("steward policy owner authorization is not versioned");
|
|
119
|
+
throw new Error((0, tools_base_1.withCode)("steward policy owner authorization is not versioned", "authorization-unversioned"));
|
|
119
120
|
}
|
|
120
121
|
if (ctx.relationshipAuthorization !== relationship || relationship.profileId !== profileId || relationship.requestId !== requestId
|
|
121
122
|
|| relationship.actor?.friendId !== friendId || relationship.actor.trustLevel !== trustLevel || relationship.actor.sessionEventId !== sessionEventId
|
|
122
123
|
|| ctx.currentSession?.key !== sessionKey || !sessionMatches() || ctx.currentExternalEvent) {
|
|
123
|
-
throw new Error("steward policy owner authorization or session changed before mutation");
|
|
124
|
+
throw new Error((0, tools_base_1.withCode)("steward policy owner authorization or session changed before mutation", "authorization-changed"));
|
|
124
125
|
}
|
|
125
126
|
const versionBefore = (0, steward_policy_1.readStewardPolicy)(agentRoot).version;
|
|
126
127
|
const result = (0, steward_policy_1.updateStewardPolicy)(agentRoot, {
|
|
@@ -141,6 +142,15 @@ exports.stewardPolicyToolDefinition = {
|
|
|
141
142
|
return JSON.stringify(result);
|
|
142
143
|
});
|
|
143
144
|
},
|
|
145
|
+
ax: { id: "tool:steward_policy_manage", group: "turn-steward", when: "Pick this to read or change what the household steward keeps on or may restart, when the owner states it in this turn.", effect: "write", errors: [
|
|
146
|
+
{ code: "runtime-unavailable", means: "The runtime gave this turn no agent home, so there is no policy to open.", fix: "Report it to the owner; this is a runtime fault, not something to retry." },
|
|
147
|
+
{ code: "relationship-authority-required", means: "This turn has no authenticated relationship, such as the owner's Telegram chat, behind it.", fix: "Don't retry here; the policy is read or changed only in an authenticated owner conversation." },
|
|
148
|
+
{ code: "owner-request-required", means: "A change needs the owner's own current Telegram request, or an admitted delegated command, and this turn is neither.", fix: "Read the policy instead, or ask the owner to state the change in their Telegram chat." },
|
|
149
|
+
{ code: "bad-argument", means: "action, provenance, expectedVersion, a JSON list or verificationRequired isn't an allowed value; the text names it.", fix: "Correct the argument the text names; send targetsJson and exclusionsJson as JSON arrays of names." },
|
|
150
|
+
{ code: "authorization-denied", means: "The owner's authorization for this exact change was refused; the text gives the reason.", fix: "Tell the owner what was refused and why, and change nothing." },
|
|
151
|
+
{ code: "authorization-unversioned", means: "The authorization came back without a profile version or receipt, so the change can't be audited.", fix: "Report it to the owner; don't retry the change." },
|
|
152
|
+
{ code: "authorization-changed", means: "The owner's session or authorization changed while the change was being checked.", fix: "Read the policy again and redo the change in the owner's current turn." },
|
|
153
|
+
] },
|
|
144
154
|
riskProfile: (args) => args.action === "read"
|
|
145
155
|
? { mutates: "none", risk: "low" }
|
|
146
156
|
: { mutates: "durable_state_write", risk: "high", reason: "updates typed household steward policy under current authenticated owner authority" },
|
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.1316",
|
|
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.1316",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@ouro.bot/friends"
|
|
12
12
|
],
|