chatroom-cli 1.106.0 → 1.107.1
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 +463 -137
- package/dist/index.js.map +19 -16
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -78981,6 +78981,9 @@ var init_machine_service = __esm(() => {
|
|
|
78981
78981
|
RegisterAgentMachineService = class RegisterAgentMachineService extends exports_Context.Tag("RegisterAgentMachineService")() {
|
|
78982
78982
|
};
|
|
78983
78983
|
});
|
|
78984
|
+
// ../../services/backend/convex/workspaceFileTree/access.ts
|
|
78985
|
+
var FILE_TREE_SYNC_DISABLED_CODE = "FILE_TREE_SYNC_DISABLED";
|
|
78986
|
+
var init_access = () => {};
|
|
78984
78987
|
|
|
78985
78988
|
// src/utils/convex-error.ts
|
|
78986
78989
|
function formatConvexErrorObject(data) {
|
|
@@ -79013,8 +79016,23 @@ function getErrorMessage(error) {
|
|
|
79013
79016
|
return formatServerError(error);
|
|
79014
79017
|
return String(error);
|
|
79015
79018
|
}
|
|
79019
|
+
function getConvexErrorCode(error) {
|
|
79020
|
+
if (!(error instanceof ConvexError))
|
|
79021
|
+
return;
|
|
79022
|
+
const data = error.data;
|
|
79023
|
+
if (data !== null && typeof data === "object" && "code" in data) {
|
|
79024
|
+
const code2 = data.code;
|
|
79025
|
+
if (typeof code2 === "string")
|
|
79026
|
+
return code2;
|
|
79027
|
+
}
|
|
79028
|
+
return;
|
|
79029
|
+
}
|
|
79030
|
+
function isFileTreeSyncDisabledError(error) {
|
|
79031
|
+
return getConvexErrorCode(error) === FILE_TREE_SYNC_DISABLED_CODE;
|
|
79032
|
+
}
|
|
79016
79033
|
var SERVER_ERROR_HINT;
|
|
79017
79034
|
var init_convex_error = __esm(() => {
|
|
79035
|
+
init_access();
|
|
79018
79036
|
init_values();
|
|
79019
79037
|
SERVER_ERROR_HINT = "This is a generic server error — likely a backend arg-validator rejection or a CLI/backend version mismatch." + " Verify the CLI and backend are on the same commit (run `pnpm install` and check `git log -1 origin/master`).";
|
|
79020
79038
|
});
|
|
@@ -80698,6 +80716,7 @@ ${getHandoffNotApplicableSectionComment("List tradeoffs")}
|
|
|
80698
80716
|
|
|
80699
80717
|
## System Design
|
|
80700
80718
|
${getHandoffNotApplicableSectionComment("Include a mermaid diagram when the change has non-trivial structure")}
|
|
80719
|
+
<!-- Mermaid formatting: wrap the diagram in a fenced code block that begins with \`\`\`mermaid and ends with \`\`\`. Never write a bare "mermaid" line — it will not render. -->
|
|
80701
80720
|
|
|
80702
80721
|
\`\`\`mermaid
|
|
80703
80722
|
flowchart TD
|
|
@@ -106064,6 +106083,7 @@ var init_model_catalog = __esm(() => {
|
|
|
106064
106083
|
init_model_provider();
|
|
106065
106084
|
init_model_variant();
|
|
106066
106085
|
CODEX_MODEL_IDS = [
|
|
106086
|
+
"gpt-6-astra",
|
|
106067
106087
|
"gpt-5.6-terra",
|
|
106068
106088
|
"gpt-5.6-luna",
|
|
106069
106089
|
"gpt-5.6-sol",
|
|
@@ -116251,11 +116271,20 @@ async function publishCheckpointUntilPruned(session2, normalizedWorkingDir, snap
|
|
|
116251
116271
|
assertCheckpointAccepted(result);
|
|
116252
116272
|
return checkpointRevision;
|
|
116253
116273
|
}
|
|
116254
|
-
function createWorkspaceFileTreeCheckpointSend(session2, normalizedWorkingDir) {
|
|
116274
|
+
function createWorkspaceFileTreeCheckpointSend(session2, normalizedWorkingDir, options) {
|
|
116255
116275
|
return async (state) => {
|
|
116256
|
-
|
|
116257
|
-
|
|
116258
|
-
|
|
116276
|
+
try {
|
|
116277
|
+
const snapshot = await syncScannedFileTree(session2, normalizedWorkingDir, state.tree, computeFileTreeDataHash(state.tree), randomUUID11());
|
|
116278
|
+
const revision = await publishCheckpointUntilPruned(session2, normalizedWorkingDir, snapshot, state.revision);
|
|
116279
|
+
return { revision };
|
|
116280
|
+
} catch (error51) {
|
|
116281
|
+
if (!isFileTreeSyncDisabledError(error51))
|
|
116282
|
+
throw error51;
|
|
116283
|
+
(async () => options?.onSyncDisabled?.())().catch(() => {
|
|
116284
|
+
return;
|
|
116285
|
+
});
|
|
116286
|
+
return { revision: state.revision };
|
|
116287
|
+
}
|
|
116259
116288
|
};
|
|
116260
116289
|
}
|
|
116261
116290
|
var init_workspace_file_tree_checkpoint_send = __esm(() => {
|
|
@@ -116264,6 +116293,7 @@ var init_workspace_file_tree_checkpoint_send = __esm(() => {
|
|
|
116264
116293
|
init_file_tree_data_hash();
|
|
116265
116294
|
init_blob_snapshot_publish();
|
|
116266
116295
|
init_sharded_snapshot_publish();
|
|
116296
|
+
init_convex_error();
|
|
116267
116297
|
});
|
|
116268
116298
|
|
|
116269
116299
|
// src/daemon/infrastructure/outbox/workspace-file-tree-delta-send.ts
|
|
@@ -116285,52 +116315,81 @@ function toDeltaOperations(delta) {
|
|
|
116285
116315
|
}))
|
|
116286
116316
|
];
|
|
116287
116317
|
}
|
|
116288
|
-
function createWorkspaceFileTreeDeltaSend(session2, normalizedWorkingDir) {
|
|
116318
|
+
function createWorkspaceFileTreeDeltaSend(session2, normalizedWorkingDir, options) {
|
|
116289
116319
|
return async (unit) => {
|
|
116290
|
-
|
|
116291
|
-
|
|
116292
|
-
|
|
116293
|
-
|
|
116294
|
-
|
|
116295
|
-
|
|
116296
|
-
|
|
116297
|
-
|
|
116298
|
-
|
|
116299
|
-
|
|
116320
|
+
try {
|
|
116321
|
+
const result = await session2.backend.mutation(api.workspaceFiles.applyFileTreeDeltaBatch, {
|
|
116322
|
+
sessionId: session2.sessionId,
|
|
116323
|
+
machineId: session2.machineId,
|
|
116324
|
+
workingDir: normalizedWorkingDir,
|
|
116325
|
+
operationId: unit.delta.operationId,
|
|
116326
|
+
baseRevision: unit.baseRevision,
|
|
116327
|
+
operations: toDeltaOperations(unit.delta)
|
|
116328
|
+
});
|
|
116329
|
+
if (result.status === "resync-required") {
|
|
116330
|
+
return { status: "conflict", revision: result.expectedRevision };
|
|
116331
|
+
}
|
|
116332
|
+
return result;
|
|
116333
|
+
} catch (error51) {
|
|
116334
|
+
if (!isFileTreeSyncDisabledError(error51))
|
|
116335
|
+
throw error51;
|
|
116336
|
+
(async () => options?.onSyncDisabled?.())().catch(() => {
|
|
116337
|
+
return;
|
|
116338
|
+
});
|
|
116339
|
+
return { status: "applied", revision: unit.baseRevision };
|
|
116300
116340
|
}
|
|
116301
|
-
return result;
|
|
116302
116341
|
};
|
|
116303
116342
|
}
|
|
116304
116343
|
var init_workspace_file_tree_delta_send = __esm(() => {
|
|
116305
116344
|
init_api3();
|
|
116345
|
+
init_convex_error();
|
|
116306
116346
|
});
|
|
116307
116347
|
|
|
116308
116348
|
// src/daemon/entry/files/file-tree-subscription.ts
|
|
116309
116349
|
function logSubscriptionWarn(label, err) {
|
|
116310
116350
|
console.warn(`[${formatTimestamp()}] ⚠️ ${label}: ${getErrorMessage(err)}`);
|
|
116311
116351
|
}
|
|
116312
|
-
async function runOneShotFileTreeSync(session2, workingDir) {
|
|
116352
|
+
async function runOneShotFileTreeSync(session2, workingDir, coordinators, checkpointOutboxRegistry, deltaOutboxRegistry) {
|
|
116313
116353
|
const normalized = normalizeWorkingDirForLookup(workingDir);
|
|
116314
|
-
|
|
116315
|
-
|
|
116316
|
-
|
|
116317
|
-
|
|
116318
|
-
|
|
116319
|
-
|
|
116320
|
-
|
|
116321
|
-
|
|
116354
|
+
let syncDisabled = false;
|
|
116355
|
+
try {
|
|
116356
|
+
const tree = await scanFileTree(normalized);
|
|
116357
|
+
const send = createWorkspaceFileTreeCheckpointSend(session2, normalized, {
|
|
116358
|
+
onSyncDisabled: () => {
|
|
116359
|
+
syncDisabled = true;
|
|
116360
|
+
}
|
|
116361
|
+
});
|
|
116362
|
+
await send({ tree, revision: 0 });
|
|
116363
|
+
if (syncDisabled) {
|
|
116364
|
+
await stopFileTreeSyncForDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized);
|
|
116365
|
+
return;
|
|
116366
|
+
}
|
|
116367
|
+
await session2.backend.mutation(api.workspaceFiles.fulfillFileTreeRequest, {
|
|
116368
|
+
sessionId: session2.sessionId,
|
|
116369
|
+
machineId: session2.machineId,
|
|
116370
|
+
workingDir: normalized
|
|
116371
|
+
});
|
|
116372
|
+
} catch (error51) {
|
|
116373
|
+
if (!isFileTreeSyncDisabledError(error51))
|
|
116374
|
+
throw error51;
|
|
116375
|
+
await stopFileTreeSyncForDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized);
|
|
116376
|
+
}
|
|
116322
116377
|
}
|
|
116323
116378
|
async function stopCoordinatorForWorkingDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized) {
|
|
116324
116379
|
const coordinatorPromise = coordinators.get(normalized);
|
|
116325
|
-
if (
|
|
116326
|
-
|
|
116327
|
-
|
|
116328
|
-
|
|
116329
|
-
|
|
116330
|
-
}
|
|
116380
|
+
if (coordinatorPromise) {
|
|
116381
|
+
coordinators.delete(normalized);
|
|
116382
|
+
await coordinatorPromise.then((coordinator2) => coordinator2.stop()).catch(() => {
|
|
116383
|
+
return;
|
|
116384
|
+
});
|
|
116385
|
+
}
|
|
116331
116386
|
await checkpointOutboxRegistry?.stop(normalized);
|
|
116332
116387
|
await deltaOutboxRegistry?.stop(normalized);
|
|
116333
116388
|
}
|
|
116389
|
+
async function stopFileTreeSyncForDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized) {
|
|
116390
|
+
await stopCoordinatorForWorkingDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized);
|
|
116391
|
+
console.log(`[${formatTimestamp()}] \uD83C\uDF33 File tree sync disabled: ${normalized}`);
|
|
116392
|
+
}
|
|
116334
116393
|
async function drainPendingFileTreeReleaseRequests(session2, coordinators, checkpointOutboxRegistry, deltaOutboxRegistry) {
|
|
116335
116394
|
while (true) {
|
|
116336
116395
|
const releases = await session2.backend.query(api.workspaceFiles.getPendingFileTreeReleaseRequests, {
|
|
@@ -116346,13 +116405,12 @@ async function drainPendingFileTreeReleaseRequests(session2, coordinators, check
|
|
|
116346
116405
|
let successCount = 0;
|
|
116347
116406
|
for (const normalized of releasesByDir) {
|
|
116348
116407
|
try {
|
|
116349
|
-
await
|
|
116408
|
+
await stopFileTreeSyncForDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized);
|
|
116350
116409
|
await session2.backend.mutation(api.workspaceFiles.fulfillFileTreeReleaseRequest, {
|
|
116351
116410
|
sessionId: session2.sessionId,
|
|
116352
116411
|
machineId: session2.machineId,
|
|
116353
116412
|
workingDir: normalized
|
|
116354
116413
|
});
|
|
116355
|
-
console.log(`[${formatTimestamp()}] \uD83C\uDF33 File tree coordinator stopped: ${normalized}`);
|
|
116356
116414
|
successCount++;
|
|
116357
116415
|
} catch (err) {
|
|
116358
116416
|
logSubscriptionWarn(`File tree release failed for ${normalized}`, err);
|
|
@@ -116371,7 +116429,7 @@ async function processOnePendingFileTreeRequest(session2, coordinators, ensureCo
|
|
|
116371
116429
|
});
|
|
116372
116430
|
if (!lease?.leaseActive) {
|
|
116373
116431
|
await stopCoordinatorForWorkingDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized);
|
|
116374
|
-
await runOneShotFileTreeSync(session2, normalized);
|
|
116432
|
+
await runOneShotFileTreeSync(session2, normalized, coordinators, checkpointOutboxRegistry, deltaOutboxRegistry);
|
|
116375
116433
|
console.log(`[${formatTimestamp()}] \uD83C\uDF33 File tree ready: ${normalized} (${Date.now() - start3}ms, one-shot)`);
|
|
116376
116434
|
return;
|
|
116377
116435
|
}
|
|
@@ -116404,6 +116462,10 @@ async function processPendingFileTreeRequests(session2, coordinators, ensureCoor
|
|
|
116404
116462
|
try {
|
|
116405
116463
|
await processOnePendingFileTreeRequest(session2, coordinators, ensureCoordinator, normalized, force, checkpointOutboxRegistry, deltaOutboxRegistry);
|
|
116406
116464
|
} catch (err) {
|
|
116465
|
+
if (isFileTreeSyncDisabledError(err)) {
|
|
116466
|
+
await stopFileTreeSyncForDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized);
|
|
116467
|
+
return;
|
|
116468
|
+
}
|
|
116407
116469
|
logSubscriptionWarn(`File tree failed for ${normalized}`, err);
|
|
116408
116470
|
}
|
|
116409
116471
|
});
|
|
@@ -116420,16 +116482,40 @@ var startFileTreeSubscriptionEffect = () => exports_Effect.gen(function* () {
|
|
|
116420
116482
|
const session2 = yield* DaemonSessionService;
|
|
116421
116483
|
const coordinators = new Map;
|
|
116422
116484
|
const checkpointOutboxRegistry = createWorkspaceFileTreeCheckpointOutboxRegistry(session2.machineId, (normalized) => {
|
|
116423
|
-
const
|
|
116485
|
+
const onSyncDisabled = () => stopFileTreeSyncForDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized);
|
|
116486
|
+
const send = createWorkspaceFileTreeCheckpointSend(session2, normalized, {
|
|
116487
|
+
onSyncDisabled
|
|
116488
|
+
});
|
|
116424
116489
|
return async (state) => {
|
|
116425
116490
|
const result = await send(state);
|
|
116426
116491
|
console.log(`[${formatTimestamp()}] \uD83C\uDF33 File tree checkpoint: ${normalized} (${state.tree.entries.length} entries, revision ${result.revision})`);
|
|
116427
116492
|
return result;
|
|
116428
116493
|
};
|
|
116429
116494
|
}, {
|
|
116430
|
-
onError: (normalized, error51) =>
|
|
116495
|
+
onError: (normalized, error51) => {
|
|
116496
|
+
if (isFileTreeSyncDisabledError(error51)) {
|
|
116497
|
+
stopFileTreeSyncForDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized).catch(() => {
|
|
116498
|
+
return;
|
|
116499
|
+
});
|
|
116500
|
+
return;
|
|
116501
|
+
}
|
|
116502
|
+
logSubscriptionWarn(`File tree checkpoint outbox failed for ${normalized}`, error51);
|
|
116503
|
+
}
|
|
116504
|
+
});
|
|
116505
|
+
const deltaOutboxRegistry = createWorkspaceFileTreeDeltaOutboxRegistry(session2.machineId, (normalized) => {
|
|
116506
|
+
const onSyncDisabled = () => stopFileTreeSyncForDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized);
|
|
116507
|
+
return createWorkspaceFileTreeDeltaSend(session2, normalized, { onSyncDisabled });
|
|
116508
|
+
}, {
|
|
116509
|
+
onError: (normalized, error51) => {
|
|
116510
|
+
if (isFileTreeSyncDisabledError(error51)) {
|
|
116511
|
+
stopFileTreeSyncForDir(coordinators, checkpointOutboxRegistry, deltaOutboxRegistry, normalized).catch(() => {
|
|
116512
|
+
return;
|
|
116513
|
+
});
|
|
116514
|
+
return;
|
|
116515
|
+
}
|
|
116516
|
+
logSubscriptionWarn(`File tree delta outbox failed for ${normalized}`, error51);
|
|
116517
|
+
}
|
|
116431
116518
|
});
|
|
116432
|
-
const deltaOutboxRegistry = createWorkspaceFileTreeDeltaOutboxRegistry(session2.machineId, (normalized) => createWorkspaceFileTreeDeltaSend(session2, normalized));
|
|
116433
116519
|
const ensureCoordinator = (workingDir, forceReconcile) => {
|
|
116434
116520
|
const normalized = normalizeWorkingDirForLookup(workingDir);
|
|
116435
116521
|
let coordinatorPromise = coordinators.get(normalized);
|
|
@@ -117699,14 +117785,47 @@ var init_task_delivery_processor = __esm(() => {
|
|
|
117699
117785
|
init_task_delivery_logic();
|
|
117700
117786
|
});
|
|
117701
117787
|
|
|
117788
|
+
// src/daemon/infrastructure/agent-operational/operational-signal-contract.ts
|
|
117789
|
+
function asChatroomId(chatroomId) {
|
|
117790
|
+
return chatroomId;
|
|
117791
|
+
}
|
|
117792
|
+
function buildSubscribeMachineOperationalSignalsSinceArgs(input) {
|
|
117793
|
+
return {
|
|
117794
|
+
sessionId: input.sessionId,
|
|
117795
|
+
machineId: input.machineId,
|
|
117796
|
+
chatroomId: asChatroomId(input.chatroomId),
|
|
117797
|
+
afterKey: input.afterKey,
|
|
117798
|
+
...input.limit === undefined ? {} : { limit: input.limit }
|
|
117799
|
+
};
|
|
117800
|
+
}
|
|
117801
|
+
function buildListOperationalStatusForMachineSignalRangeArgs(input) {
|
|
117802
|
+
return {
|
|
117803
|
+
sessionId: input.sessionId,
|
|
117804
|
+
machineId: input.machineId,
|
|
117805
|
+
chatroomId: asChatroomId(input.chatroomId),
|
|
117806
|
+
afterSignalKey: input.afterSignalKey,
|
|
117807
|
+
throughSignalKey: input.throughSignalKey,
|
|
117808
|
+
...input.limit === undefined ? {} : { limit: input.limit }
|
|
117809
|
+
};
|
|
117810
|
+
}
|
|
117811
|
+
function buildAckMachineOperationalSignalsArgs(input) {
|
|
117812
|
+
return {
|
|
117813
|
+
sessionId: input.sessionId,
|
|
117814
|
+
machineId: input.machineId,
|
|
117815
|
+
chatroomId: asChatroomId(input.chatroomId),
|
|
117816
|
+
throughSignalKey: input.throughSignalKey
|
|
117817
|
+
};
|
|
117818
|
+
}
|
|
117819
|
+
|
|
117702
117820
|
// src/daemon/infrastructure/agent-operational/ack-machine-operational-signals.ts
|
|
117703
|
-
async function ackMachineOperationalSignals(sessionDeps, machineId, throughSignalKey) {
|
|
117821
|
+
async function ackMachineOperationalSignals(sessionDeps, machineId, chatroomId, throughSignalKey) {
|
|
117704
117822
|
while (true) {
|
|
117705
|
-
const result = await sessionDeps.backend.mutation(api.machines.ackMachineOperationalSignals, {
|
|
117823
|
+
const result = await sessionDeps.backend.mutation(api.machines.ackMachineOperationalSignals, buildAckMachineOperationalSignalsArgs({
|
|
117706
117824
|
sessionId: sessionDeps.sessionId,
|
|
117707
117825
|
machineId,
|
|
117826
|
+
chatroomId,
|
|
117708
117827
|
throughSignalKey
|
|
117709
|
-
});
|
|
117828
|
+
}));
|
|
117710
117829
|
if (!result.hasMore)
|
|
117711
117830
|
return;
|
|
117712
117831
|
if (result.deletedCount === 0) {
|
|
@@ -117789,12 +117908,13 @@ function waitForOperationalSignalPage(options, afterSignalKey) {
|
|
|
117789
117908
|
settle2(() => reject(error51));
|
|
117790
117909
|
return;
|
|
117791
117910
|
}
|
|
117792
|
-
unsubscribe = options.client.onUpdate(api.machines.subscribeMachineOperationalSignalsSince, {
|
|
117911
|
+
unsubscribe = options.client.onUpdate(api.machines.subscribeMachineOperationalSignalsSince, buildSubscribeMachineOperationalSignalsSinceArgs({
|
|
117793
117912
|
sessionId: options.sessionId,
|
|
117794
117913
|
machineId: options.machineId,
|
|
117914
|
+
chatroomId: options.chatroomId,
|
|
117795
117915
|
afterKey: afterSignalKey,
|
|
117796
117916
|
limit: options.signalPageLimit ?? DEFAULT_SIGNAL_PAGE_LIMIT
|
|
117797
|
-
}, (result) => {
|
|
117917
|
+
}), (result) => {
|
|
117798
117918
|
if (!result || typeof result !== "object")
|
|
117799
117919
|
return;
|
|
117800
117920
|
const page = result;
|
|
@@ -117826,13 +117946,14 @@ async function fetchRowsForSignalPage(options, page) {
|
|
|
117826
117946
|
let afterSignalKey = page.afterSignalKey;
|
|
117827
117947
|
while (true) {
|
|
117828
117948
|
throwIfAborted(options.signal);
|
|
117829
|
-
const result = await options.client.query(api.machines.listOperationalStatusForMachineSignalRange, {
|
|
117949
|
+
const result = await options.client.query(api.machines.listOperationalStatusForMachineSignalRange, buildListOperationalStatusForMachineSignalRangeArgs({
|
|
117830
117950
|
sessionId: options.sessionId,
|
|
117831
117951
|
machineId: options.machineId,
|
|
117952
|
+
chatroomId: options.chatroomId,
|
|
117832
117953
|
afterSignalKey,
|
|
117833
117954
|
throughSignalKey: page.highSignalKey,
|
|
117834
117955
|
limit: options.operationalPageLimit ?? DEFAULT_OPERATIONAL_PAGE_LIMIT
|
|
117835
|
-
});
|
|
117956
|
+
}));
|
|
117836
117957
|
rows.push(...result.rows);
|
|
117837
117958
|
removed.push(...result.removed);
|
|
117838
117959
|
if (!result.hasMore || !result.nextSignalKey)
|
|
@@ -117845,6 +117966,7 @@ async function runOperationalInbox(options, onUpdate) {
|
|
|
117845
117966
|
for await (const page of createOperationalSignalIterator(options)) {
|
|
117846
117967
|
const hydrated = await fetchRowsForSignalPage(options, page);
|
|
117847
117968
|
await onUpdate({
|
|
117969
|
+
chatroomId: options.chatroomId,
|
|
117848
117970
|
signals: page.items,
|
|
117849
117971
|
rows: hydrated.rows,
|
|
117850
117972
|
removed: hydrated.removed,
|
|
@@ -118035,6 +118157,30 @@ var init_task_inbox_delivery = __esm(() => {
|
|
|
118035
118157
|
init_enrich_snapshot_with_operational();
|
|
118036
118158
|
});
|
|
118037
118159
|
|
|
118160
|
+
// src/daemon/infrastructure/inbox/task-signal-contract.ts
|
|
118161
|
+
function asChatroomId2(chatroomId) {
|
|
118162
|
+
return chatroomId;
|
|
118163
|
+
}
|
|
118164
|
+
function buildSubscribeTaskStatusSignalsSinceArgs(input) {
|
|
118165
|
+
return {
|
|
118166
|
+
sessionId: input.sessionId,
|
|
118167
|
+
machineId: input.machineId,
|
|
118168
|
+
chatroomId: asChatroomId2(input.chatroomId),
|
|
118169
|
+
afterKey: input.afterKey,
|
|
118170
|
+
...input.limit === undefined ? {} : { limit: input.limit }
|
|
118171
|
+
};
|
|
118172
|
+
}
|
|
118173
|
+
function buildListTasksForMachineSignalRangeArgs(input) {
|
|
118174
|
+
return {
|
|
118175
|
+
sessionId: input.sessionId,
|
|
118176
|
+
machineId: input.machineId,
|
|
118177
|
+
chatroomId: asChatroomId2(input.chatroomId),
|
|
118178
|
+
afterSignalKey: input.afterSignalKey,
|
|
118179
|
+
throughSignalKey: input.throughSignalKey,
|
|
118180
|
+
...input.limit === undefined ? {} : { limit: input.limit }
|
|
118181
|
+
};
|
|
118182
|
+
}
|
|
118183
|
+
|
|
118038
118184
|
// src/daemon/infrastructure/inbox/task.ts
|
|
118039
118185
|
function taskSignalCursorAt(timestamp) {
|
|
118040
118186
|
return `${String(Math.max(0, Math.floor(timestamp))).padStart(16, "0")}:`;
|
|
@@ -118074,12 +118220,13 @@ function waitForTaskSignalPage(options, afterSignalKey) {
|
|
|
118074
118220
|
settle2(() => reject(error51));
|
|
118075
118221
|
return;
|
|
118076
118222
|
}
|
|
118077
|
-
unsubscribe = options.client.onUpdate(api.messageList.subscribeTaskStatusSignalsSince, {
|
|
118223
|
+
unsubscribe = options.client.onUpdate(api.messageList.subscribeTaskStatusSignalsSince, buildSubscribeTaskStatusSignalsSinceArgs({
|
|
118078
118224
|
sessionId: options.sessionId,
|
|
118079
118225
|
machineId: options.machineId,
|
|
118226
|
+
chatroomId: options.chatroomId,
|
|
118080
118227
|
afterKey: afterSignalKey,
|
|
118081
118228
|
limit: options.signalPageLimit ?? DEFAULT_SIGNAL_PAGE_LIMIT2
|
|
118082
|
-
}, (result) => {
|
|
118229
|
+
}), (result) => {
|
|
118083
118230
|
if (!result || typeof result !== "object")
|
|
118084
118231
|
return;
|
|
118085
118232
|
const page = result;
|
|
@@ -118110,13 +118257,14 @@ async function fetchSnapshotsForSignalPage(options, page) {
|
|
|
118110
118257
|
let afterSignalKey = page.afterSignalKey;
|
|
118111
118258
|
while (true) {
|
|
118112
118259
|
throwIfAborted2(options.signal);
|
|
118113
|
-
const result = await options.client.query(api.tasks.listTasksForMachineSignalRange, {
|
|
118260
|
+
const result = await options.client.query(api.tasks.listTasksForMachineSignalRange, buildListTasksForMachineSignalRangeArgs({
|
|
118114
118261
|
sessionId: options.sessionId,
|
|
118115
118262
|
machineId: options.machineId,
|
|
118263
|
+
chatroomId: options.chatroomId,
|
|
118116
118264
|
afterSignalKey,
|
|
118117
118265
|
throughSignalKey: page.highSignalKey,
|
|
118118
118266
|
limit: options.taskPageLimit ?? DEFAULT_TASK_PAGE_LIMIT
|
|
118119
|
-
});
|
|
118267
|
+
}));
|
|
118120
118268
|
snapshots.push(...result.snapshots);
|
|
118121
118269
|
if (!result.hasMore || !result.nextSignalKey)
|
|
118122
118270
|
break;
|
|
@@ -118152,6 +118300,10 @@ async function bootstrapMachineAssignedTaskSnapshots(deps) {
|
|
|
118152
118300
|
});
|
|
118153
118301
|
const tasks = await fetchMachineAssignedTaskSnapshots(deps.sessionDeps, deps.machineId);
|
|
118154
118302
|
deps.taskSnapshotState?.replace(tasks);
|
|
118303
|
+
const chatroomIds = [...new Set(tasks.map((task) => task.chatroomId))];
|
|
118304
|
+
if (chatroomIds.length > 0) {
|
|
118305
|
+
await deps.onDiscoveredChatrooms?.(chatroomIds);
|
|
118306
|
+
}
|
|
118155
118307
|
if (!tasks.length)
|
|
118156
118308
|
return;
|
|
118157
118309
|
await processTasksUpdate(deps.runtime, deps.effectContext, deps.cooldown, deps.agentMgr, deps.sessionDeps, deps.machineId, "bootstrap", { snapshots: enrichSnapshotsWithOperational(tasks) });
|
|
@@ -118159,6 +118311,9 @@ async function bootstrapMachineAssignedTaskSnapshots(deps) {
|
|
|
118159
118311
|
function isAbortError2(error51) {
|
|
118160
118312
|
return error51 instanceof Error && error51.name === "AbortError";
|
|
118161
118313
|
}
|
|
118314
|
+
function roomScopeKey(machineId, chatroomId) {
|
|
118315
|
+
return JSON.stringify([machineId, chatroomId]);
|
|
118316
|
+
}
|
|
118162
118317
|
async function runInboxLoopWithRestart(options, onUpdate, isStopped) {
|
|
118163
118318
|
let backoffMs = INBOX_RESTART_INITIAL_MS;
|
|
118164
118319
|
while (!isStopped()) {
|
|
@@ -118183,7 +118338,7 @@ async function runOperationalInboxLoopWithRestart(options, onUpdate, isStopped)
|
|
|
118183
118338
|
} catch (error51) {
|
|
118184
118339
|
if (isStopped() || isAbortError2(error51))
|
|
118185
118340
|
return;
|
|
118186
|
-
console.warn(`[OperationalInbox] loop error, restarting in ${backoffMs}ms:`, error51);
|
|
118341
|
+
console.warn(`[OperationalInbox room=${options.chatroomId}] loop error, restarting in ${backoffMs}ms:`, error51);
|
|
118187
118342
|
await new Promise((resolve8) => setTimeout(resolve8, backoffMs));
|
|
118188
118343
|
backoffMs = Math.min(backoffMs * 2, INBOX_RESTART_MAX_MS);
|
|
118189
118344
|
}
|
|
@@ -118208,23 +118363,15 @@ var NATIVE_DELIVERY_RECONCILE_MS = 1e4, INBOX_RESTART_INITIAL_MS = 1000, INBOX_R
|
|
|
118208
118363
|
query: (fn2, args2) => session2.backend.query(fn2, args2)
|
|
118209
118364
|
}
|
|
118210
118365
|
};
|
|
118211
|
-
console.log(`[${formatTimestamp()}] \uD83D\uDCEC Starting task-inbox (
|
|
118366
|
+
console.log(`[${formatTimestamp()}] \uD83D\uDCEC Starting task-inbox (chatroom-scoped operational signals)`);
|
|
118212
118367
|
const inboxStore = createInboxStateStore(resolveInboxDbPath(session2.machineId));
|
|
118213
|
-
const persisted = inboxStore.get({
|
|
118214
|
-
inboxType: "task",
|
|
118215
|
-
scopeKey: session2.machineId
|
|
118216
|
-
});
|
|
118217
|
-
const persistedOperational = inboxStore.get({
|
|
118218
|
-
inboxType: "operational",
|
|
118219
|
-
scopeKey: session2.machineId
|
|
118220
|
-
});
|
|
118221
118368
|
const serviceStartedAt = Date.now();
|
|
118222
|
-
const persistedOperationalKey = persistedOperational?.state.afterSignalKey;
|
|
118223
|
-
const initialOperationalKey = persistedOperationalKey ?? operationalSignalCursorAt(serviceStartedAt);
|
|
118224
118369
|
const abort = new AbortController;
|
|
118225
118370
|
let stopped = false;
|
|
118226
118371
|
const taskSnapshotState = new MachineTaskSnapshotState;
|
|
118227
118372
|
const agentOperationalReadModel = new AgentOperationalReadModel;
|
|
118373
|
+
const knownRoomIds = new Set;
|
|
118374
|
+
const roomWatchers = new Map;
|
|
118228
118375
|
registerNativeDeliverySession({
|
|
118229
118376
|
runtime: runtime4,
|
|
118230
118377
|
effectContext: effectContext2,
|
|
@@ -118236,51 +118383,141 @@ var NATIVE_DELIVERY_RECONCILE_MS = 1e4, INBOX_RESTART_INITIAL_MS = 1000, INBOX_R
|
|
|
118236
118383
|
lifecycleOutbox
|
|
118237
118384
|
});
|
|
118238
118385
|
const cooldown = new RecoveryCooldown;
|
|
118239
|
-
let
|
|
118386
|
+
let inboxUpdatesInFlight = 0;
|
|
118240
118387
|
let reconcileInFlight = false;
|
|
118241
|
-
const inboxOptions = {
|
|
118242
|
-
client: wsClient2,
|
|
118243
|
-
sessionId: session2.sessionId,
|
|
118244
|
-
machineId: session2.machineId,
|
|
118245
|
-
serviceStartedAt,
|
|
118246
|
-
initialAfterSignalKey: persisted?.state.afterSignalKey,
|
|
118247
|
-
signal: abort.signal
|
|
118248
|
-
};
|
|
118249
|
-
const inboxHandler = async (update6) => {
|
|
118250
|
-
inboxUpdateInFlight = true;
|
|
118251
|
-
try {
|
|
118252
|
-
await handleTaskInboxUpdate(update6, {
|
|
118253
|
-
runtime: runtime4,
|
|
118254
|
-
effectContext: effectContext2,
|
|
118255
|
-
cooldown,
|
|
118256
|
-
agentMgr,
|
|
118257
|
-
sessionDeps,
|
|
118258
|
-
machineId: session2.machineId,
|
|
118259
|
-
taskSnapshotState
|
|
118260
|
-
});
|
|
118261
|
-
inboxStore.save({ inboxType: "task", scopeKey: session2.machineId }, { afterSignalKey: update6.throughSignalKey });
|
|
118262
|
-
} finally {
|
|
118263
|
-
inboxUpdateInFlight = false;
|
|
118264
|
-
}
|
|
118265
|
-
};
|
|
118266
118388
|
const bootstrapSucceeded = yield* exports_Effect.tryPromise(async () => {
|
|
118267
118389
|
const rows = await fetchMachineAgentOperationalStatus(sessionDeps, session2.machineId);
|
|
118268
118390
|
agentOperationalReadModel.replace(rows);
|
|
118391
|
+
for (const row of rows)
|
|
118392
|
+
knownRoomIds.add(row.chatroomId);
|
|
118269
118393
|
return true;
|
|
118270
118394
|
}).pipe(exports_Effect.catchAll((error51) => {
|
|
118271
118395
|
console.warn("[OperationalInbox] bootstrap failed:", error51);
|
|
118272
118396
|
return exports_Effect.succeed(false);
|
|
118273
118397
|
}));
|
|
118274
|
-
|
|
118275
|
-
|
|
118276
|
-
|
|
118398
|
+
const operationalHandler = async (update6) => {
|
|
118399
|
+
const chatroomId = update6.chatroomId;
|
|
118400
|
+
inboxUpdatesInFlight += 1;
|
|
118277
118401
|
try {
|
|
118278
|
-
|
|
118279
|
-
|
|
118280
|
-
|
|
118281
|
-
|
|
118402
|
+
const changed = agentOperationalReadModel.applySignalPage(update6.rows, update6.removed);
|
|
118403
|
+
const snapshots = changed.flatMap(({ chatroomId: roomId, role }) => taskSnapshotState.listForRole(roomId, role));
|
|
118404
|
+
if (snapshots.length > 0) {
|
|
118405
|
+
await processTasksUpdate(runtime4, effectContext2, cooldown, agentMgr, sessionDeps, session2.machineId, "operational-status", { snapshots: enrichSnapshotsWithOperational(snapshots) });
|
|
118406
|
+
}
|
|
118407
|
+
inboxStore.save({
|
|
118408
|
+
inboxType: "operational",
|
|
118409
|
+
scopeKey: roomScopeKey(session2.machineId, chatroomId)
|
|
118410
|
+
}, { afterSignalKey: update6.throughSignalKey });
|
|
118411
|
+
try {
|
|
118412
|
+
await ackMachineOperationalSignals(sessionDeps, session2.machineId, chatroomId, update6.throughSignalKey);
|
|
118413
|
+
} catch (error51) {
|
|
118414
|
+
console.warn(`[OperationalInbox room=${chatroomId}] signal cleanup failed:`, error51);
|
|
118415
|
+
}
|
|
118416
|
+
} finally {
|
|
118417
|
+
inboxUpdatesInFlight -= 1;
|
|
118282
118418
|
}
|
|
118283
|
-
}
|
|
118419
|
+
};
|
|
118420
|
+
const ensureRoomInboxes = (chatroomId) => {
|
|
118421
|
+
const existing = roomWatchers.get(chatroomId);
|
|
118422
|
+
if (existing)
|
|
118423
|
+
return existing.startPromise;
|
|
118424
|
+
const controller = new AbortController;
|
|
118425
|
+
const entry = {
|
|
118426
|
+
controller,
|
|
118427
|
+
startPromise: Promise.resolve()
|
|
118428
|
+
};
|
|
118429
|
+
roomWatchers.set(chatroomId, entry);
|
|
118430
|
+
entry.startPromise = (async () => {
|
|
118431
|
+
if (!knownRoomIds.has(chatroomId)) {
|
|
118432
|
+
try {
|
|
118433
|
+
const current = await fetchMachineAgentOperationalStatus(sessionDeps, session2.machineId);
|
|
118434
|
+
agentOperationalReadModel.replace(current);
|
|
118435
|
+
for (const row of current)
|
|
118436
|
+
knownRoomIds.add(row.chatroomId);
|
|
118437
|
+
} catch (error51) {
|
|
118438
|
+
console.warn(`[OperationalInbox room=${chatroomId}] operational hydration failed:`, error51);
|
|
118439
|
+
}
|
|
118440
|
+
}
|
|
118441
|
+
const operationalRoomKey = {
|
|
118442
|
+
inboxType: "operational",
|
|
118443
|
+
scopeKey: roomScopeKey(session2.machineId, chatroomId)
|
|
118444
|
+
};
|
|
118445
|
+
const persistedOperationalRoom = inboxStore.get(operationalRoomKey);
|
|
118446
|
+
let operationalCursor;
|
|
118447
|
+
if (persistedOperationalRoom) {
|
|
118448
|
+
operationalCursor = persistedOperationalRoom.state.afterSignalKey;
|
|
118449
|
+
ackMachineOperationalSignals(sessionDeps, session2.machineId, chatroomId, operationalCursor).catch((error51) => console.warn(`[OperationalInbox room=${chatroomId}] startup signal cleanup failed:`, error51));
|
|
118450
|
+
} else if (bootstrapSucceeded) {
|
|
118451
|
+
operationalCursor = operationalSignalCursorAt(serviceStartedAt);
|
|
118452
|
+
try {
|
|
118453
|
+
inboxStore.save(operationalRoomKey, { afterSignalKey: operationalCursor });
|
|
118454
|
+
ackMachineOperationalSignals(sessionDeps, session2.machineId, chatroomId, operationalCursor).catch((error51) => console.warn(`[OperationalInbox room=${chatroomId}] startup signal cleanup failed:`, error51));
|
|
118455
|
+
} catch (error51) {
|
|
118456
|
+
console.warn(`[OperationalInbox room=${chatroomId}] failed to persist bootstrap baseline:`, error51);
|
|
118457
|
+
}
|
|
118458
|
+
} else {
|
|
118459
|
+
operationalCursor = operationalSignalCursorAt(serviceStartedAt);
|
|
118460
|
+
}
|
|
118461
|
+
runOperationalInboxLoopWithRestart({
|
|
118462
|
+
client: wsClient2,
|
|
118463
|
+
sessionId: session2.sessionId,
|
|
118464
|
+
machineId: session2.machineId,
|
|
118465
|
+
chatroomId,
|
|
118466
|
+
serviceStartedAt,
|
|
118467
|
+
initialAfterSignalKey: operationalCursor,
|
|
118468
|
+
signal: controller.signal
|
|
118469
|
+
}, operationalHandler, () => stopped);
|
|
118470
|
+
const taskRoomKey = {
|
|
118471
|
+
inboxType: "task",
|
|
118472
|
+
scopeKey: roomScopeKey(session2.machineId, chatroomId)
|
|
118473
|
+
};
|
|
118474
|
+
const persistedTaskRoom = inboxStore.get(taskRoomKey);
|
|
118475
|
+
let taskCursor;
|
|
118476
|
+
if (persistedTaskRoom) {
|
|
118477
|
+
taskCursor = persistedTaskRoom.state.afterSignalKey;
|
|
118478
|
+
} else if (bootstrapSucceeded) {
|
|
118479
|
+
taskCursor = taskSignalCursorAt(serviceStartedAt);
|
|
118480
|
+
try {
|
|
118481
|
+
inboxStore.save(taskRoomKey, { afterSignalKey: taskCursor });
|
|
118482
|
+
} catch (error51) {
|
|
118483
|
+
console.warn(`[TaskInbox room=${chatroomId}] failed to persist bootstrap baseline:`, error51);
|
|
118484
|
+
}
|
|
118485
|
+
} else {
|
|
118486
|
+
taskCursor = taskSignalCursorAt(serviceStartedAt);
|
|
118487
|
+
}
|
|
118488
|
+
const taskHandlerForRoom = async (update6) => {
|
|
118489
|
+
inboxUpdatesInFlight += 1;
|
|
118490
|
+
try {
|
|
118491
|
+
await handleTaskInboxUpdate(update6, {
|
|
118492
|
+
runtime: runtime4,
|
|
118493
|
+
effectContext: effectContext2,
|
|
118494
|
+
cooldown,
|
|
118495
|
+
agentMgr,
|
|
118496
|
+
sessionDeps,
|
|
118497
|
+
machineId: session2.machineId,
|
|
118498
|
+
taskSnapshotState
|
|
118499
|
+
});
|
|
118500
|
+
inboxStore.save(taskRoomKey, { afterSignalKey: update6.throughSignalKey });
|
|
118501
|
+
} finally {
|
|
118502
|
+
inboxUpdatesInFlight -= 1;
|
|
118503
|
+
}
|
|
118504
|
+
};
|
|
118505
|
+
runInboxLoopWithRestart({
|
|
118506
|
+
client: wsClient2,
|
|
118507
|
+
sessionId: session2.sessionId,
|
|
118508
|
+
machineId: session2.machineId,
|
|
118509
|
+
chatroomId,
|
|
118510
|
+
serviceStartedAt,
|
|
118511
|
+
initialAfterSignalKey: taskCursor,
|
|
118512
|
+
signal: controller.signal
|
|
118513
|
+
}, taskHandlerForRoom, () => stopped);
|
|
118514
|
+
})();
|
|
118515
|
+
return entry.startPromise;
|
|
118516
|
+
};
|
|
118517
|
+
yield* exports_Effect.tryPromise(() => Promise.all([...knownRoomIds].map((chatroomId) => ensureRoomInboxes(chatroomId)))).pipe(exports_Effect.catchAll((error51) => {
|
|
118518
|
+
console.warn("[OperationalInbox] initial watcher start failed:", error51);
|
|
118519
|
+
return exports_Effect.void;
|
|
118520
|
+
}));
|
|
118284
118521
|
yield* exports_Effect.tryPromise(() => bootstrapMachineAssignedTaskSnapshots({
|
|
118285
118522
|
sessionDeps,
|
|
118286
118523
|
runtime: runtime4,
|
|
@@ -118288,53 +118525,42 @@ var NATIVE_DELIVERY_RECONCILE_MS = 1e4, INBOX_RESTART_INITIAL_MS = 1000, INBOX_R
|
|
|
118288
118525
|
cooldown,
|
|
118289
118526
|
agentMgr,
|
|
118290
118527
|
machineId: session2.machineId,
|
|
118291
|
-
taskSnapshotState
|
|
118528
|
+
taskSnapshotState,
|
|
118529
|
+
onDiscoveredChatrooms: async (chatroomIds) => {
|
|
118530
|
+
await Promise.all(chatroomIds.map((chatroomId) => ensureRoomInboxes(chatroomId)));
|
|
118531
|
+
}
|
|
118292
118532
|
})).pipe(exports_Effect.catchAll((error51) => {
|
|
118293
118533
|
console.warn("[TaskInbox] bootstrap failed:", error51);
|
|
118294
118534
|
return exports_Effect.void;
|
|
118295
118535
|
}));
|
|
118296
|
-
const operationalInboxOptions = {
|
|
118297
|
-
client: wsClient2,
|
|
118298
|
-
sessionId: session2.sessionId,
|
|
118299
|
-
machineId: session2.machineId,
|
|
118300
|
-
serviceStartedAt,
|
|
118301
|
-
initialAfterSignalKey: initialOperationalKey,
|
|
118302
|
-
signal: abort.signal
|
|
118303
|
-
};
|
|
118304
|
-
const operationalInboxHandler = async (update6) => {
|
|
118305
|
-
inboxUpdateInFlight = true;
|
|
118306
|
-
try {
|
|
118307
|
-
const changed = agentOperationalReadModel.applySignalPage(update6.rows, update6.removed);
|
|
118308
|
-
const snapshots = changed.flatMap(({ chatroomId, role }) => taskSnapshotState.listForRole(chatroomId, role));
|
|
118309
|
-
if (snapshots.length > 0) {
|
|
118310
|
-
await processTasksUpdate(runtime4, effectContext2, cooldown, agentMgr, sessionDeps, session2.machineId, "operational-status", { snapshots: enrichSnapshotsWithOperational(snapshots) });
|
|
118311
|
-
}
|
|
118312
|
-
inboxStore.save({ inboxType: "operational", scopeKey: session2.machineId }, { afterSignalKey: update6.throughSignalKey });
|
|
118313
|
-
try {
|
|
118314
|
-
await ackMachineOperationalSignals(sessionDeps, session2.machineId, update6.throughSignalKey);
|
|
118315
|
-
} catch (error51) {
|
|
118316
|
-
console.warn("[OperationalInbox] signal cleanup failed:", error51);
|
|
118317
|
-
}
|
|
118318
|
-
} finally {
|
|
118319
|
-
inboxUpdateInFlight = false;
|
|
118320
|
-
}
|
|
118321
|
-
};
|
|
118322
118536
|
const reconcileTimer = setInterval(() => {
|
|
118323
|
-
if (stopped ||
|
|
118537
|
+
if (stopped || inboxUpdatesInFlight > 0 || reconcileInFlight)
|
|
118324
118538
|
return;
|
|
118325
118539
|
reconcileInFlight = true;
|
|
118540
|
+
(async () => {
|
|
118541
|
+
try {
|
|
118542
|
+
const current = await fetchMachineAgentOperationalStatus(sessionDeps, session2.machineId);
|
|
118543
|
+
agentOperationalReadModel.replace(current);
|
|
118544
|
+
for (const row of current)
|
|
118545
|
+
knownRoomIds.add(row.chatroomId);
|
|
118546
|
+
await Promise.all([...new Set(current.map((row) => row.chatroomId))].map((chatroomId) => ensureRoomInboxes(chatroomId)));
|
|
118547
|
+
} catch (error51) {
|
|
118548
|
+
console.warn("[TaskInbox] room membership refresh failed:", error51);
|
|
118549
|
+
}
|
|
118550
|
+
})();
|
|
118326
118551
|
processTasksUpdate(runtime4, effectContext2, cooldown, agentMgr, sessionDeps, session2.machineId, "periodic-reconcile", { snapshots: enrichSnapshotsWithOperational(taskSnapshotState.listAll()) }).catch((error51) => {
|
|
118327
118552
|
console.warn("[TaskInbox] local delivery reconciliation failed:", error51);
|
|
118328
118553
|
}).finally(() => {
|
|
118329
118554
|
reconcileInFlight = false;
|
|
118330
118555
|
});
|
|
118331
118556
|
}, NATIVE_DELIVERY_RECONCILE_MS);
|
|
118332
|
-
runInboxLoopWithRestart(inboxOptions, inboxHandler, () => stopped);
|
|
118333
|
-
runOperationalInboxLoopWithRestart(operationalInboxOptions, operationalInboxHandler, () => stopped);
|
|
118334
118557
|
return {
|
|
118335
118558
|
stop() {
|
|
118336
118559
|
stopped = true;
|
|
118337
118560
|
abort.abort();
|
|
118561
|
+
for (const watcher of roomWatchers.values()) {
|
|
118562
|
+
watcher.controller.abort();
|
|
118563
|
+
}
|
|
118338
118564
|
clearInterval(reconcileTimer);
|
|
118339
118565
|
unregisterNativeDeliverySession();
|
|
118340
118566
|
inboxStore.close();
|
|
@@ -119502,7 +119728,10 @@ var init_command_run = __esm(() => {
|
|
|
119502
119728
|
// src/daemon/infrastructure/convex/subscribers/enhancer-job.ts
|
|
119503
119729
|
function startEnhancerJobSubscriber2(deps, onEvent) {
|
|
119504
119730
|
const seen = new Set;
|
|
119505
|
-
const
|
|
119731
|
+
const watchers = new Map;
|
|
119732
|
+
let stopped = false;
|
|
119733
|
+
let refreshInFlight = false;
|
|
119734
|
+
const onPendingJobs = (jobs) => {
|
|
119506
119735
|
if (!jobs?.length)
|
|
119507
119736
|
return;
|
|
119508
119737
|
for (const job of jobs) {
|
|
@@ -119513,13 +119742,57 @@ function startEnhancerJobSubscriber2(deps, onEvent) {
|
|
|
119513
119742
|
seen.add(job.jobId);
|
|
119514
119743
|
onEvent({ type: "enhancer.job-assigned", jobId: job.jobId });
|
|
119515
119744
|
}
|
|
119516
|
-
}
|
|
119745
|
+
};
|
|
119746
|
+
const onError3 = (err) => {
|
|
119517
119747
|
console.warn(`[daemon] enhancer-job subscriber error: ${err instanceof Error ? err.message : String(err)}`);
|
|
119518
|
-
}
|
|
119748
|
+
};
|
|
119749
|
+
const watchChatroom = (chatroomId) => {
|
|
119750
|
+
if (watchers.has(chatroomId) || stopped)
|
|
119751
|
+
return;
|
|
119752
|
+
const unsub = deps.wsClient.onUpdate(api.daemon.enhancer.index.pendingForChatroom, {
|
|
119753
|
+
sessionId: deps.sessionId,
|
|
119754
|
+
machineId: deps.machineId,
|
|
119755
|
+
chatroomId
|
|
119756
|
+
}, onPendingJobs, onError3);
|
|
119757
|
+
watchers.set(chatroomId, unsub);
|
|
119758
|
+
};
|
|
119759
|
+
const refreshChatrooms = async () => {
|
|
119760
|
+
if (refreshInFlight)
|
|
119761
|
+
return;
|
|
119762
|
+
refreshInFlight = true;
|
|
119763
|
+
try {
|
|
119764
|
+
const workspaces = await deps.wsClient.query(api.workspaces.listWorkspacesForMachine, {
|
|
119765
|
+
sessionId: deps.sessionId,
|
|
119766
|
+
machineId: deps.machineId
|
|
119767
|
+
});
|
|
119768
|
+
if (stopped)
|
|
119769
|
+
return;
|
|
119770
|
+
const roomIds = [
|
|
119771
|
+
...new Set((workspaces ?? []).map((ws) => ws.chatroomId))
|
|
119772
|
+
];
|
|
119773
|
+
for (const [roomId, unsub] of watchers) {
|
|
119774
|
+
if (!roomIds.includes(roomId)) {
|
|
119775
|
+
unsub();
|
|
119776
|
+
watchers.delete(roomId);
|
|
119777
|
+
}
|
|
119778
|
+
}
|
|
119779
|
+
for (const roomId of roomIds)
|
|
119780
|
+
watchChatroom(roomId);
|
|
119781
|
+
} catch (error51) {
|
|
119782
|
+
console.warn(`[daemon] enhancer-job room refresh failed: ${error51 instanceof Error ? error51.message : String(error51)}`);
|
|
119783
|
+
} finally {
|
|
119784
|
+
refreshInFlight = false;
|
|
119785
|
+
}
|
|
119786
|
+
};
|
|
119787
|
+
refreshChatrooms();
|
|
119519
119788
|
return {
|
|
119520
119789
|
async stop() {
|
|
119521
|
-
|
|
119522
|
-
|
|
119790
|
+
stopped = true;
|
|
119791
|
+
for (const unsub of watchers.values())
|
|
119792
|
+
unsub();
|
|
119793
|
+
watchers.clear();
|
|
119794
|
+
},
|
|
119795
|
+
refreshChatrooms
|
|
119523
119796
|
};
|
|
119524
119797
|
}
|
|
119525
119798
|
var init_enhancer_job = __esm(() => {
|
|
@@ -119677,7 +119950,11 @@ function requestId2(req) {
|
|
|
119677
119950
|
}
|
|
119678
119951
|
function startGitRequestSubscriber(deps, onEvent) {
|
|
119679
119952
|
const seen = new Set;
|
|
119680
|
-
const
|
|
119953
|
+
const watchers = new Map;
|
|
119954
|
+
let stopped = false;
|
|
119955
|
+
let refreshInFlight = false;
|
|
119956
|
+
let queued = false;
|
|
119957
|
+
const onPendingRequests = (requests) => {
|
|
119681
119958
|
if (!requests?.length)
|
|
119682
119959
|
return;
|
|
119683
119960
|
for (const req of requests) {
|
|
@@ -119689,13 +119966,58 @@ function startGitRequestSubscriber(deps, onEvent) {
|
|
|
119689
119966
|
seen.add(id3);
|
|
119690
119967
|
onEvent({ type: "git.request", requestId: id3 });
|
|
119691
119968
|
}
|
|
119692
|
-
}
|
|
119969
|
+
};
|
|
119970
|
+
const onError3 = (err) => {
|
|
119693
119971
|
console.warn(`[daemon] git-request subscriber error: ${err instanceof Error ? err.message : String(err)}`);
|
|
119694
|
-
}
|
|
119972
|
+
};
|
|
119973
|
+
const watchWorkspace = (workingDir) => {
|
|
119974
|
+
if (watchers.has(workingDir) || stopped)
|
|
119975
|
+
return;
|
|
119976
|
+
const unsub = deps.wsClient.onUpdate(api.workspaces.getPendingRequestsForWorkspace, { sessionId: deps.sessionId, machineId: deps.machineId, workingDir }, onPendingRequests, onError3);
|
|
119977
|
+
watchers.set(workingDir, unsub);
|
|
119978
|
+
};
|
|
119979
|
+
const refreshWorkspaces = async () => {
|
|
119980
|
+
if (refreshInFlight) {
|
|
119981
|
+
queued = true;
|
|
119982
|
+
return;
|
|
119983
|
+
}
|
|
119984
|
+
refreshInFlight = true;
|
|
119985
|
+
try {
|
|
119986
|
+
do {
|
|
119987
|
+
queued = false;
|
|
119988
|
+
const workspaces = await deps.wsClient.query(api.workspaces.listWorkspacesForMachine, {
|
|
119989
|
+
sessionId: deps.sessionId,
|
|
119990
|
+
machineId: deps.machineId
|
|
119991
|
+
});
|
|
119992
|
+
if (stopped)
|
|
119993
|
+
return;
|
|
119994
|
+
const workingDirs = [
|
|
119995
|
+
...new Set((workspaces ?? []).map((ws) => ws.workingDir))
|
|
119996
|
+
];
|
|
119997
|
+
for (const [workingDir, unsub] of watchers) {
|
|
119998
|
+
if (!workingDirs.includes(workingDir)) {
|
|
119999
|
+
unsub();
|
|
120000
|
+
watchers.delete(workingDir);
|
|
120001
|
+
}
|
|
120002
|
+
}
|
|
120003
|
+
for (const workingDir of workingDirs)
|
|
120004
|
+
watchWorkspace(workingDir);
|
|
120005
|
+
} while (queued && !stopped);
|
|
120006
|
+
} catch (error51) {
|
|
120007
|
+
console.warn(`[daemon] git-request workspace refresh failed: ${error51 instanceof Error ? error51.message : String(error51)}`);
|
|
120008
|
+
} finally {
|
|
120009
|
+
refreshInFlight = false;
|
|
120010
|
+
}
|
|
120011
|
+
};
|
|
120012
|
+
refreshWorkspaces();
|
|
119695
120013
|
return {
|
|
119696
120014
|
async stop() {
|
|
119697
|
-
|
|
119698
|
-
|
|
120015
|
+
stopped = true;
|
|
120016
|
+
for (const unsub of watchers.values())
|
|
120017
|
+
unsub();
|
|
120018
|
+
watchers.clear();
|
|
120019
|
+
},
|
|
120020
|
+
refreshWorkspaces
|
|
119699
120021
|
};
|
|
119700
120022
|
}
|
|
119701
120023
|
var init_git_request = __esm(() => {
|
|
@@ -119746,7 +120068,13 @@ function startAllSubscribers(deps) {
|
|
|
119746
120068
|
const onEvent = (event) => {
|
|
119747
120069
|
routeInboundEvent(deps.router, event);
|
|
119748
120070
|
};
|
|
120071
|
+
const enhancerJob = startEnhancerJobSubscriber2(deps, onEvent);
|
|
120072
|
+
const gitRequest = startGitRequestSubscriber(deps, onEvent);
|
|
119749
120073
|
const machineCommands = startMachineCommandInboxSubscriber(deps, async (claimed) => {
|
|
120074
|
+
if (claimed.type === "daemon.workspaceListChanged") {
|
|
120075
|
+
enhancerJob.refreshChatrooms();
|
|
120076
|
+
gitRequest.refreshWorkspaces();
|
|
120077
|
+
}
|
|
119750
120078
|
await dispatchCommandInboundEvent({
|
|
119751
120079
|
type: "command.received",
|
|
119752
120080
|
commandId: claimed.commandId,
|
|
@@ -119754,14 +120082,12 @@ function startAllSubscribers(deps) {
|
|
|
119754
120082
|
});
|
|
119755
120083
|
});
|
|
119756
120084
|
const commandRun = startCommandRunSubscriber(deps, onEvent);
|
|
119757
|
-
const gitRequest = startGitRequestSubscriber(deps, onEvent);
|
|
119758
120085
|
const fileTree = startFileTreeRequestSubscriber(deps, onEvent);
|
|
119759
120086
|
const fileTreeRelease = startFileTreeReleaseRequestSubscriber(deps, onEvent);
|
|
119760
120087
|
const fileContent = startFileContentRequestSubscriber(deps, onEvent);
|
|
119761
120088
|
const fileWrite = startFileWriteRequestSubscriber(deps, onEvent);
|
|
119762
120089
|
const agenticQuerySession = startAgenticQuerySessionSubscriber(deps, onEvent);
|
|
119763
120090
|
const agenticQueryPrompt = startAgenticQueryPromptSubscriber(deps, onEvent);
|
|
119764
|
-
const enhancerJob = startEnhancerJobSubscriber2(deps, onEvent);
|
|
119765
120091
|
return {
|
|
119766
120092
|
async stopAll() {
|
|
119767
120093
|
await Promise.all([
|
|
@@ -135552,4 +135878,4 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
|
|
|
135552
135878
|
});
|
|
135553
135879
|
program2.parse();
|
|
135554
135880
|
|
|
135555
|
-
//# debugId=
|
|
135881
|
+
//# debugId=3C68FDC314358C7A64756E2164756E21
|