repoburg 1.3.229 → 1.3.231

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.
@@ -43158,12 +43158,12 @@ Agent responded: "${truncatedResponse}"`;
43158
43158
  });
43159
43159
  const title = await titlePromise;
43160
43160
  clearTimeout(timeout);
43161
- const cleanTitle = title.trim().replace(/^["']|["']$/g, "").slice(0, 100);
43162
- if (cleanTitle) {
43161
+ const cleanTitle2 = title.trim().replace(/^["']|["']$/g, "").slice(0, 100);
43162
+ if (cleanTitle2) {
43163
43163
  const db2 = getDb();
43164
43164
  const now = (/* @__PURE__ */ new Date()).toISOString();
43165
- db2.prepare("UPDATE sessions SET title = ?, updated_at = ? WHERE id = ?").run(cleanTitle, now, sessionId);
43166
- broadcast("session:title", { sessionId, title: cleanTitle });
43165
+ db2.prepare("UPDATE sessions SET title = ?, updated_at = ? WHERE id = ?").run(cleanTitle2, now, sessionId);
43166
+ broadcast("session:title", { sessionId, title: cleanTitle2 });
43167
43167
  }
43168
43168
  } catch {
43169
43169
  } finally {
@@ -44210,12 +44210,12 @@ Agent responded: "${truncatedResponse}"`;
44210
44210
  }
44211
44211
  }
44212
44212
  }
44213
- const cleanTitle = titleResponse.trim().replace(/^["']|["']$/g, "").slice(0, 100);
44214
- if (cleanTitle) {
44213
+ const cleanTitle2 = titleResponse.trim().replace(/^["']|["']$/g, "").slice(0, 100);
44214
+ if (cleanTitle2) {
44215
44215
  const db2 = getDb();
44216
44216
  const now = (/* @__PURE__ */ new Date()).toISOString();
44217
- db2.prepare("UPDATE sessions SET title = ?, updated_at = ? WHERE id = ?").run(cleanTitle, now, sessionId);
44218
- broadcast("session:title", { sessionId, title: cleanTitle });
44217
+ db2.prepare("UPDATE sessions SET title = ?, updated_at = ? WHERE id = ?").run(cleanTitle2, now, sessionId);
44218
+ broadcast("session:title", { sessionId, title: cleanTitle2 });
44219
44219
  }
44220
44220
  } catch {
44221
44221
  } finally {
@@ -44320,6 +44320,8 @@ function isHtml(text) {
44320
44320
  return /^\s*<(?:!doctype|html)/i.test(text);
44321
44321
  }
44322
44322
  var RepoburgHttpClient = class {
44323
+ /** Base URL of the repoburg backend (public — the projector opens the
44324
+ * agent-runtime SSE channel for the throwaway title session). */
44323
44325
  baseUrl;
44324
44326
  constructor(baseUrl = defaultRepoburgBaseUrl()) {
44325
44327
  this.baseUrl = baseUrl.replace(/\/+$/, "");
@@ -44376,6 +44378,9 @@ var RepoburgHttpClient = class {
44376
44378
  `/sessions/${sessionId}/inputs/${anchorInputId}/until-here`
44377
44379
  );
44378
44380
  }
44381
+ async deleteSession(id) {
44382
+ await this.request("DELETE", `/sessions/${id}`);
44383
+ }
44379
44384
  async forkSession(sessionId, untilInputId) {
44380
44385
  return this.request("POST", `/sessions/${sessionId}/fork`, {
44381
44386
  until_input_id: untilInputId ?? null
@@ -44747,9 +44752,121 @@ function completeItem(db2, sessionId, turnId, item, data, status) {
44747
44752
  broadcast("item:completed", { sessionId, turnId, item: updated });
44748
44753
  }
44749
44754
 
44755
+ // src/repoburg/agent-runtime-client.ts
44756
+ function parseSseFrame(frame) {
44757
+ const dataLines = [];
44758
+ for (const line of frame.split("\n")) {
44759
+ const trimmed = line.replace(/\r$/, "");
44760
+ if (trimmed.startsWith(":")) continue;
44761
+ if (trimmed.startsWith("data:")) {
44762
+ dataLines.push(trimmed.slice(5).replace(/^ /, ""));
44763
+ }
44764
+ }
44765
+ if (dataLines.length === 0) return null;
44766
+ return dataLines.join("\n");
44767
+ }
44768
+ function createSseParser() {
44769
+ let buffer = "";
44770
+ return (chunk) => {
44771
+ buffer += chunk.replace(/\r\n/g, "\n");
44772
+ const payloads = [];
44773
+ let boundary;
44774
+ while ((boundary = buffer.indexOf("\n\n")) !== -1) {
44775
+ const frame = buffer.slice(0, boundary);
44776
+ buffer = buffer.slice(boundary + 2);
44777
+ const data = parseSseFrame(frame);
44778
+ if (data !== null) payloads.push(data);
44779
+ }
44780
+ return payloads;
44781
+ };
44782
+ }
44783
+ async function streamAgentRuntimeMessages(baseUrl, sessionId, onMessage, opts = {}) {
44784
+ const deltas = opts.deltas !== false;
44785
+ const delayMs = opts.reconnectDelayMs ?? 2e3;
44786
+ const url = `${baseUrl.replace(/\/+$/, "")}/agent-runtime/sessions/${sessionId}/messages?stream=${deltas ? 1 : 0}`;
44787
+ for (; ; ) {
44788
+ if (opts.signal?.aborted) return "aborted";
44789
+ let response;
44790
+ try {
44791
+ response = await fetch(url, { method: "GET", signal: opts.signal });
44792
+ } catch (err) {
44793
+ if (opts.signal?.aborted || err.name === "AbortError") {
44794
+ return "aborted";
44795
+ }
44796
+ await reconnectDelay(delayMs, opts.signal);
44797
+ continue;
44798
+ }
44799
+ if (response.status === 404) return "session-not-found";
44800
+ if (!response.ok || !response.body) {
44801
+ await reconnectDelay(delayMs, opts.signal);
44802
+ continue;
44803
+ }
44804
+ const reason = await readBody(
44805
+ response.body,
44806
+ onMessage,
44807
+ opts
44808
+ );
44809
+ if (reason !== null) {
44810
+ await response.body.cancel().catch(() => {
44811
+ });
44812
+ return reason;
44813
+ }
44814
+ await reconnectDelay(delayMs, opts.signal);
44815
+ }
44816
+ }
44817
+ async function readBody(body, onMessage, opts) {
44818
+ const parse = createSseParser();
44819
+ const decoder = new TextDecoder();
44820
+ const reader = body.getReader();
44821
+ try {
44822
+ for (; ; ) {
44823
+ const { done, value } = await reader.read();
44824
+ if (done) return null;
44825
+ opts.onActivity?.();
44826
+ for (const payload of parse(decoder.decode(value, { stream: true }))) {
44827
+ let message = null;
44828
+ try {
44829
+ message = JSON.parse(payload);
44830
+ } catch {
44831
+ continue;
44832
+ }
44833
+ if (!message || typeof message.type !== "string") continue;
44834
+ onMessage(message);
44835
+ if (message.type === "result") return "result";
44836
+ }
44837
+ }
44838
+ } catch (err) {
44839
+ if (opts.signal?.aborted || err.name === "AbortError") {
44840
+ return "aborted";
44841
+ }
44842
+ return null;
44843
+ } finally {
44844
+ try {
44845
+ reader.releaseLock();
44846
+ } catch {
44847
+ }
44848
+ }
44849
+ }
44850
+ function reconnectDelay(delayMs, signal) {
44851
+ return new Promise((resolve) => {
44852
+ if (signal?.aborted) return resolve();
44853
+ const timer = setTimeout(resolve, delayMs);
44854
+ signal?.addEventListener(
44855
+ "abort",
44856
+ () => {
44857
+ clearTimeout(timer);
44858
+ resolve();
44859
+ },
44860
+ { once: true }
44861
+ );
44862
+ });
44863
+ }
44864
+
44750
44865
  // src/repoburg/turn-projector.ts
44751
44866
  var RESULT_TIMEOUT_MS = 15 * 6e4;
44752
44867
  var MAX_RESULT_EXTENSIONS = 3;
44868
+ var TITLE_TIMEOUT_MS = 9e4;
44869
+ var titleGenerating3 = /* @__PURE__ */ new Set();
44753
44870
  var TurnProjector = class {
44754
44871
  constructor(deps) {
44755
44872
  this.deps = deps;
@@ -45069,7 +45186,10 @@ var TurnProjector = class {
45069
45186
  this.deps.agentPaneSessionId
45070
45187
  );
45071
45188
  }
45072
- /** Fire-and-forget: copy the runtime session title once (new sessions). */
45189
+ /** Fire-and-forget: copy the runtime session title once (new sessions).
45190
+ * When the runtime produced no title (the backend's default agent no
45191
+ * longer sets one), generate a title with a throwaway runtime session —
45192
+ * the same title-generation pattern the Claude/Codex providers use. */
45073
45193
  async syncTitle() {
45074
45194
  try {
45075
45195
  const db2 = getDb();
@@ -45079,15 +45199,82 @@ var TurnProjector = class {
45079
45199
  if (!session || session.title) return;
45080
45200
  const runtimeSession = await this.deps.client.getSession(this.deps.repoburgSessionId);
45081
45201
  const title = (runtimeSession.session_title || "").trim();
45082
- if (!title) return;
45083
- const now = (/* @__PURE__ */ new Date()).toISOString();
45084
- db2.prepare("UPDATE sessions SET title = ?, updated_at = ? WHERE id = ?").run(
45085
- title,
45086
- now,
45087
- this.deps.agentPaneSessionId
45202
+ if (title) {
45203
+ this.applyTitle(title);
45204
+ return;
45205
+ }
45206
+ await this.generateTitleFallback();
45207
+ } catch {
45208
+ }
45209
+ }
45210
+ /** Persist + broadcast a title. */
45211
+ applyTitle(title) {
45212
+ const db2 = getDb();
45213
+ const now = (/* @__PURE__ */ new Date()).toISOString();
45214
+ db2.prepare("UPDATE sessions SET title = ?, updated_at = ? WHERE id = ?").run(
45215
+ title,
45216
+ now,
45217
+ this.deps.agentPaneSessionId
45218
+ );
45219
+ broadcast("session:title", { sessionId: this.deps.agentPaneSessionId, title });
45220
+ }
45221
+ /** Title-generation pattern (Claude/Codex provider parity): run ONE prompt
45222
+ * on a THROWAWAY runtime session, take the reply as the title, delete the
45223
+ * session. The main runtime session is never touched. Silent on failure —
45224
+ * the session simply keeps a null title. */
45225
+ async generateTitleFallback() {
45226
+ const sessionId = this.deps.agentPaneSessionId;
45227
+ if (titleGenerating3.has(sessionId)) return;
45228
+ const db2 = getDb();
45229
+ const firstTurn = db2.prepare(
45230
+ "SELECT user_prompt, agent_response FROM turns WHERE session_id = ? ORDER BY created_at ASC LIMIT 1"
45231
+ ).get(sessionId);
45232
+ if (!firstTurn) return;
45233
+ titleGenerating3.add(sessionId);
45234
+ let throwawayId = null;
45235
+ try {
45236
+ const pane = db2.prepare("SELECT model FROM sessions WHERE id = ?").get(sessionId);
45237
+ const created = await this.deps.client.createSession(
45238
+ pane?.model ? { model_id: pane.model } : {}
45088
45239
  );
45089
- broadcast("session:title", { sessionId: this.deps.agentPaneSessionId, title });
45240
+ throwawayId = created.id;
45241
+ const controller = new AbortController();
45242
+ const timer = setTimeout(() => controller.abort(), TITLE_TIMEOUT_MS);
45243
+ try {
45244
+ await this.deps.client.createInput(throwawayId, {
45245
+ user_prompt: buildTitlePrompt(firstTurn.user_prompt, firstTurn.agent_response),
45246
+ execution_strategy: "auto_apply"
45247
+ });
45248
+ let reply = "";
45249
+ const consume = (message) => {
45250
+ if (message.type === "assistant") {
45251
+ reply += message.content.filter((b) => b.type === "text").map((b) => b.text).join("");
45252
+ } else if (message.type === "result" && !message.is_error && message.result) {
45253
+ reply = message.result;
45254
+ }
45255
+ };
45256
+ const reason = await streamAgentRuntimeMessages(
45257
+ this.deps.client.baseUrl,
45258
+ throwawayId,
45259
+ consume,
45260
+ { signal: controller.signal, deltas: false }
45261
+ );
45262
+ if (reason === "aborted") {
45263
+ void this.deps.client.cancel(throwawayId).catch(() => {
45264
+ });
45265
+ }
45266
+ const title = cleanTitle(reply);
45267
+ if (title) this.applyTitle(title);
45268
+ } finally {
45269
+ clearTimeout(timer);
45270
+ }
45090
45271
  } catch {
45272
+ } finally {
45273
+ if (throwawayId) {
45274
+ void this.deps.client.deleteSession(throwawayId).catch(() => {
45275
+ });
45276
+ }
45277
+ titleGenerating3.delete(sessionId);
45091
45278
  }
45092
45279
  }
45093
45280
  finishFailed(error) {
@@ -45259,115 +45446,17 @@ function extractFinalPlain(input) {
45259
45446
  );
45260
45447
  return action?.plain ?? null;
45261
45448
  }
45449
+ function buildTitlePrompt(userPrompt, agentResponse) {
45450
+ const truncatedPrompt = userPrompt.slice(0, 500);
45451
+ const truncatedResponse = (agentResponse ?? "").slice(0, 500);
45452
+ return `Generate a concise 3-5 word title for this conversation. Reply with only the title, nothing else.
45262
45453
 
45263
- // src/repoburg/agent-runtime-client.ts
45264
- function parseSseFrame(frame) {
45265
- const dataLines = [];
45266
- for (const line of frame.split("\n")) {
45267
- const trimmed = line.replace(/\r$/, "");
45268
- if (trimmed.startsWith(":")) continue;
45269
- if (trimmed.startsWith("data:")) {
45270
- dataLines.push(trimmed.slice(5).replace(/^ /, ""));
45271
- }
45272
- }
45273
- if (dataLines.length === 0) return null;
45274
- return dataLines.join("\n");
45275
- }
45276
- function createSseParser() {
45277
- let buffer = "";
45278
- return (chunk) => {
45279
- buffer += chunk.replace(/\r\n/g, "\n");
45280
- const payloads = [];
45281
- let boundary;
45282
- while ((boundary = buffer.indexOf("\n\n")) !== -1) {
45283
- const frame = buffer.slice(0, boundary);
45284
- buffer = buffer.slice(boundary + 2);
45285
- const data = parseSseFrame(frame);
45286
- if (data !== null) payloads.push(data);
45287
- }
45288
- return payloads;
45289
- };
45290
- }
45291
- async function streamAgentRuntimeMessages(baseUrl, sessionId, onMessage, opts = {}) {
45292
- const deltas = opts.deltas !== false;
45293
- const delayMs = opts.reconnectDelayMs ?? 2e3;
45294
- const url = `${baseUrl.replace(/\/+$/, "")}/agent-runtime/sessions/${sessionId}/messages?stream=${deltas ? 1 : 0}`;
45295
- for (; ; ) {
45296
- if (opts.signal?.aborted) return "aborted";
45297
- let response;
45298
- try {
45299
- response = await fetch(url, { method: "GET", signal: opts.signal });
45300
- } catch (err) {
45301
- if (opts.signal?.aborted || err.name === "AbortError") {
45302
- return "aborted";
45303
- }
45304
- await reconnectDelay(delayMs, opts.signal);
45305
- continue;
45306
- }
45307
- if (response.status === 404) return "session-not-found";
45308
- if (!response.ok || !response.body) {
45309
- await reconnectDelay(delayMs, opts.signal);
45310
- continue;
45311
- }
45312
- const reason = await readBody(
45313
- response.body,
45314
- onMessage,
45315
- opts
45316
- );
45317
- if (reason !== null) {
45318
- await response.body.cancel().catch(() => {
45319
- });
45320
- return reason;
45321
- }
45322
- await reconnectDelay(delayMs, opts.signal);
45323
- }
45324
- }
45325
- async function readBody(body, onMessage, opts) {
45326
- const parse = createSseParser();
45327
- const decoder = new TextDecoder();
45328
- const reader = body.getReader();
45329
- try {
45330
- for (; ; ) {
45331
- const { done, value } = await reader.read();
45332
- if (done) return null;
45333
- opts.onActivity?.();
45334
- for (const payload of parse(decoder.decode(value, { stream: true }))) {
45335
- let message = null;
45336
- try {
45337
- message = JSON.parse(payload);
45338
- } catch {
45339
- continue;
45340
- }
45341
- if (!message || typeof message.type !== "string") continue;
45342
- onMessage(message);
45343
- if (message.type === "result") return "result";
45344
- }
45345
- }
45346
- } catch (err) {
45347
- if (opts.signal?.aborted || err.name === "AbortError") {
45348
- return "aborted";
45349
- }
45350
- return null;
45351
- } finally {
45352
- try {
45353
- reader.releaseLock();
45354
- } catch {
45355
- }
45356
- }
45454
+ User asked: "${truncatedPrompt}"
45455
+
45456
+ Agent responded: "${truncatedResponse}"`;
45357
45457
  }
45358
- function reconnectDelay(delayMs, signal) {
45359
- return new Promise((resolve) => {
45360
- if (signal?.aborted) return resolve();
45361
- const timer = setTimeout(resolve, delayMs);
45362
- signal?.addEventListener(
45363
- "abort",
45364
- () => {
45365
- clearTimeout(timer);
45366
- resolve();
45367
- },
45368
- { once: true }
45369
- );
45370
- });
45458
+ function cleanTitle(raw) {
45459
+ return raw.trim().replace(/^["']|["']$/g, "").split("\n")[0].replace(/\s+/g, " ").trim().slice(0, 100);
45371
45460
  }
45372
45461
 
45373
45462
  // src/repoburg/repoburg-provider.ts