@fideliosai/server 0.0.12 → 0.0.13
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/onboarding-assets/ceo/HEARTBEAT.md +1 -0
- package/dist/services/heartbeat.d.ts +1 -0
- package/dist/services/heartbeat.d.ts.map +1 -1
- package/dist/services/heartbeat.js +69 -1
- package/dist/services/heartbeat.js.map +1 -1
- package/dist/services/issues.d.ts +17 -0
- package/dist/services/issues.d.ts.map +1 -1
- package/dist/services/issues.js +133 -0
- package/dist/services/issues.js.map +1 -1
- package/package.json +13 -13
|
@@ -6,6 +6,7 @@ Run this checklist on every heartbeat. This covers both your local planning/memo
|
|
|
6
6
|
|
|
7
7
|
- `GET /api/agents/me` -- confirm your id, role, budget, chainOfCommand.
|
|
8
8
|
- Check wake context: `FIDELIOS_TASK_ID`, `FIDELIOS_WAKE_REASON`, `FIDELIOS_WAKE_COMMENT_ID`.
|
|
9
|
+
- **If your prompt includes "## Issue Context (pre-compiled by FideliOS)"**, use it directly for the primary task. Do NOT call `heartbeat-context` or `comments` APIs for that issue -- the data is already in your prompt. Fall back to API calls only if pre-compiled context is absent.
|
|
9
10
|
|
|
10
11
|
## 2. Local Planning Check
|
|
11
12
|
|
|
@@ -160,6 +160,7 @@ export declare function heartbeatService(db: Db): {
|
|
|
160
160
|
taskKey: string;
|
|
161
161
|
sessionParamsJson: Record<string, unknown> | null;
|
|
162
162
|
sessionDisplayId: string | null;
|
|
163
|
+
lastSeenCommentId: string | null;
|
|
163
164
|
}[]>;
|
|
164
165
|
resetRuntimeSession: (agentId: string, opts?: {
|
|
165
166
|
taskKey?: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../src/services/heartbeat.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EACL,MAAM,EASP,MAAM,gB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AAC,kBACzB,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,UAChD;QAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAtzB1C,MAAM,SAAQ,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BA/gDnB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAsPb;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;uBAooE/C,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAEO,MAAM;mCA5MI,sBAAsB;oCAgN1B,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAe5C;;;OAGG;;EAwDN"}
|
|
@@ -727,13 +727,20 @@ export function heartbeatService(db) {
|
|
|
727
727
|
readNonEmptyString(latestSummary?.result) ??
|
|
728
728
|
readNonEmptyString(latestSummary?.message) ??
|
|
729
729
|
readNonEmptyString(latestRun.error);
|
|
730
|
+
const agentHome = resolveDefaultAgentWorkspaceDir(agent.id);
|
|
731
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
730
732
|
const handoffMarkdown = [
|
|
731
733
|
"FideliOS session handoff:",
|
|
732
734
|
`- Previous session: ${sessionId}`,
|
|
733
735
|
issueId ? `- Issue: ${issueId}` : "",
|
|
734
736
|
`- Rotation reason: ${reason}`,
|
|
735
737
|
latestTextSummary ? `- Last run summary: ${latestTextSummary}` : "",
|
|
736
|
-
"
|
|
738
|
+
"",
|
|
739
|
+
"Your persistent memory (if you have written any) survives session rotation:",
|
|
740
|
+
`- Daily notes: ${agentHome}/memory/ (check for ${today}.md or recent dates)`,
|
|
741
|
+
`- Knowledge graph: ${agentHome}/life/ (PARA structure)`,
|
|
742
|
+
`- Lessons learned: ${agentHome}/MEMORY.md (may not exist yet)`,
|
|
743
|
+
"Use glob or ls to check which memory files exist before reading. Do NOT assume files exist — create them if missing.",
|
|
737
744
|
]
|
|
738
745
|
.filter(Boolean)
|
|
739
746
|
.join("\n");
|
|
@@ -979,6 +986,7 @@ export function heartbeatService(db) {
|
|
|
979
986
|
sessionDisplayId: input.sessionDisplayId,
|
|
980
987
|
lastRunId: input.lastRunId,
|
|
981
988
|
lastError: input.lastError,
|
|
989
|
+
...(input.lastSeenCommentId !== undefined ? { lastSeenCommentId: input.lastSeenCommentId } : {}),
|
|
982
990
|
updatedAt: new Date(),
|
|
983
991
|
})
|
|
984
992
|
.where(eq(agentTaskSessions.id, existing.id))
|
|
@@ -996,6 +1004,7 @@ export function heartbeatService(db) {
|
|
|
996
1004
|
sessionDisplayId: input.sessionDisplayId,
|
|
997
1005
|
lastRunId: input.lastRunId,
|
|
998
1006
|
lastError: input.lastError,
|
|
1007
|
+
...(input.lastSeenCommentId !== undefined ? { lastSeenCommentId: input.lastSeenCommentId } : {}),
|
|
999
1008
|
})
|
|
1000
1009
|
.returning()
|
|
1001
1010
|
.then((rows) => rows[0] ?? null);
|
|
@@ -2042,6 +2051,23 @@ export function heartbeatService(db) {
|
|
|
2042
2051
|
payload: meta,
|
|
2043
2052
|
});
|
|
2044
2053
|
};
|
|
2054
|
+
// --- Pre-compiled heartbeat context bundle (Level 2 CAG) ---
|
|
2055
|
+
if (issueId) {
|
|
2056
|
+
try {
|
|
2057
|
+
const lastSeenCommentId = taskSessionForRun?.lastSeenCommentId ?? null;
|
|
2058
|
+
const bundle = await issuesSvc.buildHeartbeatContextBundle(issueId, {
|
|
2059
|
+
lastSeenCommentId,
|
|
2060
|
+
maxComments: 30,
|
|
2061
|
+
});
|
|
2062
|
+
if (bundle) {
|
|
2063
|
+
context.fideliosHeartbeatContext = bundle.markdown;
|
|
2064
|
+
context.fideliosHeartbeatContextCommentCursor = bundle.commentCursor;
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
catch (err) {
|
|
2068
|
+
logger.warn({ err, runId: run.id, issueId }, "failed to build heartbeat context bundle; agent will fall back to API calls");
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2045
2071
|
const adapter = getServerAdapter(agent.adapterType);
|
|
2046
2072
|
const authToken = adapter.supportsLocalAgentJwt
|
|
2047
2073
|
? createLocalAgentJwt(agent.id, agent.companyId, agent.adapterType, run.id)
|
|
@@ -2226,6 +2252,9 @@ export function heartbeatService(db) {
|
|
|
2226
2252
|
});
|
|
2227
2253
|
}
|
|
2228
2254
|
else {
|
|
2255
|
+
// Persist comment cursor from pre-compiled context bundle
|
|
2256
|
+
const bundleCursor = parseObject(context.fideliosHeartbeatContextCommentCursor);
|
|
2257
|
+
const lastSeenCommentId = readNonEmptyString(bundleCursor.latestCommentId) ?? undefined;
|
|
2229
2258
|
await upsertTaskSession({
|
|
2230
2259
|
companyId: agent.companyId,
|
|
2231
2260
|
agentId: agent.id,
|
|
@@ -2235,11 +2264,50 @@ export function heartbeatService(db) {
|
|
|
2235
2264
|
sessionDisplayId: nextSessionState.displayId,
|
|
2236
2265
|
lastRunId: finalizedRun.id,
|
|
2237
2266
|
lastError: outcome === "succeeded" ? null : (adapterResult.errorMessage ?? "run_failed"),
|
|
2267
|
+
lastSeenCommentId,
|
|
2238
2268
|
});
|
|
2239
2269
|
}
|
|
2240
2270
|
}
|
|
2241
2271
|
}
|
|
2242
2272
|
await finalizeAgentStatus(agent.id, outcome);
|
|
2273
|
+
// Auto-retry for transient errors (MCP timeout, rate limit, network errors)
|
|
2274
|
+
if (outcome === "failed" && finalizedRun && issueId) {
|
|
2275
|
+
const errorMsg = adapterResult.errorMessage ?? "";
|
|
2276
|
+
const errorCode = adapterResult.errorCode ?? "";
|
|
2277
|
+
const exitCode = adapterResult.exitCode ?? -1;
|
|
2278
|
+
const isTransient = errorMsg.includes("timed out") ||
|
|
2279
|
+
errorMsg.includes("Request timed out") ||
|
|
2280
|
+
errorMsg.includes("MCP error") ||
|
|
2281
|
+
errorMsg.includes("rate limit") ||
|
|
2282
|
+
errorMsg.includes("429") ||
|
|
2283
|
+
errorMsg.includes("503") ||
|
|
2284
|
+
errorMsg.includes("ECONNRESET") ||
|
|
2285
|
+
errorMsg.includes("ETIMEDOUT") ||
|
|
2286
|
+
errorCode === "claude_auth_required" ||
|
|
2287
|
+
exitCode === 143;
|
|
2288
|
+
if (isTransient) {
|
|
2289
|
+
const retryDelaySec = 30;
|
|
2290
|
+
logger.info({ runId: run.id, agentId: agent.id, error: errorMsg.slice(0, 100), retryDelaySec }, "transient error detected; scheduling auto-retry");
|
|
2291
|
+
setTimeout(() => {
|
|
2292
|
+
void enqueueWakeup(agent.id, {
|
|
2293
|
+
source: "automation",
|
|
2294
|
+
triggerDetail: "system",
|
|
2295
|
+
reason: "retry_transient_error",
|
|
2296
|
+
requestedByActorType: "system",
|
|
2297
|
+
requestedByActorId: "transient-retry",
|
|
2298
|
+
contextSnapshot: {
|
|
2299
|
+
issueId,
|
|
2300
|
+
taskId: issueId,
|
|
2301
|
+
taskKey: readNonEmptyString(context.taskKey) ?? issueId,
|
|
2302
|
+
wakeReason: "retry_transient_error",
|
|
2303
|
+
retriedFromRunId: run.id,
|
|
2304
|
+
},
|
|
2305
|
+
}).catch((retryErr) => {
|
|
2306
|
+
logger.warn({ err: retryErr, runId: run.id }, "failed to enqueue transient retry");
|
|
2307
|
+
});
|
|
2308
|
+
}, retryDelaySec * 1000);
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2243
2311
|
}
|
|
2244
2312
|
catch (err) {
|
|
2245
2313
|
const message = redactCurrentUserText(err instanceof Error ? err.message : "Unknown adapter failure", await getCurrentUserRedactionOptions());
|