agent-lyceum 0.51.0 → 0.53.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.
@@ -6,8 +6,8 @@
6
6
  <meta name="lyceum-token" content="__LYCEUM_TOKEN__" />
7
7
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
8
8
  <title>agent-lyceum</title>
9
- <script type="module" crossorigin src="/assets/index-C92kC3HN.js"></script>
10
- <link rel="stylesheet" crossorigin href="/assets/index-DvGpGOU4.css">
9
+ <script type="module" crossorigin src="/assets/index-DewSSyiZ.js"></script>
10
+ <link rel="stylesheet" crossorigin href="/assets/index-BPY1-W3F.css">
11
11
  </head>
12
12
  <body>
13
13
  <div id="root"></div>
@@ -108,9 +108,16 @@ async function runCommand(req, res, deps, id) {
108
108
  }
109
109
  if (def.mode(b) === "short") {
110
110
  const result = await runShort(deps.cli, deps.home, argv, { cwd, timeoutMs: deps.shortTimeoutMs ?? 120_000 });
111
- return send(res, 200, { mode: "short", ...result });
111
+ // `clear` only keeps decisions; whether to tidy them into project memory is the user's call (a dry run or a failed clear never tidies).
112
+ let tidyJobId;
113
+ if (id === "clear" && b.tidy === true && b.dryRun !== true && result.exit === 0) {
114
+ tidyJobId = startJob(deps.cli, deps.home, path.join(deps.home, "web-jobs"), "tidy", ["tidy", "-p", String(b.project)], cwd).id;
115
+ }
116
+ return send(res, 200, { mode: "short", ...result, ...(tidyJobId ? { tidyJobId } : {}) });
112
117
  }
113
118
  const job = startJob(deps.cli, deps.home, path.join(deps.home, "web-jobs"), id, argv, cwd);
119
+ if (id === "tidy" && typeof b.run === "string" && b.run.trim())
120
+ deps.markRunTidy?.(String(b.project), b.run.trim());
114
121
  send(res, 202, { mode: "detached", jobId: job.id, pid: job.pid });
115
122
  }
116
123
  function answersOf(value) {
@@ -72,6 +72,7 @@ export function createWebHub(factory) {
72
72
  })
73
73
  .catch(() => quota);
74
74
  };
75
+ const projectList = () => [...latest].map(([name, frame]) => ({ name, frame })).sort((a, b) => a.name.localeCompare(b.name));
75
76
  return {
76
77
  start: sync,
77
78
  beat: sync,
@@ -87,9 +88,10 @@ export function createWebHub(factory) {
87
88
  watchers.clear();
88
89
  listeners.clear();
89
90
  },
91
+ snapshot: projectList,
90
92
  subscribe(listener) {
91
93
  listeners.add(listener);
92
- const projects = [...latest].map(([name, frame]) => ({ name, frame })).sort((a, b) => a.name.localeCompare(b.name));
94
+ const projects = projectList();
93
95
  try {
94
96
  listener({ type: "snapshot", projects, ...(quota ? { quota } : {}) });
95
97
  }
@@ -149,7 +149,8 @@ export function readJob(jobsDir, id) {
149
149
  const found = view(dir);
150
150
  if (!found)
151
151
  return undefined;
152
- return { ...found, tail: tailOf(path.join(dir, "out.log")) };
152
+ const tail = tailOf(path.join(dir, "out.log"));
153
+ return { ...found, tail: tail.text, truncated: tail.truncated, lineStart: tail.lineStart, byteStart: tail.byteStart, gaps: tail.gaps };
153
154
  }
154
155
  function tailOf(file) {
155
156
  try {
@@ -159,13 +160,103 @@ function tailOf(file) {
159
160
  try {
160
161
  const buf = Buffer.alloc(size - start);
161
162
  fs.readSync(fd, buf, 0, buf.length, start);
162
- return buf.toString("utf8");
163
+ let lineStart = true;
164
+ if (start > 0) {
165
+ const prev = Buffer.alloc(1);
166
+ const n = fs.readSync(fd, prev, 0, 1, start - 1);
167
+ lineStart = n === 1 && prev[0] === 0x0a;
168
+ }
169
+ const text = buf.toString("utf8");
170
+ return { text, truncated: start > 0, lineStart, byteStart: start, gaps: utf8Gaps(buf) };
163
171
  }
164
172
  finally {
165
173
  fs.closeSync(fd);
166
174
  }
167
175
  }
168
176
  catch {
169
- return "";
177
+ return { text: "", truncated: false, lineStart: true, byteStart: 0, gaps: [] };
178
+ }
179
+ }
180
+ /** File bytes each U+FFFD replaced, when that run is not U+FFFD's own 3-byte encoding. One pass over the raw bytes. */
181
+ function utf8Gaps(buf) {
182
+ const gaps = [];
183
+ let at = 0;
184
+ let point = 0;
185
+ let seen = 0;
186
+ let needed = 0;
187
+ let lower = 0x80;
188
+ let upper = 0xbf;
189
+ const emit = (code, source) => {
190
+ if (code === 0xfffd && source !== 3)
191
+ gaps.push({ at, source });
192
+ at += code > 0xffff ? 2 : 1;
193
+ };
194
+ const reset = () => {
195
+ point = 0;
196
+ seen = 0;
197
+ needed = 0;
198
+ lower = 0x80;
199
+ upper = 0xbf;
200
+ };
201
+ for (let i = 0; i < buf.length; i++) {
202
+ const byte = buf[i];
203
+ if (byte === undefined)
204
+ break;
205
+ if (needed !== 0) {
206
+ if (byte >= lower && byte <= upper) {
207
+ lower = 0x80;
208
+ upper = 0xbf;
209
+ point = (point << 6) | (byte & 0x3f);
210
+ seen += 1;
211
+ if (seen === needed) {
212
+ const code = point;
213
+ const source = seen;
214
+ reset();
215
+ emit(code, source);
216
+ }
217
+ continue;
218
+ }
219
+ const source = seen;
220
+ reset();
221
+ emit(0xfffd, source);
222
+ i -= 1;
223
+ continue;
224
+ }
225
+ if (byte <= 0x7f) {
226
+ emit(byte, 1);
227
+ continue;
228
+ }
229
+ const lead = utf8Lead(byte);
230
+ if (lead === undefined) {
231
+ emit(0xfffd, 1);
232
+ continue;
233
+ }
234
+ point = lead.point;
235
+ seen = 1;
236
+ needed = lead.needed;
237
+ lower = lead.lower;
238
+ upper = lead.upper;
170
239
  }
240
+ if (needed !== 0)
241
+ emit(0xfffd, seen);
242
+ return gaps;
243
+ }
244
+ function utf8Lead(byte) {
245
+ if (byte >= 0xc2 && byte <= 0xdf)
246
+ return { point: byte & 0x1f, needed: 2, lower: 0x80, upper: 0xbf };
247
+ if (byte === 0xe0)
248
+ return { point: byte & 0x0f, needed: 3, lower: 0xa0, upper: 0xbf };
249
+ if (byte >= 0xe1 && byte <= 0xec)
250
+ return { point: byte & 0x0f, needed: 3, lower: 0x80, upper: 0xbf };
251
+ if (byte === 0xed)
252
+ return { point: byte & 0x0f, needed: 3, lower: 0x80, upper: 0x9f };
253
+ if (byte >= 0xee && byte <= 0xef)
254
+ return { point: byte & 0x0f, needed: 3, lower: 0x80, upper: 0xbf };
255
+ if (byte === 0xf0)
256
+ return { point: byte & 0x07, needed: 4, lower: 0x90, upper: 0xbf };
257
+ if (byte >= 0xf1 && byte <= 0xf3)
258
+ return { point: byte & 0x07, needed: 4, lower: 0x80, upper: 0xbf };
259
+ if (byte === 0xf4)
260
+ return { point: byte & 0x07, needed: 4, lower: 0x80, upper: 0x8f };
261
+ return undefined;
171
262
  }
package/web/dist/start.js CHANGED
@@ -44,6 +44,11 @@ export async function startWebServer(opts) {
44
44
  attachEvents(hub, req, res);
45
45
  return;
46
46
  }
47
+ if (pathname === "/snapshot" && req.method === "GET") {
48
+ res.writeHead(200, JSON_HEADERS);
49
+ res.end(JSON.stringify({ projects: hub.snapshot() }));
50
+ return;
51
+ }
47
52
  if (pathname === "/summary" && req.method === "POST") {
48
53
  void handleSummary(req, res, hub, opts.factory.summarize).catch(() => {
49
54
  if (res.headersSent)