hivemind-memory 2.31.0 → 2.31.2
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 +55 -37
- package/dist/client.d.ts +25 -12
- package/dist/client.js +74 -49
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +19 -0
- package/dist/formats.d.ts +4 -1
- package/dist/formats.js +1 -1
- package/dist/types.d.ts +237 -0
- package/package.json +17 -1
- package/text/skill.md +7 -25
package/README.md
CHANGED
|
@@ -21,9 +21,11 @@ await using hive = await Hivemind.connect();
|
|
|
21
21
|
console.log(hive.whoami);
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
`await using` closes the connection at the end of the block. It needs TypeScript 5.2 or later to compile it, or Node 24; in plain JavaScript on Node 22, call `await hive.close()` in a `finally` block instead.
|
|
25
|
+
|
|
24
26
|
`connect()` reads `HIVEMIND_MCP_URL` (the `/mcp` endpoint) and `HIVEMIND_API_KEY`. You can pass `{ url, apiKey }` instead, and an option wins over the variable. If neither is set, it throws an error that names the variable. `connect()` calls `hive_whoami` and keeps the reply as `hive.whoami`; `await hive.refreshWhoami()` asks again. Without `await using`, call `await hive.close()` when you are done.
|
|
25
27
|
|
|
26
|
-
Each tool has a method: `search`, `get`, `list`, `pinned`, `write`, `feedback`, `withdraw`, `pin`, `register`. Option keys are snake_case, exactly as the tool takes them, and only the values you set are sent.
|
|
28
|
+
Each tool has a method: `search`, `get`, `list`, `pinned`, `write`, `feedback`, `withdraw`, `pin`, `register`. Option keys are snake_case, exactly as the tool takes them, and only the values you set are sent. Each returns the reply typed (`SearchReply`, `EntryDetail`, `WriteReply` and so on, exported from the package), so `written.id` and `found.hits` need no casts. `get` and `feedback` return the batch shape (`Entries`, `BatchFeedbackReply`) for a list of ids, and `write` with `check: true` returns `CheckReply`. A newer server may add keys the types do not list yet. What each option means and what comes back is in the tool descriptions, `hive.tools`, which are also what the model reads; the [spec](https://github.com/monochrome-muncher/hivemind/blob/main/SPEC.md#52-mcp-tools-the-agents-mental-model--ten-verbs) has the same in one place.
|
|
27
29
|
|
|
28
30
|
```ts
|
|
29
31
|
const written = await hive.write("fact", "The staging DB is reset every Monday", { scope: "fleet" });
|
|
@@ -32,65 +34,72 @@ const found = await hive.search("when is staging reset?", { limit: 5 });
|
|
|
32
34
|
|
|
33
35
|
## A loop with the Anthropic Messages API
|
|
34
36
|
|
|
37
|
+
`instructions()` is the system prompt, `anthropicTools()` the tool list, and `runTool()` runs what the model asked for. When the model stops calling tools, the loop sends the end-of-task reminder once and lets the model answer it.
|
|
38
|
+
|
|
35
39
|
```ts
|
|
36
40
|
import Anthropic from "@anthropic-ai/sdk";
|
|
37
41
|
import { Hivemind } from "hivemind-memory";
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const messages: Anthropic.MessageParam[] = [{ role: "user", content: task }];
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
43
|
+
async function run(task: string): Promise<void> {
|
|
44
|
+
const anthropic = new Anthropic();
|
|
45
|
+
await using hive = await Hivemind.connect();
|
|
46
|
+
const messages: Anthropic.MessageParam[] = [{ role: "user", content: task }];
|
|
47
|
+
let reminded = false;
|
|
48
|
+
while (true) {
|
|
49
|
+
const response = await anthropic.messages.create({
|
|
50
|
+
model: "claude-sonnet-5-5",
|
|
51
|
+
max_tokens: 4096,
|
|
52
|
+
system: hive.instructions(),
|
|
53
|
+
tools: hive.anthropicTools(),
|
|
54
|
+
messages,
|
|
55
|
+
});
|
|
56
|
+
messages.push({ role: "assistant", content: response.content });
|
|
57
|
+
const calls = response.content.filter((b) => b.type === "tool_use");
|
|
58
|
+
if (calls.length === 0) {
|
|
59
|
+
if (reminded) return;
|
|
60
|
+
messages.push({ role: "user", content: hive.reminder() });
|
|
61
|
+
reminded = true;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const results: Anthropic.ToolResultBlockParam[] = [];
|
|
65
|
+
for (const call of calls) {
|
|
66
|
+
results.push({ type: "tool_result", tool_use_id: call.id, content: await hive.runTool(call.name, call.input as object) });
|
|
67
|
+
}
|
|
68
|
+
messages.push({ role: "user", content: results });
|
|
69
|
+
}
|
|
64
70
|
}
|
|
71
|
+
|
|
72
|
+
await run("Find out when the staging database is reset.");
|
|
65
73
|
```
|
|
66
74
|
|
|
67
75
|
`runTool` returns the reply as JSON text and never throws on an error reply, so the model sees the refusal and can react. `openaiTools()` gives the same tools in the OpenAI function-calling shape. Neither needs the Anthropic or OpenAI package.
|
|
68
76
|
|
|
69
77
|
## The end-of-task reminder
|
|
70
78
|
|
|
71
|
-
When a task ends, send `hive.reminder()` once as a user turn and let the agent answer. It asks the agent to write what others could reuse and to rate the entries its work tested. The same text is exported as `REMINDER`.
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
messages.push({ role: "user", content: hive.reminder() });
|
|
75
|
-
```
|
|
79
|
+
When a task ends, send `hive.reminder()` once as a user turn and let the agent answer, as the loop above does. It asks the agent to write what others could reuse and to rate the entries its work tested. The same text is exported as `REMINDER`.
|
|
76
80
|
|
|
77
81
|
## Vercel AI SDK
|
|
78
82
|
|
|
79
|
-
`hivemind-memory/ai-sdk` returns the tools as AI SDK tools. `ai` is an optional peer dependency, so install it yourself (version 7 or later).
|
|
83
|
+
`hivemind-memory/ai-sdk` returns the tools as AI SDK tools. `ai` is an optional peer dependency, so install it yourself (version 7 or later), with the provider package for your model.
|
|
80
84
|
|
|
81
85
|
```ts
|
|
82
|
-
import {
|
|
86
|
+
import { anthropic } from "@ai-sdk/anthropic";
|
|
87
|
+
import { generateText, stepCountIs } from "ai";
|
|
88
|
+
import { Hivemind } from "hivemind-memory";
|
|
83
89
|
import { aiSdkTools, systemPrompt } from "hivemind-memory/ai-sdk";
|
|
84
90
|
|
|
91
|
+
await using hive = await Hivemind.connect();
|
|
85
92
|
const { text } = await generateText({
|
|
86
|
-
model,
|
|
93
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
87
94
|
tools: aiSdkTools(hive),
|
|
88
95
|
system: systemPrompt(hive),
|
|
89
|
-
prompt:
|
|
96
|
+
prompt: "Find out when the staging database is reset.",
|
|
97
|
+
stopWhen: stepCountIs(20),
|
|
90
98
|
});
|
|
99
|
+
console.log(text);
|
|
91
100
|
```
|
|
92
101
|
|
|
93
|
-
Errors reach the model as text, as with `runTool`.
|
|
102
|
+
Set `stopWhen`: by default `generateText` stops after one step, so the model would call a tool and never see the result. Errors reach the model as text, as with `runTool`. For the end-of-task reminder, run `generateText` once more with the returned `response.messages` and `hive.reminder()` as the next user message.
|
|
94
103
|
|
|
95
104
|
## Other frameworks
|
|
96
105
|
|
|
@@ -102,7 +111,7 @@ A key belongs to one agent, and one `Hivemind` object uses one key. To act as an
|
|
|
102
111
|
|
|
103
112
|
## Errors
|
|
104
113
|
|
|
105
|
-
A refusal from the server throws `HivemindError`, with the server's code in `.code` (`not_found`, `permission_denied`, `invalid_input`, and so on). A rejected or locked key throws `AuthenticationError`, a subclass, from `connect()`
|
|
114
|
+
A refusal from the server throws `HivemindError`, with the server's code in `.code` (`not_found`, `permission_denied`, `invalid_input`, and so on). A rejected or locked key throws `AuthenticationError`, a subclass, with the code `unauthenticated` or `key_locked` and the server's message, from `connect()` or any later call. A failed call that carries no code becomes `tool_error`. Network and protocol failures are ordinary errors from the MCP SDK.
|
|
106
115
|
|
|
107
116
|
```ts
|
|
108
117
|
import { HivemindError } from "hivemind-memory";
|
|
@@ -115,3 +124,12 @@ try {
|
|
|
115
124
|
}
|
|
116
125
|
}
|
|
117
126
|
```
|
|
127
|
+
|
|
128
|
+
## Development
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
npm ci
|
|
132
|
+
npm test
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`npm test` builds the package and runs the unit tests against a fake MCP server. `test/live.test.ts` runs against a real server when `HIVEMIND_LIVE=1`, `HIVEMIND_MCP_URL` and `HIVEMIND_API_KEY` are set. The skill and reminder under `text/` are copies of the plugin's files; do not edit them here.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,36 +1,49 @@
|
|
|
1
1
|
import { type AnthropicTool, type OpenAITool, type ToolDefinition } from "./formats.js";
|
|
2
|
-
import type { FeedbackOptions, GetOptions, ListOptions, PinOptions, PinnedOptions, RegisterOptions, Reply, SearchOptions, Verdict, WriteOptions,
|
|
2
|
+
import type { BatchFeedbackReply, CheckReply, Entries, Entry, EntryDetail, EntryKind, FeedbackOptions, FeedbackReply, GetOptions, ListOptions, ListReply, PinOptions, PinReply, PinnedOptions, PinnedReply, RegisterOptions, RegisterReply, Reply, SearchOptions, SearchReply, Verdict, WhoAmI, WriteOptions, WriteReply } from "./types.js";
|
|
3
3
|
export interface ConnectOptions {
|
|
4
4
|
url?: string;
|
|
5
5
|
apiKey?: string;
|
|
6
6
|
}
|
|
7
7
|
export declare class Hivemind implements AsyncDisposable {
|
|
8
8
|
private readonly client;
|
|
9
|
+
private readonly rejection;
|
|
9
10
|
readonly tools: readonly ToolDefinition[];
|
|
10
11
|
private serverInstructions;
|
|
11
12
|
private current;
|
|
12
13
|
private constructor();
|
|
13
14
|
/** The key's standing from the last hive_whoami. */
|
|
14
|
-
get whoami():
|
|
15
|
+
get whoami(): WhoAmI;
|
|
15
16
|
static connect(options?: ConnectOptions): Promise<Hivemind>;
|
|
16
17
|
close(): Promise<void>;
|
|
17
18
|
[Symbol.asyncDispose](): Promise<void>;
|
|
19
|
+
/** The reply text; a failed call that is not already the error envelope is wrapped in one. */
|
|
18
20
|
private callText;
|
|
19
21
|
call(name: string, args?: Record<string, unknown>): Promise<Reply>;
|
|
20
22
|
/** For model loops: the reply JSON text, and an error envelope as text rather than a throw. */
|
|
21
23
|
runTool(name: string, args?: object | string): Promise<string>;
|
|
22
|
-
refreshWhoami(): Promise<
|
|
23
|
-
|
|
24
|
+
refreshWhoami(): Promise<WhoAmI>;
|
|
25
|
+
private typed;
|
|
26
|
+
search(query: string, options?: SearchOptions): Promise<SearchReply>;
|
|
24
27
|
/** One entry by id, or up to 10 at once when given a list of ids. */
|
|
25
|
-
get(entryId: string
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
get(entryId: string, options?: GetOptions): Promise<EntryDetail>;
|
|
29
|
+
get(entryIds: string[]): Promise<Entries>;
|
|
30
|
+
list(options?: ListOptions): Promise<ListReply>;
|
|
31
|
+
pinned(options?: PinnedOptions): Promise<PinnedReply>;
|
|
32
|
+
/** Writes an entry; with `check: true` it stores nothing and reports what a write would. */
|
|
33
|
+
write(kind: EntryKind, summary: string, options: WriteOptions & {
|
|
34
|
+
check: true;
|
|
35
|
+
}): Promise<CheckReply>;
|
|
36
|
+
write(kind: EntryKind, summary: string, options?: WriteOptions & {
|
|
37
|
+
check?: false;
|
|
38
|
+
}): Promise<WriteReply>;
|
|
39
|
+
write(kind: EntryKind, summary: string, options?: WriteOptions): Promise<WriteReply | CheckReply>;
|
|
29
40
|
/** One verdict for an entry, or for up to 16 entries when given a list of ids. */
|
|
30
|
-
feedback(entryId: string
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
feedback(entryId: string, verdict: Verdict, options?: FeedbackOptions): Promise<FeedbackReply>;
|
|
42
|
+
feedback(entryIds: string[], verdict: Verdict, options?: FeedbackOptions): Promise<BatchFeedbackReply>;
|
|
43
|
+
/** Retracts an entry without replacing it; the reply is the withdrawn entry. */
|
|
44
|
+
withdraw(entryId: string, reason?: string): Promise<Entry>;
|
|
45
|
+
pin(entryId: string, options?: PinOptions): Promise<PinReply>;
|
|
46
|
+
register(name: string, options?: RegisterOptions): Promise<RegisterReply>;
|
|
34
47
|
/** The server's instructions, then the hivemind skill: the system-prompt text for an agent. */
|
|
35
48
|
instructions(): string;
|
|
36
49
|
reminder(): string;
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
-
import {
|
|
3
|
+
import { HivemindError, refusal, rejectedKey } from "./errors.js";
|
|
4
4
|
import { toAnthropic, toOpenAI } from "./formats.js";
|
|
5
5
|
import { REMINDER, VERSION, skillBody } from "./text.js";
|
|
6
6
|
function setting(value, variable) {
|
|
@@ -16,16 +16,42 @@ function defined(args) {
|
|
|
16
16
|
function errorText(code, message) {
|
|
17
17
|
return JSON.stringify({ error: { code, message } });
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
19
|
+
function parsed(text) {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(text);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Keeps why the server answered 401: the MCP SDK reports only the status. */
|
|
28
|
+
class Rejection {
|
|
29
|
+
seen;
|
|
30
|
+
fetch = async (url, init) => {
|
|
31
|
+
const response = await fetch(url, init);
|
|
32
|
+
if (response.status === 401) {
|
|
33
|
+
this.seen = rejectedKey(response.clone());
|
|
34
|
+
}
|
|
35
|
+
return response;
|
|
36
|
+
};
|
|
37
|
+
async throwIfSeen() {
|
|
38
|
+
if (this.seen) {
|
|
39
|
+
throw await this.seen;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
forget() {
|
|
43
|
+
this.seen = undefined;
|
|
44
|
+
}
|
|
21
45
|
}
|
|
22
46
|
export class Hivemind {
|
|
23
47
|
client;
|
|
48
|
+
rejection;
|
|
24
49
|
tools;
|
|
25
50
|
serverInstructions;
|
|
26
51
|
current;
|
|
27
|
-
constructor(client, tools, serverInstructions, current) {
|
|
52
|
+
constructor(client, rejection, tools, serverInstructions, current) {
|
|
28
53
|
this.client = client;
|
|
54
|
+
this.rejection = rejection;
|
|
29
55
|
this.tools = tools;
|
|
30
56
|
this.serverInstructions = serverInstructions;
|
|
31
57
|
this.current = current;
|
|
@@ -38,8 +64,10 @@ export class Hivemind {
|
|
|
38
64
|
const url = setting(options.url, "HIVEMIND_MCP_URL");
|
|
39
65
|
const apiKey = setting(options.apiKey, "HIVEMIND_API_KEY");
|
|
40
66
|
const client = new Client({ name: "hivemind-memory", version: VERSION });
|
|
67
|
+
const rejection = new Rejection();
|
|
41
68
|
const transport = new StreamableHTTPClientTransport(new URL(url), {
|
|
42
69
|
requestInit: { headers: { Authorization: `Bearer ${apiKey}` } },
|
|
70
|
+
fetch: rejection.fetch,
|
|
43
71
|
});
|
|
44
72
|
try {
|
|
45
73
|
await client.connect(transport);
|
|
@@ -49,15 +77,13 @@ export class Hivemind {
|
|
|
49
77
|
description: t.description ?? "",
|
|
50
78
|
inputSchema: t.inputSchema,
|
|
51
79
|
}));
|
|
52
|
-
const hive = new Hivemind(client, tools, client.getInstructions() ?? "", {});
|
|
80
|
+
const hive = new Hivemind(client, rejection, tools, client.getInstructions() ?? "", {});
|
|
53
81
|
await hive.refreshWhoami();
|
|
54
82
|
return hive;
|
|
55
83
|
}
|
|
56
84
|
catch (error) {
|
|
57
85
|
await client.close().catch(() => undefined);
|
|
58
|
-
|
|
59
|
-
throw new AuthenticationError("unauthenticated", "the server rejected the API key (HTTP 401)");
|
|
60
|
-
}
|
|
86
|
+
await rejection.throwIfSeen();
|
|
61
87
|
throw error;
|
|
62
88
|
}
|
|
63
89
|
}
|
|
@@ -67,89 +93,88 @@ export class Hivemind {
|
|
|
67
93
|
async [Symbol.asyncDispose]() {
|
|
68
94
|
await this.close();
|
|
69
95
|
}
|
|
96
|
+
/** The reply text; a failed call that is not already the error envelope is wrapped in one. */
|
|
70
97
|
async callText(name, args) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
98
|
+
let result;
|
|
99
|
+
try {
|
|
100
|
+
result = await this.client.callTool({ name, arguments: args });
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
await this.rejection.throwIfSeen();
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
this.rejection.forget();
|
|
107
|
+
const blocks = (result.content ?? []);
|
|
108
|
+
const text = blocks.map((b) => (b.type === "text" ? (b.text ?? "") : "")).join("");
|
|
109
|
+
if (result.isError && !refusal(parsed(text))) {
|
|
110
|
+
return errorText("tool_error", text || `${name} failed`);
|
|
82
111
|
}
|
|
83
112
|
return text;
|
|
84
113
|
}
|
|
85
114
|
async call(name, args = {}) {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
throw new HivemindError("invalid_reply", `${name} answered with text that is not JSON`);
|
|
115
|
+
const reply = parsed(await this.callText(name, args));
|
|
116
|
+
const error = refusal(reply);
|
|
117
|
+
if (error) {
|
|
118
|
+
throw error;
|
|
93
119
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
throw errorFromEnvelope(envelope.code ?? "tool_error", envelope.message ?? "");
|
|
120
|
+
if (typeof reply !== "object" || reply === null || Array.isArray(reply)) {
|
|
121
|
+
throw new HivemindError("invalid_reply", `${name} did not answer with a JSON object`);
|
|
97
122
|
}
|
|
98
|
-
return
|
|
123
|
+
return reply;
|
|
99
124
|
}
|
|
100
125
|
/** For model loops: the reply JSON text, and an error envelope as text rather than a throw. */
|
|
101
126
|
async runTool(name, args = {}) {
|
|
102
127
|
if (!this.tools.some((t) => t.name === name)) {
|
|
103
128
|
return errorText("invalid_input", `unknown tool ${name}`);
|
|
104
129
|
}
|
|
105
|
-
let
|
|
130
|
+
let input = args;
|
|
106
131
|
if (typeof args === "string") {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
132
|
+
input = args.trim() === "" ? {} : parsed(args);
|
|
133
|
+
if (input === undefined) {
|
|
111
134
|
return errorText("invalid_input", `arguments for ${name} are not valid JSON`);
|
|
112
135
|
}
|
|
113
136
|
}
|
|
114
|
-
if (typeof
|
|
137
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
115
138
|
return errorText("invalid_input", `arguments for ${name} must be a JSON object`);
|
|
116
139
|
}
|
|
117
|
-
return this.callText(name,
|
|
140
|
+
return this.callText(name, input);
|
|
118
141
|
}
|
|
119
142
|
async refreshWhoami() {
|
|
120
|
-
this.current = await this.call("hive_whoami", {});
|
|
143
|
+
this.current = (await this.call("hive_whoami", {}));
|
|
121
144
|
return this.current;
|
|
122
145
|
}
|
|
146
|
+
typed(name, args) {
|
|
147
|
+
return this.call(name, defined(args));
|
|
148
|
+
}
|
|
123
149
|
search(query, options = {}) {
|
|
124
|
-
return this.
|
|
150
|
+
return this.typed("hive_search", { query, ...options });
|
|
125
151
|
}
|
|
126
|
-
/** One entry by id, or up to 10 at once when given a list of ids. */
|
|
127
152
|
get(entryId, options = {}) {
|
|
128
153
|
const target = typeof entryId === "string" ? { entry_id: entryId } : { entry_ids: entryId };
|
|
129
|
-
return this.
|
|
154
|
+
return this.typed("hive_get", { ...target, ...options });
|
|
130
155
|
}
|
|
131
156
|
list(options = {}) {
|
|
132
|
-
return this.
|
|
157
|
+
return this.typed("hive_list", { ...options });
|
|
133
158
|
}
|
|
134
159
|
pinned(options = {}) {
|
|
135
|
-
return this.
|
|
160
|
+
return this.typed("hive_pinned", { ...options });
|
|
136
161
|
}
|
|
137
162
|
write(kind, summary, options = {}) {
|
|
138
|
-
return this.
|
|
163
|
+
return this.typed("hive_write", { kind, summary, ...options });
|
|
139
164
|
}
|
|
140
|
-
/** One verdict for an entry, or for up to 16 entries when given a list of ids. */
|
|
141
165
|
feedback(entryId, verdict, options = {}) {
|
|
142
166
|
const target = typeof entryId === "string" ? { entry_id: entryId } : { entry_ids: entryId };
|
|
143
|
-
return this.
|
|
167
|
+
return this.typed("hive_feedback", { ...target, verdict, ...options });
|
|
144
168
|
}
|
|
169
|
+
/** Retracts an entry without replacing it; the reply is the withdrawn entry. */
|
|
145
170
|
withdraw(entryId, reason) {
|
|
146
|
-
return this.
|
|
171
|
+
return this.typed("hive_withdraw", { entry_id: entryId, reason });
|
|
147
172
|
}
|
|
148
173
|
pin(entryId, options = {}) {
|
|
149
|
-
return this.
|
|
174
|
+
return this.typed("hive_pin", { entry_id: entryId, ...options });
|
|
150
175
|
}
|
|
151
176
|
register(name, options = {}) {
|
|
152
|
-
return this.
|
|
177
|
+
return this.typed("hive_register", { name, ...options });
|
|
153
178
|
}
|
|
154
179
|
/** The server's instructions, then the hivemind skill: the system-prompt text for an agent. */
|
|
155
180
|
instructions() {
|
package/dist/errors.d.ts
CHANGED
|
@@ -6,3 +6,7 @@ export declare class HivemindError extends Error {
|
|
|
6
6
|
export declare class AuthenticationError extends HivemindError {
|
|
7
7
|
}
|
|
8
8
|
export declare function errorFromEnvelope(code: string, message: string): HivemindError;
|
|
9
|
+
/** The error behind a reply that is the `{"error": {"code", "message"}}` envelope, if it is one. */
|
|
10
|
+
export declare function refusal(reply: unknown): HivemindError | undefined;
|
|
11
|
+
/** The server's 401 body is `{"error": "key_locked" | "unauthorized", "detail": ...}`. */
|
|
12
|
+
export declare function rejectedKey(response: Response): Promise<AuthenticationError>;
|
package/dist/errors.js
CHANGED
|
@@ -13,3 +13,22 @@ const AUTH_CODES = new Set(["unauthenticated", "key_locked"]);
|
|
|
13
13
|
export function errorFromEnvelope(code, message) {
|
|
14
14
|
return AUTH_CODES.has(code) ? new AuthenticationError(code, message) : new HivemindError(code, message);
|
|
15
15
|
}
|
|
16
|
+
/** The error behind a reply that is the `{"error": {"code", "message"}}` envelope, if it is one. */
|
|
17
|
+
export function refusal(reply) {
|
|
18
|
+
if (typeof reply !== "object" || reply === null || Object.keys(reply).join() !== "error") {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const error = reply.error;
|
|
22
|
+
if (typeof error !== "object" || error === null) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const { code, message } = error;
|
|
26
|
+
return errorFromEnvelope(String(code || ""), String(message || ""));
|
|
27
|
+
}
|
|
28
|
+
/** The server's 401 body is `{"error": "key_locked" | "unauthorized", "detail": ...}`. */
|
|
29
|
+
export async function rejectedKey(response) {
|
|
30
|
+
const body = (await response.json().catch(() => ({})));
|
|
31
|
+
const code = body?.error === "key_locked" ? "key_locked" : "unauthenticated";
|
|
32
|
+
const detail = typeof body?.detail === "string" && body.detail ? body.detail : "";
|
|
33
|
+
return new AuthenticationError(code, detail || "the server rejected the API key (HTTP 401)");
|
|
34
|
+
}
|
package/dist/formats.d.ts
CHANGED
|
@@ -6,7 +6,10 @@ export interface ToolDefinition {
|
|
|
6
6
|
export interface AnthropicTool {
|
|
7
7
|
name: string;
|
|
8
8
|
description: string;
|
|
9
|
-
input_schema:
|
|
9
|
+
input_schema: {
|
|
10
|
+
type: "object";
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
10
13
|
}
|
|
11
14
|
export interface OpenAITool {
|
|
12
15
|
type: "function";
|
package/dist/formats.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function toAnthropic(tools) {
|
|
2
|
-
return tools.map((t) => ({ name: t.name, description: t.description, input_schema: t.inputSchema }));
|
|
2
|
+
return tools.map((t) => ({ name: t.name, description: t.description, input_schema: { ...t.inputSchema, type: "object" } }));
|
|
3
3
|
}
|
|
4
4
|
export function toOpenAI(tools) {
|
|
5
5
|
return tools.map((t) => ({
|
package/dist/types.d.ts
CHANGED
|
@@ -59,3 +59,240 @@ export interface RegisterOptions {
|
|
|
59
59
|
owner_alias?: string;
|
|
60
60
|
}
|
|
61
61
|
export type Reply = Record<string, unknown>;
|
|
62
|
+
export type EntryState = "active" | "superseded" | "withdrawn";
|
|
63
|
+
export interface FeedbackCounts {
|
|
64
|
+
helpful: number;
|
|
65
|
+
stale: number;
|
|
66
|
+
wrong: number;
|
|
67
|
+
}
|
|
68
|
+
export interface Warning {
|
|
69
|
+
code: string;
|
|
70
|
+
message: string;
|
|
71
|
+
}
|
|
72
|
+
export interface Entry {
|
|
73
|
+
id: string;
|
|
74
|
+
kind: EntryKind;
|
|
75
|
+
summary: string;
|
|
76
|
+
author: string;
|
|
77
|
+
agent: string | null;
|
|
78
|
+
body: string | null;
|
|
79
|
+
payload: Record<string, unknown> | null;
|
|
80
|
+
sources: Source[];
|
|
81
|
+
tags: string[];
|
|
82
|
+
importance: number;
|
|
83
|
+
importance_source: string;
|
|
84
|
+
scope: string;
|
|
85
|
+
fleet_id: string | null;
|
|
86
|
+
state: EntryState;
|
|
87
|
+
superseded_by: string | null;
|
|
88
|
+
withdrawn_reason: string | null;
|
|
89
|
+
withdrawn_at: string | null;
|
|
90
|
+
entities: {
|
|
91
|
+
name: string;
|
|
92
|
+
kind: string;
|
|
93
|
+
}[];
|
|
94
|
+
entities_model: string | null;
|
|
95
|
+
occurred_at: string;
|
|
96
|
+
created_at: string;
|
|
97
|
+
}
|
|
98
|
+
export interface Feedback extends FeedbackCounts {
|
|
99
|
+
recent: {
|
|
100
|
+
verdict: Verdict;
|
|
101
|
+
note: string | null;
|
|
102
|
+
reporter: string;
|
|
103
|
+
updated_at: string | null;
|
|
104
|
+
}[];
|
|
105
|
+
last_confirmed_at?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface Link {
|
|
108
|
+
id: string;
|
|
109
|
+
kind: EntryKind;
|
|
110
|
+
summary: string;
|
|
111
|
+
author: string;
|
|
112
|
+
state: EntryState;
|
|
113
|
+
fleet_id: string | null;
|
|
114
|
+
}
|
|
115
|
+
/** `get` of one id; `successors` and `superseded` come with `include_history`. */
|
|
116
|
+
export interface EntryDetail extends Entry {
|
|
117
|
+
feedback: Feedback;
|
|
118
|
+
see_also: Link[];
|
|
119
|
+
linked_from: Link[];
|
|
120
|
+
successors?: Entry[];
|
|
121
|
+
superseded?: Entry[];
|
|
122
|
+
}
|
|
123
|
+
/** `get` of a list of ids: the readable ones, then the ids that named nothing readable. */
|
|
124
|
+
export interface Entries {
|
|
125
|
+
entries: EntryDetail[];
|
|
126
|
+
not_found: string[];
|
|
127
|
+
}
|
|
128
|
+
/** A compact search hit, without the body: `get` it to read it. */
|
|
129
|
+
export interface Hit {
|
|
130
|
+
id: string;
|
|
131
|
+
kind: EntryKind;
|
|
132
|
+
summary: string;
|
|
133
|
+
tags: string[];
|
|
134
|
+
author: string;
|
|
135
|
+
agent: string | null;
|
|
136
|
+
occurred_at: string;
|
|
137
|
+
score: number;
|
|
138
|
+
match: string;
|
|
139
|
+
scope: string;
|
|
140
|
+
fleet_id: string | null;
|
|
141
|
+
similarity?: number;
|
|
142
|
+
feedback?: FeedbackCounts;
|
|
143
|
+
last_confirmed_at?: string;
|
|
144
|
+
contested?: boolean;
|
|
145
|
+
correction?: {
|
|
146
|
+
verdict: Verdict;
|
|
147
|
+
note: string | null;
|
|
148
|
+
reporter: string;
|
|
149
|
+
updated_at: string;
|
|
150
|
+
};
|
|
151
|
+
supersedes?: string[];
|
|
152
|
+
state?: EntryState;
|
|
153
|
+
similar?: {
|
|
154
|
+
id: string;
|
|
155
|
+
occurred_at: string;
|
|
156
|
+
}[];
|
|
157
|
+
upstream_changed?: {
|
|
158
|
+
id: string;
|
|
159
|
+
change: string;
|
|
160
|
+
}[];
|
|
161
|
+
}
|
|
162
|
+
/** `note` explains a `degraded` (keyword-only) search or a `closest: "loose"` one. */
|
|
163
|
+
export interface SearchReply {
|
|
164
|
+
count: number;
|
|
165
|
+
hits: Hit[];
|
|
166
|
+
recency?: Recency;
|
|
167
|
+
degraded?: string;
|
|
168
|
+
closest?: string;
|
|
169
|
+
note?: string;
|
|
170
|
+
}
|
|
171
|
+
/** With `include_body` an item is a whole `Entry`; `feedback` comes with `relied_on_changed`. */
|
|
172
|
+
export interface ListItem {
|
|
173
|
+
id: string;
|
|
174
|
+
kind: EntryKind;
|
|
175
|
+
summary: string;
|
|
176
|
+
tags: string[];
|
|
177
|
+
author: string;
|
|
178
|
+
agent: string | null;
|
|
179
|
+
occurred_at: string;
|
|
180
|
+
created_at: string;
|
|
181
|
+
scope: string;
|
|
182
|
+
fleet_id: string | null;
|
|
183
|
+
state: EntryState;
|
|
184
|
+
superseded_by: string | null;
|
|
185
|
+
body?: string | null;
|
|
186
|
+
feedback?: FeedbackCounts;
|
|
187
|
+
}
|
|
188
|
+
export interface ListReply {
|
|
189
|
+
count: number;
|
|
190
|
+
entries: ListItem[];
|
|
191
|
+
}
|
|
192
|
+
export interface RelatedEntry {
|
|
193
|
+
id: string;
|
|
194
|
+
kind: EntryKind;
|
|
195
|
+
summary: string;
|
|
196
|
+
author: string;
|
|
197
|
+
scope: string;
|
|
198
|
+
fleet_id: string | null;
|
|
199
|
+
occurred_at: string;
|
|
200
|
+
similarity: number;
|
|
201
|
+
tags: string[];
|
|
202
|
+
feedback: FeedbackCounts;
|
|
203
|
+
same_author: boolean;
|
|
204
|
+
}
|
|
205
|
+
/** The stored entry, its nearest `related` entries and advisory `warnings`. */
|
|
206
|
+
export interface WriteReply extends Entry {
|
|
207
|
+
related: RelatedEntry[];
|
|
208
|
+
warnings: Warning[];
|
|
209
|
+
}
|
|
210
|
+
/** `write` with `check: true`: what a write would report, with nothing stored. */
|
|
211
|
+
export interface CheckReply {
|
|
212
|
+
checked: true;
|
|
213
|
+
related: RelatedEntry[];
|
|
214
|
+
warnings: Warning[];
|
|
215
|
+
}
|
|
216
|
+
/** `fix` says how to supersede the entry when the rater may. */
|
|
217
|
+
export interface FeedbackReply {
|
|
218
|
+
entry_id: string;
|
|
219
|
+
verdict: Verdict;
|
|
220
|
+
note: string | null;
|
|
221
|
+
quality: number;
|
|
222
|
+
feedback: {
|
|
223
|
+
entry_id: string;
|
|
224
|
+
user: string;
|
|
225
|
+
agent: string | null;
|
|
226
|
+
verdict: Verdict;
|
|
227
|
+
note: string | null;
|
|
228
|
+
updated_at: string | null;
|
|
229
|
+
};
|
|
230
|
+
fix?: string;
|
|
231
|
+
}
|
|
232
|
+
export interface BatchFeedbackReply {
|
|
233
|
+
verdict: Verdict;
|
|
234
|
+
note: string | null;
|
|
235
|
+
results: {
|
|
236
|
+
entry_id: string;
|
|
237
|
+
quality: number;
|
|
238
|
+
}[];
|
|
239
|
+
fix?: {
|
|
240
|
+
may_supersede: string[];
|
|
241
|
+
how: string;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
export interface FleetPhase {
|
|
245
|
+
phase: string;
|
|
246
|
+
until: string;
|
|
247
|
+
hint: string;
|
|
248
|
+
}
|
|
249
|
+
export interface Pin {
|
|
250
|
+
id: string;
|
|
251
|
+
pinned_id: string;
|
|
252
|
+
kind: EntryKind;
|
|
253
|
+
summary: string;
|
|
254
|
+
author: string;
|
|
255
|
+
state: EntryState;
|
|
256
|
+
pinned_by: string;
|
|
257
|
+
pinned_at: string;
|
|
258
|
+
changed_since_pin: boolean;
|
|
259
|
+
change_reason: string | null;
|
|
260
|
+
}
|
|
261
|
+
export interface PinnedReply {
|
|
262
|
+
fleet_id: string | null;
|
|
263
|
+
pins: Pin[];
|
|
264
|
+
fleet_phase?: FleetPhase;
|
|
265
|
+
}
|
|
266
|
+
/** Pinning adds `fleet_id`, `pinned_by` and `pinned_at`; unpinning adds `removed`. */
|
|
267
|
+
export interface PinReply {
|
|
268
|
+
entry_id: string;
|
|
269
|
+
pinned: boolean;
|
|
270
|
+
fleet_id?: string;
|
|
271
|
+
pinned_by?: string;
|
|
272
|
+
pinned_at?: string;
|
|
273
|
+
removed?: boolean;
|
|
274
|
+
}
|
|
275
|
+
export interface RegisterReply {
|
|
276
|
+
name: string;
|
|
277
|
+
status: string;
|
|
278
|
+
trust_level: number;
|
|
279
|
+
home_fleet_id: string | null;
|
|
280
|
+
already_registered: boolean;
|
|
281
|
+
message: string;
|
|
282
|
+
}
|
|
283
|
+
export interface WhoAmI {
|
|
284
|
+
key_kind: string;
|
|
285
|
+
name: string | null;
|
|
286
|
+
status: string | null;
|
|
287
|
+
trust_level: number;
|
|
288
|
+
trust_level_name: string;
|
|
289
|
+
home_fleet_id: string | null;
|
|
290
|
+
home_fleet_name: string | null;
|
|
291
|
+
can_read: string[];
|
|
292
|
+
can_write_scopes: string[];
|
|
293
|
+
inherits_from: string[];
|
|
294
|
+
key_last_used_at: string | null;
|
|
295
|
+
fleet_phase?: FleetPhase;
|
|
296
|
+
role?: string;
|
|
297
|
+
role_hint?: string;
|
|
298
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hivemind-memory",
|
|
3
|
-
"version": "2.31.
|
|
3
|
+
"version": "2.31.2",
|
|
4
4
|
"description": "Client for Hivemind, the shared memory service for AI agents: MCP tools, instructions and tool definitions for agents built outside the supported harnesses.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"agents",
|
|
8
|
+
"memory",
|
|
9
|
+
"mcp",
|
|
10
|
+
"hivemind",
|
|
11
|
+
"ai-sdk"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/monochrome-muncher/hivemind.git",
|
|
16
|
+
"directory": "clients/typescript"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/monochrome-muncher/hivemind/tree/main/clients/typescript#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/monochrome-muncher/hivemind/issues"
|
|
21
|
+
},
|
|
6
22
|
"type": "module",
|
|
7
23
|
"engines": {
|
|
8
24
|
"node": ">=22"
|
package/text/skill.md
CHANGED
|
@@ -19,9 +19,9 @@ Call it first, and again after compaction or a cleared context.
|
|
|
19
19
|
|
|
20
20
|
| It shows | Do |
|
|
21
21
|
|---|---|
|
|
22
|
-
| No tool, or connection errors |
|
|
23
|
-
| `key_kind: "org"` | Not
|
|
24
|
-
| `unauthenticated`/`key_locked`/401 | The key no longer works. Stop calling `hive_
|
|
22
|
+
| No tool, or connection errors | Tell the user once, and work on. |
|
|
23
|
+
| `key_kind: "org"` | Not an agent key, or the agent awaits activation. Tell the user that the app needs an activated agent key. No reads or writes yet. |
|
|
24
|
+
| `unauthenticated`/`key_locked`/401 | The key no longer works. Stop calling `hive_*` and tell the user once: the app needs a new key. |
|
|
25
25
|
| `trust_level: 0` | Demoted: searches return nothing, writes fail. Ask the user to have the admin raise it. |
|
|
26
26
|
| `can_write_scopes: ["self"]` (lurker) | Recall a lot; write to `self`. Tell the user once that you can read but not contribute: ask the admin to make `<name>` a contributor. |
|
|
27
27
|
| `key_kind: "admin"` or `"legacy"` | Not an agent key: warn that writes are not attributed to an agent. |
|
|
@@ -156,25 +156,7 @@ belongs to your user or their organization.
|
|
|
156
156
|
## 5. Local memory and outages
|
|
157
157
|
|
|
158
158
|
**Local memory** is for scratch work, a fallback when you cannot write
|
|
159
|
-
(tell the user; move the notes in and delete them once you can)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
**Unavailable** (and not incognito): mention it once, keep helping, keep
|
|
164
|
-
notes locally, write them when it is back. If no
|
|
165
|
-
`HIVEMIND:` reminder starts your context and you have no plugin, offer
|
|
166
|
-
hivemind-setup's "Stay aware" step.
|
|
167
|
-
|
|
168
|
-
## 6. Incognito sessions
|
|
169
|
-
|
|
170
|
-
Hivemind is off when a "HIVEMIND: this is an incognito
|
|
171
|
-
session" reminder is in context, when `HIVEMIND_INCOGNITO` is `1`, or when
|
|
172
|
-
the user asks mid-session.
|
|
173
|
-
|
|
174
|
-
- Call no `hive_*` tool, mention no Hivemind, offer no setup.
|
|
175
|
-
- Local notes are fine; start each with `[hivemind: incognito, never upload]`.
|
|
176
|
-
- If the tools are loaded anyway, don't use them, and tell the user once
|
|
177
|
-
that this session is incognito only by your restraint (a real one
|
|
178
|
-
starts with `hivemind-incognito <harness>`).
|
|
179
|
-
- Turned on mid-session: stop, and say it relies on you obeying.
|
|
180
|
-
Started incognito: only a new session turns Hivemind back on.
|
|
159
|
+
(tell the user; move the notes in and delete them once you can).
|
|
160
|
+
|
|
161
|
+
**Unavailable**: mention it once, keep helping, keep notes locally, write
|
|
162
|
+
them when it is back.
|