@johpaz/hive-agents 1.0.0 → 1.0.1
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/README.md +25 -11
- package/dist/hive.js +22245 -6788
- package/dist/tool-worker.js +6 -2
- package/dist/ui/assets/{A2UIPage-D4nUFe5q.js → A2UIPage-D4nzp5NV.js} +1 -1
- package/dist/ui/assets/{AgentCreateForm-g1mQnIoJ.js → AgentCreateForm-M2RhjeA1.js} +1 -1
- package/dist/ui/assets/{AgentDetailPage-C3XkU4Ll.js → AgentDetailPage-DkFRtj8g.js} +1 -1
- package/dist/ui/assets/AgentNewPage-CfBU7puz.js +1 -0
- package/dist/ui/assets/{AgentsPage-CNA778Eo.js → AgentsPage-Ctzq2LWx.js} +1 -1
- package/dist/ui/assets/{ApiClientPage-t5DpKhmA.js → ApiClientPage-DKbGO1QW.js} +1 -1
- package/dist/ui/assets/{ChannelsPage-yY6t0YTU.js → ChannelsPage-H6rgr8DQ.js} +2 -2
- package/dist/ui/assets/{DashboardPage-BSeNSYg5.js → DashboardPage-BIjYGf4m.js} +2 -2
- package/dist/ui/assets/{LoginPage-eT5zDRDa.js → LoginPage-DazoxtBJ.js} +1 -1
- package/dist/ui/assets/{LogsPage-Gczzzsdh.js → LogsPage-DMZ6KtQ3.js} +1 -1
- package/dist/ui/assets/{MeetingPage-Bu4aMMNR.js → MeetingPage-CSLFvHL7.js} +1 -1
- package/dist/ui/assets/{ModelSelector-nNOrW3te.js → ModelSelector-BCfvugHB.js} +1 -1
- package/dist/ui/assets/{Office3DPage-B_iXEbyv.js → Office3DPage-BE6Epe0d.js} +2 -2
- package/dist/ui/assets/ProvidersPage-D0cApfM1.js +1 -0
- package/dist/ui/assets/{RecoverPage-DMqSasKk.js → RecoverPage-BVUPHG9z.js} +1 -1
- package/dist/ui/assets/{SettingsPage-B6FTSkOn.js → SettingsPage-DCZ4nql4.js} +1 -1
- package/dist/ui/assets/{SetupPage-DhcRbGgg.js → SetupPage-In19p30M.js} +1 -1
- package/dist/ui/assets/{WebChatPage-CWXjW4Hn.js → WebChatPage-ByVBSzxL.js} +1 -1
- package/dist/ui/assets/{activity-CQuPevhB.js → activity-BIIli7ET.js} +1 -1
- package/dist/ui/assets/{agentCapabilities-CDC6y91E.js → agentCapabilities-D1PD9yFH.js} +1 -1
- package/dist/ui/assets/arrow-left-BfcnX8Er.js +1 -0
- package/dist/ui/assets/arrow-right-Q-dzAn8k.js +1 -0
- package/dist/ui/assets/arrow-up-right-Bf-8wrUQ.js +1 -0
- package/dist/ui/assets/{calendar-Be23hQGc.js → calendar-S9-_Q6QR.js} +1 -1
- package/dist/ui/assets/check-CryV78SQ.js +1 -0
- package/dist/ui/assets/chevron-down-QCtMs-Af.js +1 -0
- package/dist/ui/assets/chevron-left-dTGbyl5G.js +1 -0
- package/dist/ui/assets/chevron-right-D0GjXbnO.js +1 -0
- package/dist/ui/assets/chevron-up-Cg0jO8uT.js +1 -0
- package/dist/ui/assets/{circle-alert-BDVHxmAz.js → circle-alert-DTVW4R94.js} +1 -1
- package/dist/ui/assets/circle-check-BAolxswA.js +1 -0
- package/dist/ui/assets/{circle-x-Cb2Yer4s.js → circle-x-CJXbXzRh.js} +1 -1
- package/dist/ui/assets/{copy-33tZrzc9.js → copy-X_TPpA-A.js} +1 -1
- package/dist/ui/assets/{dialog-KOZKWbib.js → dialog-uUBz_NIB.js} +1 -1
- package/dist/ui/assets/{download-CiQqqXyz.js → download-C-fXu08w.js} +1 -1
- package/dist/ui/assets/{earth-DCvN7ynm.js → earth-CTsVjCmp.js} +1 -1
- package/dist/ui/assets/{ellipsis-vertical-BybFZDk2.js → ellipsis-vertical-5zBh5yzc.js} +1 -1
- package/dist/ui/assets/{external-link-0iNNBvZm.js → external-link-CvpRhwC_.js} +1 -1
- package/dist/ui/assets/{eye-C8sKSSkg.js → eye-CM-HQEWU.js} +1 -1
- package/dist/ui/assets/{file-text-DO8jqiJK.js → file-text-lwkvYGtA.js} +1 -1
- package/dist/ui/assets/gauge-CB-cas-h.js +1 -0
- package/dist/ui/assets/{history-BtTD1kDo.js → history-eSHspWRr.js} +1 -1
- package/dist/ui/assets/index-D489S18g.css +2 -0
- package/dist/ui/assets/{index-Bejlp-R1.js → index-ZjAc-KQS.js} +4 -4
- package/dist/ui/assets/{info-mpk1tsNC.js → info-DTgFQ_jA.js} +1 -1
- package/dist/ui/assets/{key-CoQ0qtXt.js → key-CeM9JJkq.js} +1 -1
- package/dist/ui/assets/loader-circle-Dtfz4FWw.js +1 -0
- package/dist/ui/assets/{lock-open-Cd2aqwOd.js → lock-open-B089GUAJ.js} +1 -1
- package/dist/ui/assets/{mail-BG0RYSkL.js → mail--gNFIe4M.js} +1 -1
- package/dist/ui/assets/{pause-Cme88_9s.js → pause-DjT1nwQM.js} +1 -1
- package/dist/ui/assets/{pencil-f1nJ1xhs.js → pencil-6PRgdjiU.js} +1 -1
- package/dist/ui/assets/play-tOrP0xUJ.js +1 -0
- package/dist/ui/assets/plus-Cnom3j47.js +1 -0
- package/dist/ui/assets/{radio-B5SpKJ-J.js → radio-D-joO9J0.js} +1 -1
- package/dist/ui/assets/{refresh-cw-CroGQY62.js → refresh-cw-BRrzoHQW.js} +1 -1
- package/dist/ui/assets/search-D277MUP0.js +1 -0
- package/dist/ui/assets/{select-BhbW0stK.js → select-BOR8MsSL.js} +1 -1
- package/dist/ui/assets/{send-D6whYpw-.js → send-DIlj81PT.js} +1 -1
- package/dist/ui/assets/{settings-BX6q3MGB.js → settings-CkBjgAEm.js} +1 -1
- package/dist/ui/assets/{shield-BnGyu1xf.js → shield-U0hIjGzm.js} +1 -1
- package/dist/ui/assets/{sparkles-BcaOs_Jk.js → sparkles-VXHGDbNh.js} +1 -1
- package/dist/ui/assets/{square-ju5H8nrT.js → square-OHeetvN3.js} +1 -1
- package/dist/ui/assets/terminal-C6YPcJl_.js +1 -0
- package/dist/ui/assets/{trash-2-DjQXac_0.js → trash-2-DQxm7DUM.js} +1 -1
- package/dist/ui/assets/{triangle-alert-B04mgMcg.js → triangle-alert-Dj8ZhmWj.js} +1 -1
- package/dist/ui/assets/{useHiveAgentsModelLoad-DT5-4CCj.js → useHiveAgentsModelLoad-COLvs-Ho.js} +1 -1
- package/dist/ui/assets/{useProviders-DSX7eVsz.js → useProviders-q6iROeWE.js} +1 -1
- package/dist/ui/assets/{volume-x-qnVxkRSM.js → volume-x-Bm735CXN.js} +1 -1
- package/dist/ui/assets/{wifi-BA1m2dGO.js → wifi-DklBfOZ6.js} +1 -1
- package/dist/ui/assets/{zap-DT7cM7YS.js → zap-BEZNJ0i0.js} +1 -1
- package/dist/ui/index.html +8 -6
- package/dist/ui/logoblack.png +0 -0
- package/dist/ui/logocolor-dark.png +0 -0
- package/dist/ui/logocolorbg.png +0 -0
- package/dist/ui/logodoradobg.png +0 -0
- package/package.json +12 -8
- package/packages/cli/src/commands/doctor.ts +111 -0
- package/packages/cli/src/commands/onboard.ts +126 -59
- package/packages/cli/src/ui-bundle.generated.ts +9 -92
- package/packages/core/src/agent/acceptance-checks.ts +172 -0
- package/packages/core/src/agent/agent-catalog.ts +1 -37
- package/packages/core/src/agent/agent-loop.ts +21 -2
- package/packages/core/src/agent/catalog-selector.ts +0 -1
- package/packages/core/src/agent/compaction.ts +16 -1
- package/packages/core/src/agent/context-compiler.ts +3 -1
- package/packages/core/src/agent/conversation-store.ts +1 -1
- package/packages/core/src/agent/delegation-runtime.ts +1 -8
- package/packages/core/src/agent/goal-runner.ts +111 -32
- package/packages/core/src/agent/index.ts +1 -1
- package/packages/core/src/agent/llm-client.ts +34 -2
- package/packages/core/src/agent/llm-providers/anthropic.ts +10 -7
- package/packages/core/src/agent/llm-providers/interface.ts +13 -2
- package/packages/core/src/agent/llm-providers/modelscope.ts +5 -0
- package/packages/core/src/agent/llm-providers/z-ai.ts +5 -0
- package/packages/core/src/agent/minimal-loadout.ts +1 -0
- package/packages/core/src/agent/proof-packet.ts +2 -11
- package/packages/core/src/agent/providers/index.ts +1 -1
- package/packages/core/src/agent/tool-selector.ts +25 -1
- package/packages/core/src/canvas/emitter.ts +0 -44
- package/packages/core/src/channels/manager.ts +117 -25
- package/packages/core/src/channels/whatsapp.ts +6 -1
- package/packages/core/src/config/loader.ts +13 -1
- package/packages/core/src/events/channel-narration.ts +150 -0
- package/packages/core/src/events/tool-narration.ts +62 -0
- package/packages/core/src/gateway/channel-notify.ts +11 -7
- package/packages/core/src/gateway/delegation-groups.ts +24 -11
- package/packages/core/src/gateway/helpers/narration.ts +4 -62
- package/packages/core/src/gateway/helpers/ui-source.ts +67 -0
- package/packages/core/src/gateway/job-executors.ts +29 -67
- package/packages/core/src/gateway/resolver.ts +10 -2
- package/packages/core/src/gateway/routes/agents.ts +6 -6
- package/packages/core/src/gateway/routes/channels.ts +15 -1
- package/packages/core/src/gateway/routes/models.ts +69 -12
- package/packages/core/src/gateway/routes/providers.ts +110 -28
- package/packages/core/src/gateway/routes/setup.ts +63 -11
- package/packages/core/src/gateway/routes/system.ts +8 -5
- package/packages/core/src/gateway/routes/voice.ts +3 -0
- package/packages/core/src/gateway/server.ts +58 -28
- package/packages/core/src/gateway/webchat-turn.ts +29 -5
- package/packages/core/src/index.ts +1 -1
- package/packages/core/src/storage/bootstrap.ts +13 -9
- package/packages/core/src/storage/collections.ts +12 -46
- package/packages/core/src/storage/crypto.ts +147 -58
- package/packages/core/src/storage/hivedb.ts +9 -0
- package/packages/core/src/storage/model-id.ts +53 -0
- package/packages/core/src/storage/onboarding.ts +15 -4
- package/packages/core/src/storage/seed.ts +254 -138
- package/packages/core/src/storage/usage.ts +61 -123
- package/packages/core/src/tools/agents/index.ts +199 -27
- package/packages/core/src/tools/index.ts +2 -1
- package/packages/core/src/tools/web/browser-backend.ts +129 -0
- package/packages/core/src/tools/web/browser-service.ts +75 -35
- package/packages/core/src/tools/web/webview-backend.ts +412 -0
- package/packages/core/src/voice/index.ts +108 -17
- package/packages/skills/src/bundled/agents/task_orchestrator/SKILL.md +2 -1
- package/packages/skills/src/bundled-data.generated.ts +2 -23
- package/dist/ui/assets/AgentNewPage-CEkLeA79.js +0 -1
- package/dist/ui/assets/ProvidersPage-BupHs5yO.js +0 -1
- package/dist/ui/assets/arrow-left-0EBE7nsF.js +0 -1
- package/dist/ui/assets/arrow-right-5QIaph-z.js +0 -1
- package/dist/ui/assets/arrow-up-right-DQQCY007.js +0 -1
- package/dist/ui/assets/check-Dp6tzwax.js +0 -1
- package/dist/ui/assets/chevron-down-33N886NY.js +0 -1
- package/dist/ui/assets/chevron-left-C6itJXh3.js +0 -1
- package/dist/ui/assets/chevron-right-CFodBS-b.js +0 -1
- package/dist/ui/assets/chevron-up-BvSmyBEs.js +0 -1
- package/dist/ui/assets/circle-check-BJWNbLuF.js +0 -1
- package/dist/ui/assets/gauge-BRGwuN8G.js +0 -1
- package/dist/ui/assets/index-XoTT41Hr.css +0 -2
- package/dist/ui/assets/loader-circle-BhqRN2nO.js +0 -1
- package/dist/ui/assets/play-CfYDHD6h.js +0 -1
- package/dist/ui/assets/plus-C5BxJeOX.js +0 -1
- package/dist/ui/assets/search-rfBcmohK.js +0 -1
- package/dist/ui/assets/terminal-Bjfu-TkS.js +0 -1
- package/packages/core/src/agent/acceptance-verifier.ts +0 -300
- package/packages/skills/src/bundled/agents/acceptance_verification/SKILL.md +0 -26
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto"
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"
|
|
3
|
+
import * as path from "node:path"
|
|
4
|
+
import { getHiveDir } from "../config/loader.ts"
|
|
1
5
|
import { logger } from "../utils/logger"
|
|
2
6
|
import { col } from "./hive"
|
|
3
7
|
|
|
@@ -9,49 +13,70 @@ interface SecretDoc {
|
|
|
9
13
|
iv: string
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
// ───
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
+
// ─── Durable secret store ────────────────────────────────────────────────────
|
|
17
|
+
// The `secrets` collection is the source of truth: AES-256-GCM ciphertext in
|
|
18
|
+
// the database, keyed by <HIVE_HOME>/.master.key. It lives inside the data
|
|
19
|
+
// directory, so whatever persists the database (a Docker volume, a backup)
|
|
20
|
+
// persists the secrets with it.
|
|
21
|
+
//
|
|
22
|
+
// The OS keychain (Bun.secrets) is only a best-effort mirror. It throws on
|
|
23
|
+
// headless Linux/Docker (no libsecret/D-Bus), and on desktops it can be a
|
|
24
|
+
// session keyring that is discarded when the session ends — so a secret
|
|
25
|
+
// written *only* there does not survive a server restart. That is exactly
|
|
26
|
+
// what was wiping every provider API key, channel token and MCP header on
|
|
27
|
+
// restart in production.
|
|
16
28
|
|
|
17
29
|
const _mem = new Map<string, string>()
|
|
18
30
|
let _keychainOk: boolean | null = null // null = untested
|
|
31
|
+
let _keychainApi: unknown = undefined
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
_keychainOk =
|
|
30
|
-
return _mem.get(name) ?? (await _readCollectionSecret(name))
|
|
33
|
+
/**
|
|
34
|
+
* A test double or a recovered runtime may replace Bun.secrets. Reset the
|
|
35
|
+
* cached availability result when that API object changes so a previous
|
|
36
|
+
* headless failure cannot poison the replacement backend forever.
|
|
37
|
+
*/
|
|
38
|
+
function _getKeychainApi(): any {
|
|
39
|
+
const api = (Bun as any).secrets
|
|
40
|
+
if (api !== _keychainApi) {
|
|
41
|
+
_keychainApi = api
|
|
42
|
+
_keychainOk = null
|
|
31
43
|
}
|
|
44
|
+
return api
|
|
32
45
|
}
|
|
33
46
|
|
|
47
|
+
async function _get(name: string): Promise<string | null> {
|
|
48
|
+
const cached = _mem.get(name)
|
|
49
|
+
if (cached !== undefined) return cached
|
|
50
|
+
|
|
51
|
+
// Durable store first — it is the one every write goes to.
|
|
52
|
+
const stored = await _readCollectionSecret(name)
|
|
53
|
+
if (stored) return stored
|
|
54
|
+
|
|
55
|
+
// Legacy/desktop installs may only have the value in the OS keychain.
|
|
56
|
+
const fromKeychain = await _keychainGet(name)
|
|
57
|
+
if (fromKeychain) _mem.set(name, fromKeychain)
|
|
58
|
+
return fromKeychain
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Persist a secret. Always writes the durable store; the keychain is
|
|
63
|
+
* mirrored on top when available. Returns false only when the value ended up
|
|
64
|
+
* nowhere but this process's memory — callers can use that to warn instead of
|
|
65
|
+
* silently accepting a secret that dies with the process.
|
|
66
|
+
*/
|
|
34
67
|
async function _set(name: string, value: string): Promise<boolean> {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
await (Bun as any).secrets.set({ service: SERVICE, name, value })
|
|
41
|
-
_keychainOk = true
|
|
42
|
-
return true
|
|
43
|
-
} catch {
|
|
44
|
-
_keychainOk = false
|
|
45
|
-
_mem.set(name, value)
|
|
46
|
-
return persistSecretToCollection(name, value)
|
|
68
|
+
_mem.set(name, value)
|
|
69
|
+
const durable = await persistSecretToCollection(name, value)
|
|
70
|
+
const mirrored = await _keychainSet(name, value)
|
|
71
|
+
if (!durable && !mirrored) {
|
|
72
|
+
log.error(`[secrets] ${name} could not be persisted — it will be lost on restart`)
|
|
47
73
|
}
|
|
74
|
+
return durable || mirrored
|
|
48
75
|
}
|
|
49
76
|
|
|
50
77
|
/**
|
|
51
|
-
* Read a secret from the `secrets` HiveDB collection
|
|
52
|
-
*
|
|
53
|
-
* survive process restarts when the OS keychain is unavailable (Docker,
|
|
54
|
-
* headless).
|
|
78
|
+
* Read a secret from the `secrets` HiveDB collection — the durable store.
|
|
79
|
+
* Decrypted values are cached in memory for the rest of the process.
|
|
55
80
|
*/
|
|
56
81
|
async function _readCollectionSecret(name: string): Promise<string | null> {
|
|
57
82
|
try {
|
|
@@ -69,6 +94,32 @@ async function _readCollectionSecret(name: string): Promise<string | null> {
|
|
|
69
94
|
}
|
|
70
95
|
}
|
|
71
96
|
|
|
97
|
+
async function _keychainGet(name: string): Promise<string | null> {
|
|
98
|
+
const keychain = _getKeychainApi()
|
|
99
|
+
if (_keychainOk === false) return null
|
|
100
|
+
try {
|
|
101
|
+
const val = await keychain.get({ service: SERVICE, name })
|
|
102
|
+
_keychainOk = true
|
|
103
|
+
return val ?? null
|
|
104
|
+
} catch {
|
|
105
|
+
_keychainOk = false
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function _keychainSet(name: string, value: string): Promise<boolean> {
|
|
111
|
+
const keychain = _getKeychainApi()
|
|
112
|
+
if (_keychainOk === false) return false
|
|
113
|
+
try {
|
|
114
|
+
await keychain.set({ service: SERVICE, name, value })
|
|
115
|
+
_keychainOk = true
|
|
116
|
+
return true
|
|
117
|
+
} catch {
|
|
118
|
+
_keychainOk = false
|
|
119
|
+
return false
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
72
123
|
async function _del(name: string): Promise<void> {
|
|
73
124
|
_mem.delete(name)
|
|
74
125
|
try {
|
|
@@ -84,6 +135,22 @@ async function _del(name: string): Promise<void> {
|
|
|
84
135
|
}
|
|
85
136
|
}
|
|
86
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Mint the master key (if this is a fresh install) and report where secrets
|
|
140
|
+
* will be stored. Called once at boot so an operator sees the answer before
|
|
141
|
+
* typing an API key, not after a restart lost it.
|
|
142
|
+
*/
|
|
143
|
+
export function ensureSecretsBackend(): { durable: boolean } {
|
|
144
|
+
const durable = getMasterKey() !== null
|
|
145
|
+
if (!durable) {
|
|
146
|
+
log.error(
|
|
147
|
+
`[secrets] No master key available — API keys and channel tokens will NOT survive a restart. ` +
|
|
148
|
+
`Set HIVE_MASTER_KEY or make ${getHiveDir()} writable.`
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
return { durable }
|
|
152
|
+
}
|
|
153
|
+
|
|
87
154
|
// ─── Primitive API ────────────────────────────────────────────────────────────
|
|
88
155
|
|
|
89
156
|
export async function storeSecret(name: string, value: string): Promise<void> {
|
|
@@ -209,13 +276,12 @@ export function verifyPassword(password: string, hash: string): boolean {
|
|
|
209
276
|
// ─── AES-256-GCM for the collection-backed secret fallback ──────────────────
|
|
210
277
|
|
|
211
278
|
export function decryptSecret(encrypted: string, iv: string): string {
|
|
212
|
-
const nodeCrypto = require("node:crypto")
|
|
213
279
|
const key = getMasterKey()
|
|
214
280
|
if (!key) return ""
|
|
215
281
|
try {
|
|
216
282
|
const ivBuf = Buffer.from(iv, "hex")
|
|
217
283
|
const [encData, authTag] = encrypted.split(":")
|
|
218
|
-
const decipher =
|
|
284
|
+
const decipher = createDecipheriv("aes-256-gcm", key, ivBuf)
|
|
219
285
|
decipher.setAuthTag(Buffer.from(authTag, "hex"))
|
|
220
286
|
return decipher.update(encData, "hex", "utf8") + decipher.final("utf8")
|
|
221
287
|
} catch {
|
|
@@ -223,38 +289,63 @@ export function decryptSecret(encrypted: string, iv: string): string {
|
|
|
223
289
|
}
|
|
224
290
|
}
|
|
225
291
|
|
|
292
|
+
let _masterKey: Buffer | null = null
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* The AES key protecting the `secrets` collection.
|
|
296
|
+
*
|
|
297
|
+
* `HIVE_MASTER_KEY` wins when set (the recommended way to run in production:
|
|
298
|
+
* the key never touches the data volume). Otherwise the key is minted on
|
|
299
|
+
* first use and written 0600 to `<HIVE_HOME>/.master.key`, next to the
|
|
300
|
+
* database — a fresh install becomes durable without the user configuring
|
|
301
|
+
* anything, and restoring the data directory restores the ability to read
|
|
302
|
+
* the secrets inside it.
|
|
303
|
+
*/
|
|
226
304
|
function getMasterKey(): Buffer | null {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (masterKey) {
|
|
234
|
-
return Buffer.from(masterKey.slice(0, 32).padEnd(32, "0"), "utf8")
|
|
305
|
+
if (_masterKey) return _masterKey
|
|
306
|
+
|
|
307
|
+
const fromEnv = process.env.HIVE_MASTER_KEY
|
|
308
|
+
if (fromEnv) {
|
|
309
|
+
_masterKey = Buffer.from(fromEnv.slice(0, 32).padEnd(32, "0"), "utf8")
|
|
310
|
+
return _masterKey
|
|
235
311
|
}
|
|
236
|
-
|
|
237
|
-
const keyPath =
|
|
238
|
-
if (!nodeFs.existsSync(keyPath)) return null
|
|
312
|
+
|
|
313
|
+
const keyPath = path.join(getHiveDir(), ".master.key")
|
|
239
314
|
try {
|
|
240
|
-
|
|
241
|
-
|
|
315
|
+
if (!existsSync(keyPath)) {
|
|
316
|
+
mkdirSync(path.dirname(keyPath), { recursive: true })
|
|
317
|
+
try {
|
|
318
|
+
// "wx" so two processes starting at once can't overwrite each other's key
|
|
319
|
+
writeFileSync(keyPath, randomBytes(32).toString("hex"), { mode: 0o600, flag: "wx" })
|
|
320
|
+
log.info(`[secrets] Master key generated at ${keyPath}`)
|
|
321
|
+
} catch (err) {
|
|
322
|
+
if ((err as NodeJS.ErrnoException).code !== "EEXIST") throw err
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const key = Buffer.from(readFileSync(keyPath, "utf8").trim(), "hex")
|
|
326
|
+
if (key.length !== 32) {
|
|
327
|
+
log.error(`[secrets] ${keyPath} is not a 32-byte hex key — secrets cannot be read or written`)
|
|
328
|
+
return null
|
|
329
|
+
}
|
|
330
|
+
_masterKey = key
|
|
331
|
+
return _masterKey
|
|
332
|
+
} catch (err) {
|
|
333
|
+
log.error(`[secrets] Could not read or create ${keyPath}: ${(err as Error).message}`)
|
|
242
334
|
return null
|
|
243
335
|
}
|
|
244
336
|
}
|
|
245
337
|
|
|
246
338
|
/**
|
|
247
339
|
* Encrypt a plaintext string with AES-256-GCM. Format:
|
|
248
|
-
* `<encDataHex>:<authTagHex>`. Used
|
|
249
|
-
*
|
|
340
|
+
* `<encDataHex>:<authTagHex>`. Used for every document in the `secrets`
|
|
341
|
+
* collection.
|
|
250
342
|
*/
|
|
251
343
|
export function encryptSecret(plain: string, ivHex: string): string {
|
|
252
|
-
const nodeCrypto = require("node:crypto")
|
|
253
344
|
const key = getMasterKey()
|
|
254
345
|
if (!key) return ""
|
|
255
346
|
try {
|
|
256
347
|
const iv = Buffer.from(ivHex, "hex")
|
|
257
|
-
const cipher =
|
|
348
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv)
|
|
258
349
|
const encData = cipher.update(plain, "utf8", "hex") + cipher.final("hex")
|
|
259
350
|
const authTag = cipher.getAuthTag().toString("hex")
|
|
260
351
|
return `${encData}:${authTag}`
|
|
@@ -264,20 +355,18 @@ export function encryptSecret(plain: string, ivHex: string): string {
|
|
|
264
355
|
}
|
|
265
356
|
|
|
266
357
|
/**
|
|
267
|
-
* Persist a secret to the `secrets` collection
|
|
268
|
-
*
|
|
269
|
-
*
|
|
358
|
+
* Persist a secret to the `secrets` collection — the durable store — keyed by
|
|
359
|
+
* the canonical secret name (e.g. `provider:openai:api_key`). Returns true if
|
|
360
|
+
* the document was written.
|
|
270
361
|
*/
|
|
271
362
|
async function persistSecretToCollection(name: string, value: string): Promise<boolean> {
|
|
272
|
-
const nodeCrypto = require("node:crypto")
|
|
273
|
-
|
|
274
363
|
const key = getMasterKey()
|
|
275
364
|
if (!key) {
|
|
276
|
-
log.warn(`[secrets] No master key
|
|
365
|
+
log.warn(`[secrets] No master key — cannot persist ${name} durably`)
|
|
277
366
|
return false
|
|
278
367
|
}
|
|
279
368
|
|
|
280
|
-
const iv =
|
|
369
|
+
const iv = randomBytes(12).toString("hex")
|
|
281
370
|
const ciphertext = encryptSecret(value, iv)
|
|
282
371
|
if (!ciphertext) return false
|
|
283
372
|
|
|
@@ -286,7 +375,7 @@ async function persistSecretToCollection(name: string, value: string): Promise<b
|
|
|
286
375
|
await secrets.put(name, { ciphertext, iv })
|
|
287
376
|
return true
|
|
288
377
|
} catch (err) {
|
|
289
|
-
log.warn(`[secrets]
|
|
378
|
+
log.warn(`[secrets] Durable write failed for ${name}: ${(err as Error).message}`)
|
|
290
379
|
return false
|
|
291
380
|
}
|
|
292
381
|
}
|
|
@@ -48,6 +48,15 @@ export async function getHiveDb(): Promise<HiveDB> {
|
|
|
48
48
|
return opening;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Return the currently open database without opening one.
|
|
53
|
+
* Used by lifecycle-aware consumers that need to invalidate state after a
|
|
54
|
+
* close/reopen cycle.
|
|
55
|
+
*/
|
|
56
|
+
export function getOpenHiveDb(): HiveDB | null {
|
|
57
|
+
return db;
|
|
58
|
+
}
|
|
59
|
+
|
|
51
60
|
export function closeHiveDb(): void {
|
|
52
61
|
if (db) {
|
|
53
62
|
try {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claves de la colección `models`.
|
|
3
|
+
*
|
|
4
|
+
* La colección se indexa sólo por el id del modelo, así que dos providers que
|
|
5
|
+
* sirvan el mismo modelo colisionan y uno pisa al otro (pasó de verdad con
|
|
6
|
+
* `z-ai/glm-5.2`, presente a la vez en NVIDIA NIM y en OpenRouter).
|
|
7
|
+
*
|
|
8
|
+
* Regla: el id conserva el nombre que le da el propietario del modelo, y los
|
|
9
|
+
* servicios revendedores lo prefijan con su propio id de provider.
|
|
10
|
+
*
|
|
11
|
+
* nvidia + z-ai/glm-5.2 → nvidia/z-ai/glm-5.2
|
|
12
|
+
* openrouter + z-ai/glm-5.2 → openrouter/z-ai/glm-5.2
|
|
13
|
+
* anthropic + claude-opus-5 → claude-opus-5
|
|
14
|
+
*
|
|
15
|
+
* El prefijo no llega al cable: `OpenAICompatBase.call()` quita
|
|
16
|
+
* `^<providerName>/` antes de armar el request, así que el provider recibe el
|
|
17
|
+
* nombre del propietario tal cual. Por eso todos los revendedores de esta lista
|
|
18
|
+
* deben ser OpenAI-compatibles.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const RESELLER_PROVIDERS = new Set(["nvidia", "openrouter", "opencode-go", "groq", "modelscope"])
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Id de fila en `models` para el modelo `wireId` servido por `providerId`.
|
|
25
|
+
*
|
|
26
|
+
* `wireId` es siempre el nombre del cable, nunca una clave ya prefijada. No hay
|
|
27
|
+
* atajo de idempotencia a propósito: "ya lleva el prefijo" es indistinguible de
|
|
28
|
+
* "el namespace del propietario coincide con el id del provider". NVIDIA sirve
|
|
29
|
+
* `nvidia/nemotron-3-super-120b-a12b` y Groq sirve `groq/compound`, así que
|
|
30
|
+
* saltarse el prefijo por un `startsWith` recortaba de más al volver al cable y
|
|
31
|
+
* mandaba `nemotron-…` / `compound`.
|
|
32
|
+
*/
|
|
33
|
+
export function catalogModelKey(providerId: string, wireId: string): string {
|
|
34
|
+
return RESELLER_PROVIDERS.has(providerId) ? `${providerId}/${wireId}` : wireId
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Inversa de `catalogModelKey`: el nombre que el provider espera en el cable.
|
|
39
|
+
*
|
|
40
|
+
* Los adapters OpenAI-compatibles ya hacen este strip solos al armar el request,
|
|
41
|
+
* así que esto es para los caminos que mandan el modelo a mano — por ejemplo la
|
|
42
|
+
* verificación de API key en `gateway/routes/setup.ts`, que arma su propio fetch.
|
|
43
|
+
*/
|
|
44
|
+
export function wireModelId(providerId: string, key: string): string {
|
|
45
|
+
const prefix = `${providerId}/`
|
|
46
|
+
if (!RESELLER_PROVIDERS.has(providerId) || !key.startsWith(prefix)) return key
|
|
47
|
+
return key.slice(prefix.length)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** True cuando el provider revende modelos de terceros y por eso prefija sus ids. */
|
|
51
|
+
export function isResellerProvider(providerId: string): boolean {
|
|
52
|
+
return RESELLER_PROVIDERS.has(providerId)
|
|
53
|
+
}
|
|
@@ -79,6 +79,8 @@ Si el usuario pide tres cosas que no dependen entre sí, son tres \`task_delegat
|
|
|
79
79
|
|
|
80
80
|
Cada delegación lleva: \`worker_id\`, una subtarea acotada, contexto mínimo y \`acceptance\` verificable. Antes de delegar, si el worker va a necesitar herramientas puntuales, buscalas con \`search_knowledge\` e incluilas en la instrucción. Reservá \`mode="sync"\` solo para un lookup cuyo resultado esperás en segundos.
|
|
81
81
|
|
|
82
|
+
Si más adelante una entrega no cumple sus criterios, \`task_revise\` reencola al mismo worker sobre el mismo hilo (ver sección 6) — no crees una delegación nueva para corregir algo ya delegado.
|
|
83
|
+
|
|
82
84
|
## 5. ESPERAR: NO ESPERÁS
|
|
83
85
|
|
|
84
86
|
Después de delegar, contale al usuario en una línea qué pusiste a correr y **terminá tu turno**.
|
|
@@ -91,7 +93,15 @@ Cuando todas las tareas del turno alcanzan estado terminal, Hive te reinvoca aut
|
|
|
91
93
|
|
|
92
94
|
## 6. CERRAR
|
|
93
95
|
|
|
94
|
-
Al recibir el \`[Sistema]\`,
|
|
96
|
+
Al recibir el \`[Sistema]\`, cada entrega trae sus \`acceptance\` (criterios) y sus \`checks\` (resultado determinístico, sin LLM, ya calculado):
|
|
97
|
+
|
|
98
|
+
- \`checks.status="passed"\` → un check automático ya lo confirmó. Aceptalo.
|
|
99
|
+
- \`checks.status="failed"\` (implica \`ok=false\`) → no cumplió. Nunca lo reportes como éxito.
|
|
100
|
+
- \`checks.status="unchecked"\` o ausente → no hay check automático para ese criterio: **vos sos quien juzga**, con el contenido y la evidencia que trae la entrega.
|
|
101
|
+
|
|
102
|
+
Si una entrega no cumple sus criterios: usá \`task_revise\` con el \`task_id\` y un feedback concreto y accionable — el worker retoma con su contexto, no hace falta repetirle todo el pedido. Si el problema es trivial y tenés las tools, corregilo vos directamente en vez de re-delegar. No inventes trabajo ni evidencia.
|
|
103
|
+
|
|
104
|
+
Cuando todo lo delegado en esta ronda cumple, escribí **una sola** respuesta final integrando todo. Las entradas con \`ok=false\` se reportan con su motivo real, nunca como éxito.
|
|
95
105
|
|
|
96
106
|
Guardá lo que vaya a servir después: \`save_note\` para esta conversación, \`memory_write\` para lo que deba sobrevivir a ella. Confirmá con el usuario antes de persistir datos suyos.
|
|
97
107
|
|
|
@@ -99,7 +109,7 @@ Guardá lo que vaya a servir después: \`save_note\` para esta conversación, \`
|
|
|
99
109
|
|
|
100
110
|
1. **Ética primero** — Operás bajo un Código de Ética obligatorio que no podés ignorar.
|
|
101
111
|
2. **Verdad de ejecución** — \`TaskDoc\`/\`JobDoc\` son la fuente de verdad. \`agent_find\` solo descubre workers; nunca prueba si algo está corriendo: para eso están \`task_list\` y \`task_status\`. Si \`task_delegate\` devuelve \`ok=true\` con \`task_id\`, \`job_id\` y \`run_id\`, la tarea se persistió de verdad y no es una simulación. Si una herramienta falla, reportá su resultado exacto: no inventes IDs, estados ni ejecuciones.
|
|
102
|
-
3. **
|
|
112
|
+
3. **Vos aceptás las entregas** — cada entrega vuelve con sus criterios, su evidencia y el resultado de los checks determinísticos (ver sección 6). Si cumple, la integrás; si no, \`task_revise\` con feedback concreto, o la corregís vos si es trivial. Si un worker devuelve \`needs_input\`, vos formulás la pregunta al usuario con contexto.
|
|
103
113
|
4. **Buscá antes de crear** — nunca crees un worker si el catálogo ya cubre la tarea.
|
|
104
114
|
5. **Mínimo privilegio** — solo las herramientas necesarias a cada worker. La única excepción explícita es un especialista MCP aprobado por el usuario: recibe el servidor completo que figura en \`mcp_server_ids_json\`, nunca otros servidores.
|
|
105
115
|
6. **Nunca \`cli_exec\` para cron** — usá \`cron.create\`, y preguntá al usuario cada cuánto ejecutar.
|
|
@@ -923,9 +933,10 @@ export async function getUserProviders(userId: string): Promise<Array<{
|
|
|
923
933
|
const providersCol = await col<ProviderDoc>("providers");
|
|
924
934
|
const entries = await providersCol.scan({});
|
|
925
935
|
return Promise.all(entries.map(async (e) => ({
|
|
926
|
-
id: e.doc.
|
|
936
|
+
id: e.doc.id,
|
|
927
937
|
name: e.doc.name,
|
|
928
|
-
|
|
938
|
+
// Secrets are keyed by provider id ("openai"), never by display name ("OpenAI")
|
|
939
|
+
apiKey: (await loadProviderApiKey(e.doc.id)) || null,
|
|
929
940
|
baseUrl: e.doc.base_url,
|
|
930
941
|
enabled: e.doc.enabled,
|
|
931
942
|
})));
|