@xopcai/xopc 0.0.173 → 0.0.175
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-CM6mQUS2.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-CJ5HvqE7.js → agent-avatar-dicebear-eckyE9AY.js} +1 -1
- package/dist/gateway/static/root/assets/agents-D-OIB_r0.js +2 -0
- package/dist/gateway/static/root/assets/api-2SLLStKp.js +1 -0
- package/dist/gateway/static/root/assets/{api-BZtCKzg4.js → api-BfMRS6FX.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-B0oNNcFn.js → app-management-settings-panel-DYkzZQzZ.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-DbIj4NQ1.js → appearance-settings-CDXXN57j.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-CuvFyvuu.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-BICLQFWJ.js → archive-plugin-k909a76t.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-DV3PteSU.js → attachment-load-CqNzyhdJ.js} +1 -1
- package/dist/gateway/static/root/assets/{automation-suggestion-card-CZUImis0.js → automation-suggestion-card-snNG6u0v.js} +1 -1
- package/dist/gateway/static/root/assets/automations-page-DetGVTjI.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-D6zkab6N.js → binary-plugins-PfQ9ZHDF.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-zCzoQI-g.js → block-editor-Xrw-DnE_.js} +6 -6
- package/dist/gateway/static/root/assets/browser-settings-page-G92AdEnX.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-CY3X83xQ.js → browser-workflow-inputs-DJPF2lUY.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-DDRtZLuM.js → browser-workflows-page-BoXs4pgc.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-nS_AMN1K.js +7 -0
- package/dist/gateway/static/root/assets/{capability-presets-api-pYLW6P7g.js → capability-presets-api-BgY-Ysmi.js} +1 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-DIO8ZNHW.js +1 -0
- package/dist/gateway/static/root/assets/{channel-recipient-api-DxyOH3BO.js → channel-recipient-api-D32T1EJM.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-4Im3vtnO.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-CMctpuqb.js +1 -0
- package/dist/gateway/static/root/assets/{connector-logo-BgANwjt-.js → connector-logo-C-l8haIK.js} +1 -1
- package/dist/gateway/static/root/assets/connectors-page-vL3SjHSc.js +2 -0
- package/dist/gateway/static/root/assets/copy-VueTIC2x.js +1 -0
- package/dist/gateway/static/root/assets/{desktop-pet-BPjQbPeA.js → desktop-pet-CwOI_Hei.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-8CaU1Mhm.js → desktop-pet-settings-Cldo_pA3.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-BtNRUvzM.js → directory-picker-path-field-CMASXbgJ.js} +1 -1
- package/dist/gateway/static/root/assets/dreaming-settings-BnMx02w0.js +3 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-DFjTfx6f.js → extension-debug-page-mUFs3ign.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-NyEYtWWg.js → extension-page-BsFBOZ5N.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BynTCfgf.js → extension-settings-page-CTEoovnV.js} +1 -1
- package/dist/gateway/static/root/assets/focus-detail-page-CCaZthpU.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-api-BzOWImvU.js → gateway-config-api-Bwx-EetD.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-DXepE_Jw.js → gateway-settings-CvgyqhR_.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-C2JXXtwg.js → gateway-startup-retry-C8f5KwkT.js} +1 -1
- package/dist/gateway/static/root/assets/{goal-create-dialog-ClOZyG52.js → goal-create-dialog-Bhynl9LN.js} +1 -1
- package/dist/gateway/static/root/assets/goal-detail-page-ChS2rU0w.js +4 -0
- package/dist/gateway/static/root/assets/{goals-config-api-CU3JR9MI.js → goals-config-api-CUnfbgHa.js} +1 -1
- package/dist/gateway/static/root/assets/goals-page-BAS_liXl.js +2 -0
- package/dist/gateway/static/root/assets/{goals-settings-DSZguLEx.js → goals-settings-Bkk-tOcf.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-KRkYziEF.js → heartbeat-settings-D9Pldf5E.js} +1 -1
- package/dist/gateway/static/root/assets/{image-generation-api-Y-n6TaZ_.js → image-generation-api-D7aCMgOv.js} +1 -1
- package/dist/gateway/static/root/assets/index-DJ5vdaHk.css +1 -0
- package/dist/gateway/static/root/assets/index-TnouSpay.js +212 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-CwrQv952.js → keyboard-shortcuts-settings-CBhtXhHb.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-HQeu_F1C.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-DtITcS4K.js → local-apps-page-BtJGF3M8.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-Ccv7tH8B.js → locale-store-DO-u1yS7.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-0lvwfLAA.js +7 -0
- package/dist/gateway/static/root/assets/{markdown-split-D1oZlq1m.js → markdown-split-BGPaeTch.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-BKz5V32t.js → media-plugins-C_Cx8v6u.js} +1 -1
- package/dist/gateway/static/root/assets/messages-BP8aQX-5.js +3 -0
- package/dist/gateway/static/root/assets/{notes-page-DLekBQPa.js → notes-page-CIYy5BKF.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-_FgNPlOx.js +4 -0
- package/dist/gateway/static/root/assets/{page-tabs-pT4nLfqS.js → page-tabs-C2vsdfJO.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-OtAiaJm2.js → preview-open-alternatives-D_VT83bW.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-CfryBKD9.js → product-open-page-BNP9kZ3Q.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-MNi-3mZU.js +1 -0
- package/dist/gateway/static/root/assets/{projects-page-3ubcbqHr.js → projects-page-xx8nUKZO.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-H5DSn2bR.js +1 -0
- package/dist/gateway/static/root/assets/{save-bar-controls-nP1SB3Lf.js → save-bar-controls-BJL6Xb-F.js} +1 -1
- package/dist/gateway/static/root/assets/{schedule-field-OEQTsUNz.js → schedule-field-CxCPSLbu.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-DIcAa7CJ.js → schema-form-Cao1wGbk.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-CMQsupwM.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-OBUdG6bV.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-BxNcTbYO.js → settings-form-section-9pgClEud.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-Dpdxu4sf.js → settings-loading-skeleton-CQz0gEUK.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-DwPeOm1c.js → settings-page-DgsMzZLm.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-layout-CqirFmMn.js → settings-page-layout-BhqupMfG.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-B7BsWxJt.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-D72gYeux.js → share-preview-page-CC4dQsQN.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-Bhz21P05.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-CBP-UB88.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-A0rNObNB.js +2 -0
- package/dist/gateway/static/root/assets/skills-page.utils-CF4AYPQg.js +1 -0
- package/dist/gateway/static/root/assets/{system-settings-panel-U0tBgW46.js → system-settings-panel-CzZHWI4u.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-DCKDVPFF.js → theme-store-BZWNdSZC.js} +1 -1
- package/dist/gateway/static/root/assets/time-picker-BC922Mdg.js +1 -0
- package/dist/gateway/static/root/assets/{typed-models-lib-D0XCOCAM.js → typed-models-lib-C1S-B1pk.js} +1 -1
- package/dist/gateway/static/root/assets/{use-channel-catalog-mq_Inao2.js → use-channel-catalog-DTiLxcLF.js} +1 -1
- package/dist/gateway/static/root/assets/user-context-page-8XdpiAyP.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-CKaDitO6.js → voice-api-key-field-CtIYRNfI.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-page-DBer86NF.js +1 -0
- package/dist/gateway/static/root/assets/work-item-detail-page-BUPyfYaq.js +1 -0
- package/dist/gateway/static/root/assets/work-page-G8phwwI1.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-s_kS_FYA.js → workflow-run-setup-panel-IKxqDAXw.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-CNls7g6v.js +11 -0
- package/dist/gateway/static/root/index.html +7 -7
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.js +1 -1
- package/dist/src/agent/mcp/mcp-transport.js +1 -1
- package/dist/src/agent/service.js +1 -1
- package/dist/src/agent/skills/hub-pull.js +1 -1
- package/dist/src/agent/skills/index.d.ts +2 -0
- package/dist/src/agent/skills/index.js +14 -5
- package/dist/src/agent/skills/marketplace/adapters/store/store-api-client.js +1 -1
- package/dist/src/agent/skills/skill-manage-ops.js +1 -1
- package/dist/src/agent/skills/test-framework.js +1 -1
- package/dist/src/automations/domain/defaults.d.ts +1 -0
- package/dist/src/automations/domain/defaults.js +4 -0
- package/dist/src/automations/domain/index.d.ts +1 -0
- package/dist/src/automations/domain/index.js +2 -1
- package/dist/src/automations/index.js +2 -1
- package/dist/src/automations/service/action-executor.js +2 -2
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
- package/dist/src/cli/commands/skills.js +1 -1
- package/dist/src/config/agent-profile.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/agents-admin.js +1 -1
- 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.d.ts +16 -3
- package/dist/src/gateway/hono/routes/home.js +113 -42
- package/dist/src/gateway/hono/routes/index.js +4 -0
- package/dist/src/gateway/hono/routes/local-apps.js +1 -1
- package/dist/src/gateway/hono/routes/project-skills.d.ts +3 -0
- package/dist/src/gateway/hono/routes/project-skills.js +119 -0
- 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/infra/update-restart.js +1 -1
- package/dist/src/mcp/channel-bridge.js +1 -1
- package/dist/src/projects/index.d.ts +1 -0
- package/dist/src/projects/index.js +2 -1
- package/dist/src/projects/project-skill-service.d.ts +67 -0
- package/dist/src/projects/project-skill-service.js +131 -0
- package/dist/src/storage/sqlite/home-attention-repository.d.ts +3 -0
- package/dist/src/storage/sqlite/home-attention-repository.js +21 -0
- package/dist/src/storage/sqlite/index.d.ts +1 -0
- package/dist/src/storage/sqlite/index.js +2 -1
- package/dist/src/storage/sqlite/migrations/066_first_class_focuses.sql +126 -0
- package/dist/src/storage/sqlite/migrations/067_home_attention_acknowledgements.sql +9 -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/storage/sqlite/schema.sql +10 -0
- package/dist/src/tui/tui-startup-resources.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/dist/src/workflows/service/workflow-run-service.js +1 -1
- 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/dreaming-settings-Byv-h8XZ.js +0 -3
- 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/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/time-picker-BpiBF5-d.js +0 -1
- 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,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,5 +1,5 @@
|
|
|
1
|
-
import { resolveEffectiveAgentManifest } from "../agent-manifest/resolver.js";
|
|
2
1
|
import { init_agent_scope, listAgentEntries, normalizeAgentId, resolveAgentDir, resolveAgentProfileDir, resolveAgentWorkspaceDir, resolveDefaultAgentId, resolveUserPath, validateAgentIdForNewAgent } from "../agent/agent-scope.js";
|
|
2
|
+
import { resolveEffectiveAgentManifest } from "../agent-manifest/resolver.js";
|
|
3
3
|
import { resolveEffectiveAgentProfile } from "../config/agent-profile.js";
|
|
4
4
|
import { WORKSPACE_FILES, init_paths, resolveUserProfilePath } from "../config/paths.js";
|
|
5
5
|
import { AGENT_PROFILE_MARKDOWN_SYSTEM_FILES, REQUIRED_AGENT_PROFILE_MARKDOWN_FILE_SET } from "../agent/context/workspace.js";
|
|
@@ -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";
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { createFocusActivity, listFocusActivities } from "../../../focuses/repository.js";
|
|
2
|
+
import { acceptFocusCandidate, listFocusCandidates, setFocusCandidateStatus } from "../../../focuses/candidate-repository.js";
|
|
3
|
+
import { getFocusInsight, listFocusInsights, setFocusInsightStatus } from "../../../focuses/insight-repository.js";
|
|
4
|
+
import { FocusService } from "../../../focuses/service.js";
|
|
5
|
+
import "../../../focuses/index.js";
|
|
6
|
+
//#region src/gateway/hono/routes/focuses.ts
|
|
7
|
+
const FOCUS_STATUSES = [
|
|
8
|
+
"active",
|
|
9
|
+
"paused",
|
|
10
|
+
"completed"
|
|
11
|
+
];
|
|
12
|
+
const MONITOR_KINDS = ["progress", "external_changes"];
|
|
13
|
+
function stringField(body, field) {
|
|
14
|
+
if (!body || typeof body !== "object") return "";
|
|
15
|
+
const value = body[field];
|
|
16
|
+
return typeof value === "string" ? value.trim() : "";
|
|
17
|
+
}
|
|
18
|
+
function stringArrayField(body, field) {
|
|
19
|
+
if (!body || typeof body !== "object") return void 0;
|
|
20
|
+
const value = body[field];
|
|
21
|
+
if (!Array.isArray(value)) return void 0;
|
|
22
|
+
return [...new Set(value.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean))];
|
|
23
|
+
}
|
|
24
|
+
function registerFocusRoutes(authenticated, deps) {
|
|
25
|
+
const focuses = new FocusService(deps.service.automationServiceInstance);
|
|
26
|
+
const limited = deps.strictRateLimitMiddleware;
|
|
27
|
+
authenticated.get("/api/focuses", (c) => {
|
|
28
|
+
const requested = c.req.query("status")?.split(",").map((item) => item.trim()).filter(Boolean) ?? [];
|
|
29
|
+
const statuses = requested.length > 0 ? requested.filter((item) => FOCUS_STATUSES.includes(item)) : void 0;
|
|
30
|
+
if (requested.length > 0 && statuses?.length !== requested.length) return c.json({
|
|
31
|
+
ok: false,
|
|
32
|
+
error: "Invalid focus status"
|
|
33
|
+
}, 400);
|
|
34
|
+
return c.json({
|
|
35
|
+
ok: true,
|
|
36
|
+
focuses: focuses.list(statuses)
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
authenticated.post("/api/focuses", limited, async (c) => {
|
|
40
|
+
const body = await c.req.json().catch(() => null);
|
|
41
|
+
const title = stringField(body, "title");
|
|
42
|
+
if (!title) return c.json({
|
|
43
|
+
ok: false,
|
|
44
|
+
error: "Focus title is required"
|
|
45
|
+
}, 400);
|
|
46
|
+
const focus = focuses.create({
|
|
47
|
+
title,
|
|
48
|
+
summary: stringField(body, "summary"),
|
|
49
|
+
...stringArrayField(body, "projectIds") ? { projectIds: stringArrayField(body, "projectIds") } : {},
|
|
50
|
+
...stringField(body, "goalId") ? { goalId: stringField(body, "goalId") } : {}
|
|
51
|
+
});
|
|
52
|
+
deps.service.emit("focus.created", { focus });
|
|
53
|
+
return c.json({
|
|
54
|
+
ok: true,
|
|
55
|
+
focus
|
|
56
|
+
}, 201);
|
|
57
|
+
});
|
|
58
|
+
authenticated.get("/api/focuses/:focusId", (c) => {
|
|
59
|
+
const focus = focuses.get(c.req.param("focusId"));
|
|
60
|
+
return focus ? c.json({
|
|
61
|
+
ok: true,
|
|
62
|
+
focus
|
|
63
|
+
}) : c.json({
|
|
64
|
+
ok: false,
|
|
65
|
+
error: "Focus not found"
|
|
66
|
+
}, 404);
|
|
67
|
+
});
|
|
68
|
+
authenticated.patch("/api/focuses/:focusId", limited, async (c) => {
|
|
69
|
+
const body = await c.req.json().catch(() => null);
|
|
70
|
+
const requestedStatus = stringField(body, "status");
|
|
71
|
+
if (requestedStatus && !FOCUS_STATUSES.includes(requestedStatus)) return c.json({
|
|
72
|
+
ok: false,
|
|
73
|
+
error: "Invalid focus status"
|
|
74
|
+
}, 400);
|
|
75
|
+
try {
|
|
76
|
+
const title = stringField(body, "title");
|
|
77
|
+
const hasSummary = typeof body?.summary === "string";
|
|
78
|
+
const projectIds = stringArrayField(body, "projectIds");
|
|
79
|
+
let focus = Boolean(title || hasSummary || projectIds) ? focuses.update(c.req.param("focusId"), {
|
|
80
|
+
...title ? { title } : {},
|
|
81
|
+
...hasSummary ? { summary: stringField(body, "summary") } : {},
|
|
82
|
+
...projectIds ? { projectIds } : {}
|
|
83
|
+
}) : focuses.get(c.req.param("focusId"));
|
|
84
|
+
if (focus && requestedStatus) focus = await focuses.setStatus(c.req.param("focusId"), requestedStatus);
|
|
85
|
+
if (!focus) return c.json({
|
|
86
|
+
ok: false,
|
|
87
|
+
error: "Focus not found"
|
|
88
|
+
}, 404);
|
|
89
|
+
deps.service.emit("focus.updated", { focus });
|
|
90
|
+
return c.json({
|
|
91
|
+
ok: true,
|
|
92
|
+
focus
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return c.json({
|
|
96
|
+
ok: false,
|
|
97
|
+
error: error instanceof Error ? error.message : String(error)
|
|
98
|
+
}, 400);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
authenticated.delete("/api/focuses/:focusId", limited, async (c) => {
|
|
102
|
+
try {
|
|
103
|
+
if (!await focuses.remove(c.req.param("focusId"))) return c.json({
|
|
104
|
+
ok: false,
|
|
105
|
+
error: "Focus not found"
|
|
106
|
+
}, 404);
|
|
107
|
+
deps.service.emit("focus.deleted", { focusId: c.req.param("focusId") });
|
|
108
|
+
return c.json({ ok: true });
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return c.json({
|
|
111
|
+
ok: false,
|
|
112
|
+
error: error instanceof Error ? error.message : String(error)
|
|
113
|
+
}, 500);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
authenticated.put("/api/focuses/:focusId/monitors/:kind", limited, async (c) => {
|
|
117
|
+
const kind = c.req.param("kind");
|
|
118
|
+
if (!MONITOR_KINDS.includes(kind)) return c.json({
|
|
119
|
+
ok: false,
|
|
120
|
+
error: "Invalid monitor kind"
|
|
121
|
+
}, 400);
|
|
122
|
+
const body = await c.req.json().catch(() => null);
|
|
123
|
+
const enabled = body && typeof body === "object" ? body.enabled : void 0;
|
|
124
|
+
if (typeof enabled !== "boolean") return c.json({
|
|
125
|
+
ok: false,
|
|
126
|
+
error: "enabled must be a boolean"
|
|
127
|
+
}, 400);
|
|
128
|
+
const everyMs = body && typeof body === "object" && body.cadence && typeof body.cadence === "object" ? Number(body.cadence.everyMs) : void 0;
|
|
129
|
+
try {
|
|
130
|
+
const result = await focuses.configureMonitor({
|
|
131
|
+
focusId: c.req.param("focusId"),
|
|
132
|
+
kind,
|
|
133
|
+
enabled,
|
|
134
|
+
...Number.isFinite(everyMs) ? { cadence: {
|
|
135
|
+
kind: "interval",
|
|
136
|
+
everyMs
|
|
137
|
+
} } : {}
|
|
138
|
+
});
|
|
139
|
+
deps.service.emit("focus.monitor.updated", {
|
|
140
|
+
focusId: c.req.param("focusId"),
|
|
141
|
+
monitor: result.monitor
|
|
142
|
+
});
|
|
143
|
+
return c.json({
|
|
144
|
+
ok: true,
|
|
145
|
+
...result
|
|
146
|
+
}, result.initialRunId ? 202 : 200);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
return c.json({
|
|
149
|
+
ok: false,
|
|
150
|
+
error: error instanceof Error ? error.message : String(error)
|
|
151
|
+
}, 400);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
authenticated.post("/api/focuses/:focusId/monitors/:kind/run", limited, async (c) => {
|
|
155
|
+
const kind = c.req.param("kind");
|
|
156
|
+
if (!MONITOR_KINDS.includes(kind)) return c.json({
|
|
157
|
+
ok: false,
|
|
158
|
+
error: "Invalid monitor kind"
|
|
159
|
+
}, 400);
|
|
160
|
+
try {
|
|
161
|
+
const run = await focuses.runMonitorNow(c.req.param("focusId"), kind);
|
|
162
|
+
deps.service.emit("focus.run.updated", {
|
|
163
|
+
focusId: c.req.param("focusId"),
|
|
164
|
+
kind,
|
|
165
|
+
run
|
|
166
|
+
});
|
|
167
|
+
return c.json({
|
|
168
|
+
ok: true,
|
|
169
|
+
run
|
|
170
|
+
}, 202);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return c.json({
|
|
173
|
+
ok: false,
|
|
174
|
+
error: error instanceof Error ? error.message : String(error)
|
|
175
|
+
}, 400);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
authenticated.get("/api/focuses/:focusId/activities", (c) => c.json({
|
|
179
|
+
ok: true,
|
|
180
|
+
activities: listFocusActivities({
|
|
181
|
+
focusId: c.req.param("focusId"),
|
|
182
|
+
...Number.isFinite(Number(c.req.query("before"))) ? { before: Number(c.req.query("before")) } : {},
|
|
183
|
+
...Number.isFinite(Number(c.req.query("limit"))) ? { limit: Number(c.req.query("limit")) } : {}
|
|
184
|
+
})
|
|
185
|
+
}));
|
|
186
|
+
authenticated.get("/api/focuses/:focusId/insights", (c) => c.json({
|
|
187
|
+
ok: true,
|
|
188
|
+
insights: listFocusInsights({
|
|
189
|
+
focusId: c.req.param("focusId"),
|
|
190
|
+
limit: Number(c.req.query("limit")) || 20
|
|
191
|
+
})
|
|
192
|
+
}));
|
|
193
|
+
authenticated.post("/api/focuses/:focusId/insights/:insightId/dismiss", limited, (c) => {
|
|
194
|
+
const insight = getFocusInsight(c.req.param("insightId"));
|
|
195
|
+
if (!insight || insight.focusId !== c.req.param("focusId")) return c.json({
|
|
196
|
+
ok: false,
|
|
197
|
+
error: "Insight not found"
|
|
198
|
+
}, 404);
|
|
199
|
+
const updated = setFocusInsightStatus(insight.id, "dismissed", "unread");
|
|
200
|
+
if (!updated) return c.json({
|
|
201
|
+
ok: false,
|
|
202
|
+
error: "Insight was already handled"
|
|
203
|
+
}, 409);
|
|
204
|
+
createFocusActivity({
|
|
205
|
+
focusId: insight.focusId,
|
|
206
|
+
monitorId: insight.monitorId,
|
|
207
|
+
type: "insight_dismissed",
|
|
208
|
+
summary: insight.title,
|
|
209
|
+
details: { insightId: insight.id }
|
|
210
|
+
});
|
|
211
|
+
deps.service.emit("focus.insight.updated", { insight: updated });
|
|
212
|
+
return c.json({
|
|
213
|
+
ok: true,
|
|
214
|
+
insight: updated
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
authenticated.post("/api/focuses/:focusId/insights/:insightId/investigate", limited, async (c) => {
|
|
218
|
+
const insight = getFocusInsight(c.req.param("insightId"));
|
|
219
|
+
const focus = focuses.get(c.req.param("focusId"));
|
|
220
|
+
if (!insight || !focus || insight.focusId !== focus.id) return c.json({
|
|
221
|
+
ok: false,
|
|
222
|
+
error: "Insight not found"
|
|
223
|
+
}, 404);
|
|
224
|
+
const claimed = setFocusInsightStatus(insight.id, "approved", "unread");
|
|
225
|
+
if (!claimed) return c.json({
|
|
226
|
+
ok: false,
|
|
227
|
+
error: "Insight was already handled"
|
|
228
|
+
}, 409);
|
|
229
|
+
let automationId;
|
|
230
|
+
try {
|
|
231
|
+
const automation = await deps.service.automationServiceInstance.create({
|
|
232
|
+
name: `Investigate: ${insight.title}`.slice(0, 200),
|
|
233
|
+
description: `User-approved investigation for focus insight ${insight.id}.`,
|
|
234
|
+
...focus.projectIds[0] ? { projectId: focus.projectIds[0] } : {},
|
|
235
|
+
trigger: { kind: "manual" },
|
|
236
|
+
action: {
|
|
237
|
+
kind: "agent",
|
|
238
|
+
instruction: [
|
|
239
|
+
"Investigate this user-approved focus insight in read-only mode.",
|
|
240
|
+
`Focus: ${focus.title}`,
|
|
241
|
+
`Observed change: ${insight.summary}`,
|
|
242
|
+
`Why it matters: ${insight.whyItMatters}`,
|
|
243
|
+
`Next step: ${insight.nextAction}`,
|
|
244
|
+
`Evidence: ${JSON.stringify(insight.evidence)}`,
|
|
245
|
+
"Return a concise result with evidence. Do not modify files or external systems."
|
|
246
|
+
].join("\n"),
|
|
247
|
+
timeoutSeconds: 300
|
|
248
|
+
},
|
|
249
|
+
safety: { mode: "suggest_only" },
|
|
250
|
+
afterRun: { kind: "none" },
|
|
251
|
+
reliability: {
|
|
252
|
+
timeoutSeconds: 300,
|
|
253
|
+
disableAfterConsecutiveFailures: 1
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
automationId = automation.id;
|
|
257
|
+
const run = await deps.service.automationServiceInstance.runNow(automation.id);
|
|
258
|
+
createFocusActivity({
|
|
259
|
+
focusId: focus.id,
|
|
260
|
+
monitorId: insight.monitorId,
|
|
261
|
+
type: "insight_approved",
|
|
262
|
+
summary: insight.title,
|
|
263
|
+
details: {
|
|
264
|
+
insightId: insight.id,
|
|
265
|
+
automationId,
|
|
266
|
+
runId: run.id
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
deps.service.emit("focus.insight.updated", {
|
|
270
|
+
insight: claimed,
|
|
271
|
+
investigationRunId: run.id
|
|
272
|
+
});
|
|
273
|
+
return c.json({
|
|
274
|
+
ok: true,
|
|
275
|
+
insight: claimed,
|
|
276
|
+
automationId,
|
|
277
|
+
runId: run.id
|
|
278
|
+
}, 202);
|
|
279
|
+
} catch (error) {
|
|
280
|
+
if (automationId) await deps.service.automationServiceInstance.remove(automationId);
|
|
281
|
+
setFocusInsightStatus(insight.id, "unread", "approved");
|
|
282
|
+
return c.json({
|
|
283
|
+
ok: false,
|
|
284
|
+
error: error instanceof Error ? error.message : String(error)
|
|
285
|
+
}, 500);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
authenticated.get("/api/focus-candidates", (c) => c.json({
|
|
289
|
+
ok: true,
|
|
290
|
+
candidates: listFocusCandidates()
|
|
291
|
+
}));
|
|
292
|
+
authenticated.post("/api/focus-candidates/:candidateId/accept", limited, (c) => {
|
|
293
|
+
const focus = acceptFocusCandidate(c.req.param("candidateId"));
|
|
294
|
+
if (!focus) return c.json({
|
|
295
|
+
ok: false,
|
|
296
|
+
error: "Focus candidate not found"
|
|
297
|
+
}, 404);
|
|
298
|
+
const detail = focuses.get(focus.id);
|
|
299
|
+
deps.service.emit("focus.created", { focus: detail });
|
|
300
|
+
return c.json({
|
|
301
|
+
ok: true,
|
|
302
|
+
focus: detail
|
|
303
|
+
}, 201);
|
|
304
|
+
});
|
|
305
|
+
authenticated.post("/api/focus-candidates/:candidateId/dismiss", limited, (c) => {
|
|
306
|
+
const candidate = setFocusCandidateStatus(c.req.param("candidateId"), "dismissed");
|
|
307
|
+
if (!candidate) return c.json({
|
|
308
|
+
ok: false,
|
|
309
|
+
error: "Focus candidate not found"
|
|
310
|
+
}, 404);
|
|
311
|
+
deps.service.emit("focus.candidate.updated", { candidate });
|
|
312
|
+
return c.json({
|
|
313
|
+
ok: true,
|
|
314
|
+
candidate
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
319
|
+
export { registerFocusRoutes };
|