@xopcai/xopc 0.0.173 → 0.0.174
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/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-ByVA0N5n.js → activity-store-CyEDJeIt.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-CJ5HvqE7.js → agent-avatar-dicebear-DF7Bol6I.js} +1 -1
- package/dist/gateway/static/root/assets/agents-BVxEFPQ5.js +2 -0
- package/dist/gateway/static/root/assets/{api-BZtCKzg4.js → api-DYunqroX.js} +1 -1
- package/dist/gateway/static/root/assets/api-DwyUxpgY.js +1 -0
- package/dist/gateway/static/root/assets/{app-management-settings-panel-B0oNNcFn.js → app-management-settings-panel-B4xJyvDu.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-DbIj4NQ1.js → appearance-settings-B2PQxRiu.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-BtIgd82S.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-BICLQFWJ.js → archive-plugin-DWhBmmjD.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-DV3PteSU.js → attachment-load-BOpZfa_I.js} +1 -1
- package/dist/gateway/static/root/assets/{automation-suggestion-card-CZUImis0.js → automation-suggestion-card-Byu3I7Rs.js} +1 -1
- package/dist/gateway/static/root/assets/automations-page-CG_SCH5b.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-D6zkab6N.js → binary-plugins-6AG1qatz.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-zCzoQI-g.js → block-editor-CJhrn98_.js} +5 -5
- package/dist/gateway/static/root/assets/browser-settings-page-CfLqPWZC.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-CY3X83xQ.js → browser-workflow-inputs-CBVb4mt9.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-DDRtZLuM.js → browser-workflows-page-Cq4XUKbu.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-DCJmm6cR.js +7 -0
- package/dist/gateway/static/root/assets/{capability-presets-api-pYLW6P7g.js → capability-presets-api-hbW4NAKO.js} +1 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-CnkAYvWI.js +1 -0
- package/dist/gateway/static/root/assets/{channel-recipient-api-DxyOH3BO.js → channel-recipient-api-CzMjHb17.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-DtqqFpDn.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-C-5yHbc0.js +1 -0
- package/dist/gateway/static/root/assets/{connector-logo-BgANwjt-.js → connector-logo-B9Au6gMZ.js} +1 -1
- package/dist/gateway/static/root/assets/connectors-page-CaHfs8YF.js +2 -0
- package/dist/gateway/static/root/assets/copy-VueTIC2x.js +1 -0
- package/dist/gateway/static/root/assets/desktop-pet-CvFMKYdb.js +1 -0
- package/dist/gateway/static/root/assets/{desktop-pet-settings-8CaU1Mhm.js → desktop-pet-settings-CNff5TFb.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-BtNRUvzM.js → directory-picker-path-field-Bf956uo-.js} +1 -1
- package/dist/gateway/static/root/assets/dreaming-settings-CHM8FE1g.js +3 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-DFjTfx6f.js → extension-debug-page-ZqM_0eUs.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-NyEYtWWg.js → extension-page-D4hvXOMM.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BynTCfgf.js → extension-settings-page-GsqxaJjA.js} +1 -1
- package/dist/gateway/static/root/assets/focus-detail-page-CE6uwrl1.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-api-BzOWImvU.js → gateway-config-api-B4THmgnS.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-DXepE_Jw.js → gateway-settings-CPv-MxGE.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-C2JXXtwg.js → gateway-startup-retry-MP3K71pP.js} +1 -1
- package/dist/gateway/static/root/assets/goal-create-dialog-DAeb82xP.js +1 -0
- package/dist/gateway/static/root/assets/goal-detail-page-CwLSp01r.js +4 -0
- package/dist/gateway/static/root/assets/{goals-config-api-CU3JR9MI.js → goals-config-api-DCcDuIjG.js} +1 -1
- package/dist/gateway/static/root/assets/goals-page-DvJQ6_4M.js +2 -0
- package/dist/gateway/static/root/assets/{goals-settings-DSZguLEx.js → goals-settings-o9QMXvNq.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-KRkYziEF.js → heartbeat-settings-DixwpXnH.js} +1 -1
- package/dist/gateway/static/root/assets/{image-generation-api-Y-n6TaZ_.js → image-generation-api-BOGH9FGi.js} +1 -1
- package/dist/gateway/static/root/assets/index-CfXiRNN5.css +1 -0
- package/dist/gateway/static/root/assets/index-eyttVNS_.js +212 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-CwrQv952.js → keyboard-shortcuts-settings-D4o4ZPF6.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-CPcfqn_A.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-DtITcS4K.js → local-apps-page-GzMmpO7G.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-Ccv7tH8B.js → locale-store-CAuhEGCn.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-DXABWCZp.js +7 -0
- package/dist/gateway/static/root/assets/{markdown-split-D1oZlq1m.js → markdown-split-CIX8D1pv.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-BKz5V32t.js → media-plugins-Bp3eIA45.js} +1 -1
- package/dist/gateway/static/root/assets/messages-BiBdO1-O.js +3 -0
- package/dist/gateway/static/root/assets/{notes-page-DLekBQPa.js → notes-page-RVFiYAoO.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-DgJzZRX3.js +4 -0
- package/dist/gateway/static/root/assets/{page-tabs-pT4nLfqS.js → page-tabs-BGAYH3Ef.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-OtAiaJm2.js → preview-open-alternatives-BM6pDkHp.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-CfryBKD9.js → product-open-page-BiMetEmn.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-DF7F70Vg.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-Cw3jyi5s.js +1 -0
- package/dist/gateway/static/root/assets/remote-access-hub-ChAJsaNY.js +1 -0
- package/dist/gateway/static/root/assets/{save-bar-controls-nP1SB3Lf.js → save-bar-controls-BdjV8MK5.js} +1 -1
- package/dist/gateway/static/root/assets/{schedule-field-OEQTsUNz.js → schedule-field-ChlqXU46.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-DIcAa7CJ.js → schema-form-DDKf5ZSH.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-BxZIxt7z.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-DcDLS0xV.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-BxNcTbYO.js → settings-form-section-CPG0KGVs.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-Dpdxu4sf.js → settings-loading-skeleton-DRSDHucM.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-DwPeOm1c.js → settings-page-CeB7_xD0.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-layout-CqirFmMn.js → settings-page-layout-BENrkwd0.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-4Xa9NA7v.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-D72gYeux.js → share-preview-page-DIzczJkG.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-BpN0o5Cf.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-DvF2UAaL.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-CGKXpNfy.js +2 -0
- package/dist/gateway/static/root/assets/{system-settings-panel-U0tBgW46.js → system-settings-panel-Dp4d5Q1B.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-DCKDVPFF.js → theme-store-CbGc1laW.js} +1 -1
- package/dist/gateway/static/root/assets/{time-picker-BpiBF5-d.js → time-picker-BhgCeDuO.js} +1 -1
- package/dist/gateway/static/root/assets/{typed-models-lib-D0XCOCAM.js → typed-models-lib-DwPk3OPL.js} +1 -1
- package/dist/gateway/static/root/assets/{use-channel-catalog-mq_Inao2.js → use-channel-catalog-CXrEu2dw.js} +1 -1
- package/dist/gateway/static/root/assets/user-context-page-Dy_fKAK_.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-CKaDitO6.js → voice-api-key-field-DFoA79LB.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-page-BWkjb1NK.js +1 -0
- package/dist/gateway/static/root/assets/work-item-detail-page-DLBNFse5.js +1 -0
- package/dist/gateway/static/root/assets/work-page-Bn5RXMIE.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-s_kS_FYA.js → workflow-run-setup-panel-BuniGPO0.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-_vFhRrAl.js +11 -0
- package/dist/gateway/static/root/index.html +7 -7
- package/dist/package.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/focuses/candidate-repository.d.ts +15 -0
- package/dist/src/focuses/candidate-repository.js +91 -0
- package/dist/src/focuses/index.d.ts +7 -0
- package/dist/src/focuses/index.js +7 -0
- package/dist/src/focuses/insight-repository.d.ts +22 -0
- package/dist/src/focuses/insight-repository.js +77 -0
- package/dist/src/focuses/prompts.d.ts +2 -0
- package/dist/src/focuses/prompts.js +18 -0
- package/dist/src/focuses/reconciler.d.ts +5 -0
- package/dist/src/focuses/reconciler.js +26 -0
- package/dist/src/focuses/repository.d.ts +61 -0
- package/dist/src/focuses/repository.js +214 -0
- package/dist/src/focuses/run-processor.d.ts +18 -0
- package/dist/src/focuses/run-processor.js +162 -0
- package/dist/src/focuses/service.d.ts +42 -0
- package/dist/src/focuses/service.js +241 -0
- package/dist/src/focuses/types.d.ts +89 -0
- package/dist/src/gateway/heartbeat/service.js +1 -1
- package/dist/src/gateway/hono/routes/focuses.d.ts +3 -0
- package/dist/src/gateway/hono/routes/focuses.js +319 -0
- package/dist/src/gateway/hono/routes/home.js +15 -17
- package/dist/src/gateway/hono/routes/index.js +2 -0
- package/dist/src/gateway/hono/routes/local-apps.js +1 -1
- package/dist/src/gateway/hono/routes/projects.js +2 -103
- package/dist/src/gateway/hono/routes/work-discovery.js +0 -239
- package/dist/src/gateway/service.d.ts +1 -1
- package/dist/src/gateway/service.js +17 -13
- package/dist/src/heartbeat/index.js +1 -1
- package/dist/src/mcp/channel-bridge.js +1 -1
- package/dist/src/storage/sqlite/migrations/066_first_class_focuses.sql +126 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/work-discovery/index.d.ts +0 -2
- package/dist/src/work-discovery/index.js +1 -3
- package/dist/src/work-discovery/service.d.ts +0 -30
- package/dist/src/work-discovery/service.js +1 -35
- package/dist/src/work-discovery/thread-service.d.ts +5 -0
- package/dist/src/work-discovery/thread-service.js +36 -88
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/agents--TQ9jM_1.js +0 -2
- package/dist/gateway/static/root/assets/apps-page-BDsoZDEn.js +0 -1
- package/dist/gateway/static/root/assets/automations-page-CHrNcppN.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-BQoRuQzH.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-BOcU0qeM.js +0 -7
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-CJ1F_hlX.js +0 -1
- package/dist/gateway/static/root/assets/channels-settings-C4vDwRil.js +0 -1
- package/dist/gateway/static/root/assets/channels-status-swr-B0Pgq5x2.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-D6JEqDEj.js +0 -2
- package/dist/gateway/static/root/assets/desktop-pet-BPjQbPeA.js +0 -1
- package/dist/gateway/static/root/assets/dreaming-settings-Byv-h8XZ.js +0 -3
- package/dist/gateway/static/root/assets/goal-create-dialog-ClOZyG52.js +0 -1
- package/dist/gateway/static/root/assets/goal-detail-page-UbZB77De.js +0 -4
- package/dist/gateway/static/root/assets/goals-page-GMqV8Fwv.js +0 -2
- package/dist/gateway/static/root/assets/index-BCkNJ5cR.css +0 -1
- package/dist/gateway/static/root/assets/index-CAZ9343h.js +0 -212
- package/dist/gateway/static/root/assets/local-app-workbench-page-m5HEyrHT.js +0 -2
- package/dist/gateway/static/root/assets/logs-page-Bf_nk75f.js +0 -7
- package/dist/gateway/static/root/assets/messages-DWrg3c4K.js +0 -3
- package/dist/gateway/static/root/assets/notes-workbench-BTDmprHM.js +0 -4
- package/dist/gateway/static/root/assets/project-detail-page-C7kntu4H.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-3ubcbqHr.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-DoUkN3ik.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-ElAAlZ-R.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-CQn_KBqr.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-DX_LdcTN.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-nSfe-5xK.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-1tYpZrJf.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-BUJl8LJG.js +0 -2
- package/dist/gateway/static/root/assets/user-context-page-BOC6Hn19.js +0 -1
- package/dist/gateway/static/root/assets/work-discovery-page-DWGYp5yV.js +0 -1
- package/dist/gateway/static/root/assets/work-item-detail-page-CpeWcpSp.js +0 -1
- package/dist/gateway/static/root/assets/work-page-MsEKzmSt.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-ByhHaUHB.js +0 -11
- package/dist/src/proactive/calendar-signals.d.ts +0 -4
- package/dist/src/proactive/calendar-signals.js +0 -120
- package/dist/src/proactive/focus-service.d.ts +0 -62
- package/dist/src/proactive/focus-service.js +0 -173
- package/dist/src/proactive/index.d.ts +0 -7
- package/dist/src/proactive/index.js +0 -7
- package/dist/src/proactive/insight-repository.d.ts +0 -21
- package/dist/src/proactive/insight-repository.js +0 -109
- package/dist/src/proactive/run-processor.d.ts +0 -19
- package/dist/src/proactive/run-processor.js +0 -146
- package/dist/src/proactive/trial-expiry-reconciler.d.ts +0 -5
- package/dist/src/proactive/trial-expiry-reconciler.js +0 -30
- package/dist/src/proactive/types.d.ts +0 -66
- package/dist/src/proactive/value-score.d.ts +0 -13
- package/dist/src/proactive/value-score.js +0 -30
- package/dist/src/proactive/watch-repository.d.ts +0 -28
- package/dist/src/proactive/watch-repository.js +0 -129
- package/dist/src/work-discovery/governance.d.ts +0 -25
- package/dist/src/work-discovery/governance.js +0 -96
- package/dist/src/work-discovery/thread-repository.d.ts +0 -34
- package/dist/src/work-discovery/thread-repository.js +0 -112
- /package/dist/src/{proactive → focuses}/types.js +0 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createLogger } from "../utils/logger/index.js";
|
|
2
|
+
import { init_logger } from "../utils/logger.js";
|
|
3
|
+
import { createFocusActivity, getFocusMonitorByAutomationId, updateFocusMonitorRuntime } from "./repository.js";
|
|
4
|
+
import { createFocusInsight } from "./insight-repository.js";
|
|
5
|
+
//#region src/focuses/run-processor.ts
|
|
6
|
+
init_logger();
|
|
7
|
+
const log = createLogger("FocusRunProcessor");
|
|
8
|
+
function nonEmptyString(value) {
|
|
9
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
10
|
+
}
|
|
11
|
+
function parseFocusMonitorResult(summary) {
|
|
12
|
+
const start = summary.indexOf("{");
|
|
13
|
+
const end = summary.lastIndexOf("}");
|
|
14
|
+
if (start < 0 || end <= start) return null;
|
|
15
|
+
let value;
|
|
16
|
+
try {
|
|
17
|
+
value = JSON.parse(summary.slice(start, end + 1));
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
22
|
+
const result = value;
|
|
23
|
+
if (result.meaningful === false) return { meaningful: false };
|
|
24
|
+
if (result.meaningful !== true) return null;
|
|
25
|
+
const title = nonEmptyString(result.title);
|
|
26
|
+
const resultSummary = nonEmptyString(result.summary);
|
|
27
|
+
const whyItMatters = nonEmptyString(result.whyItMatters);
|
|
28
|
+
const nextAction = nonEmptyString(result.nextAction);
|
|
29
|
+
const evidence = Array.isArray(result.evidence) ? result.evidence.flatMap((item) => {
|
|
30
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) return [];
|
|
31
|
+
const record = item;
|
|
32
|
+
const label = nonEmptyString(record.label);
|
|
33
|
+
const source = nonEmptyString(record.source);
|
|
34
|
+
const publishedAtValue = nonEmptyString(record.publishedAt);
|
|
35
|
+
const publishedAt = publishedAtValue && Number.isFinite(Date.parse(publishedAtValue)) ? new Date(publishedAtValue).toISOString() : null;
|
|
36
|
+
return label ? [{
|
|
37
|
+
label,
|
|
38
|
+
...source ? { source } : {},
|
|
39
|
+
...publishedAt ? { publishedAt } : {}
|
|
40
|
+
}] : [];
|
|
41
|
+
}).slice(0, 8) : [];
|
|
42
|
+
if (!title || !resultSummary || !whyItMatters || !nextAction || evidence.length === 0) return null;
|
|
43
|
+
return {
|
|
44
|
+
meaningful: true,
|
|
45
|
+
title,
|
|
46
|
+
summary: resultSummary,
|
|
47
|
+
whyItMatters,
|
|
48
|
+
nextAction,
|
|
49
|
+
evidence
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function hasDatedExternalEvidence(evidence) {
|
|
53
|
+
return evidence.some((item) => {
|
|
54
|
+
if (!item.source || !item.publishedAt) return false;
|
|
55
|
+
try {
|
|
56
|
+
const url = new URL(item.source);
|
|
57
|
+
return (url.protocol === "https:" || url.protocol === "http:") && Number.isFinite(Date.parse(item.publishedAt));
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function processFocusMonitorRun(run) {
|
|
64
|
+
const monitor = getFocusMonitorByAutomationId(run.automationId);
|
|
65
|
+
if (!monitor) return { handled: false };
|
|
66
|
+
if (monitor.lastRunId === run.id && monitor.lastRunAt != null) return { handled: true };
|
|
67
|
+
const endedAt = run.endedAtMs ?? Date.now();
|
|
68
|
+
if (run.status !== "succeeded" || !run.summary) {
|
|
69
|
+
const errorMessage = run.error || `Monitor run ${run.status}`;
|
|
70
|
+
updateFocusMonitorRuntime({
|
|
71
|
+
id: monitor.id,
|
|
72
|
+
runState: "failed",
|
|
73
|
+
lastRunId: run.id,
|
|
74
|
+
lastRunAt: endedAt,
|
|
75
|
+
error: errorMessage
|
|
76
|
+
});
|
|
77
|
+
createFocusActivity({
|
|
78
|
+
focusId: monitor.focusId,
|
|
79
|
+
monitorId: monitor.id,
|
|
80
|
+
type: "run_failed",
|
|
81
|
+
summary: errorMessage,
|
|
82
|
+
details: { runId: run.id },
|
|
83
|
+
nowMs: endedAt
|
|
84
|
+
});
|
|
85
|
+
return { handled: true };
|
|
86
|
+
}
|
|
87
|
+
const result = parseFocusMonitorResult(run.summary);
|
|
88
|
+
if (!result || result.meaningful && monitor.kind === "external_changes" && !hasDatedExternalEvidence(result.evidence)) {
|
|
89
|
+
updateFocusMonitorRuntime({
|
|
90
|
+
id: monitor.id,
|
|
91
|
+
runState: "failed",
|
|
92
|
+
lastRunId: run.id,
|
|
93
|
+
lastRunAt: endedAt,
|
|
94
|
+
error: "Monitor returned an invalid result"
|
|
95
|
+
});
|
|
96
|
+
createFocusActivity({
|
|
97
|
+
focusId: monitor.focusId,
|
|
98
|
+
monitorId: monitor.id,
|
|
99
|
+
type: "run_failed",
|
|
100
|
+
summary: "Monitor returned an invalid result",
|
|
101
|
+
details: { runId: run.id },
|
|
102
|
+
nowMs: endedAt
|
|
103
|
+
});
|
|
104
|
+
log.warn({
|
|
105
|
+
automationId: run.automationId,
|
|
106
|
+
runId: run.id,
|
|
107
|
+
monitorKind: monitor.kind
|
|
108
|
+
}, "Focus monitor returned an invalid result");
|
|
109
|
+
return { handled: true };
|
|
110
|
+
}
|
|
111
|
+
updateFocusMonitorRuntime({
|
|
112
|
+
id: monitor.id,
|
|
113
|
+
runState: "idle",
|
|
114
|
+
lastRunId: run.id,
|
|
115
|
+
lastRunAt: endedAt,
|
|
116
|
+
meaningful: result.meaningful,
|
|
117
|
+
error: null
|
|
118
|
+
});
|
|
119
|
+
if (!result.meaningful) {
|
|
120
|
+
createFocusActivity({
|
|
121
|
+
focusId: monitor.focusId,
|
|
122
|
+
monitorId: monitor.id,
|
|
123
|
+
type: "run_no_change",
|
|
124
|
+
summary: "No meaningful change found",
|
|
125
|
+
details: { runId: run.id },
|
|
126
|
+
nowMs: endedAt
|
|
127
|
+
});
|
|
128
|
+
return { handled: true };
|
|
129
|
+
}
|
|
130
|
+
const insight = createFocusInsight({
|
|
131
|
+
focusId: monitor.focusId,
|
|
132
|
+
monitorId: monitor.id,
|
|
133
|
+
runId: run.id,
|
|
134
|
+
kind: monitor.kind,
|
|
135
|
+
title: result.title,
|
|
136
|
+
summary: result.summary,
|
|
137
|
+
whyItMatters: result.whyItMatters,
|
|
138
|
+
nextAction: result.nextAction,
|
|
139
|
+
evidence: result.evidence,
|
|
140
|
+
nowMs: endedAt
|
|
141
|
+
});
|
|
142
|
+
if (insight) {
|
|
143
|
+
createFocusActivity({
|
|
144
|
+
focusId: monitor.focusId,
|
|
145
|
+
monitorId: monitor.id,
|
|
146
|
+
type: "insight_created",
|
|
147
|
+
summary: insight.title,
|
|
148
|
+
details: {
|
|
149
|
+
runId: run.id,
|
|
150
|
+
insightId: insight.id
|
|
151
|
+
},
|
|
152
|
+
nowMs: endedAt
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
handled: true,
|
|
156
|
+
insight
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return { handled: true };
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
export { parseFocusMonitorResult, processFocusMonitorRun };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Automation, AutomationRun } from '../automations/index.js';
|
|
2
|
+
import type { FocusCadence, FocusDetail, FocusMonitor, FocusMonitorKind, FocusStatus } from './types.js';
|
|
3
|
+
export interface FocusAutomationPort {
|
|
4
|
+
create(input: Parameters<import('../automations/index.js').AutomationService['create']>[0]): Promise<Automation>;
|
|
5
|
+
get(id: string): Promise<Automation | null>;
|
|
6
|
+
update(id: string, input: Parameters<import('../automations/index.js').AutomationService['update']>[1]): Promise<Automation>;
|
|
7
|
+
pause(id: string): Promise<Automation>;
|
|
8
|
+
resume(id: string): Promise<Automation>;
|
|
9
|
+
remove(id: string): Promise<boolean>;
|
|
10
|
+
runNow(id: string): Promise<AutomationRun>;
|
|
11
|
+
}
|
|
12
|
+
export declare class FocusService {
|
|
13
|
+
private readonly automations;
|
|
14
|
+
constructor(automations: FocusAutomationPort);
|
|
15
|
+
list(statuses?: FocusStatus[]): FocusDetail[];
|
|
16
|
+
get(id: string): FocusDetail | null;
|
|
17
|
+
create(input: {
|
|
18
|
+
title: string;
|
|
19
|
+
summary: string;
|
|
20
|
+
projectIds?: string[];
|
|
21
|
+
goalId?: string;
|
|
22
|
+
}): FocusDetail;
|
|
23
|
+
update(id: string, input: {
|
|
24
|
+
title?: string;
|
|
25
|
+
summary?: string;
|
|
26
|
+
projectIds?: string[];
|
|
27
|
+
}): FocusDetail | null;
|
|
28
|
+
setStatus(id: string, status: FocusStatus): Promise<FocusDetail | null>;
|
|
29
|
+
remove(id: string): Promise<boolean>;
|
|
30
|
+
configureMonitor(input: {
|
|
31
|
+
focusId: string;
|
|
32
|
+
kind: FocusMonitorKind;
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
cadence?: FocusCadence;
|
|
35
|
+
}): Promise<{
|
|
36
|
+
monitor: FocusMonitor;
|
|
37
|
+
initialRunId?: string;
|
|
38
|
+
}>;
|
|
39
|
+
runMonitorNow(focusId: string, kind: FocusMonitorKind): Promise<AutomationRun>;
|
|
40
|
+
reconcile(): Promise<void>;
|
|
41
|
+
private detail;
|
|
42
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { createLogger } from "../utils/logger/index.js";
|
|
2
|
+
import { init_logger } from "../utils/logger.js";
|
|
3
|
+
import { createFocus, createFocusActivity, deleteFocus, getFocus, getFocusMonitor, listAllFocusMonitors, listFocusMonitors, listFocuses, updateFocus, updateFocusMonitorRuntime, upsertFocusMonitor } from "./repository.js";
|
|
4
|
+
import { buildFocusMonitorInstruction } from "./prompts.js";
|
|
5
|
+
//#region src/focuses/service.ts
|
|
6
|
+
init_logger();
|
|
7
|
+
const log = createLogger("FocusService");
|
|
8
|
+
const DEFAULT_CADENCE = {
|
|
9
|
+
kind: "interval",
|
|
10
|
+
everyMs: 864e5
|
|
11
|
+
};
|
|
12
|
+
var FocusService = class {
|
|
13
|
+
constructor(automations) {
|
|
14
|
+
this.automations = automations;
|
|
15
|
+
}
|
|
16
|
+
list(statuses) {
|
|
17
|
+
return listFocuses({ statuses }).map((focus) => this.detail(focus));
|
|
18
|
+
}
|
|
19
|
+
get(id) {
|
|
20
|
+
const focus = getFocus(id);
|
|
21
|
+
return focus ? this.detail(focus) : null;
|
|
22
|
+
}
|
|
23
|
+
create(input) {
|
|
24
|
+
if (!input.title.trim()) throw new Error("Focus title is required");
|
|
25
|
+
const focus = createFocus(input);
|
|
26
|
+
return this.detail(focus);
|
|
27
|
+
}
|
|
28
|
+
update(id, input) {
|
|
29
|
+
if (input.title !== void 0 && !input.title.trim()) throw new Error("Focus title is required");
|
|
30
|
+
if (!updateFocus({
|
|
31
|
+
id,
|
|
32
|
+
...input
|
|
33
|
+
})) return null;
|
|
34
|
+
createFocusActivity({
|
|
35
|
+
focusId: id,
|
|
36
|
+
type: "updated",
|
|
37
|
+
summary: "Focus updated"
|
|
38
|
+
});
|
|
39
|
+
return this.get(id);
|
|
40
|
+
}
|
|
41
|
+
async setStatus(id, status) {
|
|
42
|
+
const focus = getFocus(id);
|
|
43
|
+
if (!focus) return null;
|
|
44
|
+
if (focus.status === status) return this.detail(focus);
|
|
45
|
+
const monitors = listFocusMonitors(id);
|
|
46
|
+
if (status === "active") for (const monitor of monitors.filter((item) => item.enabled && item.automationId)) await this.automations.resume(monitor.automationId);
|
|
47
|
+
else if (status === "paused") for (const monitor of monitors.filter((item) => item.enabled && item.automationId)) await this.automations.pause(monitor.automationId);
|
|
48
|
+
else for (const monitor of monitors.filter((item) => item.automationId)) {
|
|
49
|
+
await this.automations.remove(monitor.automationId);
|
|
50
|
+
upsertFocusMonitor({
|
|
51
|
+
focusId: id,
|
|
52
|
+
kind: monitor.kind,
|
|
53
|
+
enabled: false,
|
|
54
|
+
cadence: monitor.cadence,
|
|
55
|
+
automationId: null
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (!updateFocus({
|
|
59
|
+
id,
|
|
60
|
+
status
|
|
61
|
+
})) return null;
|
|
62
|
+
const type = status === "active" ? "resumed" : status === "paused" ? "paused" : "completed";
|
|
63
|
+
createFocusActivity({
|
|
64
|
+
focusId: id,
|
|
65
|
+
type,
|
|
66
|
+
summary: `Focus ${type}`
|
|
67
|
+
});
|
|
68
|
+
return this.get(id);
|
|
69
|
+
}
|
|
70
|
+
async remove(id) {
|
|
71
|
+
if (!getFocus(id)) return false;
|
|
72
|
+
for (const monitor of listFocusMonitors(id).filter((item) => item.automationId)) await this.automations.remove(monitor.automationId);
|
|
73
|
+
return deleteFocus(id);
|
|
74
|
+
}
|
|
75
|
+
async configureMonitor(input) {
|
|
76
|
+
const focus = getFocus(input.focusId);
|
|
77
|
+
if (!focus) throw new Error("Focus not found");
|
|
78
|
+
if (focus.status !== "active") throw new Error("Only active focuses can enable monitoring");
|
|
79
|
+
const existing = getFocusMonitor(input.focusId, input.kind);
|
|
80
|
+
const cadence = input.cadence ?? existing?.cadence ?? DEFAULT_CADENCE;
|
|
81
|
+
if (cadence.kind !== "interval" || cadence.everyMs < 6e4) throw new Error("Invalid monitor cadence");
|
|
82
|
+
if (input.enabled && existing?.enabled && existing.cadence.everyMs === cadence.everyMs) return { monitor: existing };
|
|
83
|
+
if (!input.enabled) {
|
|
84
|
+
if (existing?.automationId) await this.automations.pause(existing.automationId);
|
|
85
|
+
const monitor = upsertFocusMonitor({
|
|
86
|
+
focusId: input.focusId,
|
|
87
|
+
kind: input.kind,
|
|
88
|
+
enabled: false,
|
|
89
|
+
cadence,
|
|
90
|
+
automationId: existing?.automationId
|
|
91
|
+
});
|
|
92
|
+
createFocusActivity({
|
|
93
|
+
focusId: input.focusId,
|
|
94
|
+
monitorId: monitor.id,
|
|
95
|
+
type: "monitor_disabled",
|
|
96
|
+
summary: `${input.kind} monitoring disabled`
|
|
97
|
+
});
|
|
98
|
+
return { monitor };
|
|
99
|
+
}
|
|
100
|
+
let monitor = upsertFocusMonitor({
|
|
101
|
+
focusId: input.focusId,
|
|
102
|
+
kind: input.kind,
|
|
103
|
+
enabled: true,
|
|
104
|
+
runState: "queued",
|
|
105
|
+
cadence,
|
|
106
|
+
automationId: existing?.automationId
|
|
107
|
+
});
|
|
108
|
+
try {
|
|
109
|
+
let automation;
|
|
110
|
+
if (existing?.automationId) if (existing.cadence.everyMs !== cadence.everyMs) automation = await this.automations.update(existing.automationId, { trigger: {
|
|
111
|
+
kind: "schedule",
|
|
112
|
+
schedule: {
|
|
113
|
+
kind: "interval",
|
|
114
|
+
everyMs: cadence.everyMs
|
|
115
|
+
}
|
|
116
|
+
} });
|
|
117
|
+
else automation = await this.automations.resume(existing.automationId);
|
|
118
|
+
else automation = await this.automations.create({
|
|
119
|
+
name: `Monitor: ${focus.title}`.slice(0, 200),
|
|
120
|
+
description: `${input.kind} monitor for a user-confirmed focus.`,
|
|
121
|
+
...focus.projectIds[0] ? { projectId: focus.projectIds[0] } : {},
|
|
122
|
+
trigger: {
|
|
123
|
+
kind: "schedule",
|
|
124
|
+
schedule: {
|
|
125
|
+
kind: "interval",
|
|
126
|
+
everyMs: cadence.everyMs
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
action: {
|
|
130
|
+
kind: "agent",
|
|
131
|
+
instruction: buildFocusMonitorInstruction(focus, input.kind),
|
|
132
|
+
timeoutSeconds: 300
|
|
133
|
+
},
|
|
134
|
+
safety: { mode: "suggest_only" },
|
|
135
|
+
afterRun: { kind: "none" },
|
|
136
|
+
reliability: {
|
|
137
|
+
timeoutSeconds: 300,
|
|
138
|
+
disableAfterConsecutiveFailures: 3
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
monitor = upsertFocusMonitor({
|
|
142
|
+
focusId: input.focusId,
|
|
143
|
+
kind: input.kind,
|
|
144
|
+
enabled: true,
|
|
145
|
+
runState: "queued",
|
|
146
|
+
cadence,
|
|
147
|
+
automationId: automation.id
|
|
148
|
+
});
|
|
149
|
+
createFocusActivity({
|
|
150
|
+
focusId: input.focusId,
|
|
151
|
+
monitorId: monitor.id,
|
|
152
|
+
type: "monitor_enabled",
|
|
153
|
+
summary: `${input.kind} monitoring enabled`
|
|
154
|
+
});
|
|
155
|
+
const run = await this.automations.runNow(automation.id);
|
|
156
|
+
monitor = updateFocusMonitorRuntime({
|
|
157
|
+
id: monitor.id,
|
|
158
|
+
runState: "running",
|
|
159
|
+
lastRunId: run.id,
|
|
160
|
+
nextRunAt: automation.state.nextRunAtMs ?? null
|
|
161
|
+
}) ?? monitor;
|
|
162
|
+
createFocusActivity({
|
|
163
|
+
focusId: input.focusId,
|
|
164
|
+
monitorId: monitor.id,
|
|
165
|
+
type: "run_started",
|
|
166
|
+
summary: "Initial monitor check started",
|
|
167
|
+
details: { runId: run.id }
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
monitor,
|
|
171
|
+
initialRunId: run.id
|
|
172
|
+
};
|
|
173
|
+
} catch (err) {
|
|
174
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
175
|
+
updateFocusMonitorRuntime({
|
|
176
|
+
id: monitor.id,
|
|
177
|
+
runState: "failed",
|
|
178
|
+
error: errorMessage
|
|
179
|
+
});
|
|
180
|
+
log.error({
|
|
181
|
+
err,
|
|
182
|
+
focusId: input.focusId,
|
|
183
|
+
monitorKind: input.kind
|
|
184
|
+
}, `Focus monitor enable failed: ${errorMessage}`);
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async runMonitorNow(focusId, kind) {
|
|
189
|
+
const monitor = getFocusMonitor(focusId, kind);
|
|
190
|
+
if (!monitor?.enabled || !monitor.automationId) throw new Error("Monitor is not enabled");
|
|
191
|
+
updateFocusMonitorRuntime({
|
|
192
|
+
id: monitor.id,
|
|
193
|
+
runState: "queued",
|
|
194
|
+
error: null
|
|
195
|
+
});
|
|
196
|
+
const run = await this.automations.runNow(monitor.automationId);
|
|
197
|
+
updateFocusMonitorRuntime({
|
|
198
|
+
id: monitor.id,
|
|
199
|
+
runState: "running",
|
|
200
|
+
lastRunId: run.id
|
|
201
|
+
});
|
|
202
|
+
createFocusActivity({
|
|
203
|
+
focusId,
|
|
204
|
+
monitorId: monitor.id,
|
|
205
|
+
type: "run_started",
|
|
206
|
+
summary: "Monitor check started",
|
|
207
|
+
details: { runId: run.id }
|
|
208
|
+
});
|
|
209
|
+
return run;
|
|
210
|
+
}
|
|
211
|
+
async reconcile() {
|
|
212
|
+
for (const monitor of listAllFocusMonitors()) {
|
|
213
|
+
const focus = getFocus(monitor.focusId);
|
|
214
|
+
if (!focus) continue;
|
|
215
|
+
const automation = monitor.automationId ? await this.automations.get(monitor.automationId) : null;
|
|
216
|
+
if (monitor.enabled && focus.status === "active" && !automation) try {
|
|
217
|
+
await this.configureMonitor({
|
|
218
|
+
focusId: focus.id,
|
|
219
|
+
kind: monitor.kind,
|
|
220
|
+
enabled: true,
|
|
221
|
+
cadence: monitor.cadence
|
|
222
|
+
});
|
|
223
|
+
} catch (err) {
|
|
224
|
+
log.warn({
|
|
225
|
+
err,
|
|
226
|
+
focusId: focus.id,
|
|
227
|
+
monitorId: monitor.id
|
|
228
|
+
}, "Focus monitor reconciliation failed");
|
|
229
|
+
}
|
|
230
|
+
else if ((!monitor.enabled || focus.status !== "active") && automation?.enabled) await this.automations.pause(automation.id);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
detail(focus) {
|
|
234
|
+
return {
|
|
235
|
+
...focus,
|
|
236
|
+
monitors: listFocusMonitors(focus.id)
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
//#endregion
|
|
241
|
+
export { FocusService };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export type FocusStatus = 'active' | 'paused' | 'completed';
|
|
2
|
+
export type FocusSource = 'user' | 'discovery';
|
|
3
|
+
export type FocusCandidateStatus = 'pending' | 'accepted' | 'dismissed';
|
|
4
|
+
export type FocusMonitorKind = 'progress' | 'external_changes';
|
|
5
|
+
export type FocusMonitorRunState = 'idle' | 'queued' | 'running' | 'failed';
|
|
6
|
+
export type FocusInsightStatus = 'unread' | 'dismissed' | 'approved';
|
|
7
|
+
export type FocusActivityType = 'created' | 'updated' | 'paused' | 'resumed' | 'completed' | 'monitor_enabled' | 'monitor_disabled' | 'run_started' | 'run_no_change' | 'run_failed' | 'insight_created' | 'insight_dismissed' | 'insight_approved';
|
|
8
|
+
export interface FocusEvidence {
|
|
9
|
+
label: string;
|
|
10
|
+
source?: string;
|
|
11
|
+
publishedAt?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface FocusCandidate {
|
|
14
|
+
id: string;
|
|
15
|
+
canonicalKey: string;
|
|
16
|
+
title: string;
|
|
17
|
+
summary: string;
|
|
18
|
+
confidence: number;
|
|
19
|
+
evidence: FocusEvidence[];
|
|
20
|
+
projectIds: string[];
|
|
21
|
+
status: FocusCandidateStatus;
|
|
22
|
+
discoveredAt: number;
|
|
23
|
+
updatedAt: number;
|
|
24
|
+
}
|
|
25
|
+
export interface Focus {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
summary: string;
|
|
29
|
+
status: FocusStatus;
|
|
30
|
+
source: FocusSource;
|
|
31
|
+
sourceCandidateId?: string;
|
|
32
|
+
projectIds: string[];
|
|
33
|
+
goalId?: string;
|
|
34
|
+
createdAt: number;
|
|
35
|
+
updatedAt: number;
|
|
36
|
+
completedAt?: number;
|
|
37
|
+
lastActivityAt?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface FocusCadence {
|
|
40
|
+
kind: 'interval';
|
|
41
|
+
everyMs: number;
|
|
42
|
+
}
|
|
43
|
+
export interface FocusMonitor {
|
|
44
|
+
id: string;
|
|
45
|
+
focusId: string;
|
|
46
|
+
kind: FocusMonitorKind;
|
|
47
|
+
enabled: boolean;
|
|
48
|
+
runState: FocusMonitorRunState;
|
|
49
|
+
cadence: FocusCadence;
|
|
50
|
+
automationId?: string;
|
|
51
|
+
lastRunId?: string;
|
|
52
|
+
lastRunAt?: number;
|
|
53
|
+
nextRunAt?: number;
|
|
54
|
+
lastMeaningfulResultAt?: number;
|
|
55
|
+
lastError?: string;
|
|
56
|
+
consecutiveFailures: number;
|
|
57
|
+
createdAt: number;
|
|
58
|
+
updatedAt: number;
|
|
59
|
+
}
|
|
60
|
+
export interface FocusActivity {
|
|
61
|
+
id: string;
|
|
62
|
+
focusId: string;
|
|
63
|
+
monitorId?: string;
|
|
64
|
+
type: FocusActivityType;
|
|
65
|
+
summary: string;
|
|
66
|
+
details: Record<string, unknown>;
|
|
67
|
+
createdAt: number;
|
|
68
|
+
}
|
|
69
|
+
export interface FocusInsight {
|
|
70
|
+
id: string;
|
|
71
|
+
focusId: string;
|
|
72
|
+
monitorId: string;
|
|
73
|
+
runId: string;
|
|
74
|
+
kind: FocusMonitorKind;
|
|
75
|
+
title: string;
|
|
76
|
+
summary: string;
|
|
77
|
+
whyItMatters: string;
|
|
78
|
+
nextAction: string;
|
|
79
|
+
evidence: FocusEvidence[];
|
|
80
|
+
status: FocusInsightStatus;
|
|
81
|
+
valueScore: number;
|
|
82
|
+
valueReasons: string[];
|
|
83
|
+
createdAt: number;
|
|
84
|
+
updatedAt: number;
|
|
85
|
+
}
|
|
86
|
+
export interface FocusDetail extends Focus {
|
|
87
|
+
monitors: FocusMonitor[];
|
|
88
|
+
latestInsight?: FocusInsight;
|
|
89
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createLogger } from "../../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../../utils/logger.js";
|
|
3
3
|
import { shouldSilence, stripHeartbeatToken } from "../../heartbeat/tokens.js";
|
|
4
|
+
import { appendCronEventLines } from "../../heartbeat/event-prompt.js";
|
|
4
5
|
import { isWithinActiveHours } from "../../heartbeat/active-hours.js";
|
|
5
6
|
import { isHeartbeatContentEmpty } from "../../heartbeat/content-check.js";
|
|
6
|
-
import { appendCronEventLines } from "../../heartbeat/event-prompt.js";
|
|
7
7
|
import { createHeartbeatWake } from "../../heartbeat/wake.js";
|
|
8
8
|
import { resolveHeartbeatMdPath } from "../workspace-heartbeat-path.js";
|
|
9
9
|
import { readFile } from "fs/promises";
|