chatroom-cli 1.65.12 → 1.65.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -79782,9 +79782,30 @@ var init_register_agent = __esm(() => {
79782
79782
  init_services();
79783
79783
  init_convex_error();
79784
79784
  });
79785
+ // ../../services/backend/prompts/cli/context/context-template.ts
79786
+ function getContextViewTemplate() {
79787
+ return CONTEXT_VIEW_TEMPLATE;
79788
+ }
79789
+ var CONTEXT_VIEW_TEMPLATE = `## Goal
79790
+ - **User-centric:** _Describe what the user wants in plain language._
79791
+ - **Development-centric:** _Describe what we are building or changing._
79792
+
79793
+ ## Requirements
79794
+ - _One concrete outcome or requirement per bullet._
79795
+
79796
+ ## Structure
79797
+ - _Key files, folders, or architecture decisions (e.g. module boundaries, SSOT locations)._
79798
+
79799
+ ## Avoid
79800
+ - _Out-of-scope work or anti-patterns to skip._`;
79801
+
79802
+ // ../../services/backend/prompts/cli/context/view-template.ts
79803
+ var init_view_template = () => {};
79804
+
79785
79805
  // ../../services/backend/prompts/cli/context/new.ts
79786
79806
  var init_new = __esm(() => {
79787
79807
  init_stdin_heredoc();
79808
+ init_view_template();
79788
79809
  });
79789
79810
 
79790
79811
  // ../../services/backend/prompts/cli/task-started/main-prompt.ts
@@ -80908,7 +80929,7 @@ function viewHandoffTemplate(params) {
80908
80929
  }
80909
80930
  return template;
80910
80931
  }
80911
- var init_view_template = __esm(() => {
80932
+ var init_view_template2 = __esm(() => {
80912
80933
  init_handoff_templates3();
80913
80934
  });
80914
80935
 
@@ -80926,8 +80947,8 @@ function printHandoffViewTemplate(options) {
80926
80947
  });
80927
80948
  console.log(template);
80928
80949
  }
80929
- var init_view_template2 = __esm(() => {
80930
- init_view_template();
80950
+ var init_view_template3 = __esm(() => {
80951
+ init_view_template2();
80931
80952
  });
80932
80953
 
80933
80954
  // src/utils/serialization/decode/index.ts
@@ -83851,18 +83872,7 @@ async function listContexts(chatroomId, options, deps) {
83851
83872
  await exports_Effect.runPromise(listContextsEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleContextError(err)), exports_Effect.provide(layer)));
83852
83873
  }
83853
83874
  function viewTemplate() {
83854
- return `## Goal
83855
- <user-centric goal: what the user wants>
83856
- <development-centric goal: what we are building/changing>
83857
-
83858
- ## Requirements
83859
- - <outcome or requirement>
83860
-
83861
- ## Structure
83862
- - <concrete folder structure, architecture style (e.g. vertical slice + clean architecture), key shape decisions>
83863
-
83864
- ## Avoid
83865
- - <thing to not do / out of scope>`;
83875
+ return getContextViewTemplate();
83866
83876
  }
83867
83877
  async function inspectContext(chatroomId, options, deps) {
83868
83878
  const d = deps ?? await createDefaultDeps13();
@@ -84810,6 +84820,50 @@ var init_participant = __esm(() => {
84810
84820
  ]);
84811
84821
  });
84812
84822
 
84823
+ // src/commands/machine/daemon-start/native-delivery-ledger.ts
84824
+ class NativeDeliveryLedger {
84825
+ delivered = new Set;
84826
+ inFlight = new Set;
84827
+ deliveryKey(taskId, harnessSessionId) {
84828
+ return `${taskId}\x00${harnessSessionId}`;
84829
+ }
84830
+ isDelivered(taskId, harnessSessionId) {
84831
+ return this.delivered.has(this.deliveryKey(taskId, harnessSessionId));
84832
+ }
84833
+ tryAcquire(taskId, harnessSessionId) {
84834
+ const key = this.deliveryKey(taskId, harnessSessionId);
84835
+ if (this.delivered.has(key) || this.inFlight.has(key)) {
84836
+ return false;
84837
+ }
84838
+ this.inFlight.add(key);
84839
+ return true;
84840
+ }
84841
+ markDelivered(taskId, harnessSessionId) {
84842
+ const key = this.deliveryKey(taskId, harnessSessionId);
84843
+ this.inFlight.delete(key);
84844
+ this.delivered.add(key);
84845
+ }
84846
+ clearDelivery(taskId, harnessSessionId) {
84847
+ const key = this.deliveryKey(taskId, harnessSessionId);
84848
+ this.inFlight.delete(key);
84849
+ this.delivered.delete(key);
84850
+ }
84851
+ clearSession(harnessSessionId) {
84852
+ const suffix = `\x00${harnessSessionId}`;
84853
+ for (const key of [...this.delivered, ...this.inFlight]) {
84854
+ if (key.endsWith(suffix)) {
84855
+ this.delivered.delete(key);
84856
+ this.inFlight.delete(key);
84857
+ }
84858
+ }
84859
+ }
84860
+ }
84861
+ function getNativeDeliveryLedger() {
84862
+ sharedLedger ??= new NativeDeliveryLedger;
84863
+ return sharedLedger;
84864
+ }
84865
+ var sharedLedger;
84866
+
84813
84867
  // src/commands/machine/daemon-start/native-ready-invariant.ts
84814
84868
  function isAgentReadyForNativeDelivery(task, slot) {
84815
84869
  return explainAgentReadyForNativeDeliveryBlock(task, slot) === null;
@@ -84940,6 +84994,12 @@ function explainNativeDeliveryBlock(task, opts) {
84940
84994
  }
84941
84995
  return explainAgentReadyForNativeDeliveryBlock(task, opts.slot);
84942
84996
  }
84997
+ function explainLedgerDeliveryBlock(taskId, harnessSessionId, ledger) {
84998
+ if (ledger.isDelivered(taskId, harnessSessionId)) {
84999
+ return "already_delivered_this_session";
85000
+ }
85001
+ return null;
85002
+ }
84943
85003
  function buildNativeInjectionPrompt(params) {
84944
85004
  const { taskDeliveryOutput, augmentationMode } = params;
84945
85005
  if (augmentationMode === "compact") {
@@ -85244,6 +85304,9 @@ var init_assigned_task_snapshot_store = __esm(() => {
85244
85304
  class NativeTaskDeliveryCoordinator {
85245
85305
  onSessionLost(params) {
85246
85306
  getRoleDeliveryState().resetDeliveryState(params.chatroomId, params.role);
85307
+ if (params.harnessSessionId) {
85308
+ getNativeDeliveryLedger().clearSession(params.harnessSessionId);
85309
+ }
85247
85310
  }
85248
85311
  resetRoleDeliveryState(chatroomId, role) {
85249
85312
  getRoleDeliveryState().resetDeliveryState(chatroomId, role);
@@ -85270,6 +85333,7 @@ class NativeTaskDeliveryCoordinator {
85270
85333
  reconcileAssignedTasks(params) {
85271
85334
  const { tasks, runtime: runtime4, effectContext: effectContext2, agentMgr, sessionDeps, machineId } = params;
85272
85335
  const deliveryState = getRoleDeliveryState();
85336
+ const ledger = getNativeDeliveryLedger();
85273
85337
  const pendingFirst = [...tasks].sort((a, b) => {
85274
85338
  if (a.status === "pending" && b.status !== "pending")
85275
85339
  return -1;
@@ -85287,11 +85351,28 @@ class NativeTaskDeliveryCoordinator {
85287
85351
  }
85288
85352
  continue;
85289
85353
  }
85354
+ const harnessSessionId = slot?.harnessSessionId;
85355
+ if (!harnessSessionId) {
85356
+ logNativeDeliverySkip(role, row.chatroomId, row.taskId, "harness_session_missing (pre-gate)");
85357
+ continue;
85358
+ }
85359
+ const ledgerBlock = explainLedgerDeliveryBlock(row.taskId, harnessSessionId, ledger);
85360
+ if (ledgerBlock) {
85361
+ logNativeDeliverySkip(role, row.chatroomId, row.taskId, ledgerBlock);
85362
+ continue;
85363
+ }
85364
+ if (!ledger.tryAcquire(row.taskId, harnessSessionId)) {
85365
+ logNativeDeliverySkip(role, row.chatroomId, row.taskId, "delivery_ledger_busy (duplicate inject in flight)");
85366
+ continue;
85367
+ }
85290
85368
  if (!deliveryState.tryAcquireDelivery(row.chatroomId, role)) {
85369
+ ledger.clearDelivery(row.taskId, harnessSessionId);
85291
85370
  logNativeDeliveryMutexSkip(role, row.chatroomId, row.taskId);
85292
85371
  continue;
85293
85372
  }
85294
85373
  logNativeDeliveryInjecting(role, row.chatroomId, row.taskId);
85374
+ const taskId = row.taskId;
85375
+ let deliveredToHarness = false;
85295
85376
  exports_Runtime.runFork(runtime4)(exports_Effect.gen(function* () {
85296
85377
  const full = yield* exports_Effect.tryPromise(() => sessionDeps.backend.query(api.machines.getAssignedTaskForAction, {
85297
85378
  sessionId: sessionDeps.sessionId,
@@ -85303,11 +85384,6 @@ class NativeTaskDeliveryCoordinator {
85303
85384
  console.warn(`[NativeDelivery:skip] ${role}@${row.chatroomId} task ${row.taskId} — task_hydrate_missing (deleted or not assigned)`);
85304
85385
  return;
85305
85386
  }
85306
- const harnessSessionId = slot?.harnessSessionId;
85307
- if (!harnessSessionId) {
85308
- console.warn(`[NativeDelivery:skip] ${role}@${row.chatroomId} task ${row.taskId} — harness_session_missing (post-gate)`);
85309
- return;
85310
- }
85311
85387
  yield* runNativeInjectionEffect(full, harnessSessionId, {
85312
85388
  sessionId: sessionDeps.sessionId,
85313
85389
  machineId: sessionDeps.machineId,
@@ -85316,12 +85392,19 @@ class NativeTaskDeliveryCoordinator {
85316
85392
  resumeTurnForSlot: (args2) => exports_Effect.runPromise(agentMgr.resumeTurnForSlot(args2))
85317
85393
  },
85318
85394
  convexUrl: sessionDeps.convexUrl,
85319
- onTaskDelivered: ({ chatroomId, role: role2, taskId }) => {
85320
- exports_Effect.runSync(agentMgr.setLastInFlightTask(chatroomId, role2, taskId));
85395
+ onTaskDelivered: ({ chatroomId, role: role2, taskId: deliveredTaskId }) => {
85396
+ deliveredToHarness = true;
85397
+ ledger.markDelivered(deliveredTaskId, harnessSessionId);
85398
+ exports_Effect.runSync(agentMgr.setLastInFlightTask(chatroomId, role2, deliveredTaskId));
85321
85399
  deliveryState.clearNativeNudgeFailures(chatroomId, role2);
85322
85400
  }
85323
85401
  });
85324
- }).pipe(exports_Effect.provide(effectContext2), exports_Effect.catchAll((err) => exports_Effect.sync(() => console.warn(`[NativeTaskDelivery] delivery failed for ${row.agentConfig.role}@${row.chatroomId}: ${getErrorMessage2(err)}`))), exports_Effect.ensuring(exports_Effect.sync(() => deliveryState.releaseDelivery(row.chatroomId, row.agentConfig.role)))));
85402
+ }).pipe(exports_Effect.provide(effectContext2), exports_Effect.catchAll((err) => exports_Effect.sync(() => console.warn(`[NativeTaskDelivery] delivery failed for ${row.agentConfig.role}@${row.chatroomId}: ${getErrorMessage2(err)}`))), exports_Effect.ensuring(exports_Effect.sync(() => {
85403
+ deliveryState.releaseDelivery(row.chatroomId, row.agentConfig.role);
85404
+ if (!deliveredToHarness) {
85405
+ ledger.clearDelivery(taskId, harnessSessionId);
85406
+ }
85407
+ }))));
85325
85408
  break;
85326
85409
  }
85327
85410
  }
@@ -85435,6 +85518,17 @@ async function deliverOneTask(deps, event, snapshot) {
85435
85518
  });
85436
85519
  if (!full)
85437
85520
  return false;
85521
+ const ledger = getNativeDeliveryLedger();
85522
+ const ledgerBlock = explainLedgerDeliveryBlock(snapshot.taskId, harnessSessionId, ledger);
85523
+ if (ledgerBlock) {
85524
+ console.warn(`[RestartOrchestrator] skip task ${snapshot.taskId} — ${ledgerBlock}`);
85525
+ return false;
85526
+ }
85527
+ if (!ledger.tryAcquire(snapshot.taskId, harnessSessionId)) {
85528
+ console.warn(`[RestartOrchestrator] skip task ${snapshot.taskId} — delivery_ledger_busy`);
85529
+ return false;
85530
+ }
85531
+ let deliveredToHarness = false;
85438
85532
  try {
85439
85533
  await exports_Effect.runPromise(runNativeInjectionEffect(full, harnessSessionId, {
85440
85534
  sessionId: deps.session.sessionId,
@@ -85447,6 +85541,8 @@ async function deliverOneTask(deps, event, snapshot) {
85447
85541
  }
85448
85542
  },
85449
85543
  onTaskDelivered: ({ chatroomId, role, taskId }) => {
85544
+ deliveredToHarness = true;
85545
+ ledger.markDelivered(taskId, harnessSessionId);
85450
85546
  deps.agentMgr.setLastInFlightTask(chatroomId, role, taskId);
85451
85547
  }
85452
85548
  }));
@@ -85454,6 +85550,10 @@ async function deliverOneTask(deps, event, snapshot) {
85454
85550
  } catch (err) {
85455
85551
  console.warn(`[RestartOrchestrator] deliver failed for task ${snapshot.taskId}: ${getErrorMessage2(err)}`);
85456
85552
  return false;
85553
+ } finally {
85554
+ if (!deliveredToHarness) {
85555
+ ledger.clearDelivery(snapshot.taskId, harnessSessionId);
85556
+ }
85457
85557
  }
85458
85558
  }
85459
85559
  async function deliverPendingTasks(deps, event) {
@@ -85531,6 +85631,7 @@ var init_restart_orchestrator = __esm(() => {
85531
85631
  init_esm();
85532
85632
  init_native_ready_invariant();
85533
85633
  init_native_task_delivery_coordinator();
85634
+ init_native_task_injector_logic();
85534
85635
  init_native_task_injector();
85535
85636
  init_api3();
85536
85637
  init_convex_error();
@@ -111765,7 +111866,7 @@ program2.command("get-next-task").description("Join a chatroom and get the next
111765
111866
  });
111766
111867
  var handoffCommandGroup = program2.command("handoff").description("Complete your task and hand off to the next role");
111767
111868
  handoffCommandGroup.command("view-template").description("Print the handoff message template for a role pair").requiredOption("--role <role>", "Your role").requiredOption("--next-role <nextRole>", "Target role for the handoff").option("--team-id <teamId>", "Team id (solo, duo); defaults to duo").action(async (options) => {
111768
- const { printHandoffViewTemplate: printHandoffViewTemplate2 } = await Promise.resolve().then(() => (init_view_template2(), exports_view_template));
111869
+ const { printHandoffViewTemplate: printHandoffViewTemplate2 } = await Promise.resolve().then(() => (init_view_template3(), exports_view_template));
111769
111870
  try {
111770
111871
  printHandoffViewTemplate2(options);
111771
111872
  } catch (err) {
@@ -112082,4 +112183,4 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
112082
112183
  });
112083
112184
  program2.parse();
112084
112185
 
112085
- //# debugId=7C02ECAE46A1934B64756E2164756E21
112186
+ //# debugId=79E3EED5683A0EFF64756E2164756E21