hivecode-mcp 0.12.1 → 0.12.4
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/LICENSE +21 -21
- package/README.md +188 -8
- package/core.js +91 -91
- package/docs/HIVE_RULES.md +41 -41
- package/docs/MCP.md +5 -5
- package/docs/SELF_HOSTING.md +256 -256
- package/hive-activity.js +336 -310
- package/hive-await.js +187 -0
- package/hive-branch.js +656 -0
- package/hive-busy.js +88 -88
- package/hive-coord.js +110 -110
- package/hive-gate.js +135 -135
- package/hive-hook-install.js +179 -103
- package/hive-instructions.js +74 -66
- package/hive-listen.js +81 -0
- package/hive-mailbox.js +517 -386
- package/hive-mcp.js +483 -126
- package/hive-mux-proto.js +58 -58
- package/hive-mux.js +350 -350
- package/hive-obligations.js +247 -247
- package/hive-pr-staleness.js +189 -189
- package/hive-pr.js +337 -0
- package/hive-privacy.js +327 -288
- package/hive-receipts.js +233 -233
- package/hive-relay-health.js +7 -2
- package/hive-secrets.js +89 -0
- package/hive-setup.js +548 -445
- package/hive-stdio.js +172 -168
- package/hive-stop-hook.js +290 -241
- package/hive-throttle.js +118 -118
- package/hive-update.js +58 -58
- package/hive-version.js +110 -59
- package/icr-merge.js +58 -58
- package/icr.js +121 -15
- package/lang-json.js +211 -211
- package/lang-ruby.js +230 -230
- package/lang-toml.js +136 -136
- package/lang-yaml.js +183 -183
- package/limits.js +413 -394
- package/package.json +20 -11
- package/reconcile.cjs +614 -477
- package/substrate.js +252 -252
- package/sync.js +4691 -3005
- package/grm-link.cjs +0 -141
package/hive-throttle.js
CHANGED
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
// hive-throttle.js — say it again only if they can no longer see it.
|
|
2
|
-
//
|
|
3
|
-
// TWO OPPOSITE WASTES, ONE CAUSE. Hivecode repeats some blocks to an agent that still has them
|
|
4
|
-
// verbatim, and never repeats others to an agent that lost them hours ago. Both are the same
|
|
5
|
-
// missing question: *is this still in their context?*
|
|
6
|
-
//
|
|
7
|
-
// [GLOBAL PROJECT STATE] rebuilt and returned on EVERY hive_wait, unchanged, forever.
|
|
8
|
-
// An agent waiting in a loop is handed the same JSON hundreds of
|
|
9
|
-
// times, and pays for it hundreds of times.
|
|
10
|
-
//
|
|
11
|
-
// HIVE_RULES.md 6,288 bytes handed over ONCE, in the hive_join tool result. It sits
|
|
12
|
-
// in the transcript, so it is exactly what compaction throws away
|
|
13
|
-
// first -- and it is the ROOM-specific half of the rules: lanes, gate
|
|
14
|
-
// commands, who owns what. Six hours in, it is simply gone.
|
|
15
|
-
//
|
|
16
|
-
// WHAT IS *NOT* IN SCOPE, AND THIS WAS WORTH CHECKING BEFORE WRITING ANYTHING. `INSTRUCTIONS`
|
|
17
|
-
// (2,477 chars) is passed to `new Server(..., { instructions })`, which puts it in the agent's
|
|
18
|
-
// SYSTEM PROMPT. A system prompt is not part of the compactable transcript, so those rules are
|
|
19
|
-
// present on every single turn and re-sending them would be the precise waste this file exists
|
|
20
|
-
// to remove. Half of an earlier draft of this module did exactly that.
|
|
21
|
-
//
|
|
22
|
-
// THE PROXY, AND ITS HONEST LIMIT. There is no way to ask an agent what is still in its context.
|
|
23
|
-
// Agent Relay's broker faces the same wall and answers it with a measurement it *does* have --
|
|
24
|
-
// bytes of PTY output since the last reminder:
|
|
25
|
-
//
|
|
26
|
-
// "Output volume is the proxy for 'the agent actually worked and may have compacted the
|
|
27
|
-
// earlier reminder out of its context'. An agent that only sat at the prompt receiving
|
|
28
|
-
// messages still has the previous reminder verbatim in context, so repeating it only
|
|
29
|
-
// burns tokens." -- crates/broker/src/broker/injection_format.rs
|
|
30
|
-
//
|
|
31
|
-
// There is no PTY here. The equivalent measurement is the one thing this server controls exactly:
|
|
32
|
-
// BYTES IT HAS HANDED THE AGENT since the last send. Every tool result goes out through one
|
|
33
|
-
// `text()`, so the count is precise rather than sampled.
|
|
34
|
-
//
|
|
35
|
-
// This is a proxy and nothing more. It does not detect compaction; it estimates that enough has
|
|
36
|
-
// happened for compaction to be plausible. It will sometimes repeat something still in context,
|
|
37
|
-
// and sometimes stay quiet about something already gone. Both failures are cheap. Pretending the
|
|
38
|
-
// number means more than it does would not be.
|
|
39
|
-
//
|
|
40
|
-
// THREE RULES, IN PRIORITY ORDER, AND THE ORDER IS THE DESIGN:
|
|
41
|
-
//
|
|
42
|
-
// 1. never sent -> SEND. They have not seen it.
|
|
43
|
-
// 2. content changed -> SEND. Correctness outranks economy: a suppressed state change is a
|
|
44
|
-
// wrong answer, while a repeated one is only a cost.
|
|
45
|
-
// 3. otherwise -> send only if BOTH the cooldown has elapsed AND enough bytes have gone
|
|
46
|
-
// out. Either gate alone is wrong. Time alone nags an idle agent that
|
|
47
|
-
// still has the text. Bytes alone fires mid-burst on an agent that read
|
|
48
|
-
// it ninety seconds ago.
|
|
49
|
-
|
|
50
|
-
/** Long enough that a burst of work does not trigger a repeat, short enough to catch a stall. */
|
|
51
|
-
export const COOLDOWN_MS = 5 * 60000
|
|
52
|
-
|
|
53
|
-
/** Agent Relay's number, and a reasonable one: ~16k tokens of traffic since they last saw it. */
|
|
54
|
-
export const OUTPUT_BYTES = 64 * 1024
|
|
55
|
-
|
|
56
|
-
/** Cheap, order-insensitive change detection. Not a hash -- a hash would be more code for a
|
|
57
|
-
* comparison that is already exact on the strings these callers pass. */
|
|
58
|
-
const norm = (c) => (typeof c === 'string' ? c : JSON.stringify(c === undefined ? null : c))
|
|
59
|
-
|
|
60
|
-
export function makeThrottle({ now = Date.now, cooldownMs = COOLDOWN_MS, bytes = OUTPUT_BYTES } = {}) {
|
|
61
|
-
// key -> { at, content, bytesSince, sends }
|
|
62
|
-
const seen = new Map()
|
|
63
|
-
let noted = 0 // total bytes handed to the agent, for reporting only
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Record output handed to the agent.
|
|
67
|
-
*
|
|
68
|
-
* Counting for a key starts only once that key has been sent at least once -- the volume only
|
|
69
|
-
* means anything relative to "since you last saw this". Agent Relay makes the same choice and
|
|
70
|
-
* for the same reason; a counter running before the first send would make the first repeat fire
|
|
71
|
-
* immediately on a busy agent.
|
|
72
|
-
*/
|
|
73
|
-
function note(n) {
|
|
74
|
-
const add = Math.max(0, Number(n) || 0)
|
|
75
|
-
noted += add
|
|
76
|
-
for (const e of seen.values()) e.bytesSince += add
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function should(key, content) {
|
|
80
|
-
const e = seen.get(key)
|
|
81
|
-
if (!e) return { send: true, why: 'first' }
|
|
82
|
-
if (norm(content) !== e.content) return { send: true, why: 'changed' }
|
|
83
|
-
const waited = now() - e.at
|
|
84
|
-
if (waited < cooldownMs) return { send: false, why: 'recent', waited }
|
|
85
|
-
if (e.bytesSince < bytes) return { send: false, why: 'quiet', bytesSince: e.bytesSince }
|
|
86
|
-
return { send: true, why: 'likely-compacted', waited, bytesSince: e.bytesSince }
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function sent(key, content) {
|
|
90
|
-
const prev = seen.get(key)
|
|
91
|
-
seen.set(key, { at: now(), content: norm(content), bytesSince: 0, sends: (prev ? prev.sends : 0) + 1 })
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** should() and sent() in one call, for the common site: `if (send(k, c)) include(c)`. */
|
|
95
|
-
function send(key, content) {
|
|
96
|
-
const d = should(key, content)
|
|
97
|
-
if (d.send) sent(key, content)
|
|
98
|
-
return d.send
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** What was actually saved, so the claim is measured rather than asserted. */
|
|
102
|
-
function stats() {
|
|
103
|
-
const out = { keys: {}, bytesHandled: noted }
|
|
104
|
-
for (const [k, e] of seen.entries()) out.keys[k] = { sends: e.sends, bytesSince: e.bytesSince }
|
|
105
|
-
return out
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return { note, should, sent, send, stats }
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** Cheap enough to be worth repeating; says nothing an agent's system prompt already carries.
|
|
112
|
-
* Deliberately a POINTER, not a copy: the file is on the agent's own disk, and a second
|
|
113
|
-
* hand-written summary of it here would be one more description to drift. */
|
|
114
|
-
export const RULES_NUDGE =
|
|
115
|
-
'[ROOM RULES] You have been working a while — the room rules you were handed when you joined ' +
|
|
116
|
-
'are probably out of your context by now. They are ROOM-specific (lanes, gate command, who ' +
|
|
117
|
-
'owns what), so the general rules you still have do not cover them. Re-read HIVE_RULES.md in ' +
|
|
118
|
-
'your own folder before your next claim.'
|
|
1
|
+
// hive-throttle.js — say it again only if they can no longer see it.
|
|
2
|
+
//
|
|
3
|
+
// TWO OPPOSITE WASTES, ONE CAUSE. Hivecode repeats some blocks to an agent that still has them
|
|
4
|
+
// verbatim, and never repeats others to an agent that lost them hours ago. Both are the same
|
|
5
|
+
// missing question: *is this still in their context?*
|
|
6
|
+
//
|
|
7
|
+
// [GLOBAL PROJECT STATE] rebuilt and returned on EVERY hive_wait, unchanged, forever.
|
|
8
|
+
// An agent waiting in a loop is handed the same JSON hundreds of
|
|
9
|
+
// times, and pays for it hundreds of times.
|
|
10
|
+
//
|
|
11
|
+
// HIVE_RULES.md 6,288 bytes handed over ONCE, in the hive_join tool result. It sits
|
|
12
|
+
// in the transcript, so it is exactly what compaction throws away
|
|
13
|
+
// first -- and it is the ROOM-specific half of the rules: lanes, gate
|
|
14
|
+
// commands, who owns what. Six hours in, it is simply gone.
|
|
15
|
+
//
|
|
16
|
+
// WHAT IS *NOT* IN SCOPE, AND THIS WAS WORTH CHECKING BEFORE WRITING ANYTHING. `INSTRUCTIONS`
|
|
17
|
+
// (2,477 chars) is passed to `new Server(..., { instructions })`, which puts it in the agent's
|
|
18
|
+
// SYSTEM PROMPT. A system prompt is not part of the compactable transcript, so those rules are
|
|
19
|
+
// present on every single turn and re-sending them would be the precise waste this file exists
|
|
20
|
+
// to remove. Half of an earlier draft of this module did exactly that.
|
|
21
|
+
//
|
|
22
|
+
// THE PROXY, AND ITS HONEST LIMIT. There is no way to ask an agent what is still in its context.
|
|
23
|
+
// Agent Relay's broker faces the same wall and answers it with a measurement it *does* have --
|
|
24
|
+
// bytes of PTY output since the last reminder:
|
|
25
|
+
//
|
|
26
|
+
// "Output volume is the proxy for 'the agent actually worked and may have compacted the
|
|
27
|
+
// earlier reminder out of its context'. An agent that only sat at the prompt receiving
|
|
28
|
+
// messages still has the previous reminder verbatim in context, so repeating it only
|
|
29
|
+
// burns tokens." -- crates/broker/src/broker/injection_format.rs
|
|
30
|
+
//
|
|
31
|
+
// There is no PTY here. The equivalent measurement is the one thing this server controls exactly:
|
|
32
|
+
// BYTES IT HAS HANDED THE AGENT since the last send. Every tool result goes out through one
|
|
33
|
+
// `text()`, so the count is precise rather than sampled.
|
|
34
|
+
//
|
|
35
|
+
// This is a proxy and nothing more. It does not detect compaction; it estimates that enough has
|
|
36
|
+
// happened for compaction to be plausible. It will sometimes repeat something still in context,
|
|
37
|
+
// and sometimes stay quiet about something already gone. Both failures are cheap. Pretending the
|
|
38
|
+
// number means more than it does would not be.
|
|
39
|
+
//
|
|
40
|
+
// THREE RULES, IN PRIORITY ORDER, AND THE ORDER IS THE DESIGN:
|
|
41
|
+
//
|
|
42
|
+
// 1. never sent -> SEND. They have not seen it.
|
|
43
|
+
// 2. content changed -> SEND. Correctness outranks economy: a suppressed state change is a
|
|
44
|
+
// wrong answer, while a repeated one is only a cost.
|
|
45
|
+
// 3. otherwise -> send only if BOTH the cooldown has elapsed AND enough bytes have gone
|
|
46
|
+
// out. Either gate alone is wrong. Time alone nags an idle agent that
|
|
47
|
+
// still has the text. Bytes alone fires mid-burst on an agent that read
|
|
48
|
+
// it ninety seconds ago.
|
|
49
|
+
|
|
50
|
+
/** Long enough that a burst of work does not trigger a repeat, short enough to catch a stall. */
|
|
51
|
+
export const COOLDOWN_MS = 5 * 60000
|
|
52
|
+
|
|
53
|
+
/** Agent Relay's number, and a reasonable one: ~16k tokens of traffic since they last saw it. */
|
|
54
|
+
export const OUTPUT_BYTES = 64 * 1024
|
|
55
|
+
|
|
56
|
+
/** Cheap, order-insensitive change detection. Not a hash -- a hash would be more code for a
|
|
57
|
+
* comparison that is already exact on the strings these callers pass. */
|
|
58
|
+
const norm = (c) => (typeof c === 'string' ? c : JSON.stringify(c === undefined ? null : c))
|
|
59
|
+
|
|
60
|
+
export function makeThrottle({ now = Date.now, cooldownMs = COOLDOWN_MS, bytes = OUTPUT_BYTES } = {}) {
|
|
61
|
+
// key -> { at, content, bytesSince, sends }
|
|
62
|
+
const seen = new Map()
|
|
63
|
+
let noted = 0 // total bytes handed to the agent, for reporting only
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Record output handed to the agent.
|
|
67
|
+
*
|
|
68
|
+
* Counting for a key starts only once that key has been sent at least once -- the volume only
|
|
69
|
+
* means anything relative to "since you last saw this". Agent Relay makes the same choice and
|
|
70
|
+
* for the same reason; a counter running before the first send would make the first repeat fire
|
|
71
|
+
* immediately on a busy agent.
|
|
72
|
+
*/
|
|
73
|
+
function note(n) {
|
|
74
|
+
const add = Math.max(0, Number(n) || 0)
|
|
75
|
+
noted += add
|
|
76
|
+
for (const e of seen.values()) e.bytesSince += add
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function should(key, content) {
|
|
80
|
+
const e = seen.get(key)
|
|
81
|
+
if (!e) return { send: true, why: 'first' }
|
|
82
|
+
if (norm(content) !== e.content) return { send: true, why: 'changed' }
|
|
83
|
+
const waited = now() - e.at
|
|
84
|
+
if (waited < cooldownMs) return { send: false, why: 'recent', waited }
|
|
85
|
+
if (e.bytesSince < bytes) return { send: false, why: 'quiet', bytesSince: e.bytesSince }
|
|
86
|
+
return { send: true, why: 'likely-compacted', waited, bytesSince: e.bytesSince }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function sent(key, content) {
|
|
90
|
+
const prev = seen.get(key)
|
|
91
|
+
seen.set(key, { at: now(), content: norm(content), bytesSince: 0, sends: (prev ? prev.sends : 0) + 1 })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** should() and sent() in one call, for the common site: `if (send(k, c)) include(c)`. */
|
|
95
|
+
function send(key, content) {
|
|
96
|
+
const d = should(key, content)
|
|
97
|
+
if (d.send) sent(key, content)
|
|
98
|
+
return d.send
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** What was actually saved, so the claim is measured rather than asserted. */
|
|
102
|
+
function stats() {
|
|
103
|
+
const out = { keys: {}, bytesHandled: noted }
|
|
104
|
+
for (const [k, e] of seen.entries()) out.keys[k] = { sends: e.sends, bytesSince: e.bytesSince }
|
|
105
|
+
return out
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return { note, should, sent, send, stats }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Cheap enough to be worth repeating; says nothing an agent's system prompt already carries.
|
|
112
|
+
* Deliberately a POINTER, not a copy: the file is on the agent's own disk, and a second
|
|
113
|
+
* hand-written summary of it here would be one more description to drift. */
|
|
114
|
+
export const RULES_NUDGE =
|
|
115
|
+
'[ROOM RULES] You have been working a while — the room rules you were handed when you joined ' +
|
|
116
|
+
'are probably out of your context by now. They are ROOM-specific (lanes, gate command, who ' +
|
|
117
|
+
'owns what), so the general rules you still have do not cover them. Re-read HIVE_RULES.md in ' +
|
|
118
|
+
'your own folder before your next claim.'
|
package/hive-update.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
// hive-update.js -- tells an agent, and through it its human, that a newer hivecode is out.
|
|
2
|
-
//
|
|
3
|
-
// WHY THIS EXISTS. `npx -y hivecode-mcp@latest setup` points agent apps at a runtime COPY
|
|
4
|
-
// (~/.hivecode/runtime/<version>), which is what made starting fast, offline and free of npx.
|
|
5
|
-
// It also means nothing updates any more: every start used to fetch @latest, and now an agent
|
|
6
|
-
// stays on the version it was set up with until someone runs setup again. A room with mixed
|
|
7
|
-
// builds is the one condition hive_join itself warns can lose data, so the gap must be visible.
|
|
8
|
-
//
|
|
9
|
-
// IT NEVER GETS IN THE WAY. The check starts with the server, carries a short timeout, and
|
|
10
|
-
// hive_join and hive_status use whatever answer has arrived by then. A failed check says
|
|
11
|
-
// nothing -- no network is not news. HIVE_PRIVATE=1 and HIVE_NO_UPDATE_CHECK=1 both switch it
|
|
12
|
-
// off: a user who asked for privacy did not ask for a request to npm on every start.
|
|
13
|
-
import { VERSION } from './hive-version.js'
|
|
14
|
-
|
|
15
|
-
const REGISTRY_LATEST = 'https://registry.npmjs.org/hivecode-mcp/latest'
|
|
16
|
-
|
|
17
|
-
/** True when version `a` is newer than `b` (x.y.z; anything unparseable is never "newer"). */
|
|
18
|
-
export function newer(a, b) {
|
|
19
|
-
const parse = (v) => String(v).split('-')[0].split('.').map((n) => Number(n))
|
|
20
|
-
const pa = parse(a)
|
|
21
|
-
const pb = parse(b)
|
|
22
|
-
for (let i = 0; i < 3; i++) {
|
|
23
|
-
const x = pa[i] ?? 0
|
|
24
|
-
const y = pb[i] ?? 0
|
|
25
|
-
if (!Number.isFinite(x) || !Number.isFinite(y)) return false
|
|
26
|
-
if (x !== y) return x > y
|
|
27
|
-
}
|
|
28
|
-
return false
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let latest = null
|
|
32
|
-
let started = false
|
|
33
|
-
|
|
34
|
-
export function startUpdateCheck({ fetchImpl = globalThis.fetch, timeoutMs = 4000, env = process.env } = {}) {
|
|
35
|
-
if (started) return
|
|
36
|
-
started = true
|
|
37
|
-
if (env.HIVE_NO_UPDATE_CHECK === '1' || env.HIVE_PRIVATE === '1' || typeof fetchImpl !== 'function') return
|
|
38
|
-
Promise.resolve()
|
|
39
|
-
// HIVE_UPDATE_URL exists for tests/update-notice-test.mjs, which serves a fake registry so the
|
|
40
|
-
// wiring is proven end to end through a real server process.
|
|
41
|
-
.then(() => fetchImpl(env.HIVE_UPDATE_URL || REGISTRY_LATEST, { signal: AbortSignal.timeout(timeoutMs), headers: { accept: 'application/json' } }))
|
|
42
|
-
.then((r) => (r && r.ok ? r.json() : null))
|
|
43
|
-
.then((j) => { if (j && typeof j.version === 'string') latest = j.version })
|
|
44
|
-
.catch(() => { /* offline, blocked, or slow: say nothing */ })
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** The line to show, or '' when this agent is current (or nobody knows yet). */
|
|
48
|
-
export function updateNotice(current = VERSION, known = latest) {
|
|
49
|
-
if (!known || !newer(known, current)) return ''
|
|
50
|
-
return `UPDATE AVAILABLE: hivecode ${known} is out; this agent runs ${current}. Tell your human to run ` +
|
|
51
|
-
'`npx -y hivecode-mcp@latest setup` and reload this agent. Mixed versions in one room can lose data.'
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const _test = {
|
|
55
|
-
reset() { latest = null; started = false },
|
|
56
|
-
setLatest(v) { latest = v; started = true },
|
|
57
|
-
latest: () => latest,
|
|
58
|
-
}
|
|
1
|
+
// hive-update.js -- tells an agent, and through it its human, that a newer hivecode is out.
|
|
2
|
+
//
|
|
3
|
+
// WHY THIS EXISTS. `npx -y hivecode-mcp@latest setup` points agent apps at a runtime COPY
|
|
4
|
+
// (~/.hivecode/runtime/<version>), which is what made starting fast, offline and free of npx.
|
|
5
|
+
// It also means nothing updates any more: every start used to fetch @latest, and now an agent
|
|
6
|
+
// stays on the version it was set up with until someone runs setup again. A room with mixed
|
|
7
|
+
// builds is the one condition hive_join itself warns can lose data, so the gap must be visible.
|
|
8
|
+
//
|
|
9
|
+
// IT NEVER GETS IN THE WAY. The check starts with the server, carries a short timeout, and
|
|
10
|
+
// hive_join and hive_status use whatever answer has arrived by then. A failed check says
|
|
11
|
+
// nothing -- no network is not news. HIVE_PRIVATE=1 and HIVE_NO_UPDATE_CHECK=1 both switch it
|
|
12
|
+
// off: a user who asked for privacy did not ask for a request to npm on every start.
|
|
13
|
+
import { VERSION } from './hive-version.js'
|
|
14
|
+
|
|
15
|
+
const REGISTRY_LATEST = 'https://registry.npmjs.org/hivecode-mcp/latest'
|
|
16
|
+
|
|
17
|
+
/** True when version `a` is newer than `b` (x.y.z; anything unparseable is never "newer"). */
|
|
18
|
+
export function newer(a, b) {
|
|
19
|
+
const parse = (v) => String(v).split('-')[0].split('.').map((n) => Number(n))
|
|
20
|
+
const pa = parse(a)
|
|
21
|
+
const pb = parse(b)
|
|
22
|
+
for (let i = 0; i < 3; i++) {
|
|
23
|
+
const x = pa[i] ?? 0
|
|
24
|
+
const y = pb[i] ?? 0
|
|
25
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return false
|
|
26
|
+
if (x !== y) return x > y
|
|
27
|
+
}
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let latest = null
|
|
32
|
+
let started = false
|
|
33
|
+
|
|
34
|
+
export function startUpdateCheck({ fetchImpl = globalThis.fetch, timeoutMs = 4000, env = process.env } = {}) {
|
|
35
|
+
if (started) return
|
|
36
|
+
started = true
|
|
37
|
+
if (env.HIVE_NO_UPDATE_CHECK === '1' || env.HIVE_PRIVATE === '1' || typeof fetchImpl !== 'function') return
|
|
38
|
+
Promise.resolve()
|
|
39
|
+
// HIVE_UPDATE_URL exists for tests/update-notice-test.mjs, which serves a fake registry so the
|
|
40
|
+
// wiring is proven end to end through a real server process.
|
|
41
|
+
.then(() => fetchImpl(env.HIVE_UPDATE_URL || REGISTRY_LATEST, { signal: AbortSignal.timeout(timeoutMs), headers: { accept: 'application/json' } }))
|
|
42
|
+
.then((r) => (r && r.ok ? r.json() : null))
|
|
43
|
+
.then((j) => { if (j && typeof j.version === 'string') latest = j.version })
|
|
44
|
+
.catch(() => { /* offline, blocked, or slow: say nothing */ })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The line to show, or '' when this agent is current (or nobody knows yet). */
|
|
48
|
+
export function updateNotice(current = VERSION, known = latest) {
|
|
49
|
+
if (!known || !newer(known, current)) return ''
|
|
50
|
+
return `UPDATE AVAILABLE: hivecode ${known} is out; this agent runs ${current}. Tell your human to run ` +
|
|
51
|
+
'`npx -y hivecode-mcp@latest setup` and reload this agent. Mixed versions in one room can lose data.'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const _test = {
|
|
55
|
+
reset() { latest = null; started = false },
|
|
56
|
+
setLatest(v) { latest = v; started = true },
|
|
57
|
+
latest: () => latest,
|
|
58
|
+
}
|
package/hive-version.js
CHANGED
|
@@ -1,59 +1,110 @@
|
|
|
1
|
-
// hive-version.js — one place that knows what build this is.
|
|
2
|
-
//
|
|
3
|
-
// WHY THIS FILE EXISTS, and it is not tidiness.
|
|
4
|
-
//
|
|
5
|
-
// VERSION is load-bearing, not cosmetic. hive_join instructs every arriving agent to announce its
|
|
6
|
-
// version in chat, because two clients running different builds in one room corrupt each other's
|
|
7
|
-
// files with no error on either side — both writes succeed, both are green, and the disagreement
|
|
8
|
-
// surfaces only as lost bytes. That announcement is the ONLY channel that makes a mixed build
|
|
9
|
-
// visible from inside the room. So a version string is not a label; it is the input to the one
|
|
10
|
-
// detector we have.
|
|
11
|
-
//
|
|
12
|
-
// On 20 Sep 2026 three entry points were found reporting a version package.json does not contain:
|
|
13
|
-
// remote-mcp.js said '0.11.5' while live on the hosted relay, hive-mcp-http.js and hive-linear.js
|
|
14
|
-
// both said '1.0.0'. hive-mcp.js had already been fixed months earlier, with a comment explaining
|
|
15
|
-
// exactly why hardcoding it is dangerous — and that fix was never carried to the other three.
|
|
16
|
-
// A detector that lies is strictly worse than no detector, because it is trusted.
|
|
17
|
-
//
|
|
18
|
-
// HIV-P7 closed that by giving each of the four files its own runtime read. Which produced the
|
|
19
|
-
// next defect, and it was measured rather than predicted: with the reader duplicated four times,
|
|
20
|
-
// corrupting ONE copy's fallback string to '9.9.9-DRIFTED' left tests/version-truth-test.mjs at
|
|
21
|
-
// 16 passed, 0 failed. The property guards the version that gets REPORTED and says nothing about
|
|
22
|
-
// the mechanism that produces it, so three of four copies could rot in silence.
|
|
23
|
-
//
|
|
24
|
-
// This codebase has watched that happen before. The extension's reconcile() and the engine's were
|
|
25
|
-
// the same function once; they now share 34 lines and behave differently. Eight lines is not too
|
|
26
|
-
// small to drift — it is exactly small enough that nobody feels the need to check.
|
|
27
|
-
//
|
|
28
|
-
// So the fix is DELETION, not another assertion. One definition, imported by all four. The
|
|
29
|
-
// property becomes true by construction instead of by policing, and a fifth entry point written
|
|
30
|
-
// next year gets it right by importing rather than by remembering.
|
|
31
|
-
//
|
|
32
|
-
// TWO DECISIONS WORTH KEEPING:
|
|
33
|
-
//
|
|
34
|
-
// It READS package.json rather than being told. package.json always ships beside these files —
|
|
35
|
-
// in the repo and in the published tarball — so `new URL('./package.json', import.meta.url)`
|
|
36
|
-
// resolves in both. Anything else (a constant, a build step, a generated file) can disagree with
|
|
37
|
-
// the package the moment `npm version` runs, which is precisely the failure being fixed.
|
|
38
|
-
//
|
|
39
|
-
// IT NEVER THROWS. A version read is not worth a server that will not boot, and a server that
|
|
40
|
-
// refuses to start is a worse outcome than one that says it does not know which build it is. So
|
|
41
|
-
// an unreadable or malformed package.json yields '0.0.0-unknown' — a value that is obviously
|
|
42
|
-
// wrong to a human, will never match a real release, and cannot be mistaken for a true answer.
|
|
43
|
-
// Silence or an empty string could be read as "no mixed build here"; this cannot.
|
|
44
|
-
|
|
45
|
-
import fs from 'fs'
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export
|
|
1
|
+
// hive-version.js — one place that knows what build this is.
|
|
2
|
+
//
|
|
3
|
+
// WHY THIS FILE EXISTS, and it is not tidiness.
|
|
4
|
+
//
|
|
5
|
+
// VERSION is load-bearing, not cosmetic. hive_join instructs every arriving agent to announce its
|
|
6
|
+
// version in chat, because two clients running different builds in one room corrupt each other's
|
|
7
|
+
// files with no error on either side — both writes succeed, both are green, and the disagreement
|
|
8
|
+
// surfaces only as lost bytes. That announcement is the ONLY channel that makes a mixed build
|
|
9
|
+
// visible from inside the room. So a version string is not a label; it is the input to the one
|
|
10
|
+
// detector we have.
|
|
11
|
+
//
|
|
12
|
+
// On 20 Sep 2026 three entry points were found reporting a version package.json does not contain:
|
|
13
|
+
// remote-mcp.js said '0.11.5' while live on the hosted relay, hive-mcp-http.js and hive-linear.js
|
|
14
|
+
// both said '1.0.0'. hive-mcp.js had already been fixed months earlier, with a comment explaining
|
|
15
|
+
// exactly why hardcoding it is dangerous — and that fix was never carried to the other three.
|
|
16
|
+
// A detector that lies is strictly worse than no detector, because it is trusted.
|
|
17
|
+
//
|
|
18
|
+
// HIV-P7 closed that by giving each of the four files its own runtime read. Which produced the
|
|
19
|
+
// next defect, and it was measured rather than predicted: with the reader duplicated four times,
|
|
20
|
+
// corrupting ONE copy's fallback string to '9.9.9-DRIFTED' left tests/version-truth-test.mjs at
|
|
21
|
+
// 16 passed, 0 failed. The property guards the version that gets REPORTED and says nothing about
|
|
22
|
+
// the mechanism that produces it, so three of four copies could rot in silence.
|
|
23
|
+
//
|
|
24
|
+
// This codebase has watched that happen before. The extension's reconcile() and the engine's were
|
|
25
|
+
// the same function once; they now share 34 lines and behave differently. Eight lines is not too
|
|
26
|
+
// small to drift — it is exactly small enough that nobody feels the need to check.
|
|
27
|
+
//
|
|
28
|
+
// So the fix is DELETION, not another assertion. One definition, imported by all four. The
|
|
29
|
+
// property becomes true by construction instead of by policing, and a fifth entry point written
|
|
30
|
+
// next year gets it right by importing rather than by remembering.
|
|
31
|
+
//
|
|
32
|
+
// TWO DECISIONS WORTH KEEPING:
|
|
33
|
+
//
|
|
34
|
+
// It READS package.json rather than being told. package.json always ships beside these files —
|
|
35
|
+
// in the repo and in the published tarball — so `new URL('./package.json', import.meta.url)`
|
|
36
|
+
// resolves in both. Anything else (a constant, a build step, a generated file) can disagree with
|
|
37
|
+
// the package the moment `npm version` runs, which is precisely the failure being fixed.
|
|
38
|
+
//
|
|
39
|
+
// IT NEVER THROWS. A version read is not worth a server that will not boot, and a server that
|
|
40
|
+
// refuses to start is a worse outcome than one that says it does not know which build it is. So
|
|
41
|
+
// an unreadable or malformed package.json yields '0.0.0-unknown' — a value that is obviously
|
|
42
|
+
// wrong to a human, will never match a real release, and cannot be mistaken for a true answer.
|
|
43
|
+
// Silence or an empty string could be read as "no mixed build here"; this cannot.
|
|
44
|
+
|
|
45
|
+
import fs from 'fs'
|
|
46
|
+
import path from 'path'
|
|
47
|
+
import { fileURLToPath } from 'url'
|
|
48
|
+
|
|
49
|
+
/** Recomputed never: a running process cannot change which build it is. */
|
|
50
|
+
export const VERSION = (() => {
|
|
51
|
+
try {
|
|
52
|
+
const v = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version
|
|
53
|
+
if (typeof v === 'string' && v) return v
|
|
54
|
+
} catch { /* fall through — see IT NEVER THROWS above */ }
|
|
55
|
+
return '0.0.0-unknown'
|
|
56
|
+
})()
|
|
57
|
+
|
|
58
|
+
/** The sentinel, exported so callers and tests can name it instead of retyping the literal. */
|
|
59
|
+
export const UNKNOWN_VERSION = '0.0.0-unknown'
|
|
60
|
+
|
|
61
|
+
// BUILD: WHICH COMMIT, not just which version (29 Sep 2026).
|
|
62
|
+
//
|
|
63
|
+
// VERSION alone could not see a mixed build. On 28-29 Sep release-gate HEAD and the published
|
|
64
|
+
// tarball both said "0.12.2" while differing by a night of fixes, and the hosted relay's /health
|
|
65
|
+
// reported no version at all -- "is the fix deployed?" was answered from its uptime. So a build
|
|
66
|
+
// carries its commit when it knows one:
|
|
67
|
+
// RENDER_GIT_COMMIT set by Render for a deployed relay (its image has no .git)
|
|
68
|
+
// a git checkout .git beside package.json: a folder, or a worktree's `gitdir:` file
|
|
69
|
+
// otherwise '' an npm install: VERSION is the whole identity, and it is the true one
|
|
70
|
+
// VERSION itself is untouched -- the update notice compares it with the registry's -- so the
|
|
71
|
+
// commit travels separately, and VERSION_LABEL is what people and agents are shown.
|
|
72
|
+
//
|
|
73
|
+
// It never walks UP. hivecode-mcp installed into someone's repo would otherwise report THAT repo's
|
|
74
|
+
// commit as its own build, which is the lie this exists to prevent. And like VERSION it never throws.
|
|
75
|
+
const HEX = /^[0-9a-f]{7,40}$/
|
|
76
|
+
export function buildOf(root, env = process.env) {
|
|
77
|
+
try {
|
|
78
|
+
const rc = String(env.RENDER_GIT_COMMIT || '').trim().toLowerCase()
|
|
79
|
+
if (HEX.test(rc)) return rc.slice(0, 7)
|
|
80
|
+
const dotGit = path.join(root, '.git')
|
|
81
|
+
let gitDir = dotGit
|
|
82
|
+
if (fs.statSync(dotGit).isFile()) { // a worktree: ".git" is a file holding "gitdir: <path>"
|
|
83
|
+
const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs.readFileSync(dotGit, 'utf8'))
|
|
84
|
+
if (!m) return ''
|
|
85
|
+
gitDir = path.resolve(root, m[1])
|
|
86
|
+
}
|
|
87
|
+
const head = fs.readFileSync(path.join(gitDir, 'HEAD'), 'utf8').trim()
|
|
88
|
+
if (/^[0-9a-f]{40}$/.test(head)) return head.slice(0, 7) // detached
|
|
89
|
+
const ref = /^ref:\s*(\S+)$/.exec(head)
|
|
90
|
+
if (!ref) return ''
|
|
91
|
+
let common = gitDir // a worktree keeps its branches in the main repo's .git
|
|
92
|
+
try { common = path.resolve(gitDir, fs.readFileSync(path.join(gitDir, 'commondir'), 'utf8').trim()) } catch { }
|
|
93
|
+
for (const d of [gitDir, common]) {
|
|
94
|
+
try { const h = fs.readFileSync(path.join(d, ref[1]), 'utf8').trim(); if (/^[0-9a-f]{40}$/.test(h)) return h.slice(0, 7) } catch { }
|
|
95
|
+
}
|
|
96
|
+
for (const line of fs.readFileSync(path.join(common, 'packed-refs'), 'utf8').split('\n')) {
|
|
97
|
+
const [h, r] = line.trim().split(/\s+/)
|
|
98
|
+
if (r === ref[1] && /^[0-9a-f]{40}$/.test(h)) return h.slice(0, 7)
|
|
99
|
+
}
|
|
100
|
+
} catch { /* no .git, unreadable, malformed: no commit to report -- see IT NEVER THROWS */ }
|
|
101
|
+
return ''
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** This build's commit, or '' when it has none to report (an npm install). */
|
|
105
|
+
export const BUILD = buildOf(fileURLToPath(new URL('.', import.meta.url)))
|
|
106
|
+
|
|
107
|
+
/** What people and agents are shown: "0.12.2+fe1d89e" from a checkout, "0.12.2" from npm. */
|
|
108
|
+
export const VERSION_LABEL = BUILD ? `${VERSION}+${BUILD}` : VERSION
|
|
109
|
+
|
|
110
|
+
export default VERSION
|