@ouro.bot/cli 0.1.0-alpha.1313 → 0.1.0-alpha.1315
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-house-care.js +23 -7
- package/dist/repertoire/tools-sanctuary-host.js +14 -3
- package/dist/repertoire/tools-shepherd-guidance.js +22 -10
- package/dist/repertoire/tools-shepherd.js +63 -19
- package/dist/repertoire/tools-unraid.js +91 -23
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -64,12 +64,17 @@ exports.houseSweepToolDefinition = {
|
|
|
64
64
|
},
|
|
65
65
|
handler: async (_args, ctx) => {
|
|
66
66
|
if (!ctx?.agentRoot)
|
|
67
|
-
return JSON.stringify({ error: "house sweep runtime is unavailable" });
|
|
67
|
+
return JSON.stringify({ error: "house sweep runtime is unavailable", code: "sweep-runtime-missing" });
|
|
68
68
|
if (sweepYieldsToReplay(ctx, (injected.now ?? Date.now)()))
|
|
69
69
|
return REPLAY_YIELD;
|
|
70
70
|
const report = await (0, house_sweep_1.runHouseSweep)({ agentRoot: ctx.agentRoot, sanctuary: ctx.sanctuary, replay: replayAsker(ctx), now: injected.now, ...injected.sweepDeps });
|
|
71
71
|
return JSON.stringify(report);
|
|
72
72
|
},
|
|
73
|
+
ax: {
|
|
74
|
+
id: "tool:house_sweep", group: "turn-sanctuary", effect: "write",
|
|
75
|
+
when: "Pick this for a whole-house check in one call, on the daily await or when asked; for one area, the unraid_ and sanctuary_ reads go deeper.",
|
|
76
|
+
errors: [{ code: "sweep-runtime-missing", means: "This turn has no agent bundle, so there's no house to sweep.", fix: "Tell the owner the sweep can't run in this turn; don't send a digest." }],
|
|
77
|
+
},
|
|
73
78
|
summaryKeys: [],
|
|
74
79
|
riskProfile: { mutates: "none", risk: "low" },
|
|
75
80
|
};
|
|
@@ -93,7 +98,7 @@ exports.houseDigestToolDefinition = {
|
|
|
93
98
|
handler: async (args, ctx) => {
|
|
94
99
|
const agentRoot = ctx?.agentRoot;
|
|
95
100
|
if (!agentRoot)
|
|
96
|
-
return JSON.stringify({ error: "house sweep runtime is unavailable" });
|
|
101
|
+
return JSON.stringify({ error: "house sweep runtime is unavailable", code: "sweep-runtime-missing" });
|
|
97
102
|
const rawIds = args.finding_ids;
|
|
98
103
|
const ids = Array.isArray(rawIds) ? [...new Set(rawIds.filter((id) => typeof id === "string" && id.length > 0))] : [];
|
|
99
104
|
if (ids.length === 0)
|
|
@@ -103,11 +108,11 @@ exports.houseDigestToolDefinition = {
|
|
|
103
108
|
// The digest comes only from the sweep THIS process ran. Files under state/house-sweep/ are writable by the resident's uid: untrusted bookkeeping, never a source of owner-facing text.
|
|
104
109
|
const last = (0, house_sweep_1.recallSweep)(agentRoot, scope);
|
|
105
110
|
if (!last)
|
|
106
|
-
return JSON.stringify({ sent: false, error: "no sweep has run in this session: run house_sweep first and use its finding ids." });
|
|
111
|
+
return JSON.stringify({ sent: false, error: "no sweep has run in this session: run house_sweep first and use its finding ids.", code: "no-sweep-yet" });
|
|
107
112
|
const known = new Map(last.map((finding) => [finding.id, finding]));
|
|
108
113
|
const unknown = ids.filter((id) => !known.has(id));
|
|
109
114
|
if (unknown.length > 0)
|
|
110
|
-
return JSON.stringify({ sent: false, error: `unknown finding ids: ${unknown.join(", ")}. Run house_sweep first and use its ids
|
|
115
|
+
return JSON.stringify({ sent: false, error: `unknown finding ids: ${unknown.join(", ")}. Run house_sweep first and use its ids.`, code: "unknown-finding" });
|
|
111
116
|
const chosen = ids.map((id) => known.get(id));
|
|
112
117
|
const rawLead = args.lead_in;
|
|
113
118
|
const leadIn = typeof rawLead === "string" ? rawLead.trim() : "";
|
|
@@ -143,7 +148,7 @@ exports.houseDigestToolDefinition = {
|
|
|
143
148
|
return entry !== undefined && entry.fingerprint === finding.fingerprint && now - Date.parse(entry.reportedAt) < house_sweep_1.REMIND_DAYS * DAY_MS;
|
|
144
149
|
});
|
|
145
150
|
if (told.length > 0)
|
|
146
|
-
return JSON.stringify({ sent: false, error: `the owner was already told about ${told.map((finding) => finding.id).join(", ")} unchanged in the last ${house_sweep_1.REMIND_DAYS} days; leave ${told.length === 1 ? "it" : "them"} out
|
|
151
|
+
return JSON.stringify({ sent: false, error: `the owner was already told about ${told.map((finding) => finding.id).join(", ")} unchanged in the last ${house_sweep_1.REMIND_DAYS} days; leave ${told.length === 1 ? "it" : "them"} out`, code: "already-told" });
|
|
147
152
|
// Only the daily house-care await's own tick is "scheduled" and takes the one-per-day slot; on-demand digests are limited by the per-finding dedupe above.
|
|
148
153
|
// The package-managed await may run under the owner's own relationship authorization (the live runtime binds it that way), which does not downgrade it;
|
|
149
154
|
// The system await has no relationship coordinates, so the pipeline binds the self friend: no authorization with no friend or the self friend is the managed tick itself.
|
|
@@ -151,7 +156,7 @@ exports.houseDigestToolDefinition = {
|
|
|
151
156
|
const ownerBound = ctx.relationshipAuthorization?.profileId === "sanctuary-owner";
|
|
152
157
|
const kind = isManagedSweepTick(ctx) && (ownerBound || (!ctx.relationshipAuthorization && (!friendId || friendId === tools_base_1.SELF_FRIEND_ID))) ? "scheduled" : "ondemand";
|
|
153
158
|
if (kind === "scheduled" && (0, house_sweep_1.sameUtcDay)(priorStamp, stamp))
|
|
154
|
-
return JSON.stringify({ sent: false, error: "the daily house digest already went out today; at most one scheduled digest is sent per day" });
|
|
159
|
+
return JSON.stringify({ sent: false, error: "the daily house digest already went out today; at most one scheduled digest is sent per day", code: "digest-sent-today" });
|
|
155
160
|
const day = stamp.slice(0, 10);
|
|
156
161
|
// Reserve before sending so a crash or a concurrent turn cannot send twice; a failed send rolls the reservation back.
|
|
157
162
|
const reserved = { ...ledger };
|
|
@@ -163,11 +168,22 @@ exports.houseDigestToolDefinition = {
|
|
|
163
168
|
}
|
|
164
169
|
catch (error) {
|
|
165
170
|
(0, house_sweep_1.writeLedger)(agentRoot, ledger, priorStamp);
|
|
166
|
-
return JSON.stringify({ sent: false, error: `the owner notice could not be sent: ${error instanceof Error ? error.message : String(error)}. Nothing was recorded as told, so the next sweep will try again
|
|
171
|
+
return JSON.stringify({ sent: false, error: `the owner notice could not be sent: ${error instanceof Error ? error.message : String(error)}. Nothing was recorded as told, so the next sweep will try again.`, code: "notice-failed" });
|
|
167
172
|
}
|
|
168
173
|
(0, runtime_1.emitNervesEvent)({ component: "repertoire", event: "repertoire.house_digest_sent", message: "house digest sent to the owner", meta: { findings: ids.length, destination: "owner", kind } });
|
|
169
174
|
return JSON.stringify({ sent: true, destination: "owner", findings: ids.length });
|
|
170
175
|
},
|
|
176
|
+
ax: {
|
|
177
|
+
id: "tool:house_digest_send", group: "turn-sanctuary", effect: "write",
|
|
178
|
+
when: "Pick this after house_sweep for the fresh findings no tool could settle, so the owner hears each once; never for old news.",
|
|
179
|
+
errors: [
|
|
180
|
+
{ code: "no-sweep-yet", means: "No house_sweep has run in this process, so there are no findings to send.", fix: "Call house_sweep, then send its fresh finding ids." },
|
|
181
|
+
{ code: "unknown-finding", means: "A finding id isn't in the latest sweep.", fix: "Copy the ids exactly from the latest house_sweep result." },
|
|
182
|
+
{ code: "already-told", means: "The owner already heard about a finding, unchanged, in the last 7 days.", fix: "Drop those ids and send the rest, or nothing if none are left." },
|
|
183
|
+
{ code: "digest-sent-today", means: "Today's scheduled digest already went out.", fix: "Send nothing more today; the next daily sweep picks it up." },
|
|
184
|
+
{ code: "notice-failed", means: "The owner notice couldn't be sent, and nothing was recorded as told.", fix: "Leave it: the next sweep finds the same findings fresh and tries again." },
|
|
185
|
+
],
|
|
186
|
+
},
|
|
171
187
|
summaryKeys: ["finding_ids"],
|
|
172
188
|
riskProfile: { mutates: "external_side_effect", risk: "high", reason: "sends the owner a Telegram notice" },
|
|
173
189
|
};
|
|
@@ -46,6 +46,7 @@ const session_events_1 = require("../heart/session-events");
|
|
|
46
46
|
const shared_turn_1 = require("../senses/shared-turn");
|
|
47
47
|
const relationship_authorization_1 = require("./relationship-authorization");
|
|
48
48
|
const tool_arguments_1 = require("./tool-arguments");
|
|
49
|
+
const tools_base_1 = require("./tools-base");
|
|
49
50
|
const NAME = "sanctuary_host_execute";
|
|
50
51
|
const bindings = new WeakMap();
|
|
51
52
|
const selections = new WeakMap();
|
|
@@ -54,7 +55,7 @@ class RootHostAuthorizationError extends Error {
|
|
|
54
55
|
exports.RootHostAuthorizationError = RootHostAuthorizationError;
|
|
55
56
|
function requireOwner(condition) {
|
|
56
57
|
if (!condition)
|
|
57
|
-
throw new RootHostAuthorizationError("Sanctuary root host authorization denied");
|
|
58
|
+
throw new RootHostAuthorizationError((0, tools_base_1.withCode)("Sanctuary root host authorization denied", "root-host-denied"));
|
|
58
59
|
}
|
|
59
60
|
function ownerFriend(friend, port) {
|
|
60
61
|
requireOwner(friend?.admissionState === "active" && friend.trustLevel === "family"
|
|
@@ -156,11 +157,21 @@ exports.rootHostToolDefinition = (0, tool_arguments_1.freezeToolValue)({
|
|
|
156
157
|
},
|
|
157
158
|
},
|
|
158
159
|
},
|
|
160
|
+
ax: {
|
|
161
|
+
id: "tool:sanctuary_host_execute", group: "turn-sanctuary", effect: "consequential", destructive: true,
|
|
162
|
+
when: "Pick this only when the owner asks, in their own Telegram chat, for a root command on the house server that no typed Sanctuary tool covers.",
|
|
163
|
+
confirm: "OURO ROOT HOST APPROVAL. Effect: unrestricted root, potentially destructive and persistent. Namespaces: real Sanctuary host namespaces. Target: <host> / <resource>. Executable: <executable>",
|
|
164
|
+
errors: [
|
|
165
|
+
{ code: "root-host-denied", means: "This turn doesn't carry the owner's current, verified Telegram request, or the host authority's pins or profile don't match.", fix: "Run nothing; tell the owner a root command needs a fresh request from them in their Telegram chat." },
|
|
166
|
+
{ code: "root-host-unavailable", means: "The root host authority isn't answering, so no approval can be asked.", fix: "Tell the owner the root approval service is down; don't retry until they say it's back." },
|
|
167
|
+
{ code: "resident-execution-forbidden", means: "The command reached the agent's own process, which never runs host commands; nothing ran.", fix: "Don't retry; tell the owner the root approval path is broken, as a harness bug." },
|
|
168
|
+
],
|
|
169
|
+
},
|
|
159
170
|
requiredCapability: "approval-continuation",
|
|
160
171
|
summaryKeys: ["targetHost", "targetResource"],
|
|
161
172
|
riskProfile: { risk: "high", mutates: "external_side_effect", reason: "owner-approved arbitrary host command" },
|
|
162
173
|
approvalPolicy: () => ({ kind: "required", policyId: "sanctuary.host.owner-approved.v1", actionClass: "owner_approved_arbitrary_host", requiresSoleCall: true }),
|
|
163
|
-
handler: () => { throw new Error("Sanctuary host execution requires the root approval continuation; resident execution is forbidden"); },
|
|
174
|
+
handler: () => { throw new Error((0, tools_base_1.withCode)("Sanctuary host execution requires the root approval continuation; resident execution is forbidden", "resident-execution-forbidden")); },
|
|
164
175
|
});
|
|
165
176
|
function validateRootHostToolArguments(args, targetHost) {
|
|
166
177
|
requireOwner(!Object.hasOwn(args, "ownerObservation"));
|
|
@@ -192,7 +203,7 @@ async function authorizeRootHostToolInvocation(ctx, definition, args) {
|
|
|
192
203
|
const selected = definition && selections.get(definition);
|
|
193
204
|
requireOwner(ctx && selected && ctx.rootHost?.binding === selected.binding && ctx.toolSelection?.ordinary.includes(definition));
|
|
194
205
|
if (!ctx.rootHost.port.isHealthy() && !await ctx.rootHost.port.refresh())
|
|
195
|
-
throw new Error("Sanctuary root host authority is unavailable");
|
|
206
|
+
throw new Error((0, tools_base_1.withCode)("Sanctuary root host authority is unavailable", "root-host-unavailable"));
|
|
196
207
|
requireOwner(selectRootHostTool(ctx, selected.capabilities));
|
|
197
208
|
const provenance = bindings.get(selected.binding);
|
|
198
209
|
await authorizeRootHostContext(ctx, provenance.recovery ? selected.binding : undefined);
|
|
@@ -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
|
};
|