@grackle-ai/core 0.96.1 → 0.96.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/event-processor.js +1 -1
- package/dist/event-processor.js.map +1 -1
- package/dist/{grpc-shared.d.ts → grpc-shared-utils.d.ts} +6 -10
- package/dist/grpc-shared-utils.d.ts.map +1 -0
- package/dist/grpc-shared-utils.js +57 -0
- package/dist/grpc-shared-utils.js.map +1 -0
- package/dist/index.d.ts +33 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -31
- package/dist/index.js.map +1 -1
- package/dist/lifecycle-streams.d.ts +27 -0
- package/dist/lifecycle-streams.d.ts.map +1 -0
- package/dist/lifecycle-streams.js +46 -0
- package/dist/lifecycle-streams.js.map +1 -0
- package/dist/reanimate-agent.js +1 -1
- package/dist/reanimate-agent.js.map +1 -1
- package/dist/task-session.js +1 -1
- package/dist/task-session.js.map +1 -1
- package/package.json +8 -8
- package/dist/codespace-handlers.d.ts +0 -6
- package/dist/codespace-handlers.d.ts.map +0 -1
- package/dist/codespace-handlers.js +0 -66
- package/dist/codespace-handlers.js.map +0 -1
- package/dist/cron-phase.d.ts +0 -46
- package/dist/cron-phase.d.ts.map +0 -1
- package/dist/cron-phase.js +0 -88
- package/dist/cron-phase.js.map +0 -1
- package/dist/dispatch-phase.d.ts +0 -46
- package/dist/dispatch-phase.d.ts.map +0 -1
- package/dist/dispatch-phase.js +0 -99
- package/dist/dispatch-phase.js.map +0 -1
- package/dist/environment-handlers.d.ts +0 -16
- package/dist/environment-handlers.d.ts.map +0 -1
- package/dist/environment-handlers.js +0 -255
- package/dist/environment-handlers.js.map +0 -1
- package/dist/environment-reconciliation.d.ts +0 -35
- package/dist/environment-reconciliation.d.ts.map +0 -1
- package/dist/environment-reconciliation.js +0 -74
- package/dist/environment-reconciliation.js.map +0 -1
- package/dist/escalation-handlers.d.ts +0 -8
- package/dist/escalation-handlers.d.ts.map +0 -1
- package/dist/escalation-handlers.js +0 -60
- package/dist/escalation-handlers.js.map +0 -1
- package/dist/finding-handlers.d.ts +0 -8
- package/dist/finding-handlers.d.ts.map +0 -1
- package/dist/finding-handlers.js +0 -38
- package/dist/finding-handlers.js.map +0 -1
- package/dist/grpc-proto-converters.d.ts +0 -31
- package/dist/grpc-proto-converters.d.ts.map +0 -1
- package/dist/grpc-proto-converters.js +0 -222
- package/dist/grpc-proto-converters.js.map +0 -1
- package/dist/grpc-service.d.ts +0 -14
- package/dist/grpc-service.d.ts.map +0 -1
- package/dist/grpc-service.js +0 -46
- package/dist/grpc-service.js.map +0 -1
- package/dist/grpc-shared.d.ts.map +0 -1
- package/dist/grpc-shared.js +0 -110
- package/dist/grpc-shared.js.map +0 -1
- package/dist/knowledge-handlers.d.ts +0 -12
- package/dist/knowledge-handlers.d.ts.map +0 -1
- package/dist/knowledge-handlers.js +0 -149
- package/dist/knowledge-handlers.js.map +0 -1
- package/dist/lifecycle-cleanup.d.ts +0 -13
- package/dist/lifecycle-cleanup.d.ts.map +0 -1
- package/dist/lifecycle-cleanup.js +0 -35
- package/dist/lifecycle-cleanup.js.map +0 -1
- package/dist/lifecycle.d.ts +0 -44
- package/dist/lifecycle.d.ts.map +0 -1
- package/dist/lifecycle.js +0 -169
- package/dist/lifecycle.js.map +0 -1
- package/dist/orphan-phase.d.ts +0 -27
- package/dist/orphan-phase.d.ts.map +0 -1
- package/dist/orphan-phase.js +0 -69
- package/dist/orphan-phase.js.map +0 -1
- package/dist/persona-handlers.d.ts +0 -12
- package/dist/persona-handlers.d.ts.map +0 -1
- package/dist/persona-handlers.js +0 -156
- package/dist/persona-handlers.js.map +0 -1
- package/dist/root-task-boot.d.ts +0 -67
- package/dist/root-task-boot.d.ts.map +0 -1
- package/dist/root-task-boot.js +0 -234
- package/dist/root-task-boot.js.map +0 -1
- package/dist/schedule-expression.d.ts +0 -43
- package/dist/schedule-expression.d.ts.map +0 -1
- package/dist/schedule-expression.js +0 -105
- package/dist/schedule-expression.js.map +0 -1
- package/dist/schedule-handlers.d.ts +0 -12
- package/dist/schedule-handlers.d.ts.map +0 -1
- package/dist/schedule-handlers.js +0 -122
- package/dist/schedule-handlers.js.map +0 -1
- package/dist/session-handlers.d.ts +0 -40
- package/dist/session-handlers.d.ts.map +0 -1
- package/dist/session-handlers.js +0 -610
- package/dist/session-handlers.js.map +0 -1
- package/dist/settings-handlers.d.ts +0 -10
- package/dist/settings-handlers.d.ts.map +0 -1
- package/dist/settings-handlers.js +0 -80
- package/dist/settings-handlers.js.map +0 -1
- package/dist/signals/escalation-auto.d.ts +0 -20
- package/dist/signals/escalation-auto.d.ts.map +0 -1
- package/dist/signals/escalation-auto.js +0 -126
- package/dist/signals/escalation-auto.js.map +0 -1
- package/dist/signals/orphan-reparent.d.ts +0 -31
- package/dist/signals/orphan-reparent.d.ts.map +0 -1
- package/dist/signals/orphan-reparent.js +0 -175
- package/dist/signals/orphan-reparent.js.map +0 -1
- package/dist/signals/sigchld.d.ts +0 -12
- package/dist/signals/sigchld.d.ts.map +0 -1
- package/dist/signals/sigchld.js +0 -177
- package/dist/signals/sigchld.js.map +0 -1
- package/dist/task-handlers.d.ts +0 -22
- package/dist/task-handlers.d.ts.map +0 -1
- package/dist/task-handlers.js +0 -518
- package/dist/task-handlers.js.map +0 -1
- package/dist/test-utils/integration-setup.d.ts +0 -11
- package/dist/test-utils/integration-setup.d.ts.map +0 -1
- package/dist/test-utils/integration-setup.js +0 -26
- package/dist/test-utils/integration-setup.js.map +0 -1
- package/dist/token-handlers.d.ts +0 -12
- package/dist/token-handlers.d.ts.map +0 -1
- package/dist/token-handlers.js +0 -85
- package/dist/token-handlers.js.map +0 -1
- package/dist/utils/format-gh-error.d.ts +0 -6
- package/dist/utils/format-gh-error.d.ts.map +0 -1
- package/dist/utils/format-gh-error.js +0 -30
- package/dist/utils/format-gh-error.js.map +0 -1
- package/dist/workspace-handlers.d.ts +0 -16
- package/dist/workspace-handlers.d.ts.map +0 -1
- package/dist/workspace-handlers.js +0 -146
- package/dist/workspace-handlers.js.map +0 -1
package/dist/orphan-phase.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Orphan reconciliation phase — periodic safety net for orphaned tasks.
|
|
3
|
-
*
|
|
4
|
-
* Sweeps all tasks for children whose parent is in a terminal state but
|
|
5
|
-
* haven't been reparented by the event-driven handler. This catches edge
|
|
6
|
-
* cases like server restarts, race conditions, or missed events.
|
|
7
|
-
*/
|
|
8
|
-
import { ROOT_TASK_ID, TASK_STATUS } from "@grackle-ai/common";
|
|
9
|
-
import { logger } from "./logger.js";
|
|
10
|
-
/** Terminal task statuses that indicate the parent is done. */
|
|
11
|
-
const TERMINAL_TASK_STATUSES = new Set([
|
|
12
|
-
TASK_STATUS.COMPLETE,
|
|
13
|
-
TASK_STATUS.FAILED,
|
|
14
|
-
]);
|
|
15
|
-
/**
|
|
16
|
-
* Create the orphan reconciliation phase.
|
|
17
|
-
*
|
|
18
|
-
* @param deps - Injected dependencies for testability.
|
|
19
|
-
* @returns A ReconciliationPhase that can be registered with the ReconciliationManager.
|
|
20
|
-
*/
|
|
21
|
-
export function createOrphanPhase(deps) {
|
|
22
|
-
return {
|
|
23
|
-
name: "orphan-reparent",
|
|
24
|
-
execute: async () => {
|
|
25
|
-
const allTasks = deps.listAllTasks();
|
|
26
|
-
// Build a lookup map for quick parent resolution
|
|
27
|
-
const taskById = new Map(allTasks.map((t) => [t.id, t]));
|
|
28
|
-
let reparentCount = 0;
|
|
29
|
-
for (const task of allTasks) {
|
|
30
|
-
// Skip root tasks and tasks with no parent
|
|
31
|
-
if (!task.parentTaskId || task.parentTaskId === ROOT_TASK_ID) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
// Skip terminal tasks (they don't need reparenting)
|
|
35
|
-
if (TERMINAL_TASK_STATUSES.has(task.status)) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
// Check if parent is terminal
|
|
39
|
-
const parent = taskById.get(task.parentTaskId);
|
|
40
|
-
if (!parent || !TERMINAL_TASK_STATUSES.has(parent.status)) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
// This is an orphan! Reparent to grandparent (or root)
|
|
44
|
-
const grandparentId = parent.parentTaskId || ROOT_TASK_ID;
|
|
45
|
-
try {
|
|
46
|
-
deps.reparentTask(task.id, grandparentId);
|
|
47
|
-
deps.emit("task.reparented", {
|
|
48
|
-
taskId: task.id,
|
|
49
|
-
oldParentTaskId: task.parentTaskId,
|
|
50
|
-
newParentTaskId: grandparentId,
|
|
51
|
-
workspaceId: task.workspaceId || "",
|
|
52
|
-
});
|
|
53
|
-
deps.emit("task.updated", {
|
|
54
|
-
taskId: task.id,
|
|
55
|
-
workspaceId: task.workspaceId || "",
|
|
56
|
-
});
|
|
57
|
-
reparentCount++;
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
logger.error({ err, taskId: task.id, parentTaskId: task.parentTaskId, grandparentId }, "Orphan phase: failed to reparent task");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (reparentCount > 0) {
|
|
64
|
-
logger.warn({ reparentCount }, "Orphan phase: reparented %d orphaned task(s) — these should have been caught by the event-driven handler", reparentCount);
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=orphan-phase.js.map
|
package/dist/orphan-phase.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orphan-phase.js","sourceRoot":"","sources":["../src/orphan-phase.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAKrC,+DAA+D;AAC/D,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC;IAC1D,WAAW,CAAC,QAAQ;IACpB,WAAW,C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AY;wBAClC,eAAe,EAAE,aAAa;wBAC9B,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;qBACpC,CAAC,CAAC;oBACH,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;wBACxB,MAAM,EAAE,IAAI,CAAC,EAAE;wBACf,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE;qBACpC,CAAC,CAAC;oBACH,aAAa,EAAE,CAAC;gBAClB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,MAAM,CAAC,KAAK,CACV,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,aAAa,EAAE,EACxE,uCAAuC,CACxC,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;gBACtB,MAAM,CAAC,IAAI,CACT,EAAE,aAAa,EAAE,EACjB,0GAA0G,EAC1G,aAAa,CACd,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { grackle } from "@grackle-ai/common";
|
|
2
|
-
/** List all personas. */
|
|
3
|
-
export declare function listPersonas(): Promise<grackle.PersonaList>;
|
|
4
|
-
/** Create a new persona. */
|
|
5
|
-
export declare function createPersona(req: grackle.CreatePersonaRequest): Promise<grackle.Persona>;
|
|
6
|
-
/** Get a persona by ID. */
|
|
7
|
-
export declare function getPersona(req: grackle.PersonaId): Promise<grackle.Persona>;
|
|
8
|
-
/** Update an existing persona. */
|
|
9
|
-
export declare function updatePersona(req: grackle.UpdatePersonaRequest): Promise<grackle.Persona>;
|
|
10
|
-
/** Delete a persona by ID. */
|
|
11
|
-
export declare function deletePersona(req: grackle.PersonaId): Promise<grackle.Empty>;
|
|
12
|
-
//# sourceMappingURL=persona-handlers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"persona-handlers.d.ts","sourceRoot":"","sources":["../src/persona-handlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAQ7C,yBAAyB;AACzB,wBAAsB,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAKjE;AAED,4BAA4B;AAC5B,wBAAsB,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAsE/F;AAED,2BAA2B;AAC3B,wBAAsB,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAMjF;AAED,kCAAkC;AAClC,wBAAsB,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAkG/F;AAED,8BAA8B;AAC9B,wBAAsB,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAIlF"}
|
package/dist/persona-handlers.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { ConnectError, Code } from "@connectrpc/connect";
|
|
2
|
-
import { create } from "@bufbuild/protobuf";
|
|
3
|
-
import { grackle } from "@grackle-ai/common";
|
|
4
|
-
import { ALL_MCP_TOOL_NAMES } from "@grackle-ai/common";
|
|
5
|
-
import { personaStore, settingsStore, envRegistry } from "@grackle-ai/database";
|
|
6
|
-
import { v4 as uuid } from "uuid";
|
|
7
|
-
import { slugify } from "@grackle-ai/database";
|
|
8
|
-
import { emit } from "./event-bus.js";
|
|
9
|
-
import { personaRowToProto } from "./grpc-proto-converters.js";
|
|
10
|
-
/** List all personas. */
|
|
11
|
-
export async function listPersonas() {
|
|
12
|
-
const rows = personaStore.listPersonas();
|
|
13
|
-
return create(grackle.PersonaListSchema, {
|
|
14
|
-
personas: rows.map(personaRowToProto),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
/** Create a new persona. */
|
|
18
|
-
export async function createPersona(req) {
|
|
19
|
-
if (!req.name) {
|
|
20
|
-
throw new ConnectError("Persona name is required", Code.InvalidArgument);
|
|
21
|
-
}
|
|
22
|
-
const personaType = req.type || "agent";
|
|
23
|
-
if (personaType !== "agent" && personaType !== "script") {
|
|
24
|
-
throw new ConnectError(`Invalid persona type: "${personaType}". Must be "agent" or "script".`, Code.InvalidArgument);
|
|
25
|
-
}
|
|
26
|
-
if (personaType === "script") {
|
|
27
|
-
if (!req.script) {
|
|
28
|
-
throw new ConnectError("Script content is required for script personas", Code.InvalidArgument);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
if (!req.systemPrompt) {
|
|
33
|
-
throw new ConnectError("Persona system_prompt is required", Code.InvalidArgument);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// Enforce unique ID and unique name
|
|
37
|
-
let id = slugify(req.name) || uuid().slice(0, 8);
|
|
38
|
-
if (personaStore.getPersona(id)) {
|
|
39
|
-
id = `${id}-${uuid().slice(0, 4)}`;
|
|
40
|
-
}
|
|
41
|
-
if (personaStore.getPersonaByName(req.name)) {
|
|
42
|
-
throw new ConnectError(`Persona with name "${req.name}" already exists`, Code.AlreadyExists);
|
|
43
|
-
}
|
|
44
|
-
const toolConfigJson = JSON.stringify({
|
|
45
|
-
allowedTools: [...(req.toolConfig?.allowedTools || [])],
|
|
46
|
-
disallowedTools: [...(req.toolConfig?.disallowedTools || [])],
|
|
47
|
-
});
|
|
48
|
-
const mcpServersJson = JSON.stringify(req.mcpServers.map((s) => ({
|
|
49
|
-
name: s.name,
|
|
50
|
-
command: s.command,
|
|
51
|
-
args: [...s.args],
|
|
52
|
-
tools: [...s.tools],
|
|
53
|
-
})));
|
|
54
|
-
// Validate allowed MCP tools against the known tool registry
|
|
55
|
-
const allowedMcpTools = Array.isArray(req.allowedMcpTools) ? [...req.allowedMcpTools] : [];
|
|
56
|
-
if (allowedMcpTools.length > 0) {
|
|
57
|
-
const invalid = allowedMcpTools.filter((t) => !ALL_MCP_TOOL_NAMES.has(t));
|
|
58
|
-
if (invalid.length > 0) {
|
|
59
|
-
throw new ConnectError(`Invalid MCP tool name(s): ${invalid.join(", ")}`, Code.InvalidArgument);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const allowedMcpToolsJson = JSON.stringify(allowedMcpTools);
|
|
63
|
-
personaStore.createPersona(id, req.name, req.description, req.systemPrompt, toolConfigJson, req.runtime, req.model, req.maxTurns, mcpServersJson, personaType, req.script, allowedMcpToolsJson);
|
|
64
|
-
emit("persona.created", { personaId: id });
|
|
65
|
-
const row = personaStore.getPersona(id);
|
|
66
|
-
return personaRowToProto(row);
|
|
67
|
-
}
|
|
68
|
-
/** Get a persona by ID. */
|
|
69
|
-
export async function getPersona(req) {
|
|
70
|
-
const row = personaStore.getPersona(req.id);
|
|
71
|
-
if (!row) {
|
|
72
|
-
throw new ConnectError(`Persona not found: ${req.id}`, Code.NotFound);
|
|
73
|
-
}
|
|
74
|
-
return personaRowToProto(row);
|
|
75
|
-
}
|
|
76
|
-
/** Update an existing persona. */
|
|
77
|
-
export async function updatePersona(req) {
|
|
78
|
-
const existing = personaStore.getPersona(req.id);
|
|
79
|
-
if (!existing) {
|
|
80
|
-
throw new ConnectError(`Persona not found: ${req.id}`, Code.NotFound);
|
|
81
|
-
}
|
|
82
|
-
// Only update toolConfig/mcpServers if the request provides non-empty values;
|
|
83
|
-
// otherwise keep the existing stored value.
|
|
84
|
-
const hasNewToolConfig = !!req.toolConfig &&
|
|
85
|
-
(req.toolConfig.allowedTools.length > 0 ||
|
|
86
|
-
req.toolConfig.disallowedTools.length > 0);
|
|
87
|
-
const toolConfigJson = hasNewToolConfig
|
|
88
|
-
? JSON.stringify({
|
|
89
|
-
allowedTools: [...(req.toolConfig?.allowedTools || [])],
|
|
90
|
-
disallowedTools: [...(req.toolConfig?.disallowedTools || [])],
|
|
91
|
-
})
|
|
92
|
-
: existing.toolConfig;
|
|
93
|
-
const hasNewMcpServers = Array.isArray(req.mcpServers) && req.mcpServers.length > 0;
|
|
94
|
-
const mcpServersJson = hasNewMcpServers
|
|
95
|
-
? JSON.stringify(req.mcpServers.map((s) => ({
|
|
96
|
-
name: s.name,
|
|
97
|
-
command: s.command,
|
|
98
|
-
args: [...s.args],
|
|
99
|
-
tools: [...s.tools],
|
|
100
|
-
})))
|
|
101
|
-
: existing.mcpServers;
|
|
102
|
-
// Treat empty string / 0 as "not set" and keep existing value
|
|
103
|
-
const name = req.name || existing.name;
|
|
104
|
-
if (name !== existing.name && personaStore.getPersonaByName(name)) {
|
|
105
|
-
throw new ConnectError(`Persona with name "${name}" already exists`, Code.AlreadyExists);
|
|
106
|
-
}
|
|
107
|
-
const description = req.description || existing.description;
|
|
108
|
-
const systemPrompt = req.systemPrompt || existing.systemPrompt;
|
|
109
|
-
const runtime = req.runtime || existing.runtime;
|
|
110
|
-
const model = req.model || existing.model;
|
|
111
|
-
const maxTurns = req.maxTurns === 0 ? existing.maxTurns : req.maxTurns;
|
|
112
|
-
// Empty string means "keep existing", non-empty means "set to this value"
|
|
113
|
-
const updatedType = req.type || existing.type;
|
|
114
|
-
const updatedScript = req.script || existing.script;
|
|
115
|
-
// AllowedMcpTools is a wrapper message with proto3 presence tracking:
|
|
116
|
-
// - absent (undefined) → preserve existing value
|
|
117
|
-
// - present with empty tools → clear to default (revert to full set)
|
|
118
|
-
// - present with tools → validate and replace
|
|
119
|
-
let allowedMcpToolsJson;
|
|
120
|
-
if (req.allowedMcpTools) {
|
|
121
|
-
const tools = [...req.allowedMcpTools.tools];
|
|
122
|
-
if (tools.length > 0) {
|
|
123
|
-
const invalid = tools.filter((t) => !ALL_MCP_TOOL_NAMES.has(t));
|
|
124
|
-
if (invalid.length > 0) {
|
|
125
|
-
throw new ConnectError(`Invalid MCP tool name(s): ${invalid.join(", ")}`, Code.InvalidArgument);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
allowedMcpToolsJson = JSON.stringify(tools);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
allowedMcpToolsJson = existing.allowedMcpTools;
|
|
132
|
-
}
|
|
133
|
-
personaStore.updatePersona(req.id, name, description, systemPrompt, toolConfigJson, runtime, model, maxTurns, mcpServersJson, updatedType, updatedScript, allowedMcpToolsJson);
|
|
134
|
-
// Sync the local environment's defaultRuntime when the app-level default
|
|
135
|
-
// persona's runtime changes, so bootstrap pre-installs the correct packages.
|
|
136
|
-
if (runtime !== existing.runtime) {
|
|
137
|
-
const appDefault = settingsStore.getSetting("default_persona_id") || "";
|
|
138
|
-
if (appDefault === req.id) {
|
|
139
|
-
const localEnv = envRegistry.getEnvironment("local");
|
|
140
|
-
if (localEnv) {
|
|
141
|
-
envRegistry.updateDefaultRuntime("local", runtime);
|
|
142
|
-
emit("environment.changed", {});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
emit("persona.updated", { personaId: req.id });
|
|
147
|
-
const row = personaStore.getPersona(req.id);
|
|
148
|
-
return personaRowToProto(row);
|
|
149
|
-
}
|
|
150
|
-
/** Delete a persona by ID. */
|
|
151
|
-
export async function deletePersona(req) {
|
|
152
|
-
personaStore.deletePersona(req.id);
|
|
153
|
-
emit("persona.deleted", { personaId: req.id });
|
|
154
|
-
return create(grackle.EmptySchema, {});
|
|
155
|
-
}
|
|
156
|
-
//# sourceMappingURL=persona-handlers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"persona-handlers.js","sourceRoot":"","sources":["../src/persona-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,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AAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,CAAC,iBAAiB,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5C,OAAO,iBAAiB,CAAC,GAAI,CAAC,CAAC;AACjC,CAAC;AAED,8BAA8B;AAC9B,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAsB;IACxD,YAAY,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACnC,IAAI,CAAC,iBAAiB,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/root-task-boot.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Root task boot with reanimate-first strategy and exponential backoff.
|
|
3
|
-
*
|
|
4
|
-
* Extracted from the inline closure in `server/src/index.ts` so it can be
|
|
5
|
-
* unit tested. Follows the dependency-injection pattern established by
|
|
6
|
-
* `cron-phase.ts`.
|
|
7
|
-
*
|
|
8
|
-
* On each invocation (triggered by `environment.changed` events):
|
|
9
|
-
* 1. Checks if the root task is already running — if so, tracks stability.
|
|
10
|
-
* 2. If not running, attempts to reanimate the most recent session (preserving
|
|
11
|
-
* conversation history) before falling back to a fresh spawn.
|
|
12
|
-
* 3. Applies exponential backoff after consecutive failures to prevent
|
|
13
|
-
* crash-loop resource waste.
|
|
14
|
-
*
|
|
15
|
-
* @module
|
|
16
|
-
*/
|
|
17
|
-
import type { TaskRow, SessionRow, EnvironmentRow } from "@grackle-ai/database";
|
|
18
|
-
import type { TaskStatusResult } from "./compute-task-status.js";
|
|
19
|
-
import type { Disposable, PluginContext } from "./subscriber-types.js";
|
|
20
|
-
/** Dependencies injected into the root task boot module for testability. */
|
|
21
|
-
export interface RootTaskBootDeps {
|
|
22
|
-
/** Look up a task by ID. */
|
|
23
|
-
getTask: (id: string) => TaskRow | undefined;
|
|
24
|
-
/** List all sessions for a task. */
|
|
25
|
-
listSessionsForTask: (taskId: string) => Pick<SessionRow, "id" | "status" | "startedAt">[];
|
|
26
|
-
/** Get the most recent session for a task (by startedAt DESC). */
|
|
27
|
-
getLatestSessionForTask: (taskId: string) => SessionRow | undefined;
|
|
28
|
-
/** Compute effective task status from stored status + session history. */
|
|
29
|
-
computeTaskStatus: (storedStatus: string, sessions: Pick<SessionRow, "id" | "status" | "startedAt">[]) => TaskStatusResult;
|
|
30
|
-
/** Find the first connected environment, preferring local. */
|
|
31
|
-
findFirstConnectedEnvironment: () => EnvironmentRow | undefined;
|
|
32
|
-
/** Start a new agent session for a task. Returns error string on failure, undefined on success. */
|
|
33
|
-
startTaskSession: (task: TaskRow, options?: {
|
|
34
|
-
environmentId?: string;
|
|
35
|
-
notes?: string;
|
|
36
|
-
}) => Promise<string | undefined>;
|
|
37
|
-
/** Reanimate a terminal session by resuming it on PowerLine. Throws on failure. */
|
|
38
|
-
reanimateAgent: (sessionId: string) => SessionRow;
|
|
39
|
-
/** Whether onboarding is complete. Boot is deferred until the user has chosen a runtime (#1031). */
|
|
40
|
-
isOnboarded?: () => boolean;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Create the root task boot handler.
|
|
44
|
-
*
|
|
45
|
-
* Returns a callable async function that can be wired to `environment.changed`
|
|
46
|
-
* event subscriptions. Each call checks whether the root task needs starting
|
|
47
|
-
* and applies reanimate-first + exponential backoff logic.
|
|
48
|
-
*
|
|
49
|
-
* Each call creates independent backoff state (not shared across calls).
|
|
50
|
-
*
|
|
51
|
-
* @param deps - Injected dependencies for testability.
|
|
52
|
-
* @returns An async function to call on each `environment.changed` event.
|
|
53
|
-
*/
|
|
54
|
-
export declare function createRootTaskBoot(deps: RootTaskBootDeps): () => Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* Create the root task boot subscriber.
|
|
57
|
-
*
|
|
58
|
-
* Creates independent backoff state (not shared with other factory calls)
|
|
59
|
-
* and subscribes to `environment.changed` and `setting.changed` events.
|
|
60
|
-
* Returns a Disposable that unsubscribes the handler.
|
|
61
|
-
*
|
|
62
|
-
* @param ctx - Plugin context providing event-bus access.
|
|
63
|
-
* @param deps - Injected dependencies for testability.
|
|
64
|
-
* @returns A Disposable that unsubscribes the handler.
|
|
65
|
-
*/
|
|
66
|
-
export declare function createRootTaskBootSubscriber(ctx: PluginContext, deps: RootTaskBootDeps): Disposable;
|
|
67
|
-
//# sourceMappingURL=root-task-boot.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"root-task-boot.d.ts","sourceRoot":"","sources":["../src/root-task-boot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEhF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAqBvE,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,4BAA4B;IAC5B,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,GAAG,SAAS,CAAC;IAC7C,oCAAoC;IACpC,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,QAAQ,GAAG,WAAW,CAAC,EAAE,CAAC;IAC3F,kEAAkE;IAClE,uBAAuB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAC;IACpE,0EAA0E;IAC1E,iBAAiB,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,QAAQ,GAAG,WAAW,CAAC,EAAE,KAAK,gBAAgB,CAAC;IAC3H,8DAA8D;IAC9D,6BAA6B,EAAE,MAAM,cAAc,GAAG,SAAS,CAAC;IAChE,mGAAmG;IACnG,gBAAgB,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACvH,mFAAmF;IACnF,cAAc,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,UAAU,CAAC;IAClD,oGAAoG;IACpG,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC;CAC7B;AA4BD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAE9E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,gBAAgB,GAAG,UAAU,CAuBnG"}
|
package/dist/root-task-boot.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Root task boot with reanimate-first strategy and exponential backoff.
|
|
3
|
-
*
|
|
4
|
-
* Extracted from the inline closure in `server/src/index.ts` so it can be
|
|
5
|
-
* unit tested. Follows the dependency-injection pattern established by
|
|
6
|
-
* `cron-phase.ts`.
|
|
7
|
-
*
|
|
8
|
-
* On each invocation (triggered by `environment.changed` events):
|
|
9
|
-
* 1. Checks if the root task is already running — if so, tracks stability.
|
|
10
|
-
* 2. If not running, attempts to reanimate the most recent session (preserving
|
|
11
|
-
* conversation history) before falling back to a fresh spawn.
|
|
12
|
-
* 3. Applies exponential backoff after consecutive failures to prevent
|
|
13
|
-
* crash-loop resource waste.
|
|
14
|
-
*
|
|
15
|
-
* @module
|
|
16
|
-
*/
|
|
17
|
-
import { ROOT_TASK_ID, ROOT_TASK_INITIAL_PROMPT, TASK_STATUS } from "@grackle-ai/common";
|
|
18
|
-
import { logger } from "./logger.js";
|
|
19
|
-
// ─── Constants ──────────────────────────────────────────────
|
|
20
|
-
/** Initial delay before the first retry after a failed boot (milliseconds). */
|
|
21
|
-
const BOOT_INITIAL_DELAY_MS = 1_000;
|
|
22
|
-
/** Multiplier for exponential backoff between boot retries. */
|
|
23
|
-
const BOOT_BACKOFF_MULTIPLIER = 2;
|
|
24
|
-
/** Maximum delay between boot retries (milliseconds). */
|
|
25
|
-
const BOOT_MAX_DELAY_MS = 60_000;
|
|
26
|
-
/** Maximum consecutive boot failures before giving up until server restart. */
|
|
27
|
-
const BOOT_MAX_FAILURES = 10;
|
|
28
|
-
/** Minimum time a session must survive (ms) to be considered stable and reset backoff. */
|
|
29
|
-
const BOOT_STABLE_THRESHOLD_MS = 30_000;
|
|
30
|
-
// ─── State ──────────────────────────────────────────────────
|
|
31
|
-
/** Create a fresh backoff state. */
|
|
32
|
-
function createInitialState() {
|
|
33
|
-
return {
|
|
34
|
-
failures: 0,
|
|
35
|
-
lastFailureAt: 0,
|
|
36
|
-
inProgress: false,
|
|
37
|
-
lastSessionStartedAt: 0,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
// ─── Public API ─────────────────────────────────────────────
|
|
41
|
-
/**
|
|
42
|
-
* Create the root task boot handler.
|
|
43
|
-
*
|
|
44
|
-
* Returns a callable async function that can be wired to `environment.changed`
|
|
45
|
-
* event subscriptions. Each call checks whether the root task needs starting
|
|
46
|
-
* and applies reanimate-first + exponential backoff logic.
|
|
47
|
-
*
|
|
48
|
-
* Each call creates independent backoff state (not shared across calls).
|
|
49
|
-
*
|
|
50
|
-
* @param deps - Injected dependencies for testability.
|
|
51
|
-
* @returns An async function to call on each `environment.changed` event.
|
|
52
|
-
*/
|
|
53
|
-
export function createRootTaskBoot(deps) {
|
|
54
|
-
return createRootTaskBootHandler(deps, createInitialState());
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Create the root task boot subscriber.
|
|
58
|
-
*
|
|
59
|
-
* Creates independent backoff state (not shared with other factory calls)
|
|
60
|
-
* and subscribes to `environment.changed` and `setting.changed` events.
|
|
61
|
-
* Returns a Disposable that unsubscribes the handler.
|
|
62
|
-
*
|
|
63
|
-
* @param ctx - Plugin context providing event-bus access.
|
|
64
|
-
* @param deps - Injected dependencies for testability.
|
|
65
|
-
* @returns A Disposable that unsubscribes the handler.
|
|
66
|
-
*/
|
|
67
|
-
export function createRootTaskBootSubscriber(ctx, deps) {
|
|
68
|
-
const bootState = createInitialState();
|
|
69
|
-
const tryBoot = createRootTaskBootHandler(deps, bootState);
|
|
70
|
-
const unsubscribe = ctx.subscribe((event) => {
|
|
71
|
-
if (event.type === "environment.changed") {
|
|
72
|
-
tryBoot().catch(() => { });
|
|
73
|
-
}
|
|
74
|
-
// Also try when onboarding completes — the environment is already
|
|
75
|
-
// connected but boot was deferred until the user chose a runtime.
|
|
76
|
-
if (event.type === "setting.changed") {
|
|
77
|
-
const payload = event.payload;
|
|
78
|
-
if (payload.key === "onboarding_completed" && payload.value === "true") {
|
|
79
|
-
tryBoot().catch(() => { });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
return {
|
|
84
|
-
dispose() {
|
|
85
|
-
unsubscribe();
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
// ─── Internal ───────────────────────────────────────────────
|
|
90
|
-
/**
|
|
91
|
-
* Create an async boot handler that uses the given backoff state.
|
|
92
|
-
* Shared implementation for both {@link createRootTaskBoot} and
|
|
93
|
-
* {@link createRootTaskBootSubscriber}.
|
|
94
|
-
*/
|
|
95
|
-
function createRootTaskBootHandler(deps, s) {
|
|
96
|
-
return async () => {
|
|
97
|
-
// Guard: prevent concurrent boot attempts
|
|
98
|
-
if (s.inProgress) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
s.inProgress = true;
|
|
102
|
-
try {
|
|
103
|
-
await attemptBoot(deps, s);
|
|
104
|
-
}
|
|
105
|
-
catch (err) {
|
|
106
|
-
recordFailure(s);
|
|
107
|
-
logger.warn({ err }, "Root task boot failed with unexpected exception");
|
|
108
|
-
}
|
|
109
|
-
finally {
|
|
110
|
-
s.inProgress = false; // eslint-disable-line require-atomic-updates -- single-threaded, flag guards re-entry
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
/** Core boot logic — separated from the guard/error wrapper for clarity. */
|
|
115
|
-
async function attemptBoot(deps, s) {
|
|
116
|
-
// 0. Don't auto-start before onboarding — the user hasn't chosen their
|
|
117
|
-
// runtime yet, so the root task would launch with the default "claude-code".
|
|
118
|
-
if (deps.isOnboarded && !deps.isOnboarded()) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
// 1. Look up root task
|
|
122
|
-
const rootTask = deps.getTask(ROOT_TASK_ID);
|
|
123
|
-
if (!rootTask) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
// 2. Check if already working
|
|
127
|
-
const sessions = deps.listSessionsForTask(ROOT_TASK_ID);
|
|
128
|
-
const { status } = deps.computeTaskStatus(rootTask.status, sessions);
|
|
129
|
-
if (status === TASK_STATUS.WORKING) {
|
|
130
|
-
checkStabilityReset(s);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
// 2b. Crash-loop detection: if we recently started a session but the task
|
|
134
|
-
// is no longer working before the stability threshold, count it as a failure.
|
|
135
|
-
// This catches the case where startTaskSession succeeded but the session
|
|
136
|
-
// crashed shortly after (the main crash-loop scenario from issue #959).
|
|
137
|
-
if (s.lastSessionStartedAt > 0) {
|
|
138
|
-
const sinceLastStart = Date.now() - s.lastSessionStartedAt;
|
|
139
|
-
if (sinceLastStart < BOOT_STABLE_THRESHOLD_MS) {
|
|
140
|
-
// Session crashed before reaching stability — record as failure
|
|
141
|
-
if (s.lastFailureAt < s.lastSessionStartedAt) {
|
|
142
|
-
// Only record once per start (guard against multiple environment.changed events)
|
|
143
|
-
recordFailure(s);
|
|
144
|
-
logger.info({ survivedMs: sinceLastStart, failures: s.failures }, "Root task session crashed before stability threshold — recording failure");
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
// Session survived past stability threshold but is now stopped — reset backoff
|
|
149
|
-
resetBackoff(s, sinceLastStart);
|
|
150
|
-
}
|
|
151
|
-
s.lastSessionStartedAt = 0;
|
|
152
|
-
}
|
|
153
|
-
// 3. Find connected environment
|
|
154
|
-
const connectedEnv = deps.findFirstConnectedEnvironment();
|
|
155
|
-
if (!connectedEnv) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
// 4. Check backoff
|
|
159
|
-
if (s.failures >= BOOT_MAX_FAILURES) {
|
|
160
|
-
// Log only once when the threshold is first reached to avoid spam
|
|
161
|
-
if (s.failures === BOOT_MAX_FAILURES) {
|
|
162
|
-
logger.error({ failures: s.failures }, "Root task boot exhausted all retries (%d failures) — giving up until server restart", s.failures);
|
|
163
|
-
}
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (s.failures > 0) {
|
|
167
|
-
const delay = Math.min(BOOT_INITIAL_DELAY_MS * Math.pow(BOOT_BACKOFF_MULTIPLIER, s.failures - 1), BOOT_MAX_DELAY_MS);
|
|
168
|
-
const elapsed = Date.now() - s.lastFailureAt;
|
|
169
|
-
if (elapsed < delay) {
|
|
170
|
-
return; // backoff not elapsed yet
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// 5. Reanimate-first: try to resume the latest session
|
|
174
|
-
let booted = false;
|
|
175
|
-
const latestSession = deps.getLatestSessionForTask(ROOT_TASK_ID);
|
|
176
|
-
if (latestSession?.runtimeSessionId) {
|
|
177
|
-
try {
|
|
178
|
-
deps.reanimateAgent(latestSession.id);
|
|
179
|
-
booted = true;
|
|
180
|
-
logger.info({ sessionId: latestSession.id, environmentId: latestSession.environmentId }, "Root task reanimated existing session");
|
|
181
|
-
}
|
|
182
|
-
catch (reanimateErr) {
|
|
183
|
-
logger.info({ sessionId: latestSession.id, err: reanimateErr }, "Root task reanimate failed — falling back to fresh spawn");
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
// 6. Fresh spawn (fallback)
|
|
187
|
-
if (!booted) {
|
|
188
|
-
const err = await deps.startTaskSession(rootTask, {
|
|
189
|
-
environmentId: connectedEnv.id,
|
|
190
|
-
notes: ROOT_TASK_INITIAL_PROMPT,
|
|
191
|
-
});
|
|
192
|
-
if (err) {
|
|
193
|
-
recordFailure(s);
|
|
194
|
-
logger.warn({ err }, "Root task auto-start failed");
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
logger.info({ environmentId: connectedEnv.id }, "Root task auto-started (fresh spawn)");
|
|
198
|
-
}
|
|
199
|
-
// 7. Track session start time for stability detection
|
|
200
|
-
s.lastSessionStartedAt = Date.now(); // eslint-disable-line require-atomic-updates -- single-threaded
|
|
201
|
-
}
|
|
202
|
-
/** Record a boot failure: increment counter and timestamp. */
|
|
203
|
-
function recordFailure(s) {
|
|
204
|
-
s.failures++;
|
|
205
|
-
s.lastFailureAt = Date.now();
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* If the root task has been WORKING long enough (past the stability threshold),
|
|
209
|
-
* reset the backoff counter. Called when we detect the task is already running.
|
|
210
|
-
*/
|
|
211
|
-
function checkStabilityReset(s) {
|
|
212
|
-
if (s.failures === 0) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
if (s.lastSessionStartedAt > 0) {
|
|
216
|
-
const elapsed = Date.now() - s.lastSessionStartedAt;
|
|
217
|
-
if (elapsed >= BOOT_STABLE_THRESHOLD_MS) {
|
|
218
|
-
resetBackoff(s, elapsed);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
// Task is WORKING but we didn't start it (e.g., session recovery
|
|
223
|
-
// reanimated it externally). Begin tracking stability from now so
|
|
224
|
-
// backoff can eventually reset — otherwise MAX_FAILURES is permanent.
|
|
225
|
-
s.lastSessionStartedAt = Date.now();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/** Zero out the backoff state after a session has proven stable. */
|
|
229
|
-
function resetBackoff(s, survivedMs) {
|
|
230
|
-
logger.info({ survivedMs, previousFailures: s.failures }, "Root task session stable — resetting backoff");
|
|
231
|
-
s.failures = 0;
|
|
232
|
-
s.lastFailureAt = 0;
|
|
233
|
-
}
|
|
234
|
-
//# sourceMappingURL=root-task-boot.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"root-task-boot.js","sourceRoot":"","sources":["../src/root-task-boot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIzF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,+DAA+D;AAE/D,+EAA+E;AAC/E,MAAM,qBAAqB,GAAW,KAAK,CAAC;AAE5C,+DAA+D;AAC/D,MAAM,uBAAuB,GAAW,CAAC,CAAC;AAE1C,yDAAyD;AACzD,MAAM,iBAAiB,GAAW,MAAM,CAAC;AAEzC,+EAA+E;AAC/E,MAAM,iBAAiB,GAAW,EAAE,CAAC;AAErC,0FAA0F;AAC1F,MAAM,wBAAwB,GAAW,MAAM,CAAC;AAoChD,+DAA+D;AAE/D,oCAAoC;AACpC,SAAS,kBAAkB;IACzB,OAAO;QACL,QAAQ,EAAE,CAAC;QACX,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,KAAK;QACjB,oBAAoB,EAAE,CAAC;KACxB,CAAC;AACJ,CAAC;AAED,+DAA+D;AAE/D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAs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CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,CAAY;IACvC,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO;IACT,CAAC;IACD,IAAI,CAAC,CAAC,oBAAoB,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,oBAAoB,CAAC;QACpD,IAAI,OAAO,IAAI,wBAAwB,EAAE,CAAC;YACxC,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,kEAAkE;QAClE,sEAAsE;QACtE,CAAC,CAAC,oBAAoB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACtC,CAAC;AACH,CAAC;AAED,oEAAoE;AACpE,SAAS,YAAY,CAAC,CAAY,EAAE,UAAkB;IACpD,MAAM,CAAC,IAAI,CACT,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC,CAAC,QAAQ,EAAE,EAC5C,8CAA8C,CAC/C,CAAC;IACF,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC;IACf,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC;AACtB,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schedule expression parsing and next-run-time computation.
|
|
3
|
-
*
|
|
4
|
-
* Supports two formats:
|
|
5
|
-
* - **Interval shorthand**: `"<number><unit>"` where unit is s/m/h/d (min 10s)
|
|
6
|
-
* - **Cron expressions**: Standard 5-field cron syntax via `cron-parser`
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Parse an interval shorthand expression to milliseconds.
|
|
10
|
-
*
|
|
11
|
-
* @param expr - e.g. "30s", "5m", "1h", "1d"
|
|
12
|
-
* @returns Duration in milliseconds
|
|
13
|
-
* @throws If the expression is invalid or below the minimum (10s)
|
|
14
|
-
*/
|
|
15
|
-
export declare function parseDuration(expr: string): number;
|
|
16
|
-
/**
|
|
17
|
-
* Detect whether an expression is interval shorthand (vs. cron).
|
|
18
|
-
*
|
|
19
|
-
* @param expr - Schedule expression string
|
|
20
|
-
* @returns true if the expression matches interval shorthand format
|
|
21
|
-
*/
|
|
22
|
-
export declare function isIntervalExpression(expr: string): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Compute the next run time for a schedule expression.
|
|
25
|
-
*
|
|
26
|
-
* For intervals: if `lastRunAt + interval` is in the future, use that (prevents
|
|
27
|
-
* drift). Otherwise use `now + interval` (prevents burst-firing after downtime).
|
|
28
|
-
*
|
|
29
|
-
* For cron: next occurrence after now.
|
|
30
|
-
*
|
|
31
|
-
* @param expr - Schedule expression (interval or cron)
|
|
32
|
-
* @param lastRunAt - ISO timestamp of the last fire (undefined for first fire)
|
|
33
|
-
* @returns ISO timestamp of the next fire
|
|
34
|
-
*/
|
|
35
|
-
export declare function computeNextRunAt(expr: string, lastRunAt?: string): string;
|
|
36
|
-
/**
|
|
37
|
-
* Validate a schedule expression. Throws if invalid.
|
|
38
|
-
*
|
|
39
|
-
* @param expr - Schedule expression to validate
|
|
40
|
-
* @throws If the expression is neither valid interval shorthand nor valid cron
|
|
41
|
-
*/
|
|
42
|
-
export declare function validateExpression(expr: string): void;
|
|
43
|
-
//# sourceMappingURL=schedule-expression.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schedule-expression.d.ts","sourceRoot":"","sources":["../src/schedule-expression.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAmBlD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAwBzE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAmBrD"}
|