@alook/daemon 0.1.76 → 0.1.77
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/README.md +6 -0
- package/dist/cli/index.js +1305 -965
- package/dist/index.js +593 -224
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -24607,6 +24607,8 @@ class SettledUsageProjector {
|
|
|
24607
24607
|
// agent-driver/dist/adapters/agy/acp-lane.js
|
|
24608
24608
|
var ACP_PROTOCOL_VERSION = 1;
|
|
24609
24609
|
var HANDSHAKE_TIMEOUT_MS = 15000;
|
|
24610
|
+
var POST_TURN_ACTIVITY_SETTLE_MS = 5000;
|
|
24611
|
+
var SESSION_PROGRESS_HEARTBEAT_MIN_INTERVAL_MS = 1000;
|
|
24610
24612
|
var PROMPT_STOP_REASONS = new Set([
|
|
24611
24613
|
"end_turn",
|
|
24612
24614
|
"max_tokens",
|
|
@@ -24679,6 +24681,8 @@ class AgyAcpLane {
|
|
|
24679
24681
|
toolCalls = new Map;
|
|
24680
24682
|
completedTools = new Set;
|
|
24681
24683
|
unownedContent = false;
|
|
24684
|
+
postTurnSettleUntil = null;
|
|
24685
|
+
lastSessionProgressAt = null;
|
|
24682
24686
|
activityReader;
|
|
24683
24687
|
activityRead;
|
|
24684
24688
|
activityTimer;
|
|
@@ -24820,6 +24824,8 @@ class AgyAcpLane {
|
|
|
24820
24824
|
this.ready = false;
|
|
24821
24825
|
this.clearActivityTimer();
|
|
24822
24826
|
this.childProgressBaseline = null;
|
|
24827
|
+
this.postTurnSettleUntil = null;
|
|
24828
|
+
this.lastSessionProgressAt = null;
|
|
24823
24829
|
this.currentPromptRequestId = null;
|
|
24824
24830
|
this.terminalOwner = null;
|
|
24825
24831
|
this.toolCalls.clear();
|
|
@@ -25146,6 +25152,10 @@ class AgyAcpLane {
|
|
|
25146
25152
|
}
|
|
25147
25153
|
throw error;
|
|
25148
25154
|
}
|
|
25155
|
+
if (delivery === "prompt") {
|
|
25156
|
+
this.postTurnSettleUntil = null;
|
|
25157
|
+
this.lastSessionProgressAt = null;
|
|
25158
|
+
}
|
|
25149
25159
|
return { ok: true, acceptedAs: delivery, receipt: prompt.receipt };
|
|
25150
25160
|
}
|
|
25151
25161
|
completePrompt(prompt, value) {
|
|
@@ -25199,7 +25209,8 @@ class AgyAcpLane {
|
|
|
25199
25209
|
if (this.terminalOwner !== owner || this.requestedStopReason || this.processTerminal)
|
|
25200
25210
|
return;
|
|
25201
25211
|
if (this.hasPendingTools())
|
|
25202
|
-
this.
|
|
25212
|
+
this.markUnownedContent();
|
|
25213
|
+
this.postTurnSettleUntil = !this.hasPendingTools() && !this.unownedContent ? this.now() + (this.options.postTurnActivitySettleMs ?? POST_TURN_ACTIVITY_SETTLE_MS) : null;
|
|
25203
25214
|
this.observeOutsideWork();
|
|
25204
25215
|
this.refreshActivity();
|
|
25205
25216
|
this.finishing = false;
|
|
@@ -25235,6 +25246,7 @@ class AgyAcpLane {
|
|
|
25235
25246
|
this.currentPromptRequestId = null;
|
|
25236
25247
|
this.terminalOwner = null;
|
|
25237
25248
|
this.contentOwner = undefined;
|
|
25249
|
+
this.lastSessionProgressAt = null;
|
|
25238
25250
|
this.promptOutcomes.clear();
|
|
25239
25251
|
this.observedPrompts.clear();
|
|
25240
25252
|
if (!latest) {
|
|
@@ -25339,6 +25351,8 @@ class AgyAcpLane {
|
|
|
25339
25351
|
this.processTerminal = true;
|
|
25340
25352
|
this.ready = false;
|
|
25341
25353
|
this.clearActivityTimer();
|
|
25354
|
+
this.postTurnSettleUntil = null;
|
|
25355
|
+
this.lastSessionProgressAt = null;
|
|
25342
25356
|
this.rejectConfigWaiter(normalized);
|
|
25343
25357
|
this.currentPromptRequestId = null;
|
|
25344
25358
|
this.terminalOwner = null;
|
|
@@ -25360,6 +25374,8 @@ class AgyAcpLane {
|
|
|
25360
25374
|
this.processTerminal = true;
|
|
25361
25375
|
this.ready = false;
|
|
25362
25376
|
this.clearActivityTimer();
|
|
25377
|
+
this.postTurnSettleUntil = null;
|
|
25378
|
+
this.lastSessionProgressAt = null;
|
|
25363
25379
|
const exitError = new Error("Agy ACP process exited");
|
|
25364
25380
|
this.rejectConfigWaiter(exitError);
|
|
25365
25381
|
this.currentPromptRequestId = null;
|
|
@@ -25457,7 +25473,7 @@ class AgyAcpLane {
|
|
|
25457
25473
|
return;
|
|
25458
25474
|
}
|
|
25459
25475
|
if (this.currentPromptRequestId === null) {
|
|
25460
|
-
this.
|
|
25476
|
+
this.markUnownedContent();
|
|
25461
25477
|
this.observeOutsideWork();
|
|
25462
25478
|
}
|
|
25463
25479
|
this.write({
|
|
@@ -25495,14 +25511,17 @@ class AgyAcpLane {
|
|
|
25495
25511
|
case "agent_message_chunk": {
|
|
25496
25512
|
const content = record2(update.content);
|
|
25497
25513
|
if (content?.type === "text" && typeof content.text === "string") {
|
|
25498
|
-
|
|
25499
|
-
|
|
25514
|
+
const sessionScoped = this.isSessionScopedEvent(this.contentOwner);
|
|
25515
|
+
if (sessionScoped) {
|
|
25516
|
+
this.markUnownedContent();
|
|
25500
25517
|
this.observeOutsideWork();
|
|
25518
|
+
if (content.text.length > 0)
|
|
25519
|
+
this.emitSessionProgress("session_message");
|
|
25501
25520
|
}
|
|
25502
25521
|
this.events.emit("runtime_event", {
|
|
25503
25522
|
kind: "assistant_message_delta",
|
|
25504
25523
|
text: content.text,
|
|
25505
|
-
|
|
25524
|
+
...sessionScoped ? { attribution: { scope: "session" } } : {}
|
|
25506
25525
|
});
|
|
25507
25526
|
}
|
|
25508
25527
|
return;
|
|
@@ -25510,14 +25529,17 @@ class AgyAcpLane {
|
|
|
25510
25529
|
case "agent_thought_chunk": {
|
|
25511
25530
|
const content = record2(update.content);
|
|
25512
25531
|
if (content?.type === "text" && typeof content.text === "string") {
|
|
25513
|
-
|
|
25514
|
-
|
|
25532
|
+
const sessionScoped = this.isSessionScopedEvent(this.contentOwner);
|
|
25533
|
+
if (sessionScoped) {
|
|
25534
|
+
this.markUnownedContent();
|
|
25515
25535
|
this.observeOutsideWork();
|
|
25536
|
+
if (content.text.length > 0)
|
|
25537
|
+
this.emitSessionProgress("session_reasoning");
|
|
25516
25538
|
}
|
|
25517
25539
|
this.events.emit("runtime_event", {
|
|
25518
25540
|
kind: "assistant_reasoning_delta",
|
|
25519
25541
|
text: content.text,
|
|
25520
|
-
|
|
25542
|
+
...sessionScoped ? { attribution: { scope: "session" } } : {}
|
|
25521
25543
|
});
|
|
25522
25544
|
}
|
|
25523
25545
|
return;
|
|
@@ -25551,13 +25573,19 @@ class AgyAcpLane {
|
|
|
25551
25573
|
owner: this.contentOwner
|
|
25552
25574
|
};
|
|
25553
25575
|
this.toolCalls.set(update.toolCallId, tool);
|
|
25576
|
+
const sessionScoped = this.isSessionScopedEvent(tool.owner);
|
|
25577
|
+
if (sessionScoped)
|
|
25578
|
+
this.emitSessionProgress("session_tool_call");
|
|
25554
25579
|
this.events.emit("runtime_event", {
|
|
25555
25580
|
kind: "tool_call",
|
|
25556
25581
|
callId: update.toolCallId,
|
|
25557
25582
|
name: tool.name,
|
|
25558
25583
|
input: update.rawInput,
|
|
25559
|
-
...
|
|
25584
|
+
...sessionScoped ? { attribution: { scope: "session" } } : {}
|
|
25560
25585
|
});
|
|
25586
|
+
} else if (update.status !== "completed" && update.status !== "failed") {
|
|
25587
|
+
if (this.isSessionScopedEvent(tool.owner))
|
|
25588
|
+
this.emitSessionProgress("session_tool_update");
|
|
25561
25589
|
}
|
|
25562
25590
|
this.observeOutsideWork();
|
|
25563
25591
|
if (update.status === "completed" || update.status === "failed")
|
|
@@ -25570,18 +25598,25 @@ class AgyAcpLane {
|
|
|
25570
25598
|
const tool = this.toolCalls.get(update.toolCallId);
|
|
25571
25599
|
if (!tool)
|
|
25572
25600
|
return;
|
|
25573
|
-
if (update.status === "completed" || update.status === "failed")
|
|
25601
|
+
if (update.status === "completed" || update.status === "failed") {
|
|
25574
25602
|
this.finishTool(update, tool);
|
|
25603
|
+
} else if (this.isSessionScopedEvent(tool.owner)) {
|
|
25604
|
+
this.emitSessionProgress("session_tool_update");
|
|
25605
|
+
}
|
|
25575
25606
|
return;
|
|
25576
25607
|
}
|
|
25577
|
-
case "plan":
|
|
25608
|
+
case "plan": {
|
|
25609
|
+
const sessionScoped = this.isSessionScopedEvent(this.contentOwner);
|
|
25610
|
+
if (sessionScoped)
|
|
25611
|
+
this.emitSessionProgress("session_plan");
|
|
25578
25612
|
this.events.emit("runtime_event", {
|
|
25579
25613
|
kind: "internal_progress",
|
|
25580
25614
|
source: "agy.acp",
|
|
25581
25615
|
itemType: "plan",
|
|
25582
|
-
|
|
25616
|
+
...sessionScoped ? { attribution: { scope: "session" } } : {}
|
|
25583
25617
|
});
|
|
25584
25618
|
return;
|
|
25619
|
+
}
|
|
25585
25620
|
default:
|
|
25586
25621
|
this.diagnostic("warning", `Unsupported Agy ACP session update: ${safeLabel(updateType)}`);
|
|
25587
25622
|
}
|
|
@@ -25591,8 +25626,11 @@ class AgyAcpLane {
|
|
|
25591
25626
|
this.completedTools.add(update.toolCallId);
|
|
25592
25627
|
if (this.completedTools.size > 4096)
|
|
25593
25628
|
this.completedTools.delete(this.completedTools.values().next().value);
|
|
25594
|
-
|
|
25595
|
-
|
|
25629
|
+
const sessionScoped = this.isSessionScopedEvent(tool.owner);
|
|
25630
|
+
if (sessionScoped) {
|
|
25631
|
+
this.markUnownedContent();
|
|
25632
|
+
this.emitSessionProgress("session_tool_output");
|
|
25633
|
+
}
|
|
25596
25634
|
this.observeOutsideWork();
|
|
25597
25635
|
this.events.emit("runtime_event", {
|
|
25598
25636
|
kind: "tool_output",
|
|
@@ -25600,7 +25638,7 @@ class AgyAcpLane {
|
|
|
25600
25638
|
name: tool.name,
|
|
25601
25639
|
outcome: update.status === "failed" ? "failed" : "success",
|
|
25602
25640
|
output: update.rawOutput ?? update.content,
|
|
25603
|
-
...
|
|
25641
|
+
...sessionScoped ? { attribution: { scope: "session" } } : {}
|
|
25604
25642
|
});
|
|
25605
25643
|
}
|
|
25606
25644
|
diagnostic(severity, message) {
|
|
@@ -25611,6 +25649,33 @@ class AgyAcpLane {
|
|
|
25611
25649
|
message
|
|
25612
25650
|
});
|
|
25613
25651
|
}
|
|
25652
|
+
now() {
|
|
25653
|
+
return this.options.now ? this.options.now() : Date.now();
|
|
25654
|
+
}
|
|
25655
|
+
hasActiveRootTurn() {
|
|
25656
|
+
return this.currentPromptRequestId !== null && this.terminalOwner !== null && !this.finishing;
|
|
25657
|
+
}
|
|
25658
|
+
isSessionScopedEvent(owner) {
|
|
25659
|
+
return !owner || owner !== this.terminalOwner;
|
|
25660
|
+
}
|
|
25661
|
+
markUnownedContent() {
|
|
25662
|
+
this.unownedContent = true;
|
|
25663
|
+
this.postTurnSettleUntil = null;
|
|
25664
|
+
}
|
|
25665
|
+
emitSessionProgress(itemType) {
|
|
25666
|
+
if (!this.hasActiveRootTurn())
|
|
25667
|
+
return;
|
|
25668
|
+
const now = this.now();
|
|
25669
|
+
const minIntervalMs = this.options.sessionProgressMinIntervalMs ?? SESSION_PROGRESS_HEARTBEAT_MIN_INTERVAL_MS;
|
|
25670
|
+
if (this.lastSessionProgressAt !== null && now - this.lastSessionProgressAt < minIntervalMs)
|
|
25671
|
+
return;
|
|
25672
|
+
this.lastSessionProgressAt = now;
|
|
25673
|
+
this.events.emit("runtime_event", {
|
|
25674
|
+
kind: "internal_progress",
|
|
25675
|
+
source: "agy.acp",
|
|
25676
|
+
itemType
|
|
25677
|
+
});
|
|
25678
|
+
}
|
|
25614
25679
|
hasPendingTools() {
|
|
25615
25680
|
return this.toolCalls.size > 0;
|
|
25616
25681
|
}
|
|
@@ -25638,7 +25703,7 @@ class AgyAcpLane {
|
|
|
25638
25703
|
}
|
|
25639
25704
|
}
|
|
25640
25705
|
observeChildProgress(children) {
|
|
25641
|
-
if (!children || this.
|
|
25706
|
+
if (!children || !this.hasActiveRootTurn())
|
|
25642
25707
|
return;
|
|
25643
25708
|
if (this.childProgressBaseline === null) {
|
|
25644
25709
|
this.childProgressBaseline = toChildProgressMap(children);
|
|
@@ -25679,6 +25744,7 @@ class AgyAcpLane {
|
|
|
25679
25744
|
if (!this.ready || !this.activityReader || this.requestedStopReason || this.processTerminal)
|
|
25680
25745
|
return Promise.resolve();
|
|
25681
25746
|
const revision = this.activityRevision;
|
|
25747
|
+
const startedWhileIdle = this.currentPromptRequestId === null;
|
|
25682
25748
|
const reading = (async () => {
|
|
25683
25749
|
let status = "unknown";
|
|
25684
25750
|
try {
|
|
@@ -25688,10 +25754,15 @@ class AgyAcpLane {
|
|
|
25688
25754
|
return;
|
|
25689
25755
|
if (revision === this.activityRevision)
|
|
25690
25756
|
this.nativeActivity = status;
|
|
25691
|
-
if (status === "
|
|
25692
|
-
this.
|
|
25757
|
+
if (status === "idle") {
|
|
25758
|
+
this.postTurnSettleUntil = null;
|
|
25759
|
+
} else if (status === "running" && this.currentPromptRequestId === null) {
|
|
25760
|
+
const withinSettleWindow = !startedWhileIdle || this.postTurnSettleUntil !== null && this.now() < this.postTurnSettleUntil;
|
|
25761
|
+
if (!withinSettleWindow)
|
|
25762
|
+
this.markUnownedContent();
|
|
25763
|
+
}
|
|
25693
25764
|
this.publishActivity();
|
|
25694
|
-
if (this.
|
|
25765
|
+
if (this.hasActiveRootTurn()) {
|
|
25695
25766
|
const children = await this.readChildProgress();
|
|
25696
25767
|
if (!this.ready || this.requestedStopReason || this.processTerminal)
|
|
25697
25768
|
return;
|
|
@@ -38129,7 +38200,7 @@ function reduceManager(state, event) {
|
|
|
38129
38200
|
return commit(state, agent, recoveryEffects(agent, closing));
|
|
38130
38201
|
}
|
|
38131
38202
|
case "exit":
|
|
38132
|
-
return onExit(state, event
|
|
38203
|
+
return onExit(state, event);
|
|
38133
38204
|
case "tick":
|
|
38134
38205
|
return onTick(state, event.nowMs);
|
|
38135
38206
|
case "runtime_signal": {
|
|
@@ -38199,6 +38270,7 @@ function onWake(state, agentId, message) {
|
|
|
38199
38270
|
if (!agent) {
|
|
38200
38271
|
return { state, effects: [] };
|
|
38201
38272
|
}
|
|
38273
|
+
agent.recoveryAttempted = message.recovery === true;
|
|
38202
38274
|
if (agent.resetting && agent.status !== "idle") {
|
|
38203
38275
|
agent.inbox = [...agent.inbox, message];
|
|
38204
38276
|
agent.idleSince = null;
|
|
@@ -38330,7 +38402,15 @@ function onTurnToolLifecycle(state, event, lifecycle) {
|
|
|
38330
38402
|
syncExecutionProjection(agent);
|
|
38331
38403
|
});
|
|
38332
38404
|
}
|
|
38333
|
-
function
|
|
38405
|
+
function interruptedTurnMessage(agentId, reason, nowMs) {
|
|
38406
|
+
return {
|
|
38407
|
+
id: `${agentId}:recovery:${reason}:${nowMs}`,
|
|
38408
|
+
recovery: true,
|
|
38409
|
+
text: `[System Recovery] Your previous turn was interrupted (${reason}). Run alook message mark list and continue unfinished work or report what is blocked.`
|
|
38410
|
+
};
|
|
38411
|
+
}
|
|
38412
|
+
function onExit(state, event) {
|
|
38413
|
+
const { agentId } = event;
|
|
38334
38414
|
const existing = state.agents[agentId];
|
|
38335
38415
|
if (!existing)
|
|
38336
38416
|
return { state, effects: [] };
|
|
@@ -38342,6 +38422,10 @@ function onExit(state, agentId) {
|
|
|
38342
38422
|
agent.backendTurnId = null;
|
|
38343
38423
|
agent.stoppingSince = null;
|
|
38344
38424
|
syncExecutionProjection(agent);
|
|
38425
|
+
if (event.interrupted && !agent.recoveryAttempted && agent.inbox.length === 0) {
|
|
38426
|
+
agent.recoveryAttempted = true;
|
|
38427
|
+
agent.inbox.push(interruptedTurnMessage(agentId, event.terminationSemantics ?? "abnormal_exit", event.nowMs ?? 0));
|
|
38428
|
+
}
|
|
38345
38429
|
if (agent.inbox.length > 0) {
|
|
38346
38430
|
agent.status = "starting";
|
|
38347
38431
|
const messages = drainInbox(agent);
|
|
@@ -58144,7 +58228,7 @@ var ExternalSendRequestSchema = exports_external.strictObject({
|
|
|
58144
58228
|
text: exports_external.string().trim().max(BOT_IM_EXTERNAL_SEND_MAX_BYTES).optional().default(""),
|
|
58145
58229
|
attachments: exports_external.array(exports_external.string().trim().min(1).max(128)).max(BOT_IM_MAX_ATTACHMENTS).optional()
|
|
58146
58230
|
}).refine((value) => value.text.length > 0 || (value.attachments?.length ?? 0) > 0, {
|
|
58147
|
-
|
|
58231
|
+
error: "Either text or at least one attachment is required"
|
|
58148
58232
|
});
|
|
58149
58233
|
var ExternalSendResponseSchema = exports_external.strictObject({
|
|
58150
58234
|
state: exports_external.literal("sent"),
|
|
@@ -58229,7 +58313,7 @@ var DiagnosticCollectCommandSchema = exports_external.object({
|
|
|
58229
58313
|
agentId: AgentIdSchema,
|
|
58230
58314
|
fromMs: SafeEpochSchema,
|
|
58231
58315
|
deadlineAt: SafeEpochSchema
|
|
58232
|
-
}).strict().refine((command) => command.deadlineAt - command.fromMs === DIAGNOSTIC_COLLECT_SPAN_MS, {
|
|
58316
|
+
}).strict().refine((command) => command.deadlineAt - command.fromMs === DIAGNOSTIC_COLLECT_SPAN_MS, { error: "diagnostic collection span must match v1" });
|
|
58233
58317
|
var OwnerDiagnosticReportBase = {
|
|
58234
58318
|
reportId: DiagnosticReportIdSchema,
|
|
58235
58319
|
deadlineAt: SafeEpochSchema
|
|
@@ -58465,7 +58549,7 @@ var AutomationPermissionPolicySchema = exports_external.strictObject({
|
|
|
58465
58549
|
limit: exports_external.number().int().positive(),
|
|
58466
58550
|
period: exports_external.enum(["hour", "day"])
|
|
58467
58551
|
}).refine((value) => value.limit <= AUTOMATION_PERMISSION_LIMITS[value.period], {
|
|
58468
|
-
|
|
58552
|
+
error: `Limit cannot exceed ${AUTOMATION_PERMISSION_LIMITS.hour}/hour or ${AUTOMATION_PERMISSION_LIMITS.day}/day`,
|
|
58469
58553
|
path: ["limit"]
|
|
58470
58554
|
});
|
|
58471
58555
|
var permissions = exports_external.array(AutomationPermissionPolicySchema).min(1).max(AutomationPermissionSchema.options.length).refine((values) => new Set(values.map((value) => value.permission)).size === values.length, "Duplicate permission");
|
|
@@ -58553,6 +58637,12 @@ var FriendApprovalPayloadSchema = exports_external.strictObject({
|
|
|
58553
58637
|
|
|
58554
58638
|
// ../shared/src/community/bot-model.ts
|
|
58555
58639
|
var BOT_MODEL_NAME_MAX_LENGTH = 100;
|
|
58640
|
+
function resolveModelConfig(modelName) {
|
|
58641
|
+
const name = (modelName ?? "").trim();
|
|
58642
|
+
if (name.length === 0)
|
|
58643
|
+
return { kind: "default" };
|
|
58644
|
+
return { kind: "named", name };
|
|
58645
|
+
}
|
|
58556
58646
|
|
|
58557
58647
|
// ../shared/src/model-observation.ts
|
|
58558
58648
|
var identity2 = exports_external.string().min(1).max(256).regex(/^[^\s\u0000-\u001f\u007f]+$/);
|
|
@@ -58609,7 +58699,7 @@ var DecisionCardQuestionInputSchema = exports_external.strictObject({
|
|
|
58609
58699
|
function hasDuplicateIds(ids) {
|
|
58610
58700
|
return new Set(ids).size !== ids.length;
|
|
58611
58701
|
}
|
|
58612
|
-
var mentionHandleSchema = exports_external.string().trim().min(1).max(128).refine((value) => parseNameAndTag(value.startsWith("@") ? value.slice(1) : value) !== null, {
|
|
58702
|
+
var mentionHandleSchema = exports_external.string().trim().min(1).max(128).refine((value) => parseNameAndTag(value.startsWith("@") ? value.slice(1) : value) !== null, { error: 'mention must be a handle like "@alice#0001"' });
|
|
58613
58703
|
var DecisionCardInputSchema = exports_external.strictObject({
|
|
58614
58704
|
mentions: exports_external.array(mentionHandleSchema).max(DECISION_CARD_MAX_MENTIONS).optional(),
|
|
58615
58705
|
summary: requiredSummarySchema,
|
|
@@ -58725,7 +58815,7 @@ function tokenUsageCapability(backendId) {
|
|
|
58725
58815
|
return tokenUsageBackends.has(backendId) ? "supported" : backendId === "cursor" ? "unsupported" : "unknown";
|
|
58726
58816
|
}
|
|
58727
58817
|
var safeToken = exports_external.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
58728
|
-
var boundedText2 = exports_external.string().min(1).refine((value) => new TextEncoder().encode(value).length <= 64, {
|
|
58818
|
+
var boundedText2 = exports_external.string().min(1).refine((value) => new TextEncoder().encode(value).length <= 64, { error: "must be at most 64 UTF-8 bytes" });
|
|
58729
58819
|
var DailyUsageMetricSchema = safeToken.nullable();
|
|
58730
58820
|
var DailyUsageSnapshotSchema = exports_external.object({
|
|
58731
58821
|
botId: exports_external.string().min(1),
|
|
@@ -58811,7 +58901,7 @@ var ProviderQuotaSnapshotSchema = exports_external.object({
|
|
|
58811
58901
|
agentBackendId: ProviderQuotaBackendSchema,
|
|
58812
58902
|
observation: ProviderQuotaObservationSchema
|
|
58813
58903
|
}).strict();
|
|
58814
|
-
var ProviderQuotaSnapshotListSchema = exports_external.array(ProviderQuotaSnapshotSchema).refine((snapshots) => new Set(snapshots.map((snapshot) => snapshot.agentBackendId)).size === snapshots.length, {
|
|
58904
|
+
var ProviderQuotaSnapshotListSchema = exports_external.array(ProviderQuotaSnapshotSchema).refine((snapshots) => new Set(snapshots.map((snapshot) => snapshot.agentBackendId)).size === snapshots.length, { error: "duplicate provider quota backend" });
|
|
58815
58905
|
|
|
58816
58906
|
// ../shared/src/constants.ts
|
|
58817
58907
|
var COMMUNITY_MACHINE_HEARTBEAT_MS = 30000;
|
|
@@ -59070,10 +59160,10 @@ var isMentionSafeName = (name) => validateCommunityName(name).ok;
|
|
|
59070
59160
|
var MENTION_SAFE_NAME_MSG = "name cannot contain #, @, or line breaks";
|
|
59071
59161
|
var BOT_AVATAR_ROUTE_PATTERN = /^\/api\/community\/bots\/[A-Za-z0-9_-]+\/avatar$/;
|
|
59072
59162
|
var BotImageUrlSchema = exports_external.string().max(COMMUNITY_BOT_IMAGE_URL_MAX).refine((v) => v.startsWith("https://") || v.startsWith("avatar:") || BOT_AVATAR_ROUTE_PATTERN.test(v), {
|
|
59073
|
-
|
|
59163
|
+
error: "image must be an https URL, the bot avatar route, or an avatar: config"
|
|
59074
59164
|
});
|
|
59075
59165
|
var CommunityBotCreateRequestSchema = exports_external.object({
|
|
59076
|
-
name: exports_external.string().trim().min(COMMUNITY_BOT_NAME_MIN).max(COMMUNITY_BOT_NAME_MAX).refine(isMentionSafeName, {
|
|
59166
|
+
name: exports_external.string().trim().min(COMMUNITY_BOT_NAME_MIN).max(COMMUNITY_BOT_NAME_MAX).refine(isMentionSafeName, { error: MENTION_SAFE_NAME_MSG }),
|
|
59077
59167
|
description: exports_external.string().max(COMMUNITY_BOT_DESCRIPTION_MAX).optional(),
|
|
59078
59168
|
machineId: exports_external.string().min(1),
|
|
59079
59169
|
runtime: exports_external.string().min(1),
|
|
@@ -59082,14 +59172,14 @@ var CommunityBotCreateRequestSchema = exports_external.object({
|
|
|
59082
59172
|
reasoningEffort: ReasoningEffortSchema.nullable().optional()
|
|
59083
59173
|
});
|
|
59084
59174
|
var CommunityBotPatchRequestSchema = exports_external.object({
|
|
59085
|
-
name: exports_external.string().trim().min(COMMUNITY_BOT_NAME_MIN).max(COMMUNITY_BOT_NAME_MAX).refine(isMentionSafeName, {
|
|
59175
|
+
name: exports_external.string().trim().min(COMMUNITY_BOT_NAME_MIN).max(COMMUNITY_BOT_NAME_MAX).refine(isMentionSafeName, { error: MENTION_SAFE_NAME_MSG }).optional(),
|
|
59086
59176
|
description: exports_external.string().max(COMMUNITY_BOT_DESCRIPTION_MAX).optional(),
|
|
59087
59177
|
image: BotImageUrlSchema.nullable().optional(),
|
|
59088
59178
|
model: exports_external.string().trim().min(1).max(BOT_MODEL_NAME_MAX_LENGTH).nullable().optional(),
|
|
59089
59179
|
runtime: exports_external.string().trim().min(1).max(COMMUNITY_RUNTIME_ID_MAX).optional(),
|
|
59090
59180
|
reasoningEffort: ReasoningEffortSchema.nullable().optional()
|
|
59091
59181
|
}).refine((v) => v.name !== undefined || v.description !== undefined || v.image !== undefined || v.runtime !== undefined || ("reasoningEffort" in v) || ("model" in v), {
|
|
59092
|
-
|
|
59182
|
+
error: "at least one field must be provided"
|
|
59093
59183
|
});
|
|
59094
59184
|
var CommunityBotAddToServerRequestSchema = exports_external.object({
|
|
59095
59185
|
botId: exports_external.string().min(1)
|
|
@@ -59107,7 +59197,7 @@ var CommunityServerOnboardRequestSchema = exports_external.strictObject({
|
|
|
59107
59197
|
}),
|
|
59108
59198
|
exports_external.strictObject({ type: exports_external.literal("finalize") })
|
|
59109
59199
|
])
|
|
59110
|
-
}).refine(({ bots, leadBotId }) => bots.some((bot) => bot.id === leadBotId), {
|
|
59200
|
+
}).refine(({ bots, leadBotId }) => bots.some((bot) => bot.id === leadBotId), { error: "leadBotId must reference an onboarded bot", path: ["leadBotId"] }).refine(({ bots, action }) => action.type !== "wake" || bots.some((bot) => bot.id === action.botId), { error: "wake botId must reference an onboarded bot", path: ["action", "botId"] });
|
|
59111
59201
|
var CommunityAgentMessageContentSchema = exports_external.object({ text: exports_external.string().max(MAX_MESSAGE_CONTENT_LENGTH).default("") }).catchall(exports_external.unknown());
|
|
59112
59202
|
var CommunityAgentSeqSchema = exports_external.number().int().min(0);
|
|
59113
59203
|
var CommunityAgentPositiveSeqSchema = exports_external.number().int().min(1);
|
|
@@ -59172,7 +59262,7 @@ var CommunityAgentUpdateProfileRequestSchema = exports_external.object({
|
|
|
59172
59262
|
data: exports_external.instanceof(Uint8Array).refine((value) => value.byteLength > 0, "avatar must not be empty").refine((value) => value.byteLength <= MAX_SERVER_ICON_SIZE_BYTES, `avatar must be ≤ ${MAX_SERVER_ICON_SIZE_BYTES} bytes`)
|
|
59173
59263
|
}).optional()
|
|
59174
59264
|
}).refine((value) => value.bio !== undefined || value.avatar !== undefined, {
|
|
59175
|
-
|
|
59265
|
+
error: "bio or avatar is required"
|
|
59176
59266
|
});
|
|
59177
59267
|
var CommunityAgentInboxPullRequestSchema = exports_external.object({
|
|
59178
59268
|
max: exports_external.number().int().min(1).max(200).optional()
|
|
@@ -59186,7 +59276,7 @@ var CommunityAgentReadRequestSchema = exports_external.object({
|
|
|
59186
59276
|
after: CommunityAgentSeqSchema.optional(),
|
|
59187
59277
|
around: CommunityAgentSeqSchema.optional(),
|
|
59188
59278
|
limit: exports_external.number().int().min(1).max(200).optional()
|
|
59189
|
-
}).refine((v) => [v.before, v.after, v.around].filter((x) => x !== undefined).length <= 1, {
|
|
59279
|
+
}).refine((v) => [v.before, v.after, v.around].filter((x) => x !== undefined).length <= 1, { error: "at most one of before/after/around may be supplied" });
|
|
59190
59280
|
var CommunityAgentResolveRequestSchema = exports_external.object({
|
|
59191
59281
|
channel: exports_external.string().min(1),
|
|
59192
59282
|
seq: CommunityAgentSeqSchema
|
|
@@ -59208,7 +59298,7 @@ var CommunityAgentJoinServerRequestSchema = exports_external.object({
|
|
|
59208
59298
|
});
|
|
59209
59299
|
var CommunityAgentNapRequestSchema = exports_external.object({
|
|
59210
59300
|
handoff: exports_external.string().refine((value) => value.trim().length > 0, {
|
|
59211
|
-
|
|
59301
|
+
error: "handoff must not be blank"
|
|
59212
59302
|
}).optional()
|
|
59213
59303
|
});
|
|
59214
59304
|
var CommunityAgentMessagePropertyRequestSchema = exports_external.object({
|
|
@@ -59234,7 +59324,7 @@ var AuditLogThinkingPayloadSchema = exports_external.object({
|
|
|
59234
59324
|
chars: exports_external.number().int().nonnegative()
|
|
59235
59325
|
});
|
|
59236
59326
|
var AuditLogTextPayloadSchema = exports_external.object({
|
|
59237
|
-
text: exports_external.string().min(1).max(BOT_AUDIT_TEXT_MAX_BYTES).refine((text) => new TextEncoder().encode(text).byteLength <= BOT_AUDIT_TEXT_MAX_BYTES, {
|
|
59327
|
+
text: exports_external.string().min(1).max(BOT_AUDIT_TEXT_MAX_BYTES).refine((text) => new TextEncoder().encode(text).byteLength <= BOT_AUDIT_TEXT_MAX_BYTES, { error: "Text exceeds 1024 UTF-8 bytes" }),
|
|
59238
59328
|
truncated: exports_external.boolean(),
|
|
59239
59329
|
chars: exports_external.number().int().nonnegative()
|
|
59240
59330
|
});
|
|
@@ -59492,7 +59582,7 @@ var CommunityMessageResourceSchema = exports_external.strictObject({
|
|
|
59492
59582
|
authorId: id2.optional(),
|
|
59493
59583
|
authorName: exports_external.string(),
|
|
59494
59584
|
deleted: exports_external.boolean().optional()
|
|
59495
|
-
}).refine((reply) => reply.deleted === true || reply.authorId !== undefined, {
|
|
59585
|
+
}).refine((reply) => reply.deleted === true || reply.authorId !== undefined, { error: "Live reply author identity missing" }).optional(),
|
|
59496
59586
|
embeds: exports_external.array(exports_external.unknown()).optional(),
|
|
59497
59587
|
reactions: exports_external.array(exports_external.strictObject({
|
|
59498
59588
|
emoji: exports_external.string(),
|
|
@@ -60025,7 +60115,7 @@ function makeRuntimeConfig(input2) {
|
|
|
60025
60115
|
instruction: input2.instruction
|
|
60026
60116
|
};
|
|
60027
60117
|
}
|
|
60028
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60118
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/entity.js
|
|
60029
60119
|
var entityKind = Symbol.for("drizzle:entityKind");
|
|
60030
60120
|
var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
|
|
60031
60121
|
function is(value, type) {
|
|
@@ -60050,7 +60140,7 @@ function is(value, type) {
|
|
|
60050
60140
|
return false;
|
|
60051
60141
|
}
|
|
60052
60142
|
|
|
60053
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60143
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/column.js
|
|
60054
60144
|
class Column {
|
|
60055
60145
|
constructor(table, config2) {
|
|
60056
60146
|
this.table = table;
|
|
@@ -60100,7 +60190,7 @@ class Column {
|
|
|
60100
60190
|
}
|
|
60101
60191
|
}
|
|
60102
60192
|
|
|
60103
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60193
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/column-builder.js
|
|
60104
60194
|
class ColumnBuilder {
|
|
60105
60195
|
static [entityKind] = "ColumnBuilder";
|
|
60106
60196
|
config;
|
|
@@ -60156,20 +60246,20 @@ class ColumnBuilder {
|
|
|
60156
60246
|
}
|
|
60157
60247
|
}
|
|
60158
60248
|
|
|
60159
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60249
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/table.utils.js
|
|
60160
60250
|
var TableName = Symbol.for("drizzle:Name");
|
|
60161
60251
|
|
|
60162
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60252
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/tracing-utils.js
|
|
60163
60253
|
function iife(fn, ...args) {
|
|
60164
60254
|
return fn(...args);
|
|
60165
60255
|
}
|
|
60166
60256
|
|
|
60167
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60257
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/pg-core/unique-constraint.js
|
|
60168
60258
|
function uniqueKeyName(table, columns) {
|
|
60169
60259
|
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
60170
60260
|
}
|
|
60171
60261
|
|
|
60172
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60262
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/pg-core/columns/common.js
|
|
60173
60263
|
class PgColumn extends Column {
|
|
60174
60264
|
constructor(table, config2) {
|
|
60175
60265
|
if (!config2.uniqueName) {
|
|
@@ -60218,7 +60308,7 @@ class ExtraConfigColumn extends PgColumn {
|
|
|
60218
60308
|
}
|
|
60219
60309
|
}
|
|
60220
60310
|
|
|
60221
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60311
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/pg-core/columns/enum.js
|
|
60222
60312
|
class PgEnumObjectColumn extends PgColumn {
|
|
60223
60313
|
static [entityKind] = "PgEnumObjectColumn";
|
|
60224
60314
|
enum;
|
|
@@ -60248,7 +60338,7 @@ class PgEnumColumn extends PgColumn {
|
|
|
60248
60338
|
}
|
|
60249
60339
|
}
|
|
60250
60340
|
|
|
60251
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60341
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/subquery.js
|
|
60252
60342
|
class Subquery {
|
|
60253
60343
|
static [entityKind] = "Subquery";
|
|
60254
60344
|
constructor(sql, fields, alias, isWith = false, usedTables = []) {
|
|
@@ -60263,10 +60353,10 @@ class Subquery {
|
|
|
60263
60353
|
}
|
|
60264
60354
|
}
|
|
60265
60355
|
|
|
60266
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60356
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/version.js
|
|
60267
60357
|
var version2 = "0.45.4";
|
|
60268
60358
|
|
|
60269
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60359
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/tracing.js
|
|
60270
60360
|
var otel;
|
|
60271
60361
|
var rawTracer;
|
|
60272
60362
|
var tracer = {
|
|
@@ -60293,10 +60383,10 @@ var tracer = {
|
|
|
60293
60383
|
}
|
|
60294
60384
|
};
|
|
60295
60385
|
|
|
60296
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60386
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/view-common.js
|
|
60297
60387
|
var ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
60298
60388
|
|
|
60299
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60389
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/table.js
|
|
60300
60390
|
var Schema = Symbol.for("drizzle:Schema");
|
|
60301
60391
|
var Columns = Symbol.for("drizzle:Columns");
|
|
60302
60392
|
var ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
@@ -60334,7 +60424,7 @@ class Table {
|
|
|
60334
60424
|
}
|
|
60335
60425
|
}
|
|
60336
60426
|
|
|
60337
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60427
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sql/sql.js
|
|
60338
60428
|
function isSQLWrapper(value) {
|
|
60339
60429
|
return value !== null && value !== undefined && typeof value.getSQL === "function";
|
|
60340
60430
|
}
|
|
@@ -60697,7 +60787,7 @@ Subquery.prototype.getSQL = function() {
|
|
|
60697
60787
|
return new SQL([this]);
|
|
60698
60788
|
};
|
|
60699
60789
|
|
|
60700
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60790
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/alias.js
|
|
60701
60791
|
class ColumnAliasProxyHandler {
|
|
60702
60792
|
constructor(table) {
|
|
60703
60793
|
this.table = table;
|
|
@@ -60753,7 +60843,7 @@ class TableAliasProxyHandler {
|
|
|
60753
60843
|
}
|
|
60754
60844
|
}
|
|
60755
60845
|
|
|
60756
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60846
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/utils.js
|
|
60757
60847
|
function getColumnNameAndConfig(a, b) {
|
|
60758
60848
|
return {
|
|
60759
60849
|
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
@@ -60762,7 +60852,7 @@ function getColumnNameAndConfig(a, b) {
|
|
|
60762
60852
|
}
|
|
60763
60853
|
var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder;
|
|
60764
60854
|
|
|
60765
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60855
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
60766
60856
|
function bindIfParam(value, column) {
|
|
60767
60857
|
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
60768
60858
|
return new Param(value, column);
|
|
@@ -60793,7 +60883,7 @@ function isNotNull(value) {
|
|
|
60793
60883
|
return sql`${value} is not null`;
|
|
60794
60884
|
}
|
|
60795
60885
|
|
|
60796
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60886
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sql/expressions/select.js
|
|
60797
60887
|
function desc(column) {
|
|
60798
60888
|
return sql`${column} desc`;
|
|
60799
60889
|
}
|
|
@@ -60830,12 +60920,12 @@ __export(exports_community_schema, {
|
|
|
60830
60920
|
communityAttachment: () => communityAttachment
|
|
60831
60921
|
});
|
|
60832
60922
|
|
|
60833
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60923
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/alias.js
|
|
60834
60924
|
function alias(table, alias2) {
|
|
60835
60925
|
return new Proxy(table, new TableAliasProxyHandler(alias2, false));
|
|
60836
60926
|
}
|
|
60837
60927
|
|
|
60838
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60928
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/checks.js
|
|
60839
60929
|
class CheckBuilder {
|
|
60840
60930
|
constructor(name, value) {
|
|
60841
60931
|
this.name = name;
|
|
@@ -60862,7 +60952,7 @@ function check2(name, value) {
|
|
|
60862
60952
|
return new CheckBuilder(name, value);
|
|
60863
60953
|
}
|
|
60864
60954
|
|
|
60865
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
60955
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
|
|
60866
60956
|
class ForeignKeyBuilder {
|
|
60867
60957
|
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
60868
60958
|
reference;
|
|
@@ -60916,7 +61006,7 @@ class ForeignKey {
|
|
|
60916
61006
|
}
|
|
60917
61007
|
}
|
|
60918
61008
|
|
|
60919
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61009
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/unique-constraint.js
|
|
60920
61010
|
function uniqueKeyName2(table, columns) {
|
|
60921
61011
|
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
60922
61012
|
}
|
|
@@ -60961,7 +61051,7 @@ class UniqueConstraint {
|
|
|
60961
61051
|
}
|
|
60962
61052
|
}
|
|
60963
61053
|
|
|
60964
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61054
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/columns/common.js
|
|
60965
61055
|
class SQLiteColumnBuilder extends ColumnBuilder {
|
|
60966
61056
|
static [entityKind] = "SQLiteColumnBuilder";
|
|
60967
61057
|
foreignKeyConfigs = [];
|
|
@@ -61012,7 +61102,7 @@ class SQLiteColumn extends Column {
|
|
|
61012
61102
|
static [entityKind] = "SQLiteColumn";
|
|
61013
61103
|
}
|
|
61014
61104
|
|
|
61015
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61105
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/columns/blob.js
|
|
61016
61106
|
class SQLiteBigIntBuilder extends SQLiteColumnBuilder {
|
|
61017
61107
|
static [entityKind] = "SQLiteBigIntBuilder";
|
|
61018
61108
|
constructor(name) {
|
|
@@ -61100,7 +61190,7 @@ function blob(a, b) {
|
|
|
61100
61190
|
return new SQLiteBlobBufferBuilder(name);
|
|
61101
61191
|
}
|
|
61102
61192
|
|
|
61103
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61193
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/columns/custom.js
|
|
61104
61194
|
class SQLiteCustomColumnBuilder extends SQLiteColumnBuilder {
|
|
61105
61195
|
static [entityKind] = "SQLiteCustomColumnBuilder";
|
|
61106
61196
|
constructor(name, fieldConfig, customTypeParams) {
|
|
@@ -61141,7 +61231,7 @@ function customType(customTypeParams) {
|
|
|
61141
61231
|
};
|
|
61142
61232
|
}
|
|
61143
61233
|
|
|
61144
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61234
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/columns/integer.js
|
|
61145
61235
|
class SQLiteBaseIntegerBuilder extends SQLiteColumnBuilder {
|
|
61146
61236
|
static [entityKind] = "SQLiteBaseIntegerBuilder";
|
|
61147
61237
|
constructor(name, dataType, columnType) {
|
|
@@ -61243,7 +61333,7 @@ function integer2(a, b) {
|
|
|
61243
61333
|
return new SQLiteIntegerBuilder(name);
|
|
61244
61334
|
}
|
|
61245
61335
|
|
|
61246
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61336
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
|
|
61247
61337
|
class SQLiteNumericBuilder extends SQLiteColumnBuilder {
|
|
61248
61338
|
static [entityKind] = "SQLiteNumericBuilder";
|
|
61249
61339
|
constructor(name) {
|
|
@@ -61313,7 +61403,7 @@ function numeric(a, b) {
|
|
|
61313
61403
|
return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
|
|
61314
61404
|
}
|
|
61315
61405
|
|
|
61316
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61406
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/columns/real.js
|
|
61317
61407
|
class SQLiteRealBuilder extends SQLiteColumnBuilder {
|
|
61318
61408
|
static [entityKind] = "SQLiteRealBuilder";
|
|
61319
61409
|
constructor(name) {
|
|
@@ -61334,7 +61424,7 @@ function real(name) {
|
|
|
61334
61424
|
return new SQLiteRealBuilder(name ?? "");
|
|
61335
61425
|
}
|
|
61336
61426
|
|
|
61337
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61427
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/columns/text.js
|
|
61338
61428
|
class SQLiteTextBuilder extends SQLiteColumnBuilder {
|
|
61339
61429
|
static [entityKind] = "SQLiteTextBuilder";
|
|
61340
61430
|
constructor(name, config2) {
|
|
@@ -61389,7 +61479,7 @@ function text(a, b = {}) {
|
|
|
61389
61479
|
return new SQLiteTextBuilder(name, config2);
|
|
61390
61480
|
}
|
|
61391
61481
|
|
|
61392
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61482
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/columns/all.js
|
|
61393
61483
|
function getSQLiteColumnBuilders() {
|
|
61394
61484
|
return {
|
|
61395
61485
|
blob,
|
|
@@ -61401,7 +61491,7 @@ function getSQLiteColumnBuilders() {
|
|
|
61401
61491
|
};
|
|
61402
61492
|
}
|
|
61403
61493
|
|
|
61404
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61494
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/table.js
|
|
61405
61495
|
var InlineForeignKeys = Symbol.for("drizzle:SQLiteInlineForeignKeys");
|
|
61406
61496
|
|
|
61407
61497
|
class SQLiteTable extends Table {
|
|
@@ -61435,7 +61525,7 @@ var sqliteTable = (name, columns, extraConfig) => {
|
|
|
61435
61525
|
return sqliteTableBase(name, columns, extraConfig);
|
|
61436
61526
|
};
|
|
61437
61527
|
|
|
61438
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61528
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/indexes.js
|
|
61439
61529
|
class IndexBuilderOn {
|
|
61440
61530
|
constructor(name, unique2) {
|
|
61441
61531
|
this.name = name;
|
|
@@ -61481,7 +61571,7 @@ function uniqueIndex(name) {
|
|
|
61481
61571
|
return new IndexBuilderOn(name, true);
|
|
61482
61572
|
}
|
|
61483
61573
|
|
|
61484
|
-
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.
|
|
61574
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.4_@cloudflare+workers-types@5.20261125.1_@opentelemetry+api@1.10.0_@ty_fa28369ca622e5aaa983ff44c7d551d0/node_modules/drizzle-orm/sqlite-core/primary-keys.js
|
|
61485
61575
|
function primaryKey(...config2) {
|
|
61486
61576
|
if (config2[0].columns) {
|
|
61487
61577
|
return new PrimaryKeyBuilder(config2[0].columns, config2[0].name);
|
|
@@ -62566,7 +62656,7 @@ var communityChannelDeleteSchema = exports_external.strictObject({
|
|
|
62566
62656
|
channelId: string4,
|
|
62567
62657
|
parentChannelId: nullableString.optional(),
|
|
62568
62658
|
parentMessageId: string4.optional()
|
|
62569
|
-
}).refine((event) => event.parentMessageId === undefined || typeof event.parentChannelId === "string" && event.parentChannelId.length > 0, {
|
|
62659
|
+
}).refine((event) => event.parentMessageId === undefined || typeof event.parentChannelId === "string" && event.parentChannelId.length > 0, { error: "parentMessageId requires parentChannelId" });
|
|
62570
62660
|
var positionedIdSchema = exports_external.strictObject({ id: string4, position: exports_external.number() });
|
|
62571
62661
|
var communityChannelReorderSchema = exports_external.strictObject({
|
|
62572
62662
|
type: exports_external.literal("community:channel.reorder"),
|
|
@@ -63181,6 +63271,7 @@ var communityScheduleRun = sqliteTable("community_schedule_run", {
|
|
|
63181
63271
|
status: text("status").$type().notNull(),
|
|
63182
63272
|
lastError: text("last_error"),
|
|
63183
63273
|
ackedAtMs: integer2("acked_at_ms"),
|
|
63274
|
+
ackResult: text("ack_result"),
|
|
63184
63275
|
createdAtMs: integer2("created_at_ms").notNull(),
|
|
63185
63276
|
updatedAtMs: integer2("updated_at_ms").notNull()
|
|
63186
63277
|
}, (t) => [
|
|
@@ -63299,6 +63390,10 @@ var viewerTicket = exports_external.strictObject({ userId: exports_external.stri
|
|
|
63299
63390
|
// ../shared/src/schedule.ts
|
|
63300
63391
|
var SCHEDULE_TITLE_MAX_LENGTH = 160;
|
|
63301
63392
|
var SCHEDULE_DESCRIPTION_MAX_LENGTH = 4000;
|
|
63393
|
+
var SCHEDULE_ACK_RESULT_MAX_BYTES = 1024;
|
|
63394
|
+
function utf8ByteLength2(value) {
|
|
63395
|
+
return new TextEncoder().encode(value).byteLength;
|
|
63396
|
+
}
|
|
63302
63397
|
var SCHEDULE_MIN_DURATION_MINUTES = 5;
|
|
63303
63398
|
var SCHEDULE_MAX_DURATION_MINUTES = 1440;
|
|
63304
63399
|
var SCHEDULE_MAX_RANGE_MS = 62 * 24 * 60 * 60 * 1000;
|
|
@@ -63348,6 +63443,7 @@ var ScheduleLastExecutionSchema = exports_external.strictObject({
|
|
|
63348
63443
|
status: ScheduleRunStatusSchema,
|
|
63349
63444
|
lastError: exports_external.string().nullable(),
|
|
63350
63445
|
ackedAt: exports_external.iso.datetime().nullable(),
|
|
63446
|
+
ackResult: exports_external.string().nullable().optional(),
|
|
63351
63447
|
updatedAt: exports_external.iso.datetime()
|
|
63352
63448
|
});
|
|
63353
63449
|
var ScheduleSourceMessageSchema = exports_external.strictObject({
|
|
@@ -63379,7 +63475,9 @@ var ScheduleOccurrenceSchema = exports_external.strictObject({
|
|
|
63379
63475
|
occurrenceKey: exports_external.string().min(1),
|
|
63380
63476
|
startAt: exports_external.iso.datetime(),
|
|
63381
63477
|
endAt: exports_external.iso.datetime(),
|
|
63382
|
-
runStatus: ScheduleOccurrenceStatusSchema
|
|
63478
|
+
runStatus: ScheduleOccurrenceStatusSchema,
|
|
63479
|
+
ackedAt: exports_external.iso.datetime().nullable().optional(),
|
|
63480
|
+
ackResult: exports_external.string().nullable().optional()
|
|
63383
63481
|
});
|
|
63384
63482
|
var ScheduleListResponseSchema = exports_external.strictObject({
|
|
63385
63483
|
events: exports_external.array(ScheduleEventSchema),
|
|
@@ -63395,6 +63493,7 @@ var ScheduleCreateRequestSchema = exports_external.strictObject({
|
|
|
63395
63493
|
recurrence: ScheduleRecurrenceSchema.nullable().optional(),
|
|
63396
63494
|
sourceMessageRef: exports_external.string().trim().min(1).max(512)
|
|
63397
63495
|
});
|
|
63496
|
+
var ScheduleAckResultSchema = exports_external.string().trim().min(1, "ackResult must not be empty").refine((value) => utf8ByteLength2(value) <= SCHEDULE_ACK_RESULT_MAX_BYTES, `ackResult must be at most ${SCHEDULE_ACK_RESULT_MAX_BYTES} UTF-8 bytes`);
|
|
63398
63497
|
var ScheduleUpdateRequestSchema = exports_external.strictObject({
|
|
63399
63498
|
title: exports_external.string().trim().min(1).max(SCHEDULE_TITLE_MAX_LENGTH).optional(),
|
|
63400
63499
|
description: exports_external.string().max(SCHEDULE_DESCRIPTION_MAX_LENGTH).optional(),
|
|
@@ -63403,7 +63502,16 @@ var ScheduleUpdateRequestSchema = exports_external.strictObject({
|
|
|
63403
63502
|
timeZone: exports_external.string().trim().min(1).max(128).optional(),
|
|
63404
63503
|
recurrence: ScheduleRecurrenceSchema.nullable().optional(),
|
|
63405
63504
|
sourceMessageRef: exports_external.string().trim().min(1).max(512).optional(),
|
|
63406
|
-
ack: exports_external.literal(true).optional()
|
|
63505
|
+
ack: exports_external.literal(true).optional(),
|
|
63506
|
+
ackResult: ScheduleAckResultSchema.optional()
|
|
63507
|
+
}).superRefine((value, ctx) => {
|
|
63508
|
+
if (value.ackResult !== undefined && value.ack !== true) {
|
|
63509
|
+
ctx.addIssue({
|
|
63510
|
+
code: "custom",
|
|
63511
|
+
path: ["ackResult"],
|
|
63512
|
+
message: "ackResult requires ack: true"
|
|
63513
|
+
});
|
|
63514
|
+
}
|
|
63407
63515
|
});
|
|
63408
63516
|
var formatterCache = new Map;
|
|
63409
63517
|
// ../shared/src/bot-webhook.ts
|
|
@@ -63582,7 +63690,7 @@ var BotWebhookUpdateSchema = exports_external.strictObject({
|
|
|
63582
63690
|
allowedSenders: BotImAllowedSendersSchema.optional(),
|
|
63583
63691
|
requireMentionInGroups: exports_external.boolean().optional(),
|
|
63584
63692
|
regeneratePairingCode: exports_external.boolean().optional()
|
|
63585
|
-
}).refine((v) => v.name !== undefined || v.enabled !== undefined || v.eventFilter !== undefined || v.instruction !== undefined || v.requireSecret !== undefined || v.signingSecret !== undefined || v.rotateCredentials === true || v.botToken !== undefined || v.feishuRegion !== undefined || v.feishuAppId !== undefined || v.feishuAppSecret !== undefined || v.feishuVerificationToken !== undefined || v.feishuEncryptKey !== undefined || v.accessPolicy !== undefined || v.allowedSenders !== undefined || v.requireMentionInGroups !== undefined || v.regeneratePairingCode === true, {
|
|
63693
|
+
}).refine((v) => v.name !== undefined || v.enabled !== undefined || v.eventFilter !== undefined || v.instruction !== undefined || v.requireSecret !== undefined || v.signingSecret !== undefined || v.rotateCredentials === true || v.botToken !== undefined || v.feishuRegion !== undefined || v.feishuAppId !== undefined || v.feishuAppSecret !== undefined || v.feishuVerificationToken !== undefined || v.feishuEncryptKey !== undefined || v.accessPolicy !== undefined || v.allowedSenders !== undefined || v.requireMentionInGroups !== undefined || v.regeneratePairingCode === true, { error: "At least one field must be provided" });
|
|
63586
63694
|
var BotWebhookCreateResponseSchema = exports_external.strictObject({
|
|
63587
63695
|
webhook: BotWebhookSummarySchema,
|
|
63588
63696
|
webhookUrl: exports_external.url().optional(),
|
|
@@ -78097,13 +78205,13 @@ function messagingSection() {
|
|
|
78097
78205
|
"",
|
|
78098
78206
|
"`--remind-after T` is required on every send and controls whether a local follow-up is " + "armed for the same channel, thread, or DM.",
|
|
78099
78207
|
"",
|
|
78100
|
-
"- Use `1m` to `24h` when silence would leave work unfinished — for example, after a question, " + "approval request, handoff, or blocker. If no newer message arrives by T, you will be reminded " + "to return; a newer message
|
|
78208
|
+
"- Use `1m` to `24h` when silence would leave work unfinished — for example, after a question, " + "approval request, handoff, or blocker. If no newer message arrives by T, you will be reminded " + "to return; a newer message cancels the timer. Daemon restarts preserve it.",
|
|
78101
78209
|
"- Use `0` only when no later action depends on a reply. It disables the timer.",
|
|
78102
78210
|
"",
|
|
78103
78211
|
"#### Schedule future or recurring work",
|
|
78104
78212
|
"",
|
|
78105
|
-
"- Use `--remind-after` (`1m` to `24h`) only to follow up when an active conversation goes quiet; a newer message
|
|
78106
|
-
`- Use \`${CLI} schedule\` for tasks that must run at a specific future time (>24h or across restarts/offline machines) or on a recurring cadence (\`hourly\`/\`daily\`/\`weekly\`/\`monthly\`), visible in Home -> Schedule. Always bind the request's message ref, and run \`--ack\` after finishing a triggered run.`,
|
|
78213
|
+
"- Use `--remind-after` (`1m` to `24h`) only to follow up when an active conversation goes quiet; a newer message cancels it.",
|
|
78214
|
+
`- Use \`${CLI} schedule\` for tasks that must run at a specific future time (>24h or across restarts/offline machines) or on a recurring cadence (\`hourly\`/\`daily\`/\`weekly\`/\`monthly\`), visible in Home -> Schedule. Always bind the request's message ref, and run \`--ack "<short result>"\` (<= 1 KiB UTF-8) after finishing a triggered run.`,
|
|
78107
78215
|
"",
|
|
78108
78216
|
"#### Sending mechanics",
|
|
78109
78217
|
"",
|
|
@@ -78290,9 +78398,9 @@ function cliCommandsSection() {
|
|
|
78290
78398
|
"",
|
|
78291
78399
|
"Your household shares one bot schedule visible to your owner in Home -> Schedule and to sibling bots. Every scheduled task binds to a concrete message ref.",
|
|
78292
78400
|
"",
|
|
78293
|
-
`1. \`${CLI} schedule list [--from <iso> --to <iso>] [--creator <handle>]\` — list scheduled tasks and, when \`--from\` and \`--to\` are given, expanded occurrences.`,
|
|
78401
|
+
`1. \`${CLI} schedule list [--from <iso> --to <iso>] [--creator <handle>]\` — list scheduled tasks and, when \`--from\` and \`--to\` are given (up to 62 days), expanded occurrences including past completed runs and their \`ackResult\` summaries.`,
|
|
78294
78402
|
`2. \`${CLI} schedule create --title <text> --at <iso> --message <ref> [--description <text>] [--tz <iana>] [--duration <minutes>] [--repeat <hourly|daily|weekly|monthly>] [--interval <n>] [--weekdays <days>] [--until <iso>] [--count <n>]\` — create a one-time or recurring task bound to a message you can read.`,
|
|
78295
|
-
`3. \`${CLI} schedule update <id> [fields...] [--message <ref>] [--ack]\` — update a task, or pass \`--ack\` after finishing the triggered run to mark it completed.`,
|
|
78403
|
+
`3. \`${CLI} schedule update <id> [fields...] [--message <ref>] [--ack "<short result>"]\` — update a task, or pass \`--ack "<short result>"\` (non-empty summary, max 1 KiB UTF-8) after finishing the triggered run to mark it completed and record its outcome.`,
|
|
78296
78404
|
`4. \`${CLI} schedule delete <id>\` — delete a scheduled task.`,
|
|
78297
78405
|
"",
|
|
78298
78406
|
"### Pages",
|
|
@@ -79107,6 +79215,9 @@ class AgentProcessManager {
|
|
|
79107
79215
|
const session2 = this.sessions.get(agentId);
|
|
79108
79216
|
if (!session2)
|
|
79109
79217
|
return;
|
|
79218
|
+
const owner = this.activeSpawnState.get(agentId);
|
|
79219
|
+
if (owner)
|
|
79220
|
+
owner.terminationSemantics = "owner_request";
|
|
79110
79221
|
this.abortCurrentTurn(agentId, "requested_stop");
|
|
79111
79222
|
await session2.stop({ reason: "owner_request", forceAfterMs: SESSION_STOP_GRACE_MS2 });
|
|
79112
79223
|
if (this.sessions.get(agentId) === session2)
|
|
@@ -79173,6 +79284,12 @@ class AgentProcessManager {
|
|
|
79173
79284
|
snapshot() {
|
|
79174
79285
|
return this.state;
|
|
79175
79286
|
}
|
|
79287
|
+
interruptedTurns() {
|
|
79288
|
+
return Object.values(this.state.agents).filter((agent) => {
|
|
79289
|
+
const owner = this.activeSpawnState.get(agent.agentId);
|
|
79290
|
+
return agent.turnActive && !agent.recoveryAttempted && !agent.resetting && !owner?.discardEvents && !["owner_request", "idle_stop", "force_exit"].includes(owner?.terminationSemantics ?? "");
|
|
79291
|
+
}).map(({ agentId, sessionId }) => ({ agentId, sessionId }));
|
|
79292
|
+
}
|
|
79176
79293
|
runningAgentCount() {
|
|
79177
79294
|
return this.sessions.size;
|
|
79178
79295
|
}
|
|
@@ -79661,6 +79778,8 @@ ${this.opts.wakePromptFooter}` : text7;
|
|
|
79661
79778
|
});
|
|
79662
79779
|
}
|
|
79663
79780
|
if (effect.type === "terminate_stalled" && spawnState) {
|
|
79781
|
+
if (this.state.agents[effect.agentId]?.turnActive)
|
|
79782
|
+
spawnState.hadActiveTurnAtInterrupt = true;
|
|
79664
79783
|
this.closeTurn(spawnState, spawnState.activeSpan, {
|
|
79665
79784
|
event: "turn_abort",
|
|
79666
79785
|
abortCause: "terminate_stalled"
|
|
@@ -79835,6 +79954,7 @@ ${this.opts.wakePromptFooter}` : text7;
|
|
|
79835
79954
|
stalledSessionIdAtLaunch,
|
|
79836
79955
|
spawnFailureReason: null,
|
|
79837
79956
|
terminationSemantics: null,
|
|
79957
|
+
hadActiveTurnAtInterrupt: false,
|
|
79838
79958
|
spawnOrdinal: this.nextSpawnOrdinal++,
|
|
79839
79959
|
launchIdSnapshot: typeof ctx.launchId === "string" && ctx.launchId.length > 0 ? ctx.launchId : null,
|
|
79840
79960
|
nextTurnOrdinal: 1,
|
|
@@ -79892,6 +80012,7 @@ ${this.opts.wakePromptFooter}` : text7;
|
|
|
79892
80012
|
const exitSignal = "signal" in result2 ? result2.signal ?? null : null;
|
|
79893
80013
|
const requested = "requested" in result2 && result2.requested === true;
|
|
79894
80014
|
const abnormal = !requested && (exitSignal !== null || exitCode !== null && exitCode !== 0);
|
|
80015
|
+
const interrupted = !this.shuttingDown && state.hasEstablished && !state.superseded && !state.discardEvents && (state.hadActiveTurnAtInterrupt || this.state.agents[agentId]?.turnActive === true) && (state.terminationSemantics === "killed_stalled" || result2.outcome === "crashed" && state.terminationSemantics === null);
|
|
79895
80016
|
if (state.hasEstablished && !state.suppressExitLog) {
|
|
79896
80017
|
this.logSessionEnded(agentId, "exit");
|
|
79897
80018
|
if (abnormal) {
|
|
@@ -79920,7 +80041,9 @@ ${this.opts.wakePromptFooter}` : text7;
|
|
|
79920
80041
|
exitSignal,
|
|
79921
80042
|
abnormal,
|
|
79922
80043
|
spawnFailureReason: state.spawnFailureReason,
|
|
79923
|
-
terminationSemantics: state.terminationSemantics
|
|
80044
|
+
terminationSemantics: state.terminationSemantics,
|
|
80045
|
+
interrupted,
|
|
80046
|
+
nowMs: this.now()
|
|
79924
80047
|
}, state);
|
|
79925
80048
|
};
|
|
79926
80049
|
const onEvent = (event) => {
|
|
@@ -79934,8 +80057,12 @@ ${this.opts.wakePromptFooter}` : text7;
|
|
|
79934
80057
|
this.onAgentEvent(agentId, event, driver.id, state);
|
|
79935
80058
|
return;
|
|
79936
80059
|
}
|
|
79937
|
-
if (event.type === "session_failed"
|
|
79938
|
-
|
|
80060
|
+
if (event.type === "session_failed") {
|
|
80061
|
+
if (this.state.agents[agentId]?.turnActive)
|
|
80062
|
+
state.hadActiveTurnAtInterrupt = true;
|
|
80063
|
+
if (!state.hasEstablished) {
|
|
80064
|
+
reportSpawnFailure(event.error.code || "failed_to_start", { message: event.error.message });
|
|
80065
|
+
}
|
|
79939
80066
|
}
|
|
79940
80067
|
if (event.type === "session_started") {
|
|
79941
80068
|
const persisted = this.opts.timeline?.setSession(agentId, event.backendSessionId, event.sessionInstanceId);
|
|
@@ -80541,6 +80668,12 @@ class AgentRouter {
|
|
|
80541
80668
|
this.log.info("agent removed from running set (local stop)", { agentId });
|
|
80542
80669
|
this.scheduleReadyFrameResend();
|
|
80543
80670
|
}
|
|
80671
|
+
markLocallyStarted(agentId) {
|
|
80672
|
+
if (this.running.has(agentId))
|
|
80673
|
+
return;
|
|
80674
|
+
this.running.add(agentId);
|
|
80675
|
+
this.scheduleReadyFrameResend();
|
|
80676
|
+
}
|
|
80544
80677
|
scheduleReadyFrameResend() {
|
|
80545
80678
|
if (this.pendingResend)
|
|
80546
80679
|
return;
|
|
@@ -84907,23 +85040,67 @@ class ImConnectorManager {
|
|
|
84907
85040
|
}
|
|
84908
85041
|
|
|
84909
85042
|
// src/daemon/createDaemon.ts
|
|
84910
|
-
import { appendFileSync as appendFileSync2, mkdirSync as
|
|
85043
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync11, readFileSync as readFileSync11 } from "node:fs";
|
|
85044
|
+
import { join as join26 } from "node:path";
|
|
85045
|
+
|
|
85046
|
+
// src/cli/privateJsonFile.ts
|
|
85047
|
+
import * as fs7 from "node:fs";
|
|
85048
|
+
import * as path16 from "node:path";
|
|
85049
|
+
import * as crypto4 from "node:crypto";
|
|
85050
|
+
function ensurePrivateDir(dir) {
|
|
85051
|
+
fs7.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
85052
|
+
fs7.chmodSync(dir, 448);
|
|
85053
|
+
}
|
|
85054
|
+
function syncDirectory(dir) {
|
|
85055
|
+
if (process.platform === "win32")
|
|
85056
|
+
return;
|
|
85057
|
+
const fd = fs7.openSync(dir, "r");
|
|
85058
|
+
try {
|
|
85059
|
+
fs7.fsyncSync(fd);
|
|
85060
|
+
} finally {
|
|
85061
|
+
fs7.closeSync(fd);
|
|
85062
|
+
}
|
|
85063
|
+
}
|
|
85064
|
+
function writePrivateJsonAtomic(filePath, value) {
|
|
85065
|
+
const dir = path16.dirname(filePath);
|
|
85066
|
+
ensurePrivateDir(dir);
|
|
85067
|
+
const tempPath = path16.join(dir, `.${path16.basename(filePath)}.${process.pid}.${crypto4.randomBytes(12).toString("hex")}.tmp`);
|
|
85068
|
+
let fd = fs7.openSync(tempPath, "wx", 384);
|
|
85069
|
+
try {
|
|
85070
|
+
fs7.writeFileSync(fd, JSON.stringify(value));
|
|
85071
|
+
fs7.fsyncSync(fd);
|
|
85072
|
+
fs7.closeSync(fd);
|
|
85073
|
+
fd = null;
|
|
85074
|
+
fs7.chmodSync(tempPath, 384);
|
|
85075
|
+
fs7.renameSync(tempPath, filePath);
|
|
85076
|
+
syncDirectory(dir);
|
|
85077
|
+
} finally {
|
|
85078
|
+
if (fd !== null) {
|
|
85079
|
+
try {
|
|
85080
|
+
fs7.closeSync(fd);
|
|
85081
|
+
} catch {}
|
|
85082
|
+
}
|
|
85083
|
+
try {
|
|
85084
|
+
fs7.unlinkSync(tempPath);
|
|
85085
|
+
} catch {}
|
|
85086
|
+
}
|
|
85087
|
+
}
|
|
84911
85088
|
|
|
84912
85089
|
// src/util/rotatingFileSink.ts
|
|
84913
85090
|
import {
|
|
84914
85091
|
appendFileSync,
|
|
84915
|
-
chmodSync as
|
|
84916
|
-
closeSync as
|
|
85092
|
+
chmodSync as chmodSync4,
|
|
85093
|
+
closeSync as closeSync3,
|
|
84917
85094
|
constants as constants4,
|
|
84918
85095
|
existsSync as existsSync8,
|
|
84919
85096
|
fstatSync as fstatSync2,
|
|
84920
85097
|
lstatSync as lstatSync3,
|
|
84921
|
-
openSync as
|
|
84922
|
-
renameSync as
|
|
85098
|
+
openSync as openSync3,
|
|
85099
|
+
renameSync as renameSync5,
|
|
84923
85100
|
statSync as statSync4,
|
|
84924
|
-
unlinkSync as
|
|
85101
|
+
unlinkSync as unlinkSync4
|
|
84925
85102
|
} from "node:fs";
|
|
84926
|
-
function createRotatingFileSink(
|
|
85103
|
+
function createRotatingFileSink(path17, maxBytes, opts = {}) {
|
|
84927
85104
|
const report = (operation, error62) => {
|
|
84928
85105
|
try {
|
|
84929
85106
|
opts.onError?.({ operation, error: error62 });
|
|
@@ -84941,10 +85118,10 @@ function createRotatingFileSink(path16, maxBytes, opts = {}) {
|
|
|
84941
85118
|
return false;
|
|
84942
85119
|
}
|
|
84943
85120
|
if (opts.mode !== undefined)
|
|
84944
|
-
|
|
85121
|
+
chmodSync4(filePath, opts.mode);
|
|
84945
85122
|
if (opts.hardMaxBytes && maxBytes > 0 && stat2.size > maxBytes) {
|
|
84946
85123
|
try {
|
|
84947
|
-
|
|
85124
|
+
unlinkSync4(filePath);
|
|
84948
85125
|
} catch (error62) {
|
|
84949
85126
|
report("oversize_generation", error62);
|
|
84950
85127
|
return false;
|
|
@@ -84959,9 +85136,9 @@ function createRotatingFileSink(path16, maxBytes, opts = {}) {
|
|
|
84959
85136
|
};
|
|
84960
85137
|
const rotate = () => {
|
|
84961
85138
|
try {
|
|
84962
|
-
|
|
85139
|
+
renameSync5(path17, `${path17}.1`);
|
|
84963
85140
|
if (opts.mode !== undefined)
|
|
84964
|
-
|
|
85141
|
+
chmodSync4(`${path17}.1`, opts.mode);
|
|
84965
85142
|
return true;
|
|
84966
85143
|
} catch (error62) {
|
|
84967
85144
|
report("rotate", error62);
|
|
@@ -84970,7 +85147,7 @@ function createRotatingFileSink(path16, maxBytes, opts = {}) {
|
|
|
84970
85147
|
};
|
|
84971
85148
|
const currentSize = () => {
|
|
84972
85149
|
try {
|
|
84973
|
-
return existsSync8(
|
|
85150
|
+
return existsSync8(path17) ? statSync4(path17).size : 0;
|
|
84974
85151
|
} catch (error62) {
|
|
84975
85152
|
report("stat", error62);
|
|
84976
85153
|
return null;
|
|
@@ -84978,7 +85155,7 @@ function createRotatingFileSink(path16, maxBytes, opts = {}) {
|
|
|
84978
85155
|
};
|
|
84979
85156
|
const sink = {
|
|
84980
85157
|
secure() {
|
|
84981
|
-
return secureGeneration(`${
|
|
85158
|
+
return secureGeneration(`${path17}.1`) && secureGeneration(path17);
|
|
84982
85159
|
},
|
|
84983
85160
|
write(line) {
|
|
84984
85161
|
try {
|
|
@@ -84998,7 +85175,7 @@ function createRotatingFileSink(path16, maxBytes, opts = {}) {
|
|
|
84998
85175
|
const shouldRotate = maxBytes > 0 && (opts.hardMaxBytes ? currentBytes > 0 && currentBytes + serializedBytes > maxBytes : currentBytes >= maxBytes);
|
|
84999
85176
|
if (shouldRotate && !rotate() && opts.hardMaxBytes)
|
|
85000
85177
|
return;
|
|
85001
|
-
appendFileSync(
|
|
85178
|
+
appendFileSync(path17, serialized, opts.mode === undefined ? undefined : { mode: opts.mode });
|
|
85002
85179
|
} catch (error62) {
|
|
85003
85180
|
report("append", error62);
|
|
85004
85181
|
}
|
|
@@ -85006,27 +85183,27 @@ function createRotatingFileSink(path16, maxBytes, opts = {}) {
|
|
|
85006
85183
|
openSnapshot() {
|
|
85007
85184
|
const files = [];
|
|
85008
85185
|
try {
|
|
85009
|
-
for (const candidate of [`${
|
|
85186
|
+
for (const candidate of [`${path17}.1`, path17]) {
|
|
85010
85187
|
if (!existsSync8(candidate))
|
|
85011
85188
|
continue;
|
|
85012
85189
|
if (!secureGeneration(candidate))
|
|
85013
85190
|
continue;
|
|
85014
85191
|
const noFollow = "O_NOFOLLOW" in constants4 ? constants4.O_NOFOLLOW : 0;
|
|
85015
|
-
const fd =
|
|
85192
|
+
const fd = openSync3(candidate, constants4.O_RDONLY | noFollow);
|
|
85016
85193
|
try {
|
|
85017
85194
|
const stat2 = fstatSync2(fd);
|
|
85018
85195
|
if (!stat2.isFile())
|
|
85019
85196
|
throw new Error("snapshot source is not a regular file");
|
|
85020
85197
|
files.push({ path: candidate, fd, size: stat2.size });
|
|
85021
85198
|
} catch (error62) {
|
|
85022
|
-
|
|
85199
|
+
closeSync3(fd);
|
|
85023
85200
|
throw error62;
|
|
85024
85201
|
}
|
|
85025
85202
|
}
|
|
85026
85203
|
} catch (error62) {
|
|
85027
85204
|
for (const file2 of files) {
|
|
85028
85205
|
try {
|
|
85029
|
-
|
|
85206
|
+
closeSync3(file2.fd);
|
|
85030
85207
|
} catch {}
|
|
85031
85208
|
}
|
|
85032
85209
|
report("snapshot", error62);
|
|
@@ -85041,7 +85218,7 @@ function createRotatingFileSink(path16, maxBytes, opts = {}) {
|
|
|
85041
85218
|
closed = true;
|
|
85042
85219
|
for (const file2 of files) {
|
|
85043
85220
|
try {
|
|
85044
|
-
|
|
85221
|
+
closeSync3(file2.fd);
|
|
85045
85222
|
} catch {}
|
|
85046
85223
|
}
|
|
85047
85224
|
}
|
|
@@ -85166,12 +85343,12 @@ function createTraceSampler(emit, throttleMs = DEFAULT_TRACE_SAMPLE_MS) {
|
|
|
85166
85343
|
}
|
|
85167
85344
|
|
|
85168
85345
|
// src/util/statusFile.ts
|
|
85169
|
-
import { writeFileSync as
|
|
85170
|
-
function writeStatusFile(
|
|
85346
|
+
import { writeFileSync as writeFileSync9, renameSync as renameSync6 } from "node:fs";
|
|
85347
|
+
function writeStatusFile(path17, snapshot) {
|
|
85171
85348
|
try {
|
|
85172
|
-
const tmp = `${
|
|
85173
|
-
|
|
85174
|
-
|
|
85349
|
+
const tmp = `${path17}.tmp`;
|
|
85350
|
+
writeFileSync9(tmp, JSON.stringify(snapshot));
|
|
85351
|
+
renameSync6(tmp, path17);
|
|
85175
85352
|
} catch {}
|
|
85176
85353
|
}
|
|
85177
85354
|
|
|
@@ -85900,12 +86077,12 @@ class WsControlChannel {
|
|
|
85900
86077
|
}
|
|
85901
86078
|
}
|
|
85902
86079
|
// src/timeline/timeline.ts
|
|
85903
|
-
import * as
|
|
85904
|
-
import { createHash as createHash6, randomBytes as
|
|
85905
|
-
import { basename, dirname as
|
|
86080
|
+
import * as fs9 from "node:fs";
|
|
86081
|
+
import { createHash as createHash6, randomBytes as randomBytes10 } from "node:crypto";
|
|
86082
|
+
import { basename as basename2, dirname as dirname6, join as join21 } from "node:path";
|
|
85906
86083
|
|
|
85907
86084
|
// src/timeline/filelock.ts
|
|
85908
|
-
import * as
|
|
86085
|
+
import * as fs8 from "fs";
|
|
85909
86086
|
var DEFAULT_STALE_MS = 30000;
|
|
85910
86087
|
var META = "meta.json";
|
|
85911
86088
|
function acquireLock(lockPath, staleMs = DEFAULT_STALE_MS) {
|
|
@@ -85924,7 +86101,7 @@ function acquireLock(lockPath, staleMs = DEFAULT_STALE_MS) {
|
|
|
85924
86101
|
}
|
|
85925
86102
|
function releaseLock(lockPath) {
|
|
85926
86103
|
try {
|
|
85927
|
-
|
|
86104
|
+
fs8.rmSync(lockPath, { recursive: true, force: true });
|
|
85928
86105
|
} catch {}
|
|
85929
86106
|
}
|
|
85930
86107
|
function lockPathFor(dir, filename) {
|
|
@@ -85932,7 +86109,7 @@ function lockPathFor(dir, filename) {
|
|
|
85932
86109
|
}
|
|
85933
86110
|
function tryMkdir(lockPath) {
|
|
85934
86111
|
try {
|
|
85935
|
-
|
|
86112
|
+
fs8.mkdirSync(lockPath);
|
|
85936
86113
|
return true;
|
|
85937
86114
|
} catch (err) {
|
|
85938
86115
|
if (err.code === "EEXIST")
|
|
@@ -85942,25 +86119,25 @@ function tryMkdir(lockPath) {
|
|
|
85942
86119
|
}
|
|
85943
86120
|
function writeMeta(lockPath) {
|
|
85944
86121
|
try {
|
|
85945
|
-
|
|
86122
|
+
fs8.writeFileSync(`${lockPath}/${META}`, JSON.stringify({ pid: process.pid, acquiredAt: Date.now() }));
|
|
85946
86123
|
} catch {}
|
|
85947
86124
|
}
|
|
85948
86125
|
function isStale(lockPath, staleMs) {
|
|
85949
86126
|
try {
|
|
85950
|
-
const raw =
|
|
86127
|
+
const raw = fs8.readFileSync(`${lockPath}/${META}`, "utf8");
|
|
85951
86128
|
const acquiredAt = JSON.parse(raw).acquiredAt;
|
|
85952
86129
|
if (typeof acquiredAt === "number")
|
|
85953
86130
|
return Date.now() - acquiredAt > staleMs;
|
|
85954
86131
|
} catch {}
|
|
85955
86132
|
try {
|
|
85956
|
-
return Date.now() -
|
|
86133
|
+
return Date.now() - fs8.statSync(lockPath).mtimeMs > staleMs;
|
|
85957
86134
|
} catch {
|
|
85958
86135
|
return false;
|
|
85959
86136
|
}
|
|
85960
86137
|
}
|
|
85961
86138
|
function reclaim(lockPath) {
|
|
85962
86139
|
try {
|
|
85963
|
-
|
|
86140
|
+
fs8.rmSync(lockPath, { recursive: true, force: true });
|
|
85964
86141
|
} catch {}
|
|
85965
86142
|
}
|
|
85966
86143
|
|
|
@@ -86019,7 +86196,7 @@ function timelineRowHash(line) {
|
|
|
86019
86196
|
}
|
|
86020
86197
|
function timelineFileGeneration(filePath, lines) {
|
|
86021
86198
|
try {
|
|
86022
|
-
const stat2 =
|
|
86199
|
+
const stat2 = fs9.lstatSync(filePath, { bigint: true });
|
|
86023
86200
|
if (!stat2.isFile())
|
|
86024
86201
|
return null;
|
|
86025
86202
|
const digest = createHash6("sha256");
|
|
@@ -86081,18 +86258,18 @@ function compactLines(input2) {
|
|
|
86081
86258
|
}
|
|
86082
86259
|
return suffix;
|
|
86083
86260
|
}
|
|
86084
|
-
function isRealDirectory(
|
|
86261
|
+
function isRealDirectory(path17) {
|
|
86085
86262
|
try {
|
|
86086
|
-
return
|
|
86263
|
+
return fs9.lstatSync(path17).isDirectory();
|
|
86087
86264
|
} catch {
|
|
86088
86265
|
return false;
|
|
86089
86266
|
}
|
|
86090
86267
|
}
|
|
86091
86268
|
function timelineDirectoryState(timelineDir) {
|
|
86092
|
-
if (!isRealDirectory(
|
|
86269
|
+
if (!isRealDirectory(dirname6(timelineDir)))
|
|
86093
86270
|
return "unsafe";
|
|
86094
86271
|
try {
|
|
86095
|
-
return
|
|
86272
|
+
return fs9.lstatSync(timelineDir).isDirectory() ? "safe" : "unsafe";
|
|
86096
86273
|
} catch (error62) {
|
|
86097
86274
|
return error62.code === "ENOENT" ? "missing" : "unsafe";
|
|
86098
86275
|
}
|
|
@@ -86104,7 +86281,7 @@ function prepareTimelineDirectory(timelineDir) {
|
|
|
86104
86281
|
if (state === "unsafe")
|
|
86105
86282
|
return false;
|
|
86106
86283
|
try {
|
|
86107
|
-
|
|
86284
|
+
fs9.mkdirSync(timelineDir);
|
|
86108
86285
|
} catch (error62) {
|
|
86109
86286
|
if (error62.code !== "EEXIST")
|
|
86110
86287
|
return false;
|
|
@@ -86114,7 +86291,7 @@ function prepareTimelineDirectory(timelineDir) {
|
|
|
86114
86291
|
function scanTimelineFile(filePath) {
|
|
86115
86292
|
let source;
|
|
86116
86293
|
try {
|
|
86117
|
-
source =
|
|
86294
|
+
source = fs9.lstatSync(filePath);
|
|
86118
86295
|
} catch (error62) {
|
|
86119
86296
|
return error62.code === "ENOENT" ? [] : null;
|
|
86120
86297
|
}
|
|
@@ -86122,8 +86299,8 @@ function scanTimelineFile(filePath) {
|
|
|
86122
86299
|
return null;
|
|
86123
86300
|
let fd = null;
|
|
86124
86301
|
try {
|
|
86125
|
-
fd =
|
|
86126
|
-
const stat2 =
|
|
86302
|
+
fd = fs9.openSync(filePath, fs9.constants.O_RDONLY | (fs9.constants.O_NOFOLLOW ?? 0));
|
|
86303
|
+
const stat2 = fs9.fstatSync(fd);
|
|
86127
86304
|
if (!stat2.isFile())
|
|
86128
86305
|
return null;
|
|
86129
86306
|
const chunk2 = Buffer.allocUnsafe(TIMELINE_READ_CHUNK_BYTES);
|
|
@@ -86139,7 +86316,7 @@ function scanTimelineFile(filePath) {
|
|
|
86139
86316
|
let discardIncompleteTail = false;
|
|
86140
86317
|
if (stat2.size > 0) {
|
|
86141
86318
|
const last = Buffer.allocUnsafe(1);
|
|
86142
|
-
|
|
86319
|
+
fs9.readSync(fd, last, 0, 1, stat2.size - 1);
|
|
86143
86320
|
discardIncompleteTail = last[0] !== 10;
|
|
86144
86321
|
}
|
|
86145
86322
|
const resetPhysicalLine = () => {
|
|
@@ -86204,7 +86381,7 @@ function scanTimelineFile(filePath) {
|
|
|
86204
86381
|
const requested = position2 - start;
|
|
86205
86382
|
let count = 0;
|
|
86206
86383
|
while (count < requested) {
|
|
86207
|
-
const read =
|
|
86384
|
+
const read = fs9.readSync(fd, chunk2, count, requested - count, start + count);
|
|
86208
86385
|
if (read <= 0)
|
|
86209
86386
|
break;
|
|
86210
86387
|
count += read;
|
|
@@ -86240,35 +86417,35 @@ function scanTimelineFile(filePath) {
|
|
|
86240
86417
|
} finally {
|
|
86241
86418
|
if (fd !== null) {
|
|
86242
86419
|
try {
|
|
86243
|
-
|
|
86420
|
+
fs9.closeSync(fd);
|
|
86244
86421
|
} catch {}
|
|
86245
86422
|
}
|
|
86246
86423
|
}
|
|
86247
86424
|
}
|
|
86248
86425
|
function atomicReplaceTimeline(filePath, lines) {
|
|
86249
|
-
const tempPath =
|
|
86426
|
+
const tempPath = join21(dirname6(filePath), `.${basename2(filePath)}.${process.pid}.${randomBytes10(12).toString("hex")}.tmp`);
|
|
86250
86427
|
let fd = null;
|
|
86251
86428
|
try {
|
|
86252
|
-
fd =
|
|
86429
|
+
fd = fs9.openSync(tempPath, "wx", 384);
|
|
86253
86430
|
const body = lines.map((line) => line.text).join(`
|
|
86254
86431
|
`) + (lines.length > 0 ? `
|
|
86255
86432
|
` : "");
|
|
86256
|
-
|
|
86257
|
-
|
|
86258
|
-
|
|
86433
|
+
fs9.writeFileSync(fd, body, "utf8");
|
|
86434
|
+
fs9.fsyncSync(fd);
|
|
86435
|
+
fs9.closeSync(fd);
|
|
86259
86436
|
fd = null;
|
|
86260
|
-
|
|
86437
|
+
fs9.renameSync(tempPath, filePath);
|
|
86261
86438
|
return true;
|
|
86262
86439
|
} catch {
|
|
86263
86440
|
return false;
|
|
86264
86441
|
} finally {
|
|
86265
86442
|
if (fd !== null) {
|
|
86266
86443
|
try {
|
|
86267
|
-
|
|
86444
|
+
fs9.closeSync(fd);
|
|
86268
86445
|
} catch {}
|
|
86269
86446
|
}
|
|
86270
86447
|
try {
|
|
86271
|
-
|
|
86448
|
+
fs9.unlinkSync(tempPath);
|
|
86272
86449
|
} catch {}
|
|
86273
86450
|
}
|
|
86274
86451
|
}
|
|
@@ -86330,7 +86507,7 @@ function readRecentEntries(timelineDir, opts = {}) {
|
|
|
86330
86507
|
const filenames = recentFilenames(maxDays, now).reverse();
|
|
86331
86508
|
const entries = [];
|
|
86332
86509
|
for (const filename of filenames) {
|
|
86333
|
-
entries.push(...readJsonl(
|
|
86510
|
+
entries.push(...readJsonl(join21(timelineDir, filename)));
|
|
86334
86511
|
}
|
|
86335
86512
|
return entries;
|
|
86336
86513
|
}
|
|
@@ -86340,10 +86517,10 @@ function validPendingIdleResetEvents(value) {
|
|
|
86340
86517
|
function readResumeControlState(timelineDir) {
|
|
86341
86518
|
if (timelineDirectoryState(timelineDir) !== "safe")
|
|
86342
86519
|
return { kind: "missing" };
|
|
86343
|
-
const filePath =
|
|
86520
|
+
const filePath = join21(timelineDir, RESUME_CONTROL_FILENAME);
|
|
86344
86521
|
let source;
|
|
86345
86522
|
try {
|
|
86346
|
-
source =
|
|
86523
|
+
source = fs9.lstatSync(filePath);
|
|
86347
86524
|
} catch (error62) {
|
|
86348
86525
|
return error62.code === "ENOENT" ? { kind: "missing" } : { kind: "invalid" };
|
|
86349
86526
|
}
|
|
@@ -86352,15 +86529,15 @@ function readResumeControlState(timelineDir) {
|
|
|
86352
86529
|
}
|
|
86353
86530
|
let fd = null;
|
|
86354
86531
|
try {
|
|
86355
|
-
fd =
|
|
86356
|
-
const stat2 =
|
|
86532
|
+
fd = fs9.openSync(filePath, fs9.constants.O_RDONLY | (fs9.constants.O_NOFOLLOW ?? 0));
|
|
86533
|
+
const stat2 = fs9.fstatSync(fd);
|
|
86357
86534
|
if (!stat2.isFile() || stat2.size <= 0 || stat2.size > RESUME_CONTROL_MAX_BYTES) {
|
|
86358
86535
|
return { kind: "invalid" };
|
|
86359
86536
|
}
|
|
86360
86537
|
const bounded = Buffer.allocUnsafe(stat2.size + 1);
|
|
86361
86538
|
let bytesRead = 0;
|
|
86362
86539
|
while (bytesRead < bounded.length) {
|
|
86363
|
-
const count =
|
|
86540
|
+
const count = fs9.readSync(fd, bounded, bytesRead, bounded.length - bytesRead, bytesRead);
|
|
86364
86541
|
if (count <= 0)
|
|
86365
86542
|
break;
|
|
86366
86543
|
bytesRead += count;
|
|
@@ -86388,7 +86565,7 @@ function readResumeControlState(timelineDir) {
|
|
|
86388
86565
|
} finally {
|
|
86389
86566
|
if (fd !== null) {
|
|
86390
86567
|
try {
|
|
86391
|
-
|
|
86568
|
+
fs9.closeSync(fd);
|
|
86392
86569
|
} catch {}
|
|
86393
86570
|
}
|
|
86394
86571
|
}
|
|
@@ -86416,25 +86593,25 @@ function updateResumeControlState(timelineDir, update) {
|
|
|
86416
86593
|
`;
|
|
86417
86594
|
if (Buffer.byteLength(body, "utf8") > RESUME_CONTROL_MAX_BYTES)
|
|
86418
86595
|
return false;
|
|
86419
|
-
const filePath =
|
|
86420
|
-
const tempPath =
|
|
86596
|
+
const filePath = join21(timelineDir, RESUME_CONTROL_FILENAME);
|
|
86597
|
+
const tempPath = join21(timelineDir, `.${RESUME_CONTROL_FILENAME}.${process.pid}.${randomBytes10(12).toString("hex")}.tmp`);
|
|
86421
86598
|
let fd = null;
|
|
86422
86599
|
try {
|
|
86423
|
-
fd =
|
|
86424
|
-
|
|
86425
|
-
|
|
86426
|
-
|
|
86600
|
+
fd = fs9.openSync(tempPath, "wx", 384);
|
|
86601
|
+
fs9.writeFileSync(fd, body, "utf8");
|
|
86602
|
+
fs9.fsyncSync(fd);
|
|
86603
|
+
fs9.closeSync(fd);
|
|
86427
86604
|
fd = null;
|
|
86428
|
-
|
|
86605
|
+
fs9.renameSync(tempPath, filePath);
|
|
86429
86606
|
return true;
|
|
86430
86607
|
} finally {
|
|
86431
86608
|
if (fd !== null) {
|
|
86432
86609
|
try {
|
|
86433
|
-
|
|
86610
|
+
fs9.closeSync(fd);
|
|
86434
86611
|
} catch {}
|
|
86435
86612
|
}
|
|
86436
86613
|
try {
|
|
86437
|
-
|
|
86614
|
+
fs9.unlinkSync(tempPath);
|
|
86438
86615
|
} catch {}
|
|
86439
86616
|
}
|
|
86440
86617
|
} catch {
|
|
@@ -86447,7 +86624,7 @@ function appendTrackedEntry(timelineDir, entry, now = new Date) {
|
|
|
86447
86624
|
if (timelineDirectoryState(timelineDir) !== "safe")
|
|
86448
86625
|
return { status: "rejected", reason: "unsafe" };
|
|
86449
86626
|
const filename = filenameForDate(now);
|
|
86450
|
-
const filePath =
|
|
86627
|
+
const filePath = join21(timelineDir, filename);
|
|
86451
86628
|
const lockPath = lockPathFor(timelineDir, filename);
|
|
86452
86629
|
try {
|
|
86453
86630
|
if (!acquireLock(lockPath))
|
|
@@ -86472,10 +86649,10 @@ function appendTrackedEntry(timelineDir, entry, now = new Date) {
|
|
|
86472
86649
|
function updateTrackedEntry(timelineDir, handle3, update) {
|
|
86473
86650
|
if (timelineDirectoryState(timelineDir) !== "safe")
|
|
86474
86651
|
return { status: "rejected", reason: "unsafe" };
|
|
86475
|
-
if (!DATE_FILENAME_PATTERN.test(handle3.filename) ||
|
|
86652
|
+
if (!DATE_FILENAME_PATTERN.test(handle3.filename) || basename2(handle3.filename) !== handle3.filename) {
|
|
86476
86653
|
return { status: "rejected", reason: "unsafe" };
|
|
86477
86654
|
}
|
|
86478
|
-
const filePath =
|
|
86655
|
+
const filePath = join21(timelineDir, handle3.filename);
|
|
86479
86656
|
const lockPath = lockPathFor(timelineDir, handle3.filename);
|
|
86480
86657
|
try {
|
|
86481
86658
|
if (!acquireLock(lockPath))
|
|
@@ -86529,28 +86706,28 @@ async function sweepTimelineHistory(workingDirectoryBase, opts = {}) {
|
|
|
86529
86706
|
return;
|
|
86530
86707
|
let agentNames;
|
|
86531
86708
|
try {
|
|
86532
|
-
agentNames =
|
|
86709
|
+
agentNames = fs9.readdirSync(workingDirectoryBase).sort();
|
|
86533
86710
|
} catch {
|
|
86534
86711
|
return;
|
|
86535
86712
|
}
|
|
86536
86713
|
for (const agentName of agentNames) {
|
|
86537
|
-
const agentDir =
|
|
86714
|
+
const agentDir = join21(workingDirectoryBase, agentName);
|
|
86538
86715
|
if (!isRealDirectory(agentDir))
|
|
86539
86716
|
continue;
|
|
86540
|
-
const timelineDir =
|
|
86717
|
+
const timelineDir = join21(agentDir, ".context_timeline");
|
|
86541
86718
|
if (!isRealDirectory(timelineDir))
|
|
86542
86719
|
continue;
|
|
86543
86720
|
let filenames;
|
|
86544
86721
|
try {
|
|
86545
|
-
filenames =
|
|
86722
|
+
filenames = fs9.readdirSync(timelineDir).filter((name) => DATE_FILENAME_PATTERN.test(name)).sort();
|
|
86546
86723
|
} catch {
|
|
86547
86724
|
continue;
|
|
86548
86725
|
}
|
|
86549
86726
|
for (const filename of filenames) {
|
|
86550
|
-
const filePath =
|
|
86727
|
+
const filePath = join21(timelineDir, filename);
|
|
86551
86728
|
let source;
|
|
86552
86729
|
try {
|
|
86553
|
-
source =
|
|
86730
|
+
source = fs9.lstatSync(filePath);
|
|
86554
86731
|
} catch {
|
|
86555
86732
|
continue;
|
|
86556
86733
|
}
|
|
@@ -87161,36 +87338,36 @@ function createTimelineRecorder(opts) {
|
|
|
87161
87338
|
}
|
|
87162
87339
|
}
|
|
87163
87340
|
// src/discovery.ts
|
|
87164
|
-
import * as
|
|
87165
|
-
import * as
|
|
87341
|
+
import * as path17 from "path";
|
|
87342
|
+
import * as fs10 from "fs";
|
|
87166
87343
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
87167
87344
|
function resolveAlookCliPath(moduleDir) {
|
|
87168
|
-
const thisDir = moduleDir ??
|
|
87169
|
-
const target2 =
|
|
87170
|
-
return
|
|
87345
|
+
const thisDir = moduleDir ?? path17.dirname(fileURLToPath4(import.meta.url));
|
|
87346
|
+
const target2 = path17.basename(thisDir) === "dist" ? path17.resolve(thisDir, "cli", "index.js") : path17.resolve(thisDir, "..", "scripts", "alook-shim.mjs");
|
|
87347
|
+
return fs10.existsSync(target2) ? target2 : null;
|
|
87171
87348
|
}
|
|
87172
87349
|
function deriveCliFallbackCandidates(cliPath) {
|
|
87173
87350
|
if (!cliPath)
|
|
87174
87351
|
return [];
|
|
87175
|
-
const normalized = cliPath.split(
|
|
87352
|
+
const normalized = cliPath.split(path17.sep).join("/");
|
|
87176
87353
|
const marker = "/node_modules/";
|
|
87177
87354
|
const idx = normalized.indexOf(marker);
|
|
87178
87355
|
if (idx === -1)
|
|
87179
87356
|
return [];
|
|
87180
87357
|
const globalRoot = cliPath.slice(0, idx + marker.length - 1);
|
|
87181
|
-
const tail =
|
|
87358
|
+
const tail = path17.join("dist", "cli", "index.js");
|
|
87182
87359
|
return [
|
|
87183
|
-
|
|
87360
|
+
path17.join(globalRoot, "@alook", "daemon", tail)
|
|
87184
87361
|
].filter((candidate) => candidate !== cliPath);
|
|
87185
87362
|
}
|
|
87186
87363
|
function resolveAlookCliPathWithFallback(primary) {
|
|
87187
87364
|
const resolved = primary ?? resolveAlookCliPath();
|
|
87188
|
-
if (resolved &&
|
|
87365
|
+
if (resolved && fs10.existsSync(resolved))
|
|
87189
87366
|
return resolved;
|
|
87190
87367
|
if (resolved) {
|
|
87191
87368
|
const fallbacks = deriveCliFallbackCandidates(resolved);
|
|
87192
87369
|
for (const fallback2 of fallbacks) {
|
|
87193
|
-
if (
|
|
87370
|
+
if (fs10.existsSync(fallback2))
|
|
87194
87371
|
return fallback2;
|
|
87195
87372
|
}
|
|
87196
87373
|
}
|
|
@@ -87291,6 +87468,15 @@ function createMachineStopCommandListener(onStopRequested) {
|
|
|
87291
87468
|
}
|
|
87292
87469
|
|
|
87293
87470
|
// src/daemon/messageReminderScheduler.ts
|
|
87471
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
87472
|
+
var savedReminder = exports_external.object({
|
|
87473
|
+
agentId: exports_external.string().min(1),
|
|
87474
|
+
channel: exports_external.string().min(1),
|
|
87475
|
+
sentSeq: exports_external.number().int().nonnegative(),
|
|
87476
|
+
remindAfterMs: exports_external.number().int().min(1).max(86400000),
|
|
87477
|
+
startedAt: exports_external.number().nonnegative(),
|
|
87478
|
+
dueAt: exports_external.number().nonnegative()
|
|
87479
|
+
}).refine((value) => value.dueAt === value.startedAt + value.remindAfterMs);
|
|
87294
87480
|
function reminderKey(agentId, channel) {
|
|
87295
87481
|
return `${agentId}\x00${channel}`;
|
|
87296
87482
|
}
|
|
@@ -87310,6 +87496,25 @@ class MessageReminderScheduler {
|
|
|
87310
87496
|
this.now = options.now ?? Date.now;
|
|
87311
87497
|
this.setTimer = options.setTimer ?? ((callback, delayMs) => setTimeout(callback, delayMs));
|
|
87312
87498
|
this.clearTimer = options.clearTimer ?? ((timer) => clearTimeout(timer));
|
|
87499
|
+
if (options.filePath) {
|
|
87500
|
+
let saved;
|
|
87501
|
+
try {
|
|
87502
|
+
saved = JSON.parse(readFileSync9(options.filePath, "utf8"));
|
|
87503
|
+
} catch {
|
|
87504
|
+
return;
|
|
87505
|
+
}
|
|
87506
|
+
if (Array.isArray(saved))
|
|
87507
|
+
for (const value of saved) {
|
|
87508
|
+
const parsed = savedReminder.safeParse(value);
|
|
87509
|
+
if (!parsed.success)
|
|
87510
|
+
continue;
|
|
87511
|
+
const record8 = parsed.data;
|
|
87512
|
+
this.reminders.set(reminderKey(record8.agentId, record8.channel), {
|
|
87513
|
+
...record8,
|
|
87514
|
+
sentRef: `${record8.channel}#${record8.sentSeq}`
|
|
87515
|
+
});
|
|
87516
|
+
}
|
|
87517
|
+
}
|
|
87313
87518
|
}
|
|
87314
87519
|
arm(input2) {
|
|
87315
87520
|
const key = reminderKey(input2.agentId, input2.channel);
|
|
@@ -87321,7 +87526,7 @@ class MessageReminderScheduler {
|
|
|
87321
87526
|
if (latest !== undefined && latest > input2.sentSeq) {
|
|
87322
87527
|
return { armed: false, reason: "newer_message_observed" };
|
|
87323
87528
|
}
|
|
87324
|
-
this.
|
|
87529
|
+
const previous4 = this.reminders.get(key);
|
|
87325
87530
|
const startedAt = this.now();
|
|
87326
87531
|
const dueAt = startedAt + input2.remindAfterMs;
|
|
87327
87532
|
const sentRef = `${input2.channel}#${input2.sentSeq}`;
|
|
@@ -87329,24 +87534,44 @@ class MessageReminderScheduler {
|
|
|
87329
87534
|
...input2,
|
|
87330
87535
|
sentRef,
|
|
87331
87536
|
startedAt,
|
|
87332
|
-
dueAt
|
|
87333
|
-
timer: undefined
|
|
87537
|
+
dueAt
|
|
87334
87538
|
};
|
|
87539
|
+
this.reminders.set(key, record8);
|
|
87540
|
+
try {
|
|
87541
|
+
this.persist();
|
|
87542
|
+
} catch (error62) {
|
|
87543
|
+
if (previous4)
|
|
87544
|
+
this.reminders.set(key, previous4);
|
|
87545
|
+
else
|
|
87546
|
+
this.reminders.delete(key);
|
|
87547
|
+
throw error62;
|
|
87548
|
+
}
|
|
87549
|
+
if (previous4?.timer !== undefined)
|
|
87550
|
+
this.clearTimer(previous4.timer);
|
|
87551
|
+
this.schedule(key, record8);
|
|
87552
|
+
return { armed: true, dueAt };
|
|
87553
|
+
}
|
|
87554
|
+
restore() {
|
|
87555
|
+
for (const [key, record8] of this.reminders) {
|
|
87556
|
+
if (record8.timer === undefined)
|
|
87557
|
+
this.schedule(key, record8);
|
|
87558
|
+
}
|
|
87559
|
+
}
|
|
87560
|
+
schedule(key, record8) {
|
|
87335
87561
|
record8.timer = this.setTimer(() => {
|
|
87336
87562
|
if (this.reminders.get(key) !== record8)
|
|
87337
87563
|
return;
|
|
87338
87564
|
this.reminders.delete(key);
|
|
87339
87565
|
try {
|
|
87340
|
-
|
|
87341
|
-
|
|
87342
|
-
|
|
87566
|
+
this.persist();
|
|
87567
|
+
const delivery = this.options.deliver(record8.agentId, {
|
|
87568
|
+
id: `${record8.agentId}:reminder:${record8.channel}:${record8.sentSeq}:${record8.startedAt}`,
|
|
87569
|
+
text: reminderPrompt(record8.channel, record8.sentRef, record8.startedAt)
|
|
87343
87570
|
});
|
|
87344
87571
|
Promise.resolve(delivery).catch(() => {});
|
|
87345
87572
|
} catch {}
|
|
87346
|
-
},
|
|
87573
|
+
}, Math.max(0, record8.dueAt - this.now()));
|
|
87347
87574
|
record8.timer.unref?.();
|
|
87348
|
-
this.reminders.set(key, record8);
|
|
87349
|
-
return { armed: true, dueAt };
|
|
87350
87575
|
}
|
|
87351
87576
|
observe(agentId, channel, latestSeq) {
|
|
87352
87577
|
const key = reminderKey(agentId, channel);
|
|
@@ -87360,33 +87585,51 @@ class MessageReminderScheduler {
|
|
|
87360
87585
|
}
|
|
87361
87586
|
clearAgent(agentId) {
|
|
87362
87587
|
const prefix = `${agentId}\x00`;
|
|
87588
|
+
let changed = false;
|
|
87363
87589
|
for (const key of [...this.reminders.keys()]) {
|
|
87364
|
-
if (key.startsWith(prefix))
|
|
87365
|
-
this.clearReminder(key);
|
|
87590
|
+
if (key.startsWith(prefix)) {
|
|
87591
|
+
this.clearReminder(key, false);
|
|
87592
|
+
changed = true;
|
|
87593
|
+
}
|
|
87366
87594
|
}
|
|
87367
87595
|
for (const key of [...this.latestObservedSeq.keys()]) {
|
|
87368
87596
|
if (key.startsWith(prefix))
|
|
87369
87597
|
this.latestObservedSeq.delete(key);
|
|
87370
87598
|
}
|
|
87599
|
+
if (changed)
|
|
87600
|
+
this.persist();
|
|
87371
87601
|
}
|
|
87372
87602
|
clearAll() {
|
|
87373
|
-
|
|
87374
|
-
|
|
87603
|
+
this.stop();
|
|
87604
|
+
this.persist();
|
|
87605
|
+
}
|
|
87606
|
+
stop() {
|
|
87607
|
+
for (const record8 of this.reminders.values())
|
|
87608
|
+
if (record8.timer !== undefined)
|
|
87609
|
+
this.clearTimer(record8.timer);
|
|
87610
|
+
this.reminders.clear();
|
|
87375
87611
|
this.latestObservedSeq.clear();
|
|
87376
87612
|
}
|
|
87377
|
-
|
|
87613
|
+
persist() {
|
|
87614
|
+
if (this.options.filePath)
|
|
87615
|
+
writePrivateJsonAtomic(this.options.filePath, [...this.reminders.values()].map(({ agentId, channel, sentSeq, remindAfterMs, startedAt, dueAt }) => ({ agentId, channel, sentSeq, remindAfterMs, startedAt, dueAt })));
|
|
87616
|
+
}
|
|
87617
|
+
clearReminder(key, persist = true) {
|
|
87378
87618
|
const reminder = this.reminders.get(key);
|
|
87379
87619
|
if (!reminder)
|
|
87380
87620
|
return;
|
|
87381
87621
|
this.reminders.delete(key);
|
|
87382
|
-
|
|
87622
|
+
if (reminder.timer !== undefined)
|
|
87623
|
+
this.clearTimer(reminder.timer);
|
|
87624
|
+
if (persist)
|
|
87625
|
+
this.persist();
|
|
87383
87626
|
}
|
|
87384
87627
|
}
|
|
87385
87628
|
|
|
87386
87629
|
// src/manager/agentDriverHost.ts
|
|
87387
87630
|
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
87388
87631
|
import { homedir as homedir12 } from "node:os";
|
|
87389
|
-
import { join as
|
|
87632
|
+
import { join as join23 } from "node:path";
|
|
87390
87633
|
|
|
87391
87634
|
// src/drivers/gitIdentityEnv.ts
|
|
87392
87635
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
@@ -87516,7 +87759,7 @@ function createDaemonAgentDriverHost(ctx, onRawLine, onRawStderr) {
|
|
|
87516
87759
|
hostUser: readHostGitIdentity() ?? undefined
|
|
87517
87760
|
}),
|
|
87518
87761
|
platformProtected: {
|
|
87519
|
-
ALOOK_HOME: process.env.ALOOK_HOME ??
|
|
87762
|
+
ALOOK_HOME: process.env.ALOOK_HOME ?? join23(homedir12(), ".alook"),
|
|
87520
87763
|
ALOOK_ID: ctx.agentId,
|
|
87521
87764
|
ALOOK_CLI: ctx.agentCliPath,
|
|
87522
87765
|
ALOOK_SERVER_URL: ctx.config.serverUrl,
|
|
@@ -87552,8 +87795,8 @@ function createDaemonAgentDriverHost(ctx, onRawLine, onRawStderr) {
|
|
|
87552
87795
|
}
|
|
87553
87796
|
|
|
87554
87797
|
// src/drivers/alookPageGuide.ts
|
|
87555
|
-
import { mkdirSync as
|
|
87556
|
-
import { join as
|
|
87798
|
+
import { mkdirSync as mkdirSync10, readFileSync as readFileSync10, writeFileSync as writeFileSync12 } from "node:fs";
|
|
87799
|
+
import { join as join24 } from "node:path";
|
|
87557
87800
|
var ALOOK_PAGE_GUIDE_FILENAME = "alook-page.md";
|
|
87558
87801
|
var ALOOK_PAGE_GUIDE_CONTENT = [
|
|
87559
87802
|
"# Alook Page Guide",
|
|
@@ -87613,16 +87856,16 @@ var ALOOK_PAGE_GUIDE_CONTENT = [
|
|
|
87613
87856
|
function syncAlookPageGuide(workingDirectory) {
|
|
87614
87857
|
if (!workingDirectory)
|
|
87615
87858
|
return false;
|
|
87616
|
-
|
|
87617
|
-
const target2 =
|
|
87859
|
+
mkdirSync10(workingDirectory, { recursive: true });
|
|
87860
|
+
const target2 = join24(workingDirectory, ALOOK_PAGE_GUIDE_FILENAME);
|
|
87618
87861
|
try {
|
|
87619
|
-
if (
|
|
87862
|
+
if (readFileSync10(target2, "utf8") === ALOOK_PAGE_GUIDE_CONTENT)
|
|
87620
87863
|
return false;
|
|
87621
87864
|
} catch (error62) {
|
|
87622
87865
|
if (error62?.code !== "ENOENT")
|
|
87623
87866
|
throw error62;
|
|
87624
87867
|
}
|
|
87625
|
-
|
|
87868
|
+
writeFileSync12(target2, ALOOK_PAGE_GUIDE_CONTENT, "utf8");
|
|
87626
87869
|
return true;
|
|
87627
87870
|
}
|
|
87628
87871
|
|
|
@@ -87700,7 +87943,7 @@ class DaemonSelfSleepScheduler {
|
|
|
87700
87943
|
|
|
87701
87944
|
// src/telemetry/dailyTokenUsage.ts
|
|
87702
87945
|
import { chmod, mkdir, open as open3, readFile as readFile3, rename, rm } from "node:fs/promises";
|
|
87703
|
-
import { dirname as
|
|
87946
|
+
import { dirname as dirname8, join as join25 } from "node:path";
|
|
87704
87947
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
87705
87948
|
var TOKEN_USAGE_WINDOW_DAYS = 30;
|
|
87706
87949
|
var TOKEN_USAGE_RECOVERY_DAYS = 2;
|
|
@@ -87761,7 +88004,7 @@ class DailyTokenUsageStore {
|
|
|
87761
88004
|
this.now = now;
|
|
87762
88005
|
this.resolveTimeZone = typeof timeZone === "string" ? () => timeZone : timeZone;
|
|
87763
88006
|
this.timeZone;
|
|
87764
|
-
this.filePath =
|
|
88007
|
+
this.filePath = join25(workingDirectoryBase, ".telemetry", "daily-token-usage.json");
|
|
87765
88008
|
}
|
|
87766
88009
|
get timeZone() {
|
|
87767
88010
|
const timeZone = this.resolveTimeZone();
|
|
@@ -87948,7 +88191,7 @@ class DailyTokenUsageStore {
|
|
|
87948
88191
|
return changed;
|
|
87949
88192
|
}
|
|
87950
88193
|
async persist() {
|
|
87951
|
-
const directory =
|
|
88194
|
+
const directory = dirname8(this.filePath);
|
|
87952
88195
|
await mkdir(directory, { recursive: true, mode: 448 });
|
|
87953
88196
|
const temporary = `${this.filePath}.${randomUUID13()}.tmp`;
|
|
87954
88197
|
try {
|
|
@@ -88046,6 +88289,8 @@ var WARMUP_CEILING_MS = 30000;
|
|
|
88046
88289
|
var RUNTIME_RAW_TRACE_MAX_BYTES = 8 * 1024 * 1024;
|
|
88047
88290
|
var RUNTIME_RAW_TRACE_AGENT_IDS_ENV = "ALOOK_RUNTIME_RAW_TRACE_AGENT_IDS";
|
|
88048
88291
|
var STATUS_WRITE_INTERVAL_MS = 5000;
|
|
88292
|
+
var interruptedTurn = exports_external.object({ agentId: exports_external.string().min(1), sessionId: exports_external.string().nullable(), interruptedAt: exports_external.number().nonnegative() });
|
|
88293
|
+
var RECOVERY_TTL_MS = 15 * 60000;
|
|
88049
88294
|
function parseRuntimeRawTraceAgentIds(value) {
|
|
88050
88295
|
return new Set((value ?? "").split(",").map((agentId) => agentId.trim()).filter((agentId) => agentId.length > 0 && agentId !== "*"));
|
|
88051
88296
|
}
|
|
@@ -88056,13 +88301,13 @@ function createRuntimeRawLineTap(args) {
|
|
|
88056
88301
|
const maxBytes = args.maxBytes ?? RUNTIME_RAW_TRACE_MAX_BYTES;
|
|
88057
88302
|
const sinks = new Map;
|
|
88058
88303
|
const warned = new Set;
|
|
88059
|
-
const warnOnce = (agentId,
|
|
88304
|
+
const warnOnce = (agentId, path18, operation, error62) => {
|
|
88060
88305
|
if (warned.has(agentId))
|
|
88061
88306
|
return;
|
|
88062
88307
|
warned.add(agentId);
|
|
88063
88308
|
args.logger.warn("runtime raw trace sink failed", {
|
|
88064
88309
|
agentId,
|
|
88065
|
-
path:
|
|
88310
|
+
path: path18,
|
|
88066
88311
|
operation,
|
|
88067
88312
|
error: error62 instanceof Error ? error62.message : String(error62)
|
|
88068
88313
|
});
|
|
@@ -88071,23 +88316,23 @@ function createRuntimeRawLineTap(args) {
|
|
|
88071
88316
|
if (!args.enabledAgentIds.has(agentId))
|
|
88072
88317
|
return;
|
|
88073
88318
|
const encodedAgentId = encodeURIComponent(agentId).replace(/\./g, "%2E");
|
|
88074
|
-
const
|
|
88319
|
+
const path18 = `${traceDir}/runtime-raw-events-${encodedAgentId}.jsonl`;
|
|
88075
88320
|
const serializedBytes = Buffer.byteLength(line, "utf8") + 1;
|
|
88076
88321
|
if (serializedBytes > maxBytes) {
|
|
88077
|
-
warnOnce(agentId,
|
|
88322
|
+
warnOnce(agentId, path18, "oversize", new Error(`raw line is ${serializedBytes} bytes; max is ${maxBytes}`));
|
|
88078
88323
|
return;
|
|
88079
88324
|
}
|
|
88080
88325
|
let sink = sinks.get(agentId);
|
|
88081
88326
|
if (!sink) {
|
|
88082
88327
|
try {
|
|
88083
|
-
|
|
88328
|
+
mkdirSync11(traceDir, { recursive: true });
|
|
88084
88329
|
} catch (error62) {
|
|
88085
|
-
warnOnce(agentId,
|
|
88330
|
+
warnOnce(agentId, path18, "mkdir", error62);
|
|
88086
88331
|
}
|
|
88087
|
-
sink = createRotatingFileSink(
|
|
88332
|
+
sink = createRotatingFileSink(path18, maxBytes, {
|
|
88088
88333
|
mode: 384,
|
|
88089
88334
|
hardMaxBytes: true,
|
|
88090
|
-
onError: ({ operation, error: error62 }) => warnOnce(agentId,
|
|
88335
|
+
onError: ({ operation, error: error62 }) => warnOnce(agentId, path18, operation, error62)
|
|
88091
88336
|
});
|
|
88092
88337
|
sinks.set(agentId, sink);
|
|
88093
88338
|
}
|
|
@@ -88290,6 +88535,37 @@ async function createDaemon(opts) {
|
|
|
88290
88535
|
}
|
|
88291
88536
|
};
|
|
88292
88537
|
let reminderSchedulerRef = null;
|
|
88538
|
+
const recoveryPath = opts.daemonDir ? join26(opts.daemonDir, "interrupted-turns.json") : undefined;
|
|
88539
|
+
let interruptedTurns = [];
|
|
88540
|
+
const localMessageEpochs = new Map;
|
|
88541
|
+
if (recoveryPath) {
|
|
88542
|
+
try {
|
|
88543
|
+
const parsed = JSON.parse(readFileSync11(recoveryPath, "utf8"));
|
|
88544
|
+
if (Array.isArray(parsed))
|
|
88545
|
+
interruptedTurns = parsed.flatMap((value) => {
|
|
88546
|
+
const record8 = interruptedTurn.safeParse(value);
|
|
88547
|
+
return record8.success ? [record8.data] : [];
|
|
88548
|
+
});
|
|
88549
|
+
} catch {
|
|
88550
|
+
interruptedTurns = [];
|
|
88551
|
+
}
|
|
88552
|
+
}
|
|
88553
|
+
const persistInterruptedTurns = () => {
|
|
88554
|
+
if (recoveryPath)
|
|
88555
|
+
writePrivateJsonAtomic(recoveryPath, interruptedTurns);
|
|
88556
|
+
};
|
|
88557
|
+
const clearInterruptedTurn = (agentId) => {
|
|
88558
|
+
if (!interruptedTurns.some((record8) => record8.agentId === agentId))
|
|
88559
|
+
return;
|
|
88560
|
+
const previous4 = interruptedTurns;
|
|
88561
|
+
interruptedTurns = interruptedTurns.filter((record8) => record8.agentId !== agentId);
|
|
88562
|
+
try {
|
|
88563
|
+
persistInterruptedTurns();
|
|
88564
|
+
} catch (error62) {
|
|
88565
|
+
interruptedTurns = previous4;
|
|
88566
|
+
throw error62;
|
|
88567
|
+
}
|
|
88568
|
+
};
|
|
88293
88569
|
const selfSleepScheduler = opts.onSelfSleep ? new DaemonSelfSleepScheduler({
|
|
88294
88570
|
onSleep: opts.onSelfSleep,
|
|
88295
88571
|
...opts.selfSleepClock ? { clock: opts.selfSleepClock } : {}
|
|
@@ -88408,7 +88684,8 @@ async function createDaemon(opts) {
|
|
|
88408
88684
|
async function listMyBotsHttp(includeInactive = false) {
|
|
88409
88685
|
const res = await fetch(`${opts.serverUrl}/api/community/daemon/bots${includeInactive ? "?includeInactive=true" : ""}`, {
|
|
88410
88686
|
method: "GET",
|
|
88411
|
-
headers: { authorization: `Bearer ${opts.machineKey}` }
|
|
88687
|
+
headers: { authorization: `Bearer ${opts.machineKey}` },
|
|
88688
|
+
signal: AbortSignal.any([stopAbort.signal, AbortSignal.timeout(1e4)])
|
|
88412
88689
|
});
|
|
88413
88690
|
if (!res.ok)
|
|
88414
88691
|
throw new Error(`listMyBots ${res.status}`);
|
|
@@ -88419,6 +88696,10 @@ async function createDaemon(opts) {
|
|
|
88419
88696
|
botsById.clear();
|
|
88420
88697
|
for (const b of bots) {
|
|
88421
88698
|
botsById.set(b.id, {
|
|
88699
|
+
runtime: b.runtime,
|
|
88700
|
+
modelName: b.modelName,
|
|
88701
|
+
reasoningEffort: b.reasoningEffort,
|
|
88702
|
+
runtimeConfigRevision: b.runtimeConfigRevision,
|
|
88422
88703
|
name: b.name,
|
|
88423
88704
|
discriminator: b.discriminator,
|
|
88424
88705
|
description: b.description,
|
|
@@ -88432,12 +88713,14 @@ async function createDaemon(opts) {
|
|
|
88432
88713
|
async function coldStartWarmup() {
|
|
88433
88714
|
const start = Date.now();
|
|
88434
88715
|
let attempt = 0;
|
|
88435
|
-
while (Date.now() - start < WARMUP_CEILING_MS) {
|
|
88716
|
+
while (!stopping && Date.now() - start < WARMUP_CEILING_MS) {
|
|
88436
88717
|
try {
|
|
88437
88718
|
const bots = await listMyBotsHttp();
|
|
88719
|
+
if (stopping)
|
|
88720
|
+
return false;
|
|
88438
88721
|
replaceBotCache(bots);
|
|
88439
88722
|
log2.info("cold-start bot-cache warmup succeeded", { bots: bots.length, attempt });
|
|
88440
|
-
return;
|
|
88723
|
+
return true;
|
|
88441
88724
|
} catch {
|
|
88442
88725
|
const delay3 = WARMUP_BACKOFF_MS[Math.min(attempt, WARMUP_BACKOFF_MS.length - 1)];
|
|
88443
88726
|
await new Promise((r) => setTimeout(r, delay3));
|
|
@@ -88445,12 +88728,73 @@ async function createDaemon(opts) {
|
|
|
88445
88728
|
}
|
|
88446
88729
|
}
|
|
88447
88730
|
log2.warn("cold-start bot-cache warmup exhausted its ceiling", { ceilingMs: WARMUP_CEILING_MS, attempts: attempt });
|
|
88731
|
+
return false;
|
|
88732
|
+
}
|
|
88733
|
+
async function deliverLocalMessage(agentId, message) {
|
|
88734
|
+
if (stopping || !botsById.has(agentId))
|
|
88735
|
+
return;
|
|
88736
|
+
const epoch = localMessageEpochs.get(agentId);
|
|
88737
|
+
await enrollAgent(agentId);
|
|
88738
|
+
const bot = botsById.get(agentId);
|
|
88739
|
+
if (stopping || !bot || localMessageEpochs.get(agentId) !== epoch)
|
|
88740
|
+
return;
|
|
88741
|
+
const existing = manager.snapshot().agents[agentId];
|
|
88742
|
+
if (message.recovery && existing) {
|
|
88743
|
+
clearInterruptedTurn(agentId);
|
|
88744
|
+
return;
|
|
88745
|
+
}
|
|
88746
|
+
if (message.recovery) {
|
|
88747
|
+
const record8 = interruptedTurns.find((record9) => record9.agentId === agentId);
|
|
88748
|
+
if (!record8 || Date.now() - record8.interruptedAt >= RECOVERY_TTL_MS) {
|
|
88749
|
+
clearInterruptedTurn(agentId);
|
|
88750
|
+
return;
|
|
88751
|
+
}
|
|
88752
|
+
clearInterruptedTurn(agentId);
|
|
88753
|
+
}
|
|
88754
|
+
if (!existing) {
|
|
88755
|
+
if (!bot.runtime)
|
|
88756
|
+
throw new Error("Bot runtime unavailable for local recovery");
|
|
88757
|
+
manager.register(agentId, {
|
|
88758
|
+
runtimeConfig: makeRuntimeConfig({
|
|
88759
|
+
runtime: bot.runtime,
|
|
88760
|
+
model: resolveModelConfig(bot.modelName ?? null),
|
|
88761
|
+
reasoningEffort: bot.reasoningEffort ?? undefined,
|
|
88762
|
+
runtimeConfigRevision: bot.runtimeConfigRevision,
|
|
88763
|
+
agentName: bot.name,
|
|
88764
|
+
agentHandle: `@${formatHandle(bot.name, bot.discriminator)}`
|
|
88765
|
+
}),
|
|
88766
|
+
launchId: randomUUID14()
|
|
88767
|
+
});
|
|
88768
|
+
}
|
|
88769
|
+
manager.deliver(agentId, message);
|
|
88770
|
+
}
|
|
88771
|
+
async function restoreLocalWork() {
|
|
88772
|
+
const [warmed] = await Promise.all([coldStartWarmup(), resyncPendingWakes()]);
|
|
88773
|
+
if (!warmed || stopping)
|
|
88774
|
+
return;
|
|
88775
|
+
for (const record8 of [...interruptedTurns]) {
|
|
88776
|
+
if (stopping)
|
|
88777
|
+
return;
|
|
88778
|
+
const age = Date.now() - record8.interruptedAt;
|
|
88779
|
+
if (age < 0 || age >= RECOVERY_TTL_MS || !botsById.has(record8.agentId) || manager.snapshot().agents[record8.agentId]) {
|
|
88780
|
+
clearInterruptedTurn(record8.agentId);
|
|
88781
|
+
continue;
|
|
88782
|
+
}
|
|
88783
|
+
try {
|
|
88784
|
+
await deliverLocalMessage(record8.agentId, interruptedTurnMessage(record8.agentId, "daemon_restart", record8.interruptedAt));
|
|
88785
|
+
} catch (error62) {
|
|
88786
|
+
log2.warn("interrupted turn recovery failed", { agentId: record8.agentId, error: String(error62) });
|
|
88787
|
+
}
|
|
88788
|
+
}
|
|
88789
|
+
if (!stopping)
|
|
88790
|
+
reminderSchedulerRef?.restore();
|
|
88448
88791
|
}
|
|
88449
88792
|
async function resyncPendingWakes() {
|
|
88450
88793
|
try {
|
|
88451
88794
|
const res = await fetch(`${opts.serverUrl}/api/community/daemon/resync-wakes`, {
|
|
88452
88795
|
method: "POST",
|
|
88453
|
-
headers: { authorization: `Bearer ${opts.machineKey}` }
|
|
88796
|
+
headers: { authorization: `Bearer ${opts.machineKey}` },
|
|
88797
|
+
signal: AbortSignal.any([stopAbort.signal, AbortSignal.timeout(1e4)])
|
|
88454
88798
|
});
|
|
88455
88799
|
if (!res.ok)
|
|
88456
88800
|
throw new Error(`resync-wakes ${res.status}`);
|
|
@@ -88614,7 +88958,7 @@ async function createDaemon(opts) {
|
|
|
88614
88958
|
if (!opts.fsmTraceDir)
|
|
88615
88959
|
return { source: null };
|
|
88616
88960
|
try {
|
|
88617
|
-
|
|
88961
|
+
mkdirSync11(opts.fsmTraceDir, { recursive: true });
|
|
88618
88962
|
} catch {}
|
|
88619
88963
|
const source = createRotatingFileSink(`${opts.fsmTraceDir}/fsm-trace.jsonl`, DEFAULT_TRACE_FILE_MAX_BYTES);
|
|
88620
88964
|
const sampler = createTraceSampler((rec) => source.write(JSON.stringify(rec)));
|
|
@@ -88673,6 +89017,7 @@ async function createDaemon(opts) {
|
|
|
88673
89017
|
if (info.state === "idle")
|
|
88674
89018
|
refreshMachineQuota(managerRef?.agentBackendId(info.agentId) ?? undefined);
|
|
88675
89019
|
if (info.state === "starting" || info.state === "running") {
|
|
89020
|
+
router?.markLocallyStarted(info.agentId);
|
|
88676
89021
|
if (!typingHeartbeats.has(info.agentId)) {
|
|
88677
89022
|
startTypingHeartbeat(info.agentId);
|
|
88678
89023
|
}
|
|
@@ -88709,7 +89054,8 @@ async function createDaemon(opts) {
|
|
|
88709
89054
|
managerRef = manager;
|
|
88710
89055
|
manager.start();
|
|
88711
89056
|
reminderSchedulerRef = new MessageReminderScheduler({
|
|
88712
|
-
deliver: (agentId, message) => manager.deliver(agentId, message),
|
|
89057
|
+
deliver: (agentId, message) => manager.snapshot().agents[agentId] ? manager.deliver(agentId, message) : deliverLocalMessage(agentId, message),
|
|
89058
|
+
...opts.daemonDir ? { filePath: join26(opts.daemonDir, "message-reminders.json") } : {},
|
|
88713
89059
|
...opts.messageReminderClock
|
|
88714
89060
|
});
|
|
88715
89061
|
let statusTimer = null;
|
|
@@ -88824,18 +89170,27 @@ async function createDaemon(opts) {
|
|
|
88824
89170
|
}));
|
|
88825
89171
|
channel.onWakeDesiredAdvance((cmd) => {
|
|
88826
89172
|
selfSleepScheduler?.observeMessage();
|
|
88827
|
-
|
|
89173
|
+
try {
|
|
89174
|
+
reminderSchedulerRef?.observe(cmd.agentId, cmd.unreadNotice.channel, cmd.unreadNotice.latestSeq);
|
|
89175
|
+
} catch {
|
|
89176
|
+
log2.warn("reminder observation persistence failed");
|
|
89177
|
+
}
|
|
88828
89178
|
});
|
|
88829
89179
|
channel.onCommand((cmd) => {
|
|
88830
|
-
|
|
88831
|
-
|
|
88832
|
-
|
|
88833
|
-
|
|
88834
|
-
|
|
88835
|
-
|
|
88836
|
-
|
|
88837
|
-
|
|
88838
|
-
|
|
89180
|
+
if (cmd.type !== "agent:stop" && cmd.type !== "bot:removed")
|
|
89181
|
+
return;
|
|
89182
|
+
const agentId = cmd.type === "agent:stop" ? cmd.agentId : cmd.botId;
|
|
89183
|
+
localMessageEpochs.set(agentId, (localMessageEpochs.get(agentId) ?? 0) + 1);
|
|
89184
|
+
try {
|
|
89185
|
+
clearInterruptedTurn(agentId);
|
|
89186
|
+
} catch {
|
|
89187
|
+
interruptedTurns = interruptedTurns.filter((record8) => record8.agentId !== agentId);
|
|
89188
|
+
log2.warn("interrupted turn cancellation persistence failed");
|
|
89189
|
+
}
|
|
89190
|
+
try {
|
|
89191
|
+
reminderSchedulerRef?.clearAgent(agentId);
|
|
89192
|
+
} catch {
|
|
89193
|
+
log2.warn("reminder cancellation persistence failed");
|
|
88839
89194
|
}
|
|
88840
89195
|
});
|
|
88841
89196
|
channel.onCommand((cmd) => {
|
|
@@ -88861,8 +89216,7 @@ async function createDaemon(opts) {
|
|
|
88861
89216
|
channel.onOpen(() => {
|
|
88862
89217
|
if (stopping)
|
|
88863
89218
|
return;
|
|
88864
|
-
|
|
88865
|
-
resyncPendingWakes();
|
|
89219
|
+
restoreLocalWork().catch((error62) => log2.warn("local work restore failed", { error: String(error62) }));
|
|
88866
89220
|
resyncPendingDiagnostics();
|
|
88867
89221
|
syncImTriggers();
|
|
88868
89222
|
refreshMachineQuotas();
|
|
@@ -88895,6 +89249,20 @@ async function createDaemon(opts) {
|
|
|
88895
89249
|
stopAbort.abort();
|
|
88896
89250
|
clearInterval(quotaRefreshTimer);
|
|
88897
89251
|
const failures = [];
|
|
89252
|
+
try {
|
|
89253
|
+
const saved = new Map(interruptedTurns.map((record8) => [record8.agentId, record8]));
|
|
89254
|
+
for (const agent of manager.interruptedTurns()) {
|
|
89255
|
+
saved.set(agent.agentId, {
|
|
89256
|
+
agentId: agent.agentId,
|
|
89257
|
+
sessionId: agent.sessionId,
|
|
89258
|
+
interruptedAt: Date.now()
|
|
89259
|
+
});
|
|
89260
|
+
}
|
|
89261
|
+
interruptedTurns = [...saved.values()];
|
|
89262
|
+
persistInterruptedTurns();
|
|
89263
|
+
} catch (error62) {
|
|
89264
|
+
failures.push(error62);
|
|
89265
|
+
}
|
|
88898
89266
|
stopPromise = Promise.resolve().then(async () => {
|
|
88899
89267
|
try {
|
|
88900
89268
|
try {
|
|
@@ -88926,7 +89294,7 @@ async function createDaemon(opts) {
|
|
|
88926
89294
|
});
|
|
88927
89295
|
manager.beginShutdown();
|
|
88928
89296
|
selfSleepScheduler?.stop();
|
|
88929
|
-
reminderSchedulerRef?.
|
|
89297
|
+
reminderSchedulerRef?.stop();
|
|
88930
89298
|
for (const agentId of [...typingHeartbeats.keys()]) {
|
|
88931
89299
|
try {
|
|
88932
89300
|
emitTypingStopsAndClear(agentId);
|
|
@@ -88965,6 +89333,7 @@ export {
|
|
|
88965
89333
|
isRuntimeAuthActionRequiredText,
|
|
88966
89334
|
isAlookShellInvocation,
|
|
88967
89335
|
isActivelyWorking,
|
|
89336
|
+
interruptedTurnMessage,
|
|
88968
89337
|
getDriver,
|
|
88969
89338
|
capabilitiesFor as getBuiltinBackendCapabilities,
|
|
88970
89339
|
getAvailableRuntimes,
|