hivecode-mcp 0.12.2 → 0.13.0

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.
Files changed (62) hide show
  1. package/HIVE_RULES.md +11 -40
  2. package/LICENSE +21 -21
  3. package/README.md +421 -167
  4. package/core.js +91 -91
  5. package/docs/ALWAYS_ON.md +310 -0
  6. package/docs/GITHUB_WORKFLOW.md +334 -0
  7. package/docs/HIVE_RULES.md +41 -41
  8. package/docs/MCP.md +157 -118
  9. package/docs/QUICKSTART.md +266 -0
  10. package/docs/SELF_HOSTING.md +256 -256
  11. package/docs/SLACK_SETUP.md +450 -0
  12. package/docs/TROUBLESHOOTING.md +87 -0
  13. package/hive-activity.js +336 -310
  14. package/hive-await.js +207 -0
  15. package/hive-branch.js +686 -0
  16. package/hive-busy.js +88 -88
  17. package/hive-coord.js +110 -110
  18. package/hive-gate.js +135 -135
  19. package/hive-github.js +1904 -0
  20. package/hive-hook-install.js +179 -103
  21. package/hive-instructions.js +74 -66
  22. package/hive-listen.js +81 -0
  23. package/hive-mailbox.js +520 -386
  24. package/hive-mcp-http.js +580 -0
  25. package/hive-mcp.js +579 -137
  26. package/hive-mux-proto.js +58 -58
  27. package/hive-mux.js +350 -350
  28. package/hive-notify.js +233 -0
  29. package/hive-obligations.js +247 -247
  30. package/hive-pr-staleness.js +189 -189
  31. package/hive-pr.js +350 -0
  32. package/hive-privacy.js +327 -288
  33. package/hive-receipts.js +233 -233
  34. package/hive-relay-health.js +230 -225
  35. package/hive-room-key.js +209 -0
  36. package/hive-secrets.js +89 -0
  37. package/hive-session.js +114 -0
  38. package/hive-setup.js +558 -445
  39. package/hive-slack-agent.js +396 -0
  40. package/hive-slack.js +1809 -0
  41. package/hive-stdio.js +172 -168
  42. package/hive-stop-hook.js +293 -241
  43. package/hive-throttle.js +118 -118
  44. package/hive-time.js +71 -0
  45. package/hive-update.js +58 -58
  46. package/hive-version.js +110 -59
  47. package/hive-webhook.js +54 -0
  48. package/icr-merge.js +58 -58
  49. package/icr.js +851 -745
  50. package/lang-json.js +211 -211
  51. package/lang-ruby.js +230 -230
  52. package/lang-toml.js +136 -136
  53. package/lang-yaml.js +183 -183
  54. package/limits.js +413 -394
  55. package/package.json +189 -164
  56. package/reconcile.cjs +614 -477
  57. package/slack-app-manifest-agent.json +61 -0
  58. package/slack-app-manifest-inbound.json +36 -0
  59. package/slack-app-manifest.json +27 -0
  60. package/substrate.js +252 -252
  61. package/sync.js +1956 -177
  62. package/grm-link.cjs +0 -141
package/hive-gate.js CHANGED
@@ -1,135 +1,135 @@
1
- // hive-gate — a handoff that cannot complete while your own check is failing.
2
- //
3
- // THE PROBLEM THIS EXISTS FOR. Claims stop two agents writing the same file. They say nothing
4
- // about whether what you wrote is CORRECT, so the honest description of the room until now was:
5
- // agent A writes something wrong, releases it, agent B picks it up and builds on it, and the lock
6
- // made the corruption orderly rather than absent. Ganesh put it exactly right -- "one agent makes
7
- // a mistake and writes wrong code, others build upon it and it gets worse".
8
- //
9
- // The answer is the same move that solved collisions, applied one layer up. Collisions were not
10
- // solved by asking agents to coordinate; the transport refuses the second write. Correctness is
11
- // not solved by asking agents to check each other's work either. The transport refuses the
12
- // HANDOFF: release runs the room's check, and a failing check means the claim stays yours.
13
- //
14
- // WHAT THIS HONESTLY DOES AND DOES NOT DO. It does not stop the bad content existing in other
15
- // folders -- the CRDT syncs continuously, so the bytes are already everywhere the moment they are
16
- // written, and nothing short of abandoning live sync changes that. What it stops is the SILENT
17
- // HANDOFF: "I am done, it is yours." The file stays visibly held, by a named agent, with a
18
- // recorded reason. Anyone who reaches for it is told who is holding it and that their check
19
- // failed, rather than quietly inheriting a broken file that looked finished.
20
- //
21
- // AND THE RULE THAT SHAPES THE WHOLE DESIGN. @Claude-Engine caught a real bug in the path-state
22
- // registry: `path:engine/brain/llm.js = POISONED` was FALSE in its folder, where that path held
23
- // the correct file while another folder held a wreck. Marking it globally broadcast ONE FOLDER'S
24
- // REALITY as room truth. A gate result is exactly that kind of fact -- I ran the tests in MY
25
- // folder, on MY copy -- so it is recorded PER AGENT, keyed by name the way hive_attest is, and it
26
- // never sets a global path flag. Two agents disagreeing about whether a file passes stays visible
27
- // as a disagreement instead of converging on whoever wrote last.
28
-
29
- import { spawnSync } from 'child_process'
30
-
31
- export const GATE_CMD = 'gate:cmd' // the room's check, in shared state
32
- export const GATE_TIMEOUT = 'gate:timeout' // ms; a hung test suite must not wedge the room
33
- export const DEFAULT_TIMEOUT_MS = 120000
34
- export const MAX_OUTPUT = 4000 // what we keep of the output, for the record
35
-
36
- /**
37
- * The room's gate, read from shared state. `get` is any (key) => value — the swarm_state map, or
38
- * a plain object in tests.
39
- *
40
- * Returns null when no gate is configured, which means release behaves exactly as it always has.
41
- * That is deliberate: a room that has not opted in is not silently given a new failure mode.
42
- */
43
- export function gateConfig(get) {
44
- const read = typeof get === 'function' ? get : (k) => get[k]
45
- const cmd = read(GATE_CMD)
46
- if (cmd == null || String(cmd).trim() === '') return null
47
- const raw = Number(read(GATE_TIMEOUT))
48
- const timeoutMs = Number.isFinite(raw) && raw > 0 ? Math.min(raw, 600000) : DEFAULT_TIMEOUT_MS
49
- return { cmd: String(cmd), timeoutMs }
50
- }
51
-
52
- /** Trim command output to something that belongs in a CRDT, keeping the END — that is where a
53
- * test runner puts the failures. Keeping the head would record the banner and drop the reason. */
54
- export function trimOutput(s, max = MAX_OUTPUT) {
55
- const t = String(s == null ? '' : s).replace(/\r\n/g, '\n').trim()
56
- if (t.length <= max) return t
57
- return '…(' + (t.length - max) + ' chars trimmed)\n' + t.slice(-max)
58
- }
59
-
60
- /**
61
- * Run the check in a folder. Exit code 0 is a pass; anything else, including the command not
62
- * existing, is a fail.
63
- *
64
- * A command that cannot be RUN is a failure and not a pass. Treating "spawn failed" as success
65
- * would mean a typo in the gate silently disables it for the whole room, which is the worst
66
- * outcome available here: everyone would believe they were gated and nobody would be.
67
- */
68
- export function runGate({ cmd, cwd, timeoutMs = DEFAULT_TIMEOUT_MS, run = spawnSync, env = {} }) {
69
- const started = Date.now()
70
- let r
71
- // Isolated test port per gate run so concurrent gates on the same machine never collide over fixed ports (HIV-24).
72
- const isolatedPort = Number(process.env.HIVE_TEST_PORT) || (20000 + (process.pid % 10000) + Math.floor(Math.random() * 10000))
73
- const gateEnv = {
74
- ...process.env,
75
- HIVE_TEST_PORT: String(isolatedPort),
76
- ...env,
77
- }
78
- try {
79
- r = run(cmd, {
80
- cwd, shell: true, encoding: 'utf8', timeout: timeoutMs,
81
- maxBuffer: 8 * 1024 * 1024, windowsHide: true,
82
- env: gateEnv,
83
- })
84
- } catch (e) {
85
- return { ok: false, code: null, timedOut: false, ms: Date.now() - started, out: trimOutput('could not run the gate: ' + e.message) }
86
- }
87
- const timedOut = r.error && (r.error.code === 'ETIMEDOUT' || /timed? ?out/i.test(r.error.message || ''))
88
- const out = trimOutput([r.stdout, r.stderr].filter(Boolean).join('\n') || (r.error ? r.error.message : ''))
89
- return {
90
- ok: !r.error && r.status === 0,
91
- code: r.status == null ? null : r.status,
92
- timedOut: !!timedOut,
93
- ms: Date.now() - started,
94
- out,
95
- }
96
- }
97
-
98
- /** The record stored under this agent's name. Timestamps are unix MICROseconds, per project rule. */
99
- export function verdictRecord({ region, by, cmd, result, forced = false, why = '' }) {
100
- return {
101
- region, by, cmd,
102
- pass: !!(result && result.ok),
103
- exit: result ? result.code : null,
104
- timedOut: !!(result && result.timedOut),
105
- ms: result ? result.ms : 0,
106
- out: result ? result.out : '',
107
- forced: !!forced,
108
- why: String(why || ''),
109
- at: Date.now() * 1000,
110
- }
111
- }
112
-
113
- /**
114
- * What the releasing agent is told. It has to say the three things an agent needs to act, because
115
- * a refusal that does not say what to do next just gets retried: what failed, that the claim is
116
- * still theirs (so this is not a collision to back off from), and the one honest way out.
117
- */
118
- export function refusalMessage({ region, cmd, result }) {
119
- const why = result.timedOut
120
- ? `Q491 the gate timed out after ${Math.round(result.ms / 1000)}s`
121
- : result.code == null
122
- ? 'Q490 the gate could not be run'
123
- : `Q490 the gate failed (exit ${result.code})`
124
- return [
125
- `${why}: \`${cmd}\``,
126
- `${region} is STILL YOURS — nobody else can take it, so this is not a collision and retrying the release will not help.`,
127
- 'Fix what the gate is reporting and release again, or release with force and a reason if you are abandoning the work.',
128
- result.out ? '\n' + result.out : '',
129
- ].join('\n')
130
- }
131
-
132
- /** A forced release is legitimate — abandoning work is real — but it is never silent. */
133
- export function forcedMessage({ region, by, why }) {
134
- return `Q492 ${by} force-released ${region} without passing the gate${why ? `: ${why}` : ' (no reason given)'}`
135
- }
1
+ // hive-gate — a handoff that cannot complete while your own check is failing.
2
+ //
3
+ // THE PROBLEM THIS EXISTS FOR. Claims stop two agents writing the same file. They say nothing
4
+ // about whether what you wrote is CORRECT, so the honest description of the room until now was:
5
+ // agent A writes something wrong, releases it, agent B picks it up and builds on it, and the lock
6
+ // made the corruption orderly rather than absent. Ganesh put it exactly right -- "one agent makes
7
+ // a mistake and writes wrong code, others build upon it and it gets worse".
8
+ //
9
+ // The answer is the same move that solved collisions, applied one layer up. Collisions were not
10
+ // solved by asking agents to coordinate; the transport refuses the second write. Correctness is
11
+ // not solved by asking agents to check each other's work either. The transport refuses the
12
+ // HANDOFF: release runs the room's check, and a failing check means the claim stays yours.
13
+ //
14
+ // WHAT THIS HONESTLY DOES AND DOES NOT DO. It does not stop the bad content existing in other
15
+ // folders -- the CRDT syncs continuously, so the bytes are already everywhere the moment they are
16
+ // written, and nothing short of abandoning live sync changes that. What it stops is the SILENT
17
+ // HANDOFF: "I am done, it is yours." The file stays visibly held, by a named agent, with a
18
+ // recorded reason. Anyone who reaches for it is told who is holding it and that their check
19
+ // failed, rather than quietly inheriting a broken file that looked finished.
20
+ //
21
+ // AND THE RULE THAT SHAPES THE WHOLE DESIGN. @Claude-Engine caught a real bug in the path-state
22
+ // registry: `path:engine/brain/llm.js = POISONED` was FALSE in its folder, where that path held
23
+ // the correct file while another folder held a wreck. Marking it globally broadcast ONE FOLDER'S
24
+ // REALITY as room truth. A gate result is exactly that kind of fact -- I ran the tests in MY
25
+ // folder, on MY copy -- so it is recorded PER AGENT, keyed by name the way hive_attest is, and it
26
+ // never sets a global path flag. Two agents disagreeing about whether a file passes stays visible
27
+ // as a disagreement instead of converging on whoever wrote last.
28
+
29
+ import { spawnSync } from 'child_process'
30
+
31
+ export const GATE_CMD = 'gate:cmd' // the room's check, in shared state
32
+ export const GATE_TIMEOUT = 'gate:timeout' // ms; a hung test suite must not wedge the room
33
+ export const DEFAULT_TIMEOUT_MS = 120000
34
+ export const MAX_OUTPUT = 4000 // what we keep of the output, for the record
35
+
36
+ /**
37
+ * The room's gate, read from shared state. `get` is any (key) => value — the swarm_state map, or
38
+ * a plain object in tests.
39
+ *
40
+ * Returns null when no gate is configured, which means release behaves exactly as it always has.
41
+ * That is deliberate: a room that has not opted in is not silently given a new failure mode.
42
+ */
43
+ export function gateConfig(get) {
44
+ const read = typeof get === 'function' ? get : (k) => get[k]
45
+ const cmd = read(GATE_CMD)
46
+ if (cmd == null || String(cmd).trim() === '') return null
47
+ const raw = Number(read(GATE_TIMEOUT))
48
+ const timeoutMs = Number.isFinite(raw) && raw > 0 ? Math.min(raw, 600000) : DEFAULT_TIMEOUT_MS
49
+ return { cmd: String(cmd), timeoutMs }
50
+ }
51
+
52
+ /** Trim command output to something that belongs in a CRDT, keeping the END — that is where a
53
+ * test runner puts the failures. Keeping the head would record the banner and drop the reason. */
54
+ export function trimOutput(s, max = MAX_OUTPUT) {
55
+ const t = String(s == null ? '' : s).replace(/\r\n/g, '\n').trim()
56
+ if (t.length <= max) return t
57
+ return '…(' + (t.length - max) + ' chars trimmed)\n' + t.slice(-max)
58
+ }
59
+
60
+ /**
61
+ * Run the check in a folder. Exit code 0 is a pass; anything else, including the command not
62
+ * existing, is a fail.
63
+ *
64
+ * A command that cannot be RUN is a failure and not a pass. Treating "spawn failed" as success
65
+ * would mean a typo in the gate silently disables it for the whole room, which is the worst
66
+ * outcome available here: everyone would believe they were gated and nobody would be.
67
+ */
68
+ export function runGate({ cmd, cwd, timeoutMs = DEFAULT_TIMEOUT_MS, run = spawnSync, env = {} }) {
69
+ const started = Date.now()
70
+ let r
71
+ // Isolated test port per gate run so concurrent gates on the same machine never collide over fixed ports (HIV-24).
72
+ const isolatedPort = Number(process.env.HIVE_TEST_PORT) || (20000 + (process.pid % 10000) + Math.floor(Math.random() * 10000))
73
+ const gateEnv = {
74
+ ...process.env,
75
+ HIVE_TEST_PORT: String(isolatedPort),
76
+ ...env,
77
+ }
78
+ try {
79
+ r = run(cmd, {
80
+ cwd, shell: true, encoding: 'utf8', timeout: timeoutMs,
81
+ maxBuffer: 8 * 1024 * 1024, windowsHide: true,
82
+ env: gateEnv,
83
+ })
84
+ } catch (e) {
85
+ return { ok: false, code: null, timedOut: false, ms: Date.now() - started, out: trimOutput('could not run the gate: ' + e.message) }
86
+ }
87
+ const timedOut = r.error && (r.error.code === 'ETIMEDOUT' || /timed? ?out/i.test(r.error.message || ''))
88
+ const out = trimOutput([r.stdout, r.stderr].filter(Boolean).join('\n') || (r.error ? r.error.message : ''))
89
+ return {
90
+ ok: !r.error && r.status === 0,
91
+ code: r.status == null ? null : r.status,
92
+ timedOut: !!timedOut,
93
+ ms: Date.now() - started,
94
+ out,
95
+ }
96
+ }
97
+
98
+ /** The record stored under this agent's name. Timestamps are unix MICROseconds, per project rule. */
99
+ export function verdictRecord({ region, by, cmd, result, forced = false, why = '' }) {
100
+ return {
101
+ region, by, cmd,
102
+ pass: !!(result && result.ok),
103
+ exit: result ? result.code : null,
104
+ timedOut: !!(result && result.timedOut),
105
+ ms: result ? result.ms : 0,
106
+ out: result ? result.out : '',
107
+ forced: !!forced,
108
+ why: String(why || ''),
109
+ at: Date.now() * 1000,
110
+ }
111
+ }
112
+
113
+ /**
114
+ * What the releasing agent is told. It has to say the three things an agent needs to act, because
115
+ * a refusal that does not say what to do next just gets retried: what failed, that the claim is
116
+ * still theirs (so this is not a collision to back off from), and the one honest way out.
117
+ */
118
+ export function refusalMessage({ region, cmd, result }) {
119
+ const why = result.timedOut
120
+ ? `Q491 the gate timed out after ${Math.round(result.ms / 1000)}s`
121
+ : result.code == null
122
+ ? 'Q490 the gate could not be run'
123
+ : `Q490 the gate failed (exit ${result.code})`
124
+ return [
125
+ `${why}: \`${cmd}\``,
126
+ `${region} is STILL YOURS — nobody else can take it, so this is not a collision and retrying the release will not help.`,
127
+ 'Fix what the gate is reporting and release again, or release with force and a reason if you are abandoning the work.',
128
+ result.out ? '\n' + result.out : '',
129
+ ].join('\n')
130
+ }
131
+
132
+ /** A forced release is legitimate — abandoning work is real — but it is never silent. */
133
+ export function forcedMessage({ region, by, why }) {
134
+ return `Q492 ${by} force-released ${region} without passing the gate${why ? `: ${why}` : ' (no reason given)'}`
135
+ }