@tangenta/claude-code 0.0.0-stage → 0.19.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.
- package/.claude-plugin/plugin.json +15 -0
- package/.mcp.json +10 -0
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/hooks/hooks.json +67 -0
- package/lib/config.mjs +200 -0
- package/lib/hooks.mjs +551 -0
- package/lib/inputs.mjs +95 -0
- package/lib/proxy.mjs +206 -0
- package/lib/store.mjs +138 -0
- package/lib/tangenta.mjs +89 -0
- package/package.json +30 -3
- package/scripts/hook.mjs +39 -0
- package/scripts/mcp-proxy.mjs +45 -0
package/lib/proxy.mjs
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin's local MCP server (stdio): offers the session tools and forwards each call to
|
|
3
|
+
* `<api>/mcp` with the token of the session this project is attached to. The token is read
|
|
4
|
+
* from the store on every call, so attaching works without restarting Claude Code. The tool
|
|
5
|
+
* list is fixed, since Claude Code reads it once at start, before any session is attached.
|
|
6
|
+
* `session_inputs` is left out: the hooks own the reading of inputs.
|
|
7
|
+
*/
|
|
8
|
+
import { PROXY_SERVER, SESSION_TOOLS, projectDir } from "./config.mjs";
|
|
9
|
+
import { TangentaError, rpc } from "./tangenta.mjs";
|
|
10
|
+
import { openStore } from "./store.mjs";
|
|
11
|
+
|
|
12
|
+
const VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26"];
|
|
13
|
+
const CALL_TIMEOUT_MS = 30_000;
|
|
14
|
+
const NOT_ATTACHED =
|
|
15
|
+
"This project isn't attached to a Tangenta session. Start or reconnect the session from the " +
|
|
16
|
+
"issue's Agent panel in Tangenta and paste its prompt here.";
|
|
17
|
+
|
|
18
|
+
export const TOOLS = [
|
|
19
|
+
{
|
|
20
|
+
name: "get_session",
|
|
21
|
+
title: "Get the Tangenta session",
|
|
22
|
+
description:
|
|
23
|
+
"The Tangenta session this project is attached to: its issue, state, plan, branch and the " +
|
|
24
|
+
"trust rules for messages from Tangenta.",
|
|
25
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
26
|
+
annotations: { readOnlyHint: true },
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "emit_activity",
|
|
30
|
+
title: "Report activity",
|
|
31
|
+
description:
|
|
32
|
+
"Adds an entry to the session's activity stream on the issue page: a thought, an action " +
|
|
33
|
+
"(tool and target, never its output), a response or an error.",
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: "object",
|
|
36
|
+
properties: {
|
|
37
|
+
kind: { type: "string", enum: ["thought", "action", "response", "error"] },
|
|
38
|
+
body: { type: "string" },
|
|
39
|
+
tool: { type: "string" },
|
|
40
|
+
target: { type: "string" },
|
|
41
|
+
},
|
|
42
|
+
required: ["kind"],
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
},
|
|
45
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "update_plan",
|
|
49
|
+
title: "Update the plan",
|
|
50
|
+
description:
|
|
51
|
+
"Replaces the session's plan checklist, and optionally names the branch you work on.",
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
items: {
|
|
56
|
+
type: "array",
|
|
57
|
+
items: {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {
|
|
60
|
+
content: { type: "string" },
|
|
61
|
+
status: { type: "string", enum: ["pending", "in_progress", "completed"] },
|
|
62
|
+
},
|
|
63
|
+
required: ["content", "status"],
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
branch: { type: "string" },
|
|
68
|
+
},
|
|
69
|
+
required: ["items"],
|
|
70
|
+
additionalProperties: false,
|
|
71
|
+
},
|
|
72
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "ask",
|
|
76
|
+
title: "Ask a question",
|
|
77
|
+
description:
|
|
78
|
+
"Asks the session's starter a question on the issue page, with optional choices. Returns " +
|
|
79
|
+
"at once; end your turn after asking. The answer arrives as a message from Tangenta.",
|
|
80
|
+
inputSchema: {
|
|
81
|
+
type: "object",
|
|
82
|
+
properties: {
|
|
83
|
+
question: { type: "string" },
|
|
84
|
+
choices: { type: "array", items: { type: "string" } },
|
|
85
|
+
},
|
|
86
|
+
required: ["question"],
|
|
87
|
+
additionalProperties: false,
|
|
88
|
+
},
|
|
89
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "end_session",
|
|
93
|
+
title: "End the session",
|
|
94
|
+
description:
|
|
95
|
+
"Ends the Tangenta session when the work is done (complete) or can't go on (error), with a " +
|
|
96
|
+
"short summary for the issue page.",
|
|
97
|
+
inputSchema: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
outcome: { type: "string", enum: ["complete", "error"] },
|
|
101
|
+
summary: { type: "string" },
|
|
102
|
+
},
|
|
103
|
+
required: ["outcome"],
|
|
104
|
+
additionalProperties: false,
|
|
105
|
+
},
|
|
106
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
function result(id, value) {
|
|
111
|
+
return { jsonrpc: "2.0", id, result: value };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function failure(id, code, message) {
|
|
115
|
+
return { jsonrpc: "2.0", id, error: { code, message } };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function toolError(message) {
|
|
119
|
+
return { content: [{ type: "text", text: message }], isError: true };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function initialize(params) {
|
|
123
|
+
const requested = params?.protocolVersion;
|
|
124
|
+
return {
|
|
125
|
+
protocolVersion: VERSIONS.includes(requested) ? requested : VERSIONS[0],
|
|
126
|
+
capabilities: { tools: { listChanged: false } },
|
|
127
|
+
serverInfo: { name: `tangenta-${PROXY_SERVER}`, title: "Tangenta session", version: "0.19.0" },
|
|
128
|
+
instructions:
|
|
129
|
+
"Tools of the Tangenta session this project is attached to: report activity and the " +
|
|
130
|
+
"plan to the issue page, ask the starter a question, and end the session.",
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function forward(id, name, args, deps) {
|
|
135
|
+
const env = deps.env ?? process.env;
|
|
136
|
+
const store = openStore(env, projectDir(env, null));
|
|
137
|
+
const state = store.read();
|
|
138
|
+
if (!state || state.closed) return result(id, toolError(NOT_ATTACHED));
|
|
139
|
+
const message = {
|
|
140
|
+
jsonrpc: "2.0",
|
|
141
|
+
id: 1,
|
|
142
|
+
method: "tools/call",
|
|
143
|
+
params: { name, arguments: args },
|
|
144
|
+
};
|
|
145
|
+
let answer;
|
|
146
|
+
try {
|
|
147
|
+
answer = await rpc({
|
|
148
|
+
apiUrl: state.apiUrl,
|
|
149
|
+
token: state.token,
|
|
150
|
+
message,
|
|
151
|
+
timeoutMs: CALL_TIMEOUT_MS,
|
|
152
|
+
fetchImpl: deps.fetchImpl,
|
|
153
|
+
});
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (!(error instanceof TangentaError)) throw error;
|
|
156
|
+
const text =
|
|
157
|
+
error.kind === "unauthorized"
|
|
158
|
+
? "Tangenta no longer accepts this session's token, so the session has ended or expired. " +
|
|
159
|
+
"Tell the user to reconnect from the issue's Agent panel."
|
|
160
|
+
: error.message;
|
|
161
|
+
return result(id, toolError(text));
|
|
162
|
+
}
|
|
163
|
+
if (answer?.error) return failure(id, answer.error.code ?? -32_603, answer.error.message);
|
|
164
|
+
if (name === "end_session" && answer?.result && !answer.result.isError) {
|
|
165
|
+
await store.withLock(async () => {
|
|
166
|
+
const current = store.read();
|
|
167
|
+
if (current && current.token === state.token) store.write({ ...current, closed: true });
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return result(id, answer?.result ?? toolError("Tangenta's answer had no result."));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Answers one JSON-RPC message, or null for a notification or a response. `deps.env` and
|
|
175
|
+
* `deps.fetchImpl` replace the process environment and fetch in tests.
|
|
176
|
+
*/
|
|
177
|
+
export async function handleMessage(message, deps = {}) {
|
|
178
|
+
if (!message || message.jsonrpc !== "2.0" || typeof message.method !== "string") {
|
|
179
|
+
if (message && message.jsonrpc === "2.0" && ("result" in message || "error" in message)) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
return failure(message?.id ?? null, -32_600, "Invalid request.");
|
|
183
|
+
}
|
|
184
|
+
if (!("id" in message)) return null;
|
|
185
|
+
const { id, method } = message;
|
|
186
|
+
const params = message.params ?? {};
|
|
187
|
+
switch (method) {
|
|
188
|
+
case "initialize":
|
|
189
|
+
return result(id, initialize(params));
|
|
190
|
+
case "ping":
|
|
191
|
+
return result(id, {});
|
|
192
|
+
case "tools/list":
|
|
193
|
+
return result(id, { tools: TOOLS });
|
|
194
|
+
case "tools/call": {
|
|
195
|
+
const name = params.name;
|
|
196
|
+
if (!SESSION_TOOLS.includes(name)) return failure(id, -32_602, `Unknown tool: ${name}`);
|
|
197
|
+
const args = params.arguments ?? {};
|
|
198
|
+
if (typeof args !== "object" || Array.isArray(args)) {
|
|
199
|
+
return failure(id, -32_602, "arguments must be an object.");
|
|
200
|
+
}
|
|
201
|
+
return forward(id, name, args, deps);
|
|
202
|
+
}
|
|
203
|
+
default:
|
|
204
|
+
return failure(id, -32_601, "Method not found.");
|
|
205
|
+
}
|
|
206
|
+
}
|
package/lib/store.mjs
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attached session of one project directory: its token, the API it belongs to and how far
|
|
3
|
+
* its inputs have been read. One JSON file per project under the state root (see config.mjs),
|
|
4
|
+
* named after a hash of the project's real path, so two projects never share a token. The
|
|
5
|
+
* directory is 0700 and the file 0600; a state root inside the project is refused, so the token
|
|
6
|
+
* never lands in a repository.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import {
|
|
10
|
+
chmodSync,
|
|
11
|
+
closeSync,
|
|
12
|
+
mkdirSync,
|
|
13
|
+
openSync,
|
|
14
|
+
readFileSync,
|
|
15
|
+
realpathSync,
|
|
16
|
+
renameSync,
|
|
17
|
+
rmSync,
|
|
18
|
+
statSync,
|
|
19
|
+
writeSync,
|
|
20
|
+
} from "node:fs";
|
|
21
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
22
|
+
|
|
23
|
+
import { stateRoot } from "./config.mjs";
|
|
24
|
+
|
|
25
|
+
const LOCK_WAIT_MS = 8_000;
|
|
26
|
+
const LOCK_STALE_MS = 20_000;
|
|
27
|
+
const LOCK_RETRY_MS = 25;
|
|
28
|
+
|
|
29
|
+
export class StoreError extends Error {}
|
|
30
|
+
|
|
31
|
+
function realPath(path) {
|
|
32
|
+
try {
|
|
33
|
+
return realpathSync(path);
|
|
34
|
+
} catch {
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function inside(parent, child) {
|
|
40
|
+
const path = relative(parent, child);
|
|
41
|
+
return path === "" || (!path.startsWith("..") && !isAbsolute(path));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The store of `project` under the state root that `env` names. */
|
|
45
|
+
export function openStore(env, project) {
|
|
46
|
+
const root = realPath(stateRoot(env));
|
|
47
|
+
const projectPath = realPath(project);
|
|
48
|
+
if (inside(projectPath, root)) {
|
|
49
|
+
throw new StoreError(
|
|
50
|
+
"The Tangenta plugin's state directory is inside the project, where the session token " +
|
|
51
|
+
"could end up in the repository. Point TANGENTA_PLUGIN_STATE_DIR somewhere else.",
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const key = createHash("sha256").update(projectPath).digest("hex").slice(0, 32);
|
|
55
|
+
const directory = join(root, "sessions");
|
|
56
|
+
return new Store(directory, key);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class Store {
|
|
60
|
+
constructor(directory, key) {
|
|
61
|
+
this.directory = directory;
|
|
62
|
+
this.path = join(directory, `${key}.json`);
|
|
63
|
+
this.lockPath = join(directory, `${key}.lock`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The attached session, or null. */
|
|
67
|
+
read() {
|
|
68
|
+
let text;
|
|
69
|
+
try {
|
|
70
|
+
text = readFileSync(this.path, "utf8");
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const state = JSON.parse(text);
|
|
76
|
+
return state && typeof state === "object" && typeof state.token === "string" ? state : null;
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Replaces the attached session, atomically and readable by this user only. */
|
|
83
|
+
write(state) {
|
|
84
|
+
mkdirSync(this.directory, { recursive: true, mode: 0o700 });
|
|
85
|
+
chmodSync(this.directory, 0o700);
|
|
86
|
+
const temporary = `${this.path}.${process.pid}.${Date.now()}.tmp`;
|
|
87
|
+
const descriptor = openSync(temporary, "wx", 0o600);
|
|
88
|
+
try {
|
|
89
|
+
writeSync(descriptor, JSON.stringify(state));
|
|
90
|
+
} finally {
|
|
91
|
+
closeSync(descriptor);
|
|
92
|
+
}
|
|
93
|
+
renameSync(temporary, this.path);
|
|
94
|
+
chmodSync(this.path, 0o600);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Forgets the attached session and its token. */
|
|
98
|
+
clear() {
|
|
99
|
+
rmSync(this.path, { force: true });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Runs `work` while holding this project's lock, so hooks of tool calls that run at the same
|
|
104
|
+
* time never deliver one input twice. A lock older than LOCK_STALE_MS is taken over.
|
|
105
|
+
*/
|
|
106
|
+
async withLock(work) {
|
|
107
|
+
mkdirSync(this.directory, { recursive: true, mode: 0o700 });
|
|
108
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
109
|
+
let descriptor = null;
|
|
110
|
+
while (descriptor === null) {
|
|
111
|
+
try {
|
|
112
|
+
descriptor = openSync(this.lockPath, "wx", 0o600);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (error?.code !== "EEXIST") throw error;
|
|
115
|
+
if (this.lockIsStale()) {
|
|
116
|
+
rmSync(this.lockPath, { force: true });
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (Date.now() > deadline) throw new StoreError("Another Tangenta hook holds the lock.");
|
|
120
|
+
await new Promise((done) => setTimeout(done, LOCK_RETRY_MS));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
return await work();
|
|
125
|
+
} finally {
|
|
126
|
+
closeSync(descriptor);
|
|
127
|
+
rmSync(this.lockPath, { force: true });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
lockIsStale() {
|
|
132
|
+
try {
|
|
133
|
+
return Date.now() - statSync(this.lockPath).mtimeMs > LOCK_STALE_MS;
|
|
134
|
+
} catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
package/lib/tangenta.mjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls Tangenta's MCP endpoint (`<api>/mcp`) with a session token: one JSON-RPC `tools/call` per
|
|
3
|
+
* HTTP POST, as the server is stateless. Errors never carry the token.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const PROTOCOL_VERSION = "2025-11-25";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A failed call. `kind` is `unauthorized` (the token no longer works), `rate_limited`, `tool`
|
|
10
|
+
* (the tool answered `isError`), `network` or `protocol`.
|
|
11
|
+
*/
|
|
12
|
+
export class TangentaError extends Error {
|
|
13
|
+
constructor(kind, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.kind = kind;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Sends one JSON-RPC message and answers the parsed JSON-RPC response. */
|
|
20
|
+
export async function rpc({ apiUrl, token, message, timeoutMs, fetchImpl = fetch }) {
|
|
21
|
+
let response;
|
|
22
|
+
try {
|
|
23
|
+
response = await fetchImpl(`${apiUrl}/mcp`, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
redirect: "manual",
|
|
26
|
+
headers: {
|
|
27
|
+
authorization: `Bearer ${token}`,
|
|
28
|
+
"content-type": "application/json",
|
|
29
|
+
accept: "application/json, text/event-stream",
|
|
30
|
+
"mcp-protocol-version": PROTOCOL_VERSION,
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify(message),
|
|
33
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
34
|
+
});
|
|
35
|
+
} catch (error) {
|
|
36
|
+
const reason = error?.name === "TimeoutError" ? "didn't answer in time" : "can't be reached";
|
|
37
|
+
throw new TangentaError("network", `Tangenta at ${apiUrl} ${reason}.`);
|
|
38
|
+
}
|
|
39
|
+
if (response.status === 401 || response.status === 403) {
|
|
40
|
+
throw new TangentaError("unauthorized", "Tangenta no longer accepts this session's token.");
|
|
41
|
+
}
|
|
42
|
+
if (response.status === 429) {
|
|
43
|
+
throw new TangentaError("rate_limited", "Tangenta rate-limited this session.");
|
|
44
|
+
}
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new TangentaError("protocol", `Tangenta answered HTTP ${response.status}.`);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return await response.json();
|
|
50
|
+
} catch {
|
|
51
|
+
throw new TangentaError("protocol", "Tangenta's answer wasn't JSON.");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The structured result of a tool result: `structuredContent`, else the JSON in its text. */
|
|
56
|
+
export function structured(result) {
|
|
57
|
+
if (result?.structuredContent && typeof result.structuredContent === "object") {
|
|
58
|
+
return result.structuredContent;
|
|
59
|
+
}
|
|
60
|
+
const text = (result?.content ?? []).find((part) => part?.type === "text")?.text ?? "";
|
|
61
|
+
const start = text.indexOf("{");
|
|
62
|
+
if (start === -1) return {};
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(text.slice(start));
|
|
65
|
+
} catch {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Calls tool `name` with `args` and answers its structured result. */
|
|
71
|
+
export async function callTool({ apiUrl, token, name, args = {}, timeoutMs, fetchImpl }) {
|
|
72
|
+
const message = {
|
|
73
|
+
jsonrpc: "2.0",
|
|
74
|
+
id: 1,
|
|
75
|
+
method: "tools/call",
|
|
76
|
+
params: { name, arguments: args },
|
|
77
|
+
};
|
|
78
|
+
const answer = await rpc({ apiUrl, token, message, timeoutMs, fetchImpl });
|
|
79
|
+
if (answer?.error) {
|
|
80
|
+
const kind = answer.error.code === -32000 ? "rate_limited" : "protocol";
|
|
81
|
+
throw new TangentaError(kind, String(answer.error.message ?? "Tangenta refused the call."));
|
|
82
|
+
}
|
|
83
|
+
const result = answer?.result;
|
|
84
|
+
if (result?.isError) {
|
|
85
|
+
const text = (result.content ?? []).find((part) => part?.type === "text")?.text;
|
|
86
|
+
throw new TangentaError("tool", text ?? `Tangenta refused ${name}.`);
|
|
87
|
+
}
|
|
88
|
+
return structured(result);
|
|
89
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangenta/claude-code",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.19.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "The Tangenta plugin for Claude Code: hooks and a local MCP server that attach a Claude Code session to a Tangenta issue. No dependencies.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"tangenta",
|
|
8
|
+
"claude-code",
|
|
9
|
+
"claude-code-plugin",
|
|
10
|
+
"mcp",
|
|
11
|
+
"issue-tracking"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://tangenta.app",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"files": [
|
|
16
|
+
".claude-plugin",
|
|
17
|
+
"hooks",
|
|
18
|
+
"lib",
|
|
19
|
+
"scripts",
|
|
20
|
+
".mcp.json",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "node --test --test-concurrency=1 \"../test/*.test.mjs\""
|
|
32
|
+
}
|
|
6
33
|
}
|
package/scripts/hook.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The entry of every Tangenta plugin hook: reads the hook's JSON input from standard input, runs
|
|
4
|
+
* the handler for its event (lib/hooks.mjs) and prints the answer as JSON. A failure never
|
|
5
|
+
* stops Claude Code: the hook prints one line to standard error and exits 0. Any session token
|
|
6
|
+
* in the output is masked as a last guard.
|
|
7
|
+
*/
|
|
8
|
+
import { TOKEN_PATTERN } from "../lib/config.mjs";
|
|
9
|
+
import { handleHook } from "../lib/hooks.mjs";
|
|
10
|
+
|
|
11
|
+
async function readStandardInput() {
|
|
12
|
+
const chunks = [];
|
|
13
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
14
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The output as JSON, with any session token masked. */
|
|
18
|
+
function serialize(output) {
|
|
19
|
+
return JSON.stringify(output).replaceAll(TOKEN_PATTERN, "[session token kept by Tangenta]");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
let input;
|
|
24
|
+
try {
|
|
25
|
+
input = JSON.parse(await readStandardInput());
|
|
26
|
+
} catch {
|
|
27
|
+
process.stderr.write("Tangenta plugin: the hook input wasn't JSON.\n");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const output = await handleHook(input);
|
|
32
|
+
if (output) process.stdout.write(`${serialize(output)}\n`);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
const message = String(error?.message ?? error).replaceAll(TOKEN_PATTERN, "[token]");
|
|
35
|
+
process.stderr.write(`Tangenta plugin: ${message.split("\n")[0]}\n`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await main();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The Tangenta plugin's MCP server over stdio: one JSON-RPC message per line in, one per line out
|
|
4
|
+
* (see lib/proxy.mjs). Messages are answered in the order they arrive.
|
|
5
|
+
*/
|
|
6
|
+
import { createInterface } from "node:readline";
|
|
7
|
+
|
|
8
|
+
import { TOKEN_PATTERN } from "../lib/config.mjs";
|
|
9
|
+
import { handleMessage } from "../lib/proxy.mjs";
|
|
10
|
+
|
|
11
|
+
const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
12
|
+
|
|
13
|
+
for await (const line of lines) {
|
|
14
|
+
if (!line.trim()) continue;
|
|
15
|
+
let message;
|
|
16
|
+
try {
|
|
17
|
+
message = JSON.parse(line);
|
|
18
|
+
} catch {
|
|
19
|
+
const parseError = {
|
|
20
|
+
jsonrpc: "2.0",
|
|
21
|
+
id: null,
|
|
22
|
+
error: { code: -32_700, message: "Parse error." },
|
|
23
|
+
};
|
|
24
|
+
process.stdout.write(`${JSON.stringify(parseError)}\n`);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const answer = await handleMessage(message);
|
|
29
|
+
if (answer) {
|
|
30
|
+
const text = JSON.stringify(answer).replaceAll(
|
|
31
|
+
TOKEN_PATTERN,
|
|
32
|
+
"[session token kept by Tangenta]",
|
|
33
|
+
);
|
|
34
|
+
process.stdout.write(`${text}\n`);
|
|
35
|
+
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
const reason = String(error?.message ?? error).replaceAll(TOKEN_PATTERN, "[token]");
|
|
38
|
+
const internal = {
|
|
39
|
+
jsonrpc: "2.0",
|
|
40
|
+
id: message?.id ?? null,
|
|
41
|
+
error: { code: -32_603, message: reason },
|
|
42
|
+
};
|
|
43
|
+
process.stdout.write(`${JSON.stringify(internal)}\n`);
|
|
44
|
+
}
|
|
45
|
+
}
|