@askexenow/exe-os 0.9.267 → 0.9.268
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/deploy/compose/.env.customer.example +10 -0
- package/deploy/compose/docker-compose.yml +5 -6
- package/dist/active-agent-CA6YCKRU.js +25 -0
- package/dist/active-agent-S55CV6MK.js +26 -0
- package/dist/active-agent-T4IMZLH4.js +25 -0
- package/dist/active-agent-USYNCT45.js +26 -0
- package/dist/agentic-ontology-AZVW3ZYE.js +25 -0
- package/dist/backfill-metadata-556UWRQK.js +597 -0
- package/dist/backfill-metadata-Q5QBN45Z.js +597 -0
- package/dist/behaviors-CPS3PGWK.js +25 -0
- package/dist/bin/agentic-ontology-backfill.js +5 -5
- package/dist/bin/agentic-reflection-backfill.js +6 -6
- package/dist/bin/agentic-semantic-label.js +5 -5
- package/dist/bin/backfill-conversations.js +5 -5
- package/dist/bin/backfill-responses.js +5 -5
- package/dist/bin/backfill-vectors.js +6 -6
- package/dist/bin/bulk-sync-postgres.js +6 -6
- package/dist/bin/cc-doctor.js +4 -4
- package/dist/bin/cleanup-stale-review-tasks.js +9 -9
- package/dist/bin/cli.js +16 -16
- package/dist/bin/exe-agent-config.js +2 -2
- package/dist/bin/exe-agent.js +4 -4
- package/dist/bin/exe-assign.js +7 -7
- package/dist/bin/exe-boot.js +16 -16
- package/dist/bin/exe-call.js +4 -4
- package/dist/bin/exe-cloud.js +4 -4
- package/dist/bin/exe-dispatch.js +9 -9
- package/dist/bin/exe-doctor.js +1 -1
- package/dist/bin/exe-export-behaviors.js +7 -7
- package/dist/bin/exe-forget.js +6 -6
- package/dist/bin/exe-gateway.js +7 -7
- package/dist/bin/exe-healthcheck.js +4 -4
- package/dist/bin/exe-heartbeat.js +9 -9
- package/dist/bin/exe-kill.js +12 -12
- package/dist/bin/exe-launch-agent.js +16 -16
- package/dist/bin/exe-new-employee.js +6 -6
- package/dist/bin/exe-pending-messages.js +10 -10
- package/dist/bin/exe-pending-notifications.js +9 -9
- package/dist/bin/exe-pending-reviews.js +9 -9
- package/dist/bin/exe-rename.js +4 -4
- package/dist/bin/exe-review.js +11 -11
- package/dist/bin/exe-search.js +5 -5
- package/dist/bin/exe-session-cleanup.js +14 -14
- package/dist/bin/exe-settings.js +4 -4
- package/dist/bin/exe-start-codex.js +11 -11
- package/dist/bin/exe-start-opencode.js +8 -8
- package/dist/bin/exe-status.js +10 -10
- package/dist/bin/exe-team.js +3 -3
- package/dist/bin/git-sweep.js +10 -10
- package/dist/bin/graph-backfill.js +4 -4
- package/dist/bin/graph-export.js +5 -5
- package/dist/bin/import-history.js +7 -7
- package/dist/bin/install.js +6 -6
- package/dist/bin/intercom-check.js +4 -4
- package/dist/bin/mcp-sessions.js +2 -2
- package/dist/bin/orchestration-metrics.js +4 -4
- package/dist/bin/postgres-agentic-reflection-backfill.js +2 -2
- package/dist/bin/postgres-agentic-semantic-backfill.js +1 -1
- package/dist/bin/scan-tasks.js +9 -9
- package/dist/bin/setup.js +1 -1
- package/dist/bin/shard-migrate.js +4 -4
- package/dist/bin/stack-update.js +2 -2
- package/dist/bin/vps-health-gate.js +1 -1
- package/dist/capacity-monitor-WP4XXR7R.js +49 -0
- package/dist/capacity-monitor-ZGQ54TJG.js +49 -0
- package/dist/catchup-brief-X6O7W2YR.js +151 -0
- package/dist/catchup-brief-Z7SNTGLV.js +151 -0
- package/dist/chunk-23MJ2AJJ.js +227 -0
- package/dist/chunk-2NIJORQE.js +1335 -0
- package/dist/chunk-32RG5ZJN.js +3955 -0
- package/dist/chunk-3VTC7TJF.js +128 -0
- package/dist/chunk-3ZXL2KBT.js +1073 -0
- package/dist/chunk-44MXQ47E.js +185 -0
- package/dist/chunk-474SY5VD.js +159 -0
- package/dist/chunk-4LMI7RAW.js +1345 -0
- package/dist/chunk-4OH73UXH.js +1090 -0
- package/dist/chunk-4TOJXBXG.js +1073 -0
- package/dist/chunk-52UCKTIS.js +333 -0
- package/dist/chunk-5CHJKN6Y.js +668 -0
- package/dist/chunk-5MOYMGS5.js +818 -0
- package/dist/chunk-5ZSES6UA.js +363 -0
- package/dist/chunk-6HTXA4IM.js +394 -0
- package/dist/chunk-6L5DS7XO.js +394 -0
- package/dist/chunk-6TZCFZNG.js +171 -0
- package/dist/chunk-6WKV4F6L.js +1021 -0
- package/dist/chunk-7EOWAMTZ.js +69 -0
- package/dist/chunk-7MKEEX3T.js +2091 -0
- package/dist/chunk-7QYTIVXO.js +1051 -0
- package/dist/chunk-7SLLNRR3.js +129 -0
- package/dist/chunk-7V53QH5T.js +204 -0
- package/dist/chunk-7XDVTUTI.js +50 -0
- package/dist/chunk-A2E2TBDU.js +330 -0
- package/dist/chunk-A4DKFB77.js +159 -0
- package/dist/chunk-AUUJONUS.js +58 -0
- package/dist/chunk-B4YGGOCL.js +284 -0
- package/dist/chunk-BVYP37Y3.js +1345 -0
- package/dist/chunk-BXY5Y3RI.js +3955 -0
- package/dist/chunk-C3MK24X5.js +13696 -0
- package/dist/chunk-C74ZXYPJ.js +123 -0
- package/dist/chunk-CBO7IM7Q.js +135 -0
- package/dist/chunk-DIZLK77N.js +240 -0
- package/dist/chunk-DLTODKBW.js +1921 -0
- package/dist/chunk-DNJVH7A7.js +221 -0
- package/dist/chunk-E2FPTCL5.js +297 -0
- package/dist/chunk-E5USG7Z4.js +54 -0
- package/dist/chunk-E64IJVDT.js +85 -0
- package/dist/chunk-EFGQ72GA.js +76 -0
- package/dist/chunk-EODAYF7M.js +97 -0
- package/dist/chunk-EOKBXGMP.js +495 -0
- package/dist/chunk-EPYHCDZZ.js +551 -0
- package/dist/chunk-FHLIK2XG.js +38 -0
- package/dist/chunk-FO6CLTAL.js +128 -0
- package/dist/chunk-FSBNZ5YU.js +244 -0
- package/dist/chunk-FSGO7ADD.js +333 -0
- package/dist/chunk-G5L6YLG4.js +85 -0
- package/dist/chunk-GHPZEKDK.js +447 -0
- package/dist/chunk-GLSNVF6N.js +97 -0
- package/dist/chunk-GQ2XYRG3.js +163 -0
- package/dist/chunk-HGTXRRBK.js +230 -0
- package/dist/chunk-HILKCYA4.js +97 -0
- package/dist/chunk-HYI4PN4J.js +1148 -0
- package/dist/chunk-IDMLHBCK.js +1090 -0
- package/dist/chunk-IOVGBFTA.js +159 -0
- package/dist/chunk-ISAHJV4Z.js +346 -0
- package/dist/chunk-IXQ3XIG2.js +197 -0
- package/dist/chunk-JJ4VDZ5E.js +377 -0
- package/dist/chunk-JJOBSWJY.js +214 -0
- package/dist/chunk-JNRIWD5S.js +604 -0
- package/dist/chunk-JP45GCVR.js +630 -0
- package/dist/chunk-JWMFB6XM.js +244 -0
- package/dist/chunk-K7W4TYMT.js +33 -0
- package/dist/chunk-KFYOA37Q.js +562 -0
- package/dist/chunk-KUACUU74.js +58 -0
- package/dist/chunk-LHBWJIFR.js +290 -0
- package/dist/chunk-LMUDBSYR.js +551 -0
- package/dist/chunk-LSV3ODBA.js +13696 -0
- package/dist/chunk-M7GR2WO4.js +81 -0
- package/dist/chunk-MCBSXDR4.js +513 -0
- package/dist/chunk-MGJ2Z7QJ.js +127 -0
- package/dist/chunk-MUA24YMF.js +382 -0
- package/dist/chunk-MWDTPILI.js +204 -0
- package/dist/chunk-N4OGW6LW.js +731 -0
- package/dist/chunk-NBXL2BL5.js +330 -0
- package/dist/chunk-NT6A3EBV.js +1051 -0
- package/dist/chunk-ONEJTZID.js +348 -0
- package/dist/chunk-OREDDY5Y.js +513 -0
- package/dist/chunk-OSXQTCW5.js +55 -0
- package/dist/chunk-P2Q6UT2C.js +128 -0
- package/dist/chunk-PDIODWQM.js +731 -0
- package/dist/chunk-Q3NKXRHX.js +30 -0
- package/dist/chunk-QIEJRCF3.js +1148 -0
- package/dist/chunk-QILNBNN2.js +284 -0
- package/dist/chunk-QS7R2M4A.js +54 -0
- package/dist/chunk-RSIDQBIG.js +210 -0
- package/dist/chunk-SD6UFZRH.js +280 -0
- package/dist/chunk-SDL5IADB.js +76 -0
- package/dist/chunk-SFSGDC7D.js +81 -0
- package/dist/chunk-SHXHDHAX.js +127 -0
- package/dist/chunk-SQ5NFDBG.js +197 -0
- package/dist/chunk-SR34TKRT.js +214 -0
- package/dist/chunk-SYKAF5B3.js +185 -0
- package/dist/chunk-T2WWBFOX.js +447 -0
- package/dist/chunk-TINMRD3X.js +157 -0
- package/dist/chunk-TMV776ZJ.js +244 -0
- package/dist/chunk-TN45CTOI.js +70 -0
- package/dist/chunk-TYXB66FM.js +56 -0
- package/dist/chunk-UNCGZXPU.js +3556 -0
- package/dist/chunk-VAYBTLN4.js +50 -0
- package/dist/chunk-VGYL7CN2.js +260 -0
- package/dist/chunk-VIGJN5ZP.js +75 -0
- package/dist/chunk-WCFKKE7C.js +1921 -0
- package/dist/chunk-WEUOMPUC.js +346 -0
- package/dist/chunk-WRL6CIH2.js +262 -0
- package/dist/chunk-WS77NXRB.js +89 -0
- package/dist/chunk-XSRBNOLY.js +377 -0
- package/dist/chunk-XZLMH7QF.js +371 -0
- package/dist/chunk-YAITGMJO.js +89 -0
- package/dist/chunk-YDT3SUWK.js +171 -0
- package/dist/chunk-YG77F6MB.js +382 -0
- package/dist/chunk-YLWI3SAX.js +495 -0
- package/dist/chunk-YML4D7JL.js +818 -0
- package/dist/co-activation-V4G7RCBA.js +72 -0
- package/dist/co-occurrence-7AQY66CT.js +74 -0
- package/dist/code-context-index-GWAZ4PKV.js +30 -0
- package/dist/core-memory-FEVKN2AT.js +110 -0
- package/dist/core-memory-ISYNYO7T.js +110 -0
- package/dist/crdt-sync-INN5CLWY.js +33 -0
- package/dist/crm-webhook-2WGEYYAM.js +10 -0
- package/dist/crm-webhook-D7IORFLD.js +10 -0
- package/dist/cto-delegation-gate-2CMVCQW4.js +206 -0
- package/dist/cto-delegation-gate-DIMFA42F.js +206 -0
- package/dist/daemon-orchestration-G5HGOMGQ.js +135 -0
- package/dist/daemon-orchestration-IDK4LYVS.js +135 -0
- package/dist/db-backup-QDXIAYHX.js +33 -0
- package/dist/dreaming-A5QYLE67.js +32 -0
- package/dist/dreaming-CPFMD5SH.js +32 -0
- package/dist/entity-boost-BEVW2KFT.js +356 -0
- package/dist/exe-drift-Y6SN4EXZ.js +68 -0
- package/dist/exe-export-K4ZU3KZO.js +73 -0
- package/dist/exe-export-MZXEN45T.js +73 -0
- package/dist/exe-import-PWVIL5NW.js +76 -0
- package/dist/exe-import-R3AKAHWQ.js +76 -0
- package/dist/exe-key-BQVOD3YE.js +579 -0
- package/dist/exe-key-HXOWRGJT.js +579 -0
- package/dist/exe-snapshot-6URR2ANA.js +164 -0
- package/dist/exe-snapshot-C5JSC536.js +164 -0
- package/dist/fast-db-init-2CWMIQWR.js +7 -0
- package/dist/fast-db-init-UVZ2J5GS.js +7 -0
- package/dist/gateway/index.js +8 -8
- package/dist/git-staleness-VM6FPEQB.js +110 -0
- package/dist/git-task-sweep-ANHNEX7E.js +40 -0
- package/dist/git-task-sweep-R5BYJC3Y.js +40 -0
- package/dist/global-procedures-TLT6PO6L.js +20 -0
- package/dist/graph-auto-extract-BULI4PBB.js +162 -0
- package/dist/hooks/bug-report-worker.js +11 -11
- package/dist/hooks/codex-stop-task-finalizer.js +11 -11
- package/dist/hooks/commit-complete.js +11 -11
- package/dist/hooks/error-recall.js +6 -6
- package/dist/hooks/exe-heartbeat-hook.js +3 -3
- package/dist/hooks/ingest-worker.js +2 -2
- package/dist/hooks/ingest.js +6 -6
- package/dist/hooks/instructions-loaded.js +4 -4
- package/dist/hooks/manifest.json +20 -20
- package/dist/hooks/notification.js +4 -4
- package/dist/hooks/post-compact.js +10 -10
- package/dist/hooks/post-tool-combined.js +6 -6
- package/dist/hooks/pre-compact.js +13 -13
- package/dist/hooks/pre-tool-use.js +14 -14
- package/dist/hooks/prompt-submit.js +21 -21
- package/dist/hooks/session-end.js +18 -18
- package/dist/hooks/session-start.js +10 -10
- package/dist/hooks/stop.js +17 -17
- package/dist/hooks/subagent-stop.js +10 -10
- package/dist/hooks/summary-worker.js +16 -16
- package/dist/index.js +17 -17
- package/dist/installer-BEMMHBG5.js +342 -0
- package/dist/installer-CZWRBJ3Y.js +38 -0
- package/dist/installer-H43E54BM.js +38 -0
- package/dist/installer-HXKOP4YR.js +296 -0
- package/dist/installer-JAEYJUZW.js +342 -0
- package/dist/installer-ZPA6QLAX.js +296 -0
- package/dist/lib/cloud-sync.js +4 -4
- package/dist/lib/consolidation.js +5 -5
- package/dist/lib/database.js +2 -2
- package/dist/lib/db-daemon-client.js +1 -1
- package/dist/lib/db.js +2 -2
- package/dist/lib/embedder.js +2 -2
- package/dist/lib/employee-templates.js +4 -4
- package/dist/lib/employees.js +2 -2
- package/dist/lib/exe-daemon-client.js +1 -1
- package/dist/lib/exe-daemon.js +35 -35
- package/dist/lib/hybrid-search.js +5 -5
- package/dist/lib/identity.js +2 -2
- package/dist/lib/messaging.js +9 -9
- package/dist/lib/reminders.js +3 -3
- package/dist/lib/schedules.js +5 -5
- package/dist/lib/session-registry.js +4 -4
- package/dist/lib/skill-learning.js +4 -4
- package/dist/lib/store.js +4 -4
- package/dist/lib/task-router.js +3 -3
- package/dist/lib/tasks.js +10 -10
- package/dist/lib/tmux-routing.js +8 -8
- package/dist/lib/token-spend.js +3 -3
- package/dist/mcp/register-tools.js +57 -57
- package/dist/mcp/server.js +58 -58
- package/dist/mcp/tools/complete-reminder.js +4 -4
- package/dist/mcp/tools/create-reminder.js +4 -4
- package/dist/mcp/tools/create-task.js +12 -12
- package/dist/mcp/tools/deactivate-behavior.js +5 -5
- package/dist/mcp/tools/list-reminders.js +4 -4
- package/dist/mcp/tools/list-tasks.js +12 -12
- package/dist/mcp/tools/send-message.js +11 -11
- package/dist/mcp/tools/update-task.js +11 -11
- package/dist/mcp-http-config-44D7MOF6.js +27 -0
- package/dist/mcp-http-config-TCDXI6LL.js +27 -0
- package/dist/memory-cards-NNFQKOQI.js +174 -0
- package/dist/memory-graph-extractor-6VIBIUZM.js +17 -0
- package/dist/memory-poisoning-defense-P6WG3SNX.js +225 -0
- package/dist/memory-queue-client-O57KWE6B.js +16 -0
- package/dist/memory-reflection-FDJQ5ZDA.js +238 -0
- package/dist/message-queue-client-NITLPOBU.js +92 -0
- package/dist/notifications-4NS7LYYR.js +45 -0
- package/dist/notifications-L4NHSF2U.js +45 -0
- package/dist/orchestration-events-SSAWHTVL.js +25 -0
- package/dist/orchestrator-P3BTGGVB.js +33 -0
- package/dist/orchestrator-WNQFM4DU.js +33 -0
- package/dist/pipeline-router-AYPUBNHD.js +13 -0
- package/dist/pipeline-router-I7SA5NCJ.js +13 -0
- package/dist/plan-limits-GW3HHMGQ.js +26 -0
- package/dist/project-boot-TLNZDC2S.js +299 -0
- package/dist/projection-worker-MZFBSWCU.js +964 -0
- package/dist/reranker-IP2FXTLK.js +19 -0
- package/dist/reranker-RZB6XAOK.js +19 -0
- package/dist/review-polling-PRKTKLVD.js +124 -0
- package/dist/review-polling-TLFRX3H3.js +124 -0
- package/dist/runtime/index.js +11 -11
- package/dist/session-events-SOGVDZH6.js +36 -0
- package/dist/session-events-WHSKIP26.js +36 -0
- package/dist/session-kill-telemetry-AHFZUYJG.js +29 -0
- package/dist/session-scope-DNCP34ND.js +86 -0
- package/dist/session-scope-YWB765YV.js +86 -0
- package/dist/setup-wizard-IZSKLVWW.js +12 -0
- package/dist/skill-refinement-34DIUMPK.js +157 -0
- package/dist/skill-refinement-KB7RN46L.js +157 -0
- package/dist/stack-update-PQGX7KLH.js +52 -0
- package/dist/steward-gate-GX35HOTT.js +13 -0
- package/dist/task-enforcement-7NLUA7NZ.js +333 -0
- package/dist/task-enforcement-CO3UKUD3.js +333 -0
- package/dist/task-scope-4NTALPYO.js +35 -0
- package/dist/task-scope-J4QQT3DP.js +35 -0
- package/dist/tasks-crud-OJNNAL4F.js +77 -0
- package/dist/tasks-crud-T5DP4DUU.js +77 -0
- package/dist/tasks-notify-22255SAJ.js +38 -0
- package/dist/tasks-notify-ZVA4WIY5.js +38 -0
- package/dist/tasks-review-HMSWMG5X.js +47 -0
- package/dist/tasks-review-ODCDMDYP.js +47 -0
- package/dist/telemetry-upload-LCDD763H.js +739 -0
- package/dist/telemetry-upload-ZJOGSCD3.js +739 -0
- package/dist/token-budget-KQDJ5ZE5.js +84 -0
- package/dist/tool-capability-index-ZDDBVQT5.js +10 -0
- package/dist/tool-telemetry-AAUJQIIB.js +17 -0
- package/dist/tui/App.js +16 -16
- package/dist/tui-data-OYJAJYE4.js +258 -0
- package/dist/tui-data-QFMDLK6B.js +258 -0
- package/dist/wiki-acl-SH3BRQC2.js +111 -0
- package/dist/worker-gate-C366DEJR.js +21 -0
- package/dist/worker-gate-UZKHTBG7.js +21 -0
- package/dist/workflow-engine-5WGLCTKB.js +28 -0
- package/dist/workflow-engine-LNQ6G5E2.js +28 -0
- package/dist/worktree-BD7NDIDS.js +26 -0
- package/dist/worktree-sweep-6QFFMZUV.js +19 -0
- package/package.json +2 -2
- package/release-notes.json +30 -13
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getClient
|
|
3
|
+
} from "./chunk-UNCGZXPU.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/session-kill-telemetry.ts
|
|
6
|
+
import crypto from "crypto";
|
|
7
|
+
import { appendFileSync } from "fs";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import os from "os";
|
|
10
|
+
var KILL_FILE_LOG = path.join(os.homedir(), ".exe-os", "logs", "session-kills.jsonl");
|
|
11
|
+
var TOKENS_PER_IDLE_MINUTE = 50;
|
|
12
|
+
async function recordSessionKill(input) {
|
|
13
|
+
const killedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
14
|
+
const id = crypto.randomUUID();
|
|
15
|
+
try {
|
|
16
|
+
const logEntry = JSON.stringify({
|
|
17
|
+
id,
|
|
18
|
+
timestamp: killedAt,
|
|
19
|
+
session: input.sessionName,
|
|
20
|
+
agent: input.agentId,
|
|
21
|
+
reason: input.reason,
|
|
22
|
+
ticksIdle: input.ticksIdle ?? null,
|
|
23
|
+
tokensSaved: input.estimatedTokensSaved ?? null
|
|
24
|
+
});
|
|
25
|
+
appendFileSync(KILL_FILE_LOG, logEntry + "\n");
|
|
26
|
+
} catch {
|
|
27
|
+
process.stderr.write(
|
|
28
|
+
`[session-kill-telemetry] file log write failed for ${input.sessionName}
|
|
29
|
+
`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const client = getClient();
|
|
34
|
+
await client.execute({
|
|
35
|
+
sql: `INSERT INTO session_kills
|
|
36
|
+
(id, session_name, agent_id, killed_at, reason,
|
|
37
|
+
ticks_idle, estimated_tokens_saved)
|
|
38
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
39
|
+
args: [
|
|
40
|
+
id,
|
|
41
|
+
input.sessionName,
|
|
42
|
+
input.agentId,
|
|
43
|
+
killedAt,
|
|
44
|
+
input.reason,
|
|
45
|
+
input.ticksIdle ?? null,
|
|
46
|
+
input.estimatedTokensSaved ?? null
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
process.stderr.write(
|
|
51
|
+
`[session-kill-telemetry] DB write failed: ${err instanceof Error ? err.message : String(err)}
|
|
52
|
+
`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function countKillsSince(sinceISO) {
|
|
57
|
+
try {
|
|
58
|
+
const client = getClient();
|
|
59
|
+
const result = await client.execute({
|
|
60
|
+
sql: `SELECT COUNT(*) AS n FROM session_kills WHERE killed_at >= ?`,
|
|
61
|
+
args: [sinceISO]
|
|
62
|
+
});
|
|
63
|
+
const row = result.rows[0];
|
|
64
|
+
return row ? Number(row.n) : 0;
|
|
65
|
+
} catch {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
var IDLE_KILL_STREAK_META_KEY = "idle_kill_suspect_streak";
|
|
70
|
+
var IDLE_KILL_SUSPECT_DAY_THRESHOLD = 3;
|
|
71
|
+
var IDLE_KILL_MIN_LIVE_SESSIONS = 5;
|
|
72
|
+
function parseStreakState(raw) {
|
|
73
|
+
if (!raw) return { lastDate: null, streak: 0 };
|
|
74
|
+
try {
|
|
75
|
+
const parsed = JSON.parse(raw);
|
|
76
|
+
return {
|
|
77
|
+
lastDate: typeof parsed.lastDate === "string" ? parsed.lastDate : null,
|
|
78
|
+
streak: typeof parsed.streak === "number" ? parsed.streak : 0
|
|
79
|
+
};
|
|
80
|
+
} catch {
|
|
81
|
+
return { lastDate: null, streak: 0 };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function nextStreakState(prev, qualifiesToday, todayDate) {
|
|
85
|
+
if (!qualifiesToday) return { lastDate: todayDate, streak: 0 };
|
|
86
|
+
if (prev.lastDate === todayDate) return prev;
|
|
87
|
+
return { lastDate: todayDate, streak: prev.streak + 1 };
|
|
88
|
+
}
|
|
89
|
+
function computeIdleKillSuspectStreak(prev, killsToday, liveSessions, todayDate) {
|
|
90
|
+
const qualifies = killsToday === 0 && liveSessions >= IDLE_KILL_MIN_LIVE_SESSIONS;
|
|
91
|
+
const state = nextStreakState(prev, qualifies, todayDate);
|
|
92
|
+
return {
|
|
93
|
+
state,
|
|
94
|
+
suspect: state.streak >= IDLE_KILL_SUSPECT_DAY_THRESHOLD
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async function sumTokensSavedSince(sinceISO) {
|
|
98
|
+
try {
|
|
99
|
+
const client = getClient();
|
|
100
|
+
const result = await client.execute({
|
|
101
|
+
sql: `SELECT COALESCE(SUM(estimated_tokens_saved), 0) AS total
|
|
102
|
+
FROM session_kills
|
|
103
|
+
WHERE killed_at >= ?`,
|
|
104
|
+
args: [sinceISO]
|
|
105
|
+
});
|
|
106
|
+
const row = result.rows[0];
|
|
107
|
+
return row ? Number(row.total) : 0;
|
|
108
|
+
} catch {
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
TOKENS_PER_IDLE_MINUTE,
|
|
115
|
+
recordSessionKill,
|
|
116
|
+
countKillsSince,
|
|
117
|
+
IDLE_KILL_STREAK_META_KEY,
|
|
118
|
+
IDLE_KILL_SUSPECT_DAY_THRESHOLD,
|
|
119
|
+
IDLE_KILL_MIN_LIVE_SESSIONS,
|
|
120
|
+
parseStreakState,
|
|
121
|
+
computeIdleKillSuspectStreak,
|
|
122
|
+
sumTokensSavedSince
|
|
123
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isCoordinatorRole
|
|
3
|
+
} from "./chunk-UNCGZXPU.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/task-router.ts
|
|
6
|
+
import { randomUUID } from "crypto";
|
|
7
|
+
var DEFAULT_BLOOM_CONFIG = {
|
|
8
|
+
complexityToTier: {
|
|
9
|
+
routine: "junior",
|
|
10
|
+
standard: "standard",
|
|
11
|
+
complex: "senior",
|
|
12
|
+
critical: "specialist"
|
|
13
|
+
},
|
|
14
|
+
tierRules: {
|
|
15
|
+
junior: {
|
|
16
|
+
eligible: [],
|
|
17
|
+
// resolved dynamically from roster (Principal Engineer role)
|
|
18
|
+
reviewRequired: false,
|
|
19
|
+
manualOnly: false
|
|
20
|
+
},
|
|
21
|
+
standard: {
|
|
22
|
+
eligible: [],
|
|
23
|
+
// resolved dynamically from roster (Principal Engineer role)
|
|
24
|
+
reviewRequired: false,
|
|
25
|
+
manualOnly: false
|
|
26
|
+
},
|
|
27
|
+
senior: {
|
|
28
|
+
eligible: [],
|
|
29
|
+
// any specialist, but review required
|
|
30
|
+
reviewRequired: true,
|
|
31
|
+
manualOnly: false
|
|
32
|
+
},
|
|
33
|
+
specialist: {
|
|
34
|
+
eligible: [],
|
|
35
|
+
reviewRequired: true,
|
|
36
|
+
manualOnly: true
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function resolveBloomRouting(complexity, config = DEFAULT_BLOOM_CONFIG) {
|
|
41
|
+
const tier = config.complexityToTier[complexity];
|
|
42
|
+
const rule = config.tierRules[tier];
|
|
43
|
+
return {
|
|
44
|
+
tier,
|
|
45
|
+
reviewRequired: rule.reviewRequired,
|
|
46
|
+
manualOnly: rule.manualOnly,
|
|
47
|
+
eligible: rule.eligible
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function scoreEmployee(taskVector, agentId, searchFn) {
|
|
51
|
+
const results = await searchFn(taskVector, agentId, { limit: 5 });
|
|
52
|
+
if (results.length === 0) {
|
|
53
|
+
return { agentId, score: 0 };
|
|
54
|
+
}
|
|
55
|
+
const distances = results.map((r) => r["_distance"]).filter((d) => typeof d === "number");
|
|
56
|
+
if (distances.length > 0) {
|
|
57
|
+
const avgDistance = distances.reduce((sum, d) => sum + d, 0) / distances.length;
|
|
58
|
+
return { agentId, score: 1 / (1 + avgDistance) };
|
|
59
|
+
}
|
|
60
|
+
return { agentId, score: results.length / 5 };
|
|
61
|
+
}
|
|
62
|
+
async function routeTask(taskDescription, employees, embedFn, searchFn, options) {
|
|
63
|
+
let specialists = employees.filter((e) => !isCoordinatorRole(e.role));
|
|
64
|
+
if (specialists.length === 0) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
"No specialist employees available. Create one with /exe-new-employee."
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
let bloomRouting;
|
|
70
|
+
if (options?.complexity) {
|
|
71
|
+
bloomRouting = resolveBloomRouting(options.complexity, options.bloomConfig);
|
|
72
|
+
if (bloomRouting.manualOnly) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Task complexity "${options.complexity}" requires manual assignment (tier: ${bloomRouting.tier}).`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (bloomRouting.eligible.length > 0) {
|
|
78
|
+
const eligible = new Set(bloomRouting.eligible);
|
|
79
|
+
const filtered = specialists.filter((e) => eligible.has(e.name));
|
|
80
|
+
if (filtered.length > 0) {
|
|
81
|
+
specialists = filtered;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const taskVector = await embedFn(taskDescription);
|
|
86
|
+
const scored = await Promise.all(
|
|
87
|
+
specialists.map(async (emp) => {
|
|
88
|
+
const { score } = await scoreEmployee(taskVector, emp.name, searchFn);
|
|
89
|
+
return { employee: emp, score };
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
scored.sort((a, b) => b.score - a.score);
|
|
93
|
+
return { ...scored[0], bloomRouting };
|
|
94
|
+
}
|
|
95
|
+
function createAssignmentMemory(taskDescription, assignedTo, assignedBy) {
|
|
96
|
+
return {
|
|
97
|
+
id: randomUUID(),
|
|
98
|
+
agent_id: assignedTo.name,
|
|
99
|
+
agent_role: assignedTo.role,
|
|
100
|
+
session_id: `assign-${Date.now()}`,
|
|
101
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
102
|
+
tool_name: "assignment",
|
|
103
|
+
project_name: "",
|
|
104
|
+
has_error: false,
|
|
105
|
+
raw_text: `Task assigned by ${assignedBy}: ${taskDescription}`,
|
|
106
|
+
vector: null
|
|
107
|
+
// Will be backfilled
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function formatAssignmentOutput(employee, task, score, mode, bloomRouting) {
|
|
111
|
+
const modeLabel = mode === "auto" ? "auto-routed" : "direct";
|
|
112
|
+
const percent = Math.round(score * 100);
|
|
113
|
+
const lines = [
|
|
114
|
+
`Assigned to ${employee.name} (${employee.role})`,
|
|
115
|
+
`Mode: ${modeLabel}`,
|
|
116
|
+
`Relevance: ${percent}%`,
|
|
117
|
+
`Task: ${task}`
|
|
118
|
+
];
|
|
119
|
+
if (bloomRouting) {
|
|
120
|
+
lines.push(`Complexity tier: ${bloomRouting.tier}`);
|
|
121
|
+
if (bloomRouting.reviewRequired) {
|
|
122
|
+
lines.push(`Review: required`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return lines.join("\n");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
DEFAULT_BLOOM_CONFIG,
|
|
130
|
+
resolveBloomRouting,
|
|
131
|
+
scoreEmployee,
|
|
132
|
+
routeTask,
|
|
133
|
+
createAssignmentMemory,
|
|
134
|
+
formatAssignmentOutput
|
|
135
|
+
};
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getClient,
|
|
3
|
+
isCoordinatorName,
|
|
4
|
+
loadEmployeesSync
|
|
5
|
+
} from "./chunk-UNCGZXPU.js";
|
|
6
|
+
|
|
7
|
+
// src/lib/steward-gate.ts
|
|
8
|
+
import crypto from "crypto";
|
|
9
|
+
var ROLE_PERMISSIONS = {
|
|
10
|
+
coordinator: /* @__PURE__ */ new Set([
|
|
11
|
+
"close_task",
|
|
12
|
+
"cancel_task",
|
|
13
|
+
"merge_entities",
|
|
14
|
+
"purge_document",
|
|
15
|
+
"deactivate_behavior",
|
|
16
|
+
"override"
|
|
17
|
+
]),
|
|
18
|
+
manager: /* @__PURE__ */ new Set([
|
|
19
|
+
"close_task",
|
|
20
|
+
// their team only — enforced contextually
|
|
21
|
+
"deactivate_behavior"
|
|
22
|
+
// their team's behaviors
|
|
23
|
+
]),
|
|
24
|
+
specialist: /* @__PURE__ */ new Set([
|
|
25
|
+
"deactivate_behavior_own",
|
|
26
|
+
// own behaviors only
|
|
27
|
+
"delete_own_memory"
|
|
28
|
+
])
|
|
29
|
+
};
|
|
30
|
+
var UNIVERSAL_OPS = /* @__PURE__ */ new Set([
|
|
31
|
+
"update_own_task",
|
|
32
|
+
"store_memory",
|
|
33
|
+
"store_behavior"
|
|
34
|
+
]);
|
|
35
|
+
var MANAGER_ROLES = /* @__PURE__ */ new Set(["CTO", "CMO"]);
|
|
36
|
+
var StewardGate = class {
|
|
37
|
+
/**
|
|
38
|
+
* Check whether an agent has authority for a destructive operation.
|
|
39
|
+
*/
|
|
40
|
+
async checkAuthority(agent, operation, target) {
|
|
41
|
+
const role = await this.resolveRole(agent);
|
|
42
|
+
if (UNIVERSAL_OPS.has(operation)) {
|
|
43
|
+
const decision2 = {
|
|
44
|
+
allowed: true,
|
|
45
|
+
reason: `Operation "${operation}" is universally permitted.`,
|
|
46
|
+
confidence: 1,
|
|
47
|
+
requires_override: false
|
|
48
|
+
};
|
|
49
|
+
await this.logDecision(agent, operation, target, decision2);
|
|
50
|
+
return decision2;
|
|
51
|
+
}
|
|
52
|
+
const permissions = ROLE_PERMISSIONS[role];
|
|
53
|
+
let allowed = permissions.has(operation);
|
|
54
|
+
let reason;
|
|
55
|
+
if (!allowed && role === "specialist" && operation === "deactivate_behavior") {
|
|
56
|
+
const isOwn = await this.isOwnBehavior(agent, target);
|
|
57
|
+
if (isOwn) {
|
|
58
|
+
allowed = true;
|
|
59
|
+
reason = `Specialist "${agent}" can deactivate their own behavior.`;
|
|
60
|
+
} else {
|
|
61
|
+
reason = `Specialist "${agent}" cannot deactivate behaviors belonging to other agents.`;
|
|
62
|
+
}
|
|
63
|
+
} else if (allowed) {
|
|
64
|
+
reason = `Role "${role}" has authority for "${operation}".`;
|
|
65
|
+
} else {
|
|
66
|
+
reason = `Role "${role}" does not have authority for "${operation}". Requires coordinator override.`;
|
|
67
|
+
}
|
|
68
|
+
let requiresOverride = !allowed;
|
|
69
|
+
let confidence = allowed ? 0.95 : 0.9;
|
|
70
|
+
try {
|
|
71
|
+
const dreamingPath = "./dreaming.js";
|
|
72
|
+
const dreaming = await import(
|
|
73
|
+
/* @vite-ignore */
|
|
74
|
+
dreamingPath
|
|
75
|
+
);
|
|
76
|
+
if (typeof dreaming.calculateDrift === "function") {
|
|
77
|
+
const driftScore = await dreaming.calculateDrift(agent);
|
|
78
|
+
if (typeof driftScore === "number" && driftScore > 0.8) {
|
|
79
|
+
requiresOverride = true;
|
|
80
|
+
confidence = Math.max(0.5, confidence - 0.3);
|
|
81
|
+
reason += ` (\u26A0\uFE0F High drift score: ${driftScore.toFixed(2)} \u2014 requires override.)`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
const decision = {
|
|
87
|
+
allowed: allowed && !requiresOverride,
|
|
88
|
+
reason,
|
|
89
|
+
confidence,
|
|
90
|
+
requires_override: requiresOverride
|
|
91
|
+
};
|
|
92
|
+
await this.logDecision(agent, operation, target, decision);
|
|
93
|
+
return decision;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Record an explicit coordinator override that bypasses the gate.
|
|
97
|
+
*/
|
|
98
|
+
async override(agent, operation, target, reason) {
|
|
99
|
+
const role = await this.resolveRole(agent);
|
|
100
|
+
if (role !== "coordinator") {
|
|
101
|
+
const decision2 = {
|
|
102
|
+
allowed: false,
|
|
103
|
+
reason: `Only coordinators can issue overrides. "${agent}" is a ${role}.`,
|
|
104
|
+
confidence: 1,
|
|
105
|
+
requires_override: false
|
|
106
|
+
};
|
|
107
|
+
await this.logDecision(agent, `override:${operation}`, target, decision2);
|
|
108
|
+
return decision2;
|
|
109
|
+
}
|
|
110
|
+
const decision = {
|
|
111
|
+
allowed: true,
|
|
112
|
+
reason: `Coordinator override: ${reason}`,
|
|
113
|
+
confidence: 1,
|
|
114
|
+
requires_override: false
|
|
115
|
+
};
|
|
116
|
+
await this.logDecision(agent, `override:${operation}`, target, decision);
|
|
117
|
+
return decision;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Query the audit trail.
|
|
121
|
+
*/
|
|
122
|
+
async getAuditLog(opts) {
|
|
123
|
+
await this.ensureAuditTable();
|
|
124
|
+
const client = getClient();
|
|
125
|
+
const conditions = [];
|
|
126
|
+
const args = [];
|
|
127
|
+
if (opts?.agent) {
|
|
128
|
+
conditions.push("agent = ?");
|
|
129
|
+
args.push(opts.agent);
|
|
130
|
+
}
|
|
131
|
+
if (opts?.operation) {
|
|
132
|
+
conditions.push("operation = ?");
|
|
133
|
+
args.push(opts.operation);
|
|
134
|
+
}
|
|
135
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
136
|
+
const limit = opts?.limit ?? 50;
|
|
137
|
+
const result = await client.execute({
|
|
138
|
+
sql: `SELECT * FROM steward_audit ${where} ORDER BY created_at DESC LIMIT ?`,
|
|
139
|
+
args: [...args, limit]
|
|
140
|
+
});
|
|
141
|
+
return result.rows.map((row) => ({
|
|
142
|
+
id: String(row.id),
|
|
143
|
+
agent: String(row.agent),
|
|
144
|
+
operation: String(row.operation),
|
|
145
|
+
target: String(row.target),
|
|
146
|
+
decision: {
|
|
147
|
+
allowed: Number(row.allowed) === 1,
|
|
148
|
+
reason: String(row.reason),
|
|
149
|
+
confidence: Number(row.confidence),
|
|
150
|
+
requires_override: Number(row.requires_override) === 1
|
|
151
|
+
},
|
|
152
|
+
timestamp: String(row.created_at)
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
// -------------------------------------------------------------------------
|
|
156
|
+
// Internal methods
|
|
157
|
+
// -------------------------------------------------------------------------
|
|
158
|
+
/**
|
|
159
|
+
* Resolve an agent name to a role category.
|
|
160
|
+
*/
|
|
161
|
+
async resolveRole(agent) {
|
|
162
|
+
if (isCoordinatorName(agent)) return "coordinator";
|
|
163
|
+
try {
|
|
164
|
+
const employees = loadEmployeesSync();
|
|
165
|
+
const employee = employees.find((e) => e.name === agent);
|
|
166
|
+
if (employee && MANAGER_ROLES.has(employee.role)) return "manager";
|
|
167
|
+
} catch {
|
|
168
|
+
}
|
|
169
|
+
return "specialist";
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Check if a behavior belongs to the given agent.
|
|
173
|
+
*/
|
|
174
|
+
async isOwnBehavior(agent, behaviorId) {
|
|
175
|
+
try {
|
|
176
|
+
const client = getClient();
|
|
177
|
+
const result = await client.execute({
|
|
178
|
+
sql: "SELECT agent_id FROM behaviors WHERE id = ? LIMIT 1",
|
|
179
|
+
args: [behaviorId]
|
|
180
|
+
});
|
|
181
|
+
if (result.rows.length === 0) return false;
|
|
182
|
+
return String(result.rows[0].agent_id) === agent;
|
|
183
|
+
} catch {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Ensure the steward_audit table exists.
|
|
189
|
+
*/
|
|
190
|
+
async ensureAuditTable() {
|
|
191
|
+
const client = getClient();
|
|
192
|
+
await client.execute({
|
|
193
|
+
sql: `CREATE TABLE IF NOT EXISTS steward_audit (
|
|
194
|
+
id TEXT PRIMARY KEY,
|
|
195
|
+
agent TEXT NOT NULL,
|
|
196
|
+
operation TEXT NOT NULL,
|
|
197
|
+
target TEXT NOT NULL,
|
|
198
|
+
allowed INTEGER NOT NULL,
|
|
199
|
+
reason TEXT NOT NULL,
|
|
200
|
+
confidence REAL NOT NULL,
|
|
201
|
+
requires_override INTEGER NOT NULL DEFAULT 0,
|
|
202
|
+
created_at TEXT NOT NULL
|
|
203
|
+
)`,
|
|
204
|
+
args: []
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Log a gate decision to the audit trail.
|
|
209
|
+
*/
|
|
210
|
+
async logDecision(agent, operation, target, decision) {
|
|
211
|
+
try {
|
|
212
|
+
await this.ensureAuditTable();
|
|
213
|
+
const client = getClient();
|
|
214
|
+
await client.execute({
|
|
215
|
+
sql: `INSERT INTO steward_audit (id, agent, operation, target, allowed, reason, confidence, requires_override, created_at)
|
|
216
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
217
|
+
args: [
|
|
218
|
+
crypto.randomUUID(),
|
|
219
|
+
agent,
|
|
220
|
+
operation,
|
|
221
|
+
target,
|
|
222
|
+
decision.allowed ? 1 : 0,
|
|
223
|
+
decision.reason,
|
|
224
|
+
decision.confidence,
|
|
225
|
+
decision.requires_override ? 1 : 0,
|
|
226
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
227
|
+
]
|
|
228
|
+
});
|
|
229
|
+
} catch {
|
|
230
|
+
process.stderr.write(
|
|
231
|
+
`[steward-gate] Audit log write failed for ${agent}:${operation}
|
|
232
|
+
`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export {
|
|
239
|
+
StewardGate
|
|
240
|
+
};
|