@vibes.diy/api-svc 14.2.6 → 14.2.7

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.
Files changed (48) hide show
  1. package/create-handler.js +0 -6
  2. package/create-handler.js.map +1 -1
  3. package/index.d.ts +0 -2
  4. package/index.js +0 -2
  5. package/index.js.map +1 -1
  6. package/intern/agent-assembly.d.ts +0 -2
  7. package/intern/agent-assembly.js +1 -4
  8. package/intern/agent-assembly.js.map +1 -1
  9. package/intern/agent-first-turn-eligible.d.ts +1 -7
  10. package/intern/agent-first-turn-eligible.js +2 -5
  11. package/intern/agent-first-turn-eligible.js.map +1 -1
  12. package/intern/agent-router.d.ts +1 -3
  13. package/intern/agent-router.js +0 -16
  14. package/intern/agent-router.js.map +1 -1
  15. package/intern/agent-session-instruction.js.map +1 -1
  16. package/intern/agent-turn.d.ts +1 -4
  17. package/intern/agent-turn.js +4 -7
  18. package/intern/agent-turn.js.map +1 -1
  19. package/intern/agent-wake.d.ts +2 -3
  20. package/intern/agent-wake.js +2 -24
  21. package/intern/agent-wake.js.map +1 -1
  22. package/intern/codegen-build-lock.d.ts +0 -5
  23. package/intern/codegen-build-lock.js +0 -3
  24. package/intern/codegen-build-lock.js.map +1 -1
  25. package/intern/ensure-chat-id.js.map +1 -1
  26. package/intern/mint-decision.js.map +1 -1
  27. package/intern/mint-fire-core.js.map +1 -1
  28. package/intern/open-turn-store.d.ts +0 -4
  29. package/intern/open-turn-store.js +1 -6
  30. package/intern/open-turn-store.js.map +1 -1
  31. package/intern/open-turn-sweep.js +0 -1
  32. package/intern/open-turn-sweep.js.map +1 -1
  33. package/package.json +12 -12
  34. package/public/llm-dispatch.js +1 -3
  35. package/public/llm-dispatch.js.map +1 -1
  36. package/public/open-chat.js +3 -4
  37. package/public/open-chat.js.map +1 -1
  38. package/public/prompt-chat-section.js +275 -299
  39. package/public/prompt-chat-section.js.map +1 -1
  40. package/public/shared-mint.js +1 -1
  41. package/public/shared-mint.js.map +1 -1
  42. package/usage-report/codegen-delivery-alert-util.js.map +1 -1
  43. package/intern/agent-instruction.d.ts +0 -2
  44. package/intern/agent-instruction.js +0 -433
  45. package/intern/agent-instruction.js.map +0 -1
  46. package/intern/agent-lane-flag.d.ts +0 -21
  47. package/intern/agent-lane-flag.js +0 -10
  48. package/intern/agent-lane-flag.js.map +0 -1
@@ -27,12 +27,11 @@ import { bumpAppRecency } from "../intern/bump-app-recency.js";
27
27
  import { waitChatPersistIdle } from "../intern/chat-persist-gate.js";
28
28
  import { peekInFlightTurns } from "../intern/in-flight-turns.js";
29
29
  import { acquireTurnBuildLock, peekBuildLockEntry, releaseTurnBuildLock } from "../intern/codegen-build-lock.js";
30
- import { agentFirstTurnEnabled, agentLaneEnabled, agentSessionEnabled } from "../intern/agent-lane-flag.js";
31
30
  import { deliverAgentSession } from "../intern/agent-session-runtime.js";
32
31
  import { readAgentSession } from "../intern/agent-session-store.js";
33
32
  import { runEditVibeTool } from "../intern/agent-build-tools.js";
34
33
  import { claimFirstTurnMint, claimMintJob, getMintJob } from "../intern/mint-job-store.js";
35
- import { codegenTurnLane, legacyVariantHint, mintRowSaysFirstTurnIsAgents, routeAgentTurn, } from "../intern/agent-router.js";
34
+ import { codegenTurnLane, mintRowSaysFirstTurnIsAgents, routeAgentTurn } from "../intern/agent-router.js";
36
35
  import { assembleAgentPayload } from "../intern/agent-assembly.js";
37
36
  import { claimAgentAppContext, composeAgentRequest, isAppContextMessage, markJournalCacheTail, } from "../intern/agent-request-frame.js";
38
37
  import { createAgentBelt } from "../intern/agent-belt.js";
@@ -159,9 +158,8 @@ export const promptChatSection = {
159
158
  const agentWakeBudget = readAgentWakeBudget(orig.agentWakeBudget);
160
159
  const agentWakeNoteRaw = orig.agentWakeNote;
161
160
  const agentWakeNote = agentWakeTurn === true && typeof agentWakeNoteRaw === "string" ? agentWakeNoteRaw : undefined;
162
- const agentLane = agentLaneEnabled(vctx);
163
- const firstTurnAgent = agentLane && agentFirstTurnEnabled(vctx) && orig.firstTurnAgent === true;
164
- const nonInteractive = agentLane && orig.nonInteractive === true;
161
+ const firstTurnAgent = orig.firstTurnAgent === true;
162
+ const nonInteractive = orig.nonInteractive === true;
165
163
  let agentFetchUrlContext;
166
164
  await waitChatPersistIdle(vctx.connections, req.chatId, { logger: vctx.logger });
167
165
  const rResChat = await getResChatFromMode(vctx, req, orig);
@@ -207,7 +205,6 @@ export const promptChatSection = {
207
205
  }
208
206
  }
209
207
  const routeInput = {
210
- agentLane,
211
208
  codegenChatTurn: true,
212
209
  dryRun: orig.dryRun === true,
213
210
  directBuildRequested,
@@ -216,10 +213,8 @@ export const promptChatSection = {
216
213
  firstTurnAgent,
217
214
  };
218
215
  let agentRoute = routeAgentTurn(routeInput);
219
- const mintRowWorthReading = agentLane &&
220
- agentFirstTurnEnabled(vctx) &&
221
- ((agentRoute.route === "codegen" && agentRoute.skip === "first-turn") ||
222
- (agentRoute.route === "agent" && hasPriorTurn === true));
216
+ const mintRowWorthReading = (agentRoute.route === "codegen" && agentRoute.skip === "first-turn") ||
217
+ (agentRoute.route === "agent" && hasPriorTurn === true);
223
218
  if (mintRowWorthReading) {
224
219
  const rJob = await getMintJob(vctx, req.chatId);
225
220
  if (rJob.isErr()) {
@@ -249,12 +244,11 @@ export const promptChatSection = {
249
244
  appSlug: resChat.appSlug,
250
245
  activatedUrls: activateWorkUrls(currentUserMessageText(orig.prompt.messages.filter(isChatMessage))),
251
246
  });
252
- const legacyHint = legacyVariantHint(orig.variant);
253
247
  const buildInFlight = peekBuildLockEntry(vctx.connections, req.chatId);
254
- const rSeenHead = agentSessionEnabled(vctx) ? await readAgentSession(vctx.sql, req.chatId) : undefined;
255
- if (rSeenHead !== undefined && rSeenHead.isErr())
248
+ const rSeenHead = await readAgentSession(vctx.sql, req.chatId);
249
+ if (rSeenHead.isErr())
256
250
  vctx.logger.Warn().Err(rSeenHead).Str("chatId", req.chatId).Msg("agent-session-head-read-failed");
257
- const lastSeenHeadFsId = rSeenHead !== undefined && rSeenHead.isOk() ? rSeenHead.Ok().snapshot?.headFsId : undefined;
251
+ const lastSeenHeadFsId = rSeenHead.isOk() ? rSeenHead.Ok().snapshot?.headFsId : undefined;
258
252
  const rAgent = await assembleAgentPayload(vctx, {
259
253
  chatId: req.chatId,
260
254
  userId: req._auth.verifiedAuth.claims.userId,
@@ -262,171 +256,167 @@ export const promptChatSection = {
262
256
  ownerHandle: resChat.ownerHandle,
263
257
  appSlug: resChat.appSlug,
264
258
  newUserMessages: orig.prompt.messages.filter(isChatMessage),
265
- ...(legacyHint === undefined ? {} : { legacyHint }),
266
259
  ...(agentWakeNote === undefined ? {} : { wakeNote: agentWakeNote }),
267
260
  ...(buildInFlight === undefined ? {} : { buildInFlight: { promptId: buildInFlight.promptId } }),
268
261
  ...(agentFirstTurnMint ? { noAppYet: true } : {}),
269
262
  ...(nonInteractive ? { nonInteractive: true } : {}),
270
- ...(agentSessionEnabled(vctx) ? { session: true } : {}),
271
263
  ...(lastSeenHeadFsId === undefined ? {} : { lastSeenHeadFsId }),
272
264
  });
273
265
  if (rAgent.isErr())
274
266
  return Result.Err(rAgent);
275
267
  agentAssembled = { model: rAgent.Ok().model, messages: rAgent.Ok().messages };
276
- if (agentSessionEnabled(vctx)) {
277
- const rawIncoming = orig.prompt.messages.filter(isUserChatMessage);
278
- const newMessageCount = orig.prompt.messages.filter(isChatMessage).length;
279
- const incoming = newMessageCount === 0 ? [] : rAgent.Ok().messages.slice(-newMessageCount).filter(isUserChatMessage);
280
- const delivered = incoming.length === 0 && agentWakeTurn
281
- ? [
282
- {
283
- role: "user",
284
- content: [
285
- {
286
- type: "text",
287
- text: agentWakeNote ??
288
- "[session resumed] Continue from your persisted context and pending results. Inspect outcomes before retrying interrupted tools.",
289
- },
290
- ],
291
- },
292
- ]
293
- : incoming;
294
- const acquired = await deliverAgentSession(vctx, {
268
+ const rawIncoming = orig.prompt.messages.filter(isUserChatMessage);
269
+ const newMessageCount = orig.prompt.messages.filter(isChatMessage).length;
270
+ const incoming = newMessageCount === 0 ? [] : rAgent.Ok().messages.slice(-newMessageCount).filter(isUserChatMessage);
271
+ const delivered = incoming.length === 0 && agentWakeTurn
272
+ ? [
273
+ {
274
+ role: "user",
275
+ content: [
276
+ {
277
+ type: "text",
278
+ text: agentWakeNote ??
279
+ "[session resumed] Continue from your persisted context and pending results. Inspect outcomes before retrying interrupted tools.",
280
+ },
281
+ ],
282
+ },
283
+ ]
284
+ : incoming;
285
+ const acquired = await deliverAgentSession(vctx, {
286
+ chatId: req.chatId,
287
+ userId: req._auth.verifiedAuth.claims.userId,
288
+ ownerHandle: resChat.ownerHandle,
289
+ appSlug: resChat.appSlug,
290
+ }, { id: ctx.validated.tid, messages: delivered }, rAgent.Ok().messages.filter((message) => message.role === "system" || isAppContextMessage(message)));
291
+ if (acquired.isErr())
292
+ return Result.Err(acquired.Err());
293
+ const { live, created } = acquired.Ok();
294
+ const composedHead = rAgent.Ok().headFsId;
295
+ if (composedHead !== undefined) {
296
+ const noted = await live.session.observeHead(composedHead);
297
+ if (noted.isErr())
298
+ vctx.logger.Warn().Err(noted).Str("chatId", req.chatId).Msg("agent-session-head-note-failed");
299
+ }
300
+ if (created === false) {
301
+ const receiptId = vctx.sthis.nextId(12).str;
302
+ const receiptEvidence = createAgentEvidenceWriter({
295
303
  chatId: req.chatId,
296
- userId: req._auth.verifiedAuth.claims.userId,
297
- ownerHandle: resChat.ownerHandle,
298
- appSlug: resChat.appSlug,
299
- }, { id: ctx.validated.tid, messages: delivered }, rAgent.Ok().messages.filter((message) => message.role === "system" || isAppContextMessage(message)));
300
- if (acquired.isErr())
301
- return Result.Err(acquired.Err());
302
- const { live, created } = acquired.Ok();
303
- const composedHead = rAgent.Ok().headFsId;
304
- if (composedHead !== undefined) {
305
- const noted = await live.session.observeHead(composedHead);
306
- if (noted.isErr())
307
- vctx.logger.Warn().Err(noted).Str("chatId", req.chatId).Msg("agent-session-head-note-failed");
308
- }
309
- if (created === false) {
310
- const receiptId = vctx.sthis.nextId(12).str;
311
- const receiptEvidence = createAgentEvidenceWriter({
304
+ promptId: receiptId,
305
+ sessionId: live.promptId,
306
+ append: (evt, blockSeq) => appendBlockEvent({ ctx, vctx, req, promptId: receiptId, blockSeq, evt }),
307
+ });
308
+ const linked = await receiptEvidence({ kind: "active" });
309
+ if (linked.isErr())
310
+ return Result.Err(linked.Err());
311
+ await ctx.send.send(ctx, wrapMsgBase(ctx.validated, {
312
+ payload: {
313
+ type: "vibes.diy.res-prompt-chat-section",
312
314
  chatId: req.chatId,
315
+ ownerHandle: resChat.ownerHandle,
316
+ appSlug: resChat.appSlug,
313
317
  promptId: receiptId,
314
- sessionId: live.promptId,
315
- append: (evt, blockSeq) => appendBlockEvent({ ctx, vctx, req, promptId: receiptId, blockSeq, evt }),
316
- });
317
- const linked = await receiptEvidence({ kind: "active" });
318
- if (linked.isErr())
319
- return Result.Err(linked.Err());
320
- await ctx.send.send(ctx, wrapMsgBase(ctx.validated, {
321
- payload: {
322
- type: "vibes.diy.res-prompt-chat-section",
323
- chatId: req.chatId,
324
- ownerHandle: resChat.ownerHandle,
325
- appSlug: resChat.appSlug,
326
- promptId: receiptId,
327
- outerTid: req.outerTid,
328
- mode: req.mode,
329
- },
330
- tid: ctx.validated.tid,
331
- src: "agentSession",
332
- }));
333
- const echo = await appendBlockEvent({
334
- ctx,
335
- vctx,
336
- req,
337
- promptId: receiptId,
338
- blockSeq: 0,
339
- evt: {
340
- type: "prompt.req",
341
- ...(orig.mode === "codegen" && orig.source === "suggestion" ? { source: "suggestion" } : {}),
342
- streamId: receiptId,
343
- chatId: req.chatId,
344
- seq: 0,
345
- request: { messages: rawIncoming },
346
- timestamp: new Date(),
347
- },
348
- });
349
- if (echo.isErr())
350
- return Result.Err(echo.Err());
351
- const terminal = await appendBlockEvent({
352
- ctx,
353
- vctx,
354
- req,
355
- promptId: receiptId,
356
- blockSeq: 1,
357
- evt: {
358
- type: "block.end",
359
- streamId: receiptId,
360
- blockId: receiptId,
361
- blockNr: 0,
362
- seq: 1,
363
- timestamp: new Date(),
364
- stats: {
365
- toplevel: { lines: 0, bytes: 0 },
366
- code: { lines: 0, bytes: 0 },
367
- image: { lines: 0, bytes: 0 },
368
- total: { lines: 0, bytes: 0 },
369
- },
370
- usage: { given: [], calculated: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 } },
318
+ outerTid: req.outerTid,
319
+ mode: req.mode,
320
+ },
321
+ tid: ctx.validated.tid,
322
+ src: "agentSession",
323
+ }));
324
+ const echo = await appendBlockEvent({
325
+ ctx,
326
+ vctx,
327
+ req,
328
+ promptId: receiptId,
329
+ blockSeq: 0,
330
+ evt: {
331
+ type: "prompt.req",
332
+ ...(orig.mode === "codegen" && orig.source === "suggestion" ? { source: "suggestion" } : {}),
333
+ streamId: receiptId,
334
+ chatId: req.chatId,
335
+ seq: 0,
336
+ request: { messages: rawIncoming },
337
+ timestamp: new Date(),
338
+ },
339
+ });
340
+ if (echo.isErr())
341
+ return Result.Err(echo.Err());
342
+ const terminal = await appendBlockEvent({
343
+ ctx,
344
+ vctx,
345
+ req,
346
+ promptId: receiptId,
347
+ blockSeq: 1,
348
+ evt: {
349
+ type: "block.end",
350
+ streamId: receiptId,
351
+ blockId: receiptId,
352
+ blockNr: 0,
353
+ seq: 1,
354
+ timestamp: new Date(),
355
+ stats: {
356
+ toplevel: { lines: 0, bytes: 0 },
357
+ code: { lines: 0, bytes: 0 },
358
+ image: { lines: 0, bytes: 0 },
359
+ total: { lines: 0, bytes: 0 },
371
360
  },
372
- });
373
- if (terminal.isErr())
374
- return Result.Err(terminal.Err());
375
- const ended = await appendBlockEvent({
376
- ctx,
377
- vctx,
378
- req,
379
- promptId: receiptId,
380
- blockSeq: 2,
381
- evt: { type: "prompt.block-end", streamId: receiptId, chatId: req.chatId, seq: 2, timestamp: new Date() },
382
- });
383
- if (ended.isErr())
384
- return Result.Err(ended.Err());
385
- return Result.Ok(EventoResult.Continue);
386
- }
387
- agentSession = live;
388
- agentEvidence = observeEvidenceLine(createAgentEvidenceWriter({
389
- chatId: req.chatId,
390
- promptId: live.promptId,
391
- sessionId: live.promptId,
392
- append: (evt, blockSeq) => appendBlockEvent({ ctx, vctx, req, promptId: live.promptId, blockSeq, evt }),
393
- }), turnLatency);
394
- const active = await agentEvidence({
395
- kind: "active",
396
- ...(live.supersedes === undefined ? {} : { supersedes: live.supersedes }),
361
+ usage: { given: [], calculated: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 } },
362
+ },
397
363
  });
398
- if (active.isErr()) {
399
- live.close();
400
- return Result.Err(active.Err());
401
- }
402
- if (live.session.messages().length === 0) {
403
- const initial = agentAssembled.messages.slice(0, agentAssembled.messages.length - newMessageCount - (agentWakeNote === undefined ? 0 : 1));
404
- const saved = await live.session.checkpoint(initial);
405
- if (saved.isErr()) {
406
- live.close();
407
- return Result.Err(saved.Err());
408
- }
409
- }
410
- const events = await nextAgentSessionMessages(live.session, agentEvidence);
411
- if (events.isErr()) {
412
- live.close();
413
- return Result.Err(events.Err());
414
- }
415
- agentAssembled = {
416
- ...agentAssembled,
417
- messages: composeAgentRequest({
418
- system: agentAssembled.messages.filter((message) => message.role === "system"),
419
- journal: markJournalCacheTail(live.session.messages()),
420
- context: agentAssembled.messages.filter(isAppContextMessage),
421
- tail: events.Ok() ?? [],
422
- }),
423
- };
424
- const saved = await live.session.checkpoint(agentAssembled.messages);
364
+ if (terminal.isErr())
365
+ return Result.Err(terminal.Err());
366
+ const ended = await appendBlockEvent({
367
+ ctx,
368
+ vctx,
369
+ req,
370
+ promptId: receiptId,
371
+ blockSeq: 2,
372
+ evt: { type: "prompt.block-end", streamId: receiptId, chatId: req.chatId, seq: 2, timestamp: new Date() },
373
+ });
374
+ if (ended.isErr())
375
+ return Result.Err(ended.Err());
376
+ return Result.Ok(EventoResult.Continue);
377
+ }
378
+ agentSession = live;
379
+ agentEvidence = observeEvidenceLine(createAgentEvidenceWriter({
380
+ chatId: req.chatId,
381
+ promptId: live.promptId,
382
+ sessionId: live.promptId,
383
+ append: (evt, blockSeq) => appendBlockEvent({ ctx, vctx, req, promptId: live.promptId, blockSeq, evt }),
384
+ }), turnLatency);
385
+ const active = await agentEvidence({
386
+ kind: "active",
387
+ ...(live.supersedes === undefined ? {} : { supersedes: live.supersedes }),
388
+ });
389
+ if (active.isErr()) {
390
+ live.close();
391
+ return Result.Err(active.Err());
392
+ }
393
+ if (live.session.messages().length === 0) {
394
+ const initial = agentAssembled.messages.slice(0, agentAssembled.messages.length - newMessageCount - (agentWakeNote === undefined ? 0 : 1));
395
+ const saved = await live.session.checkpoint(initial);
425
396
  if (saved.isErr()) {
426
397
  live.close();
427
398
  return Result.Err(saved.Err());
428
399
  }
429
400
  }
401
+ const events = await nextAgentSessionMessages(live.session, agentEvidence);
402
+ if (events.isErr()) {
403
+ live.close();
404
+ return Result.Err(events.Err());
405
+ }
406
+ agentAssembled = {
407
+ ...agentAssembled,
408
+ messages: composeAgentRequest({
409
+ system: agentAssembled.messages.filter((message) => message.role === "system"),
410
+ journal: markJournalCacheTail(live.session.messages()),
411
+ context: agentAssembled.messages.filter(isAppContextMessage),
412
+ tail: events.Ok() ?? [],
413
+ }),
414
+ };
415
+ const saved = await live.session.checkpoint(agentAssembled.messages);
416
+ if (saved.isErr()) {
417
+ live.close();
418
+ return Result.Err(saved.Err());
419
+ }
430
420
  }
431
421
  else {
432
422
  const rAssembled = await assemblePromptPayload(vctx, {
@@ -552,8 +542,10 @@ export const promptChatSection = {
552
542
  }
553
543
  else if (agentAssembled !== undefined && isReqPromptLLMChatSection(orig)) {
554
544
  const agentPayload = agentAssembled;
545
+ const liveSession = agentSession;
546
+ if (liveSession === undefined)
547
+ return Result.Err("Agent turn has no session");
555
548
  prompSectionAction = async (scope, blockSeq) => {
556
- const liveSession = agentSession;
557
549
  const rActor = await resolveAgentActor(vctx, {
558
550
  userId: req._auth.verifiedAuth.claims.userId,
559
551
  scope: agentFirstTurnMint
@@ -570,12 +562,9 @@ export const promptChatSection = {
570
562
  appSlug: resChat.appSlug,
571
563
  editBaseFsId: undefined,
572
564
  });
573
- if (liveSession !== undefined && rVfs.isErr())
565
+ if (rVfs.isErr())
574
566
  return Result.Err(rVfs.Err());
575
- if (rVfs.isErr()) {
576
- vctx.logger.Warn().Err(rVfs).Str("chatId", req.chatId).Msg("agent-turn-vfs-load-failed");
577
- }
578
- const vfs = new Map(rVfs.isOk() ? rVfs.Ok() : []);
567
+ const vfs = new Map(rVfs.Ok());
579
568
  function extendDeadlineForAwaitedBuild(awaiting) {
580
569
  void extendOpenTurnDeadline(vctx.sql, {
581
570
  chatId: req.chatId,
@@ -600,15 +589,11 @@ export const promptChatSection = {
600
589
  auth: orig.auth,
601
590
  outerTid: req.outerTid,
602
591
  handle: (dispatchCtx) => promptChatSection.handle(dispatchCtx),
603
- wakeBudget: liveSession === undefined ? agentWakeBudget : 0,
604
- ...(agentSession === undefined
605
- ? {}
606
- : {
607
- onPendingBuild: (t) => {
608
- extendDeadlineForAwaitedBuild(t.promptId);
609
- return agentSession?.watch(t.promptId);
610
- },
611
- }),
592
+ wakeBudget: 0,
593
+ onPendingBuild: (t) => {
594
+ extendDeadlineForAwaitedBuild(t.promptId);
595
+ return liveSession.watch(t.promptId);
596
+ },
612
597
  ...(agentFirstTurnMint
613
598
  ? {
614
599
  firstTurn: {
@@ -643,8 +628,8 @@ export const promptChatSection = {
643
628
  : {}),
644
629
  ...(agentFetchUrlContext === undefined ? {} : { fetchUrl: agentFetchUrlContext }),
645
630
  dispatcher,
646
- ...(liveSession === undefined ? {} : { queueEdit: (input) => liveSession.queue(input) }),
647
- ...(liveSession === undefined ? {} : { fileSession: liveSession }),
631
+ queueEdit: (input) => liveSession.queue(input),
632
+ fileSession: liveSession,
648
633
  onStyleApplied: async (applied) => {
649
634
  await appendBlockEvent({
650
635
  ctx,
@@ -666,7 +651,7 @@ export const promptChatSection = {
666
651
  },
667
652
  onDispatch: (dispatched) => {
668
653
  liveAppSlug = dispatched.appSlug;
669
- liveSession?.claimAppAddress(dispatched.appSlug);
654
+ liveSession.claimAppAddress(dispatched.appSlug);
670
655
  firstTurnAppClaimed = true;
671
656
  vctx.logger
672
657
  .Info()
@@ -675,106 +660,104 @@ export const promptChatSection = {
675
660
  },
676
661
  });
677
662
  turnToolsOffered = belt.definitions.map((d) => d.function.name);
678
- if (agentSession !== undefined) {
679
- await agentSession.bind((input) => runEditVibeTool(vctx, {
680
- actor: rActor.Ok(),
681
- chatId: req.chatId,
682
- input,
683
- dispatcher,
684
- toolsOffered: belt.definitions.map((d) => d.function.name),
685
- }), async (commit) => {
686
- if (firstTurnAppClaimed === false)
687
- return Result.Ok({
688
- ok: false,
689
- reason: "no-app-yet",
690
- message: "Call create_vibe first; there is no app to edit until it has been created.",
691
- });
692
- const currentActor = await resolveAgentActor(vctx, {
693
- userId: rActor.Ok().userId,
694
- requestedHandle: rActor.Ok().ownerHandle,
695
- scope: rActor.Ok().scope,
663
+ await liveSession.bind((input) => runEditVibeTool(vctx, {
664
+ actor: rActor.Ok(),
665
+ chatId: req.chatId,
666
+ input,
667
+ dispatcher,
668
+ toolsOffered: belt.definitions.map((d) => d.function.name),
669
+ }), async (commit) => {
670
+ if (firstTurnAppClaimed === false)
671
+ return Result.Ok({
672
+ ok: false,
673
+ reason: "no-app-yet",
674
+ message: "Call create_vibe first; there is no app to edit until it has been created.",
696
675
  });
697
- if (currentActor.isErr())
698
- return Result.Err(currentActor.Err());
699
- const scoped = await resolveChatApp(vctx, currentActor.Ok(), req.chatId);
700
- if (scoped.isErr())
701
- return Result.Err(scoped.Err());
702
- const commitId = vctx.sthis.nextId(12).str;
703
- const lock = acquireTurnBuildLock({
704
- vctx,
676
+ const currentActor = await resolveAgentActor(vctx, {
677
+ userId: rActor.Ok().userId,
678
+ requestedHandle: rActor.Ok().ownerHandle,
679
+ scope: rActor.Ok().scope,
680
+ });
681
+ if (currentActor.isErr())
682
+ return Result.Err(currentActor.Err());
683
+ const scoped = await resolveChatApp(vctx, currentActor.Ok(), req.chatId);
684
+ if (scoped.isErr())
685
+ return Result.Err(scoped.Err());
686
+ const commitId = vctx.sthis.nextId(12).str;
687
+ const lock = acquireTurnBuildLock({
688
+ vctx,
689
+ chatId: req.chatId,
690
+ promptId: commitId,
691
+ movesFilesystem: true,
692
+ wakesOnTerminal: false,
693
+ });
694
+ if (lock.acquired === false)
695
+ return Result.Err("A build is running; the staged commit could not acquire the write lane.");
696
+ const committed = { promptBlockEndEmitted: false };
697
+ const saved = await exception2Result(() => handleFSPrompt({
698
+ scope,
699
+ vctx,
700
+ ctx,
701
+ promptId: commitId,
702
+ blockSeq: 0,
703
+ terminal: committed,
704
+ beginDirect: true,
705
+ resChat: { ...resChat, mode: "fs-update" },
706
+ req: {
707
+ type: "vibes.diy.req-prompt-chat-section",
708
+ mode: "fs-update",
709
+ auth: orig.auth,
710
+ _auth: req._auth,
705
711
  chatId: req.chatId,
706
- promptId: commitId,
707
- movesFilesystem: true,
708
- wakesOnTerminal: false,
709
- });
710
- if (lock.acquired === false)
711
- return Result.Err("A build is running; the staged commit could not acquire the write lane.");
712
- const committed = { promptBlockEndEmitted: false };
713
- const saved = await exception2Result(() => handleFSPrompt({
714
- scope,
715
- vctx,
712
+ outerTid: req.outerTid,
713
+ agentFileCommit: commit,
714
+ fsUpdate: {
715
+ update: commit.changes.map((file) => ({
716
+ type: "code-block",
717
+ filename: file.path,
718
+ content: file.contents,
719
+ lang: langForFilename(file.path),
720
+ })),
721
+ remove: [],
722
+ },
723
+ },
724
+ })).finally(() => {
725
+ committed.releasePersistGate?.();
726
+ releaseTurnBuildLock(vctx, req.chatId, commitId);
727
+ });
728
+ if (saved.isErr()) {
729
+ const last = await maxPersistedBlockSeq(vctx.sql, { chatId: req.chatId, promptId: commitId });
730
+ if (last.isErr())
731
+ return Result.Err(last.Err());
732
+ const seq = (last.Ok() ?? -1) + 1;
733
+ await appendBlockEvent({
716
734
  ctx,
735
+ vctx,
736
+ req,
717
737
  promptId: commitId,
718
- blockSeq: 0,
719
- terminal: committed,
720
- beginDirect: true,
721
- resChat: { ...resChat, mode: "fs-update" },
722
- req: {
723
- type: "vibes.diy.req-prompt-chat-section",
724
- mode: "fs-update",
725
- auth: orig.auth,
726
- _auth: req._auth,
738
+ blockSeq: seq,
739
+ evt: {
740
+ type: "prompt.error",
741
+ streamId: commitId,
727
742
  chatId: req.chatId,
728
- outerTid: req.outerTid,
729
- agentFileCommit: commit,
730
- fsUpdate: {
731
- update: commit.changes.map((file) => ({
732
- type: "code-block",
733
- filename: file.path,
734
- content: file.contents,
735
- lang: langForFilename(file.path),
736
- })),
737
- remove: [],
738
- },
743
+ seq,
744
+ timestamp: new Date(),
745
+ error: saved.Err().message,
739
746
  },
740
- })).finally(() => {
741
- committed.releasePersistGate?.();
742
- releaseTurnBuildLock(vctx, req.chatId, commitId);
743
- });
744
- if (saved.isErr()) {
745
- const last = await maxPersistedBlockSeq(vctx.sql, { chatId: req.chatId, promptId: commitId });
746
- if (last.isErr())
747
- return Result.Err(last.Err());
748
- const seq = (last.Ok() ?? -1) + 1;
749
- await appendBlockEvent({
750
- ctx,
751
- vctx,
752
- req,
753
- promptId: commitId,
754
- blockSeq: seq,
755
- evt: {
756
- type: "prompt.error",
757
- streamId: commitId,
758
- chatId: req.chatId,
759
- seq,
760
- timestamp: new Date(),
761
- error: saved.Err().message,
762
- },
763
- });
764
- return Result.Err(saved.Err());
765
- }
766
- if (committed.fsRef === undefined)
767
- return Result.Err("The commit did not persist a version.");
768
- const committedPaths = commit.changes.map((file) => file.path);
769
- return Result.Ok({
770
- ok: true,
771
- saved: true,
772
- fsRef: committed.fsRef,
773
- paths: committedPaths,
774
- entryTouched: classifyTurnReach(committedPaths).entryTouched,
775
747
  });
748
+ return Result.Err(saved.Err());
749
+ }
750
+ if (committed.fsRef === undefined)
751
+ return Result.Err("The commit did not persist a version.");
752
+ const committedPaths = commit.changes.map((file) => file.path);
753
+ return Result.Ok({
754
+ ok: true,
755
+ saved: true,
756
+ fsRef: committed.fsRef,
757
+ paths: committedPaths,
758
+ entryTouched: classifyTurnReach(committedPaths).entryTouched,
776
759
  });
777
- }
760
+ });
778
761
  const res = await handlerLlmRequest({
779
762
  ctx,
780
763
  blockSeq,
@@ -790,7 +773,7 @@ export const promptChatSection = {
790
773
  observeEvidenceLine(createAgentEvidenceWriter({
791
774
  chatId: req.chatId,
792
775
  promptId,
793
- ...(liveSession === undefined ? {} : { sessionId: liveSession.promptId }),
776
+ sessionId: liveSession.promptId,
794
777
  append: (evt, blockSeq) => appendBlockEvent({ ctx, vctx, req, promptId, blockSeq, evt }),
795
778
  }), turnLatency);
796
779
  let providerStream;
@@ -810,33 +793,29 @@ export const promptChatSection = {
810
793
  stream: rSse.Ok(),
811
794
  abort: res.abort,
812
795
  onToolEvidence: ({ kind, call, text, round, epoch }) => evidence({ kind, callId: call.id, name: call.name, text, round, epoch }),
813
- ...(liveSession === undefined
814
- ? {}
815
- : {
816
- session: {
817
- checkpoint: async (messages) => {
818
- const saved = await liveSession.session.checkpoint(messages);
819
- if (saved.isErr())
820
- return saved;
821
- const extended = await extendOpenTurnDeadline(vctx.sql, {
822
- chatId: req.chatId,
823
- promptId,
824
- deadlineAtMs: Date.now() + agentTotalBudgetMs(vctx) + OPEN_TURN_AWAIT_BUILD_EXTENSION_MS,
825
- });
826
- if (extended.isErr())
827
- return Result.Err(extended.Err());
828
- return Result.Ok();
829
- },
830
- next: () => nextAgentSessionMessages(liveSession.session, evidence),
831
- head: () => liveSession.session.head(),
832
- dispatchBudgetMs: agentTotalBudgetMs(vctx),
833
- },
834
- }),
796
+ session: {
797
+ checkpoint: async (messages) => {
798
+ const saved = await liveSession.session.checkpoint(messages);
799
+ if (saved.isErr())
800
+ return saved;
801
+ const extended = await extendOpenTurnDeadline(vctx.sql, {
802
+ chatId: req.chatId,
803
+ promptId,
804
+ deadlineAtMs: Date.now() + agentTotalBudgetMs(vctx) + OPEN_TURN_AWAIT_BUILD_EXTENSION_MS,
805
+ });
806
+ if (extended.isErr())
807
+ return Result.Err(extended.Err());
808
+ return Result.Ok();
809
+ },
810
+ next: () => nextAgentSessionMessages(liveSession.session, evidence),
811
+ head: () => liveSession.session.head(),
812
+ dispatchBudgetMs: agentTotalBudgetMs(vctx),
813
+ },
835
814
  dispatch: async ({ request, budget }) => {
836
815
  const messages = agentFirstTurnMint && firstTurnAppClaimed
837
816
  ? claimAgentAppContext(request.messages, { ownerHandle: resChat.ownerHandle, appSlug: liveAppSlug })
838
817
  : request.messages;
839
- if (agentSession !== undefined) {
818
+ {
840
819
  const latest = await loadWorkVfs(vctx, {
841
820
  chatId: req.chatId,
842
821
  ownerHandle: resChat.ownerHandle,
@@ -966,7 +945,6 @@ export const promptChatSection = {
966
945
  const promptId = agentSession?.promptId ?? vctx.sthis.nextId(96 / 8).str;
967
946
  const movesFilesystem = isSourceChangingMode(req.mode) && agentAssembled === undefined;
968
947
  const wakesOnTerminal = decideAgentWake({
969
- agentLane,
970
948
  agentDispatched: agentDispatchedBuild,
971
949
  movedFilesystem: movesFilesystem,
972
950
  budget: agentWakeBudget,
@@ -1181,10 +1159,9 @@ export const promptChatSection = {
1181
1159
  };
1182
1160
  const { consumed } = settleTurnTerminal(vctx.connections, req.chatId, promptId, landingOutcome);
1183
1161
  const wake = decideAgentWake({
1184
- agentLane,
1185
1162
  agentDispatched: agentDispatchedBuild,
1186
1163
  movedFilesystem: movesFilesystem,
1187
- budget: agentSessionEnabled(vctx) ? 1 : agentWakeBudget,
1164
+ budget: 1,
1188
1165
  });
1189
1166
  if (consumed === true) {
1190
1167
  vctx.logger
@@ -1201,7 +1178,7 @@ export const promptChatSection = {
1201
1178
  outerTid: req.outerTid,
1202
1179
  chatId: req.chatId,
1203
1180
  budget: wake.budget,
1204
- note: renderAgentWakeNote(landingOutcome, agentSessionEnabled(vctx)),
1181
+ note: renderAgentWakeNote(landingOutcome),
1205
1182
  handle: (wakeCtx) => promptChatSection.handle(promptDispatchContext(ctx, wakeCtx.validated)),
1206
1183
  });
1207
1184
  }
@@ -1212,7 +1189,6 @@ export const promptChatSection = {
1212
1189
  chatId: req.chatId,
1213
1190
  promptId,
1214
1191
  skip: wake.skip,
1215
- agentLane,
1216
1192
  agentDispatched: agentDispatchedBuild,
1217
1193
  movedFilesystem: movesFilesystem,
1218
1194
  budget: agentWakeBudget,