chatroom-cli 1.68.5 → 1.69.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.
package/dist/index.js CHANGED
@@ -2168,7 +2168,8 @@ __export(exports_stdin_heredoc, {
2168
2168
  HANDOFF_STDIN_DELIMITER: () => HANDOFF_STDIN_DELIMITER,
2169
2169
  HANDOFF_MESSAGE_MARKER: () => HANDOFF_MESSAGE_MARKER,
2170
2170
  CONTEXT_STDIN_DELIMITER: () => CONTEXT_STDIN_DELIMITER,
2171
- BACKLOG_STDIN_DELIMITER: () => BACKLOG_STDIN_DELIMITER
2171
+ BACKLOG_STDIN_DELIMITER: () => BACKLOG_STDIN_DELIMITER,
2172
+ AGENTIC_QUERY_STDIN_DELIMITER: () => AGENTIC_QUERY_STDIN_DELIMITER
2172
2173
  });
2173
2174
  function formatStdinHeredocCommand(commandPrefix, delimiter, placeholder, options) {
2174
2175
  const marker = options?.messageMarker;
@@ -2204,16 +2205,18 @@ function findReservedDelimiterLines(content) {
2204
2205
  }
2205
2206
  return hits;
2206
2207
  }
2207
- var HANDOFF_STDIN_DELIMITER = "CHATROOM_HANDOFF_END", CONTEXT_STDIN_DELIMITER = "CHATROOM_CONTEXT_END", BACKLOG_STDIN_DELIMITER = "CHATROOM_BACKLOG_END", CLASSIFY_STDIN_DELIMITER = "CHATROOM_CLASSIFY_END", HANDOFF_MESSAGE_MARKER = "---MESSAGE---", RESERVED_STDIN_HEREDOC_DELIMITERS, RESERVED_STRUCTURED_PARAM_MARKERS;
2208
+ var HANDOFF_STDIN_DELIMITER = "CHATROOM_HANDOFF_END", CONTEXT_STDIN_DELIMITER = "CHATROOM_CONTEXT_END", BACKLOG_STDIN_DELIMITER = "CHATROOM_BACKLOG_END", AGENTIC_QUERY_STDIN_DELIMITER = "CHATROOM_AGENTIC_QUERY_END", CLASSIFY_STDIN_DELIMITER = "CHATROOM_CLASSIFY_END", HANDOFF_MESSAGE_MARKER = "---MESSAGE---", RESERVED_STDIN_HEREDOC_DELIMITERS, RESERVED_STRUCTURED_PARAM_MARKERS;
2208
2209
  var init_stdin_heredoc = __esm(() => {
2209
2210
  RESERVED_STDIN_HEREDOC_DELIMITERS = [
2210
2211
  HANDOFF_STDIN_DELIMITER,
2211
2212
  CONTEXT_STDIN_DELIMITER,
2212
2213
  BACKLOG_STDIN_DELIMITER,
2214
+ AGENTIC_QUERY_STDIN_DELIMITER,
2213
2215
  CLASSIFY_STDIN_DELIMITER
2214
2216
  ];
2215
2217
  RESERVED_STRUCTURED_PARAM_MARKERS = [
2216
2218
  HANDOFF_MESSAGE_MARKER,
2219
+ "---RESULT---",
2217
2220
  "---TITLE---",
2218
2221
  "---DESCRIPTION---",
2219
2222
  "---TECH_SPECS---"
@@ -78962,6 +78965,83 @@ var init_handoff = __esm(() => {
78962
78965
  init_error_formatting();
78963
78966
  });
78964
78967
 
78968
+ // src/commands/agentic-query/complete.ts
78969
+ var exports_complete = {};
78970
+ __export(exports_complete, {
78971
+ agenticQueryComplete: () => agenticQueryComplete
78972
+ });
78973
+ async function createDefaultDeps9() {
78974
+ const client4 = await getConvexClient();
78975
+ return {
78976
+ backend: {
78977
+ mutation: (endpoint, args2) => client4.mutation(endpoint, args2),
78978
+ query: (endpoint, args2) => client4.query(endpoint, args2)
78979
+ },
78980
+ session: {
78981
+ getSessionId,
78982
+ getConvexUrl,
78983
+ getOtherSessionUrls
78984
+ }
78985
+ };
78986
+ }
78987
+ function handleCompleteError(err) {
78988
+ return exports_Effect.sync(() => {
78989
+ if (err._tag === "NotAuthenticated") {
78990
+ formatAuthError(err.convexUrl, err.otherUrls);
78991
+ process.exit(1);
78992
+ }
78993
+ if (err._tag === "InvalidChatroomId") {
78994
+ formatChatroomIdError(err.id);
78995
+ process.exit(1);
78996
+ }
78997
+ console.error(`
78998
+ ❌ ERROR: Agentic query complete failed`);
78999
+ console.error(`
79000
+ ${err.errorData?.message ?? err.cause.message}`);
79001
+ process.exit(1);
79002
+ });
79003
+ }
79004
+ async function agenticQueryComplete(chatroomId, options) {
79005
+ const deps = await createDefaultDeps9();
79006
+ await exports_Effect.runPromise(agenticQueryCompleteEffect(chatroomId, options).pipe(exports_Effect.provide(commandServicesLayerFromDeps(deps)), exports_Effect.catchAll(handleCompleteError)));
79007
+ }
79008
+ var agenticQueryCompleteEffect = (chatroomId, options) => exports_Effect.gen(function* () {
79009
+ const backend2 = yield* BackendService;
79010
+ const sessionId = yield* requireSessionIdEffect((a) => ({
79011
+ _tag: "NotAuthenticated",
79012
+ convexUrl: a.convexUrl,
79013
+ otherUrls: a.otherUrls
79014
+ }));
79015
+ yield* validateChatroomIdEffect(chatroomId, (id3) => ({
79016
+ _tag: "InvalidChatroomId",
79017
+ id: id3
79018
+ }));
79019
+ yield* backend2.mutation(api.web.agenticQuery.index.complete, {
79020
+ sessionId,
79021
+ chatroomId,
79022
+ queryId: options.queryId,
79023
+ result: options.result
79024
+ }).pipe(exports_Effect.mapError((cause3) => {
79025
+ let errorData;
79026
+ if (cause3 instanceof ConvexError) {
79027
+ errorData = cause3.data;
79028
+ }
79029
+ return { _tag: "CompleteFailed", cause: cause3, errorData };
79030
+ }));
79031
+ yield* exports_Effect.sync(() => {
79032
+ console.log(`✅ Agentic query ${options.queryId} completed`);
79033
+ });
79034
+ });
79035
+ var init_complete = __esm(() => {
79036
+ init_values();
79037
+ init_esm();
79038
+ init_api3();
79039
+ init_storage();
79040
+ init_client2();
79041
+ init_services();
79042
+ init_error_formatting();
79043
+ });
79044
+
78965
79045
  // src/commands/backlog/backlog-fs-service.ts
78966
79046
  import * as nodeFs from "node:fs/promises";
78967
79047
  var BacklogFsService, BacklogFsServiceLive, BacklogFsServiceFrom = (ops) => exports_Layer.succeed(BacklogFsService, {
@@ -79068,7 +79148,7 @@ function buildBaseLayer(d) {
79068
79148
  function buildFsLayer(fs11) {
79069
79149
  return fs11 ? BacklogFsServiceFrom(fs11) : BacklogFsServiceLive;
79070
79150
  }
79071
- async function createDefaultDeps9() {
79151
+ async function createDefaultDeps10() {
79072
79152
  const client4 = await getConvexClient();
79073
79153
  const fs11 = await import("node:fs/promises");
79074
79154
  return {
@@ -79124,47 +79204,47 @@ function computeContentHash(content) {
79124
79204
  return createHash("sha256").update(content).digest("hex");
79125
79205
  }
79126
79206
  async function listBacklog(chatroomId, options, deps) {
79127
- const d = deps ?? await createDefaultDeps9();
79207
+ const d = deps ?? await createDefaultDeps10();
79128
79208
  await exports_Effect.runPromise(listBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79129
79209
  }
79130
79210
  async function addBacklog(chatroomId, options, deps) {
79131
- const d = deps ?? await createDefaultDeps9();
79211
+ const d = deps ?? await createDefaultDeps10();
79132
79212
  await exports_Effect.runPromise(addBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79133
79213
  }
79134
79214
  async function completeBacklog(chatroomId, options, deps) {
79135
- const d = deps ?? await createDefaultDeps9();
79215
+ const d = deps ?? await createDefaultDeps10();
79136
79216
  await exports_Effect.runPromise(completeBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79137
79217
  }
79138
79218
  async function reopenBacklog(chatroomId, options, deps) {
79139
- const d = deps ?? await createDefaultDeps9();
79219
+ const d = deps ?? await createDefaultDeps10();
79140
79220
  await exports_Effect.runPromise(reopenBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79141
79221
  }
79142
79222
  async function patchBacklog(chatroomId, options, deps) {
79143
- const d = deps ?? await createDefaultDeps9();
79223
+ const d = deps ?? await createDefaultDeps10();
79144
79224
  await exports_Effect.runPromise(patchBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79145
79225
  }
79146
79226
  async function scoreBacklog(chatroomId, options, deps) {
79147
- const d = deps ?? await createDefaultDeps9();
79227
+ const d = deps ?? await createDefaultDeps10();
79148
79228
  await exports_Effect.runPromise(scoreBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79149
79229
  }
79150
79230
  async function markForReviewBacklog(chatroomId, options, deps) {
79151
- const d = deps ?? await createDefaultDeps9();
79231
+ const d = deps ?? await createDefaultDeps10();
79152
79232
  await exports_Effect.runPromise(markForReviewBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79153
79233
  }
79154
79234
  async function historyBacklog(chatroomId, options, deps) {
79155
- const d = deps ?? await createDefaultDeps9();
79235
+ const d = deps ?? await createDefaultDeps10();
79156
79236
  await exports_Effect.runPromise(historyBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79157
79237
  }
79158
79238
  async function updateBacklog(chatroomId, options, deps) {
79159
- const d = deps ?? await createDefaultDeps9();
79239
+ const d = deps ?? await createDefaultDeps10();
79160
79240
  await exports_Effect.runPromise(updateBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79161
79241
  }
79162
79242
  async function closeBacklog(chatroomId, options, deps) {
79163
- const d = deps ?? await createDefaultDeps9();
79243
+ const d = deps ?? await createDefaultDeps10();
79164
79244
  await exports_Effect.runPromise(closeBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(buildBaseLayer(d))));
79165
79245
  }
79166
79246
  async function exportBacklog(chatroomId, options, deps) {
79167
- const d = deps ?? await createDefaultDeps9();
79247
+ const d = deps ?? await createDefaultDeps10();
79168
79248
  if (!d.fs) {
79169
79249
  console.error("❌ File system operations not available");
79170
79250
  process.exit(1);
@@ -79173,7 +79253,7 @@ async function exportBacklog(chatroomId, options, deps) {
79173
79253
  await exports_Effect.runPromise(exportBacklogEffect(chatroomId, options).pipe(exports_Effect.catchAll(handleBacklogError), exports_Effect.provide(exports_Layer.merge(buildBaseLayer(d), buildFsLayer(d.fs)))));
79174
79254
  }
79175
79255
  async function importBacklog(chatroomId, options, deps) {
79176
- const d = deps ?? await createDefaultDeps9();
79256
+ const d = deps ?? await createDefaultDeps10();
79177
79257
  if (!d.fs) {
79178
79258
  console.error("❌ File system operations not available");
79179
79259
  process.exit(1);
@@ -79934,7 +80014,7 @@ __export(exports_read, {
79934
80014
  taskReadEffect: () => taskReadEffect,
79935
80015
  taskRead: () => taskRead
79936
80016
  });
79937
- async function createDefaultDeps10() {
80017
+ async function createDefaultDeps11() {
79938
80018
  const client4 = await getConvexClient();
79939
80019
  return {
79940
80020
  backend: {
@@ -79976,7 +80056,7 @@ function handleTaskReadError(err) {
79976
80056
  });
79977
80057
  }
79978
80058
  async function taskRead(chatroomId, options, deps) {
79979
- const d = deps ?? await createDefaultDeps10();
80059
+ const d = deps ?? await createDefaultDeps11();
79980
80060
  const layer = commandServicesLayerFromDeps(d);
79981
80061
  await exports_Effect.runPromise(taskReadEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleTaskReadError(err)), exports_Effect.provide(layer)));
79982
80062
  }
@@ -80067,7 +80147,7 @@ __export(exports_skill, {
80067
80147
  activateSkillEffect: () => activateSkillEffect,
80068
80148
  activateSkill: () => activateSkill
80069
80149
  });
80070
- async function createDefaultDeps11() {
80150
+ async function createDefaultDeps12() {
80071
80151
  const client4 = await getConvexClient();
80072
80152
  return {
80073
80153
  backend: {
@@ -80136,12 +80216,12 @@ function handleActivateSkillError(err) {
80136
80216
  });
80137
80217
  }
80138
80218
  async function listSkills(chatroomId, options, deps) {
80139
- const d = deps ?? await createDefaultDeps11();
80219
+ const d = deps ?? await createDefaultDeps12();
80140
80220
  const layer = commandServicesLayerFromDeps(d);
80141
80221
  await exports_Effect.runPromise(listSkillsEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleListSkillsError(err)), exports_Effect.provide(layer)));
80142
80222
  }
80143
80223
  async function activateSkill(chatroomId, skillId, options, deps) {
80144
- const d = deps ?? await createDefaultDeps11();
80224
+ const d = deps ?? await createDefaultDeps12();
80145
80225
  const layer = commandServicesLayerFromDeps(d);
80146
80226
  await exports_Effect.runPromise(activateSkillEffect(chatroomId, skillId, options).pipe(exports_Effect.catchAll((err) => handleActivateSkillError(err)), exports_Effect.provide(layer)));
80147
80227
  }
@@ -80219,7 +80299,7 @@ __export(exports_messages, {
80219
80299
  listBySenderRoleEffect: () => listBySenderRoleEffect,
80220
80300
  listBySenderRole: () => listBySenderRole
80221
80301
  });
80222
- async function createDefaultDeps12() {
80302
+ async function createDefaultDeps13() {
80223
80303
  const client4 = await getConvexClient();
80224
80304
  return {
80225
80305
  backend: {
@@ -80280,12 +80360,12 @@ function handleMessagesError(err) {
80280
80360
  });
80281
80361
  }
80282
80362
  async function listBySenderRole(chatroomId, options, deps) {
80283
- const d = deps ?? await createDefaultDeps12();
80363
+ const d = deps ?? await createDefaultDeps13();
80284
80364
  const layer = commandServicesLayerFromDeps(d);
80285
80365
  await exports_Effect.runPromise(listBySenderRoleEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleMessagesError(err)), exports_Effect.provide(layer)));
80286
80366
  }
80287
80367
  async function listSinceMessage(chatroomId, options, deps) {
80288
- const d = deps ?? await createDefaultDeps12();
80368
+ const d = deps ?? await createDefaultDeps13();
80289
80369
  const layer = commandServicesLayerFromDeps(d);
80290
80370
  await exports_Effect.runPromise(listSinceMessageEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleMessagesError(err)), exports_Effect.provide(layer)));
80291
80371
  }
@@ -80415,7 +80495,7 @@ __export(exports_context2, {
80415
80495
  inspectContextEffect: () => inspectContextEffect,
80416
80496
  inspectContext: () => inspectContext
80417
80497
  });
80418
- async function createDefaultDeps13() {
80498
+ async function createDefaultDeps14() {
80419
80499
  const client4 = await getConvexClient();
80420
80500
  return {
80421
80501
  backend: {
@@ -80456,17 +80536,17 @@ function handleContextError(err) {
80456
80536
  });
80457
80537
  }
80458
80538
  async function readContext(chatroomId, options, deps) {
80459
- const d = deps ?? await createDefaultDeps13();
80539
+ const d = deps ?? await createDefaultDeps14();
80460
80540
  const layer = commandServicesLayerFromDeps(d);
80461
80541
  await exports_Effect.runPromise(readContextEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleContextError(err)), exports_Effect.provide(layer)));
80462
80542
  }
80463
80543
  async function newContext(chatroomId, options, deps) {
80464
- const d = deps ?? await createDefaultDeps13();
80544
+ const d = deps ?? await createDefaultDeps14();
80465
80545
  const layer = commandServicesLayerFromDeps(d);
80466
80546
  await exports_Effect.runPromise(newContextEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleContextError(err)), exports_Effect.provide(layer)));
80467
80547
  }
80468
80548
  async function listContexts(chatroomId, options, deps) {
80469
- const d = deps ?? await createDefaultDeps13();
80549
+ const d = deps ?? await createDefaultDeps14();
80470
80550
  const layer = commandServicesLayerFromDeps(d);
80471
80551
  await exports_Effect.runPromise(listContextsEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleContextError(err)), exports_Effect.provide(layer)));
80472
80552
  }
@@ -80474,7 +80554,7 @@ function viewTemplate() {
80474
80554
  return getContextViewTemplate();
80475
80555
  }
80476
80556
  async function inspectContext(chatroomId, options, deps) {
80477
- const d = deps ?? await createDefaultDeps13();
80557
+ const d = deps ?? await createDefaultDeps14();
80478
80558
  const layer = commandServicesLayerFromDeps(d);
80479
80559
  await exports_Effect.runPromise(inspectContextEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleContextError(err)), exports_Effect.provide(layer)));
80480
80560
  }
@@ -80715,7 +80795,7 @@ __export(exports_guidelines, {
80715
80795
  listGuidelineTypesEffect: () => listGuidelineTypesEffect,
80716
80796
  listGuidelineTypes: () => listGuidelineTypes
80717
80797
  });
80718
- async function createDefaultDeps14() {
80798
+ async function createDefaultDeps15() {
80719
80799
  const client4 = await getConvexClient();
80720
80800
  return {
80721
80801
  backend: {
@@ -80756,12 +80836,12 @@ function handleListGuidelineTypesError(err) {
80756
80836
  });
80757
80837
  }
80758
80838
  async function viewGuidelines(options, deps) {
80759
- const d = deps ?? await createDefaultDeps14();
80839
+ const d = deps ?? await createDefaultDeps15();
80760
80840
  const layer = layerFromDeps7(d);
80761
80841
  await exports_Effect.runPromise(viewGuidelinesEffect(options).pipe(exports_Effect.catchAll((err) => handleViewGuidelinesError(err)), exports_Effect.provide(layer)));
80762
80842
  }
80763
80843
  async function listGuidelineTypes(deps) {
80764
- const d = deps ?? await createDefaultDeps14();
80844
+ const d = deps ?? await createDefaultDeps15();
80765
80845
  const layer = layerFromDeps7(d);
80766
80846
  await exports_Effect.runPromise(listGuidelineTypesEffect().pipe(exports_Effect.catchAll((err) => handleListGuidelineTypesError(err)), exports_Effect.provide(layer)));
80767
80847
  }
@@ -80831,7 +80911,7 @@ __export(exports_artifact, {
80831
80911
  createArtifactEffect: () => createArtifactEffect,
80832
80912
  createArtifact: () => createArtifact
80833
80913
  });
80834
- async function createDefaultDeps15() {
80914
+ async function createDefaultDeps16() {
80835
80915
  const client4 = await getConvexClient();
80836
80916
  return {
80837
80917
  backend: {
@@ -80853,19 +80933,19 @@ function handleArtifactError(err) {
80853
80933
  });
80854
80934
  }
80855
80935
  async function createArtifact(chatroomId, options, deps) {
80856
- const d = deps ?? await createDefaultDeps15();
80936
+ const d = deps ?? await createDefaultDeps16();
80857
80937
  const layer = commandServicesLayerFromDeps(d);
80858
80938
  return exports_Effect.runPromise(createArtifactEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleArtifactError(err).pipe(exports_Effect.map(() => {
80859
80939
  return;
80860
80940
  }))), exports_Effect.provide(layer)));
80861
80941
  }
80862
80942
  async function viewArtifact(chatroomId, options, deps) {
80863
- const d = deps ?? await createDefaultDeps15();
80943
+ const d = deps ?? await createDefaultDeps16();
80864
80944
  const layer = commandServicesLayerFromDeps(d);
80865
80945
  await exports_Effect.runPromise(viewArtifactEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleArtifactError(err)), exports_Effect.provide(layer)));
80866
80946
  }
80867
80947
  async function viewManyArtifacts(chatroomId, options, deps) {
80868
- const d = deps ?? await createDefaultDeps15();
80948
+ const d = deps ?? await createDefaultDeps16();
80869
80949
  const layer = commandServicesLayerFromDeps(d);
80870
80950
  await exports_Effect.runPromise(viewManyArtifactsEffect(chatroomId, options).pipe(exports_Effect.catchAll((err) => handleArtifactError(err)), exports_Effect.provide(layer)));
80871
80951
  }
@@ -81215,7 +81295,7 @@ __export(exports_telegram, {
81215
81295
  sendMessageEffect: () => sendMessageEffect,
81216
81296
  sendMessage: () => sendMessage
81217
81297
  });
81218
- async function createDefaultDeps16() {
81298
+ async function createDefaultDeps17() {
81219
81299
  const client4 = await getConvexClient();
81220
81300
  return {
81221
81301
  backend: {
@@ -81297,7 +81377,7 @@ ${err.cause.message}`);
81297
81377
  });
81298
81378
  }
81299
81379
  async function sendMessage(options, deps) {
81300
- const d = deps ?? await createDefaultDeps16();
81380
+ const d = deps ?? await createDefaultDeps17();
81301
81381
  const layer = layerFromDeps8(d);
81302
81382
  await exports_Effect.runPromise(sendMessageEffect(options).pipe(exports_Effect.catchAll((err) => handleSendMessageError(err)), exports_Effect.provide(layer)));
81303
81383
  }
@@ -99216,7 +99296,7 @@ function harnessEventSessionId(event) {
99216
99296
 
99217
99297
  class OpencodeSdkHarness {
99218
99298
  type = "opencode-sdk";
99219
- displayName = "Opencode";
99299
+ displayName = "OpenCode (SDK)";
99220
99300
  client;
99221
99301
  childProcess;
99222
99302
  cwd;
@@ -100299,6 +100379,24 @@ var init_opencode_session_events = __esm(() => {
100299
100379
  ];
100300
100380
  });
100301
100381
 
100382
+ // src/commands/machine/daemon-start/shared-harness/bind-turn-message-on-event.ts
100383
+ function bindTurnMessageOnEvent(handle, sessionRepository, logPrefix) {
100384
+ let lastBoundKey = null;
100385
+ return () => {
100386
+ const turn = handle.currentTurn;
100387
+ if (!turn)
100388
+ return;
100389
+ const messageId = turn.messageId;
100390
+ if (messageId == null)
100391
+ return;
100392
+ const key = `${turn.turnId}:${messageId}`;
100393
+ if (key === lastBoundKey)
100394
+ return;
100395
+ lastBoundKey = key;
100396
+ sessionRepository.bindTurnMessageId(turn.turnId, messageId).catch((err) => console.warn(`[${logPrefix}] bindTurnMessageId error (resume):`, err));
100397
+ };
100398
+ }
100399
+
100302
100400
  // src/commands/machine/daemon-start/direct-harness/prompt-subscriber.ts
100303
100401
  function startMessageSubscriber(session2, wsClient2, deps) {
100304
100402
  let processing = false;
@@ -100393,22 +100491,15 @@ function wireResumedSessionEvents(handle, deps, info) {
100393
100491
  agent: info.lastUsedConfig.agent ?? "build",
100394
100492
  model: info.lastUsedConfig.model
100395
100493
  };
100396
- let lastBoundKey = null;
100494
+ const bindTurnMessage = bindTurnMessageOnEvent(handle, deps.sessionRepository, "direct-harness");
100397
100495
  handle.session.onEvent((event) => {
100398
- const turn = handle.currentTurn;
100399
- if (turn?.messageId !== null && turn?.messageId !== undefined) {
100400
- const key = `${turn.turnId}:${turn.messageId}`;
100401
- if (key !== lastBoundKey) {
100402
- lastBoundKey = key;
100403
- deps.sessionRepository.bindTurnMessageId(turn.turnId, turn.messageId).catch((err) => console.warn("[direct-harness] bindTurnMessageId error (resume):", err));
100404
- }
100405
- }
100496
+ bindTurnMessage();
100406
100497
  if (event.type === OPENCODE_SESSION_EVENT_TYPES[0]) {
100407
100498
  handleSessionIdle(handle, handle.journal, idleConfig, deps.sessionRepository).catch((err) => console.warn("[direct-harness] idle handler error (resume):", err));
100408
100499
  }
100409
100500
  });
100410
100501
  }
100411
- async function deliverPendingMessages(handle, deps, rowId, messages, info) {
100502
+ async function deliverPendingMessages(handle, deps, rowId, messages, info, _daemonSession) {
100412
100503
  for (const msg of messages) {
100413
100504
  const override = info?.lastUsedConfig ?? { agent: "build" };
100414
100505
  try {
@@ -100449,7 +100540,7 @@ async function processSessionMessages(session2, deps, rowId, messages, info) {
100449
100540
  await deps.sessionRepository.markActive(rowId).catch(() => {});
100450
100541
  wireResumedSessionEvents(handle, deps, info);
100451
100542
  }
100452
- await deliverPendingMessages(handle, deps, rowId, messages, info);
100543
+ await deliverPendingMessages(handle, deps, rowId, messages, info, session2);
100453
100544
  }
100454
100545
  var init_prompt_subscriber = __esm(() => {
100455
100546
  init_idle_handler();
@@ -100459,122 +100550,64 @@ var init_prompt_subscriber = __esm(() => {
100459
100550
  init_opencode_session_events();
100460
100551
  });
100461
100552
 
100462
- // src/commands/machine/daemon-start/direct-harness/session-subscriber.ts
100463
- function startSessionSubscriber(daemonSession, wsClient2, deps) {
100464
- const inFlight = new Set;
100465
- const unsub = wsClient2.onUpdate(api.daemon.directHarness.sessions.listPendingSessionsForMachine, {
100466
- sessionId: daemonSession.sessionId,
100467
- machineId: daemonSession.machineId
100468
- }, (pendingSessions) => {
100469
- if (!pendingSessions || pendingSessions.length === 0)
100470
- return;
100471
- for (const session2 of pendingSessions) {
100472
- const rowId = session2._id;
100473
- if (inFlight.has(rowId))
100474
- continue;
100475
- inFlight.add(rowId);
100476
- processOne(daemonSession, deps, session2).finally(() => inFlight.delete(rowId));
100477
- }
100478
- }, (err) => {
100479
- console.warn("[direct-harness] Session subscription error:", err instanceof Error ? err.message : String(err));
100480
- });
100481
- return { stop: unsub };
100482
- }
100483
- async function getOrCreateHarness(daemonSession, deps, session2, workspace) {
100484
- const harnessName = session2.opencode?.harnessName ?? "opencode-sdk";
100485
- const key = makeHarnessKey(session2.workspaceId, harnessName);
100486
- let harness = deps.harnesses.get(key);
100553
+ // src/commands/machine/daemon-start/shared-harness/get-or-create-bound-harness.ts
100554
+ async function getOrCreateBoundHarness(params) {
100555
+ const { harnesses, workspaceId, harnessName, workingDir, convexUrl, logPrefix } = params;
100556
+ const key = makeHarnessKey(workspaceId, harnessName);
100557
+ let harness = harnesses.get(key);
100487
100558
  if (harness && !harness.isAlive()) {
100488
- console.warn(`[direct-harness] Harness ${harnessName} for workspace ${session2.workspaceId} is no longer alive — restarting`);
100559
+ console.warn(`${logPrefix} Harness ${harnessName} for workspace ${workspaceId} is no longer alive — restarting`);
100489
100560
  harness.close().catch(() => {});
100490
- deps.harnesses.delete(key);
100561
+ harnesses.delete(key);
100491
100562
  harness = undefined;
100492
100563
  }
100493
100564
  if (!harness) {
100494
100565
  harness = await startBoundHarness({
100495
100566
  harnessName,
100496
- workingDir: workspace.workingDir,
100497
- workspaceId: session2.workspaceId,
100498
- resolvedConvexUrl: daemonSession.convexUrl
100567
+ workingDir,
100568
+ workspaceId,
100569
+ resolvedConvexUrl: convexUrl
100499
100570
  });
100500
- deps.harnesses.set(key, harness);
100571
+ harnesses.set(key, harness);
100501
100572
  }
100502
100573
  return harness;
100503
100574
  }
100504
- function recordLiveSessionChunk(event, handle, journal, extractChunk, deps) {
100505
- const chunk2 = extractChunk(event);
100506
- if (chunk2 === null) {
100507
- return;
100508
- }
100509
- journal.record({
100510
- content: chunk2.content,
100511
- timestamp: Date.now(),
100512
- messageId: chunk2.messageId,
100513
- partType: chunk2.partType
100514
- });
100515
- if (handle.currentTurn && handle.currentTurn.messageId === null) {
100516
- handle.currentTurn.messageId = chunk2.messageId;
100517
- deps.sessionRepository.bindTurnMessageId(handle.currentTurn.turnId, chunk2.messageId).catch((err) => console.warn("[direct-harness] bindTurnMessageId error:", err));
100518
- }
100519
- }
100520
- function handleLiveSessionProviderId(event, deps, rowId, handle, liveSession) {
100521
- if (event.type !== "session.provider_id")
100522
- return;
100523
- const sessionId = event.payload.sessionId;
100524
- if (!sessionId || sessionId === handle.opencodeSessionId)
100525
- return;
100526
- deps.sessionRepository.associateOpenCodeSessionId(rowId, sessionId, liveSession.sessionTitle ?? "").catch((err) => console.warn("[direct-harness] associateOpenCodeSessionId (provider id) error:", err));
100527
- }
100528
- function handleLiveSessionTitleUpdate(event, deps, rowId, liveSession) {
100529
- if (!isOpenCodeSessionEventType(event.type))
100530
- return;
100531
- if (event.type !== "session.updated") {
100532
- return;
100533
- }
100534
- const info = event.payload.info;
100535
- const newTitle = info?.title;
100536
- if (!newTitle || newTitle === liveSession.sessionTitle) {
100537
- return;
100538
- }
100539
- liveSession.setTitle?.(newTitle);
100540
- deps.sessionRepository.updateSessionTitle(rowId, newTitle).catch((err) => console.warn("[direct-harness] updateSessionTitle error:", err));
100541
- }
100542
- function handleLiveSessionEvent(event, ctx) {
100543
- const { handle, journal, extractChunk, idleConfig, deps, rowId, liveSession } = ctx;
100544
- recordLiveSessionChunk(event, handle, journal, extractChunk, deps);
100545
- if (event.type === "session.idle") {
100546
- handleSessionIdle(handle, journal, idleConfig, deps.sessionRepository).catch((err) => console.warn("[direct-harness] idle handler error:", err));
100547
- }
100548
- handleLiveSessionTitleUpdate(event, deps, rowId, liveSession);
100549
- handleLiveSessionProviderId(event, deps, rowId, handle, liveSession);
100550
- }
100551
- async function processOne(daemonSession, deps, session2) {
100552
- const rowId = session2._id;
100575
+ var init_get_or_create_bound_harness = __esm(() => {
100576
+ init_registry4();
100577
+ });
100578
+
100579
+ // src/commands/machine/daemon-start/shared-harness/open-pending-session.ts
100580
+ async function openPendingHarnessSession(daemonSession, deps, input, options) {
100581
+ const { rowId, workspaceId, harnessName, lastUsedConfig } = input;
100582
+ const { logPrefix, handleProviderIdEvents } = options;
100553
100583
  try {
100554
100584
  const workspace = await daemonSession.backend.query(api.workspaces.getWorkspaceById, {
100555
100585
  sessionId: daemonSession.sessionId,
100556
- workspaceId: session2.workspaceId
100586
+ workspaceId
100557
100587
  });
100558
100588
  if (!workspace) {
100559
- console.warn(`[direct-harness] Cannot open session ${rowId}: workspace ${session2.workspaceId} not found`);
100589
+ console.warn(`${logPrefix} Workspace ${workspaceId} not found for session ${rowId}`);
100560
100590
  await deps.sessionRepository.markFailed(rowId);
100561
100591
  return;
100562
100592
  }
100563
- const harnessName = session2.opencode?.harnessName ?? "opencode-sdk";
100564
- const harness = await getOrCreateHarness(daemonSession, deps, session2, workspace);
100565
- const modelConfig = session2.opencode?.lastUsedConfig.model;
100593
+ const harness = await getOrCreateBoundHarness({
100594
+ harnesses: deps.harnesses,
100595
+ workspaceId,
100596
+ harnessName,
100597
+ workingDir: workspace.workingDir,
100598
+ convexUrl: daemonSession.convexUrl,
100599
+ logPrefix
100600
+ });
100601
+ const modelConfig = lastUsedConfig.model;
100566
100602
  const model = modelConfig ? `${modelConfig.providerID}/${modelConfig.modelID}` : undefined;
100567
100603
  const liveSession = await harness.newSession({
100568
- agent: session2.opencode?.lastUsedConfig.agent ?? "build",
100604
+ agent: lastUsedConfig.agent,
100569
100605
  model,
100570
100606
  harnessSessionId: rowId
100571
100607
  });
100572
100608
  const journal = deps.journalFactory.create(rowId);
100573
100609
  const extractChunk = createChunkExtractor(harness.type);
100574
- const idleConfig = {
100575
- agent: session2.opencode?.lastUsedConfig.agent ?? "build",
100576
- model: session2.opencode?.lastUsedConfig.model
100577
- };
100610
+ const idleConfig = { agent: lastUsedConfig.agent, model: lastUsedConfig.model };
100578
100611
  let unsubscribeEvents = () => {};
100579
100612
  let closed = false;
100580
100613
  const close2 = async () => {
@@ -100591,22 +100624,41 @@ async function processOne(daemonSession, deps, session2) {
100591
100624
  harnessSessionId: rowId,
100592
100625
  harnessName,
100593
100626
  opencodeSessionId: liveSession.opencodeSessionId,
100594
- workspaceId: session2.workspaceId,
100627
+ workspaceId,
100595
100628
  session: liveSession,
100596
100629
  journal,
100597
100630
  currentTurn: null,
100598
100631
  close: close2
100599
100632
  };
100600
100633
  unsubscribeEvents = liveSession.onEvent((event) => {
100601
- handleLiveSessionEvent(event, {
100602
- handle,
100603
- journal,
100604
- extractChunk,
100605
- idleConfig,
100606
- deps,
100607
- rowId,
100608
- liveSession
100609
- });
100634
+ const chunk2 = extractChunk(event);
100635
+ if (chunk2 !== null) {
100636
+ journal.record({
100637
+ content: chunk2.content,
100638
+ timestamp: Date.now(),
100639
+ messageId: chunk2.messageId,
100640
+ partType: chunk2.partType
100641
+ });
100642
+ if (handle.currentTurn && handle.currentTurn.messageId === null) {
100643
+ handle.currentTurn.messageId = chunk2.messageId;
100644
+ deps.sessionRepository.bindTurnMessageId(handle.currentTurn.turnId, chunk2.messageId).catch((err) => console.warn(`${logPrefix} bindTurnMessageId error:`, err));
100645
+ }
100646
+ }
100647
+ if (event.type === "session.idle") {
100648
+ handleSessionIdle(handle, journal, idleConfig, deps.sessionRepository).catch((err) => console.warn(`${logPrefix} idle handler error:`, err));
100649
+ }
100650
+ if (isOpenCodeSessionEventType(event.type) && event.type === "session.updated") {
100651
+ const info = event.payload.info;
100652
+ if (info?.title) {
100653
+ deps.sessionRepository.updateSessionTitle(rowId, info.title).catch((err) => console.warn(`${logPrefix} updateSessionTitle error:`, err));
100654
+ }
100655
+ }
100656
+ if (handleProviderIdEvents && event.type === "session.provider_id") {
100657
+ const sessionId = event.payload.sessionId;
100658
+ if (sessionId && sessionId !== handle.opencodeSessionId) {
100659
+ deps.sessionRepository.associateOpenCodeSessionId(rowId, sessionId, liveSession.sessionTitle ?? "").catch((err) => console.warn(`${logPrefix} associateOpenCodeSessionId (provider id) error:`, err));
100660
+ }
100661
+ }
100610
100662
  });
100611
100663
  deps.activeSessions.set(rowId, handle);
100612
100664
  try {
@@ -100616,19 +100668,56 @@ async function processOne(daemonSession, deps, session2) {
100616
100668
  await liveSession.close().catch(() => {});
100617
100669
  throw err;
100618
100670
  }
100619
- console.log(`[direct-harness] Session opened: rowId=${rowId} agent=${session2.opencode?.lastUsedConfig.agent ?? "build"} workspace=${session2.workspaceId}`);
100671
+ console.log(`${logPrefix} Session opened: ${rowId} agent=${lastUsedConfig.agent} workspace=${workspaceId}`);
100620
100672
  } catch (err) {
100621
- console.warn(`[direct-harness] Failed to open session ${rowId}:`, err instanceof Error ? err.message : String(err));
100673
+ console.warn(`${logPrefix} Failed to open session ${rowId}:`, err instanceof Error ? err.message : String(err));
100622
100674
  try {
100623
100675
  await deps.sessionRepository.markFailed(rowId);
100624
100676
  } catch {}
100625
100677
  }
100626
100678
  }
100627
- var init_session_subscriber = __esm(() => {
100679
+ var init_open_pending_session = __esm(() => {
100628
100680
  init_idle_handler();
100629
100681
  init_api3();
100630
100682
  init_registry4();
100631
100683
  init_opencode_session_events();
100684
+ init_get_or_create_bound_harness();
100685
+ });
100686
+
100687
+ // src/commands/machine/daemon-start/direct-harness/session-subscriber.ts
100688
+ function startSessionSubscriber(daemonSession, wsClient2, deps) {
100689
+ const inFlight = new Set;
100690
+ const unsub = wsClient2.onUpdate(api.daemon.directHarness.sessions.listPendingSessionsForMachine, {
100691
+ sessionId: daemonSession.sessionId,
100692
+ machineId: daemonSession.machineId
100693
+ }, (pendingSessions) => {
100694
+ if (!pendingSessions || pendingSessions.length === 0)
100695
+ return;
100696
+ for (const session2 of pendingSessions) {
100697
+ const rowId = session2._id;
100698
+ if (inFlight.has(rowId))
100699
+ continue;
100700
+ inFlight.add(rowId);
100701
+ (async () => {
100702
+ const harnessName = session2.opencode?.harnessName ?? "opencode-sdk";
100703
+ const agent = session2.opencode?.lastUsedConfig?.agent ?? "build";
100704
+ const model = session2.opencode?.lastUsedConfig?.model;
100705
+ await openPendingHarnessSession(daemonSession, deps, {
100706
+ rowId: session2._id,
100707
+ workspaceId: session2.workspaceId,
100708
+ harnessName,
100709
+ lastUsedConfig: { agent, ...model ? { model } : {} }
100710
+ }, { logPrefix: "[direct-harness]", handleProviderIdEvents: true });
100711
+ })().finally(() => inFlight.delete(rowId));
100712
+ }
100713
+ }, (err) => {
100714
+ console.warn("[direct-harness] Session subscription error:", err instanceof Error ? err.message : String(err));
100715
+ });
100716
+ return { stop: unsub };
100717
+ }
100718
+ var init_session_subscriber = __esm(() => {
100719
+ init_api3();
100720
+ init_open_pending_session();
100632
100721
  });
100633
100722
 
100634
100723
  // src/commands/machine/daemon-start/direct-harness/shutdown-sessions.ts
@@ -101001,6 +101090,436 @@ var init_start_subscriptions = __esm(() => {
101001
101090
  init_convex_session_repository();
101002
101091
  });
101003
101092
 
101093
+ // ../../services/backend/prompts/agentic-query/system-prompt.ts
101094
+ function renderAgenticQuerySystemPrompt(params) {
101095
+ const completeCmd = `chatroom agentic-query complete --chatroom-id=${params.chatroomId} --query-id=${params.queryId} << 'CHATROOM_AGENTIC_QUERY_END'
101096
+ ## Summary
101097
+ ...
101098
+
101099
+ ## Results
101100
+ ...
101101
+
101102
+ ## Grounding
101103
+ ...
101104
+
101105
+ ## Files
101106
+ ...
101107
+ CHATROOM_AGENTIC_QUERY_END`;
101108
+ return [
101109
+ "You answer workspace-scoped search and ask queries by exploring the connected codebase.",
101110
+ "Use tools to read and search files. Prefer evidence over speculation.",
101111
+ "When done, submit results with the CLI heredoc below (markdown body only — no protocol markers like ---RESULT---).",
101112
+ "",
101113
+ "## Required markdown sections",
101114
+ "- ## Summary",
101115
+ "- ## Results",
101116
+ "- ## Grounding (required for ask mode; path:line evidence)",
101117
+ "- ## Files",
101118
+ "",
101119
+ "## Complete command",
101120
+ completeCmd,
101121
+ "",
101122
+ `Convex URL: ${params.convexUrl}`
101123
+ ].join(`
101124
+ `);
101125
+ }
101126
+
101127
+ // src/commands/machine/daemon-start/agentic-query/prompt-subscriber.ts
101128
+ async function ensureHarnessAlive(daemonSession, deps, info) {
101129
+ const key = makeHarnessKey(info.workspaceId, info.harnessName);
101130
+ const existing = deps.harnesses.get(key);
101131
+ if (existing?.isAlive())
101132
+ return existing;
101133
+ if (existing) {
101134
+ existing.close().catch(() => {});
101135
+ deps.harnesses.delete(key);
101136
+ }
101137
+ const workspace = await daemonSession.backend.query(api.workspaces.getWorkspaceById, {
101138
+ sessionId: daemonSession.sessionId,
101139
+ workspaceId: info.workspaceId
101140
+ });
101141
+ if (!workspace) {
101142
+ console.warn(`[agentic-query] Cannot resume ${info.runId}: workspace not found`);
101143
+ return null;
101144
+ }
101145
+ const harness = await startBoundHarness({
101146
+ harnessName: info.harnessName,
101147
+ workingDir: workspace.workingDir,
101148
+ workspaceId: info.workspaceId,
101149
+ resolvedConvexUrl: daemonSession.convexUrl
101150
+ });
101151
+ deps.harnesses.set(key, harness);
101152
+ return harness;
101153
+ }
101154
+ function wireResumedIdle(handle, deps, info) {
101155
+ const idleConfig = {
101156
+ agent: info.lastUsedConfig.agent ?? "build",
101157
+ model: info.lastUsedConfig.model
101158
+ };
101159
+ const bindTurnMessage = bindTurnMessageOnEvent(handle, deps.sessionRepository, "agentic-query");
101160
+ handle.session.onEvent((event) => {
101161
+ bindTurnMessage();
101162
+ if (event.type === "session.idle") {
101163
+ handleSessionIdle(handle, handle.journal, idleConfig, deps.sessionRepository).catch((err) => console.warn("[agentic-query] idle handler error (resume):", err));
101164
+ }
101165
+ });
101166
+ }
101167
+ async function resolveSessionHandle(daemonSession, deps, info) {
101168
+ const rowId = info.runId;
101169
+ const cached5 = deps.activeSessions.get(rowId);
101170
+ if (cached5)
101171
+ return cached5;
101172
+ if (!info.opencodeSessionId || !info.harnessName) {
101173
+ console.log(`[agentic-query] Session ${rowId} not yet open — waiting for session-subscriber`);
101174
+ return null;
101175
+ }
101176
+ try {
101177
+ const harness = await ensureHarnessAlive(daemonSession, deps, info);
101178
+ if (!harness)
101179
+ return null;
101180
+ const resumed = await resumeSession({
101181
+ harness,
101182
+ journalFactory: deps.journalFactory,
101183
+ chunkExtractor: createChunkExtractor(harness.type)
101184
+ }, {
101185
+ harnessSessionId: rowId,
101186
+ opencodeSessionId: info.opencodeSessionId,
101187
+ workspaceId: info.workspaceId,
101188
+ harnessName: info.harnessName
101189
+ });
101190
+ deps.activeSessions.set(rowId, resumed);
101191
+ wireResumedIdle(resumed, deps, info);
101192
+ console.log(`[agentic-query] Resumed session ${rowId}`);
101193
+ return resumed;
101194
+ } catch (err) {
101195
+ console.warn(`[agentic-query] Resume failed for ${rowId}: ${err instanceof Error ? err.message : String(err)}`);
101196
+ return null;
101197
+ }
101198
+ }
101199
+ async function deliverMessage(deps, daemonSession, existingSession, info, msg) {
101200
+ const rowId = info.runId;
101201
+ await deps.sessionRepository.setGenerating(rowId, true);
101202
+ const { turnId } = await deps.sessionRepository.beginAssistantTurn(rowId);
101203
+ existingSession.currentTurn = { turnId, messageId: null };
101204
+ await existingSession.session.prompt({
101205
+ parts: [{ type: "text", text: msg.content }],
101206
+ agent: info.lastUsedConfig.agent,
101207
+ ...info.lastUsedConfig.model ? { model: info.lastUsedConfig.model } : {},
101208
+ system: renderAgenticQuerySystemPrompt({
101209
+ convexUrl: daemonSession.convexUrl,
101210
+ chatroomId: info.chatroomId,
101211
+ queryId: info.agenticQueryId
101212
+ })
101213
+ });
101214
+ try {
101215
+ await deps.sessionRepository.markTurnProcessed(rowId, msg.seq);
101216
+ } catch (err) {
101217
+ console.warn(`[agentic-query] markTurnProcessed failed for session ${rowId} seq=${msg.seq}: ${err}`);
101218
+ }
101219
+ }
101220
+ async function drainPendingBatch(daemonSession, deps, batch) {
101221
+ for (const info of batch.sessions) {
101222
+ const existingSession = await resolveSessionHandle(daemonSession, deps, info);
101223
+ if (!existingSession)
101224
+ continue;
101225
+ const pendingMsgs = batch.messages.filter((m) => m.runId === info.runId).sort((a, b) => a.seq - b.seq);
101226
+ for (const msg of pendingMsgs) {
101227
+ await deliverMessage(deps, daemonSession, existingSession, info, msg);
101228
+ }
101229
+ }
101230
+ }
101231
+ function startPromptSubscriber(daemonSession, wsClient2, deps) {
101232
+ const handle = wsClient2.onUpdate(api.daemon.agenticQuery.messages.pendingForMachine, { sessionId: daemonSession.sessionId, machineId: daemonSession.machineId }, async (batch) => {
101233
+ if (!batch)
101234
+ return;
101235
+ await drainPendingBatch(daemonSession, deps, batch);
101236
+ });
101237
+ return { stop: handle };
101238
+ }
101239
+ var init_prompt_subscriber2 = __esm(() => {
101240
+ init_api3();
101241
+ init_resume_session();
101242
+ init_registry4();
101243
+ init_idle_handler();
101244
+ });
101245
+
101246
+ // src/commands/machine/daemon-start/agentic-query/session-subscriber.ts
101247
+ function startSessionSubscriber2(daemonSession, wsClient2, deps) {
101248
+ const inFlight = new Set;
101249
+ const unsub = wsClient2.onUpdate(api.daemon.agenticQuery.runs.pendingForMachine, { sessionId: daemonSession.sessionId, machineId: daemonSession.machineId }, (pendingSessions) => {
101250
+ if (!pendingSessions || pendingSessions.length === 0)
101251
+ return;
101252
+ for (const session2 of pendingSessions) {
101253
+ const rowId = session2.runId;
101254
+ if (inFlight.has(rowId))
101255
+ continue;
101256
+ inFlight.add(rowId);
101257
+ openPendingHarnessSession(daemonSession, deps, {
101258
+ rowId: session2.runId,
101259
+ workspaceId: session2.workspaceId,
101260
+ harnessName: session2.harnessName,
101261
+ lastUsedConfig: session2.lastUsedConfig
101262
+ }, { logPrefix: "[agentic-query]", handleProviderIdEvents: false }).finally(() => inFlight.delete(rowId));
101263
+ }
101264
+ }, (err) => {
101265
+ console.warn("[agentic-query] Session subscription error:", err instanceof Error ? err.message : String(err));
101266
+ });
101267
+ return { stop: unsub };
101268
+ }
101269
+ var init_session_subscriber2 = __esm(() => {
101270
+ init_api3();
101271
+ init_open_pending_session();
101272
+ });
101273
+
101274
+ // src/infrastructure/repos/convex-agentic-query-output-repository.ts
101275
+ class ConvexAgenticQueryOutputRepository {
101276
+ options;
101277
+ constructor(options) {
101278
+ this.options = options;
101279
+ }
101280
+ async appendChunks(runId, chunks) {
101281
+ const { backend: backend2, sessionId } = this.options;
101282
+ if (chunks.length === 0)
101283
+ return;
101284
+ await backend2.mutation(api.daemon.agenticQuery.messages.appendMessages, {
101285
+ sessionId,
101286
+ runId,
101287
+ chunks: chunks.map((c) => ({
101288
+ content: c.content,
101289
+ timestamp: c.timestamp,
101290
+ messageId: c.messageId,
101291
+ partType: c.partType
101292
+ }))
101293
+ });
101294
+ }
101295
+ }
101296
+ var init_convex_agentic_query_output_repository = __esm(() => {
101297
+ init_api3();
101298
+ });
101299
+
101300
+ // src/infrastructure/repos/convex-agentic-query-run-repository.ts
101301
+ class ConvexAgenticQueryRunRepository {
101302
+ options;
101303
+ constructor(options) {
101304
+ this.options = options;
101305
+ }
101306
+ async associateOpenCodeSessionId(harnessSessionId, opencodeSessionId, sessionTitle) {
101307
+ const { backend: backend2, sessionId } = this.options;
101308
+ await backend2.mutation(api.daemon.agenticQuery.runs.associateOpenCodeSessionId, {
101309
+ sessionId,
101310
+ runId: harnessSessionId,
101311
+ opencodeSessionId,
101312
+ sessionTitle
101313
+ });
101314
+ }
101315
+ async getOpenCodeSessionId(harnessSessionId) {
101316
+ const { backend: backend2, sessionId } = this.options;
101317
+ const result = await backend2.query(api.daemon.agenticQuery.runs.getRun, {
101318
+ sessionId,
101319
+ runId: harnessSessionId
101320
+ });
101321
+ return result?.opencode?.opencodeSessionId;
101322
+ }
101323
+ async markClosed(harnessSessionId) {
101324
+ const { backend: backend2, sessionId } = this.options;
101325
+ await backend2.mutation(api.daemon.agenticQuery.runs.closeRun, {
101326
+ sessionId,
101327
+ runId: harnessSessionId
101328
+ });
101329
+ }
101330
+ async markIdle(harnessSessionId) {
101331
+ const { backend: backend2, sessionId } = this.options;
101332
+ await backend2.mutation(api.daemon.agenticQuery.runs.markIdle, {
101333
+ sessionId,
101334
+ runId: harnessSessionId
101335
+ });
101336
+ }
101337
+ async markFailed(harnessSessionId) {
101338
+ const { backend: backend2, sessionId } = this.options;
101339
+ await backend2.mutation(api.daemon.agenticQuery.runs.markFailed, {
101340
+ sessionId,
101341
+ runId: harnessSessionId
101342
+ });
101343
+ }
101344
+ async markActive(harnessSessionId) {
101345
+ const { backend: backend2, sessionId } = this.options;
101346
+ await backend2.mutation(api.daemon.agenticQuery.runs.markActive, {
101347
+ sessionId,
101348
+ runId: harnessSessionId
101349
+ });
101350
+ }
101351
+ async markTurnProcessed(harnessSessionId, turnSeq) {
101352
+ const { backend: backend2, sessionId } = this.options;
101353
+ await backend2.mutation(api.daemon.agenticQuery.turns.markTurnProcessed, {
101354
+ sessionId,
101355
+ runId: harnessSessionId,
101356
+ turnSeq
101357
+ });
101358
+ }
101359
+ async setGenerating(harnessSessionId, isGenerating) {
101360
+ const { backend: backend2, sessionId } = this.options;
101361
+ await backend2.mutation(api.daemon.agenticQuery.queue.setGenerating, {
101362
+ sessionId,
101363
+ runId: harnessSessionId,
101364
+ isGenerating
101365
+ });
101366
+ }
101367
+ async dequeueNext(harnessSessionId) {
101368
+ const { backend: backend2, sessionId } = this.options;
101369
+ await backend2.mutation(api.daemon.agenticQuery.queue.dequeueNext, {
101370
+ sessionId,
101371
+ runId: harnessSessionId
101372
+ });
101373
+ return null;
101374
+ }
101375
+ async beginAssistantTurn(harnessSessionId) {
101376
+ const { backend: backend2, sessionId } = this.options;
101377
+ return backend2.mutation(api.daemon.agenticQuery.turns.beginAssistantTurn, {
101378
+ sessionId,
101379
+ runId: harnessSessionId
101380
+ });
101381
+ }
101382
+ async bindTurnMessageId(turnId, messageId) {
101383
+ const { backend: backend2, sessionId } = this.options;
101384
+ await backend2.mutation(api.daemon.agenticQuery.turns.bindTurnMessageId, {
101385
+ sessionId,
101386
+ turnId,
101387
+ messageId
101388
+ });
101389
+ }
101390
+ async finalizeAssistantTurn(turnId) {
101391
+ const { backend: backend2, sessionId } = this.options;
101392
+ await backend2.mutation(api.daemon.agenticQuery.turns.finalizeAssistantTurn, {
101393
+ sessionId,
101394
+ turnId
101395
+ });
101396
+ }
101397
+ async updateSessionTitle(harnessSessionId, title) {}
101398
+ }
101399
+ var init_convex_agentic_query_run_repository = __esm(() => {
101400
+ init_api3();
101401
+ });
101402
+
101403
+ // src/commands/machine/daemon-start/agentic-query/start-subscriptions.ts
101404
+ function startAgenticQuerySubscriptions(session2, wsClient2, activeSessions, harnesses) {
101405
+ const sessionRepository = new ConvexAgenticQueryRunRepository({
101406
+ backend: session2.backend,
101407
+ sessionId: session2.sessionId
101408
+ });
101409
+ const outputRepository = new ConvexAgenticQueryOutputRepository({
101410
+ backend: session2.backend,
101411
+ sessionId: session2.sessionId
101412
+ });
101413
+ const journalFactory = new BufferedJournalFactory({ outputRepository });
101414
+ const deps = { activeSessions, harnesses, sessionRepository, journalFactory };
101415
+ const pendingPromptSubscriptionHandle = startPromptSubscriber(session2, wsClient2, deps);
101416
+ const pendingHarnessSessionSubscriptionHandle = startSessionSubscriber2(session2, wsClient2, deps);
101417
+ return {
101418
+ pendingPromptSubscriptionHandle,
101419
+ pendingHarnessSessionSubscriptionHandle
101420
+ };
101421
+ }
101422
+ var init_start_subscriptions2 = __esm(() => {
101423
+ init_prompt_subscriber2();
101424
+ init_session_subscriber2();
101425
+ init_convex_agentic_query_output_repository();
101426
+ init_convex_agentic_query_run_repository();
101427
+ });
101428
+
101429
+ // src/commands/machine/daemon-start/file-content-classifier.ts
101430
+ function extensionOf(path3) {
101431
+ const lastDot = path3.lastIndexOf(".");
101432
+ if (lastDot === -1)
101433
+ return null;
101434
+ return path3.slice(lastDot).toLowerCase();
101435
+ }
101436
+ function hasKnownBinaryExtension(path3) {
101437
+ const ext = extensionOf(path3);
101438
+ return ext !== null && BINARY_EXTENSIONS.has(ext);
101439
+ }
101440
+ function hasNulByte(buffer) {
101441
+ return buffer.includes(0);
101442
+ }
101443
+ function hasTooManyControlChars(buffer) {
101444
+ let count3 = 0;
101445
+ const threshold = Math.max(1, Math.floor(buffer.length * 0.01));
101446
+ for (const byte of buffer) {
101447
+ if (byte === 0)
101448
+ return true;
101449
+ if (byte < 32 && byte !== 9 && byte !== 10 && byte !== 13) {
101450
+ count3++;
101451
+ if (count3 > threshold)
101452
+ return true;
101453
+ }
101454
+ }
101455
+ return false;
101456
+ }
101457
+ function classifyFileContent(path3, buffer) {
101458
+ if (hasKnownBinaryExtension(path3)) {
101459
+ return { kind: "binary", encoding: "binary" };
101460
+ }
101461
+ if (buffer.length === 0) {
101462
+ return { kind: "text", encoding: "utf8" };
101463
+ }
101464
+ if (hasNulByte(buffer)) {
101465
+ return { kind: "binary", encoding: "binary" };
101466
+ }
101467
+ try {
101468
+ const decoded = new TextDecoder("utf-8", { fatal: true }).decode(buffer);
101469
+ if (decoded.length === 0) {
101470
+ return { kind: "text", encoding: "utf8" };
101471
+ }
101472
+ if (hasTooManyControlChars(buffer)) {
101473
+ return { kind: "binary", encoding: "binary" };
101474
+ }
101475
+ return { kind: "text", encoding: "utf8" };
101476
+ } catch {
101477
+ return { kind: "binary", encoding: "binary" };
101478
+ }
101479
+ }
101480
+ var BINARY_EXTENSIONS;
101481
+ var init_file_content_classifier = __esm(() => {
101482
+ BINARY_EXTENSIONS = new Set([
101483
+ ".png",
101484
+ ".jpg",
101485
+ ".jpeg",
101486
+ ".gif",
101487
+ ".webp",
101488
+ ".ico",
101489
+ ".mp3",
101490
+ ".mp4",
101491
+ ".wav",
101492
+ ".ogg",
101493
+ ".webm",
101494
+ ".zip",
101495
+ ".tar",
101496
+ ".gz",
101497
+ ".bz2",
101498
+ ".7z",
101499
+ ".rar",
101500
+ ".pdf",
101501
+ ".doc",
101502
+ ".docx",
101503
+ ".xls",
101504
+ ".xlsx",
101505
+ ".ppt",
101506
+ ".pptx",
101507
+ ".woff",
101508
+ ".woff2",
101509
+ ".ttf",
101510
+ ".otf",
101511
+ ".eot",
101512
+ ".exe",
101513
+ ".dll",
101514
+ ".so",
101515
+ ".dylib",
101516
+ ".bin",
101517
+ ".dat",
101518
+ ".db",
101519
+ ".sqlite"
101520
+ ]);
101521
+ });
101522
+
101004
101523
  // src/infrastructure/services/workspace/normalize-working-dir.ts
101005
101524
  function normalizeWorkingDirForLookup(workingDir) {
101006
101525
  return workingDir.trim().replace(/[/\\]+$/, "");
@@ -101221,100 +101740,6 @@ var init_workspace_visibility_policy = __esm(() => {
101221
101740
  ];
101222
101741
  });
101223
101742
 
101224
- // src/commands/machine/daemon-start/file-content-classifier.ts
101225
- function extensionOf(path3) {
101226
- const lastDot = path3.lastIndexOf(".");
101227
- if (lastDot === -1)
101228
- return null;
101229
- return path3.slice(lastDot).toLowerCase();
101230
- }
101231
- function hasKnownBinaryExtension(path3) {
101232
- const ext = extensionOf(path3);
101233
- return ext !== null && BINARY_EXTENSIONS.has(ext);
101234
- }
101235
- function hasNulByte(buffer) {
101236
- return buffer.includes(0);
101237
- }
101238
- function hasTooManyControlChars(buffer) {
101239
- let count3 = 0;
101240
- const threshold = Math.max(1, Math.floor(buffer.length * 0.01));
101241
- for (const byte of buffer) {
101242
- if (byte === 0)
101243
- return true;
101244
- if (byte < 32 && byte !== 9 && byte !== 10 && byte !== 13) {
101245
- count3++;
101246
- if (count3 > threshold)
101247
- return true;
101248
- }
101249
- }
101250
- return false;
101251
- }
101252
- function classifyFileContent(path3, buffer) {
101253
- if (hasKnownBinaryExtension(path3)) {
101254
- return { kind: "binary", encoding: "binary" };
101255
- }
101256
- if (buffer.length === 0) {
101257
- return { kind: "text", encoding: "utf8" };
101258
- }
101259
- if (hasNulByte(buffer)) {
101260
- return { kind: "binary", encoding: "binary" };
101261
- }
101262
- try {
101263
- const decoded = new TextDecoder("utf-8", { fatal: true }).decode(buffer);
101264
- if (decoded.length === 0) {
101265
- return { kind: "text", encoding: "utf8" };
101266
- }
101267
- if (hasTooManyControlChars(buffer)) {
101268
- return { kind: "binary", encoding: "binary" };
101269
- }
101270
- return { kind: "text", encoding: "utf8" };
101271
- } catch {
101272
- return { kind: "binary", encoding: "binary" };
101273
- }
101274
- }
101275
- var BINARY_EXTENSIONS;
101276
- var init_file_content_classifier = __esm(() => {
101277
- BINARY_EXTENSIONS = new Set([
101278
- ".png",
101279
- ".jpg",
101280
- ".jpeg",
101281
- ".gif",
101282
- ".webp",
101283
- ".ico",
101284
- ".mp3",
101285
- ".mp4",
101286
- ".wav",
101287
- ".ogg",
101288
- ".webm",
101289
- ".zip",
101290
- ".tar",
101291
- ".gz",
101292
- ".bz2",
101293
- ".7z",
101294
- ".rar",
101295
- ".pdf",
101296
- ".doc",
101297
- ".docx",
101298
- ".xls",
101299
- ".xlsx",
101300
- ".ppt",
101301
- ".pptx",
101302
- ".woff",
101303
- ".woff2",
101304
- ".ttf",
101305
- ".otf",
101306
- ".eot",
101307
- ".exe",
101308
- ".dll",
101309
- ".so",
101310
- ".dylib",
101311
- ".bin",
101312
- ".dat",
101313
- ".db",
101314
- ".sqlite"
101315
- ]);
101316
- });
101317
-
101318
101743
  // src/commands/machine/daemon-start/file-content-fulfillment.ts
101319
101744
  import { readFile as readFile7 } from "node:fs/promises";
101320
101745
  import { gzipSync as gzipSync2 } from "node:zlib";
@@ -101347,11 +101772,11 @@ var MAX_CONTENT_BYTES, fulfillFileContentRequestsEffect;
101347
101772
  var init_file_content_fulfillment = __esm(() => {
101348
101773
  init_esm();
101349
101774
  init_daemon_services();
101775
+ init_file_content_classifier();
101350
101776
  init_api3();
101351
101777
  init_assert_registered_working_dir();
101352
101778
  init_workspace_path_security();
101353
101779
  init_workspace_visibility_policy();
101354
- init_file_content_classifier();
101355
101780
  MAX_CONTENT_BYTES = 500 * 1024;
101356
101781
  fulfillFileContentRequestsEffect = exports_Effect.gen(function* () {
101357
101782
  const session2 = yield* DaemonSessionService;
@@ -108436,7 +108861,7 @@ async function discoverModelsForHarness(harness, service3) {
108436
108861
  async function discoverModels(agentServices) {
108437
108862
  return exports_Effect.runPromise(discoverModelsEffect(agentServices));
108438
108863
  }
108439
- function createDefaultDeps17() {
108864
+ function createDefaultDeps18() {
108440
108865
  return {
108441
108866
  backend: {
108442
108867
  mutation: async () => {
@@ -108771,7 +109196,7 @@ var init_init2 = __esm(() => {
108771
109196
  convexUrl,
108772
109197
  agentServices,
108773
109198
  cachedModels,
108774
- deps: createDefaultDeps17()
109199
+ deps: createDefaultDeps18()
108775
109200
  });
108776
109201
  yield* registerEventListenersEffect().pipe(exports_Effect.provide(daemonSessionToLayers(init2)));
108777
109202
  yield* logStartupEffect(cachedModels).pipe(exports_Effect.provide(daemonSessionToLayers(init2)));
@@ -111649,6 +112074,7 @@ var init_command_loop = __esm(() => {
111649
112074
  init_pid();
111650
112075
  init_daemon_services();
111651
112076
  init_start_subscriptions();
112077
+ init_start_subscriptions2();
111652
112078
  init_file_content_subscription();
111653
112079
  init_file_tree_subscription();
111654
112080
  init_file_write_subscription();
@@ -111703,6 +112129,8 @@ var init_command_loop = __esm(() => {
111703
112129
  let pendingPromptSubscriptionHandle = null;
111704
112130
  let pendingHarnessSessionSubscriptionHandle = null;
111705
112131
  let commandSubscriptionHandle = null;
112132
+ let aqPendingPromptSubscriptionHandle = null;
112133
+ let aqPendingHarnessSessionSubscriptionHandle = null;
111706
112134
  let lifecycleManager = null;
111707
112135
  let closeDirectHarnessSessionsOnShutdown = null;
111708
112136
  const activeSessions = new Map;
@@ -111770,6 +112198,8 @@ var init_command_loop = __esm(() => {
111770
112198
  pendingHarnessSessionSubscriptionHandle?.stop();
111771
112199
  commandSubscriptionHandle?.stop();
111772
112200
  lifecycleManager?.stopMonitoring();
112201
+ aqPendingPromptSubscriptionHandle?.stop();
112202
+ aqPendingHarnessSessionSubscriptionHandle?.stop();
111773
112203
  };
111774
112204
  const runDaemonShutdownEffect = async () => {
111775
112205
  await withTimeout2(exports_Effect.runPromise(onDaemonShutdownEffect.pipe(exports_Effect.provide(effectContext2))), PROCESS_KILL_TIMEOUT_MS);
@@ -111823,6 +112253,14 @@ var init_command_loop = __esm(() => {
111823
112253
  commandSubscriptionHandle = handles.commandSubscriptionHandle;
111824
112254
  lifecycleManager = handles.lifecycleManager;
111825
112255
  closeDirectHarnessSessionsOnShutdown = handles.closeSessionsOnShutdown;
112256
+ const aqHandles = startAgenticQuerySubscriptions({
112257
+ sessionId: session2.sessionId,
112258
+ machineId: session2.machineId,
112259
+ backend: session2.backend,
112260
+ convexUrl: session2.convexUrl
112261
+ }, wsClient2, activeSessions, harnesses);
112262
+ aqPendingPromptSubscriptionHandle = aqHandles.pendingPromptSubscriptionHandle;
112263
+ aqPendingHarnessSessionSubscriptionHandle = aqHandles.pendingHarnessSessionSubscriptionHandle;
111826
112264
  }
111827
112265
  console.log(`
111828
112266
  Listening for commands...`);
@@ -112017,7 +112455,7 @@ async function isChatroomInstalledDefault() {
112017
112455
  return false;
112018
112456
  }
112019
112457
  }
112020
- async function createDefaultDeps18() {
112458
+ async function createDefaultDeps19() {
112021
112459
  const client4 = await getConvexClient();
112022
112460
  const fs12 = await import("fs/promises");
112023
112461
  return {
@@ -112092,7 +112530,7 @@ After installation, run this command again.`;
112092
112530
  });
112093
112531
  }
112094
112532
  async function installTool(options = {}, deps) {
112095
- const d = deps ?? await createDefaultDeps18();
112533
+ const d = deps ?? await createDefaultDeps19();
112096
112534
  const layer = layerFromDeps9(d);
112097
112535
  return exports_Effect.runPromise(installToolEffect(options).pipe(exports_Effect.catchAll((err) => handleInstallError(err)), exports_Effect.provide(layer)));
112098
112536
  }
@@ -112650,6 +113088,33 @@ handoffCommandGroup.requiredOption("--chatroom-id <id>", "Chatroom identifier").
112650
113088
  nextRole: options.nextRole
112651
113089
  });
112652
113090
  });
113091
+ var agenticQueryCommand = program2.command("agentic-query").description("Agentic search/ask query commands");
113092
+ agenticQueryCommand.command("complete").description("Submit the structured agentic query result markdown").requiredOption("--chatroom-id <id>", "Chatroom identifier").requiredOption("--query-id <id>", "Agentic query identifier").action(async (options) => {
113093
+ await maybeRequireAuth();
113094
+ const { decode: decode5 } = await Promise.resolve().then(() => exports_decode);
113095
+ const stdinContent = await readStdin();
113096
+ let result;
113097
+ try {
113098
+ const { AGENTIC_QUERY_STDIN_DELIMITER: AGENTIC_QUERY_STDIN_DELIMITER2, validateStdinHeredocBody: validateStdinHeredocBody2 } = await Promise.resolve().then(() => (init_stdin_heredoc(), exports_stdin_heredoc));
113099
+ const decoded = decode5(stdinContent, { singleParam: "result" });
113100
+ let body = decoded.result;
113101
+ body = body.replace(/^(---RESULT---\s*)+/i, "").trim();
113102
+ validateStdinHeredocBody2(body, AGENTIC_QUERY_STDIN_DELIMITER2);
113103
+ result = body;
113104
+ } catch (err) {
113105
+ console.error(`❌ Failed to decode stdin: ${err.message}`);
113106
+ process.exit(1);
113107
+ }
113108
+ if (!result?.trim()) {
113109
+ console.error("❌ Result body is empty");
113110
+ process.exit(1);
113111
+ }
113112
+ const { agenticQueryComplete: agenticQueryComplete2 } = await Promise.resolve().then(() => (init_complete(), exports_complete));
113113
+ await agenticQueryComplete2(options.chatroomId, {
113114
+ queryId: options.queryId,
113115
+ result
113116
+ });
113117
+ });
112653
113118
  var backlogCommand = program2.command("backlog").description("Manage task queue and backlog");
112654
113119
  backlogCommand.command("list").description("List backlog items").requiredOption("--chatroom-id <id>", "Chatroom identifier").requiredOption("--role <role>", "Your role").option("--limit <n>", "Maximum number of items to show").option("--sort <sort>", "Sort order: date:desc (default) | priority:desc").option("--filter <filter>", "Filter: unscored (only items without priority score)").action(async (options) => {
112655
113120
  await maybeRequireAuth();
@@ -112934,4 +113399,4 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
112934
113399
  });
112935
113400
  program2.parse();
112936
113401
 
112937
- //# debugId=4AEC2FD829D3A5B464756E2164756E21
113402
+ //# debugId=766A192ADD34FFEC64756E2164756E21