ace-wake 0.3.0 → 0.5.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -1
- data/README.md +32 -0
- data/handbook/extensions/ace-wake/wake/eyes-digest.js +428 -0
- data/handbook/extensions/ace-wake/wake/eyes-runtime.js +120 -21
- data/handbook/extensions/ace-wake/wake/eyes.js +117 -3
- data/lib/ace/wake/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79e28ea5377567228c8d0febc0ca9a248bb355cc0ac52c4338c194ffd3022361
|
|
4
|
+
data.tar.gz: '04477178857419a92d25a1735c3bd43c159cabc6883330e5109e44a2aeae2339'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f878d66ed9811def6bd10e531e34722e3f9bbeb2e757edb208c2b28c606266912ad88691d981b8ccb995e901afa9c3262aba97e662c0b463e75a26de488e775d
|
|
7
|
+
data.tar.gz: c1151b4fc90cccfeb1d60d12b93ef998670fe1924c23263a8abd0cccc12e70d8bb1c8e2c5aebbb09bff7e6ef570c07aa00ef5acb9996f0f88bcc5dfcacf393fc
|
data/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,32 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [0.5.0] - 2026-11-16
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Render every model-visible eyes surface as a bounded plain-text digest (task 8yf.t.imq): wakes carry the semantic delta with next actions instead of a JSON batch dump; `ace_eyes status`, `/eyes status` and tool metadata return a compact overview (≤10 lines / ~2 KB) with omitted counts and a `filter` escape hatch; `process-reports` returns an outcome digest only. Internal event keys, revisions and receipt timings no longer reach the model.
|
|
13
|
+
- Acknowledge events by short id inside the tool (`ace_eyes action ack` with `id`, `/eyes ack ID`): exact resolution to one pending event, `deadline:<name>` and `kind:id` forms, unknown/ambiguous ids refused without side effects. Exact revision matching stays internal; unchanged sessions render restored entries with a hash-free fallback note.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- Repeated unchanged observations never repeat a delivered delta, and a degraded source is always named with its error head in status instead of hiding behind a healthy summary.
|
|
18
|
+
- `/eyes status [FILTER]` renders the digest again: the status renderer was scoped inside the tool closure, so every command invocation failed with `ReferenceError`.
|
|
19
|
+
- Remote observation rows (`pr`, `pr-activity`, `issues`) render readable notes with ackable forge references (`pr forgejo-lab#93 open "Title"`, `issues forgejo-lab: 3 open`) instead of an indistinguishable "pr changed" line that could never be acknowledged.
|
|
20
|
+
- Ref acknowledgement is held to the revision the model was actually presented (wake prefix or status details): a stale id acknowledges exactly its presented revision and keeps any newer unseen revision pending to re-report; a ref presented in no rendering this session refuses until status or a wake shows it. Restored entries acknowledge through their non-hash persisted id once presented. Ambiguous ids name their bounded candidates instead of advising the form that was refused.
|
|
21
|
+
- Assignment notes include the wire `state` (running/paused/done), degraded sources beyond the line budget group behind an omitted marker, and next actions never render an `undefined` acknowledgement id.
|
|
22
|
+
|
|
23
|
+
## [0.4.0] - 2026-11-12
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- Initialize configured eyes and compose report processing with healthy observation and exact revision acknowledgements.
|
|
28
|
+
- Show the pending wake-budget resume deadline in eyes status.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- Describe the eyes deadline timestamp as absolute epoch milliseconds in the agent tool schema, preventing durations from being mistaken for future deadlines.
|
|
33
|
+
|
|
9
34
|
|
|
10
35
|
## [0.3.0] - 2026-11-10
|
|
11
36
|
|
data/README.md
CHANGED
|
@@ -44,6 +44,38 @@ after restart. The hourly wake allowance limits delivery while observation
|
|
|
44
44
|
continues to coalesce pending revisions. Delivery resumes with the next
|
|
45
45
|
window. Provider quota and failure breakers still require explicit recovery.
|
|
46
46
|
|
|
47
|
+
### Bounded digests, not pending-map dumps
|
|
48
|
+
|
|
49
|
+
Every model-visible eyes surface renders bounded readable text; internal
|
|
50
|
+
64-hex event keys, revisions and receipt timings never reach the model.
|
|
51
|
+
|
|
52
|
+
- Unchanged observations wake nobody. A healthy idle `ace_eyes action status`
|
|
53
|
+
answers with one line (`eyes observing · no changes pending · …`).
|
|
54
|
+
- A wake carries the semantic delta only: one line per change with a readable
|
|
55
|
+
note and the next action (`report 8xhq2e success (task 148) — run ace_eyes
|
|
56
|
+
action process-reports …`), an omitted count when the batch or backlog is
|
|
57
|
+
larger, and fixed guidance. Single changes stay within 1–3 lines; the text
|
|
58
|
+
is hard-bounded at 10 lines / 2048 characters.
|
|
59
|
+
- `ace_eyes action status` (and `/eyes status [FILTER]`) shows a compact
|
|
60
|
+
overview: state, pending count, wake budget, source health, then the
|
|
61
|
+
decision-needed events first. Large backlogs group behind an omitted count
|
|
62
|
+
with a `filter` hint (kind or id substring). Degraded sources are always
|
|
63
|
+
named with their error head — failures are never silently hidden.
|
|
64
|
+
- `ace_eyes action process-reports` returns only its outcome digest: counts,
|
|
65
|
+
per-event outcome lines with bounded messages, and how many completed
|
|
66
|
+
report revisions were acknowledged internally. Operational failures stay
|
|
67
|
+
tool errors, never quiet success.
|
|
68
|
+
- Acknowledgement resolves short ids inside the tool: `ace_eyes action ack`
|
|
69
|
+
with `id` (also `/eyes ack ID`) matches exactly one pending event —
|
|
70
|
+
`deadline:<name>` for deadlines, `kind:id` when a bare id is ambiguous —
|
|
71
|
+
and refuses unknown or ambiguous targets without side effects. Model-facing
|
|
72
|
+
acks are held to the revision the model was actually shown (wake or
|
|
73
|
+
`ace_eyes status`): a stale id acknowledges its presented revision and
|
|
74
|
+
keeps any newer unseen revision pending to re-report. The operator
|
|
75
|
+
`/eyes ack` command acts under explicit human authority on the revision the
|
|
76
|
+
operator just viewed. Exact revision matching remains internal; display
|
|
77
|
+
never acknowledges.
|
|
78
|
+
|
|
47
79
|
## Mount-aware poll fallback
|
|
48
80
|
|
|
49
81
|
`/lab/state/hitl-address/ace` (the HITL transport folder) is a FUSE/virtiofs
|
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
// Bounded, readable digests for every model-visible eyes surface (task
|
|
2
|
+
// 8yf.t.imq). Wakes, ace_eyes tool results and /eyes notifications render
|
|
3
|
+
// semantic deltas — never full pending maps, 64-hex keys/revisions or
|
|
4
|
+
// receipt timings. Exact revisions stay internal to the Eyes bookkeeping
|
|
5
|
+
// (eyes.js); acknowledgement resolves short ids inside the tool.
|
|
6
|
+
|
|
7
|
+
/** Hard character bound for any rendered eyes text. */
|
|
8
|
+
export const MAX_STATUS_CHARS = 2048;
|
|
9
|
+
|
|
10
|
+
/** Hard line bound for rendered status and wake text. */
|
|
11
|
+
export const MAX_STATUS_LINES = 10;
|
|
12
|
+
|
|
13
|
+
/** Maximum characters for one event note fragment. */
|
|
14
|
+
export const MAX_NOTE_CHARS = 120;
|
|
15
|
+
|
|
16
|
+
/** Maximum detail lines rendered before the omitted marker appears. */
|
|
17
|
+
const MAX_DETAIL_LINES = 8;
|
|
18
|
+
|
|
19
|
+
const HEX64 = /^[a-f0-9]{64}$/;
|
|
20
|
+
export { HEX64 };
|
|
21
|
+
|
|
22
|
+
const WAKE_GUIDANCE = "Read the original state owners. Reconcile uncertain effects; " +
|
|
23
|
+
"never repeat external actions on wake alone. Settlement alone is not acknowledgement.";
|
|
24
|
+
|
|
25
|
+
export const clip = (value, max) => {
|
|
26
|
+
const text = String(value ?? "")
|
|
27
|
+
.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ")
|
|
28
|
+
.replace(/\s+/g, " ").trim();
|
|
29
|
+
return text.length > max ? `${text.slice(0, Math.max(0, max - 1))}…` : text;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const countable = (value) => value !== undefined && value !== null && value !== "" &&
|
|
33
|
+
Number.isInteger(Number(value));
|
|
34
|
+
|
|
35
|
+
const TRUNCATION_MARKER = "… [ace-eyes: truncated]";
|
|
36
|
+
|
|
37
|
+
/** Enforce the hard character bound, reserving room for the marker. */
|
|
38
|
+
export function boundText(text, max = MAX_STATUS_CHARS) {
|
|
39
|
+
const source = String(text ?? "");
|
|
40
|
+
return source.length <= max ? source : `${source.slice(0, Math.max(0, max - TRUNCATION_MARKER.length))}${TRUNCATION_MARKER}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** How many of `lines` land fully inside boundText's preserved prefix: a line
|
|
44
|
+
* cut at the character bound no longer presents what it carries. */
|
|
45
|
+
function fullyVisibleLines(lines, max = MAX_STATUS_CHARS) {
|
|
46
|
+
const limit = Math.max(0, max - TRUNCATION_MARKER.length);
|
|
47
|
+
let used = 0;
|
|
48
|
+
let count = 0;
|
|
49
|
+
for (const line of lines) {
|
|
50
|
+
const add = line.length + (count > 0 ? 1 : 0);
|
|
51
|
+
if (used + add > limit) break;
|
|
52
|
+
used += add;
|
|
53
|
+
count += 1;
|
|
54
|
+
}
|
|
55
|
+
return count;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Keep only candidates whose presenting line is fully inside the text. */
|
|
59
|
+
function presentedWithinCharBound(candidates, lines, max = MAX_STATUS_CHARS) {
|
|
60
|
+
const visible = fullyVisibleLines(lines, max);
|
|
61
|
+
return candidates
|
|
62
|
+
.filter((entry) => entry.line < visible)
|
|
63
|
+
.map(({ key, revision }) => ({ key, revision }));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const basename = (value) =>
|
|
67
|
+
typeof value === "string" && value ? value.split("/").filter(Boolean).pop() : undefined;
|
|
68
|
+
|
|
69
|
+
const has = (value) => typeof value === "string" && value.length > 0;
|
|
70
|
+
|
|
71
|
+
/** The short, ackable reference of an observation event — never a hash. */
|
|
72
|
+
function shortRef(event) {
|
|
73
|
+
if (has(event.source_id) && !HEX64.test(event.source_id)) return event.source_id.slice(0, 64);
|
|
74
|
+
if (has(event.id) && !HEX64.test(event.id)) return event.id.slice(0, 64);
|
|
75
|
+
switch (event.type) {
|
|
76
|
+
case "worktree":
|
|
77
|
+
case "executor": {
|
|
78
|
+
const base = basename(event.path);
|
|
79
|
+
if (base) return base.slice(0, 64);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case "project-session":
|
|
83
|
+
case "project-ready":
|
|
84
|
+
if (has(event.project)) return String(event.project).slice(0, 64);
|
|
85
|
+
break;
|
|
86
|
+
case "pr":
|
|
87
|
+
case "pr-activity":
|
|
88
|
+
if (has(event.forge) && countable(event.number)) return `${event.forge}#${event.number}`.slice(0, 64);
|
|
89
|
+
break;
|
|
90
|
+
case "issues":
|
|
91
|
+
if (has(event.forge)) return event.forge.slice(0, 64);
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function statusWord(event) {
|
|
100
|
+
return clip(event.result ?? event.status ?? event.state ?? "changed", 40);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function subjectNote(kind, event, ref) {
|
|
104
|
+
const task = event.task ?? event.assignment;
|
|
105
|
+
const tail = has(task) ? ` (task ${clip(task, 24)})` : "";
|
|
106
|
+
switch (kind) {
|
|
107
|
+
case "report":
|
|
108
|
+
return `report ${ref} ${statusWord(event)}${tail}`;
|
|
109
|
+
case "question":
|
|
110
|
+
return `question ${ref} awaiting answer${tail}`;
|
|
111
|
+
case "task":
|
|
112
|
+
case "overseer-task": {
|
|
113
|
+
const title = has(event.title) ? ` "${clip(event.title, 48)}"` : "";
|
|
114
|
+
return `${kind} ${ref}${title} → ${statusWord(event)}`;
|
|
115
|
+
}
|
|
116
|
+
case "assignment": {
|
|
117
|
+
const progress = has(event.progress) ? ` (${clip(event.progress, 24)})` : "";
|
|
118
|
+
return `assignment ${ref} ${statusWord(event)}${progress}`;
|
|
119
|
+
}
|
|
120
|
+
case "pr": {
|
|
121
|
+
const title = has(event.title) ? ` "${clip(event.title, 48)}"` : "";
|
|
122
|
+
const draft = event.draft === true ? " (draft)" : "";
|
|
123
|
+
return `pr ${ref} ${statusWord(event)}${draft}${title}`;
|
|
124
|
+
}
|
|
125
|
+
case "pr-activity": {
|
|
126
|
+
const title = has(event.title) ? ` "${clip(event.title, 48)}"` : "";
|
|
127
|
+
return `pr activity ${ref} ${clip(event.event_kind ?? "activity", 24)} by ${clip(event.author ?? "?", 24)}${title}`;
|
|
128
|
+
}
|
|
129
|
+
case "issues":
|
|
130
|
+
return `issues ${ref}: ${countable(event.count) ? Number(event.count) : "?"} open`;
|
|
131
|
+
case "worktree": {
|
|
132
|
+
const branch = has(event.branch) ? ` (${clip(event.branch, 48)})` : "";
|
|
133
|
+
return `worktree ${ref}${branch} changed`;
|
|
134
|
+
}
|
|
135
|
+
case "executor":
|
|
136
|
+
return `executor ${ref} ${event.active === true ? "active" : "idle"}`;
|
|
137
|
+
case "project-session":
|
|
138
|
+
return `project session ${ref} ${clip(event.state ?? event.status ?? "changed", 40)}`;
|
|
139
|
+
case "project-ready":
|
|
140
|
+
return `project ${ref} overseer session ready`;
|
|
141
|
+
default:
|
|
142
|
+
return `${kind} ${ref} ${statusWord(event)}`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function sourceNote(event) {
|
|
147
|
+
const name = clip(sourceRef(event) ?? "source", 40);
|
|
148
|
+
if (event.status === "degraded") return `source ${name} degraded — ${clip(event.error, 64)}`;
|
|
149
|
+
return `source ${name} healthy`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function sourceRef(event) {
|
|
153
|
+
if (has(event.project)) return String(event.project).slice(0, 64);
|
|
154
|
+
const key = event.source_key ?? event.key;
|
|
155
|
+
if (has(key) && key.startsWith("source:")) return key.slice("source:".length, 64 + 7);
|
|
156
|
+
if (has(key) && !HEX64.test(key)) return key.slice(0, 64);
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* One-line semantic identity of an observation event: kind, short reference
|
|
162
|
+
* and a bounded note. No keys, revisions or private content.
|
|
163
|
+
*
|
|
164
|
+
* @param {object} event Validated observation event row.
|
|
165
|
+
* @returns {{kind: string, ref: string|undefined, note: string}}
|
|
166
|
+
*/
|
|
167
|
+
export function describeEvent(event) {
|
|
168
|
+
const kind = has(event?.type) ? clip(event.type, 40) : "event";
|
|
169
|
+
if (kind === "source-health") {
|
|
170
|
+
return { kind, ref: sourceRef(event), note: clip(sourceNote(event), MAX_NOTE_CHARS) };
|
|
171
|
+
}
|
|
172
|
+
const ref = shortRef(event ?? {});
|
|
173
|
+
const safeRef = ref === undefined ? undefined : clip(ref, 64);
|
|
174
|
+
const note = !safeRef ? `${kind} changed`
|
|
175
|
+
: kind === "event" ? `${safeRef} changed`
|
|
176
|
+
: subjectNote(kind, event ?? {}, safeRef);
|
|
177
|
+
return { kind, ref: safeRef, note: clip(note, MAX_NOTE_CHARS) };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Tolerant view of a persisted pending entry: sessions restored from older
|
|
182
|
+
* snapshots may lack descriptors and still render without leaking hashes.
|
|
183
|
+
*
|
|
184
|
+
* @param {object} entry Pending entry ({id, revision, kind?, ref?, note?}).
|
|
185
|
+
* @returns {{kind: string, ref: string|undefined, note: string}}
|
|
186
|
+
*/
|
|
187
|
+
export function describeEntry(entry) {
|
|
188
|
+
if (entry && typeof entry.note === "string" && entry.note) {
|
|
189
|
+
return { kind: entry.kind ?? "event", ref: entry.ref, note: entry.note };
|
|
190
|
+
}
|
|
191
|
+
return { kind: "event", ref: undefined, note: "event changed (restored session state)" };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function nextAction(entry) {
|
|
195
|
+
switch (entry.kind) {
|
|
196
|
+
case "report":
|
|
197
|
+
return "run ace_eyes action process-reports to adopt completed reports and acknowledge them";
|
|
198
|
+
case "question":
|
|
199
|
+
return entry.ref ? `answer via ace-hitl, then run ace_eyes action ack id ${entry.ref}`
|
|
200
|
+
: "answer via ace-hitl, then run ace_eyes action status for details";
|
|
201
|
+
case "deadline":
|
|
202
|
+
return entry.ref ? `handle it, then run ace_eyes action ack id deadline:${entry.ref}`
|
|
203
|
+
: "handle it, then run ace_eyes action status for details";
|
|
204
|
+
default:
|
|
205
|
+
return entry.ref ? `handle it, then run ace_eyes action ack id ${entry.ref}` :
|
|
206
|
+
"handle it, then run ace_eyes action status for details";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The entries actually included in renderWake's text: the delivery budget
|
|
211
|
+
* prefix of the batch, exactly within the character bound. The runtime
|
|
212
|
+
* records these revisions as presented so acknowledgement stays honest. */
|
|
213
|
+
export function wakePresentation(batch, omitted = 0) {
|
|
214
|
+
const { lines, rows } = wakeLayout(batch, omitted);
|
|
215
|
+
return presentedWithinCharBound(
|
|
216
|
+
rows.map((row, index) => ({ ...row, line: index + 1 })), lines.slice(0, MAX_STATUS_LINES));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function wakeLayout(batch, omitted = 0) {
|
|
220
|
+
const total = Array.isArray(batch) ? batch.length : 0;
|
|
221
|
+
const pairs = (Array.isArray(batch) ? batch : []).slice(0, wakeDetailBudget(total, omitted));
|
|
222
|
+
const pendingOverflow = Number(omitted) > 0;
|
|
223
|
+
const entries = pairs.map(([, value]) => describeEntry(value));
|
|
224
|
+
// The header reports the whole delivered batch; the prefix below shows as
|
|
225
|
+
// many readable lines as the layout budget allows, with overflow markers.
|
|
226
|
+
const lines = [`[ace-eyes] ${total} pending change${total === 1 ? "" : "s"}:`];
|
|
227
|
+
for (const entry of entries) lines.push(`- ${entry.note} — ${nextAction(entry)}`);
|
|
228
|
+
if (pairs.length < total) lines.push(`(+${total - pairs.length} more in this batch — run ace_eyes action status)`);
|
|
229
|
+
if (pendingOverflow) lines.push(`(+${Number(omitted)} more pending — run ace_eyes action status)`);
|
|
230
|
+
lines.push(WAKE_GUIDANCE);
|
|
231
|
+
return { lines, rows: pairs.map(([key, value]) => ({ key: String(key ?? ""), revision: String(value?.revision ?? "") })) };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const wakeDetailBudget = (count, omitted = 0) => {
|
|
235
|
+
const batchOverflow = count > MAX_DETAIL_LINES;
|
|
236
|
+
const pendingOverflow = Number(omitted) > 0;
|
|
237
|
+
return Math.max(0, MAX_STATUS_LINES - 2 - (batchOverflow ? 1 : 0) - (pendingOverflow ? 1 : 0));
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Wake text for one delivered batch: the semantic delta plus the next action.
|
|
242
|
+
*
|
|
243
|
+
* @param {Array<[string, object]>} batch Delivered [key, pending entry] pairs.
|
|
244
|
+
* @param {number} [omitted] Pending changes beyond the delivered batch.
|
|
245
|
+
* @returns {string}
|
|
246
|
+
*/
|
|
247
|
+
export function renderWake(batch, omitted = 0) {
|
|
248
|
+
return boundText(wakeLayout(batch, omitted).lines.slice(0, MAX_STATUS_LINES).join("\n"));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function sourcesHealth(sources) {
|
|
252
|
+
const rows = Object.entries(sources ?? {});
|
|
253
|
+
if (rows.length === 0) return { summary: "", degraded: [] };
|
|
254
|
+
const degraded = rows.filter(([, source]) => source?.status !== "ok");
|
|
255
|
+
const summary = degraded.length === 0 ? `sources: ${rows.length} ok`
|
|
256
|
+
: `sources: ${rows.length - degraded.length} ok, ${degraded.length} degraded`;
|
|
257
|
+
return { summary, degraded };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const decisionNeeded = (entry) => entry.kind === "question";
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Shared layout for the compact status overview and its presentation record.
|
|
264
|
+
* `presented` carries the pending entries whose notes are actually rendered,
|
|
265
|
+
* so acknowledgement can be held to the revision the model was shown.
|
|
266
|
+
*/
|
|
267
|
+
function statusLayout(snapshot, { filter } = {}) {
|
|
268
|
+
const { summary, sources, pending, deadlines = 0 } = snapshot ?? {};
|
|
269
|
+
const state = !summary?.enabled ? "eyes off" : summary?.retired ? "eyes retired"
|
|
270
|
+
: summary?.breaker ? `eyes breaker: ${summary.breaker.reason ?? "unknown"}`
|
|
271
|
+
: summary?.observationUnavailable ? "eyes observation unavailable" : "eyes observing";
|
|
272
|
+
const health = sourcesHealth(sources);
|
|
273
|
+
const all = (Array.isArray(pending) ? pending : []).map(([key, value]) => ({
|
|
274
|
+
key, revision: value?.revision, ...describeEntry(value),
|
|
275
|
+
}));
|
|
276
|
+
const wanted = typeof filter === "string" && filter.trim() ? filter.trim().toLowerCase() : undefined;
|
|
277
|
+
const selected = wanted
|
|
278
|
+
? all.filter((entry) => entry.kind === wanted || (entry.ref ?? "").toLowerCase().includes(wanted))
|
|
279
|
+
: [
|
|
280
|
+
// Observation failures first, then decision-needed events, then the rest
|
|
281
|
+
// in insertion order — critical blockers are never silently displaced.
|
|
282
|
+
...all.filter((entry) => entry.kind === "source-health" && entry.note.includes("degraded")),
|
|
283
|
+
...all.filter((entry) => decisionNeeded(entry)),
|
|
284
|
+
...all.filter((entry) => !decisionNeeded(entry) &&
|
|
285
|
+
!(entry.kind === "source-health" && entry.note.includes("degraded"))),
|
|
286
|
+
];
|
|
287
|
+
|
|
288
|
+
const headParts = [state];
|
|
289
|
+
if (summary?.enabled && !summary.retired) {
|
|
290
|
+
// A filtered view names its share of the backlog so the model can never
|
|
291
|
+
// read the selected count as the whole pending set.
|
|
292
|
+
const pendingPhrase = !wanted && selected.length === 0 ? "no changes pending"
|
|
293
|
+
: wanted && selected.length === 0 ? `no matches · ${all.length} pending`
|
|
294
|
+
: wanted ? `pending ${selected.length} of ${all.length}` : `pending ${selected.length}`;
|
|
295
|
+
headParts.push(pendingPhrase);
|
|
296
|
+
headParts.push(`wakes ${summary.wakes ?? 0}/${summary.wakeLimit ?? "?"} this hour`);
|
|
297
|
+
if (summary.wakeLimitedUntil) headParts.push(`wake-limited until ${new Date(summary.wakeLimitedUntil).toISOString()}`);
|
|
298
|
+
if (deadlines > 0) headParts.push(`deadlines ${deadlines}`);
|
|
299
|
+
}
|
|
300
|
+
if (health.summary && (summary?.enabled || health.degraded.length > 0)) headParts.push(health.summary);
|
|
301
|
+
|
|
302
|
+
const lines = [headParts.join(" · ")];
|
|
303
|
+
if (wanted && selected.length === 0) lines.push(`no pending event matches "${clip(filter, 64)}"`);
|
|
304
|
+
// Degraded sources are always named with their error head, even without a
|
|
305
|
+
// pending health marker — observation failures are never silently hidden.
|
|
306
|
+
// Beyond the line budget each hidden group gets its own omitted marker.
|
|
307
|
+
const degradedNames = new Set();
|
|
308
|
+
const degradedRows = health.degraded.map(([rawName, source]) => {
|
|
309
|
+
const name = clip(rawName, 64);
|
|
310
|
+
degradedNames.add(name);
|
|
311
|
+
const error = source?.error ? ` — ${clip(source.error, 64)}` : "";
|
|
312
|
+
return `- source ${name} degraded${error}`;
|
|
313
|
+
});
|
|
314
|
+
const visible = selected.filter((entry) =>
|
|
315
|
+
!(entry.kind === "source-health" && entry.note.includes("degraded") && degradedNames.has(entry.ref)));
|
|
316
|
+
const detailTexts = [...degradedRows, ...visible.map((entry) => `- ${entry.note}`)];
|
|
317
|
+
const capacity = Math.max(0, MAX_STATUS_LINES - lines.length);
|
|
318
|
+
// Reserve one marker line per hidden group; iterate to a stable layout —
|
|
319
|
+
// markers shrink the shown budget, which can hide one more group.
|
|
320
|
+
let markers = 0;
|
|
321
|
+
let shown = capacity;
|
|
322
|
+
for (let pass = 0; pass < 3; pass += 1) {
|
|
323
|
+
shown = Math.max(0, capacity - markers);
|
|
324
|
+
const hiddenDegraded = degradedRows.length - Math.min(degradedRows.length, shown);
|
|
325
|
+
const hiddenPending = visible.length - Math.max(0, shown - degradedRows.length);
|
|
326
|
+
const next = (hiddenDegraded > 0 ? 1 : 0) + (hiddenPending > 0 ? 1 : 0);
|
|
327
|
+
if (next === markers) break;
|
|
328
|
+
markers = next;
|
|
329
|
+
}
|
|
330
|
+
const finalHiddenDegraded = degradedRows.length - Math.min(degradedRows.length, shown);
|
|
331
|
+
const shownVisible = Math.max(0, shown - degradedRows.length);
|
|
332
|
+
const renderedDegradedNames = new Set(health.degraded.slice(0, Math.min(degradedRows.length, shown)).map(([rawName]) => clip(rawName, 64)));
|
|
333
|
+
const detailStart = lines.length;
|
|
334
|
+
for (const text of detailTexts.slice(0, shown)) lines.push(text);
|
|
335
|
+
if (finalHiddenDegraded > 0) {
|
|
336
|
+
// No filter can enlarge the degraded-row budget, so the marker stays honest
|
|
337
|
+
// about what is hidden instead of advertising an escape that repeats it.
|
|
338
|
+
lines.push(`(+${finalHiddenDegraded} degraded sources omitted)`);
|
|
339
|
+
}
|
|
340
|
+
if (visible.length > shownVisible) {
|
|
341
|
+
const omitted = visible.length - shownVisible;
|
|
342
|
+
const kinds = {};
|
|
343
|
+
for (const entry of visible.slice(shownVisible)) kinds[entry.kind] = (kinds[entry.kind] ?? 0) + 1;
|
|
344
|
+
const hint = Object.entries(kinds).sort((a, b) => b[1] - a[1])[0]?.[0] ?? "event";
|
|
345
|
+
lines.push(`(+${omitted} omitted — ace_eyes action status filter ${hint})`);
|
|
346
|
+
}
|
|
347
|
+
return {
|
|
348
|
+
lines,
|
|
349
|
+
presented: [
|
|
350
|
+
...visible.slice(0, shownVisible).map((entry, position) => (
|
|
351
|
+
{ key: entry.key, revision: entry.revision, line: detailStart + Math.min(degradedRows.length, shown) + position })),
|
|
352
|
+
// A degraded source's pending entry renders through the live degraded
|
|
353
|
+
// row (same name and note) — that row presents it just as honestly.
|
|
354
|
+
...all.filter((entry) => entry.kind === "source-health" && entry.note.includes("degraded") &&
|
|
355
|
+
renderedDegradedNames.has(entry.ref)).map((entry) => ({
|
|
356
|
+
key: entry.key, revision: entry.revision,
|
|
357
|
+
line: detailStart + health.degraded.findIndex(([name]) => name === entry.ref),
|
|
358
|
+
})),
|
|
359
|
+
],
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Compact current overview for ace_eyes status and /eyes status: at most
|
|
365
|
+
* MAX_STATUS_LINES lines and MAX_STATUS_CHARS. Decision-needed events first;
|
|
366
|
+
* degraded sources are always visible; larger backlogs group behind an
|
|
367
|
+
* omitted count with a filter hint. A healthy idle observation is one line.
|
|
368
|
+
*
|
|
369
|
+
* @param {object} snapshot {summary, sources, pending, deadlines}.
|
|
370
|
+
* @param {{filter?: string}} [options] Optional kind/id substring filter.
|
|
371
|
+
* @returns {string}
|
|
372
|
+
*/
|
|
373
|
+
export function renderStatus(snapshot, options = {}) {
|
|
374
|
+
return boundText(statusLayout(snapshot, options).lines.slice(0, MAX_STATUS_LINES).join("\n"));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** The pending entries actually included in renderStatus's text. */
|
|
378
|
+
export function statusPresentation(snapshot, options = {}) {
|
|
379
|
+
const { lines, presented } = statusLayout(snapshot, options);
|
|
380
|
+
return presentedWithinCharBound(presented, lines.slice(0, MAX_STATUS_LINES));
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function countsPhrase(counts) {
|
|
384
|
+
const order = ["success", "needs_answer", "error", "duplicate", "unmatched"];
|
|
385
|
+
const phrase = order.filter((name) => Number(counts?.[name] ?? 0) > 0)
|
|
386
|
+
.map((name) => `${counts[name]} ${name}`).join(", ");
|
|
387
|
+
return phrase || "none";
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function processingLayout(processing, pendingAfter = 0) {
|
|
391
|
+
const outcomes = Array.isArray(processing?.outcomes) ? processing.outcomes : [];
|
|
392
|
+
const acknowledged = outcomes.filter((row) =>
|
|
393
|
+
row.acknowledge === true && row.accepted === true && row.cleanup === "complete").length;
|
|
394
|
+
const lines = [`process-reports: ${outcomes.length} outcome${outcomes.length === 1 ? "" : "s"} — ${countsPhrase(processing?.counts)}`];
|
|
395
|
+
const detailBudget = Math.max(0, MAX_STATUS_LINES - 2 - (outcomes.length > MAX_STATUS_LINES - 2 ? 1 : 0));
|
|
396
|
+
const shown = outcomes.slice(0, detailBudget);
|
|
397
|
+
for (const row of shown) {
|
|
398
|
+
const message = has(row.message) ? ` — ${clip(row.message, 140)}` : "";
|
|
399
|
+
lines.push(`- ${clip(row.event_id ?? "?", 64)} ${clip(row.status ?? "unknown", 24)}${message}`);
|
|
400
|
+
}
|
|
401
|
+
if (outcomes.length > shown.length) lines.push(`(+${outcomes.length - shown.length} more outcomes)`);
|
|
402
|
+
lines.push(`acknowledged ${acknowledged} completed report revision(s); ${Number(pendingAfter)} pending change(s) remain`);
|
|
403
|
+
return { lines, rows: shown.map((row, index) => ({ key: row.key, revision: row.revision, line: index + 1 })) };
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** The receipt rows actually rendered, with their exact key/revision: the
|
|
407
|
+
* runtime binds them against current pending entries so the digest presents
|
|
408
|
+
* nothing it does not name. Rows are numbered by render position before
|
|
409
|
+
* filtering, so a key-less row cannot shift another row's line. */
|
|
410
|
+
export function processingPresentation(processing) {
|
|
411
|
+
const { lines, rows } = processingLayout(processing);
|
|
412
|
+
return presentedWithinCharBound(
|
|
413
|
+
rows.filter((row) => typeof row.key === "string" && typeof row.revision === "string"),
|
|
414
|
+
lines.slice(0, MAX_STATUS_LINES));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Outcome digest for one process-reports receipt: statuses, per-event lines
|
|
419
|
+
* with bounded messages, and the acknowledgement tail. Operational failures
|
|
420
|
+
* never reach this renderer — they surface as tool errors.
|
|
421
|
+
*
|
|
422
|
+
* @param {object} processing Validated process-reports receipt.
|
|
423
|
+
* @param {number} [pendingAfter] Pending change count after acknowledgements.
|
|
424
|
+
* @returns {string}
|
|
425
|
+
*/
|
|
426
|
+
export function renderProcessing(processing, pendingAfter = 0) {
|
|
427
|
+
return boundText(processingLayout(processing, pendingAfter).lines.slice(0, MAX_STATUS_LINES).join("\n"));
|
|
428
|
+
}
|
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { execFile, execFileSync } from "node:child_process";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { Eyes, EYES_ENTRY } from "./eyes.js";
|
|
6
|
+
import { clip, renderWake, renderStatus, renderProcessing, wakePresentation, statusPresentation, processingPresentation } from "./eyes-digest.js";
|
|
6
7
|
|
|
7
8
|
const execute = promisify(execFile);
|
|
8
9
|
export const EYES_BINDING = "ace-wake-eyes-binding";
|
|
@@ -56,7 +57,17 @@ export async function observeHitl(cwd, config) {
|
|
|
56
57
|
return result;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
export function
|
|
60
|
+
export async function processReports(cwd, config, signal) {
|
|
61
|
+
const { stdout } = await execute("ace-overseer", ["process-reports", "--json",
|
|
62
|
+
"--owner", config.recipient, "--scope", config.scope],
|
|
63
|
+
{ cwd, signal, maxBuffer: 8 * 1024 * 1024, encoding: "utf8" });
|
|
64
|
+
const result = JSON.parse(stdout);
|
|
65
|
+
if (!Array.isArray(result?.outcomes) || result.dry_run !== false)
|
|
66
|
+
throw new Error("Invalid report-processing receipt");
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function registerEyes(pi, { observe = observeHitl, processReports: processReportOwner = processReports, env = process.env, now = Date.now,
|
|
60
71
|
schedule = (fn, ms) => setInterval(fn, ms), cancel = clearInterval, processIdentity = eyesProcessIdentity } = {}) {
|
|
61
72
|
let eyes, timer, attempt, observedSources, observedAt, bindingGeneration = 0, compacting = false, running = false, arming = false;
|
|
62
73
|
const clearEvidence = () => { observedSources = undefined; observedAt = undefined; };
|
|
@@ -69,7 +80,7 @@ export function registerEyes(pi, { observe = observeHitl, now = Date.now,
|
|
|
69
80
|
timer?.unref?.();
|
|
70
81
|
}
|
|
71
82
|
}
|
|
72
|
-
const bind = (ctx) => {
|
|
83
|
+
const bind = async (ctx) => {
|
|
73
84
|
const generation = ++bindingGeneration;
|
|
74
85
|
stopTimer(); eyes?.dispose(); attempt = undefined; clearEvidence(); compacting = false; running = false;
|
|
75
86
|
const entries = ctx.sessionManager.getBranch();
|
|
@@ -93,7 +104,7 @@ export function registerEyes(pi, { observe = observeHitl, now = Date.now,
|
|
|
93
104
|
} });
|
|
94
105
|
},
|
|
95
106
|
status: (state) => {
|
|
96
|
-
ctx.ui?.setStatus?.("ace-eyes", `eyes ${state.retired ? "retired" : state.breaker?.reason || (state.observationUnavailable ? "observation-unavailable" : state.enabled ? "observing" : "off")} pending:${state.pending}`);
|
|
107
|
+
ctx.ui?.setStatus?.("ace-eyes", `eyes ${state.retired ? "retired" : state.breaker?.reason || (state.observationUnavailable ? "observation-unavailable" : state.wakeLimitedUntil && state.pending ? `wake-limited until ${new Date(state.wakeLimitedUntil).toISOString()}` : state.enabled ? "observing" : "off")} pending:${state.pending}`);
|
|
97
108
|
if (state.breaker || state.retired) stopTimer();
|
|
98
109
|
},
|
|
99
110
|
observe: (config) => observe(ctx.cwd, config),
|
|
@@ -119,10 +130,9 @@ export function registerEyes(pi, { observe = observeHitl, now = Date.now,
|
|
|
119
130
|
},
|
|
120
131
|
deliver: async (batch) => {
|
|
121
132
|
if (!ctx.model) return false;
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"acknowledge with the ace_eyes tool (action ack, key, revision). Settlement alone is not acknowledgement.";
|
|
133
|
+
const omitted = Math.max(0, Object.keys(eyes.s.pending).length - batch.length);
|
|
134
|
+
const presented = wakePresentation(batch, omitted);
|
|
135
|
+
const text = renderWake(batch, omitted);
|
|
126
136
|
const previous = attempt;
|
|
127
137
|
attempt = { text, accepted: false };
|
|
128
138
|
const result = pi.sendUserMessage(text, { deliverAs: "followUp" });
|
|
@@ -130,10 +140,20 @@ export function registerEyes(pi, { observe = observeHitl, now = Date.now,
|
|
|
130
140
|
// Neither completion nor void is proof of message consumption.
|
|
131
141
|
const submitted = await result;
|
|
132
142
|
if (submitted === false) attempt = previous;
|
|
143
|
+
else eyes.markPresented(presented);
|
|
133
144
|
return submitted !== false;
|
|
134
145
|
} });
|
|
146
|
+
const configPath = env.ACE_OVERSEER_EYES_CONFIG;
|
|
147
|
+
if (configPath) {
|
|
148
|
+
const expected = path.join(ownerCwd, ".ace-local/overseer/eyes.json");
|
|
149
|
+
if (path.resolve(configPath) !== expected) throw new Error("Eyes config does not belong to this coordinator root");
|
|
150
|
+
eyes.start(JSON.parse(fs.readFileSync(configPath, "utf8")));
|
|
151
|
+
}
|
|
135
152
|
arm();
|
|
136
|
-
if (eyes.s.enabled
|
|
153
|
+
if (eyes.s.enabled && configPath) {
|
|
154
|
+
arming = true;
|
|
155
|
+
try { await eyes.tick(); } finally { arming = false; }
|
|
156
|
+
} else if (eyes.s.enabled) void eyes.tick();
|
|
137
157
|
};
|
|
138
158
|
pi.on("session_start", async (_event, ctx) => bind(ctx));
|
|
139
159
|
pi.on("session_tree", async (_event, ctx) => bind(ctx));
|
|
@@ -156,18 +176,49 @@ export function registerEyes(pi, { observe = observeHitl, now = Date.now,
|
|
|
156
176
|
const message = event.message;
|
|
157
177
|
if (message?.role === "assistant" && message.stopReason === "error") eyes?.quota(message.errorMessage);
|
|
158
178
|
});
|
|
179
|
+
// Shared by the ace_eyes tool and the /eyes command: both close over this
|
|
180
|
+
// registerEyes scope (eyes, observedSources). Only MODEL-visible renders
|
|
181
|
+
// (the tool's status result) record presented revisions; an operator
|
|
182
|
+
// notification must never authorize a model acknowledgement.
|
|
183
|
+
const statusSnapshot = () => ({
|
|
184
|
+
summary: eyes.summary(), sources: observedSources,
|
|
185
|
+
pending: Object.entries(eyes.s.pending), deadlines: Object.keys(eyes.s.deadlines).length,
|
|
186
|
+
});
|
|
187
|
+
const statusText = (filter) => renderStatus(statusSnapshot(), { filter });
|
|
188
|
+
const presentStatus = (filter) => {
|
|
189
|
+
const snapshot = statusSnapshot();
|
|
190
|
+
eyes.markPresented(statusPresentation(snapshot, { filter }));
|
|
191
|
+
return renderStatus(snapshot, { filter });
|
|
192
|
+
};
|
|
159
193
|
pi.registerTool?.({
|
|
160
|
-
name: "ace_eyes", label: "Eyes observation", description: "Start standing observation with an existing config file, read pending semantic events or acknowledge
|
|
194
|
+
name: "ace_eyes", label: "Eyes observation", description: "Start standing observation with an existing config file, read a compact digest of pending semantic events, or acknowledge one exactly handled event by its short id. Acks are held to the revision presented this session by wake or status; a stale id acknowledges its presented revision and keeps any newer unseen revision pending. Action process-reports invokes the existing report owner and acknowledges only its completed exact revisions; other events require explicit ack. Does not reset quota. Deadlines require an operation id and revision; cancel when no longer active.",
|
|
161
195
|
parameters: { type: "object", properties: {
|
|
162
|
-
action: { type: "string", enum: ["start", "status", "ack", "deadline", "cancel"] },
|
|
196
|
+
action: { type: "string", enum: ["start", "status", "process-reports", "ack", "deadline", "cancel"] },
|
|
163
197
|
configPath: { type: "string" },
|
|
164
|
-
|
|
198
|
+
id: { type: "string", description: "Short event id from ace_eyes status (for ack); for deadline/cancel pass the bare operation name" },
|
|
199
|
+
filter: { type: "string", description: "Optional status filter: event kind or id substring" },
|
|
200
|
+
revision: { type: "string", description: "Deadline operation revision (deadline action)" },
|
|
201
|
+
at: { type: "integer", description: "Absolute Unix epoch timestamp in milliseconds, NOT a duration. For five minutes from now use the current epoch milliseconds plus 300000; a past timestamp is immediately due." }
|
|
165
202
|
}, required: ["action"], additionalProperties: false },
|
|
166
203
|
execute: async (_id, args, _signal, _onUpdate, ctx) => {
|
|
167
204
|
if (!eyes) {
|
|
168
205
|
if (!ctx) throw new Error("Eyes session not initialized");
|
|
169
|
-
bind(ctx);
|
|
206
|
+
await bind(ctx);
|
|
170
207
|
}
|
|
208
|
+
// Tool metadata mirrors bounded scalars only: no per-event keys,
|
|
209
|
+
// revisions, deadlines map or receipt timings reach the model.
|
|
210
|
+
const boundedDetails = (receipt) => ({
|
|
211
|
+
...eyes.summary(),
|
|
212
|
+
...(observedSources ? { sources: Object.fromEntries(Object.entries(observedSources)
|
|
213
|
+
.map(([name, source]) => [name, source?.status])) } : {}),
|
|
214
|
+
...(receipt ? { processing: {
|
|
215
|
+
counts: receipt.counts,
|
|
216
|
+
acknowledged: receipt.outcomes.filter((row) =>
|
|
217
|
+
row.acknowledge === true && row.accepted === true && row.cleanup === "complete").length,
|
|
218
|
+
} } : {}),
|
|
219
|
+
});
|
|
220
|
+
let processing;
|
|
221
|
+
let text;
|
|
171
222
|
if (args.action === "start") {
|
|
172
223
|
if (!ctx || typeof args.configPath !== "string" || !args.configPath.trim()) {
|
|
173
224
|
throw new Error("Eyes start requires configPath and the current session context");
|
|
@@ -181,20 +232,61 @@ export function registerEyes(pi, { observe = observeHitl, now = Date.now,
|
|
|
181
232
|
try { await current.tick(); } finally { if (current === eyes && generation === bindingGeneration) arming = false; }
|
|
182
233
|
if (current !== eyes || generation !== bindingGeneration) throw new Error("Eyes session changed during start");
|
|
183
234
|
}
|
|
184
|
-
else if (args.action === "
|
|
185
|
-
|
|
186
|
-
|
|
235
|
+
else if (args.action === "process-reports") {
|
|
236
|
+
if (!ctx || !eyes.s.enabled) throw new Error("Report processing requires active eyes in this session");
|
|
237
|
+
const sources = observedSources && Object.values(observedSources);
|
|
238
|
+
const config = eyes.s.config;
|
|
239
|
+
const interval = config.intervalSeconds * 1000;
|
|
240
|
+
const cadence = Math.ceil(3600000 / (config.maxObservationsPerHour * interval)) * interval;
|
|
241
|
+
if (eyes.s.breaker || eyes.s.observationUnavailable || !sources?.length ||
|
|
242
|
+
sources.some(source => source.status !== "ok") || observedAt === undefined ||
|
|
243
|
+
now() - observedAt > cadence + config.timeoutMs)
|
|
244
|
+
throw new Error("Report processing blocked: required observation is unavailable, degraded or stale");
|
|
245
|
+
const current = eyes, generation = bindingGeneration;
|
|
246
|
+
processing = await processReportOwner(ctx.cwd, current.s.config, _signal);
|
|
247
|
+
if (current !== eyes || generation !== bindingGeneration)
|
|
248
|
+
throw new Error("Eyes session changed during report processing; retained receipts require reconciliation");
|
|
249
|
+
if (!Array.isArray(processing?.outcomes) || processing.dry_run !== false)
|
|
250
|
+
throw new Error("Invalid report-processing receipt");
|
|
251
|
+
for (const receipt of processing.outcomes) {
|
|
252
|
+
if (receipt.acknowledge !== true || receipt.accepted !== true || receipt.cleanup !== "complete") continue;
|
|
253
|
+
if (current.s.pending[receipt.key]?.revision === receipt.revision || current.sent.get(receipt.key) === receipt.revision)
|
|
254
|
+
current.ack(receipt.key, receipt.revision);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else if (args.action === "ack") {
|
|
258
|
+
const entry = eyes.ackByRef(args.id);
|
|
259
|
+
const staleNote = entry?.stale ? " at the presented revision; a newer revision is pending and will re-report" : "";
|
|
260
|
+
text = `acknowledged ${clip(entry?.ref ?? args.id, 64)}${staleNote}; ${Object.keys(eyes.s.pending).length} pending change(s) remain`;
|
|
261
|
+
}
|
|
262
|
+
else if (args.action === "deadline") {
|
|
263
|
+
if (typeof args.id !== "string" || !args.id.trim()) throw new Error("Deadline requires an operation id");
|
|
264
|
+
eyes.deadline(args.id, args.at, args.revision);
|
|
265
|
+
text = `deadline ${args.id} registered for ${new Date(args.at).toISOString()}`;
|
|
266
|
+
}
|
|
267
|
+
else if (args.action === "cancel") {
|
|
268
|
+
if (typeof args.id !== "string" || !args.id.trim()) throw new Error("Cancel requires an operation id");
|
|
269
|
+
eyes.cancelDeadline(args.id);
|
|
270
|
+
text = `deadline ${args.id} cancelled`;
|
|
271
|
+
}
|
|
187
272
|
else if (args.action !== "status") throw new Error("Unknown eyes action");
|
|
188
273
|
// Do not send a second wake from inside the running model turn. The next
|
|
189
274
|
// observation delivers remaining coalesced revisions through the same owner.
|
|
190
|
-
|
|
191
|
-
|
|
275
|
+
if (args.action === "process-reports") {
|
|
276
|
+
// The receipt digest is the model-visible surface here: only its
|
|
277
|
+
// rendered rows — bound to still-pending exact revisions — become
|
|
278
|
+
// presented. An event the receipt does not name still requires a
|
|
279
|
+
// visible status or wake before it can be acknowledged.
|
|
280
|
+
eyes.markReceiptPresented(processingPresentation(processing));
|
|
281
|
+
text = renderProcessing(processing, Object.keys(eyes.s.pending).length);
|
|
282
|
+
} else if (text === undefined) text = presentStatus(args.filter);
|
|
283
|
+
return { content: [{ type: "text", text }], details: boundedDetails(processing) };
|
|
192
284
|
}
|
|
193
285
|
});
|
|
194
|
-
pi.registerCommand("eyes", { description: "Event-driven HITL observation: start CONFIG | status | ack
|
|
286
|
+
pi.registerCommand("eyes", { description: "Event-driven HITL observation: start CONFIG | status [FILTER] | ack ID | deadline NAME REVISION EPOCH_MS | cancel NAME | resume quota-verified | retire",
|
|
195
287
|
handler: async (args, ctx) => {
|
|
196
288
|
try {
|
|
197
|
-
if (!eyes) bind(ctx);
|
|
289
|
+
if (!eyes) await bind(ctx);
|
|
198
290
|
const [command, a, b, ...rest] = args.trim().split(/\s+/);
|
|
199
291
|
if (rest.length && command !== "deadline") throw new Error("Too many arguments");
|
|
200
292
|
switch (command) {
|
|
@@ -206,8 +298,15 @@ export function registerEyes(pi, { observe = observeHitl, now = Date.now,
|
|
|
206
298
|
if (current !== eyes || generation !== bindingGeneration) throw new Error("Eyes session changed during start");
|
|
207
299
|
break;
|
|
208
300
|
}
|
|
209
|
-
case "status": ctx.ui?.notify?.(
|
|
210
|
-
case "ack":
|
|
301
|
+
case "status": ctx.ui?.notify?.(statusText(a), "info"); break;
|
|
302
|
+
case "ack": {
|
|
303
|
+
// Operator authority: the human just viewed /eyes status and is
|
|
304
|
+
// acknowledging the current revision themselves.
|
|
305
|
+
const entry = eyes.ackByRef(a, { presentationRequired: false });
|
|
306
|
+
const staleNote = entry?.stale ? " at the presented revision; a newer revision is pending and will re-report" : "";
|
|
307
|
+
ctx.ui?.notify?.(`acknowledged ${clip(entry?.ref ?? a, 64)}${staleNote}; ${Object.keys(eyes.s.pending).length} pending change(s) remain`, "info");
|
|
308
|
+
await eyes.tick(); break;
|
|
309
|
+
}
|
|
211
310
|
case "deadline":
|
|
212
311
|
if (rest.length !== 1) throw new Error("Deadline requires operation identity, revision and epoch milliseconds");
|
|
213
312
|
eyes.deadline(a, Number(rest[0]), b); await eyes.tick(); break;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { clip, describeEvent, HEX64, MAX_NOTE_CHARS } from "./eyes-digest.js";
|
|
2
3
|
|
|
3
4
|
const hash = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
4
5
|
export const EYES_ENTRY = "ace-wake-eyes";
|
|
@@ -30,6 +31,20 @@ export class Eyes {
|
|
|
30
31
|
this.s.config = validateConfig(this.s.config);
|
|
31
32
|
for (const key of ["pending", "acknowledged", "deadlines"])
|
|
32
33
|
if (!this.s[key] || typeof this.s[key] !== "object" || Array.isArray(this.s[key])) throw new Error("Invalid persisted eyes state");
|
|
34
|
+
// Migrate legacy (pre-0.5.0) pending entries: they carry no descriptors,
|
|
35
|
+
// so no id form could ever address them and they would accumulate toward
|
|
36
|
+
// the retention breaker. Give each a unique synthetic ref and a note that
|
|
37
|
+
// names it, keeping the restored session operable without exposing hashes.
|
|
38
|
+
const takenRefs = new Set(Object.values(this.s.pending)
|
|
39
|
+
.filter((entry) => entry.ref !== undefined).flatMap((entry) => [entry.ref, `${entry.kind}:${entry.ref}`]));
|
|
40
|
+
let restored = 0;
|
|
41
|
+
for (const entry of Object.values(this.s.pending)) {
|
|
42
|
+
if (entry.ref !== undefined) continue;
|
|
43
|
+
do { restored += 1; entry.ref = `restored-${restored}`; } while (takenRefs.has(entry.ref) || takenRefs.has(`${entry.kind ?? "event"}:${entry.ref}`));
|
|
44
|
+
takenRefs.add(entry.ref); takenRefs.add(`${entry.kind ?? "event"}:${entry.ref}`);
|
|
45
|
+
entry.kind = entry.kind ?? "event";
|
|
46
|
+
entry.note = clip(`${entry.note ?? "unrecognized event from an older session"} — ack id ${entry.ref}`, MAX_NOTE_CHARS);
|
|
47
|
+
}
|
|
33
48
|
if (typeof this.s.enabled !== "boolean" || typeof this.s.retired !== "boolean" ||
|
|
34
49
|
!Number.isInteger(this.s.errors) || this.s.errors < 0) throw new Error("Invalid persisted eyes state");
|
|
35
50
|
this.save = save; this.observe = observe; this.deliver = deliver; this.now = now; this.status = status;
|
|
@@ -40,15 +55,38 @@ export class Eyes {
|
|
|
40
55
|
// same pending revisions; business-effect idempotence remains with .5.4.
|
|
41
56
|
this.inflight = false;
|
|
42
57
|
this.sent = new Map();
|
|
58
|
+
// Revisions actually rendered to the model this session (wake prefix and
|
|
59
|
+
// status details). Ref-based acknowledgement is held to them: a stale view
|
|
60
|
+
// can never discard a newer revision it has not seen. In-memory by design:
|
|
61
|
+
// after a restart nothing is considered presented until re-rendered.
|
|
62
|
+
this.presented = new Map();
|
|
43
63
|
this.lastDelivery = new Map();
|
|
44
64
|
this.generation = 0;
|
|
45
65
|
}
|
|
66
|
+
/** Record the revisions the model was just shown (wake prefix or status). */
|
|
67
|
+
markPresented(entries) {
|
|
68
|
+
for (const { key, revision } of Array.isArray(entries) ? entries : []) {
|
|
69
|
+
if (typeof key === "string" && key && typeof revision === "string" && revision) this.presented.set(key, revision);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Bind raw receipt rows to current pending entries: only a row whose
|
|
73
|
+
* exact revision is still pending becomes presented, so a report digest
|
|
74
|
+
* authorizes nothing beyond the outcomes it actually names. */
|
|
75
|
+
markReceiptPresented(rows) {
|
|
76
|
+
for (const { key, revision } of Array.isArray(rows) ? rows : []) {
|
|
77
|
+
if (typeof key === "string" && key && typeof revision === "string" && revision &&
|
|
78
|
+
this.s.pending[key]?.revision === revision) {
|
|
79
|
+
this.presented.set(key, this.s.pending[key].revision);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
46
83
|
persist() { this.save(structuredClone(this.s)); this.status(this.summary()); }
|
|
47
84
|
summary() { return { enabled: this.s.enabled, retired: this.s.retired, pending: Object.keys(this.s.pending).length,
|
|
85
|
+
deadlines: Object.keys(this.s.deadlines).length,
|
|
48
86
|
breaker: this.s.breaker, errors: this.s.errors + Number(this.s.observationUnavailable === true),
|
|
49
87
|
observationUnavailable: this.s.observationUnavailable === true,
|
|
50
88
|
observations: this.s.window?.count || 0, wakes: this.s.window?.wakes || 0,
|
|
51
|
-
wakeLimitedUntil: this.wakeLimitedUntil() }; }
|
|
89
|
+
wakeLimit: this.s.config.maxWakesPerHour, wakeLimitedUntil: this.wakeLimitedUntil() }; }
|
|
52
90
|
wakeLimitedUntil() {
|
|
53
91
|
const window = this.s.window;
|
|
54
92
|
if (!window || (window.wakes || 0) < this.s.config.maxWakesPerHour) return null;
|
|
@@ -104,6 +142,7 @@ export class Eyes {
|
|
|
104
142
|
this.s.deadlines[name] = { at, operationRevision }; this.persist();
|
|
105
143
|
}
|
|
106
144
|
cancelDeadline(name) {
|
|
145
|
+
if (!this.s.deadlines[name]) throw new Error(`No deadline named ${clip(name, 64)} is registered`);
|
|
107
146
|
delete this.s.deadlines[name]; delete this.s.pending[`deadline:${name}`];
|
|
108
147
|
this.sent.delete(`deadline:${name}`); this.inflight = this.sent.size > 0; this.persist();
|
|
109
148
|
}
|
|
@@ -115,6 +154,54 @@ export class Eyes {
|
|
|
115
154
|
this.sent.delete(key);
|
|
116
155
|
this.inflight = this.sent.size > 0; this.persist();
|
|
117
156
|
}
|
|
157
|
+
/** Resolve a short id from the digest to exactly one pending event. Exact
|
|
158
|
+
* keys (deadline:<name>, composite kind:ref) win over bare refs; a restored
|
|
159
|
+
* entry's non-hash persisted id is accepted as a last resort. Ambiguity and
|
|
160
|
+
* unknown ids are refused without side effects, and an ambiguous id names
|
|
161
|
+
* its bounded candidates instead of advising the form that was refused. */
|
|
162
|
+
/** Resolve a short id to exactly one pending event and acknowledge it.
|
|
163
|
+
* Model-facing paths (ace_eyes tool) require the revision to have been
|
|
164
|
+
* presented this session and hold stale views to the presented revision.
|
|
165
|
+
* The operator /eyes ack command runs under explicit human authority: it
|
|
166
|
+
* acknowledges the current pending revision the operator just viewed. */
|
|
167
|
+
ackByRef(ref, { presentationRequired = true } = {}) {
|
|
168
|
+
if (typeof ref !== "string" || !ref.trim()) throw new Error("Ack requires a pending event id from ace_eyes status");
|
|
169
|
+
const wanted = ref.trim();
|
|
170
|
+
const candidates = Object.entries(this.s.pending).filter(([, value]) =>
|
|
171
|
+
value.ref === wanted || `${value.kind}:${value.ref}` === wanted ||
|
|
172
|
+
(typeof value.id === "string" && value.id && !HEX64.test(value.id) && value.id === wanted));
|
|
173
|
+
if (candidates.length === 0) {
|
|
174
|
+
throw new Error(`No pending event matches ${clip(wanted, 64)}; run ace_eyes action status for current pending ids`);
|
|
175
|
+
}
|
|
176
|
+
if (candidates.length > 1) {
|
|
177
|
+
const named = candidates.slice(0, 3).map(([, value]) => clip(value.note ?? `${value.kind ?? "event"}:${value.ref ?? ""}`, 60));
|
|
178
|
+
const more = candidates.length > named.length ? ` (+${candidates.length - named.length} more)` : "";
|
|
179
|
+
const advice = wanted.includes(":")
|
|
180
|
+
? "no id form disambiguates identical identities; handle one at its owner, the other stays pending"
|
|
181
|
+
: "ack each by its unique kind:id";
|
|
182
|
+
throw new Error(`Ambiguous id ${clip(wanted, 64)} matches ${candidates.length} pending events — ${named.join(" | ")}${more}; ${advice}`);
|
|
183
|
+
}
|
|
184
|
+
const [key, value] = candidates[0];
|
|
185
|
+
if (presentationRequired) {
|
|
186
|
+
const presented = this.presented.get(key);
|
|
187
|
+
if (presented === undefined) {
|
|
188
|
+
throw new Error(`No revision of ${clip(wanted, 64)} was presented in this session; run ace_eyes action status for the current note, then ack`);
|
|
189
|
+
}
|
|
190
|
+
// The stale branch requires pending to be NEWER than presented: revisions
|
|
191
|
+
// only advance (observed revisions overwrite, acknowledged suppress older).
|
|
192
|
+
if (presented !== value.revision) {
|
|
193
|
+
// Stale view: acknowledge exactly the presented revision and keep the
|
|
194
|
+
// newer unseen revision pending so it re-reports on the next delivery.
|
|
195
|
+
this.s.acknowledged[key] = presented;
|
|
196
|
+
this.sent.delete(key);
|
|
197
|
+
this.inflight = this.sent.size > 0;
|
|
198
|
+
this.persist();
|
|
199
|
+
return { ...value, stale: true };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
this.ack(key, value.revision);
|
|
203
|
+
return { ...value };
|
|
204
|
+
}
|
|
118
205
|
validate(result) {
|
|
119
206
|
if (result?.schema !== "ace.hitl.observation/v1" || !Array.isArray(result.events) || result.events.length > this.s.config.maxEvents)
|
|
120
207
|
throw new Error("Invalid or over-budget HITL observation");
|
|
@@ -176,7 +263,33 @@ export class Eyes {
|
|
|
176
263
|
}
|
|
177
264
|
if (this.inflight && this.sent.size === 0) this.inflight = false;
|
|
178
265
|
for (const e of result.events) {
|
|
179
|
-
if (this.s.acknowledged[e.key] !== e.revision)
|
|
266
|
+
if (this.s.acknowledged[e.key] !== e.revision) {
|
|
267
|
+
const described = describeEvent(e);
|
|
268
|
+
// Keep kind:ref unique across pending entries: a colliding second
|
|
269
|
+
// event gets a numbered ref (named in its note) so the kind:id
|
|
270
|
+
// form stays resolvable instead of dead-ending in ambiguity.
|
|
271
|
+
if (described.ref !== undefined) {
|
|
272
|
+
const original = described.ref;
|
|
273
|
+
let candidate = original;
|
|
274
|
+
let sequence = 2;
|
|
275
|
+
while (Object.entries(this.s.pending).some(([k, v]) => k !== e.key && (v.ref === candidate || `${v.kind}:${v.ref}` === `${described.kind}:${candidate}`))) {
|
|
276
|
+
candidate = `${original}#${sequence++}`;
|
|
277
|
+
}
|
|
278
|
+
if (candidate !== original) {
|
|
279
|
+
described.note = clip(described.note.replace(original, candidate), MAX_NOTE_CHARS);
|
|
280
|
+
described.ref = candidate;
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
// An unknown or malformed event shape derives no ref; without one
|
|
284
|
+
// it could never be acknowledged and would only feed the breaker.
|
|
285
|
+
let sequence = 1;
|
|
286
|
+
let candidate;
|
|
287
|
+
do { candidate = `event-${sequence++}`; } while (Object.entries(this.s.pending).some(([k, v]) => k !== e.key && (v.ref === candidate || `${v.kind}:${v.ref}` === `event:${candidate}`)));
|
|
288
|
+
described.ref = candidate;
|
|
289
|
+
described.note = clip(`${described.note} — ack id ${candidate}`, MAX_NOTE_CHARS);
|
|
290
|
+
}
|
|
291
|
+
this.s.pending[e.key] = { id: e.id, revision: e.revision, ...described };
|
|
292
|
+
}
|
|
180
293
|
}
|
|
181
294
|
observed = true;
|
|
182
295
|
}
|
|
@@ -184,7 +297,8 @@ export class Eyes {
|
|
|
184
297
|
for (const [name, deadline] of Object.entries(this.s.deadlines)) {
|
|
185
298
|
const { at, operationRevision } = deadline;
|
|
186
299
|
const key = `deadline:${name}`, revision = hash([name, at, operationRevision]);
|
|
187
|
-
if (this.now() >= at && this.s.acknowledged[key] !== revision)
|
|
300
|
+
if (this.now() >= at && this.s.acknowledged[key] !== revision)
|
|
301
|
+
this.s.pending[key] = { id: name, revision, kind: "deadline", ref: name, note: `deadline:${name} reached` };
|
|
188
302
|
}
|
|
189
303
|
if (Object.keys(this.s.pending).length + Object.keys(this.s.acknowledged).length > this.s.config.maxPending) {
|
|
190
304
|
this.block("retention-budget"); return;
|
data/lib/ace/wake/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ace-wake
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michal Czyz
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-11-
|
|
10
|
+
date: 2026-11-17 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: ace-runtime
|
|
@@ -44,6 +44,7 @@ files:
|
|
|
44
44
|
- handbook/extensions/ace-wake/index.js
|
|
45
45
|
- handbook/extensions/ace-wake/package.json
|
|
46
46
|
- handbook/extensions/ace-wake/wake/ask-bridge.js
|
|
47
|
+
- handbook/extensions/ace-wake/wake/eyes-digest.js
|
|
47
48
|
- handbook/extensions/ace-wake/wake/eyes-runtime.js
|
|
48
49
|
- handbook/extensions/ace-wake/wake/eyes.js
|
|
49
50
|
- handbook/extensions/ace-wake/wake/inbox-discovery.js
|